/* 字速 · Chinese Typing Speed Test
   Dark ink desk + cinnabar accent
*/

:root {
  --bg: #0c0e12;
  --bg-elev: #141820;
  --surface: #1a1f2a;
  --surface-2: #222836;
  --line: rgba(255, 255, 255, 0.08);
  --line-strong: rgba(255, 255, 255, 0.14);
  --ink: #eef1f6;
  --ink-dim: #9aa3b5;
  --ink-mute: #6b7488;
  --accent: #e85d3b;
  --accent-soft: rgba(232, 93, 59, 0.16);
  --accent-glow: rgba(232, 93, 59, 0.35);
  --ok: #3ecf8e;
  --ok-soft: rgba(62, 207, 142, 0.18);
  --bad: #f07178;
  --bad-soft: rgba(240, 113, 120, 0.18);
  --caret: #e85d3b;
  --radius: 14px;
  --radius-sm: 10px;
  --radius-pill: 999px;
  --font-sans: "Noto Sans TC", system-ui, -apple-system, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, monospace;
  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
  --ease-io: cubic-bezier(0.77, 0, 0.175, 1);
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
  --z-bg: 0;
  --z-app: 1;
  --z-header: 10;
}

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  color-scheme: dark;
  -webkit-text-size-adjust: 100%;
}

body {
  min-height: 100dvh;
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--ink);
  line-height: 1.6;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

/* Three.js + grain + vignette */
#webgl-root {
  position: fixed;
  inset: 0;
  z-index: var(--z-bg);
  pointer-events: none;
}

#webgl-root canvas,
#webgl-canvas {
  display: block;
  width: 100% !important;
  height: 100% !important;
}

.grain {
  position: fixed;
  inset: 0;
  z-index: calc(var(--z-bg) + 1);
  pointer-events: none;
  opacity: 0.045;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  background-size: 180px;
}

.vignette {
  position: fixed;
  inset: 0;
  z-index: calc(var(--z-bg) + 1);
  pointer-events: none;
  background: radial-gradient(
    ellipse 75% 70% at 50% 45%,
    transparent 0%,
    transparent 42%,
    rgba(8, 10, 14, 0.45) 75%,
    rgba(8, 10, 14, 0.78) 100%
  );
}

/* Countdown overlay */
.countdown {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  background: rgba(8, 10, 14, 0.72);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.countdown[hidden] {
  display: none;
}

.countdown-num {
  font-family: var(--font-mono);
  font-size: clamp(5rem, 18vw, 8rem);
  font-weight: 700;
  color: var(--accent);
  text-shadow: 0 0 60px var(--accent-glow);
  animation: count-pop 0.75s var(--ease-out) both;
  line-height: 1;
}

.countdown-num.is-go {
  font-size: clamp(3.5rem, 14vw, 6rem);
  letter-spacing: 0.08em;
}

@keyframes count-pop {
  0% {
    opacity: 0;
    transform: scale(0.55);
    filter: blur(8px);
  }
  55% {
    opacity: 1;
    transform: scale(1.08);
    filter: blur(0);
  }
  100% {
    opacity: 1;
    transform: scale(1);
  }
}

/* Floating FX layer — typing feedback only (above UI, never WebGL) */
.fx-layer {
  position: fixed;
  inset: 0;
  z-index: 40;
  pointer-events: none;
  overflow: hidden;
}

.fx-pop {
  position: fixed;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  font-weight: 600;
  pointer-events: none;
  animation: fx-float 0.7s var(--ease-out) forwards;
  color: var(--ok);
  text-shadow: 0 0 12px rgba(62, 207, 142, 0.5);
  z-index: 2;
}

.fx-pop.is-bad {
  color: var(--bad);
  text-shadow: 0 0 12px rgba(240, 113, 120, 0.45);
}

.fx-ring {
  position: fixed;
  width: 12px;
  height: 12px;
  margin: -6px 0 0 -6px;
  border-radius: 50%;
  border: 2px solid rgba(62, 207, 142, 0.75);
  pointer-events: none;
  animation: fx-ring 0.48s var(--ease-out) forwards;
  z-index: 1;
  box-shadow: 0 0 12px rgba(62, 207, 142, 0.35);
}

.fx-ring.is-bad {
  border-color: rgba(240, 113, 120, 0.8);
  box-shadow: 0 0 12px rgba(240, 113, 120, 0.35);
}

.fx-spark {
  position: fixed;
  width: 4px;
  height: 4px;
  margin: -2px 0 0 -2px;
  border-radius: 50%;
  background: #7dffc0;
  box-shadow: 0 0 8px rgba(62, 207, 142, 0.7);
  pointer-events: none;
  animation: fx-spark 0.55s var(--ease-out) forwards;
  z-index: 1;
}

.fx-spark.is-bad {
  background: #f07178;
  box-shadow: 0 0 8px rgba(240, 113, 120, 0.65);
}

@keyframes fx-float {
  0% {
    opacity: 0;
    transform: translate(-50%, 0) scale(0.7);
  }
  20% {
    opacity: 1;
    transform: translate(-50%, -6px) scale(1.05);
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -36px) scale(0.9);
  }
}

@keyframes fx-ring {
  0% {
    opacity: 0.9;
    transform: scale(0.35);
  }
  100% {
    opacity: 0;
    transform: scale(2.4);
  }
}

@keyframes fx-spark {
  0% {
    opacity: 1;
    transform: translate(0, 0) scale(1);
  }
  100% {
    opacity: 0;
    transform: translate(var(--dx, 0), var(--dy, -20px)) scale(0.2);
  }
}

.app {
  position: relative;
  z-index: var(--z-app);
  max-width: 1200px;
  margin: 0 auto;
  min-height: 100dvh;
  padding: 1.25rem 1.25rem 2rem;
  display: flex;
  flex-direction: column;
}

/* Soft glass on secondary surfaces (passage uses stronger fill) */
.live-bar,
.detail-card,
.hero-wpm,
.hero-ring-card,
.stat-chip,
.chart-stage,
.rank-block {
  backdrop-filter: blur(12px) saturate(1.15);
  -webkit-backdrop-filter: blur(12px) saturate(1.15);
}

