:root {
  color-scheme: light;
  --ink: #17212b;
  --muted: #657180;
  --line: #dfe6ee;
  --panel: #ffffff;
  --page: #f4f7fb;
  --blue: #2777f3;
  --blue-dark: #1658c8;
  --green: #18ad6f;
  --red: #e14d4d;
  --amber: #f0a338;
  --shadow: 0 18px 45px rgba(27, 43, 67, 0.12);
  font-family:
    Inter, "PingFang SC", "Microsoft YaHei", "Noto Sans SC", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 18% 20%, rgba(39, 119, 243, 0.12), transparent 28%),
    linear-gradient(135deg, #f7fafc 0%, #eef4fa 100%);
  color: var(--ink);
}

button {
  font: inherit;
}

.app-shell {
  display: grid;
  grid-template-columns: 280px 1fr;
  min-height: 100vh;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 28px;
  padding: 28px 20px;
  border-right: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.78);
  backdrop-filter: blur(18px);
  min-width: 0;
  max-height: 100vh;
  overflow: hidden;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  color: inherit;
  text-decoration: none;
}

.brand-mark {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border-radius: 8px;
  background: var(--ink);
  color: #fff;
  font-weight: 800;
}

.brand strong,
.brand small {
  display: block;
}

.brand small,
.eyebrow,
.sidebar-foot span,
.stat-tile span,
.panel-heading span,
.mini-test span {
  color: var(--muted);
}

.nav-list {
  display: grid;
  gap: 8px;
  min-width: 0;
  overflow-y: auto;
  padding-right: 4px;
  scrollbar-width: thin;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 48px;
  padding: 10px 12px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  text-align: left;
}

.nav-item:hover,
.nav-item.is-active {
  border-color: #c9dcf8;
  background: #eef5ff;
}

.nav-icon {
  display: grid;
  width: 34px;
  height: 28px;
  place-items: center;
  border-radius: 6px;
  background: #dbeafe;
  color: var(--blue-dark);
  font-size: 12px;
  font-weight: 800;
}

