@font-face {
  font-family: "DM Sans";
  src: url("fonts/dm-sans-latin.woff2") format("woff2");
  font-display: swap;
}
@font-face {
  font-family: "Archivo Black";
  src: url("fonts/archivo-black-latin.woff2") format("woff2");
  font-display: swap;
}

:root {
  --paper: #e8edf1;
  --surface: #ffffff;
  --ink: #1e2a30;
  --muted: #58645f;
  --brick: #a94335;
  --brick-soft: #efd4cf;
  --teal: #176b66;
  --teal-soft: #cde3e1;
  --border: #c5cdd2;
  --edge: #d5dce0;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body {
  margin: 0;
  display: flex;
  flex-direction: column;
  color: var(--ink);
  background: var(--paper);
  font-family: "DM Sans", system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.35;
  -webkit-font-smoothing: antialiased;
}
button, select, input { font: inherit; }
button { touch-action: manipulation; }
a { color: var(--teal); }
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.shell {
  width: min(720px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0 18px;
  flex: 1;
}
.masthead {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--border);
}
.eyebrow {
  margin: 0 0 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .13em;
  text-transform: uppercase;
}
h1 {
  margin: 0;
  font: 400 clamp(40px, 6vw, 42px)/.98 "Archivo Black", "DM Sans", sans-serif;
  letter-spacing: -.045em;
}
h1 em { color: var(--teal); font-style: normal; font-weight: 400; }
h1 span { color: var(--brick); }
.utility-controls { display: flex; align-items: center; gap: 6px; }
.icon-toggle {
  min-height: 42px;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 8px 10px;
  display: flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  background: transparent;
  cursor: pointer;
  font-size: 14px;
  font-weight: 700;
}
.icon-toggle:hover { border-color: var(--border); background: var(--surface); color: var(--ink); }
.icon-toggle[aria-pressed="true"] { color: var(--teal); border-color: var(--teal); }

.game { width: min(100%, 620px); margin: 0 auto; padding: 18px 0 8px; }
.control-row { display: flex; justify-content: space-between; align-items: center; gap: 18px; }
.pill-switch {
  display: flex;
  padding: 3px;
  gap: 2px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
}
.choice {
  min-height: 42px;
  padding: 8px 13px;
  border: 0;
  border-radius: 6px;
  color: var(--muted);
  background: transparent;
  cursor: pointer;
  font-size: 14px;
  font-weight: 700;
}
.choice.active { color: var(--surface); background: var(--ink); }
.size-switch { display: flex; gap: 4px; }
.text-choice, .difficulty {
  min-height: 42px;
  padding: 7px 9px;
  border: 1px solid transparent;
  border-radius: 6px;
  color: var(--muted);
  background: transparent;
  cursor: pointer;
  font-size: 14px;
  font-weight: 700;
}
.text-choice small { display: block; font-size: 12px; line-height: 1.1; font-weight: 600; }
.text-choice:hover, .difficulty:hover { border-color: var(--border); background: var(--surface); }
.text-choice.active, .difficulty.active { color: var(--teal); border-color: var(--teal); background: var(--surface); }
.difficulty-row {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  min-height: 46px;
  gap: 4px;
  margin: 4px 0;
  color: var(--muted);
  font-size: 12px;
}
.difficulty-row > span { margin-right: 4px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; }
.difficulty { min-height: 40px; padding: 7px 9px; }
.difficulty-row[hidden] { display: none; }

.scorebar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
  padding: 8px 0;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}
.player-card {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
  min-height: 48px;
  padding: 5px 8px;
  border: 1px solid transparent;
  border-radius: 6px;
  color: var(--muted);
}
.player-card.teal { justify-content: flex-end; text-align: right; }
.player-card.is-current { color: var(--ink); border-color: var(--border); background: var(--surface); }
.player-card small {
  display: block;
  overflow: hidden;
  color: inherit;
  font-size: 12px;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.player-card strong { display: block; color: var(--ink); font-size: 24px; line-height: 1; font-weight: 800; }
.player-symbol { font-size: 17px; }
.coral .player-symbol { color: var(--brick); }
.teal .player-symbol { color: var(--teal); }
.turn-copy { min-width: 126px; text-align: center; }
.turn-copy span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: .06em;
  text-transform: uppercase;
}
.turn-copy strong { display: block; margin-top: 3px; color: var(--ink); font-size: 15px; line-height: 1.2; font-weight: 800; }

