/* ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
   한글 받아쓰기 — 모바일 우선 반응형
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ */
:root {
  --bg: #0f172a;
  --surface: #1e293b;
  --surface-2: #334155;
  --text: #f1f5f9;
  --text-dim: #94a3b8;
  --accent: #38bdf8;
  --accent-strong: #0ea5e9;
  --ok: #22c55e;
  --mid: #f59e0b;
  --bad: #ef4444;
  --radius: 12px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: 'Noto Sans KR', -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  overscroll-behavior: contain;
  -webkit-tap-highlight-color: transparent;
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
}

.app {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  max-width: 768px;
  margin: 0 auto;
  background: var(--bg);
}

/* ── 공통 ── */
.scene {
  display: flex;
  flex-direction: column;
  flex: 1;
  width: 100%;
  padding: 0;
}

.primary-btn, .ghost-btn {
  font-size: 16px;
  font-weight: 700;
  padding: 14px 22px;
  border-radius: var(--radius);
  min-height: 48px;
  transition: transform 0.05s, background 0.15s;
}

.primary-btn {
  background: var(--accent-strong);
  color: #fff;
}
.primary-btn:hover { background: var(--accent); }
.primary-btn:active { transform: scale(0.97); }
.primary-btn:disabled { opacity: 0.6; cursor: default; }

.ghost-btn {
  background: var(--surface);
  color: var(--text);
}
.ghost-btn:hover { background: var(--surface-2); }
.ghost-btn:active { transform: scale(0.97); }

.action-row {
  padding: 16px;
  display: flex;
  gap: 12px;
}
.action-row.two > * { flex: 1; }
.action-row .submit-btn { flex: 1; }

/* ── TopBar ── */
.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--surface);
  min-height: 56px;
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar-back {
  font-size: 24px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-2);
  flex-shrink: 0;
}
.topbar-back:hover { background: var(--accent-strong); }
.topbar-info {
  flex: 1;
  display: flex;
  gap: 16px;
  align-items: center;
  font-weight: 700;
  font-size: 15px;
  color: var(--text-dim);
}
.topbar-tier { color: var(--accent); }
.topbar-progress { color: var(--text); }
.topbar-score { color: var(--ok); margin-left: auto; }

/* ── Menu ── */
.scene-menu {
  align-items: center;
  justify-content: space-between;
  padding: 32px 24px;
}
.hero {
  text-align: center;
  margin-top: 60px;
}
.title {
  font-size: 40px;
  font-weight: 900;
  margin: 0 0 12px 0;
  color: var(--text);
  letter-spacing: -1px;
}
.subtitle {
  font-size: 16px;
  color: var(--text-dim);
  margin: 0;
}
.actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
  max-width: 360px;
}
.menu-footer {
  text-align: center;
  font-size: 13px;
  color: var(--text-dim);
  padding: 16px 0;
}

/* ── Difficulty ── */
.tier-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  padding: 16px;
}
.tier-card {
  display: grid;
  grid-template-columns: auto auto 1fr auto;
  grid-template-rows: auto auto;
  gap: 4px 12px;
  align-items: center;
  text-align: left;
  padding: 18px 20px;
  background: var(--surface);
  border-radius: var(--radius);
  min-height: 80px;
  transition: background 0.15s, transform 0.05s;
}
.tier-card:hover { background: var(--surface-2); }
.tier-card:active { transform: scale(0.99); }
.tier-emoji {
  grid-row: 1 / 3;
  font-size: 32px;
}
.tier-num {
  font-weight: 900;
  font-size: 18px;
  color: var(--accent);
}
.tier-label {
  font-weight: 700;
  font-size: 16px;
}
.tier-desc {
  grid-column: 2 / 4;
  grid-row: 2;
  font-size: 13px;
  color: var(--text-dim);
}
.tier-best {
  grid-column: 4;
  grid-row: 1;
  font-size: 12px;
  color: var(--ok);
  font-weight: 700;
}

/* ── Dictation play area ── */
.scene-dictation { gap: 0; }

.play-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 12px 16px;
  gap: 12px;
}

.prompt-row {
  display: flex;
  gap: 12px;
  align-items: center;
}

.play-btn {
  width: 100%;
  display: flex;
  flex-direction: row;
  align-items: center;
   justify-content: center;
  gap: 8px;
  padding: 16px 28px;
  background: var(--accent-strong);
  border-radius: var(--radius);
  font-weight: 800;
  flex: 0 0 auto;
  min-height: 72px;
  color: #fff;
}
.play-btn:active { transform: scale(0.97); }
.play-icon { font-size: 28px; line-height: 1; }
.play-label { font-size: 14px; }

