/* 色阶 · 视觉：实验室粉笔台 + 青绿锚点，色块本身是唯一高饱和 */
:root {
  --bg: #eef2ec;
  --bg-deep: #e2e8df;
  --ink: #1a2332;
  --ink-soft: #5a6574;
  --line: #c5cfc0;
  --teal: #0d9488;
  --teal-deep: #0f766e;
  --danger: #c62828;
  --panel: #f7faf5;
  --shadow: 0 12px 40px rgba(26, 35, 50, 0.08);
  --radius: 18px;
  --font: "Noto Sans CJK SC", "Source Han Sans SC", "WenQuanYi Micro Hei",
    "Microsoft YaHei", "PingFang SC", "Hiragino Sans GB", "Noto Sans SC",
    sans-serif;
  --mono: "Ubuntu Mono", "DejaVu Sans Mono", "Consolas", monospace;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  user-select: none;
}

body {
  background-image:
    radial-gradient(ellipse 80% 50% at 50% -10%, rgba(13, 148, 136, 0.12), transparent),
    linear-gradient(180deg, #f4f7f1 0%, var(--bg) 40%, var(--bg-deep) 100%);
  min-height: 100dvh;
}

#app {
  max-width: 440px;
  margin: 0 auto;
  min-height: 100dvh;
  padding: calc(16px + var(--safe-t)) 20px calc(24px + var(--safe-b));
  position: relative;
}

.screen {
  display: none;
  flex-direction: column;
  animation: fade-in 0.35s ease;
}

.screen.active {
  display: flex;
  min-height: calc(100dvh - 40px - var(--safe-t) - var(--safe-b));
}

@keyframes fade-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

.brand {
  margin-top: 28px;
  text-align: center;
}

.brand-mark {
  margin: 0;
  font-size: clamp(3.2rem, 14vw, 4.2rem);
  font-weight: 800;
  letter-spacing: 0.18em;
  line-height: 1;
  color: var(--ink);
}

.brand-sub {
  margin: 10px 0 0;
  font-family: var(--mono);
  font-size: 0.78rem;
  letter-spacing: 0.42em;
  color: var(--teal);
}

.tagline {
  text-align: center;
  color: var(--ink-soft);
  line-height: 1.65;
  margin: 28px 0 32px;
  font-size: 1.02rem;
}

.home-actions {
  display: grid;
  gap: 12px;
}

.btn {
  appearance: none;
  border: none;
  border-radius: 999px;
  padding: 16px 22px;
  font: inherit;
  font-size: 1.05rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.12s ease, background 0.15s ease, box-shadow 0.15s ease;
}

.btn:active {
  transform: scale(0.97);
}

.btn-primary {
  background: var(--teal);
  color: #fff;
  box-shadow: 0 8px 24px rgba(13, 148, 136, 0.28);
}

.btn-primary:hover {
  background: var(--teal-deep);
}

.btn-ghost {
  background: var(--panel);
  color: var(--ink);
  border: 1.5px solid var(--line);
}

.btn-sm {
  padding: 10px 16px;
  font-size: 0.92rem;
}

.home-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 28px;
}

.stat {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  text-align: center;
}

.stat-label {
  display: block;
  font-size: 0.78rem;
  color: var(--ink-soft);
  margin-bottom: 6px;
}

.stat-value {
  font-size: 1.6rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.home-tip {
  margin-top: 22px;
  font-size: 0.86rem;
  color: var(--ink-soft);
  text-align: center;
  line-height: 1.5;
}

.link-btn {
  margin: 12px auto 0;
  background: none;
  border: none;
  color: var(--teal);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.back-btn,
.icon-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1.5px solid var(--line);
  background: var(--panel);
  font-size: 1.35rem;
  line-height: 1;
  cursor: pointer;
  color: var(--ink);
}

.screen-title {
  margin: 8px 0 10px;
  font-size: 1.75rem;
  font-weight: 800;
}

.screen-desc {
  color: var(--ink-soft);
  line-height: 1.6;
  margin: 0 0 22px;
}

.howto-list {
  margin: 0 0 28px;
  padding-left: 1.2em;
  line-height: 1.75;
  color: var(--ink-soft);
}

.howto-list strong {
  color: var(--ink);
}

/* Play */
.play-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.play-scores {
  display: flex;
  gap: 18px;
  font-size: 0.95rem;
  color: var(--ink-soft);
}

.play-scores strong {
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

.play-mode-label {
  text-align: center;
  margin: 18px 0 4px;
  font-size: 0.8rem;
  letter-spacing: 0.12em;
  color: var(--teal);
  font-weight: 700;
}

.play-hint {
  text-align: center;
  margin: 0 0 8px;
  min-height: 1.4em;
  font-size: 1.05rem;
  font-weight: 700;
}

.stage {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 220px;
  padding-bottom: 36px;
}

.block-wrap {
  position: relative;
  width: min(56vw, 220px);
  height: min(56vw, 220px);
}

.block-wrap.reacting .timer-ring {
  opacity: 1;
}

.block-wrap.urgent {
  animation: urgent-shake 0.35s ease-in-out infinite;
}

@keyframes urgent-shake {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.02); }
}