.sidebar-foot {
  margin-top: auto;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.sidebar-foot strong {
  display: block;
  margin-top: 6px;
  font-size: 24px;
}

.main-panel {
  min-width: 0;
  padding: 30px clamp(18px, 4vw, 56px) 42px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
}

.eyebrow {
  margin: 0 0 6px;
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
}

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

h1 {
  margin-bottom: 0;
  font-size: clamp(30px, 4vw, 52px);
  line-height: 1.05;
}

.ghost-button,
.primary-button {
  min-height: 42px;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 800;
}

.ghost-button {
  padding: 0 16px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
}

.primary-button {
  padding: 0 22px;
  background: #fff;
  color: var(--blue-dark);
  box-shadow: 0 8px 24px rgba(18, 55, 103, 0.18);
}

.hero-zone {
  display: grid;
  gap: 18px;
}

.test-card {
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.stage {
  position: relative;
  display: grid;
  min-height: clamp(360px, 56vh, 520px);
  place-items: center;
  overflow: hidden;
  border-radius: 8px;
  background: #2777f3;
  color: #fff;
  cursor: pointer;
  transition:
    background-color 160ms ease,
    transform 160ms ease;
}

.stage.is-waiting {
  background: var(--red);
}

.stage.is-ready {
  background: var(--green);
}

.stage.is-result {
  background: var(--blue);
}

.stage.is-too-soon {
  background: var(--amber);
}

.stage.is-aim-idle,
.stage.is-aim-result,
.stage.is-aim-playing {
  background: var(--blue);
}

.stage.is-aim-playing .stage-content {
  pointer-events: none;
  opacity: 0;
}

.stage.is-sequence-idle,
.stage.is-sequence-showing,
.stage.is-sequence-input,
.stage.is-sequence-success,
.stage.is-sequence-ending,
.stage.is-sequence-result {
  background: var(--blue);
}

.stage.is-sequence-showing .stage-content,
.stage.is-sequence-input .stage-content,
.stage.is-sequence-success .stage-content,
.stage.is-sequence-ending .stage-content {
  pointer-events: none;
  opacity: 0;
}

.stage.is-extra-idle,
.stage.is-extra-playing,
.stage.is-extra-result {
  background: var(--blue);
}

.stage.is-extra-playing {
  min-height: 480px;
}

.stage.is-extra-playing .stage-content {
  pointer-events: none;
  opacity: 0;
}

.stage:focus-visible {
  outline: 4px solid rgba(39, 119, 243, 0.35);
  outline-offset: 3px;
}

#pulseCanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.stage-content {
  position: relative;
  z-index: 1;
  width: min(680px, calc(100% - 32px));
  text-align: center;
}

.stage-kicker {
  margin-bottom: 12px;
  font-size: 14px;
  font-weight: 800;
  text-transform: uppercase;
  opacity: 0.82;
}

.stage h2 {
  margin-bottom: 12px;
  font-size: clamp(36px, 7vw, 82px);
  line-height: 1;
}

.stage p {
  margin-bottom: 24px;
  font-size: clamp(16px, 2vw, 22px);
  line-height: 1.55;
}

.aim-hud {
  position: absolute;
  top: 18px;
  left: 50%;
  z-index: 3;
  display: flex;
  align-items: center;
  gap: 14px;
  min-height: 42px;
  padding: 8px 14px;
  border: 1px solid rgba(255, 255, 255, 0.34);
  border-radius: 8px;
  background: rgba(23, 33, 43, 0.28);
  box-shadow: 0 10px 26px rgba(23, 33, 43, 0.12);
  color: #fff;
  transform: translateX(-50%);
  backdrop-filter: blur(10px);
}

.aim-hud strong,
.aim-hud span {
  white-space: nowrap;
}

.aim-target {
  position: absolute;
  z-index: 4;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background:
    radial-gradient(circle, #17212b 0 16%, transparent 17%),
    radial-gradient(circle, #fff 0 36%, transparent 37%),
    radial-gradient(circle, #ff5a5f 0 62%, #c91f3a 63% 100%);
  box-shadow:
    0 0 0 5px rgba(255, 255, 255, 0.32),
    0 12px 32px rgba(23, 33, 43, 0.28);
  cursor: crosshair;
  transform: scale(1);
  transition:
    transform 80ms ease,
    box-shadow 80ms ease;
}

.aim-target:hover {
  transform: scale(1.06);
  box-shadow:
    0 0 0 7px rgba(255, 255, 255, 0.38),
    0 16px 38px rgba(23, 33, 43, 0.32);
}

.aim-target:active {
  transform: scale(0.94);
}

.aim-target:focus-visible {
  outline: 4px solid rgba(255, 255, 255, 0.7);
  outline-offset: 4px;
}

.sequence-hud {
  position: absolute;
  top: 20px;
  left: 50%;
  z-index: 4;
  display: flex;
  align-items: center;
  gap: 14px;
  min-height: 44px;
  padding: 8px 14px;
  border: 1px solid rgba(255, 255, 255, 0.34);
  border-radius: 8px;
  background: rgba(23, 33, 43, 0.3);
  color: #fff;
  transform: translateX(-50%);
  backdrop-filter: blur(10px);
}

.sequence-hud strong,
.sequence-hud span {
  white-space: nowrap;
}

.sequence-board {
  position: relative;
  z-index: 3;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: clamp(10px, 1.4vw, 16px);
  width: min(330px, calc(100% - 48px));
  aspect-ratio: 1;
}

.sequence-cell {
  width: 100%;
  aspect-ratio: 1;
  border: 2px solid rgba(255, 255, 255, 0.32);
  border-radius: 8px;
  background: rgba(13, 61, 143, 0.55);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.06);
  cursor: pointer;
  transition: background-color 100ms ease, transform 100ms ease, box-shadow 100ms ease;
}

.sequence-cell:not(:disabled):hover {
  background: rgba(255, 255, 255, 0.26);
  transform: translateY(-2px);
}

.sequence-cell.is-lit,
.sequence-cell.is-correct {
  background: #fff;
  box-shadow: 0 0 0 5px rgba(255, 255, 255, 0.22), 0 10px 28px rgba(10, 47, 113, 0.3);
  transform: scale(1.04);
}

.sequence-cell.is-wrong {
  background: #ff6670;
}

.sequence-cell.is-expected {
  background: #ffd166;
  box-shadow: 0 0 0 5px rgba(255, 209, 102, 0.22);
}

.sequence-board.is-success .sequence-cell {
  border-color: rgba(255, 255, 255, 0.66);
  background: rgba(24, 173, 111, 0.72);
}

.sequence-cell:focus-visible {
  outline: 4px solid rgba(255, 255, 255, 0.72);
  outline-offset: 3px;
}

.extra-surface {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 18px;
  padding: 76px 24px 24px;
  color: #fff;
}

.game-hud {
  position: absolute;
  top: 18px;
  left: 50%;
  display: flex;
  align-items: center;
  gap: 14px;
  min-height: 44px;
  padding: 8px 14px;
  border: 1px solid rgba(255, 255, 255, 0.34);
  border-radius: 8px;
  background: rgba(23, 33, 43, 0.3);
  transform: translateX(-50%);
  backdrop-filter: blur(10px);
}

.game-hud strong,
.game-hud span {
  white-space: nowrap;
}

.game-hud b {
  margin-left: 8px;
  font-size: 24px;
}

.game-feedback {
  min-height: 24px;
  font-weight: 700;
  text-align: center;
}

.extra-surface button,
.extra-surface input,
.extra-surface textarea {
  font: inherit;
}

.extra-surface button {
  cursor: pointer;
}

.typing-passage {
  width: min(720px, 100%);
  margin: 0;
  font-size: clamp(22px, 3vw, 34px) !important;
  font-weight: 700;
  text-align: center;
}

.typing-input {
  width: min(680px, 100%);
  min-height: 112px;
  padding: 16px;
  border: 2px solid rgba(255, 255, 255, 0.5);
  border-radius: 8px;
  outline: 0;
  resize: none;
  color: var(--ink);
  font-size: 20px !important;
  line-height: 1.6;
}

.memory-card,
.number-display {
  display: grid;
  min-width: 180px;
  min-height: 150px;
  place-items: center;
  font-size: clamp(70px, 12vw, 132px);
  font-weight: 900;
}

.game-actions,
.option-row,
.number-form {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 12px;
}

.game-actions button,
.option-row button,
.number-form button {
  min-width: 120px;
  min-height: 48px;
  padding: 0 18px;
  border: 0;
  border-radius: 8px;
  background: #fff;
  color: var(--blue-dark);
  font-weight: 800;
}

.ishihara {
  position: relative;
  display: grid;
  width: min(250px, 65vw);
  aspect-ratio: 1;
  place-items: center;
  overflow: hidden;
  border-radius: 50%;
  background:
    radial-gradient(circle at 20% 30%, hsl(var(--plate-hue) 45% 62%) 0 5%, transparent 6%),
    radial-gradient(circle at 75% 22%, hsl(calc(var(--plate-hue) + 18) 42% 58%) 0 6%, transparent 7%),
    radial-gradient(circle at 65% 72%, hsl(var(--plate-hue) 48% 66%) 0 7%, transparent 8%),
    radial-gradient(circle at 28% 76%, hsl(calc(var(--plate-hue) + 12) 38% 55%) 0 6%, transparent 7%),
    hsl(var(--plate-hue) 46% 64%);
  box-shadow: inset 0 0 0 12px rgba(255,255,255,.14);
}

.ishihara strong {
  color: hsl(calc(var(--plate-hue) + 28) 48% 48%);
  font-size: 82px;
}

.hue-grid,
.symbol-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  width: min(320px, 78vw);
}

.hue-grid button,
.symbol-grid button {
  aspect-ratio: 1;
  border: 2px solid rgba(255,255,255,.36);
  border-radius: 8px;
}

.symbol-grid button {
  background: rgba(255,255,255,.14);
  color: #fff;
  font-size: 38px;
}

.moving-target {
  position: absolute;
  width: 64px;
  height: 64px;
  border: 5px solid #fff;
  border-radius: 50%;
  background: #ff5a5f;
  box-shadow: 0 12px 30px rgba(23,33,43,.3);
  transform: translate(-50%, -50%);
  transition: left 120ms ease, top 120ms ease;
}

.chimp-grid {
  position: relative;
  width: min(420px, 82vw);
  aspect-ratio: 1.25;
}

.chimp-grid button {
  position: absolute;
  width: 64px;
  height: 64px;
  border: 2px solid #fff;
  border-radius: 8px;
  background: transparent;
  color: #fff;
  font-size: 28px;
  font-weight: 900;
}

.chimp-grid button.is-hidden-number {
  color: transparent;
  background: #fff;
}

.chimp-grid button.is-cleared {
  visibility: hidden;
}

.visual-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  width: min(370px, 82vw);
}

.visual-grid button {
  aspect-ratio: 1;
  border: 2px solid rgba(255,255,255,.28);
  border-radius: 6px;
  background: rgba(15,67,152,.62);
}

.visual-grid button.is-preview,
.visual-grid button.is-found {
  background: #fff;
}

.visual-grid button.is-wrong {
  background: var(--red);
}

.number-timer {
  width: min(420px, 78vw);
  height: 6px;
  overflow: hidden;
  border-radius: 3px;
  background: rgba(255,255,255,.22);
}

.number-timer span {
  display: block;
  width: 100%;
  height: 100%;
  background: #fff;
  animation: countdown 2.2s linear forwards;
}

@keyframes countdown { to { width: 0; } }

.number-form input {
  width: min(420px, 70vw);
  min-height: 54px;
  padding: 0 16px;
  border: 0;
  border-radius: 8px;
  color: var(--ink);
  font-size: 24px;
  text-align: center;
}

.face-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  width: min(600px, 90%);
}