.replay-btn {
  flex: 1;
  padding: 14px;
  background: var(--surface);
  border-radius: var(--radius);
  font-weight: 700;
  min-height: 48px;
  color: var(--text);
}
.replay-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.replay-count { font-size: 0.85em; opacity: 0.8; margin-left: 6px; }

/* ── Mode toggle ── */
.mode-toggle {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  background: var(--surface);
  padding: 4px;
  border-radius: var(--radius);
}
.mode-btn {
  padding: 10px 12px;
  border-radius: 8px;
  font-weight: 700;
  font-size: 14px;
  color: var(--text-dim);
  min-height: 40px;
  transition: background 0.15s, color 0.15s;
}
.mode-btn.active {
  background: var(--accent-strong);
  color: #fff;
}

/* ── Drawing pad ── */
.input-host { display: flex; flex-direction: column; min-height: 240px; }
.pad-wrap {
  position: relative;
  flex: 1;
  background: #f8fafc;
  border-radius: var(--radius);
  overflow: hidden;
  min-height: 240px;
  display: flex;
  flex-direction: column;
}
.pad-canvas {
  display: block;
  width: 100%;
  flex: 1;
  touch-action: none;
  cursor: crosshair;
}
.pad-hint {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  color: #94a3b8;
  font-size: 16px;
  font-weight: 500;
}
.pad-toolbar {
  display: flex;
  gap: 8px;
  padding: 8px;
  background: rgba(248, 250, 252, 0.95);
  border-top: 1px solid #e2e8f0;
}
.pad-btn {
  flex: 1;
  padding: 10px;
  background: #e2e8f0;
  color: #1e293b;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 700;
  min-height: 40px;
}
.pad-btn:hover { background: #cbd5e1; }

/* ── Keypad ── */
.keypad-wrap {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 24px 0;
}
.keypad-input {
  width: 100%;
  font-size: 28px;
  font-weight: 700;
  padding: 18px 16px;
  background: #f8fafc;
  color: #0f172a;
  border: 3px solid var(--surface-2);
  border-radius: var(--radius);
  outline: none;
  text-align: center;
  font-family: inherit;
}
.keypad-input:focus { border-color: var(--accent); }

/* ── Candidates ── */
.candidates {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-height: 28px;
}
.cand {
  font-size: 14px;
  padding: 6px 10px;
  background: var(--surface);
  color: var(--text-dim);
  border-radius: 6px;
}
.cand-top {
  background: var(--accent-strong);
  color: #fff;
  font-weight: 700;
}

/* ── Feedback ── */
.feedback {
  min-height: 28px;
  text-align: center;
  font-size: 16px;
  padding: 8px;
  border-radius: 8px;
  font-weight: 600;
}
.feedback.ok  { background: rgba(34, 197, 94, 0.15);  color: var(--ok); }
.feedback.mid { background: rgba(245, 158, 11, 0.15); color: var(--mid); }
.feedback.bad { background: rgba(239, 68, 68, 0.15);  color: var(--bad); }
.feedback.warn{ background: rgba(245, 158, 11, 0.15); color: var(--mid); }

/* ── Result ── */
.scene-result { gap: 0; }
.result-summary {
  text-align: center;
  padding: 32px 16px 16px;
}
.result-grade { font-size: 22px; font-weight: 700; color: var(--accent); margin-bottom: 8px; }
.result-total { font-size: 18px; color: var(--text-dim); }
.result-total strong { font-size: 56px; color: var(--text); display: block; line-height: 1; margin-bottom: 4px; }
.result-pct { font-size: 14px; color: var(--text-dim); margin-top: 6px; }

.result-list {
  list-style: none;
  margin: 0;
  padding: 8px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.rc {
  display: grid;
  grid-template-columns: auto auto 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  background: var(--surface);
  border-radius: 10px;
  font-size: 15px;
}
.rc-no { color: var(--text-dim); font-weight: 700; min-width: 18px; }
.rc-mark { font-size: 20px; font-weight: 900; }
.rc-words { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.rc-target { font-weight: 700; }
.rc-arrow { color: var(--text-dim); }
.rc-input { color: var(--text-dim); }
.rc-score { font-weight: 800; }
.rc-ok  .rc-mark, .rc-ok  .rc-score { color: var(--ok); }
.rc-mid .rc-mark, .rc-mid .rc-score { color: var(--mid); }
.rc-bad .rc-mark, .rc-bad .rc-score { color: var(--bad); }

/* ── 가로 모드 (태블릿/PC) ── */
@media (min-width: 768px) and (orientation: landscape) {
  .play-area {
    flex-direction: row;
    flex-wrap: wrap;
    align-content: flex-start;
  }
  .prompt-row { width: 100%; }
  .mode-host  { width: 100%; }
  .input-host { flex: 1 1 60%; min-width: 320px; }
  .candidates { width: 100%; }
  .action-row { width: 100%; }
  .feedback   { width: 100%; }
}
