:root {
  color-scheme: light;
  --bg: #eef2ef;
  --surface: #fffdf8;
  --surface-soft: #e7ece9;
  --surface-raised: #f9fbf7;
  --surface-quiet: rgba(255, 253, 248, 0.78);
  --surface-hover: #f1f7f2;
  --body-overlay: rgba(255,255,255,0.5);
  --ink: #1f2b2f;
  --muted: #5f6d70;
  --line: #cdd8d2;
  --accent: #2f5f7a;
  --accent-strong: #1d4b65;
  --accent-soft: #dbe9ef;
  --accent-warm: #a75447;
  --accent-warm-soft: #f1dfdc;
  --button-ink: #ffffff;
  --blue: #2865a8;
  --red: #b4473d;
  --green: #3b7a52;
  --yellow: #9a731b;
  --shadow: 0 14px 30px rgba(23, 43, 52, 0.1);
  --shadow-soft: 0 8px 18px rgba(23, 43, 52, 0.08);
  --shadow-raised: 0 10px 0 rgba(23, 43, 52, 0.05), 0 16px 30px rgba(23, 43, 52, 0.11);
  --shadow-pressed: 0 5px 12px rgba(23, 43, 52, 0.08);
  --button-lift: 0 5px 0 rgba(23, 43, 52, 0.1), var(--shadow-soft), var(--inner-light);
  --tile-lift: 0 4px 0 rgba(23, 43, 52, 0.06), var(--shadow-soft), var(--inner-light);
  --inner-light: inset 0 1px 0 rgba(255, 255, 255, 0.72);
  --edge-dark: rgba(23, 43, 52, 0.12);
  --board-shadow: 0 9px 0 rgba(23, 43, 52, 0.05), 0 18px 34px rgba(23, 43, 52, 0.12);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

html.mode-dark {
  color-scheme: dark;
  --bg: #101719;
  --surface: #1a2428;
  --surface-soft: #28363a;
  --surface-raised: #202c30;
  --surface-quiet: rgba(26, 36, 40, 0.88);
  --surface-hover: #253338;
  --body-overlay: rgba(255,255,255,0.04);
  --ink: #f2f6f5;
  --muted: #bdcbcb;
  --line: #425258;
  --accent: #8dc7df;
  --accent-strong: #bee6f2;
  --accent-soft: #243e49;
  --accent-warm: #e49a8d;
  --accent-warm-soft: #432f2f;
  --button-ink: #0e2028;
  --blue: #83b8ff;
  --red: #ff978d;
  --green: #93d7ad;
  --yellow: #f3d37b;
  --shadow: 0 14px 30px rgba(0, 0, 0, 0.28);
  --shadow-soft: 0 8px 18px rgba(0, 0, 0, 0.22);
  --shadow-raised: 0 10px 0 rgba(0, 0, 0, 0.18), 0 16px 30px rgba(0, 0, 0, 0.3);
  --shadow-pressed: 0 5px 12px rgba(0, 0, 0, 0.24);
  --button-lift: 0 5px 0 rgba(0, 0, 0, 0.24), var(--shadow-soft), var(--inner-light);
  --tile-lift: 0 4px 0 rgba(0, 0, 0, 0.2), var(--shadow-soft), var(--inner-light);
  --inner-light: inset 0 1px 0 rgba(255, 255, 255, 0.09);
  --edge-dark: rgba(0, 0, 0, 0.42);
  --board-shadow: 0 9px 0 rgba(0, 0, 0, 0.2), 0 18px 34px rgba(0, 0, 0, 0.34);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  min-height: 100%;
  margin: 0;
  overflow-x: hidden;
  color: var(--ink);
  background:
    linear-gradient(180deg, var(--body-overlay), rgba(255,255,255,0) 38%),
    var(--bg);
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  width: 100%;
  min-height: 100vh;
  padding: 16px 12px 28px;
}

.app {
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
}

.screen {
  display: grid;
  gap: 18px;
}

.panel {
  padding: 22px;
  border: 1px solid var(--line);
  border-bottom-color: var(--edge-dark);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(255,255,255,0.18), rgba(255,255,255,0) 42%),
    var(--surface);
  box-shadow: var(--shadow-raised), var(--inner-light);
}