.board-frame {
  position: relative;
  width: min(100%, 480px);
  margin: 0 auto;
  padding: 12px;
  border: 2px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
}
.board { position: relative; aspect-ratio: 1; isolation: isolate; }
.box {
  position: absolute;
  z-index: 0;
  display: grid;
  place-items: center;
  border-radius: 4px;
  transform: scale(.86);
  opacity: 0;
  transition: transform .22s ease, opacity .18s ease;
}
.box.claimed { transform: scale(1); opacity: 1; }
.box.owner-0 { background: var(--brick-soft); }
.box.owner-1 { background: var(--teal-soft); }
.box span { color: var(--ink); font-weight: 900; font-size: clamp(13px, 2.2vw, 18px); }
.dot {
  position: absolute;
  z-index: 4;
  width: clamp(9px, 2.5%, 12px);
  aspect-ratio: 1;
  border-radius: 50%;
  background: var(--ink);
  transform: translate(-50%, -50%);
  pointer-events: none;
}
.edge { position: absolute; z-index: 2; margin: 0; padding: 0; border: 0; background: transparent; cursor: pointer; }
.edge::before {
  content: "";
  position: absolute;
  border-radius: 4px;
  background: var(--edge);
  transition: background .14s ease, transform .14s ease, opacity .14s ease;
}
.edge.horizontal { height: 42px; transform: translateY(-50%); }
.edge.horizontal::before { left: 0; right: 0; top: 50%; height: 5px; transform: translateY(-50%) scaleX(.94); }
.edge.vertical { width: 42px; transform: translateX(-50%); }
.edge.vertical::before { top: 0; bottom: 0; left: 50%; width: 5px; transform: translateX(-50%) scaleY(.94); }
.edge:not(:disabled):hover::before, .edge.preview::before { background: var(--preview, var(--brick)); opacity: .62; }
.edge.claimed::before { background: var(--owner); opacity: 1; transform: translateY(-50%) scaleX(1); animation: line-in .2s ease-out both; }
.edge.vertical.claimed::before { transform: translateX(-50%) scaleY(1); }
.edge:focus-visible { outline: 3px solid var(--ink); outline-offset: -3px; border-radius: 6px; }
.edge:disabled { cursor: default; }

.actions { display: flex; justify-content: center; align-items: center; gap: 16px; margin-top: 12px; }
.primary {
  min-height: 44px;
  border: 1px solid var(--ink);
  border-radius: 6px;
  padding: 10px 18px;
  color: var(--surface);
  background: var(--ink);
  cursor: pointer;
  font-size: 14px;
  font-weight: 800;
}
.primary:hover { color: var(--ink); background: var(--surface); }
.primary span { margin-left: 6px; }
.rule-note { margin: 0; color: var(--muted); font-size: 14px; font-weight: 600; }
.settings { margin: 9px auto 0; width: min(100%, 440px); color: var(--muted); font-size: 12px; text-align: center; }
.settings summary { display: inline-block; min-height: 40px; padding: 10px; cursor: pointer; list-style: none; font-size: 14px; font-weight: 700; }
.settings summary::-webkit-details-marker { display: none; }
.music-row {
  display: grid;
  grid-template-columns: 42px minmax(130px, 1fr) 42px minmax(100px, .55fr);
  gap: 6px;
  align-items: center;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
}
.music-row button { min-height: 42px; border: 1px solid transparent; border-radius: 6px; color: var(--muted); background: transparent; cursor: pointer; }
.music-row button:hover { color: var(--ink); border-color: var(--border); }
.music-row select { width: 100%; min-height: 42px; border: 1px solid var(--border); border-radius: 6px; padding: 0 8px; color: var(--ink); background: var(--surface); font-size: 14px; font-weight: 700; }
.volume { display: flex; align-items: center; gap: 6px; color: var(--muted); }
.volume input { width: 100%; accent-color: var(--teal); }

footer { width: min(720px, calc(100% - 32px)); margin: 0 auto; padding: 0 0 16px; color: var(--muted); text-align: center; }
.credits { display: inline-block; font-size: 12px; }
.credits summary { min-height: 36px; padding: 8px; cursor: pointer; list-style: none; font-weight: 700; }
.credits summary::-webkit-details-marker { display: none; }
.credits p { max-width: 520px; margin: 5px auto 0; }
.credits a { color: var(--teal); text-underline-offset: 2px; }
.privacy-link { display: inline-block; min-height: 36px; margin-left: 8px; padding: 8px; color: var(--teal); font-size: 12px; font-weight: 700; text-underline-offset: 2px; }

button:focus-visible, a:focus-visible, summary:focus-visible, select:focus-visible, input:focus-visible {
  outline: 3px solid var(--ink);
  outline-offset: 2px;
}

@keyframes line-in { from { opacity: .25; } to { opacity: 1; } }

@media (max-width: 560px) {
  .shell { width: min(100% - 24px, 500px); padding-top: 16px; }
  .masthead { align-items: flex-start; gap: 12px; padding-bottom: 14px; }
  h1 { font-size: clamp(30px, 9vw, 36px); }
  .icon-toggle { width: 42px; justify-content: center; padding: 8px; }
  .icon-toggle span:last-child { display: none; }
  .game { padding-top: 14px; }
  .control-row { align-items: stretch; flex-direction: column; gap: 10px; }
  .pill-switch, .size-switch { width: 100%; }
  .choice, .text-choice { flex: 1; }
  .difficulty-row { justify-content: center; flex-wrap: wrap; }
  .scorebar { gap: 4px; }
  .player-card { padding: 5px; gap: 5px; }
  .turn-copy { min-width: 104px; }
  .turn-copy strong { font-size: 14px; }
  .board-frame { padding: 8px; }
  .edge.horizontal { height: 46px; }
  .edge.vertical { width: 46px; }
  .actions { gap: 10px; }
  .music-row { grid-template-columns: 42px minmax(110px, 1fr) 42px; }
  .volume { grid-column: 1 / -1; padding: 4px 8px; }
  footer { width: min(100% - 24px, 500px); }
}

@media (max-width: 375px) {
  .choice, .text-choice, .difficulty { padding-left: 6px; padding-right: 6px; }
  .scorebar { margin-bottom: 8px; }
  .rule-note { max-width: 140px; font-size: 13px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
    scroll-behavior: auto !important;
  }
}
