:root {
  color-scheme: light;
  --ink: #16211f;
  --muted: #5c6f6b;
  --line: #d8dfd9;
  --paper: #f7f4ed;
  --panel: #ffffff;
  --mint: #2f9d86;
  --coral: #e85d4f;
  --gold: #edb937;
  --blue: #3268a8;
  --black: #111817;
  --shadow: 0 20px 60px rgba(22, 33, 31, 0.12);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  color: var(--ink);
  font-family: "Segoe UI", "Noto Sans TC", system-ui, sans-serif;
  background:
    linear-gradient(90deg, rgba(47, 157, 134, 0.09) 1px, transparent 1px),
    linear-gradient(0deg, rgba(232, 93, 79, 0.08) 1px, transparent 1px),
    var(--paper);
  background-size: 38px 38px;
}

button,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  gap: 24px;
  min-height: 100vh;
  padding: 24px;
}

.game-rail {
  display: flex;
  flex-direction: column;
  gap: 22px;
  min-height: calc(100vh - 48px);
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.78);
  box-shadow: var(--shadow);
}

.brand-block {
  display: grid;
  grid-template-columns: 54px 1fr;
  gap: 12px;
  align-items: center;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 54px;
  height: 54px;
  border: 3px solid var(--black);
  border-radius: 6px;
  color: white;
  background: var(--black);
  font-weight: 900;
  letter-spacing: 0;
}

.brand-block h1,
.stage-header h2 {
  margin: 0;
  line-height: 1.05;
  letter-spacing: 0;
}

.brand-block h1 {
  font-size: 26px;
}

.brand-block p,
.eyebrow {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

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

.game-tab {
  display: grid;
  grid-template-columns: 42px 1fr;
  gap: 12px;
  align-items: center;
  width: 100%;
  min-height: 66px;
  padding: 10px 12px;
  border: 1px solid transparent;
  border-radius: 8px;
  color: var(--ink);
  text-align: left;
  background: transparent;
}

.game-tab:hover,
.game-tab.active {
  border-color: var(--black);
  background: #fff;
}

.game-tab.active {
  box-shadow: 5px 5px 0 var(--gold);
}

.game-icon {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border: 2px solid var(--black);
  border-radius: 6px;
  color: #fff;
  background: var(--mint);
  font-weight: 900;
}

.game-tab:nth-child(2) .game-icon {
  background: var(--coral);
}

.game-tab:nth-child(3) .game-icon {
  background: var(--blue);
}

.game-tab:nth-child(4) .game-icon {
  background: var(--gold);
  color: var(--black);
}

.game-tab:nth-child(5) .game-icon {
  background: var(--black);
}

.game-tab strong,
.game-tab small {
  display: block;
}

.game-tab small {
  margin-top: 3px;
  color: var(--muted);
}

.stage {
  min-width: 0;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.82);
  box-shadow: var(--shadow);
}

.stage-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
}

.stage-header h2 {
  font-size: clamp(34px, 5vw, 64px);
}

.score-strip,
.mini-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.score-strip span,
.mini-stats span {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 38px;
  padding: 7px 10px;
  border: 1px solid var(--black);
  border-radius: 6px;
  background: #fff;
  font-size: 14px;
  font-weight: 700;
}

.score-strip strong,
.mini-stats strong {
  font-size: 18px;
}

.game-panel {
  display: none;
}

.game-panel.active {
  display: block;
}

.snake-layout {
  display: grid;
  grid-template-columns: minmax(280px, 620px) minmax(220px, 300px);
  gap: 20px;
  align-items: start;
}

.canvas-frame,
.reaction-board,
.target-grid,
.memory-grid,
.number-game {
  border: 3px solid var(--black);
  border-radius: 8px;
  background: #fff;
}

.canvas-frame {
  position: relative;
  overflow: hidden;
  width: min(100%, 620px);
  aspect-ratio: 1;
  box-shadow: 8px 8px 0 var(--mint);
}

#snakeCanvas {
  display: block;
  width: 100%;
  height: 100%;
  background: #f9fbf6;
}

.game-overlay {
  position: absolute;
  inset: 0;
  display: none;
  place-items: center;
  gap: 14px;
  background: rgba(247, 244, 237, 0.88);
  text-align: center;
}

.game-overlay.show {
  display: grid;
}

.game-overlay strong {
  font-size: clamp(34px, 6vw, 70px);
  line-height: 1;
}

.control-panel,
.panel-top {
  display: flex;
  gap: 14px;
}