.quiet-panel {
  padding: 18px;
  border: 1px solid var(--line);
  border-bottom-color: var(--edge-dark);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(255,255,255,0.14), rgba(255,255,255,0) 46%),
    var(--surface-quiet);
  box-shadow: var(--shadow-soft), var(--inner-light);
}

.stack {
  display: grid;
  gap: 12px;
}

.app-stage {
  max-width: 640px;
  margin: 0 auto;
}

.app-title-panel,
.screen-title,
.play-panel,
.game-board {
  position: relative;
  overflow: hidden;
}

.app-title-panel::before,
.screen-title::before,
.game-board::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 5px;
  background: var(--accent);
}

.app-title-panel::after {
  content: "";
  position: absolute;
  right: 18px;
  top: 18px;
  width: 42px;
  height: 42px;
  border: 1px solid var(--accent-warm);
  border-radius: 50%;
  opacity: 0.26;
}

.app-status-grid .status-box,
.result-board .result-box {
  background:
    linear-gradient(180deg, rgba(255,255,255,0.34), rgba(255,255,255,0)),
    var(--surface-raised);
  box-shadow: var(--shadow-soft), var(--inner-light);
}

.play-panel {
  border-color: color-mix(in srgb, var(--accent) 28%, var(--line));
}

.home-actions .main-action {
  min-height: 64px;
  font-size: 1.05rem;
}

.notice-scroll {
  border-left: 5px solid var(--accent-warm);
}

.sound-card,
.settings-card,
.result-note {
  border-left: 5px solid var(--accent);
}

.quiz-scroll {
  padding: 14px;
}

.quiz-card-list {
  display: grid;
  gap: 8px;
  padding: 0;
  margin: 0;
  list-style: none;
}

.quiz-card {
  display: grid;
  grid-template-columns: 38px 1fr;
  align-items: center;
  gap: 10px;
  min-height: 52px;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-bottom-color: var(--edge-dark);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(255,255,255,0.24), rgba(255,255,255,0)),
    var(--surface);
  box-shadow: var(--shadow-soft), var(--inner-light);
}

.quiz-card-index {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-weight: 800;
}

.quiz-card-label {
  font-weight: 750;
  line-height: 1.45;
}

.action-dock {
  position: sticky;
  bottom: 10px;
  z-index: 2;
  padding: 10px;
  border: 1px solid var(--line);
  border-bottom-color: var(--edge-dark);
  border-radius: 8px;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  box-shadow: var(--shadow-raised), var(--inner-light);
  backdrop-filter: blur(10px);
}

.training-screen {
  min-height: calc(100vh - 44px);
  align-content: center;
}

.game-board {
  padding: 18px;
  box-shadow: var(--board-shadow), var(--inner-light);
}

.quiz-hud {
  min-height: 44px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-bottom-color: var(--edge-dark);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(255,255,255,0.22), rgba(255,255,255,0)),
    var(--surface-raised);
  box-shadow: var(--shadow-soft), var(--inner-light);
}

.board-exit {
  justify-self: center;
}

.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.brand {
  display: grid;
  gap: 8px;
}

.eyebrow {
  margin: 0;
  color: var(--accent);
  font-size: 0.92rem;
  font-weight: 700;
}

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

h1 {
  font-size: clamp(2rem, 10vw, 3.4rem);
  line-height: 1.08;
  font-weight: 750;
  letter-spacing: 0;
}

h2 {
  font-size: 1.48rem;
  line-height: 1.25;
  letter-spacing: 0;
}

h3 {
  font-size: 1.06rem;
  line-height: 1.35;
}

p,
li {
  line-height: 1.75;
}

.lead {
  color: var(--muted);
  font-size: 1.02rem;
}

.small {
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.65;
}

.status-grid,
.result-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

