/* 429 – monospaced HTTP-error / console aesthetic
   Machine voice: IBM Plex Mono (wordmark, status lines, cells, chrome).
   Human voice: Atkinson Hyperlegible (taglines, facts, help prose).
   Signature: the six-block rate-limit pip meter. */

:root {
  --bg: #0a0e14;
  --surface: #111823;
  --line: #263041;
  --text: #e6edf3;
  --dim: #7d8590;
  --amber: #ffa733;          /* near AWS orange, deliberately not #ff9900 */
  --amber-glow: 255, 167, 51;
  --ok: #2ea043;
  --ok-text: #3fb950;
  --warn: #b98a1c;
  --mono: 'IBM Plex Mono', ui-monospace, Consolas, Menlo, monospace;
  --sans: 'Atkinson Hyperlegible', system-ui, -apple-system, sans-serif;
}

:root[data-theme="light"] {
  --bg: #f7f6f2;
  --surface: #ffffff;
  --line: #d5d9e0;
  --text: #1b222b;
  --dim: #5b6570;
  --amber: #e07f00;
  --amber-glow: 224, 127, 0;
  --ok: #2f9e44;
  --ok-text: #2b8a3e;
  --warn: #c9930a;
}

/* Colourblind mode: daily-game convention orange/blue, distinct from brand amber */
:root[data-cb="1"] {
  --ok: #f5793a;
  --ok-text: #f5793a;
  --warn: #4a8fd4;
}
:root[data-cb="1"][data-theme="light"] {
  --ok: #e5601f;
  --ok-text: #c74e12;
  --warn: #2f76c0;
}

* { box-sizing: border-box; margin: 0; }

[hidden] { display: none !important; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--mono);
  font-size: 15px;
  line-height: 1.55;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 1.5rem 1rem;
}

.prose { font-family: var(--sans); }

a:focus-visible, button:focus-visible, input:focus-visible {
  outline: 2px solid var(--amber);
  outline-offset: 2px;
}

/* --- rate-limit pips (the signature) --- */

.pips { display: flex; gap: 6px; }
.pips span {
  width: 22px;
  height: 10px;
  background: var(--amber);
  box-shadow: 0 0 10px rgba(var(--amber-glow), 0.35);
}
.pips span.used {
  background: transparent;
  border: 1px solid var(--line);
  box-shadow: none;
}

/* --- intro: centered error-page hero --- */

#intro {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 1.1rem;
  padding-bottom: 8vh;
}

.wordmark {
  font-size: clamp(4.5rem, 16vw, 7.5rem);
  font-weight: 700;
  line-height: 1;
  letter-spacing: -0.04em;
  color: var(--amber);
  text-shadow: 0 0 40px rgba(var(--amber-glow), 0.25);
}

.caret {
  display: inline-block;
  width: 0.5em;
  height: 0.82em;
  margin-left: 0.08em;
  background: var(--amber);
  animation: blink 1.1s steps(1) infinite;
}
/* the caret hangs outside the centering box so "429" stays optically centered */
.wordmark .caret { margin-right: -0.58em; }

#intro h1 {
  font-size: clamp(1.1rem, 4vw, 1.5rem);
  font-weight: 600;
  letter-spacing: 0.35em;
  margin-right: -0.35em; /* optically recenter tracked caps */
  text-transform: uppercase;
}

.tagline { color: var(--dim); font-family: var(--sans); font-size: 1.05rem; }

.meta { color: var(--dim); font-size: 0.75rem; }
.meta.dim { opacity: 0.6; font-size: 0.7rem; }

/* orchestrated load */
#intro > * { animation: rise 0.5s ease both; }
#intro > :nth-child(2) { animation-delay: 0.05s; }
#intro > :nth-child(3) { animation-delay: 0.15s; }
#intro > :nth-child(4) { animation-delay: 0.25s; }
#intro > :nth-child(5) { animation-delay: 0.35s; }
#intro > :nth-child(6) { animation-delay: 0.45s; }
#intro > :nth-child(7) { animation-delay: 0.5s; }

@keyframes rise { from { opacity: 0; transform: translateY(10px); } }
@keyframes blink { 50% { opacity: 0; } }
@keyframes shake {
  20%, 60% { transform: translateX(-5px); }
  40%, 80% { transform: translateX(5px); }
}
.shake { animation: shake 0.35s ease; }

button {
  font-family: var(--mono);
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  background: var(--amber);
  color: var(--bg);
  border: none;
  padding: 0.8rem 2.4rem;
  cursor: pointer;
}
button:hover { filter: brightness(1.12); box-shadow: 0 0 24px rgba(var(--amber-glow), 0.35); }
button:active { transform: translateY(1px); }