/* Header */
.header {
  position: sticky;
  top: 0;
  z-index: var(--z-header);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.65rem 0 1rem;
  margin-bottom: 0.5rem;
  background: linear-gradient(to bottom, var(--bg) 70%, transparent);
}

.header-right {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.lang-switch {
  display: inline-flex;
  padding: 0.15rem;
  background: rgba(26, 31, 42, 0.85);
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  gap: 0.1rem;
}

.lang-btn {
  font-family: inherit;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--ink-mute);
  background: transparent;
  border: none;
  border-radius: var(--radius-pill);
  padding: 0.35rem 0.65rem;
  cursor: pointer;
  transition: color 0.15s var(--ease-out), background 0.15s var(--ease-out);
}

.lang-btn.is-active {
  color: var(--ink);
  background: var(--accent-soft);
}

.lang-btn:active {
  transform: scale(0.97);
}

/* EDM music toggle */
.music-btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.3rem;
  width: 2.35rem;
  height: 2.1rem;
  padding: 0;
  border-radius: var(--radius-pill);
  border: 1px solid var(--line);
  background: rgba(26, 31, 42, 0.88);
  color: var(--ink-mute);
  cursor: pointer;
  transition: color 0.18s var(--ease-out), border-color 0.18s var(--ease-out),
    background 0.18s var(--ease-out), box-shadow 0.18s var(--ease-out), transform 0.12s var(--ease-out);
}

.music-btn:hover {
  color: var(--ink);
  border-color: var(--line-strong);
}

.music-btn:active {
  transform: scale(0.96);
}

.music-btn.is-on {
  color: var(--accent);
  border-color: rgba(232, 93, 59, 0.4);
  background: rgba(232, 93, 59, 0.1);
}

.music-btn.is-on.is-playing {
  box-shadow: 0 0 0 1px rgba(232, 93, 59, 0.18), 0 0 18px rgba(232, 93, 59, 0.2);
}

.music-btn.is-off {
  color: var(--ink-mute);
  opacity: 0.85;
}

.music-ico {
  display: grid;
  place-items: center;
  line-height: 0;
}

.music-btn .ico-off {
  display: none;
}

.music-btn.is-off .ico-on {
  display: none;
}

.music-btn.is-off .ico-off {
  display: block;
}

.music-btn.is-off .music-eq {
  display: none;
}

.music-eq {
  display: none;
  align-items: flex-end;
  gap: 2px;
  height: 12px;
}

.music-btn.is-on.is-playing .music-eq {
  display: inline-flex;
}

.music-eq i {
  display: block;
  width: 2px;
  height: 100%;
  border-radius: 1px;
  background: currentColor;
  transform-origin: bottom center;
  animation: eq-bounce 0.55s ease-in-out infinite;
}

.music-eq i:nth-child(1) { animation-delay: 0s; height: 55%; }
.music-eq i:nth-child(2) { animation-delay: 0.12s; height: 100%; }
.music-eq i:nth-child(3) { animation-delay: 0.22s; height: 70%; }

@keyframes eq-bounce {
  0%, 100% { transform: scaleY(0.45); }
  50% { transform: scaleY(1); }
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.brand-mark {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  background: var(--accent);
  box-shadow: 0 0 18px var(--accent-glow);
  animation: mark-pulse 3.2s var(--ease-io) infinite;
}

@keyframes mark-pulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(0.88); opacity: 0.75; }
}

.brand-name {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: 0.12em;
}

.header-stats {
  display: flex;
  gap: 0.4rem;
}

.stat-chip {
  display: flex;
  align-items: baseline;
  gap: 0.25rem;
  padding: 0.35rem 0.7rem;
  background: rgba(26, 31, 42, 0.72);
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  font-variant-numeric: tabular-nums;
  transition: transform 0.2s var(--ease-out), border-color 0.2s ease;
}

.stat-num {
  font-family: var(--font-mono);
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--ink);
}

.stat-unit {
  font-size: 0.7rem;
  color: var(--ink-mute);
}

.timer-chip .stat-num {
  color: var(--accent);
  transition: color 0.2s ease, transform 0.2s var(--ease-out);
}

.timer-chip.is-urgent {
  border-color: rgba(232, 93, 59, 0.55);
  box-shadow: 0 0 0 3px var(--accent-soft);
  animation: urgent-pulse 0.9s ease-in-out infinite;
}

.timer-chip.is-urgent .stat-num {
  color: #ff7a55;
}

@keyframes urgent-pulse {
  0%, 100% { box-shadow: 0 0 0 2px var(--accent-soft); }
  50% { box-shadow: 0 0 0 5px rgba(232, 93, 59, 0.12); }
}

.stat-chip.is-flash {
  transform: scale(1.06);
  border-color: rgba(232, 93, 59, 0.4);
}

/* Main panels */
.main {
  flex: 1;
  display: grid;
  place-items: center;
  position: relative;
}

.panel {
  width: 100%;
  animation: panel-in 0.5s var(--ease-out) both;
}

.panel.is-hidden {
  display: none;
}

@keyframes panel-in {
  from {
    opacity: 0;
    transform: translateY(16px) scale(0.985);
    filter: blur(4px);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
    filter: blur(0);
  }
}

/* Staggered idle entrance */
.anim-rise {
  animation: rise-in 0.55s calc(var(--d, 0) * 70ms) var(--ease-out) both;
}

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

/* Idle */
.idle-inner {
  position: relative;
  z-index: 1;
  text-align: left;
  max-width: 42rem;
  padding: 1.5rem 0 2rem;
}

.idle-kicker {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--accent);
  letter-spacing: 0.06em;
  margin-bottom: 0.85rem;
}

.idle-title {
  font-size: clamp(2.1rem, 6vw, 3.25rem);
  font-weight: 900;
  line-height: 1.15;
  letter-spacing: -0.02em;
  text-wrap: balance;
  margin-bottom: 1rem;
}

