:root {
  color-scheme: dark;
  --bg: #14110f;
  --panel: #211c18;
  --line: #3a312a;
  --text: #f2e9de;
  --muted: #a3968a;
  --accent: #f2a154;
  font-family: ui-rounded, "Hiragino Maru Gothic ProN", "Hiragino Sans", system-ui, sans-serif;
}

* { box-sizing: border-box; }

/* `display: grid` on .bars would otherwise win over the hidden attribute. */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  line-height: 1.7;
}

main {
  max-width: 760px;
  margin: 0 auto;
  padding: 32px 16px 64px;
}

h1 {
  margin: 0;
  font-size: clamp(1.8rem, 6vw, 2.6rem);
  letter-spacing: -0.02em;
}

.lead { margin: 4px 0 24px; color: var(--muted); }

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: end;
  padding: 16px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
}

.controls label {
  display: grid;
  gap: 4px;
  font-size: 0.8rem;
  color: var(--muted);
}

select, input, button {
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 12px;
  min-height: 42px;
}

input[type="number"] { width: 7.5em; }

button {
  margin-left: auto;
  background: var(--accent);
  border-color: var(--accent);
  color: #1b130b;
  font-weight: 700;
  cursor: pointer;
}

button[data-mode="stop"] { background: transparent; color: var(--accent); }
:is(select, input, button):focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
:is(select, input):disabled { opacity: 0.5; }

.stats {
  margin: 20px 0 8px;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
}

.stage {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 20px;
  align-items: start;
}

.board {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  padding: 8px;
  aspect-ratio: 1;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
}

.tile {
  display: grid;
  place-items: center;
  border-radius: 9px;
  background: #2b241f;
  color: #1b130b;
  font-weight: 800;
  font-size: clamp(0.9rem, 4.2vw, 1.5rem);
  font-variant-numeric: tabular-nums;
}

.tile[data-value="2"] { background: #e9dfd2; }
.tile[data-value="4"] { background: #e8d3b0; }
.tile[data-value="8"] { background: #f2b179; }
.tile[data-value="16"] { background: #f59563; }
.tile[data-value="32"] { background: #f67c5f; }
.tile[data-value="64"] { background: #f65e3b; color: #fff; }
.tile[data-value="128"] { background: #edcf72; }
.tile[data-value="256"] { background: #edcc61; }
.tile[data-value="512"] { background: #edc850; }
.tile[data-value="1024"] { background: #e6b422; }
.tile[data-value="2048"] { background: #d99a00; color: #fff; }
.tile[data-value="4096"] { background: #7a4bd1; color: #fff; }

.bars {
  display: grid;
  gap: 10px;
  padding: 16px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
}

.bar-row {
  display: grid;
  grid-template-columns: 5.5em 1fr 3em;
  gap: 10px;
  align-items: center;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
}

.bar-row.chosen { color: var(--text); }
.bar-track { height: 12px; border-radius: 6px; background: var(--bg); overflow: hidden; }
.bar-fill { display: block; height: 100%; border-radius: 6px; background: var(--muted); transition: width 120ms ease-out; }
.bar-row.chosen .bar-fill { background: var(--accent); }
.bar-value { text-align: right; }
.confidence { margin-top: 4px; padding-top: 10px; border-top: 1px solid var(--line); color: var(--muted); }

.message { min-height: 1.7em; margin: 16px 0 0; color: var(--accent); }
.remaining { margin: 0; color: var(--muted); font-size: 0.85rem; }

details {
  margin-top: 32px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 14px;
}

summary { cursor: pointer; font-weight: 700; }
a { color: var(--accent); }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { padding: 6px 8px; border-bottom: 1px solid var(--line); text-align: right; }
th:first-child, td:first-child { text-align: left; }

@media (max-width: 560px) {
  .stage { grid-template-columns: 1fr; }
  button { margin-left: 0; width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  .bar-fill { transition: none; }
}
