/* ── Reset & base ───────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:        #282828;
  --surface:   #32302f;
  --border:    #504945;
  --text:      #ebdbb2;
  --dim:       #665c54;
  --accent:    #83a598;
  --correct:   #b8bb26;
  --wrong:     #fb4934;
  --learning:  #d79921;
  --locked:    #32302f;
  --locked-fg: #665c54;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: 'Apple SD Gothic Neo', 'Noto Sans KR', 'Malgun Gothic', system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  max-width: 860px;
  margin: 0 auto;
  padding: 0 24px;
}

/* ── Top bar: brand + stats ─────────────────────────────────────── */
#topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 0 14px;
  border-bottom: 1px solid var(--border);
}

#brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

#brand-mark {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: var(--accent);
  color: var(--bg);
  font-size: 1.15rem;
  font-weight: 700;
}

#brand-name {
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: 0.04em;
}

#stats-bar {
  display: flex;
  align-items: center;
  gap: 22px;
}

.stat {
  display: flex;
  align-items: baseline;
  gap: 5px;
}

.stat span {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

.stat label {
  font-size: 0.65rem;
  letter-spacing: 0.08em;
  color: var(--dim);
  text-transform: uppercase;
}

#btn-reset {
  background: none;
  border: 1px solid var(--border);
  color: var(--dim);
  font-size: 1rem;
  width: 30px;
  height: 30px;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.15s, border-color 0.15s;
}
#btn-reset:hover { color: var(--text); border-color: var(--dim); }

/* ── Level strip: makes the unlock system visible ───────────────── */
#level-strip {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 0 0;
}

#level-num {
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--learning);
  white-space: nowrap;
}

#level-bar {
  flex: 1;
  height: 6px;
  border-radius: 3px;
  background: var(--surface);
  border: 1px solid var(--border);
  overflow: hidden;
}

#level-fill {
  height: 100%;
  width: 0;
  background: var(--learning);
  border-radius: 3px;
  transition: width 0.4s ease;
}

#level-next {
  font-size: 0.75rem;
  color: var(--dim);
  letter-spacing: 0.05em;
  white-space: nowrap;
}

#unlock-banner {
  padding-top: 8px;
  font-size: 0.8rem;
  color: var(--learning);
  letter-spacing: 0.05em;
  text-align: center;
  animation: fade-in 0.4s ease;
}
#unlock-banner.hidden { display: none; }

/* ── Trainer: meaning → cells → status ──────────────────────────── */
#trainer {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  padding: 24px 0;
}

#target-meaning {
  font-size: 0.9rem;
  color: var(--dim);
  letter-spacing: 0.04em;
  min-height: 1.2em;
}

#word-cells {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  justify-content: center;
}

.cell {
  width: 104px;
  height: 104px;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  transition: border-color 0.2s, box-shadow 0.4s;
  user-select: none;
}

.cell-char, .cell-ghost {
  font-size: 3.4rem;
  font-weight: 300;
  line-height: 1;
}
.cell-char  { color: var(--text); }
.cell-ghost { color: var(--dim); }

/* Small reminder of the target in the corner once you start composing */
.cell-mini {
  position: absolute;
  top: 6px;
  right: 9px;
  font-size: 0.85rem;
  color: var(--dim);
}

.cell-active { border-color: var(--accent); }
.cell-active::after {
  content: '';
  position: absolute;
  bottom: 10px;
  left: 50%;
  transform: translateX(-50%);
  width: 38%;
  height: 3px;
  border-radius: 2px;
  background: var(--accent);
  animation: caret-blink 1.1s steps(1) infinite;
}

.cell-correct { border-color: var(--correct); }
.cell-correct .cell-char { color: var(--correct); }

.cell-wrong { border-color: var(--wrong); }
.cell-wrong .cell-char { color: var(--wrong); }
.cell-wrong .cell-mini { color: var(--text); }

/* Submit feedback: brief glow on all cells */
#word-cells.flash-correct .cell { box-shadow: 0 0 16px rgba(184, 187, 38, 0.35); }
#word-cells.flash-wrong   .cell { box-shadow: 0 0 16px rgba(251, 73, 52, 0.35); }

@keyframes caret-blink {
  50% { opacity: 0; }
}

#status-line {
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  min-height: 1.4em;
}
#status-line.status-correct { color: var(--correct); }
#status-line.status-wrong   { color: var(--wrong); }

#hint {
  font-size: 0.72rem;
  color: var(--dim);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  transition: opacity 0.8s;
}
#hint.hint-faded { opacity: 0; }

@keyframes fade-in {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── On-screen keyboard ─────────────────────────────────────────── */
#progress-section {
  padding: 18px 0 22px;
  border-top: 1px solid var(--border);
}

#keyboard {
  display: flex;
  flex-direction: column;
  gap: 5px;
  align-items: center;
}

.kb-row {
  display: flex;
  gap: 5px;
}

.kb-key {
  width: 48px;
  height: 48px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  border-radius: 7px;
  background: var(--surface);
  border: 1px solid var(--border);
  cursor: default;
  transition: background 0.25s, border-color 0.25s, transform 0.08s;
  position: relative;
}

.kb-jamo {
  font-size: 1.25rem;
  font-weight: 600;
  line-height: 1;
}

.kb-latin {
  font-size: 0.55rem;
  color: var(--dim);
  letter-spacing: 0.05em;
}

.kb-key.locked   { background: var(--locked); border-color: var(--border); }
.kb-key.locked .kb-jamo  { color: var(--locked-fg); }
.kb-key.learning { border-color: var(--learning); }
.kb-key.learning .kb-jamo { color: var(--learning); }
.kb-key.mastered { border-color: var(--correct); }
.kb-key.mastered .kb-jamo { color: var(--correct); }

.kb-key.pressed {
  background: #3c3836;
  transform: translateY(2px);
}

/* Special & number keys — inert, dim, realistic widths */
.kb-special, .kb-num {
  background: var(--locked);
}

.kb-label {
  font-size: 0.7rem;
  color: var(--locked-fg);
  letter-spacing: 0.05em;
  text-transform: lowercase;
}

.kb-num .kb-label { font-size: 0.95rem; }

/* Key widths in keyboard units (1u = 48px, pitch = 53px): n·53 − 5 */
.kb-u125 { width: 61px; }
.kb-u15  { width: 74px; }
.kb-u175 { width: 88px; }
.kb-u2   { width: 101px; }
.kb-u225 { width: 114px; }
.kb-u275 { width: 141px; }
.kb-u625 { width: 326px; }

/* Toggle: hide Latin letters on keys */
#keyboard.hide-latin .kb-latin { display: none; }

/* Toggle: hide the whole keyboard graphic */
#progress-section.kb-hidden #keyboard,
#progress-section.kb-hidden #kb-legend { display: none; }

/* ── Keyboard footer: legend + display toggles ──────────────────── */
#kb-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 12px;
}

#kb-legend {
  display: flex;
  gap: 18px;
  font-size: 0.7rem;
  color: var(--dim);
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
}
.dot-mastered { background: var(--correct); }
.dot-learning { background: var(--learning); }
.dot-locked   { background: var(--locked-fg); }

#kb-toggles {
  display: flex;
  gap: 20px;
  font-size: 0.7rem;
  color: var(--dim);
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.kb-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  user-select: none;
}

.kb-toggle input {
  accent-color: var(--accent);
  cursor: pointer;
}