.idle-title em,
.idle-title .title-em {
  font-style: normal;
  color: var(--accent);
  display: inline-block;
  position: relative;
  animation: em-glow 3.2s var(--ease-io) infinite;
}

@keyframes em-glow {
  0%, 100% { text-shadow: 0 0 0 transparent; }
  50% { text-shadow: 0 0 28px var(--accent-glow); }
}

.idle-desc {
  color: var(--ink-dim);
  font-size: 1rem;
  max-width: 36ch;
  margin-bottom: 1.75rem;
  text-wrap: pretty;
}

.mode-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin-bottom: 1.5rem;
}

.mode-btn {
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--ink-dim);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  padding: 0.5rem 0.95rem;
  cursor: pointer;
  transition: color 0.18s var(--ease-out), background 0.18s var(--ease-out), border-color 0.18s var(--ease-out), transform 0.18s var(--ease-out), box-shadow 0.18s var(--ease-out);
}

.mode-btn:hover {
  color: var(--ink);
  border-color: var(--line-strong);
  transform: translateY(-1px);
}

.mode-btn.is-active {
  color: var(--ink);
  background: var(--accent-soft);
  border-color: rgba(232, 93, 59, 0.45);
  box-shadow: 0 0 0 3px rgba(232, 93, 59, 0.1);
  animation: mode-select 0.35s var(--ease-out);
}

@keyframes mode-select {
  0% { transform: scale(0.94); }
  60% { transform: scale(1.04); }
  100% { transform: scale(1); }
}

.mode-btn:active,
.btn-primary:active,
.btn-ghost:active {
  transform: scale(0.97);
}

.btn-primary {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  font-family: inherit;
  font-size: 1rem;
  font-weight: 600;
  color: #1a0f0c;
  background: var(--accent);
  border: none;
  border-radius: var(--radius-pill);
  padding: 0.85rem 1.6rem;
  cursor: pointer;
  overflow: hidden;
  isolation: isolate;
  transition: transform 0.12s var(--ease-out), box-shadow 0.2s var(--ease-out), filter 0.2s var(--ease-out);
  box-shadow: 0 8px 24px var(--accent-glow);
}

.btn-shine {
  position: absolute;
  inset: 0;
  background: linear-gradient(105deg, transparent 40%, rgba(255, 255, 255, 0.35) 50%, transparent 60%);
  transform: translateX(-120%);
  animation: shine-sweep 3.5s ease-in-out infinite;
  pointer-events: none;
  z-index: 0;
}

@keyframes shine-sweep {
  0%, 55% { transform: translateX(-120%); }
  75%, 100% { transform: translateX(120%); }
}

.btn-primary > *:not(.btn-shine) {
  position: relative;
  z-index: 1;
}

.btn-primary:hover {
  filter: brightness(1.06);
  box-shadow: 0 10px 28px var(--accent-glow);
}

.btn-arrow {
  display: grid;
  place-items: center;
  transition: transform 0.2s var(--ease-out);
}

.btn-primary:hover .btn-arrow {
  transform: translateX(3px);
}

.btn-ghost {
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--ink-dim);
  background: transparent;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-pill);
  padding: 0.8rem 1.35rem;
  cursor: pointer;
  transition: color 0.18s var(--ease-out), border-color 0.18s var(--ease-out), transform 0.12s var(--ease-out);
}

.btn-ghost:hover {
  color: var(--ink);
  border-color: var(--ink-mute);
}

/* Test */
.test-shell {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  padding: 0.5rem 0 1rem;
}

.progress-track {
  position: relative;
  height: 5px;
  background: var(--surface);
  border-radius: var(--radius-pill);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, var(--accent), #f0a060, var(--accent));
  background-size: 200% 100%;
  border-radius: inherit;
  transform-origin: left center;
  transition: transform 0.2s linear;
  animation: progress-shimmer 2.4s linear infinite;
}

.progress-glow {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 24px;
  right: 0;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.45));
  opacity: 0.6;
  pointer-events: none;
  transform: translateX(0);
  transition: transform 0.2s linear;
  mix-blend-mode: screen;
}

@keyframes progress-shimmer {
  0% { background-position: 100% 0; }
  100% { background-position: -100% 0; }
}

.progress-track.is-low .progress-fill {
  background: linear-gradient(90deg, #f07178, #e85d3b, #f07178);
  background-size: 200% 100%;
}

.passage-wrap {
  background: rgba(16, 19, 26, 0.96);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.5rem 1.35rem;
  min-height: 11rem;
  max-height: min(42vh, 280px);
  overflow-y: auto;
  box-shadow: var(--shadow);
  /* Custom rAF ease handles auto-scroll; keep native wheel snappy */
  scroll-behavior: auto;
  transition: border-color 0.25s var(--ease-out), box-shadow 0.25s var(--ease-out);
  animation: shell-in 0.45s 0.05s var(--ease-out) both;
  backdrop-filter: blur(16px) saturate(1.1);
  -webkit-backdrop-filter: blur(16px) saturate(1.1);
  /* Soft edge fade so pushed lines feel gentler leaving the top */
  -webkit-mask-image: linear-gradient(
    to bottom,
    transparent 0,
    #000 0.65rem,
    #000 calc(100% - 0.65rem),
    transparent 100%
  );
  mask-image: linear-gradient(
    to bottom,
    transparent 0,
    #000 0.65rem,
    #000 calc(100% - 0.65rem),
    transparent 100%
  );
}

.passage-wrap.is-active {
  border-color: rgba(232, 93, 59, 0.35);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35), 0 0 0 1px rgba(232, 93, 59, 0.12), 0 0 40px rgba(232, 93, 59, 0.08);
}

.passage-wrap.is-shake {
  animation: wrap-shake 0.35s var(--ease-out);
}

@keyframes wrap-shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-4px); }
  40% { transform: translateX(4px); }
  60% { transform: translateX(-3px); }
  80% { transform: translateX(2px); }
}