.ghost {
  background: none;
  border: 1px solid var(--line);
  color: var(--dim);
  font-weight: 600;
  font-size: 0.85rem;
  padding: 0.15rem 0.6rem;
  letter-spacing: 0;
}
.ghost:hover { color: var(--amber); border-color: var(--amber); background: none; box-shadow: none; filter: none; }
.ghost.wide { padding: 0.5rem 1.2rem; letter-spacing: 0.08em; }

/* --- game --- */

#game {
  width: 100%;
  max-width: 44rem;
  flex: 1;
  display: flex;
  flex-direction: column;
}

/* header pinned top, board centered in the remaining space – daily-game convention */
#play-area { margin: auto 0; padding: 1rem 0; }

header {
  display: flex;
  gap: 1.25rem;
  align-items: center;
  border-bottom: 1px solid var(--line);
  padding-bottom: 0.8rem;
}
.logo { color: var(--amber); font-weight: 700; font-size: 1.5rem; line-height: 1; }
.logo .caret { width: 0.4em; }
#puzzle-no { color: var(--dim); font-size: 0.85rem; }
header .pips { margin-left: auto; }
.header-btns { display: flex; gap: 0.4rem; }

/* board */

#board { display: flex; flex-direction: column; gap: 5px; overflow-x: auto; padding-bottom: 2px; }

.row { display: grid; grid-template-columns: 1.5fr 1.15fr repeat(4, 1fr); gap: 5px; min-width: 38rem; }
.row.head .cell {
  background: none;
  border: none;
  color: var(--dim);
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  padding: 0.15rem 0.4rem;
}

.cell {
  background: var(--surface);
  border: 1px solid var(--line);
  padding: 0.6rem 0.4rem;
  font-size: 0.8rem;
  font-weight: 500;
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  display: flex;
  align-items: center;
  justify-content: center;
}
.cell.name { text-align: left; white-space: normal; font-weight: 600; justify-content: flex-start; }
.cell.c-category { white-space: normal; line-height: 1.2; font-size: 0.74rem; }
.cell.green { background: var(--ok); border-color: var(--ok); color: #fff; font-weight: 600; }
.cell.yellow { background: var(--warn); border-color: var(--warn); color: #fff; font-weight: 600; }
.cell.grey { color: var(--dim); }
.row.empty .cell { background: transparent; border-color: var(--line); opacity: 0.45; min-height: 2.35rem; }

.row.reveal .cell:not(.name) {
  animation: flip 0.3s ease both;
  animation-delay: calc(var(--i) * 0.15s);
}
@keyframes flip { from { transform: rotateX(90deg); } }

/* search + notice */

#search { position: relative; margin-top: 1.1rem; }
#search-input {
  width: 100%;
  font-family: var(--mono);
  font-size: 1rem;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--line);
  padding: 0.75rem 0.9rem;
}
#search-input::placeholder { color: var(--dim); }
#search-input:focus { outline: none; border-color: var(--amber); }

#search-list {
  position: absolute;
  z-index: 2;
  width: 100%;
  max-height: 14rem;
  overflow-y: auto;
  list-style: none;
  padding: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-top: none;
}
#search-list li { padding: 0.5rem 0.9rem; cursor: pointer; }
#search-list li.active, #search-list li:hover { background: var(--bg); color: var(--amber); }

#notice {
  margin-top: 0.6rem;
  font-size: 0.8rem;
  text-align: center;
}
#notice.err { color: var(--amber); }
#notice.ok { color: var(--ok-text); }

/* result */

#result {
  margin-top: 1.6rem;
  border: 1px solid var(--line);
  padding: 1.5rem;
  text-align: center;
}
#result.ok { border-color: var(--ok); }
#result.throttled { border-color: var(--amber); }
#result-status { font-weight: 700; font-size: 1.05rem; margin-bottom: 0.8rem; }
#result.ok #result-status { color: var(--ok-text); }
#result.throttled #result-status { color: var(--amber); }
#result-answer { font-size: 1.5rem; font-weight: 700; margin-bottom: 0.6rem; }
#result-fact { color: var(--dim); font-family: var(--sans); font-size: 1rem; max-width: 34rem; margin: 0 auto 0.8rem; }
#result-streak { color: var(--dim); font-size: 0.78rem; margin-bottom: 0.3rem; }
#result-countdown { margin-bottom: 1.1rem; }

.legend { color: var(--dim); font-size: 0.72rem; margin-top: 1.6rem; text-align: center; }

footer {
  margin-top: auto;
  padding-top: 2rem;
  color: var(--dim);
  font-size: 0.8rem;
  text-align: center;
}
footer a { color: var(--dim); }
footer a:hover { color: var(--amber); }

/* --- dialogs (help / stats / settings) --- */