.status-box,
.result-box {
  min-height: 82px;
  padding: 14px;
  border: 1px solid var(--line);
  border-bottom-color: var(--edge-dark);
  border-radius: 8px;
  background: var(--surface-raised);
}

.status-label,
.result-label {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 0.84rem;
}

.status-value,
.result-value {
  font-weight: 700;
  line-height: 1.4;
}

.button-row {
  display: grid;
  gap: 10px;
}

.button {
  min-height: 52px;
  width: 100%;
  padding: 13px 16px;
  border: 1px solid transparent;
  border-bottom-color: color-mix(in srgb, var(--edge-dark) 55%, transparent);
  border-radius: 8px;
  background: var(--accent);
  color: var(--button-ink);
  font-weight: 700;
  text-align: center;
  box-shadow: var(--button-lift);
  transition: background-color 160ms ease, border-color 160ms ease, box-shadow 160ms ease, transform 120ms ease;
}

.button:hover,
.button:focus-visible {
  background: var(--accent-strong);
}

.button.secondary {
  border-color: var(--line);
  border-bottom-color: var(--edge-dark);
  background: var(--surface);
  color: var(--ink);
}

.button.secondary:hover,
.button.secondary:focus-visible {
  border-color: var(--accent);
  background: var(--surface-hover);
}

.background-links {
  display: grid;
  gap: 10px;
}

.background-links .button {
  display: flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
}

.button.subtle {
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.button.text {
  min-height: 44px;
  width: auto;
  padding: 8px 4px;
  border: 0;
  background: transparent;
  color: var(--accent-strong);
  box-shadow: none;
  font-weight: 700;
  text-decoration: underline;
  text-underline-offset: 4px;
}

.button:disabled {
  cursor: default;
  opacity: 0.58;
  box-shadow: none;
  transform: none;
}

.button:not(.text):active {
  transform: translateY(2px);
  box-shadow: var(--shadow-pressed), var(--inner-light);
}

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

.number-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
}

.number-button {
  aspect-ratio: 1;
  min-height: 48px;
  border: 1px solid var(--line);
  border-bottom-color: var(--edge-dark);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  font-weight: 750;
  box-shadow: var(--tile-lift);
  transition: background-color 160ms ease, border-color 160ms ease, box-shadow 160ms ease, transform 120ms ease;
}

.number-button.selected {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent-strong);
  box-shadow: var(--shadow-pressed), var(--inner-light);
}

.number-button:active,
.sequence-button:active,
.shape-button:active,
.compare-number:active {
  transform: translateY(2px);
  box-shadow: var(--shadow-pressed), var(--inner-light);
}

.question {
  padding: 18px;
  border: 1px solid var(--line);
  border-bottom-color: var(--edge-dark);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(255,255,255,0.28), rgba(255,255,255,0)),
    var(--surface-raised);
  box-shadow: var(--shadow-soft), var(--inner-light);
  text-align: center;
}

.question-main {
  font-size: clamp(2rem, 12vw, 4rem);
  line-height: 1.1;
  font-weight: 750;
  letter-spacing: 0;
}

.feedback {
  min-height: 36px;
  color: var(--accent-strong);
  font-weight: 700;
  line-height: 1.6;
}

.phase-label {
  display: inline-block;
  margin: 8px auto 12px;
  padding: 4px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--accent-strong);
  background: var(--accent-soft);
  font-size: 0.9rem;
  font-weight: 700;
}

.progress {
  width: 100%;
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--surface-soft);
}

/* Native values replace inline widths while keeping the existing bar design. */
progress.progress,
progress.bar {
  display: block;
  width: 100%;
  border: 0;
  appearance: none;
  -webkit-appearance: none;
  color: var(--accent);
}

progress::-webkit-progress-bar {
  border-radius: inherit;
  background: var(--surface-soft);
}

progress::-webkit-progress-value {
  border-radius: inherit;
  background: var(--accent);
}

progress::-moz-progress-bar {
  border-radius: inherit;
  background: var(--accent);
}

