:root {
  --bg: #11131a;
  --panel: #1b1f2b;
  --ink: #eef1f7;
  --muted: #aab4ca;          /* 4.5:1 on the page background */
  --accent: #5cc8ff;
  --good: #59d98b;
  --bad: #ff6b6b;
  --tap: 44px;              /* smallest comfortable touch target */
}
* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  /* dvh so mobile browser chrome sliding in and out cannot clip the board. */
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--ink);
  /* Games are tapped fast and repeatedly: no double-tap zoom, no grey flash,
     no accidental text selection from a quick double press. */
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  overscroll-behavior: none;
}

header {
  padding: 10px max(12px, env(safe-area-inset-left)) 10px max(12px, env(safe-area-inset-right));
  border-bottom: 1px solid #2a3040;
  flex: none;
}
h1 { margin: 0 0 6px; font-size: clamp(15px, 4vw, 20px); letter-spacing: .04em; }
#hud {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
  font-size: clamp(13px, 3.4vw, 16px);
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
#timer { color: var(--accent); }
#game-name { flex: 1 1 100%; }

main {
  flex: 1;
  min-height: 0;                /* let the board shrink instead of overflowing */
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: clamp(8px, 2vh, 24px) 12px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.panel, .game {
  width: min(560px, 100%);
  text-align: center;
}
.game {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(8px, 2vh, 16px);
  max-height: 100%;
}
.panel {
  background: var(--panel);
  border-radius: 14px;
  padding: clamp(16px, 4vw, 24px);
  max-height: 100%;
  overflow-y: auto;
}
.how {
  color: var(--muted);
  margin: 0;
  font-size: clamp(13px, 3.4vw, 16px);
  text-wrap: balance;
}
.result { font-size: clamp(32px, 10vw, 40px); margin: 8px 0; }
.record { color: var(--good); font-weight: 600; }

button {
  font: inherit;
  color: var(--ink);
  background: #2a3242;
  border: 1px solid #3a465c;
  border-radius: 10px;
  padding: 10px 18px;
  min-height: var(--tap);
  cursor: pointer;
  touch-action: manipulation;
}
/* Hover only where there is a real pointer — on touch it sticks after a tap. */
@media (hover: hover) {
  button:hover { background: #354054; }
  button.big:hover { filter: brightness(1.08); }
  .simon.live .pad:hover { opacity: .65; }
}
button:active { transform: scale(.97); }
button.big {
  font-size: clamp(16px, 4.4vw, 18px);
  padding: 14px 24px;
  background: var(--accent);
  color: #06202b;
  border: 0;
  font-weight: 600;
  margin-top: 12px;
  width: min(320px, 100%);
}
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
/* Focus lands on these containers programmatically; the ring would be noise. */
#stage:focus, .game:focus, .panel:focus { outline: none; }

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

table { width: 100%; margin: 8px 0 0; border-collapse: collapse; color: var(--muted); }
td { padding: 4px 0; text-align: left; font-variant-numeric: tabular-nums; }
td + td { text-align: right; }
h3 { margin: 16px 0 0; font-size: 16px; }
h4 {
  margin: 14px 0 0;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--muted);
}
footer {
  flex: none;
  padding: 8px 12px max(8px, env(safe-area-inset-bottom));
  text-align: center;
  min-height: 52px;
}

/* ---- shared game furniture ---- */

.stimulus {
  /* Scales with the smaller viewport axis, so it never eats a phone screen. */
  font-size: clamp(44px, 14vmin, 88px);
  font-weight: 700;
  line-height: 1.1;
  min-height: 1.4em;
  display: flex;
  align-items: center;
  justify-content: center;
}
.flash-good { animation: flash .3s; }
.flash-bad { animation: shake .3s; }
@keyframes flash { from { color: var(--good); } }
@keyframes shake {
  25% { transform: translateX(-8px); color: var(--bad); }
  75% { transform: translateX(8px); color: var(--bad); }
}
@media (prefers-reduced-motion: reduce) {
  .flash-good, .flash-bad, .simon.wrong, .spot.wrong { animation-duration: .01ms; }
  button:active { transform: none; }
}

.controls {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
  width: 100%;
}
.claim { flex: 1 1 auto; max-width: 220px; }

/* Boards sized by framework/layout.js: --cell comes from the space available. */
.board {
  display: grid;
  grid-template-columns: repeat(var(--cols), var(--cell, 64px));
  gap: var(--gap, 8px);
  justify-content: center;
  margin: 0 auto;
}
.board > * {
  width: var(--cell, 64px);
  height: calc(var(--cell, 64px) * var(--ratio, 1));
  /* Icons scale with their cell rather than a fixed point size. */
  font-size: calc(var(--cell, 64px) * .42);
  padding: 0;
  min-height: 0;
  line-height: 1;
}

.item-pad { max-width: 460px; }
.item {
  font-size: clamp(24px, 7vmin, 32px);
  min-width: var(--tap);
  min-height: var(--tap);
  padding: 4px 10px;
  line-height: 1;
}
.item-pad.locked { opacity: .35; pointer-events: none; }
.key { min-width: 52px; font-weight: 600; font-size: clamp(20px, 5.5vmin, 26px); }

.card { background: #2a3242; }
.card.up { background: #3d4a63; }
.card.done { background: #1f3a2c; border-color: #2f6b4a; opacity: .7; }

.pad {
  border: 0;
  border-radius: 12px;
  opacity: .62;
  transition: opacity .1s;
  cursor: default;
  color: #06202b;
  font-size: calc(var(--cell, 64px) * .3);
}
.simon.live .pad { cursor: pointer; }
.pad.lit { opacity: 1; }
.pad-green { background: #2fbf6b; }
.pad-red { background: #e0524f; }
.pad-yellow { background: #e5c04b; }
.pad-blue { background: #4b8fe5; }
.simon.wrong { animation: shake .3s; }

.spot {
  background: #232b3a;
  border: 1px dashed #3a465c;
  border-radius: 10px;
}
.spot.right { background: #1f3a2c; border-style: solid; border-color: #2f6b4a; }
.spot.wrong { animation: shake .3s; }
.item.held { outline: 2px solid var(--accent); }

.dual-grid .spot { border-style: solid; cursor: default; }
.spot.lit-cell { background: var(--accent); border-color: var(--accent); }
.dual-letter {
  font-size: clamp(34px, 9vmin, 52px);
  font-weight: 700;
  line-height: 1.2;
}

/* Landscape phones are short: put the board beside the rest instead of under it. */
@media (orientation: landscape) and (max-height: 480px) {
  h1 { display: none; }
  header { padding-top: 6px; padding-bottom: 6px; }
  #game-name { flex: 0 1 auto; }
  .game { flex-flow: row wrap; align-items: center; }
  .stimulus { font-size: clamp(36px, 16vh, 64px); min-height: 0; }
  .how { flex: 1 1 100%; }
  footer { min-height: 0; }
}

/* No keyboard, no key hints. */
@media (hover: none) and (pointer: coarse) {
  .keyhint { display: none; }
}

/* Respect a stated preference for more contrast. */
@media (prefers-contrast: more) {
  :root { --muted: #d5dcea; }
  button { border-color: #7b8aa6; }
  .pad { opacity: .85; }
  .spot { border-style: solid; border-color: #7b8aa6; }
}

/* Windows high contrast: system colours replace ours, so state that was
   carried by background colour needs a border to survive. */
@media (forced-colors: active) {
  .card.up, .card.done, .spot.right, .spot.lit-cell, .pad.lit {
    border: 3px solid Highlight;
  }
  .pad { opacity: 1; forced-color-adjust: none; }
  :focus-visible { outline: 3px solid Highlight; }
}