.timer-ring {
  position: absolute;
  inset: -6px;
  width: calc(100% + 12px);
  height: calc(100% + 12px);
  transform: rotate(-90deg);
  opacity: 0.55;
  pointer-events: none;
  z-index: 3;
  filter: drop-shadow(0 0 0 transparent);
  transition: filter 0.15s ease, opacity 0.15s ease;
}

.block-wrap.reacting .timer-ring {
  filter: drop-shadow(0 0 6px rgba(13, 148, 136, 0.45));
}

.block-wrap.warn .timer-ring {
  filter: drop-shadow(0 0 8px rgba(245, 158, 11, 0.55));
}

.block-wrap.urgent .timer-ring {
  filter: drop-shadow(0 0 10px rgba(198, 40, 40, 0.65));
  opacity: 1;
}

.timer-track {
  fill: none;
  stroke: rgba(26, 35, 50, 0.18);
  stroke-width: 6;
}

.timer-progress {
  fill: none;
  stroke: #0d9488;
  stroke-width: 6;
  stroke-linecap: round;
  stroke-dasharray: 339.292;
  stroke-dashoffset: 339.292;
  transition: stroke 0.08s linear;
}

.react-countdown {
  position: absolute;
  left: 50%;
  bottom: -38px;
  transform: translateX(-50%);
  min-width: 64px;
  padding: 4px 12px;
  border-radius: 999px;
  background: var(--ink);
  color: #fff;
  font-family: var(--mono);
  font-size: 1.05rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  text-align: center;
  z-index: 4;
  letter-spacing: 0.04em;
  box-shadow: 0 6px 18px rgba(26, 35, 50, 0.2);
}

.react-countdown.warn {
  background: #f59e0b;
  color: #1a2332;
}

.react-countdown.urgent {
  background: #c62828;
  color: #fff;
  animation: countdown-blink 0.28s ease-in-out infinite;
}

@keyframes countdown-blink {
  0%, 100% { opacity: 1; transform: translateX(-50%) scale(1); }
  50% { opacity: 0.85; transform: translateX(-50%) scale(1.08); }
}

.color-block {
  width: 100%;
  height: 100%;
  border-radius: 28px;
  background: #9aa3ad;
  box-shadow: var(--shadow);
  animation: breathe 2.4s ease-in-out infinite;
  transition: background-color 0.12s ease, transform 0.18s ease, filter 0.2s ease;
  position: relative;
  z-index: 1;
}

.color-block.flash {
  transform: scale(1.04);
}

.color-block.dim {
  filter: brightness(0.55) saturate(0.85);
}

.color-block.hidden-color {
  background: var(--bg-deep) !important;
  box-shadow: inset 0 0 0 2px var(--line);
}

@keyframes breathe {
  0%, 100% { opacity: 0.88; }
  50% { opacity: 1; }
}

.flash-digit {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 4rem;
  font-weight: 800;
  color: #fff;
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.35);
  pointer-events: none;
  z-index: 2;
}

.color-buttons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: auto;
  padding-bottom: 8px;
}

.color-btn {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 64px;
  border-radius: 16px;
  border: 2px solid var(--line);
  background: var(--panel);
  font: inherit;
  font-size: 1.25rem;
  font-weight: 800;
  cursor: pointer;
  transition: transform 0.1s ease, border-color 0.15s ease, background 0.15s ease;
}

.color-btn:disabled {
  opacity: 0.55;
  cursor: default;
}

.color-btn:not(:disabled):active {
  transform: scale(0.96);
}

.color-btn .swatch {
  width: 14px;
  height: 14px;
  border-radius: 4px;
  flex-shrink: 0;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.12);
}

.color-btn.wrong {
  border-color: var(--danger);
  background: #fdecea;
}

.color-btn.correct {
  border-color: var(--teal);
  background: #e0f2f1;
}

.play-footer {
  text-align: center;
  min-height: 1.4em;
  margin: 10px 0 0;
  font-size: 0.85rem;
  color: var(--ink-soft);
}

/* Result */
#screen-result {
  justify-content: center;
  text-align: center;
}

.result-eyebrow {
  margin: 0;
  color: var(--teal);
  font-weight: 700;
  letter-spacing: 0.08em;
}