@keyframes shell-in {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.passage {
  font-size: clamp(1.2rem, 2.6vw, 1.45rem);
  line-height: 2;
  letter-spacing: 0.04em;
  word-break: break-all;
  font-weight: 400;
  user-select: none;
  white-space: pre-wrap;
}

.char {
  position: relative;
  border-radius: 3px;
  transition: color 0.12s ease, background 0.12s ease, transform 0.15s var(--ease-out);
  display: inline-block;
}

/* Space slots keep width; no special background color */
.char.is-space {
  min-width: 0.55em;
  margin: 0 0.02em;
}

.char.is-pending {
  color: var(--ink-mute);
}

.char.is-correct {
  color: var(--ok);
}

.char.is-correct.just-hit,
.char.just-hit-ok {
  animation: char-ok 0.3s var(--ease-out);
}

.char.is-wrong {
  color: var(--bad);
  background: var(--bad-soft);
}

.char.is-wrong.just-hit,
.char.just-hit-bad {
  animation: char-bad 0.34s var(--ease-out);
}

.char.is-current {
  color: var(--ink);
  background: var(--accent-soft);
  animation: current-breathe 1.4s ease-in-out infinite;
}

.char.is-current::after {
  content: "";
  position: absolute;
  left: 0;
  bottom: 0.1em;
  width: 100%;
  height: 2px;
  background: var(--caret);
  border-radius: 1px;
  animation: caret-blink 1s steps(1) infinite;
}

@keyframes char-ok {
  0% { transform: scale(1); filter: brightness(1); }
  35% { transform: scale(1.22); color: #7dffc0; filter: brightness(1.25); }
  100% { transform: scale(1); filter: brightness(1); }
}

@keyframes char-bad {
  0%, 100% { transform: translateX(0) scale(1); }
  20% { transform: translateX(-3px) scale(1.1); }
  45% { transform: translateX(3px) scale(1.08); }
  70% { transform: translateX(-2px) scale(1.04); }
}

@keyframes current-breathe {
  0%, 100% { background: var(--accent-soft); }
  50% { background: rgba(232, 93, 59, 0.28); }
}

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

/* Input field typing pulse */
.typing-input.is-hit-ok {
  animation: input-ok 0.22s var(--ease-out);
}

.typing-input.is-hit-bad {
  animation: input-bad 0.24s var(--ease-out);
}

@keyframes input-ok {
  0% { box-shadow: 0 0 0 3px var(--accent-soft); }
  40% { box-shadow: 0 0 0 3px rgba(62, 207, 142, 0.35), 0 0 18px rgba(62, 207, 142, 0.2); border-color: rgba(62, 207, 142, 0.55); }
  100% { box-shadow: 0 0 0 3px var(--accent-soft); }
}

@keyframes input-bad {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-2px); box-shadow: 0 0 0 3px rgba(240, 113, 120, 0.28); border-color: rgba(240, 113, 120, 0.55); }
  55% { transform: translateX(2px); }
}

/* IME practice hint panel */
.hint-toggle-row {
  margin: 0 0 1.25rem;
}

.hint-toggle {
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--ink-dim);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  padding: 0.5rem 1rem;
  cursor: pointer;
  transition: color 0.18s var(--ease-out), background 0.18s var(--ease-out), border-color 0.18s var(--ease-out);
}

.hint-toggle.is-on {
  color: var(--ink);
  background: var(--accent-soft);
  border-color: rgba(232, 93, 59, 0.45);
}

.hint-panel {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 1rem 1.25rem;
  align-items: center;
  padding: 0.95rem 1.1rem;
  background: rgba(16, 19, 26, 0.96);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  animation: shell-in 0.4s 0.08s var(--ease-out) both;
}

.hint-panel.is-off {
  display: none;
}

.hint-char-block {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.2rem;
  min-width: 4.5rem;
  padding-right: 1rem;
  border-right: 1px solid var(--line);
}

.hint-label {
  font-size: 0.7rem;
  color: var(--ink-mute);
}

.hint-char {
  font-size: clamp(2.4rem, 6vw, 3.2rem);
  font-weight: 700;
  line-height: 1.1;
  color: var(--ink);
  min-height: 1.15em;
  transition: transform 0.2s var(--ease-out), color 0.2s ease;
}

.hint-char.is-pop {
  transform: scale(1.12);
  color: var(--accent);
}

.hint-progress {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--ink-mute);
  font-variant-numeric: tabular-nums;
}

.hint-methods {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  min-width: 0;
}

.hint-row {
  display: grid;
  grid-template-columns: 3.4rem 1fr auto;
  gap: 0.55rem;
  align-items: center;
  min-height: 1.7rem;
}

.hint-row[data-method="stroke"] {
  grid-template-columns: 3.4rem 1fr;
  align-items: start;
}

.hint-tag {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--accent);
  letter-spacing: 0.04em;
}

.hint-rad {
  font-size: clamp(0.95rem, 2.2vw, 1.15rem);
  font-weight: 600;
  color: var(--ink);
  letter-spacing: 0.12em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.hint-stroke-block {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  min-width: 0;
}

.hint-row[data-method="stroke"] .hint-rad {
  letter-spacing: 0.14em;
  font-weight: 600;
  white-space: normal;
  line-height: 1.35;
}

.hint-nums {
  font-family: var(--font-mono);
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--accent);
  letter-spacing: 0.18em;
  font-variant-numeric: tabular-nums;
}

.hint-code {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--ink-mute);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.hint-row[data-method="stroke"] .hint-code {
  display: none;
}

.hint-legend {
  margin-top: 0.15rem;
  font-size: 0.7rem;
  color: var(--ink-mute);
  letter-spacing: 0.02em;
}

.hint-row.is-empty .hint-rad,
.hint-row.is-empty .hint-code,
.hint-row.is-empty .hint-nums {
  color: var(--ink-mute);
  font-weight: 400;
  letter-spacing: 0;
}

/* English mode: calm base text + DOM typing motion (no IME, no WebGL coupling) */
html[lang="en"] .passage {
  letter-spacing: 0.01em;
  word-break: normal;
  overflow-wrap: break-word;
  line-height: 1.85;
  white-space: pre-wrap;
  color: var(--ink-dim);
}

