:root {
  color-scheme: light dark;
  --bg: #eef1ec;
  --surface: #f8f9f6;
  --surface-strong: #ffffff;
  --text: #1e2923;
  --muted: #647068;
  --line: #cfd7d0;
  --accent: #466b55;
  --accent-strong: #31533f;
  --accent-soft: #dce8df;
  --danger: #8c4b47;
  --shadow: 0 14px 35px rgba(43, 58, 48, 0.1);
  --radius: 18px;
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic UI", sans-serif;
  font-synthesis: none;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17201b;
    --surface: #202a24;
    --surface-strong: #29342d;
    --text: #edf2ed;
    --muted: #acb8af;
    --line: #3d4a41;
    --accent: #91b39b;
    --accent-strong: #bad0bf;
    --accent-soft: #2e4035;
    --danger: #e0a19a;
    --shadow: 0 14px 35px rgba(0, 0, 0, 0.24);
  }
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
}

body {
  min-height: 100dvh;
  overscroll-behavior: none;
}

button,
input {
  font: inherit;
}

button {
  touch-action: manipulation;
}

button:focus-visible,
input:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--accent) 65%, transparent);
  outline-offset: 3px;
}

.shell {
  width: min(100%, 520px);
  min-height: 100dvh;
  margin: 0 auto;
  padding: max(18px, env(safe-area-inset-top)) 18px max(24px, env(safe-area-inset-bottom));
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 52px;
  margin-bottom: 18px;
}

.brand {
  margin: 0;
  font-size: 1.05rem;
  letter-spacing: -0.02em;
}

.icon-button,
.text-button,
.primary-button,
.secondary-button,
.choice-button {
  border: 0;
  cursor: pointer;
  transition: transform 120ms ease, background-color 160ms ease;
}

.icon-button:active,
.text-button:active,
.primary-button:active,
.secondary-button:active,
.choice-button:active {
  transform: scale(0.98);
}

.icon-button {
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  border-radius: 50%;
  background: var(--surface);
  color: var(--text);
  font-size: 1.25rem;
}

.text-button {
  min-height: 44px;
  padding: 0 4px;
  background: transparent;
  color: var(--accent-strong);
  font-weight: 650;
}

.hero {
  padding: 8px 2px 24px;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--accent-strong);
  font-size: 0.75rem;
  font-weight: 750;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

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

h1 {
  max-width: 12ch;
  margin-bottom: 12px;
  font-size: clamp(2.15rem, 9vw, 3.15rem);
  line-height: 1.04;
  letter-spacing: -0.055em;
}

h2 {
  margin-bottom: 10px;
  font-size: 1.35rem;
  letter-spacing: -0.035em;
}

h3 {
  margin-bottom: 6px;
  font-size: 1rem;
}

.lede,
.muted,
.helper {
  color: var(--muted);
  line-height: 1.65;
}

.lede {
  max-width: 31rem;
  margin-bottom: 0;
}

.summary-strip {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1px;
  overflow: hidden;
  margin: 2px 0 22px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--line);
}

.summary-item {
  min-width: 0;
  padding: 15px 10px;
  background: var(--surface);
  text-align: center;
}

.summary-value {
  display: block;
  margin-bottom: 5px;
  font-size: 1.35rem;
  font-variant-numeric: tabular-nums;
  font-weight: 750;
}

.summary-label {
  display: block;
  color: var(--muted);
  font-size: 0.72rem;
}

.mode-list {
  display: grid;
  gap: 12px;
}

.mode-card {
  width: 100%;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  text-align: left;
}

.mode-card.primary {
  border-color: transparent;
  background: var(--accent-strong);
  color: #f6faf6;
  box-shadow: var(--shadow);
}

.mode-card p {
  margin: 0;
  color: inherit;
  line-height: 1.55;
  opacity: 0.82;
}

.mode-meta {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 18px;
  font-size: 0.82rem;
  font-weight: 650;
}

.section {
  margin-top: 26px;
}

.notice {
  padding: 16px 18px;
  border-left: 4px solid var(--accent);
  border-radius: 0 var(--radius) var(--radius) 0;
  background: var(--accent-soft);
  line-height: 1.55;
}

.history-list {
  display: grid;
  gap: 1px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--line);
}

.history-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  padding: 15px 16px;
  background: var(--surface);
}

.history-row strong,
.history-row span {
  display: block;
}

.history-row span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.82rem;
}

.history-score {
  align-self: center;
  font-variant-numeric: tabular-nums;
  font-weight: 750;
}

.screen {
  display: flex;
  min-height: calc(100dvh - max(36px, env(safe-area-inset-top)) - max(48px, env(safe-area-inset-bottom)));
  flex-direction: column;
}

