:root {
  --bg: #11141b;
  --bg2: #161b25;
  --fg: #e7ecf3;
  --muted: #8b95a7;
  --accent: #4488ee;
  /* atom palette — reused semantically across the HUD */
  --red: #e8473f;
  --green: #37c46b;
  --blue: #4488ee;
  --steel: #9fb7d8;
  --hairline: rgba(159, 183, 216, 0.22);
  --mono: ui-monospace, "SFMono-Regular", "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; }
/* On a phone `100%` is the *large* viewport, so the bottom of the board hides
   behind the browser toolbar until you scroll.  dvh tracks the visible area. */
@supports (height: 100dvh) { html, body { height: 100dvh; } }
body {
  background: radial-gradient(1200px 800px at 50% -10%, #1d2533, var(--bg) 60%);
  color: var(--fg);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  display: flex; flex-direction: column;
  user-select: none; -webkit-user-select: none;
  overflow: hidden;
  overscroll-behavior: none;   /* no pull-to-refresh when a drag starts on the HUD */
}

/* HUD — a lean instrument panel, not a navbar.  Mono readouts, mode tabs
   colour-keyed to the R/G/B atoms, a faded steel hairline instead of a border. */
#hud {
  flex: 0 0 auto; position: relative;
  display: flex; align-items: center; gap: 22px;
  padding: 11px 22px 12px;
  background: linear-gradient(180deg, rgba(0,0,0,0.40), rgba(0,0,0,0.10));
}
#hud::after { /* hairline that fades out at both ends */
  content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 1px;
  background: linear-gradient(90deg, transparent, var(--hairline) 14%, var(--hairline) 86%, transparent);
}

