:root {
  --paper: #edf0f5;
  --card: #fbfcfe;
  --ink: #182033;
  --muted: #5d6779;
  --rule: #d5dbe6;
  --x: #c2255c;
  --o: #1971c2;
  --gauge: #f5b301;
  --good: #2b8a3e;
  --bad: #c92a2a;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --sans: "Avenir Next", "Segoe UI Variable", "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #0f1420;
    --card: #171e2e;
    --ink: #e7ecf6;
    --muted: #93a0b8;
    --rule: #2a3449;
    --x: #ff6b9a;
    --o: #74b0ff;
    --gauge: #ffca3a;
    --good: #69db7c;
    --bad: #ff8787;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--paper);
  color: var(--ink);
  font: 15px/1.5 var(--sans);
  -webkit-text-size-adjust: 100%;
}
button, input { font: inherit; color: inherit; }
.wrap {
  max-width: 960px;
  margin: 0 auto;
  padding: 28px 16px 56px;
  display: grid;
  gap: 22px;
}
header h1 {
  font: 600 clamp(1.9rem, 4.5vw, 2.6rem)/1.1 var(--serif);
  margin: 0 0 6px;
  letter-spacing: -0.01em;
}
header p {
  margin: 0;
  color: var(--muted);
  max-width: 60ch;
}
.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 320px);
  gap: 22px;
  align-items: start;
}
@media (max-width: 800px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
}
.panel {
  background: var(--card);
  border: 1px solid var(--rule);
  border-radius: 14px;
  padding: 16px;
}
.modes {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  padding: 4px;
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: 12px;
  margin-bottom: 14px;
}
.modes button {
  border: 0;
  background: transparent;
  padding: 9px 6px;
  border-radius: 9px;
  cursor: pointer;
  color: var(--muted);
  font-weight: 600;
}
.modes button[aria-pressed="true"] {
  background: var(--card);
  color: var(--ink);
  box-shadow: 0 0 0 1px var(--rule);
}
.status {
  min-height: 64px;
  margin-bottom: 14px;
  display: grid;
  gap: 8px;
  align-content: center;
}
.status p { margin: 0; }
.status .headline { font: 600 1.35rem/1.2 var(--serif); }
.status.bad p { color: var(--bad); }
.status.done .headline { color: var(--good); }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.board {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  width: min(100%, 420px);
  margin: 0 auto;
}
.cell {
  position: relative;
  overflow: hidden;
  aspect-ratio: 1;
  background: var(--card);
  border: 1.5px solid var(--rule);
  border-radius: 12px;
  padding: 0;
  display: grid;
  place-items: center;
  cursor: default;
}
.cell::before {
  content: "";
  position: absolute;
  inset: auto 0 0 0;
  height: calc(var(--heat, 0) * 100%);
  background: color-mix(in srgb, var(--gauge) 55%, transparent);
  transition: height 0.55s cubic-bezier(.2, .8, .2, 1);
}
.cell.playable { cursor: pointer; }
.cell.playable:hover { border-color: var(--ink); }
.cell:focus-visible, .btn:focus-visible, .modes button:focus-visible, input:focus-visible, summary:focus-visible {
  outline: 2px solid var(--o);
  outline-offset: 2px;
}
.cell.win {
  border-color: var(--ink);
  box-shadow: inset 0 0 0 2px var(--ink);
}
.pct {
  position: absolute;
  left: 9px;
  top: 6px;
  font-size: 0.78rem;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
  opacity: 0.75;
}
.glyph {
  position: relative;
  width: 64%;
  height: 64%;
  fill: none;
  stroke-width: 9;
  stroke-linecap: round;
}
.glyph.x { stroke: var(--x); }
.glyph.o { stroke: var(--o); }
.cell.fresh .glyph * {
  stroke-dasharray: 1;
  stroke-dashoffset: 1;
  animation: draw 0.35s ease-out forwards;
}

@keyframes draw {
  to { stroke-dashoffset: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .cell::before { transition: none; }
  .cell.fresh .glyph * { animation: none; stroke-dashoffset: 0; }
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  margin-top: 16px;
}
.btn {
  border: 1px solid var(--rule);
  background: var(--card);
  border-radius: 10px;
  padding: 8px 14px;
  cursor: pointer;
  font-weight: 600;
}
.btn:hover { border-color: var(--ink); }
.btn.primary {
  background: var(--ink);
  color: var(--paper);
  border-color: var(--ink);
}
.btn.ghost { background: transparent; }
.series {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 18px;
  justify-content: center;
  margin-top: 12px;
  color: var(--muted);
  font-size: 0.9rem;
}
.check {
  display: inline-flex;
  gap: 8px;
  align-items: center;
  cursor: pointer;
}
.score {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 8px;
  margin-bottom: 14px;
}
.tile {
  border: 1px solid var(--rule);
  border-radius: 10px;
  padding: 10px;
  display: grid;
  gap: 2px;
  text-align: center;
  min-width: 0;
}
.tile strong { font: 600 1.7rem/1 var(--serif); }
.tname {
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.tseat {
  font-size: 0.8rem;
  color: var(--muted);
}
.tseat.x { color: var(--x); }
.tseat.o { color: var(--o); }
.tile.d { align-content: center; }
.log {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 260px;
  overflow: auto;
  display: grid;
  gap: 8px;
}
.log li {
  border-left: 3px solid var(--rule);
  padding: 2px 0 2px 10px;
  font-size: 0.92rem;
}
.log li.x { border-color: var(--x); }
.log li.o { border-color: var(--o); }
.log small { display: block; color: var(--muted); }
.log li.warn small { color: var(--bad); }
.empty { color: var(--muted); margin: 0; font-size: 0.92rem; }
h2 {
  font: 600 1.05rem/1.3 var(--serif);
  margin: 0 0 10px;
}
details.panel summary { cursor: pointer; font: 600 1.05rem/1.3 var(--serif); }
.fields {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 18px;
  margin-top: 14px;
}
fieldset {
  border: 1px solid var(--rule);
  border-radius: 12px;
  padding: 12px 14px 14px;
  display: grid;
  gap: 10px;
  margin: 0;
  min-width: 0;
}
legend { padding: 0 6px; font-weight: 600; }
.field { display: grid; gap: 4px; }
.field span { font-size: 0.85rem; color: var(--muted); }
.field input {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--rule);
  border-radius: 8px;
  background: var(--paper);
}
.note {
  color: var(--muted);
  font-size: 0.85rem;
  margin: 12px 0 0;
  max-width: 70ch;
}
