:root {
  font:
    15px/1.4 system-ui,
    sans-serif;
  color: #f3f4e9;
  background: #172630;
  --accent: #eac279;
  --surface: #233c48;
  --ink: #121f28;
  color-scheme: dark;
}
* {
  box-sizing: border-box;
}
body {
  margin: 0;
  min-height: 100dvh;
  display: grid;
  align-content: safe center;
  padding: clamp(8px, 2vw, 20px);
  background:
    radial-gradient(ellipse at 90% 0%, var(--surface), transparent 65%), #13212b;
}
main {
  width: min(100%, 680px);
  margin: auto;
  display: grid;
  gap: clamp(5px, 1.5vh, 13px);
}
header,
footer,
#actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 7px;
  flex-wrap: wrap;
}
h1 {
  margin: 0;
  font:
    680 clamp(23px, 5vw, 38px)/1.08 system-ui,
    sans-serif;
  letter-spacing: -0.035em;
}
p {
  margin: 0;
}
#goal {
  color: #d8e1e3;
  font-size: clamp(12px, 2.5vw, 15px);
  max-width: 62ch;
}
button,
input,
select {
  font: inherit;
}
button {
  border: 1px solid #72879366;
  border-radius: 7px;
  background: var(--surface);
  color: inherit;
  padding: 6px 12px;
  min-height: 34px;
  cursor: pointer;
  touch-action: manipulation;
}
button:disabled {
  cursor: default;
  opacity: 0.8;
}
button:focus-visible,
input:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: -3px;
}
#actions {
  justify-content: center;
}
#surface {
  width: min(100%, 460px, max(205px, calc(100dvh - 210px)));
  margin: auto;
}
#surface.cells {
  display: grid;
  grid-template-columns: repeat(var(--cols), 1fr);
  gap: 3px;
  border: 1px solid #ffffff33;
  background: #10232b;
  padding: 6px;
  border-radius: 12px;
}
.cells button {
  aspect-ratio: 1;
  min-width: 0;
  min-height: 0;
  padding: 0;
  font-weight: 750;
  font-size: clamp(12px, 4vw, 25px);
  line-height: 1.05;
  overflow-wrap: anywhere;
}
.cells .on,
.cells .hero,
.cells .chosen {
  background: var(--accent);
  color: var(--ink);
}
.cells .wall {
  background: repeating-linear-gradient(135deg, #192830 0 4px, #2c3c46 4px 6px);
}
.cells .target,
.cells .good {
  background: #a8dbba;
  color: #153829;
}
.cells .bad {
  background: #ba5e51;
  color: #fff;
}
.cells .fixed {
  color: #a9bbc4;
  background: #1a2f38;
}
#message {
  color: var(--accent);
  min-height: 1.5em;
  text-align: center;
  font-weight: 650;
}
footer {
  border-top: 1px solid #ffffff26;
  padding-top: 5px;
}
#counter {
  font:
    600 13px ui-monospace,
    monospace;
}
body[data-phase="won"] #message {
  color: #bcf0be;
}
#new {
  background: var(--accent);
  color: var(--ink);
}
#surface.words {
  display: flex;
  justify-content: center;
  align-content: center;
  flex-wrap: wrap;
  gap: 7px;
  min-height: 150px;
}
#surface.words button {
  font-size: clamp(16px, 4vw, 25px);
  padding: 10px;
  min-width: 42px;
}
#surface canvas {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 12px;
  touch-action: none;
}
@media (max-height: 450px) and (min-width: 590px) {
  main {
    grid-template-columns: 1fr 1.2fr;
  }
  #surface {
    grid-column: 2;
    grid-row: 1 / span 6;
    width: min(95%, 72dvh);
  }
  #actions {
    justify-content: start;
  }
}
#surface.readout {
  display: grid;
  grid-template-columns: repeat(var(--cols, 2), minmax(0, 1fr));
  gap: 5px;
  padding: 12px;
  border-radius: 15px;
  background: #10232b;
  border: 1px solid #ffffff32;
}
.readout span {
  display: grid;
  place-items: center;
  text-align: center;
  min-height: 36px;
  padding: 6px 3px;
  background: var(--surface);
  border-radius: 5px;
  color: #f4f2e4;
  font-weight: 650;
}
.reference {
  white-space: pre-line;
  text-align: center;
  font-family: ui-monospace, monospace;
  background: #13232d;
  border-radius: 7px;
  padding: 6px;
  color: #f3dfad;
}

/* Keep the board stable when round feedback or translated controls change. */
body {
  background:
    radial-gradient(ellipse at 80% 5%, var(--surface), transparent 60%),
    #0b181f;
}
main {
  background: linear-gradient(155deg, #152631f2, #0e1c24f2);
  border: 1px solid #ffffff24;
  border-radius: 18px;
  padding: clamp(9px, 2vw, 20px);
  box-shadow: 0 10px 28px #0310164d;
}
header {
  padding-inline-start: 12px;
  border-inline-start: 4px solid var(--accent);
}
#goal { line-height: 1.48; }
#surface.cells, #surface.readout, #surface canvas {
  box-shadow: 0 3px 12px #03101670;
}
#actions button, footer button {
  min-height: 40px;
  font-weight: 650;
}
footer { justify-content: flex-end; }
#counter {
  margin-inline-end: auto;
  color: #e0e7eb;
  font-variant-numeric: tabular-nums;
}
#new, #actions button:only-child {
  background: var(--accent);
  color: var(--ink);
}
body[data-phase="paused"] #surface { opacity: .6; }
body[data-phase="lost"] #message { color: #ffb6a5; }
@media (hover: hover) {
  button:enabled:hover { border-color: var(--accent); }
}
@media (max-height: 500px) {
  main { padding: 7px 10px; gap: 4px; }
  #actions button, footer button { min-height: 32px; }
}