html[lang="en"] .passage .char,
html[lang="en"] .passage .char.is-pending {
  color: var(--ink-mute) !important;
  background: transparent !important;
  box-shadow: none !important;
  border-radius: 2px;
}

/* Typed progress: slightly brighter, not full Chinese green flood */
html[lang="en"] .passage .char.is-correct {
  color: var(--ink) !important;
  background: transparent !important;
}

html[lang="en"] .passage .char.is-wrong {
  color: var(--bad) !important;
  background: transparent !important;
}

html[lang="en"] .passage .char.is-current {
  color: var(--ink) !important;
  background: rgba(232, 93, 59, 0.12) !important;
  animation: current-breathe 1.4s ease-in-out infinite !important;
}

html[lang="en"] .passage .char.is-current::after {
  display: block !important;
}

/* Hit pops allowed in English */
html[lang="en"] .passage .char.just-hit-ok,
html[lang="en"] .passage .char.is-correct.just-hit {
  animation: char-ok 0.3s var(--ease-out) !important;
}

html[lang="en"] .passage .char.just-hit-bad,
html[lang="en"] .passage .char.is-wrong.just-hit {
  animation: char-bad 0.34s var(--ease-out) !important;
}

/* Spaces are plain text nodes — no box UI */
html[lang="en"] .hint-toggle-row,
html[lang="en"] .hint-panel {
  display: none !important;
}

@media (max-width: 640px) {
  .hint-panel {
    grid-template-columns: 1fr;
    gap: 0.75rem;
  }

  .hint-char-block {
    flex-direction: row;
    justify-content: flex-start;
    gap: 0.75rem;
    padding-right: 0;
    padding-bottom: 0.65rem;
    border-right: none;
    border-bottom: 1px solid var(--line);
    min-width: 0;
  }

  .hint-char {
    font-size: 2.1rem;
  }

  .hint-row {
    grid-template-columns: 2.8rem 1fr;
  }

  .hint-row:not([data-method="stroke"]) .hint-code {
    grid-column: 2;
    justify-self: start;
  }
}

.input-wrap {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  /* Keep above soft UI chrome; mobile keyboard handled below */
  position: relative;
  z-index: 5;
}

.typing-input {
  width: 100%;
  min-height: 3.25rem;
  font-family: var(--font-sans);
  /* ≥16px avoids iOS focus zoom */
  font-size: max(1.15rem, 16px);
  line-height: 1.7;
  color: var(--ink);
  background: rgba(22, 26, 36, 0.96);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  padding: 0.9rem 1rem;
  resize: none;
  outline: none;
  /* Comfortable touch target */
  touch-action: manipulation;
  -webkit-appearance: none;
  appearance: none;
  transition: border-color 0.18s var(--ease-out), box-shadow 0.18s var(--ease-out);
}

.typing-input::placeholder {
  color: var(--ink-mute);
}

.typing-input:focus {
  border-color: rgba(232, 93, 59, 0.55);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.typing-input:disabled {
  opacity: 0.65;
  cursor: not-allowed;
}

.input-tip {
  font-size: 0.8rem;
  color: var(--ink-mute);
  transition: opacity 0.25s var(--ease-out);
}

.input-tip.is-gone {
  opacity: 0;
}

.live-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.25rem;
  flex-wrap: wrap;
  padding: 0.85rem 1rem;
  background: rgba(26, 31, 42, 0.7);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  animation: shell-in 0.45s 0.12s var(--ease-out) both;
}

.test-actions {
  display: flex;
  justify-content: center;
  padding-top: 0.15rem;
  animation: shell-in 0.45s 0.18s var(--ease-out) both;
}

.btn-stop {
  min-width: 8.5rem;
  padding: 0.65rem 1.25rem;
  font-size: 0.88rem;
  color: var(--ink-mute);
  border-color: var(--line);
}

.btn-stop:hover {
  color: var(--bad);
  border-color: rgba(240, 113, 120, 0.45);
  background: rgba(240, 113, 120, 0.08);
}

.live-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 5.5rem;
  padding: 0.25rem 0.75rem;
}

.live-val {
  font-family: var(--font-mono);
  font-size: 1.35rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
  transition: color 0.2s ease, transform 0.2s var(--ease-out);
}

.live-val.is-tick {
  transform: scale(1.06);
  color: var(--accent);
}

.live-lab {
  font-size: 0.72rem;
  color: var(--ink-mute);
  margin-top: 0.1rem;
}

.live-sep {
  width: 1px;
  height: 2rem;
  background: var(--line-strong);
}

/* Result */
.result-shell {
  position: relative;
  width: 100%;
  max-width: 40rem;
  margin: 0 auto;
  padding: 0.5rem 0 1.5rem;
  text-align: center;
}

.confetti {
  position: absolute;
  inset: -1.5rem -1rem auto;
  height: 10rem;
  pointer-events: none;
  overflow: hidden;
  z-index: 2;
}

.confetti i {
  position: absolute;
  top: -8px;
  width: 6px;
  height: 10px;
  border-radius: 1px;
  opacity: 0;
  animation: confetti-fall 1.8s var(--ease-out) forwards;
}

@keyframes confetti-fall {
  0% {
    opacity: 1;
    transform: translateY(0) rotate(0deg);
  }
  100% {
    opacity: 0;
    transform: translateY(140px) rotate(480deg);
  }
}

.result-head {
  margin-bottom: 1.15rem;
  animation: fade-up 0.45s var(--ease-out) both;
}

.result-kicker {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--accent);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  margin-bottom: 0.35rem;
}

.result-title {
  font-size: clamp(1.7rem, 4.2vw, 2.2rem);
  font-weight: 800;
  letter-spacing: -0.02em;
  margin-bottom: 0.75rem;
}

.result-meta {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.4rem;
}

.meta-chip {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  color: var(--ink-dim);
  padding: 0.28rem 0.65rem;
  border-radius: var(--radius-pill);
  border: 1px solid var(--line);
  background: rgba(26, 31, 42, 0.65);
  letter-spacing: 0.02em;
}

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