.control-panel {
  flex-direction: column;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfbf8;
}

.panel-top {
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.action-row {
  display: flex;
  gap: 10px;
}

.primary-action,
.icon-button,
.dpad button,
.memory-card,
.reaction-pad,
.target-cell,
.number-key,
select {
  border: 2px solid var(--black);
  border-radius: 6px;
  color: var(--black);
  background: #fff;
  box-shadow: 3px 3px 0 var(--black);
}

.primary-action {
  min-height: 42px;
  padding: 8px 16px;
  background: var(--gold);
  font-weight: 900;
}

.primary-action:active,
.icon-button:active,
.dpad button:active,
.memory-card:active,
.reaction-pad:active,
.target-cell:active,
.number-key:active {
  transform: translate(2px, 2px);
  box-shadow: 1px 1px 0 var(--black);
}

.icon-button {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  background: #fff;
  font-size: 22px;
}

.field-label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

select {
  width: 100%;
  min-height: 42px;
  padding: 6px 10px;
}

.dpad {
  display: grid;
  grid-template-columns: repeat(3, 54px);
  grid-template-rows: repeat(3, 54px);
  gap: 8px;
  justify-content: center;
  margin-top: 8px;
}

.dpad button {
  background: #fff;
  font-size: 20px;
  font-weight: 900;
}

.dpad button[data-dir="up"] {
  grid-column: 2;
}

.dpad button[data-dir="left"] {
  grid-column: 1;
  grid-row: 2;
}

.dpad button[data-dir="right"] {
  grid-column: 3;
  grid-row: 2;
}

.dpad button[data-dir="down"] {
  grid-column: 2;
  grid-row: 3;
}

.memory-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(62px, 1fr));
  gap: 12px;
  padding: 16px;
  max-width: 620px;
}

.memory-card {
  display: grid;
  place-items: center;
  aspect-ratio: 1;
  background: var(--blue);
  color: transparent;
  font-size: clamp(28px, 7vw, 54px);
  font-weight: 900;
  user-select: none;
}

.memory-card.flipped,
.memory-card.matched {
  background: #fff;
  color: var(--black);
}

.memory-card.matched {
  border-color: var(--mint);
  box-shadow: 3px 3px 0 var(--mint);
}

.reaction-wrap {
  max-width: 720px;
}

.reaction-board {
  display: grid;
  place-items: center;
  min-height: 360px;
  margin-bottom: 16px;
  background:
    radial-gradient(circle at center, rgba(237, 185, 55, 0.28) 0 14%, transparent 15%),
    #fff;
}

.reaction-pad {
  display: grid;
  place-items: center;
  width: min(260px, 70vw);
  aspect-ratio: 1;
  background: var(--coral);
  color: #fff;
  font-size: 34px;
  font-weight: 900;
}

.reaction-pad.ready {
  background: var(--mint);
}

.target-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(62px, 1fr));
  gap: 12px;
  padding: 16px;
  max-width: 620px;
}

.target-cell {
  aspect-ratio: 1;
  background: #fff;
}

.target-cell.active {
  background:
    radial-gradient(circle, var(--gold) 0 32%, transparent 34%),
    radial-gradient(circle, var(--coral) 0 52%, transparent 54%),
    var(--mint);
}

.number-game {
  display: grid;
  gap: 16px;
  max-width: 520px;
  padding: 18px;
}

.number-display {
  display: grid;
  place-items: center;
  min-height: 88px;
  border: 3px solid var(--black);
  border-radius: 8px;
  background: #f9fbf6;
  font-size: 48px;
  font-weight: 900;
  letter-spacing: 0;
}

.number-pad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.number-key {
  min-height: 58px;
  background: #fff;
  font-size: 24px;
  font-weight: 900;
}

.number-key.command {
  background: var(--gold);
  font-size: 18px;
}

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

  .game-rail {
    min-height: auto;
  }

  .game-list {
    grid-template-columns: repeat(5, minmax(132px, 1fr));
    overflow-x: auto;
    padding-bottom: 8px;
  }

  .game-tab {
    min-width: 132px;
  }

  .snake-layout {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .stage,
  .game-rail {
    padding: 14px;
  }

  .stage-header,
  .panel-top {
    align-items: flex-start;
    flex-direction: column;
  }

  .stage-header h2 {
    font-size: 36px;
  }

  .brand-block h1 {
    font-size: 22px;
  }

  .memory-grid,
  .target-grid {
    gap: 8px;
    padding: 10px;
  }

  .reaction-board {
    min-height: 280px;
  }
}