.panel {
  margin: auto;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--line);
  padding: 2rem;
  max-width: 26rem;
  width: calc(100% - 2rem);
  max-height: calc(100dvh - 2rem);
  overflow-y: auto;
  font-family: var(--mono);
  font-size: 0.85rem;
}
.panel::backdrop { background: rgba(4, 6, 10, 0.75); }
.panel h2 { font-size: 1.3rem; margin-bottom: 0.9rem; }
.panel .goal { color: var(--dim); margin: -0.6rem 0 1rem; }
.panel ul { padding-left: 1.2rem; color: var(--dim); margin-bottom: 1.4rem; }
.panel li { margin-bottom: 0.4rem; }
.panel .close { position: absolute; top: 0.8rem; right: 0.8rem; border: none; }
.panel .prose { font-size: 0.92rem; }

.section-label {
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  margin-bottom: 0.7rem;
}

.example { margin-bottom: 1rem; }
.example p { color: var(--dim); margin-top: 0.35rem; }
.example strong { color: var(--text); }
.example-cells .cell { display: inline-flex; padding: 0.45rem 0.9rem; font-size: 0.8rem; }

.dialog-meta {
  border-top: 1px solid var(--line);
  margin-top: 1.4rem;
  padding-top: 1rem;
  color: var(--dim);
  font-size: 0.8rem;
}
.dialog-meta a, .panel a { color: var(--amber); }

/* stats */

.stat-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.5rem;
  text-align: center;
  margin-bottom: 1.4rem;
}
.stat-grid b { display: block; font-size: 1.7rem; font-weight: 700; }
.stat-grid span { color: var(--dim); font-size: 0.68rem; letter-spacing: 0.06em; }

#dist { margin-bottom: 1.4rem; }
.dist-row { display: flex; align-items: center; gap: 0.5rem; margin-bottom: 4px; }
.dist-n { color: var(--dim); font-size: 0.75rem; width: 0.8rem; }
.dist-bar {
  background: var(--line);
  color: var(--text);
  font-size: 0.72rem;
  font-weight: 600;
  padding: 0.1rem 0.45rem;
  text-align: right;
  min-width: 1.4rem;
}
.dist-bar.today { background: var(--ok); color: #fff; }

#qr { margin: 1rem auto 0.8rem; max-width: 180px; }
#qr svg { display: block; width: 100%; height: auto; background: #fff; padding: 6px; }
.linkrow { display: flex; gap: 0.4rem; }
.linkrow input {
  flex: 1;
  min-width: 0;
  font-family: var(--mono);
  font-size: 0.72rem;
  background: var(--bg);
  color: var(--dim);
  border: 1px solid var(--line);
  padding: 0.4rem 0.6rem;
}

/* settings */

.setting {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: 0.8rem 0;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
}
.setting small { display: block; color: var(--dim); font-family: var(--sans); font-size: 0.78rem; }
.setting input {
  appearance: none;
  width: 40px;
  height: 22px;
  flex: none;
  background: var(--line);
  border-radius: 11px;
  position: relative;
  cursor: pointer;
  transition: background 0.15s;
}
.setting input::after {
  content: '';
  position: absolute;
  top: 3px; left: 3px;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: var(--bg);
  transition: left 0.15s;
}
.setting input:checked { background: var(--amber); }
.setting input:checked::after { left: 21px; }
.setting input:disabled { opacity: 0.4; cursor: not-allowed; }

/* --- mobile --- */

@media (max-width: 640px) {
  body { padding: 1rem 0.8rem; }
  header { gap: 0.8rem; flex-wrap: wrap; }
  header .pips span { width: 16px; height: 8px; }

  #board { overflow-x: visible; }
  .row { min-width: 0; grid-template-columns: repeat(3, 1fr); gap: 4px; }
  .row.head { display: none; }
  .row .cell.name {
    grid-column: 1 / -1;
    background: none;
    border: none;
    padding: 0.25rem 0.1rem 0.1rem;
    min-height: 0;
    font-size: 0.85rem;
  }
  .cell { font-size: 0.72rem; padding: 0.45rem 0.2rem; flex-direction: column; gap: 1px; }
  .cell:not(.name)::before {
    content: attr(data-label);
    font-size: 0.55rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    opacity: 0.65;
  }
  .row.empty { grid-template-columns: 1fr; }
  .row.empty .cell { display: none; }
  .row.empty .cell.name {
    display: flex;
    border: 1px solid var(--line);
    min-height: 2.1rem;
    opacity: 0.45;
  }
  .row + .row { margin-top: 0.5rem; }

  .panel { padding: 1.4rem; }
  .stat-grid b { font-size: 1.4rem; }
}

@media (prefers-reduced-motion: reduce) {
  .caret, #intro > *, .row.reveal .cell, .shake { animation: none !important; }
}
