* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: var(--body);
  line-height: 1.5;
}

button, input { font: inherit; color: inherit; }

button { cursor: pointer; }

h1, h2, h3, p { margin: 0; }

h1 { font-size: var(--h1); letter-spacing: -0.04em; line-height: 1.05; }
h2 { font-size: var(--h2); letter-spacing: -0.03em; line-height: 1.15; }
h3 { font-size: var(--h3); letter-spacing: -0.02em; }

:focus { outline: none; }
:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 3px;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 0.5rem 0.5rem;
  width: min(100% - 2rem, var(--max));
  margin: 0 auto;
  padding: 1rem 0 0.4rem;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  color: inherit;
  text-decoration: none;
  flex: 0 0 auto;
}

.brand img { display: none; }

.brand-symbol { height: 2.5rem; width: auto; }

.brand-word { height: 1.22rem; width: auto; }

html[data-theme="light"] .brand .theme-light,
html[data-theme="dark"] .brand .theme-dark { display: block; }

.nav {
  display: flex;
  gap: 0.1rem;
  flex: 0 1 auto;
  flex-wrap: nowrap;
  min-width: 0;
  margin-left: auto;
  margin-right: auto;
  padding: 0.15rem;
}

.nav button {
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
  min-height: 44px;
  flex: 0 0 auto;
  border: 1px solid transparent;
  background: transparent;
  border-radius: 999px;
  padding: 0.3rem 0.4rem;
  color: var(--muted);
  white-space: nowrap;
}

.nav button svg { width: 1rem; height: 1rem; }

.nav button:hover { color: var(--text); background: var(--muted-bg); }

.nav button.active,
.nav button[aria-current="page"] {
  background: var(--primary);
  color: var(--on-primary);
}

.header-controls {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  flex: 0 0 auto;
}

.icon-btn, .btn, .choice, .profile-switch button, .seg button {
  min-height: 44px;
  min-width: 44px;
}

.icon-btn {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 999px;
  display: grid;
  place-items: center;
  padding: 0 0.7rem;
}

.icon-btn svg { width: 1.15rem; height: 1.15rem; }

.profile-switch, .seg {
  display: inline-flex;
  padding: 0.2rem;
  border-radius: 999px;
  background: var(--muted-bg);
  border: 1px solid var(--border);
}

.profile-switch button, .seg button, .choice {
  border: 0;
  background: transparent;
  border-radius: 999px;
  padding: 0.35rem 0.85rem;
  color: var(--muted);
}

.profile-switch button { padding-inline: 0.55rem; }

.profile-switch button.active,
.profile-switch button[aria-pressed="true"],
.seg button[aria-pressed="true"],
.choice.active,
.choice[aria-pressed="true"] {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}

html[data-mode="child"] #profile-child[aria-pressed="true"],
html[data-mode="child"] #profile-child.active {
  background: var(--orange, #ff8734);
  color: #1a1208;
}

.lang-switch button {
  min-height: 32px;
  min-width: 0;
  padding: 0.15rem 0.6rem;
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.04em;
}

main {
  width: min(100% - 2rem, var(--max));
  margin: 0 auto;
  padding: 0.85rem 0 2.5rem;
}