.result-score {
  margin: 12px 0;
  font-size: clamp(4rem, 18vw, 5.5rem);
  font-weight: 800;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.result-msg {
  font-size: 1.2rem;
  font-weight: 700;
  margin: 0 0 8px;
}

.result-detail {
  color: var(--ink-soft);
  margin: 0 0 16px;
  line-height: 1.55;
}

.result-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 0 0 28px;
}

.result-stat {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 8px;
  text-align: center;
}

.result-stat-label {
  display: block;
  font-size: 0.75rem;
  color: var(--ink-soft);
  margin-bottom: 6px;
}

.result-stat-value {
  font-size: 1.05rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
}

.result-actions {
  display: grid;
  gap: 12px;
}

.friend-compare {
  margin-top: 24px;
  padding: 16px;
  border-radius: var(--radius);
  background: var(--panel);
  border: 1px solid var(--line);
  text-align: left;
}

.friend-compare h3 {
  margin: 0 0 12px;
  font-size: 1rem;
}

.friend-row {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  border-top: 1px solid var(--line);
}

.friend-row:first-of-type {
  border-top: none;
}

.friend-row.winner strong {
  color: var(--teal);
}

/* Training */
.train-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 10px;
}

.train-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  background: var(--panel);
  border: 1.5px solid var(--line);
  border-radius: var(--radius);
  cursor: pointer;
  text-align: left;
  font: inherit;
  width: 100%;
  color: inherit;
}

.train-item.done {
  border-color: var(--teal);
  background: #e8f6f4;
}

.train-check {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid var(--line);
  display: grid;
  place-items: center;
  flex-shrink: 0;
  font-size: 0.85rem;
  color: var(--teal);
}

.train-item.done .train-check {
  background: var(--teal);
  border-color: var(--teal);
  color: #fff;
}

.train-meta {
  flex: 1;
  min-width: 0;
}

.train-meta strong {
  display: block;
  margin-bottom: 2px;
}

.train-meta span {
  font-size: 0.82rem;
  color: var(--ink-soft);
}

.train-go {
  flex-shrink: 0;
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--teal);
}

.brain-card {
  margin-top: 24px;
  padding: 20px;
  border-radius: var(--radius);
  background: linear-gradient(160deg, #dff5f1, var(--panel));
  border: 1px solid #b7ddd7;
  text-align: center;
}

.brain-label {
  margin: 0;
  font-size: 0.85rem;
  color: var(--ink-soft);
}

.brain-age {
  margin: 8px 0;
  font-size: 2.6rem;
  font-weight: 800;
}

.brain-note {
  margin: 0 0 14px;
  font-size: 0.88rem;
  color: var(--ink-soft);
}

.report-panel {
  margin-top: 12px;
  text-align: left;
  font-size: 0.9rem;
  line-height: 1.6;
  color: var(--ink-soft);
  background: rgba(255, 255, 255, 0.55);
  border-radius: 12px;
  padding: 12px 14px;
}

.field {
  display: grid;
  gap: 8px;
  margin-bottom: 20px;
  text-align: left;
  font-weight: 600;
}

.field input {
  font: inherit;
  padding: 14px 16px;
  border-radius: 14px;
  border: 1.5px solid var(--line);
  background: var(--panel);
  color: var(--ink);
}

.field input:focus {
  outline: 2px solid var(--teal);
  outline-offset: 1px;
}

/* Sheets */
.sheet {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.sheet[hidden] {
  display: none;
}

.sheet-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(26, 35, 50, 0.35);
}

.sheet-body {
  position: relative;
  width: min(100%, 440px);
  background: var(--panel);
  border-radius: 24px 24px 0 0;
  padding: 24px 20px calc(24px + var(--safe-b));
  box-shadow: var(--shadow);
  display: grid;
  gap: 12px;
  animation: sheet-up 0.28s ease;
}

@keyframes sheet-up {
  from { transform: translateY(40px); opacity: 0; }
  to { transform: none; opacity: 1; }
}

.sheet-body h2 {
  margin: 0;
  font-size: 1.25rem;
}

.sheet-body p {
  margin: 0;
  color: var(--ink-soft);
  line-height: 1.55;
}

.sheet-body textarea {
  width: 100%;
  font: inherit;
  font-size: 0.85rem;
  padding: 12px;
  border-radius: 12px;
  border: 1px solid var(--line);
  resize: none;
  background: #fff;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(28px + var(--safe-b));
  transform: translateX(-50%);
  background: var(--ink);
  color: #fff;
  padding: 12px 18px;
  border-radius: 999px;
  font-size: 0.92rem;
  z-index: 50;
  max-width: 90vw;
  text-align: center;
  animation: fade-in 0.2s ease;
}

.toast[hidden] {
  display: none;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }
}