.face-grid.choices {
  grid-template-columns: repeat(3, 1fr);
}

.face-card {
  position: relative;
  min-width: 0;
  aspect-ratio: 1;
  overflow: hidden;
  border: 3px solid rgba(255,255,255,.48);
  border-radius: 50%;
  background: var(--skin);
}

.face-card button { padding: 0; }
.face-hair { position:absolute; inset:0 0 62% 0; background:var(--hair); border-radius:50% 50% 25% 25%; }
.face-eyes { position:absolute; top:45%; left:50%; width:var(--eye-gap); height:7px; border-left:6px solid #17212b; border-right:6px solid #17212b; transform:translateX(-50%); }
.face-mouth { position:absolute; bottom:22%; left:50%; width:var(--mouth); height:8px; border-bottom:4px solid #9b3b48; border-radius:50%; transform:translateX(-50%); }

.tracking-field {
  position: absolute;
  inset: 72px 20px 20px;
}

.track-ball {
  position: absolute;
  width: 54px;
  height: 54px;
  border: 5px solid rgba(255,255,255,.72);
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 8px 20px rgba(23,33,43,.24);
  transform: translate(-50%, -50%);
  transition: left 560ms ease-in-out, top 560ms ease-in-out, background-color 160ms ease;
}

.track-ball.is-target { background:#ffd166; box-shadow:0 0 0 8px rgba(255,209,102,.28); }
.track-ball.is-selected { background:#18ad6f; }

.focus-pad,
.auditory-pad {
  display: grid;
  place-items: center;
  border: 0;
  color: #fff;
  font-size: 28px;
  font-weight: 800;
}

.focus-pad {
  width: min(270px, 68vw);
  aspect-ratio: 1;
  border-radius: 50%;
  background: rgba(255,255,255,.12);
  box-shadow: inset 0 0 0 5px rgba(255,255,255,.34);
}

.focus-pad span {
  width: 34%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: #fff;
}

.focus-pad.is-beat { animation: focusBeat 700ms ease-out; }
@keyframes focusBeat { 0% { box-shadow: inset 0 0 0 85px rgba(255,255,255,.7); } 100% { box-shadow: inset 0 0 0 5px rgba(255,255,255,.34); } }

.auditory-pad {
  width: min(400px, 80vw);
  min-height: 180px;
  border: 2px solid rgba(255,255,255,.42);
  border-radius: 8px;
  background: rgba(23,33,43,.22);
}

.auditory-game.is-sounded .auditory-pad { background: var(--green); }

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.stat-tile,
.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.9);
}

.stat-tile {
  padding: 16px;
}

.stat-tile strong {
  display: block;
  margin-top: 8px;
  font-size: clamp(24px, 3vw, 34px);
}

.lower-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(300px, 0.8fr);
  gap: 18px;
  margin-top: 18px;
}

.leaderboard-panel {
  grid-column: 1 / -1;
  min-width: 0;
}

.leaderboard-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 16px;
}