.card, .lesson-card, .result, .tl-card, .feature, .widget {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.card, .result { padding: var(--space-4); }

.btn {
  border: 0;
  border-radius: 999px;
  background: var(--primary);
  color: var(--on-primary);
  padding: 0.65rem 1.15rem;
  font-weight: 700;
  transition: background 150ms ease, transform 150ms ease;
}

.btn:hover { background: var(--primary-hover); }

.btn.secondary, .choice {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn.secondary:hover, .choice:hover { background: var(--muted-bg); }

.btn-row, .choice-row, .page-head, .metrics {
  display: flex;
  gap: var(--space-2);
  flex-wrap: wrap;
  align-items: center;
}

.btn-row, .choice-row { margin: var(--space-3) 0; }

.lead, .muted, .legend, .lesson-meta, .seed-line { color: var(--muted); }
.lead { margin: 0.4rem 0 var(--space-3); max-width: 40rem; }

.eyebrow {
  font-size: var(--meta);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 0.35rem;
}

.progress-bar {
  display: block;
  height: 0.55rem;
  background: var(--muted-bg);
  border-radius: 999px;
  overflow: hidden;
}

.progress-bar > span,
.progress-bar > div,
.rhythm-fill {
  display: block;
  height: 100%;
  width: 0;
  background: var(--primary);
  border-radius: inherit;
}

.metrics {
  margin: 0 0 0.6rem;
  color: var(--muted);
  font-size: var(--meta);
}

.metrics strong, .stat-value {
  color: var(--text);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.03em;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: var(--space-3);
  margin: var(--space-3) 0;
}

.stat {
  background: var(--elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.9rem 1rem;
}

.stat-label, .legend { display: block; font-size: var(--meta); color: var(--muted); }
.stat-value { font-size: 1.6rem; display: block; }
.stat-unit { color: var(--muted); font-size: var(--meta); }

.typing-wrap { position: relative; }

.typing-area {
  font-family: var(--mono);
  font-size: 1.35rem;
  line-height: 1.6;
  max-width: var(--practice-w);
  min-height: 7.5rem;
  padding: 1rem 1.1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

html[data-mode="child"] .typing-area { font-size: 1.55rem; }

.typing-area.is-wrong { box-shadow: inset 0 0 0 2px var(--error); }

.char.ok { color: var(--typed); }
.char.pending { color: var(--text); }
.char.bad, .char.is-wrong {
  color: var(--error);
  text-decoration: underline;
  text-underline-offset: 0.18em;
}
.char.is-space.bad, .char.is-space.is-wrong {
  background: color-mix(in srgb, var(--error) 22%, transparent);
  border-radius: 0.2rem;
}

.caret {
  display: inline-block;
  width: 2px;
  height: 1.15em;
  background: var(--primary);
  margin-right: -2px;
  vertical-align: text-bottom;
  animation: blink 1s steps(1) infinite;
}

.input-capture {
  position: absolute;
  opacity: 0;
  pointer-events: none;
  width: 1px;
  height: 1px;
}

.focus-hint {
  position: absolute;
  inset: auto 1rem 1rem auto;
  border: 0;
  border-radius: 999px;
  background: var(--text);
  color: var(--bg);
  min-height: 44px;
  padding: 0.4rem 0.9rem;
}

.finger-hint { color: var(--muted); margin: 0.35rem 0; }
.finger-hint:empty { display: none; }

.layout-banner {
  background: color-mix(in srgb, var(--warning) 16%, var(--surface));
  border: 1px solid var(--warning);
  border-radius: var(--radius-sm);
  padding: 0.7rem 0.9rem;
  margin-bottom: 0.7rem;
}

.keyboard { margin: 0.8rem 0; user-select: none; max-width: var(--practice-w); }
.practice-progress, .practice-main .metrics { max-width: var(--practice-w); }
.practice-progress { margin-bottom: 0.6rem; }
.key-row { display: flex; gap: 0.35rem; margin-bottom: 0.35rem; }
.key {
  flex: 1;
  min-width: 0;
  min-height: 2.5rem;
  display: grid;
  place-items: center;
  position: relative;
  background: var(--key-bg);
  color: var(--key-text);
  border: 1px solid var(--border);
  border-bottom-width: 3px;
  border-radius: 0.55rem;
  font-size: 0.92rem;
  box-shadow: inset 0 3px 0 var(--finger, transparent);
}
.key.grow-2 { flex-grow: 1.7; }
.key.grow-6 { flex-grow: 6; }
.f-lp { --finger: var(--finger-lp); }
.f-lr { --finger: var(--finger-lr); }
.f-lm { --finger: var(--finger-lm); }
.f-li { --finger: var(--finger-li); }
.f-ri { --finger: var(--finger-ri); }
.f-rm { --finger: var(--finger-rm); }
.f-rr { --finger: var(--finger-rr); }
.f-rp { --finger: var(--finger-rp); }
.f-th { --finger: var(--finger-th); }
.key.is-next { outline: 2px solid var(--primary); outline-offset: 1px; }
.key.is-bad { box-shadow: inset 0 0 0 2px var(--error); }
.key.has-heat { background: color-mix(in srgb, var(--heat) calc(var(--heat) * 55%), var(--key-bg)); }
.bump {
  position: absolute;
  bottom: 0.28rem;
  width: 0.55rem;
  height: 0.18rem;
  border-radius: 99px;
  background: var(--muted);
}

.stars { display: inline-flex; gap: 0.15rem; color: var(--border); }
.stars svg { width: 1rem; height: 1rem; }
.stars .is-on { color: var(--warning); }
.badge-icon, .lock { display: inline-grid; }
.badge-icon svg, .lock svg { width: 1.25rem; height: 1.25rem; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 1.2rem;
  transform: translate(-50%, 0.6rem);
  background: var(--text);
  color: var(--bg);
  border-radius: 999px;
  padding: 0.7rem 1rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 200ms ease, transform 200ms ease;
  z-index: 20;
}
.toast.is-on { opacity: 1; transform: translate(-50%, 0); }

.confirm-dialog {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  padding: 1.4rem;
  width: min(26rem, calc(100% - 2rem));
  box-shadow: var(--shadow);
}
.confirm-dialog::backdrop { background: rgba(8, 10, 16, 0.48); }

.mascot {
  display: block;
  width: 220px;
  height: 220px;
  max-width: 100%;
  object-fit: cover;
  border-radius: 1.4rem;
}

.mascot-rail {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.6rem;
  width: 180px;
}
.mascot-rail p, #character-message {
  margin: 0;
  text-align: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.7rem 0.8rem;
}

.practice-layout { display: flex; gap: 1.2rem; align-items: flex-start; }
.practice-main { flex: 1; min-width: 0; }

.hidden, [hidden] { display: none !important; }

.empty {
  text-align: center;
  padding: 2rem 1rem;
}
.empty svg { width: 2rem; height: 2rem; margin-bottom: 0.6rem; }

.timer-ring {
  position: relative;
  width: 4.6rem;
  height: 4.6rem;
  display: grid;
  place-items: center;
}
.timer-ring svg { position: absolute; inset: 0; width: 100%; height: 100%; transform: rotate(-90deg); }
.timer-ring circle { fill: none; stroke-width: 6; }
.ring-bg { stroke: var(--muted-bg); }
.ring-fg {
  stroke: var(--primary);
  stroke-linecap: round;
  stroke-dasharray: 188;
  stroke-dashoffset: calc(188 - (188 * var(--p, 100) / 100));
}

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

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation: none !important;
    transition: none !important;
    scroll-behavior: auto !important;
  }
}