.memory-display {
  display: flex;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
  font-size: clamp(2rem, 12vw, 4.2rem);
  font-weight: 750;
  line-height: 1.1;
}

.short-text-display {
  margin-top: 8px;
  font-size: clamp(1.45rem, 7vw, 2.6rem);
  line-height: 1.45;
  font-weight: 750;
}

.text-choice {
  min-height: 64px;
  line-height: 1.5;
}

.sound-options,
.reasoning-choice-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.reasoning-choice-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.reasoning-choice {
  min-height: 72px;
  font-size: clamp(1.2rem, 6vw, 2rem);
}

.reasoning-prompt,
.analogy-prompt {
  margin-top: 12px;
  font-size: clamp(1.55rem, 7vw, 2.8rem);
  line-height: 1.4;
  font-weight: 750;
}

.image-memory-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  width: 100%;
  max-width: 660px;
  margin-inline: auto;
}

.image-memory-card {
  display: grid;
  justify-items: center;
  align-content: center;
  gap: 4px;
  min-width: 0;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  color: var(--ink);
  overflow-wrap: anywhere;
}

.image-memory-card svg {
  display: block;
  width: clamp(64px, 18vw, 110px);
  max-width: 100%;
  height: auto;
  background: #fffdf8;
  border-radius: 8px;
}

.image-memory-card[aria-pressed="true"] {
  outline: 3px solid var(--ink);
  outline-offset: -4px;
}

.image-memory-card:disabled {
  opacity: 1;
}

.image-memory-status {
  min-height: 1.5em;
  font-size: 0.85em;
}

.image-memory-study {
  max-width: 440px;
}

@media (min-width: 560px) {
  .image-memory-grid:not(.image-memory-study) {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

.matrix-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 104px));
  justify-content: center;
  gap: 10px;
  margin-top: 14px;
}

.matrix-grid-three {
  grid-template-columns: repeat(3, minmax(0, 104px));
  gap: 6px;
}

.matrix-grid-three .matrix-cell {
  min-width: 0;
  font-size: clamp(1.25rem, 5vw, 2rem);
}

.logic-prompt,
.reasoning-rule {
  overflow-wrap: anywhere;
  line-height: 1.7;
}

.logic-prompt {
  font-size: 1.15rem;
}

.reasoning-choice {
  overflow-wrap: anywhere;
  min-width: 0;
}

.matrix-cell {
  min-width: 0;
  padding: 4px;
  display: grid;
  place-items: center;
  min-height: 68px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  color: var(--ink);
  font-size: clamp(2rem, 10vw, 3.5rem);
  font-weight: 750;
}

.matrix-symbols {
  display: block;
  width: 100%;
  min-width: 0;
  max-width: 100%;
  height: clamp(32px, 12vw, 64px);
}

.matrix-choice {
  padding: 8px;
}

.sequence-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
  margin-top: 12px;
}

.sequence-button {
  aspect-ratio: 1;
  min-height: 50px;
  border: 1px solid var(--line);
  border-bottom-color: var(--edge-dark);
  border-radius: 999px;
  background: var(--surface);
  color: var(--ink);
  font-size: 1.2rem;
  font-weight: 750;
  box-shadow: var(--tile-lift);
  transition: background-color 160ms ease, border-color 160ms ease, box-shadow 160ms ease, transform 120ms ease;
}

.sequence-button.active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent-strong);
  box-shadow: var(--shadow-pressed), var(--inner-light);
}

.compare-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-top: 14px;
}

.compare-number {
  min-height: 88px;
  border: 1px solid var(--line);
  border-bottom-color: var(--edge-dark);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  font-size: clamp(2rem, 12vw, 4rem);
  font-weight: 750;
  box-shadow: var(--button-lift);
  transition: background-color 160ms ease, border-color 160ms ease, box-shadow 160ms ease, transform 120ms ease;
}

.word-prompt {
  margin-top: 8px;
  font-size: clamp(1.8rem, 9vw, 3rem);
  line-height: 1.25;
  font-weight: 750;
}

.shape-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
  margin-top: 12px;
}

