/*
  디자인 가이드는 Docs/project_analysis.md §4를 따른다.
  무채색 계열, 둥근 모서리, 시스템 폰트 기반의 미니멀한 구성.
*/

:root {
  --bg: #f5f5f5;
  --surface: #ffffff;
  --ink: #333333;
  --ink-soft: #767676;
  --line: #d0d0d0;
  --accent: #333333;
  --danger: #c0392b;
  --radius: 12px;
  --radius-sm: 6px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.08), 0 4px 12px rgba(0, 0, 0, 0.04);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151515;
    --surface: #1f1f1f;
    --ink: #ececec;
    --ink-soft: #9a9a9a;
    --line: #383838;
    --accent: #ececec;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px 16px calc(20px + env(safe-area-inset-bottom));
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Apple SD Gothic Neo',
    'Pretendard', system-ui, sans-serif;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

#app { width: 100%; max-width: 440px; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  text-align: center;
}

h1 { font-size: 20px; font-weight: 700; margin: 0; }
h2 { font-size: 16px; font-weight: 600; margin: 0; }
p { margin: 0; }

.muted { color: var(--ink-soft); font-size: 14px; }
.small { font-size: 12px; }
.center-text { text-align: center; }
.big-emoji { font-size: 44px; line-height: 1; }
.game-title { font-size: 16px; font-weight: 600; }

.badge {
  display: inline-block;
  padding: 4px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 12px;
  color: var(--ink-soft);
}

/* ── 버튼 · 입력 ─────────────────────────────── */

.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  border-radius: var(--radius-sm);
  padding: 12px 18px;
  font-size: 15px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
  transition: transform 0.08s ease, opacity 0.15s ease;
}
.btn:active { transform: scale(0.98); }

.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--surface);
  width: 100%;
}

.btn.subtle {
  background: transparent;
  color: var(--ink-soft);
  font-weight: 500;
  padding: 8px 14px;
  font-size: 14px;
}

.btn.choice { width: 100%; font-weight: 500; }

.input {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--ink);
  font-size: 16px; /* 16px 미만이면 iOS에서 입력 시 화면이 확대된다 */
  font-family: inherit;
}
.input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

.intro-form,
.answer-form,
.choices {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
}

/*
  퀴즈 답 입력은 입력창과 버튼을 나란히 둔다.
  .btn.primary의 width:100%를 여기서 풀어주지 않으면 버튼이 가로를 다 먹고
  입력창이 눌려 사라진다.
*/
.answer-form { flex-direction: row; align-items: stretch; gap: 8px; }
.answer-form .input { flex: 1 1 auto; min-width: 0; }
.answer-form .btn { width: auto; flex: 0 0 auto; padding-inline: 20px; }

/* ── 퍼즐 ────────────────────────────────────── */

.stage { width: 100%; display: flex; flex-direction: column; gap: 12px; align-items: center; }

.puzzle-board {
  display: grid;
  grid-template-columns: repeat(var(--n), 1fr);
  gap: 3px;
  width: 100%;
  aspect-ratio: 1;
  background: var(--line);
  border-radius: var(--radius-sm);
  overflow: hidden;
  padding: 3px;
}

.puzzle-tile {
  appearance: none;
  border: none;
  padding: 0;
  background-color: var(--bg);
  background-repeat: no-repeat;
  border-radius: 3px;
  cursor: pointer;
  transition: opacity 0.1s ease;
}
.puzzle-tile:active { opacity: 0.85; }
.puzzle-tile.blank { background: transparent; cursor: default; }

.puzzle-board.solved { gap: 0; padding: 0; }
.puzzle-board.solved .puzzle-tile { border-radius: 0; }

/* ── 기억력 ──────────────────────────────────── */

.memory-board {
  display: grid;
  grid-template-columns: repeat(var(--cols), 1fr);
  gap: 8px;
  width: 100%;
}