/* Hero: WPM + accuracy ring */
.result-hero {
  display: grid;
  grid-template-columns: 1.2fr 0.9fr;
  gap: 0.75rem;
  margin-bottom: 0.85rem;
  animation: fade-up 0.5s 0.06s var(--ease-out) both;
}

.hero-wpm {
  position: relative;
  overflow: hidden;
  text-align: left;
  padding: 1.25rem 1.2rem 1.15rem;
  border-radius: calc(var(--radius) + 2px);
  border: 1px solid rgba(232, 93, 59, 0.32);
  background:
    radial-gradient(120% 90% at 10% 0%, rgba(232, 93, 59, 0.22), transparent 55%),
    linear-gradient(155deg, #1c222e 0%, #141820 100%);
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.28), inset 0 1px 0 rgba(255, 255, 255, 0.04);
}

.hero-glow {
  position: absolute;
  width: 10rem;
  height: 10rem;
  right: -2rem;
  top: -3rem;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(232, 93, 59, 0.35), transparent 68%);
  filter: blur(6px);
  pointer-events: none;
  animation: hero-pulse 3.2s ease-in-out infinite;
}

@keyframes hero-pulse {
  0%, 100% { opacity: 0.55; transform: scale(1); }
  50% { opacity: 1; transform: scale(1.08); }
}

.hero-eyebrow {
  position: relative;
  z-index: 1;
  font-size: 0.78rem;
  color: var(--ink-mute);
  margin-bottom: 0.2rem;
}

.score-val {
  font-family: var(--font-mono);
  font-size: 1.75rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1.15;
}

.hero-val {
  position: relative;
  z-index: 1;
  font-size: clamp(2.8rem, 9vw, 3.8rem);
  font-weight: 800;
  color: var(--accent);
  text-shadow: 0 0 40px rgba(232, 93, 59, 0.35);
  letter-spacing: -0.03em;
}

.hero-delta {
  position: relative;
  z-index: 1;
  margin-top: 0.45rem;
  display: inline-flex;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 600;
  padding: 0.28rem 0.6rem;
  border-radius: var(--radius-pill);
  border: 1px solid var(--line);
  color: var(--ink-dim);
  background: rgba(0, 0, 0, 0.22);
}

.hero-delta.is-best {
  color: #ffd28a;
  border-color: rgba(255, 210, 138, 0.4);
  background: rgba(255, 180, 80, 0.12);
  box-shadow: 0 0 18px rgba(255, 180, 80, 0.18);
}

.hero-delta.is-up {
  color: var(--ok);
  border-color: rgba(62, 207, 142, 0.35);
  background: var(--ok-soft);
}

.hero-delta.is-down {
  color: var(--ink-mute);
}

.hero-ring-card {
  display: grid;
  place-items: center;
  padding: 0.85rem;
  border-radius: calc(var(--radius) + 2px);
  border: 1px solid var(--line);
  background: rgba(22, 26, 36, 0.88);
  box-shadow: var(--shadow);
}

.acc-ring {
  position: relative;
  width: 7.5rem;
  height: 7.5rem;
}

.acc-svg {
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
}

.acc-track {
  fill: none;
  stroke: rgba(255, 255, 255, 0.06);
  stroke-width: 8;
}

.acc-prog {
  fill: none;
  stroke: var(--accent);
  stroke-width: 8;
  stroke-linecap: round;
  stroke-dasharray: 327;
  stroke-dashoffset: 327;
  transition: stroke-dashoffset 1.1s var(--ease-out), stroke 0.35s ease;
  filter: drop-shadow(0 0 8px rgba(232, 93, 59, 0.45));
}

.acc-prog.is-hot { stroke: #ffb454; filter: drop-shadow(0 0 10px rgba(255, 180, 84, 0.5)); }
.acc-prog.is-ok { stroke: var(--ok); filter: drop-shadow(0 0 8px rgba(62, 207, 142, 0.45)); }
.acc-prog.is-mid { stroke: #f0a060; }
.acc-prog.is-low { stroke: var(--bad); filter: drop-shadow(0 0 8px rgba(240, 113, 120, 0.4)); }

.acc-center {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  text-align: center;
  gap: 0.05rem;
}

.acc-val {
  font-size: 1.45rem;
  font-weight: 700;
  color: var(--ink);
}

.score-lab {
  font-size: 0.72rem;
  color: var(--ink-mute);
}

/* Detail stats */
.detail-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.55rem;
  margin-bottom: 1rem;
}

.detail-card {
  position: relative;
  padding: 0.85rem 0.55rem 0.75rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: rgba(26, 31, 42, 0.72);
  animation: fade-up 0.45s var(--ease-out) both;
  transition: border-color 0.2s ease, transform 0.2s var(--ease-out);
}

.detail-card:nth-child(1) { animation-delay: 0.1s; }
.detail-card:nth-child(2) { animation-delay: 0.13s; }
.detail-card:nth-child(3) { animation-delay: 0.16s; }
.detail-card:nth-child(4) { animation-delay: 0.19s; }
.detail-card:nth-child(5) { animation-delay: 0.22s; }
.detail-card:nth-child(6) { animation-delay: 0.25s; }

.detail-card:hover {
  border-color: rgba(255, 255, 255, 0.14);
  transform: translateY(-1px);
}

.detail-ico {
  display: inline-grid;
  place-items: center;
  width: 1.25rem;
  height: 1.25rem;
  margin: 0 auto 0.35rem;
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--accent);
  border-radius: 6px;
  background: var(--accent-soft);
}

.detail-ico.is-bad {
  color: var(--bad);
  background: var(--bad-soft);
}

.detail-val {
  font-family: var(--font-mono);
  font-size: 1.2rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
  line-height: 1.15;
}

.detail-lab {
  margin-top: 0.2rem;
  font-size: 0.68rem;
  color: var(--ink-mute);
  letter-spacing: 0.01em;
}

/* Chart */
.chart-block {
  margin-bottom: 1.1rem;
  text-align: left;
  animation: fade-up 0.45s 0.26s var(--ease-out) both;
}

.chart-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.5rem;
  padding: 0 0.15rem;
}

.chart-title {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--ink-dim);
}