.shape-button {
  aspect-ratio: 1;
  min-height: 50px;
  border: 1px solid var(--line);
  border-bottom-color: var(--edge-dark);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  font-size: 1.35rem;
  font-weight: 750;
  box-shadow: var(--tile-lift);
  transition: background-color 160ms ease, border-color 160ms ease, box-shadow 160ms ease, transform 120ms ease;
}

.shape-button.active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent-strong);
  box-shadow: var(--shadow-pressed), var(--inner-light);
}

.color-instruction {
  font-size: 1.2rem;
  font-weight: 750;
  line-height: 1.5;
}

/* Fixed task colors must remain independent of the display theme. */
.color-word[data-ink="red"] { color: #D32F2F; }
.color-word[data-ink="blue"] { color: #1976D2; }
.color-word[data-ink="green"] { color: #388E3C; }
.color-word[data-ink="yellow"] { color: #FDD835; }

.color-word {
  /* 課題の固定色を、表示テーマに依存しない背景で識別する。 */
  background: #171717;
  padding: 16px;
  border-radius: 8px;
  font-size: clamp(2.4rem, 14vw, 5rem);
  line-height: 1;
  font-weight: 800;
}


.history-list {
  display: grid;
  gap: 10px;
}

.history-month-panel {
  display: grid;
  gap: 8px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  box-shadow: var(--shadow-soft), var(--inner-light);
}

.history-month-panel label {
  font-weight: 750;
}

.history-month-panel select {
  width: 100%;
  min-height: 48px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-raised);
  color: var(--ink);
  font: inherit;
}

.history-more {
  width: 100%;
}

.history-item {
  padding: 14px;
  border: 1px solid var(--line);
  border-bottom-color: var(--edge-dark);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(255,255,255,0.2), rgba(255,255,255,0)),
    var(--surface-raised);
  box-shadow: var(--shadow-soft), var(--inner-light);
}

.bar {
  height: 8px;
  margin-top: 10px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--surface-soft);
}

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.setting-text {
  flex: 1 1 200px;
  display: grid;
  gap: 4px;
}

.setting-actions {
  flex: 1 1 220px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.button.setting-toggle {
  width: auto;
  min-width: 96px;
  flex: 0 0 auto;
}

.app-shell {
  background:
    radial-gradient(circle at 18% 12%, color-mix(in srgb, var(--accent-soft) 52%, transparent) 0 90px, transparent 91px),
    radial-gradient(circle at 90% 24%, color-mix(in srgb, var(--accent-warm-soft) 45%, transparent) 0 80px, transparent 81px),
    linear-gradient(180deg, color-mix(in srgb, var(--surface-soft) 44%, transparent), transparent 36%),
    var(--bg);
}

.app-frame {
  position: relative;
  width: min(100%, calc(100vw - 24px));
  max-width: 330px;
  min-height: calc(100vh - 44px);
  align-content: start;
  padding: 10px;
  border: 1px solid color-mix(in srgb, var(--line) 82%, transparent);
  border-radius: 18px;
  background:
    linear-gradient(180deg, color-mix(in srgb, var(--surface) 84%, transparent), color-mix(in srgb, var(--surface-soft) 30%, transparent)),
    var(--surface-quiet);
  box-shadow: var(--shadow-raised), var(--inner-light);
}

.app-frame::before {
  content: "";
  position: absolute;
  inset: 9px;
  z-index: 0;
  border: 1px solid color-mix(in srgb, var(--accent) 18%, transparent);
  border-radius: 14px;
  pointer-events: none;
}

.app-frame > * {
  position: relative;
  z-index: 1;
}

.menu-board,
.stage-shell,
.stage-select-board,
.home-start-pad,
.sub-panel {
  border: 1px solid var(--line);
  border-bottom-color: var(--edge-dark);
  border-radius: 12px;
  background:
    linear-gradient(180deg, rgba(255,255,255,0.24), rgba(255,255,255,0) 48%),
    var(--surface);
  box-shadow: var(--shadow-soft), var(--inner-light);
}

.menu-board {
  display: grid;
  gap: 8px;
  padding: 20px;
}

.home-screen {
  gap: 12px;
}

.home-title-board {
  min-height: 178px;
  align-content: center;
  overflow: hidden;
}

.home-title-board h1 {
  font-size: clamp(1.8rem, 8.5vw, 2.6rem);
}

.home-status-deck {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

.status-token {
  min-height: 76px;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background:
    linear-gradient(180deg, rgba(255,255,255,0.22), rgba(255,255,255,0)),
    var(--surface-raised);
  box-shadow: var(--tile-lift);
}

.home-start-pad {
  display: grid;
  gap: 10px;
  padding: 18px;
}

.home-start-pad .main-action {
  min-height: 76px;
  border-radius: 14px;
  font-size: 1.08rem;
}

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

.home-site-link {
  grid-column: 1 / -1;
  justify-content: center;
  text-align: center;
}

.sub-screen {
  gap: 12px;
}

.sub-panel {
  padding: 16px;
}

.stage-select-board {
  padding: 14px;
}

.stage-shell {
  display: grid;
  gap: 12px;
  min-height: calc(100vh - 86px);
  padding: 14px;
}

.stage-hud {
  display: grid;
  gap: 9px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background:
    linear-gradient(180deg, color-mix(in srgb, var(--accent-soft) 40%, transparent), transparent),
    var(--surface-raised);
  box-shadow: var(--tile-lift);
}

.stage-hud .row {
  min-height: auto;
  padding: 0;
  border: 0;
  background: transparent;
  box-shadow: none;
}

.stage-board {
  display: grid;
  gap: 10px;
  align-content: center;
  min-height: 222px;
  padding: 12px;
  border: 1px solid color-mix(in srgb, var(--accent) 28%, var(--line));
  border-radius: 16px;
  background:
    linear-gradient(180deg, rgba(255,255,255,0.2), rgba(255,255,255,0) 48%),
    color-mix(in srgb, var(--surface-raised) 82%, var(--accent-soft));
  box-shadow: var(--board-shadow), var(--inner-light);
}

.question-plate {
  min-height: 138px;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 8px;
  padding: 20px 14px;
  border-radius: 14px;
}

.stage-log {
  display: grid;
  gap: 2px;
  min-height: 54px;
  padding: 10px 12px;
  border: 1px solid color-mix(in srgb, var(--line) 78%, transparent);
  border-radius: 10px;
  background: color-mix(in srgb, var(--surface) 72%, transparent);
}

.stage-log .feedback {
  min-height: 28px;
}

.answer-pad {
  padding: 12px;
  border: 1px solid var(--line);
  border-bottom-color: var(--edge-dark);
  border-radius: 16px;
  background:
    linear-gradient(180deg, rgba(255,255,255,0.18), rgba(255,255,255,0)),
    var(--surface-quiet);
  box-shadow: var(--shadow-soft), var(--inner-light);
}

.answer-pad.number-grid {
  gap: 9px;
}

.answer-pad.choice-grid,
.answer-pad.compare-grid {
  gap: 10px;
}

.answer-pad.sequence-grid,
.answer-pad.shape-grid {
  gap: 9px;
  margin-top: 0;
}

.answer-pad .button,
.answer-pad .number-button,
.answer-pad .sequence-button,
.answer-pad .shape-button,
.answer-pad .compare-number {
  border-radius: 12px;
}

.answer-pad .button {
  min-height: 62px;
}

.answer-pad .number-button,
.answer-pad .sequence-button,
.answer-pad .shape-button {
  min-height: 54px;
}

.answer-pad .compare-number {
  min-height: 108px;
}

.control-pad {
  border-radius: 14px;
}

.history-scroll.stage-select-board {
  display: grid;
  gap: 10px;
}

.result-board.stage-select-board {
  display: grid;
}

.setting-row {
  padding: 4px;
}

html.mode-large-text {
  font-size: 112.5%;
}

html.mode-large-text .button {
  min-height: 58px;
}

html.mode-large-text .button.text {
  min-height: 48px;
}

html.mode-large-text .number-button {
  min-height: 54px;
}

html.mode-large-text .sequence-button,
html.mode-large-text .shape-button {
  min-height: 56px;
}

html.mode-large-text .text-choice {
  min-height: 72px;
}

html.mode-large-text .reasoning-choice {
  min-height: 80px;
}

html.mode-large-text .compare-number {
  min-height: 96px;
}

html.mode-large-text .quiz-card {
  min-height: 58px;
}

html.mode-large-text .home-start-pad .main-action {
  min-height: 84px;
}

html.mode-large-text .answer-pad .button {
  min-height: 70px;
}

html.mode-large-text .stage-log {
  min-height: 64px;
}

html.mode-low-stim *,
html.mode-low-stim *::before,
html.mode-low-stim *::after {
  transition: none !important;
}

html.mode-low-stim body {
  background: var(--bg);
}

html.mode-low-stim .panel {
  box-shadow: none;
}

html.mode-low-stim .action-dock,
html.mode-low-stim .app-frame,
html.mode-low-stim .menu-board,
html.mode-low-stim .stage-shell,
html.mode-low-stim .stage-select-board,
html.mode-low-stim .home-start-pad,
html.mode-low-stim .status-token,
html.mode-low-stim .sub-panel,
html.mode-low-stim .stage-hud,
html.mode-low-stim .stage-board,
html.mode-low-stim .stage-log,
html.mode-low-stim .answer-pad,
html.mode-low-stim .game-board,
html.mode-low-stim .quiet-panel,
html.mode-low-stim .status-box,
html.mode-low-stim .result-box,
html.mode-low-stim .quiz-card,
html.mode-low-stim .quiz-hud,
html.mode-low-stim .question,
html.mode-low-stim .history-item,
html.mode-low-stim .button,
html.mode-low-stim .number-button,
html.mode-low-stim .sequence-button,
html.mode-low-stim .shape-button,
html.mode-low-stim .compare-number,
html.mode-low-stim .matrix-cell {
  box-shadow: none;
}

html.mode-low-stim .app-frame::before {
  opacity: 0.35;
}

html.mode-low-stim .button:active,
html.mode-low-stim .number-button:active,
html.mode-low-stim .sequence-button:active,
html.mode-low-stim .shape-button:active,
html.mode-low-stim .compare-number:active {
  transform: none;
}

html.mode-low-stim .app-title-panel::after {
  display: none;
}

html.mode-low-stim .sequence-button.active,
html.mode-low-stim .shape-button.active {
  border-color: var(--accent);
  background: var(--surface-soft);
  color: var(--ink);
}

.link-button {
  display: grid;
  place-items: center;
  text-decoration: none;
}

.consent-note {
  text-align: center;
}

.consent-screen {
  position: relative;
  overflow: hidden;
  gap: 18px;
}

.consent-screen::before {
  content: "";
  position: absolute;
  inset: -20% -40% auto;
  height: 360px;
  background:
    radial-gradient(circle at 42% 42%, rgba(84, 174, 162, 0.2), transparent 34%),
    radial-gradient(circle at 64% 30%, rgba(52, 91, 128, 0.18), transparent 31%);
  pointer-events: none;
}

.consent-hero,
.consent-summary,
.consent-form,
.consent-declined-card {
  position: relative;
  z-index: 1;
}

.consent-hero {
  padding: clamp(26px, 8vw, 50px) 20px 24px;
  text-align: center;
}

.consent-hero h1,
.consent-declined-card h1 {
  margin: 8px 0 10px;
  font-size: clamp(1.75rem, 8vw, 2.8rem);
  letter-spacing: 0.04em;
}

.consent-orbit {
  position: relative;
  width: 78px;
  height: 78px;
  margin: 0 auto 18px;
  border: 1px solid var(--accent);
  border-radius: 50%;
  opacity: 0.9;
}

.consent-orbit::before,
.consent-orbit::after {
  content: "";
  position: absolute;
  inset: 14px;
  border: 1px solid var(--accent-strong);
  border-radius: 43% 57% 52% 48%;
  opacity: 0.55;
  transform: rotate(36deg);
}

.consent-orbit::after {
  inset: 26px;
  border-radius: 50%;
  background: var(--accent);
  opacity: 0.8;
}

.consent-orbit span {
  position: absolute;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent-strong);
}

.consent-orbit span:nth-child(1) { top: 7px; left: 35px; }
.consent-orbit span:nth-child(2) { right: 5px; bottom: 22px; }
.consent-orbit span:nth-child(3) { left: 8px; bottom: 15px; }

.consent-summary,
.consent-form,
.consent-checks {
  display: grid;
  gap: 12px;
}

.consent-summary-item {
  display: grid;
  grid-template-columns: 36px 1fr;
  align-items: start;
  gap: 10px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface-quiet);
}

.consent-summary-item span {
  color: var(--accent-strong);
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.08em;
}

.consent-summary-item p {
  margin: 0;
  line-height: 1.6;
}

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

.consent-document-card {
  display: grid;
  gap: 5px;
  min-width: 0;
  padding: 15px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-soft);
  text-decoration: none;
}