.screen-header {
  display: grid;
  grid-template-columns: 44px 1fr 44px;
  align-items: center;
  min-height: 52px;
}

.screen-header h2 {
  margin: 0;
  text-align: center;
  font-size: 1rem;
}

.setup-panel,
.fatigue-panel,
.result-panel,
.calibration-panel {
  display: flex;
  flex: 1;
  flex-direction: column;
  justify-content: center;
}

.option-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin: 22px 0;
}

.option-button {
  min-height: 54px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  color: var(--text);
  font-weight: 700;
}

.option-button.selected {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.primary-button,
.secondary-button {
  width: 100%;
  min-height: 58px;
  border-radius: 15px;
  font-weight: 750;
}

.primary-button {
  background: var(--accent-strong);
  color: #f7faf7;
}

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

.secondary-button {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
}

.button-stack {
  display: grid;
  gap: 10px;
  margin-top: 22px;
}

.fatigue-value {
  margin: 24px 0 4px;
  font-size: 4rem;
  font-variant-numeric: tabular-nums;
  font-weight: 760;
  letter-spacing: -0.06em;
}

.range {
  width: 100%;
  margin: 22px 0 10px;
  accent-color: var(--accent-strong);
}

.range-labels {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: 0.78rem;
}

.training-shell {
  display: grid;
  min-height: 100dvh;
  grid-template-rows: auto minmax(280px, 1fr) auto;
  background: #888b88;
  color: #172019;
}

.game-training-shell {
  grid-template-rows: auto auto minmax(0, 1fr);
}

.training-top {
  display: grid;
  grid-template-columns: 48px 1fr 48px;
  align-items: center;
  padding: max(10px, env(safe-area-inset-top)) 14px 10px;
  background: var(--surface);
  color: var(--text);
}

.timer {
  text-align: center;
  font-size: 1rem;
  font-variant-numeric: tabular-nums;
  font-weight: 750;
}

.trial-stage {
  position: relative;
  display: grid;
  min-height: 0;
  place-items: center;
  overflow: hidden;
}

#stimulus-canvas,
#game-canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

.stage-message {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(238, 241, 236, 0.94);
  color: #1e2923;
  text-align: center;
}

.stage-message[hidden] {
  display: none;
}

.stage-message strong {
  display: block;
  margin-bottom: 8px;
  font-size: 1.5rem;
}

.answer-area {
  padding: 16px 18px max(18px, env(safe-area-inset-bottom));
  background: var(--surface);
  color: var(--text);
}

.prompt {
  min-height: 1.5em;
  margin-bottom: 12px;
  text-align: center;
  color: var(--muted);
  font-size: 0.9rem;
}

.choices {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.choice-button {
  min-height: 64px;
  border: 1px solid var(--line);
  border-radius: 15px;
  background: var(--surface-strong);
  color: var(--text);
  font-size: 1.05rem;
  font-weight: 760;
}

.choice-button:disabled {
  opacity: 0.45;
}

.game-instruction {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 84px;
  padding: 12px 16px;
  background: var(--surface);
  color: var(--text);
}

.sample-canvas {
  width: 64px;
  height: 64px;
  flex: 0 0 64px;
  border-radius: 12px;
  background: #888b88;
}

.game-score {
  margin-left: auto;
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-weight: 760;
}

.game-stage {
  min-height: 0;
}

.game-stage #game-canvas {
  min-height: 100%;
}

.result-number {
  margin: 18px 0 4px;
  font-size: 4.4rem;
  font-variant-numeric: tabular-nums;
  font-weight: 780;
  letter-spacing: -0.07em;
}

.result-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1px;
  overflow: hidden;
  margin-top: 24px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--line);
}

.result-cell {
  padding: 15px;
  background: var(--surface);
}

.result-cell span {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.75rem;
}

.rest-orb {
  display: grid;
  width: 190px;
  height: 190px;
  margin: 24px auto;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--accent-soft);
}

.rest-count {
  font-size: 4rem;
  font-variant-numeric: tabular-nums;
  font-weight: 760;
}

.calibration-line-wrap {
  display: grid;
  min-height: 120px;
  margin: 22px 0;
  place-items: center start;
  overflow: hidden;
  border-radius: var(--radius);
  background: var(--surface);
}

.calibration-line {
  height: 8px;
  border-radius: 8px;
  background: var(--accent-strong);
}

.settings-list {
  display: grid;
  gap: 12px;
}

.settings-row {
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.settings-row p {
  margin-bottom: 0;
  color: var(--muted);
  line-height: 1.55;
}

.danger-button {
  color: var(--danger);
}

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