.leaderboard-heading h3 {
  margin-bottom: 4px;
  font-size: 20px;
}

.leaderboard-heading > div > span,
.player-name-field > span {
  color: var(--muted);
  font-size: 13px;
}

.player-name-field {
  display: grid;
  gap: 6px;
  width: min(240px, 100%);
}

.player-name-field input {
  width: 100%;
  min-height: 42px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  outline: 0;
  background: #fff;
  color: var(--ink);
  font: inherit;
}

.player-name-field input:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(39, 119, 243, 0.14);
}

.leaderboard-table {
  width: 100%;
  max-width: 100%;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.leaderboard-row {
  display: grid;
  grid-template-columns: 72px minmax(120px, 1fr) minmax(110px, 0.7fr) 90px;
  align-items: center;
  min-height: 48px;
  border-top: 1px solid var(--line);
}

.leaderboard-row:first-child,
.leaderboard-header + #leaderboardList .leaderboard-row:first-child {
  border-top: 0;
}

.leaderboard-row span {
  min-width: 0;
  padding: 10px 14px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.leaderboard-header {
  border-top: 0;
  background: #f2f6fb;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

#leaderboardList .leaderboard-row:nth-child(-n + 3) span:first-child {
  color: var(--blue-dark);
  font-weight: 900;
}

.leaderboard-empty {
  padding: 24px 14px;
  color: var(--muted);
  text-align: center;
}

.panel {
  padding: 18px;
}

.panel-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.panel-heading h3 {
  margin-bottom: 0;
  font-size: 20px;
}

.history-list {
  display: grid;
  gap: 8px;
  min-height: 104px;
  margin: 0;
  padding-left: 24px;
}

.history-list li {
  padding: 10px 12px;
  border-radius: 8px;
  background: #f7f9fc;
}

.history-list strong {
  float: right;
}

.mini-tests {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.mini-test {
  min-height: 92px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: inherit;
  cursor: pointer;
  text-align: left;
}

.mini-test:hover {
  border-color: #b9d4fb;
  background: #f4f8ff;
}

.mini-test strong,
.mini-test span {
  display: block;
}

.mini-test strong {
  margin-bottom: 8px;
}

@media (max-width: 860px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 3;
    display: block;
    padding: 14px;
    max-height: none;
  }

  .brand {
    margin-bottom: 12px;
  }

  .nav-list {
    width: 100%;
    max-width: 100%;
    grid-auto-flow: column;
    grid-auto-columns: max-content;
    overflow-x: auto;
    overflow-y: hidden;
    padding-bottom: 4px;
  }

  .sidebar-foot {
    display: none;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .stats-grid,
  .lower-grid,
  .mini-tests {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 560px) {
  .main-panel {
    padding: 22px 14px 32px;
  }

  .stats-grid,
  .lower-grid,
  .mini-tests {
    grid-template-columns: 1fr;
  }

  .stage {
    min-height: 380px;
  }

  .stage.is-extra-playing {
    min-height: 430px;
  }

  .aim-hud {
    top: 12px;
    left: 12px;
    right: 12px;
    justify-content: center;
    transform: none;
  }

  .sequence-hud {
    top: 12px;
    left: 12px;
    right: 12px;
    justify-content: center;
    transform: none;
  }

  .sequence-board {
    width: min(300px, calc(100% - 36px));
  }

  .leaderboard-heading {
    align-items: stretch;
    flex-direction: column;
  }

  .player-name-field {
    width: 100%;
  }

  .leaderboard-table {
    overflow-x: auto;
  }

  .leaderboard-row {
    grid-template-columns: 56px minmax(110px, 1fr) 100px 76px;
    min-width: 410px;
  }

  .extra-surface {
    padding: 70px 12px 12px;
  }

  .game-hud {
    top: 10px;
    left: 10px;
    right: 10px;
    justify-content: center;
    transform: none;
  }

  .face-grid { gap: 8px; }
}