.consent-document-card:hover {
  border-color: var(--accent);
}

.consent-document-card:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 3px;
}

.consent-document-card strong {
  font-size: 1rem;
  overflow-wrap: anywhere;
}

.consent-document-card > span:last-child {
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.5;
}

.consent-document-label {
  color: var(--accent-strong);
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.consent-check {
  display: flex;
  align-items: flex-start;
  gap: 11px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  font-weight: 700;
  line-height: 1.55;
}

.consent-check input {
  flex: 0 0 auto;
  width: 1.3rem;
  height: 1.3rem;
  margin: 0.12rem 0 0;
  accent-color: var(--accent-strong);
}

.consent-message {
  min-height: 1.5em;
  margin: 0;
  color: var(--muted);
  text-align: center;
}

.consent-actions .button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.consent-declined-card {
  display: grid;
  gap: 14px;
  margin: auto 0;
  padding: clamp(24px, 7vw, 42px);
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--surface);
  box-shadow: var(--shadow);
  text-align: center;
}

html.mode-low-stim .consent-screen::before,
html.mode-low-stim .consent-orbit {
  display: none;
}

html.mode-low-stim .consent-document-card,
html.mode-low-stim .consent-declined-card {
  box-shadow: none;
}

.hidden {
  display: none !important;
}