.memory-card {
  appearance: none;
  aspect-ratio: 1;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background-color: var(--bg);
  background-repeat: no-repeat;
  color: var(--ink-soft);
  font-size: 20px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.15s ease, opacity 0.15s ease;
}
.memory-card.open { color: transparent; }
.memory-card.matched { opacity: 0.45; cursor: default; }
.memory-card:active { transform: scale(0.96); }

/* ── 답을 적는 게임 (퀴즈·초성·빈칸) ─────────── */

.prompt { font-size: 17px; font-weight: 600; }
.feedback { font-size: 14px; min-height: 20px; }
.feedback.wrong { color: var(--danger); }

/* 초성은 크게, 자간을 벌린다. 붙여 쓰면 글자 수가 안 세어지는데
   글자 수가 이 게임에서 거의 유일한 단서다. */
.chosung-box { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.chosung {
  font-size: 32px;
  font-weight: 700;
  letter-spacing: 0.18em;
  word-spacing: 0.4em;
  line-height: 1.4;
  text-align: center;
  overflow-wrap: anywhere;
}

.blank-sentence { line-height: 1.7; text-align: center; overflow-wrap: anywhere; }
.blank-sentence .blank {
  display: inline-block;
  min-width: 48px;
  margin: 0 2px;
  border-bottom: 2px solid var(--accent);
  color: var(--ink-soft);
  text-align: center;
}

/* ── 숨은 곳 찾기 ────────────────────────────── */

.spot-stage { position: relative; width: 100%; line-height: 0; }
.spot-image {
  width: 100%;
  display: block;
  max-height: 60vh;
  object-fit: contain;
  border-radius: var(--radius-sm);
  cursor: crosshair;
  user-select: none;
  -webkit-user-select: none;
}

/* 눌러본 자리. 안 남기면 같은 데를 또 누른다. */
.spot-mark {
  position: absolute;
  width: 14px;
  height: 14px;
  margin: -7px 0 0 -7px;
  border: 2px solid var(--danger);
  border-radius: 50%;
  pointer-events: none;
  opacity: 0.75;
}

/* ── 확대 조각 찾기 ──────────────────────────── */

/* 아래 칸과 같은 비율이어야 한다. 모양이 다르면 같은 부분인데도
   다르게 보여서, 알고도 못 맞히는 게임이 된다. */
.zoom-view {
  width: 100%;
  aspect-ratio: 1;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background-color: var(--bg);
  background-repeat: no-repeat;
}

.zoom-board {
  display: grid;
  grid-template-columns: repeat(var(--n), 1fr);
  gap: 3px;
  width: 100%;
}

.zoom-cell {
  appearance: none;
  aspect-ratio: 1;
  border: 1px solid var(--line);
  border-radius: 3px;
  background-color: var(--bg);
  background-repeat: no-repeat;
  cursor: pointer;
  transition: opacity 0.15s ease, transform 0.15s ease;
}
.zoom-cell:active { transform: scale(0.96); }
.zoom-cell.missed { opacity: 0.25; cursor: default; }
.zoom-cell.found { outline: 3px solid var(--accent); outline-offset: -3px; }

/* ── 이어붙이기 ──────────────────────────────── */

.stitch-strip {
  display: grid;
  grid-template-columns: repeat(var(--n), 1fr);
  gap: 4px;
  width: 100%;
  aspect-ratio: 3 / 2;
}

.stitch-piece {
  appearance: none;
  height: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background-color: var(--bg);
  background-repeat: no-repeat;
  cursor: pointer;
  transition: transform 0.15s ease;
}
.stitch-piece.picked { outline: 3px solid var(--accent); outline-offset: -3px; transform: translateY(-4px); }

.stitch-strip.solved { gap: 0; }
.stitch-strip.solved .stitch-piece { border-radius: 0; border-left-width: 0; border-right-width: 0; }

/* ── 힌트 · 타이머 ───────────────────────────── */

.hint-box { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.hint-text {
  font-size: 14px;
  color: var(--ink-soft);
  background: var(--bg);
  border: 1px dashed var(--line);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
}

.timer { font-size: 14px; color: var(--ink-soft); font-variant-numeric: tabular-nums; }
.timer.urgent { color: var(--danger); font-weight: 600; }

/* ── 결과 ────────────────────────────────────── */

.congrats { font-size: 15px; }

.media-box {
  width: 100%;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--bg);
  border: 1px solid var(--line);
}
.media { width: 100%; display: block; max-height: 60vh; object-fit: contain; }

.ranking { width: 100%; border-top: 1px solid var(--line); padding-top: 14px; margin-top: 4px; }
.ranking-title { font-size: 14px; color: var(--ink-soft); margin-bottom: 8px; }
.ranking-list { list-style: none; counter-reset: rank; margin: 0; padding: 0; }
.ranking-item {
  counter-increment: rank;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 0;
  font-size: 14px;
  border-bottom: 1px solid var(--line);
}
.ranking-item:last-child { border-bottom: none; }
.ranking-item::before {
  content: counter(rank);
  width: 20px;
  color: var(--ink-soft);
  font-variant-numeric: tabular-nums;
  text-align: right;
}
.ranking-name { flex: 1; text-align: left; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ranking-time { color: var(--ink-soft); font-variant-numeric: tabular-nums; }

/* ── 로딩 ────────────────────────────────────── */

.center { align-items: center; }
.spinner {
  width: 24px;
  height: 24px;
  border: 2px solid var(--line);
  border-top-color: var(--ink-soft);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

/* ── 발신자 화면 (게임 만들기) ───────────────────── */

.field { display: flex; flex-direction: column; gap: 6px; width: 100%; }
.field-label { font-size: 13px; font-weight: 600; color: var(--ink-soft); }

.game-fields { display: flex; flex-direction: column; gap: 14px; width: 100%; }
.game-fields:empty { display: none; }

select.input { appearance: none; background: var(--surface); }

.preview {
  width: 100%;
  max-height: 40vh;
  object-fit: contain;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
}

/* 발신자가 찍어둔 정답 지점 */
.spot-mark.picked { border-color: var(--accent); background: var(--accent); opacity: 0.9; }

.link-box { display: flex; flex-direction: column; gap: 8px; width: 100%; }
.link-box .input { font-size: 13px; }

/*
  보관 기간 안내.

  예전에는 `.muted .small`로 흐릿하게 "약 6시간 뒤에 사라져요"라고만 적었다.
  두 가지가 문제였다.
    1. 눈에 안 띄어 그냥 지나친다. 정작 지금 저장하지 않으면 못 받는 안내다.
    2. **저장한 사진이 사라진다**고 읽힌다. 사라지는 건 서버의 원본과 이
       링크지, 기기에 받아둔 파일이 아니다.
  그래서 테두리를 주고 두 줄로 나눠 무엇이 닫히는지 분명히 한다.
*/
.expiry-notice {
  display: flex;
  flex-direction: column;
  gap: 4px;
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-left: 3px solid var(--ink-soft);
  border-radius: var(--radius-sm);
  background: var(--bg);
  text-align: left;
}

.expiry-notice strong { font-size: 14px; color: var(--ink); font-weight: 600; }
.expiry-notice span { font-size: 13px; color: var(--ink-soft); }

/* 저장 버튼과 실패 안내 */
.save-box { display: flex; flex-direction: column; gap: 8px; width: 100%; }
.save-hint:empty { display: none; }
.save-hint { font-size: 12px; color: var(--ink-soft); text-align: center; }
/* 실패했을 때만 붉게. 평소 안내까지 빨가면 다 실패처럼 보인다. */
.save-hint.error { color: var(--danger); }

/* 인트로에서 보낸 사람 아래 붙는 게임 제목 */
.game-title { font-size: 14px; color: var(--ink-soft); }