.chart-sub,
.chart-cap {
  font-size: 0.7rem;
  color: var(--ink-mute);
  font-family: var(--font-mono);
}

.chart-stage {
  position: relative;
  height: 132px;
  padding: 1.1rem 0.65rem 0.55rem;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background:
    linear-gradient(180deg, rgba(232, 93, 59, 0.05), transparent 40%),
    rgba(14, 17, 24, 0.92);
  overflow: hidden;
}

.chart-line {
  position: absolute;
  inset: 0.55rem 0.5rem 0.45rem;
  width: calc(100% - 1rem);
  height: calc(100% - 1rem);
  opacity: 0.95;
  pointer-events: none;
  z-index: 1;
}

.chart-path {
  fill: none;
  stroke: #f08a68;
  stroke-width: 2.4;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-dasharray: 480;
  stroke-dashoffset: 480;
  animation: chart-draw 1.1s 0.2s var(--ease-out) forwards;
  filter: drop-shadow(0 0 6px rgba(232, 93, 59, 0.45));
}

.chart-area {
  opacity: 0;
  animation: fade-up 0.8s 0.35s var(--ease-out) forwards;
}

.chart-dot {
  fill: #1a1f2a;
  stroke: #f08a68;
  stroke-width: 1.6;
  opacity: 0;
  animation: fade-up 0.4s 0.55s var(--ease-out) forwards;
}

.chart-dot.is-peak {
  fill: #ffb454;
  stroke: #ffd9a0;
  filter: drop-shadow(0 0 6px rgba(255, 180, 84, 0.65));
}

@keyframes chart-draw {
  to { stroke-dashoffset: 0; }
}

.chart-bars {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 0.35rem;
  height: 100%;
  padding: 0 0.15rem;
}

.chart-bar {
  flex: 1;
  max-width: 2.2rem;
  min-width: 0.55rem;
  background: rgba(232, 93, 59, 0.12);
  border-radius: 5px 5px 2px 2px;
  position: relative;
  height: 4px;
  transition: height 0.7s var(--ease-out);
}

.chart-bar.is-on {
  background: linear-gradient(to top, rgba(232, 93, 59, 0.55), rgba(240, 160, 96, 0.85));
  box-shadow: 0 0 12px rgba(232, 93, 59, 0.15);
}

.chart-bar.is-peak.is-on {
  background: linear-gradient(to top, #e85d3b, #ffc078);
  box-shadow: 0 0 16px rgba(255, 180, 84, 0.35);
}

.chart-bar span {
  position: absolute;
  bottom: calc(100% + 5px);
  left: 50%;
  transform: translateX(-50%);
  font-family: var(--font-mono);
  font-size: 0.6rem;
  color: var(--ink-mute);
  white-space: nowrap;
  opacity: 0.9;
}

.chart-bar.is-peak span {
  color: #ffd9a0;
  font-weight: 600;
}

/* Rank */
.rank-block {
  position: relative;
  overflow: hidden;
  margin-bottom: 1.35rem;
  padding: 1.15rem 1rem 1.05rem;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: rgba(22, 26, 36, 0.82);
  animation: fade-up 0.45s 0.3s var(--ease-out) both;
}

.rank-glow {
  position: absolute;
  inset: auto 50% -40% auto;
  width: 12rem;
  height: 8rem;
  transform: translateX(50%);
  background: radial-gradient(circle, rgba(232, 93, 59, 0.22), transparent 70%);
  pointer-events: none;
}

.rank-badge {
  position: relative;
  display: inline-block;
  font-weight: 800;
  font-size: 1rem;
  letter-spacing: 0.04em;
  padding: 0.45rem 1.15rem;
  border-radius: var(--radius-pill);
  background: var(--accent-soft);
  color: var(--accent);
  border: 1px solid rgba(232, 93, 59, 0.4);
  margin-bottom: 0.4rem;
  animation: badge-pop 0.55s 0.35s var(--ease-out) both;
}

.rank-tier {
  position: relative;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--ink-mute);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-bottom: 0.45rem;
}

.rank-msg {
  position: relative;
  color: var(--ink-dim);
  font-size: 0.95rem;
  max-width: 34ch;
  margin: 0 auto;
  text-wrap: pretty;
  line-height: 1.55;
}

.rank-next {
  position: relative;
  margin-top: 0.7rem;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--ink-mute);
  letter-spacing: 0.02em;
}

.rank--god .rank-badge {
  color: #ffd28a;
  border-color: rgba(255, 210, 138, 0.5);
  background: linear-gradient(135deg, rgba(255, 180, 84, 0.22), rgba(232, 93, 59, 0.18));
  box-shadow: 0 0 24px rgba(255, 180, 84, 0.25);
}

.rank--pro .rank-badge {
  color: #7dffc0;
  border-color: rgba(62, 207, 142, 0.45);
  background: rgba(62, 207, 142, 0.14);
}

.rank--good .rank-badge {
  color: #8ec5ff;
  border-color: rgba(110, 181, 255, 0.4);
  background: rgba(110, 181, 255, 0.12);
}

.rank--ok .rank-badge {
  color: #f0a060;
  border-color: rgba(240, 160, 96, 0.4);
}

.rank--start .rank-badge {
  color: var(--ink-dim);
  border-color: var(--line-strong);
  background: rgba(255, 255, 255, 0.04);
}

@keyframes badge-pop {
  0% {
    opacity: 0;
    transform: scale(0.72);
  }
  70% {
    opacity: 1;
    transform: scale(1.08);
  }
  100% {
    opacity: 1;
    transform: scale(1);
  }
}

.result-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.65rem;
  animation: fade-up 0.45s 0.34s var(--ease-out) both;
}

.btn-share {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--ink);
  background: linear-gradient(145deg, rgba(232, 93, 59, 0.16), rgba(240, 160, 96, 0.1));
  border: 1px solid rgba(232, 93, 59, 0.4);
  border-radius: var(--radius-pill);
  padding: 0.8rem 1.25rem;
  cursor: pointer;
  transition: color 0.18s var(--ease-out), border-color 0.18s var(--ease-out),
    background 0.18s var(--ease-out), transform 0.12s var(--ease-out), box-shadow 0.18s var(--ease-out);
  box-shadow: 0 0 0 0 rgba(232, 93, 59, 0);
}