@media (min-width: 620px) {
  .button-row {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .status-grid,
  .result-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .number-grid {
    grid-template-columns: repeat(7, minmax(0, 1fr));
  }
}

/* Keep Safari's multiline focus ring rectangular on phone screens. */
@media (max-width: 559px) {
  .consent-hero h1 {
    padding: 4px 6px;
    border-radius: 4px;
    overflow-wrap: anywhere;
  }

  .consent-hero h1:focus {
    outline: 2px solid #78baff;
    outline-offset: 2px;
  }

  .consent-orbit {
    width: 78px;
    height: auto;
    aspect-ratio: 1 / 1;
    flex-shrink: 0;
  }

  .consent-orbit::before {
    border-radius: 50%;
    transform: none;
  }
}

@media (max-width: 420px) {
  .app-shell {
    padding-inline: 10px;
  }

  .app-frame {
    width: calc(100vw - 20px);
    max-width: none;
    padding: 9px;
  }

  .panel {
    padding: 18px;
  }

  .home-status-deck {
    grid-template-columns: 1fr;
  }

  .home-title-board h1 {
    font-size: clamp(1.7rem, 8vw, 2.3rem);
  }

  .choice-grid {
    grid-template-columns: 1fr;
  }

  .sound-options {
    grid-template-columns: 1fr;
  }

  .consent-documents {
    grid-template-columns: 1fr;
  }

  .sequence-grid {
    gap: 6px;
  }

  .shape-grid {
    gap: 6px;
  }
}

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