.hud-mark { display: flex; align-items: center; gap: 11px; }
.hud-atom { /* the game's blue atom, drifting like the molecules behind it */
  width: 18px; height: 18px; flex: 0 0 auto;
  background: url(favicon.svg) center / contain no-repeat;
  animation: hud-bob 6.5s ease-in-out infinite;
}
@keyframes hud-bob {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  50%      { transform: translateY(-2px) rotate(9deg); }
}
.hud-title {
  margin: 0; white-space: nowrap;
  font-size: 13px; font-weight: 600; letter-spacing: 0.17em; text-transform: uppercase;
  color: #c4cee0;
}
.hud-title b { font-weight: 600; color: #fff; }

.hud-sep { width: 1px; height: 18px; background: var(--hairline); flex: 0 0 auto; }

.hud-modes { display: flex; align-items: center; gap: 20px; }
.mode {
  appearance: none; background: none; border: 0; padding: 3px 0 7px; cursor: pointer;
  font: 600 12.5px/1 var(--mono); letter-spacing: 0.03em; text-transform: lowercase;
  color: var(--muted); position: relative; transition: color .18s ease;
}
.mode:hover { color: var(--fg); }
.mode::after { /* sliding underline tick in the mode's own colour */
  content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 2px; border-radius: 1px;
  background: currentColor; transform: scaleX(0); transform-origin: left;
  transition: transform .22s cubic-bezier(.4, 0, .2, 1);
}
.mode.active::after { transform: scaleX(1); }
.mode[data-mode="standard"].active     { color: var(--red); }
.mode[data-mode="zen"].active          { color: var(--green); }
.mode[data-mode="tautological"].active { color: var(--blue); }

.hud-stats { margin-left: auto; display: flex; align-items: center; gap: 20px; }
.stat { display: flex; align-items: baseline; gap: 7px; }
.stat-k {
  font: 600 9.5px/1 var(--mono); letter-spacing: 0.22em; text-transform: uppercase;
  color: var(--muted);
}
.stat-v {
  font: 500 16px/1 var(--mono); color: var(--fg);
  font-variant-numeric: tabular-nums; min-width: 1.4ch; text-align: right;
}
.hud-icon {
  margin-left: 2px; width: 30px; height: 30px; border-radius: 7px; cursor: pointer;
  background: transparent; border: 1px solid var(--hairline); color: var(--steel);
  font-size: 15px; line-height: 1; display: grid; place-items: center;
  transition: transform .35s cubic-bezier(.4, 0, .2, 1), color .18s, border-color .18s;
}
.hud-icon:hover { color: var(--fg); border-color: rgba(159,183,216,0.5); }
/* only the reshuffle spins — a spinning speaker would read as a second action */
.hud-reset:hover { transform: rotate(-160deg); }
.hud-reset:active { transform: rotate(-300deg); }
.hud-mute svg { display: block; }
.hud-mute[aria-pressed="true"] { color: var(--muted); border-color: rgba(159,183,216,0.14); }

main { position: relative; flex: 1 1 auto; min-height: 0; }
#board { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }

.overlay {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  background: rgba(8,10,14,0.55); backdrop-filter: blur(3px);
  transition: opacity .25s;
}
.overlay.hidden { opacity: 0; pointer-events: none; }

/* result panel — same instrument language as the HUD: status tag, mono
   readout, faded hairline, colour keyed to outcome (green=solved, red=lost). */
.card {
  position: relative; overflow: hidden;
  min-width: 300px; max-width: 360px;
  padding: 26px 28px 24px; border-radius: 14px; text-align: left;
  background: linear-gradient(180deg, #1a2230, var(--bg2));
  border: 1px solid var(--hairline);
  box-shadow: 0 24px 70px rgba(0,0,0,0.55);
  transform: translateY(10px) scale(0.985);
  transition: transform .28s cubic-bezier(.2,.7,.2,1);
}
.overlay:not(.hidden) .card { transform: none; }
.card::before { /* status accent strip along the top edge */
  content: ""; position: absolute; top: 0; left: 0; right: 0; height: 2px;
  background: linear-gradient(90deg, transparent, var(--status), transparent);
}
.card.win  { --status: var(--green); --status-soft: rgba(55,196,107,0.14); }
.card.lose { --status: var(--red);   --status-soft: rgba(232,71,63,0.14); }

.card-tag {
  display: inline-block; margin-bottom: 12px;
  font: 600 10px/1 var(--mono); letter-spacing: 0.26em; text-transform: uppercase;
  color: var(--status);
}
.card-title { margin: 0; font-size: 24px; font-weight: 700; letter-spacing: -0.01em; color: #fff; }
.card-note { margin: 8px 0 0; color: var(--muted); font-size: 14px; line-height: 1.45; max-width: 30ch; }
.card-stat { margin-top: 18px; }
.card-stat .stat-v { font-size: 22px; }

.card-actions { display: flex; gap: 10px; margin-top: 24px; }
.btn-primary, .btn-ghost {
  font: 600 13px/1 var(--mono); letter-spacing: 0.02em; cursor: pointer;
  padding: 11px 16px; border-radius: 7px; border: 1px solid transparent;
  transition: filter .15s, color .15s, border-color .15s, background .15s;
}
.btn-primary { background: var(--status-soft); border-color: var(--status); color: var(--status); }
.btn-primary:hover { filter: brightness(1.25); }
.btn-ghost { background: transparent; border-color: var(--hairline); color: var(--muted); }
.btn-ghost:hover { border-color: rgba(159,183,216,0.5); color: var(--fg); }

@media (max-width: 600px) {
  /* Two rows rather than one cramped one: readouts and reset on top, the mode
     tabs given a full row of their own underneath.  Squeezing all of it onto a
     single line overflows a phone and pushes the reset button off the screen
     entirely, and leaves nothing tall enough to hit. */
  #hud { flex-wrap: wrap; gap: 8px 14px; padding: 8px 14px 0; }
  .hud-title, .hud-mark + .hud-sep { display: none; } /* drop wordmark, keep the atom */
  .hud-stats { gap: 16px; }

  .hud-modes { order: 2; width: 100%; justify-content: space-between; gap: 4px; }
  .mode {
    min-height: 44px; display: inline-flex; align-items: center;  /* touch target */
    padding: 3px 6px 7px;
  }

  .hud-icon { width: 44px; height: 44px; font-size: 18px; }
}

/* Everywhere: give the mode tabs a hit area past their ink without moving
   them.  The tabs are small type by design; this keeps the look and makes
   them reachable with a thumb. */
.mode::before { content: ""; position: absolute; inset: -11px -7px; }