.btn-share svg {
  flex-shrink: 0;
}

.btn-share:hover {
  border-color: rgba(232, 93, 59, 0.65);
  background: linear-gradient(145deg, rgba(232, 93, 59, 0.24), rgba(240, 160, 96, 0.14));
  box-shadow: 0 8px 24px rgba(232, 93, 59, 0.18);
}

.btn-share:active {
  transform: scale(0.97);
}

.share-toast {
  margin: 0.85rem auto 0;
  max-width: 28rem;
  padding: 0.55rem 0.9rem;
  border-radius: var(--radius-pill);
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--ink);
  background: rgba(26, 31, 42, 0.92);
  border: 1px solid var(--line-strong);
  opacity: 0;
  transform: translateY(6px);
  transition: opacity 0.25s var(--ease-out), transform 0.25s var(--ease-out);
  pointer-events: none;
}

.share-toast.is-show {
  opacity: 1;
  transform: translateY(0);
}

.share-toast.is-ok {
  border-color: rgba(62, 207, 142, 0.4);
  color: #9ef0c5;
  box-shadow: 0 0 20px rgba(62, 207, 142, 0.12);
}

.share-toast.is-err {
  border-color: rgba(240, 113, 120, 0.4);
  color: #ffb0b5;
}

/* Footer */
.footer {
  margin-top: auto;
  padding-top: 1.75rem;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.footer p {
  font-size: 0.75rem;
  color: var(--ink-mute);
}

.footer-copy {
  font-size: 0.7rem;
  color: var(--ink-mute);
  letter-spacing: 0.04em;
}

.footer-copy a {
  color: var(--ink-dim);
  text-decoration: none;
  transition: color 0.18s var(--ease-out);
}

.footer-copy a:hover {
  color: var(--accent);
}

/* Utils */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }

  .btn-shine,
  .hero-glow,
  .rank-glow {
    display: none;
  }

  #webgl-root {
    opacity: 0.35;
  }

  .char.is-current::after {
    animation: none;
    opacity: 1;
  }

  .panel {
    filter: none;
  }
}

/* Mobile */
@media (max-width: 640px) {
  .app {
    padding: 0.85rem 0.9rem 1.5rem;
    padding-bottom: max(1.5rem, env(safe-area-inset-bottom, 0px));
  }

  .header-stats .stat-chip:not(.timer-chip) {
    display: none;
  }

  .idle-inner {
    max-width: 100%;
  }

  #webgl-root {
    opacity: 0.85;
  }

  .live-sep {
    display: none;
  }

  .live-bar {
    gap: 0.15rem;
  }

  .live-item {
    min-width: 4.5rem;
    padding: 0.2rem 0.4rem;
  }

  .live-val {
    font-size: 1.15rem;
  }

  /* Typing test: keep passage shorter so input + keyboard fit */
  #panel-test .test-shell {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    min-height: 0;
  }

  #panel-test .passage-wrap {
    min-height: 6.5rem;
    max-height: min(28vh, 180px);
    padding: 1rem 0.95rem;
    flex: 0 1 auto;
  }

  #panel-test .passage {
    font-size: clamp(1.05rem, 4.2vw, 1.25rem);
    line-height: 1.85;
  }

  /* Sticky input above virtual keyboard / home indicator */
  #panel-test .input-wrap {
    position: sticky;
    bottom: 0;
    z-index: 12;
    margin: 0 -0.15rem;
    padding: 0.55rem 0.15rem
      max(0.55rem, env(safe-area-inset-bottom, 0px));
    background: linear-gradient(
      to top,
      rgba(12, 14, 18, 0.98) 55%,
      rgba(12, 14, 18, 0.88) 85%,
      transparent
    );
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
  }

  .typing-input {
    font-size: 16px; /* iOS: no zoom on focus */
    min-height: 3.5rem;
    padding: 0.85rem 0.95rem;
    line-height: 1.65;
    border-radius: 12px;
  }

  .typing-input:focus {
    box-shadow: 0 0 0 3px var(--accent-soft), 0 8px 24px rgba(0, 0, 0, 0.35);
  }

  #panel-test .hint-panel {
    max-height: 9.5rem;
    overflow-y: auto;
  }

  #panel-test .live-bar {
    padding: 0.55rem 0.65rem;
  }

  #panel-test .test-actions {
    padding-bottom: 0.25rem;
  }

  /* When keyboard open (class set by JS) */
  body.is-keyboard-open #panel-test .hint-panel {
    display: none;
  }

  body.is-keyboard-open #panel-test .live-bar {
    padding: 0.4rem 0.5rem;
  }

  body.is-keyboard-open #panel-test .passage-wrap {
    max-height: min(22vh, 140px);
  }
}

/* Coarse pointer (phones / tablets): larger hit areas */
@media (pointer: coarse) {
  .typing-input {
    min-height: 3.75rem;
    font-size: max(16px, 1.05rem);
    padding: 1rem 1.05rem;
  }

  .mode-btn {
    min-height: 2.75rem;
    padding-inline: 0.95rem;
  }

  .btn-primary {
    min-height: 3.15rem;
  }
}

@media (max-width: 520px) {
  .result-hero {
    grid-template-columns: 1fr;
  }

  .hero-wpm {
    text-align: center;
  }

  .detail-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .acc-ring {
    width: 6.75rem;
    height: 6.75rem;
  }
}

@media (min-width: 768px) {
  .result-shell {
    max-width: 44rem;
  }

  .detail-grid {
    grid-template-columns: repeat(6, 1fr);
  }

  .detail-card {
    padding: 0.9rem 0.4rem 0.8rem;
  }

  .detail-val {
    font-size: 1.1rem;
  }
}

/* Hover only on fine pointers */
@media (hover: hover) and (pointer: fine) {
  .mode-btn:hover,
  .btn-ghost:hover {
    background: var(--surface-2);
  }
}
