:root {
  color-scheme: light;
  --paper: #f4f3ed;
  --ink: #243d34;
  --muted: #4e6156;
  --line: #c9cec0;
  --white: #fcfbf5;
  --lime: #d2f06c;
  --orange: #a84717;
  --danger: #9e3522;
  --radius: 1.4rem;
  font-family: 'Segoe UI', system-ui, sans-serif;
  font-synthesis: none;
}
*, *::before, *::after { box-sizing: border-box; }
body {
  min-width: 300px;
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background-color: var(--paper);
  background-image: linear-gradient(#243d3409 1px, transparent 1px), linear-gradient(90deg, #243d3409 1px, transparent 1px);
  background-size: 32px 32px;
  line-height: 1.5;
}
button, input { font: inherit; }
button { color: inherit; }
a { color: inherit; }
button:not(:disabled) { cursor: pointer; }
button:focus-visible, a:focus-visible, input:focus-visible {
  outline: 3px solid #b2461d;
  outline-offset: 4px;
}
h1, h2, h3, p { margin: 0; }
h1[tabindex="-1"]:focus { outline: none; }
[hidden] { display: none !important; }

.topbar {
  min-height: 72px;
  padding: .8rem max(1.25rem, calc((100% - 1120px) / 2));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  border-bottom: 1px solid var(--line);
  background: #f4f3edf0;
}
.brand, .header-action {
  display: inline-flex;
  align-items: center;
  gap: .65rem;
  border: 0;
  background: transparent;
  padding: 0;
  font-weight: 750;
  text-decoration: none;
}
.brand { font-size: 1.15rem; letter-spacing: -.035em; }
.brand-mark {
  display: inline-grid;
  place-items: center;
  width: 2.2rem;
  height: 2.2rem;
  border-radius: .6rem;
  color: var(--lime);
  background: var(--ink);
  font-size: 1.4rem;
}
.header-action { min-height: 44px; font-size: .9rem; }
.header-action:hover { text-decoration: underline; text-underline-offset: .22em; }

#app { padding: clamp(1.65rem, 5vw, 4.3rem) 1.25rem 4rem; }
.screen { max-width: 1120px; margin-inline: auto; }
.hero-grid {
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  align-items: center;
  gap: clamp(1.5rem, 6vw, 5rem);
  margin-bottom: clamp(2rem, 5vw, 4.5rem);
}
.hero-copy { min-width: 0; }
.eyebrow {
  color: var(--muted);
  font-size: .76rem;
  font-weight: 800;
  letter-spacing: .17em;
  text-transform: uppercase;
}
.hero-title, .page-heading h1, h1.page-heading {
  font-weight: 900;
  letter-spacing: -.08em;
  line-height: .98;
}
.hero-title {
  margin-block: .4rem .95rem;
  font-size: clamp(3.4rem, 8.5vw, 8.1rem);
}
.subtitle {
  max-width: 34rem;
  color: var(--muted);
  font-size: clamp(1.05rem, 2.2vw, 1.25rem);
}
.hero-art {
  position: relative;
  isolation: isolate;
  display: grid;
  place-items: center;
  min-height: clamp(15rem, 32vw, 22rem);
  padding: 2rem;
  overflow: hidden;
  border-radius: calc(var(--radius) * 1.3);
  background: var(--ink);
  color: var(--lime);
  background-image: radial-gradient(#d2f06c24 1px, transparent 1px);
  background-size: 16px 16px;
}
.demo-board {
  position: relative;
  width: min(100%, 12rem);
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: .4rem;
  transform: rotate(-8deg);
}
.demo-cell {
  display: grid;
  place-items: center;
  aspect-ratio: 1;
  border: 1px solid #d2f06c5e;
  border-radius: .55rem;
  background: #304c40;
  font-size: clamp(1.35rem, 4vw, 2.2rem);
  font-weight: 850;
  line-height: 1;
}
.demo-cell.filled { color: var(--ink); background: var(--lime); }
.art-note { position: absolute; inset: auto auto .8rem 1rem; font-size: .72rem; font-weight: 800; letter-spacing: .1em; text-transform: uppercase; }
.art-spark { position: absolute; inset: .6rem 1.05rem auto auto; font-size: clamp(1.7rem, 4vw, 3rem); line-height: 1; }

.opponent-options { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .9rem; }
.menu-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: .4rem 1rem;
  margin-top: 1rem;
  color: var(--muted);
}
.menu-footer .text-button { color: var(--ink); }
.menu-footer p { font-size: .87rem; }
.option-card {
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: .35rem;
  padding: clamp(1rem, 2.4vw, 1.55rem);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--white);
  text-align: left;
  text-decoration: none;
  transition: background-color 150ms ease, border-color 150ms ease, translate 150ms ease;
}
.option-card:hover { translate: 0 -3px; border-color: var(--ink); background: #f6fbdc; }
.option-icon {
  display: inline-grid;
  place-items: center;
  width: 2.7rem;
  height: 2.7rem;
  margin-bottom: .45rem;
  border-radius: .8rem;
  background: #e8eddb;
  font-size: 1.3rem;
}
.option-icon svg { width: 1.35rem; height: 1.35rem; }
.option-title { font-size: 1.2rem; font-weight: 800; letter-spacing: -.035em; }
.option-description { color: var(--muted); font-size: .9rem; }
.menu-screen h2 { margin-bottom: .75rem; font-size: 1.25rem; letter-spacing: -.03em; }

.button, .text-button {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  gap: .45rem;
  min-height: 46px;
  padding: .6rem 1rem;
  border: 1px solid transparent;
  border-radius: .72rem;
  background: transparent;
  font-weight: 750;
  text-align: center;
  text-decoration: none;
  transition: background-color 150ms ease, border-color 150ms ease;
}
.button.primary { border-color: var(--ink); background: var(--lime); }
.button.primary:hover:not(:disabled) { background: #c3e951; }
.button.secondary { border-color: var(--line); background: var(--white); }
.button.secondary:hover:not(:disabled), .button.ghost:hover:not(:disabled) { border-color: var(--ink); }
.button.small { min-height: 44px; padding: .4rem .8rem; font-size: .88rem; }
.button:disabled, .text-button:disabled { opacity: .55; }
.text-button { padding-inline: .4rem; }
.text-button:hover:not(:disabled) { text-decoration: underline; text-underline-offset: .22em; }

.page-heading { margin-bottom: 1.35rem; }
.page-heading h1, h1.page-heading { margin-block: .35rem .65rem; font-size: clamp(2.65rem, 7vw, 5rem); }
.page-heading p + p, .page-heading h1 + p { color: var(--muted); }
.settings-screen, .lobby-screen { max-width: 620px; }
.settings-card, .lobby-card, .tutorial-bubble, .result-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--white);
  padding: clamp(1.05rem, 3vw, 1.9rem);
}
.settings-card { max-width: 620px; }
.setting-group, .settings-card fieldset { min-inline-size: 0; margin: 0 0 1.45rem; padding: 0; border: 0; }
.setting-group legend, .setting-group > label, .settings-card legend { display: block; margin-bottom: .45rem; padding: 0; font-weight: 800; }
.segmented { display: flex; flex-wrap: wrap; gap: .45rem; }
.segmented button {
  flex: 1 1 auto;
  min-height: 46px;
  padding: .45rem .7rem;
  border: 1px solid var(--line);
  border-radius: .65rem;
  background: var(--paper);
  font-weight: 700;
}
.segmented button:hover, .segmented button.selected, .segmented button[aria-pressed="true"] { border-color: var(--ink); }
.segmented button.selected, .segmented button[aria-pressed="true"] { background: var(--lime); }
.setting-tip { margin-top: .5rem; color: var(--muted); font-size: .9rem; }
.settings-actions, .game-actions, .share-actions, .tutorial-controls { display: flex; flex-wrap: wrap; align-items: center; gap: .6rem; }
.game-top { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: .65rem; margin-bottom: 1rem; }
.turn-pill, .board-count, .board-status {
  display: inline-flex;
  align-items: center;
  gap: .45rem;
  min-height: 2rem;
  border-radius: 999px;
  font-size: .83rem;
  font-weight: 750;
}
.turn-pill { padding: .35rem .8rem; background: var(--ink); color: var(--white); }
.turn-dot { width: .6rem; height: .6rem; border-radius: 100%; background: var(--lime); }
.board-count { padding: .3rem .75rem; background: #e5eadb; }
.boards-grid {
  display: grid;
  grid-template-columns: repeat(var(--board-count, 3), minmax(0, 1fr));
  gap: clamp(.75rem, 2vw, 1.2rem);
  align-items: start;
  max-width: calc(var(--board-count, 3) * 23rem);
  margin-inline: auto;
}
.board-card {
  position: relative;
  width: 100%;
  min-width: 0;
  padding: clamp(.65rem, 2vw, 1.25rem);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--white);
}
.board-card.dead { background: #e7e9df; border-style: dashed; }
.board-card > header, .board-header, .board-meta { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: .35rem; margin-bottom: .65rem; }
.board-label { font-size: 1.12rem; font-weight: 850; letter-spacing: -.025em; }
.board-status { min-height: auto; padding: .2rem .55rem; color: var(--muted); background: #e8eddb; }
.board-card.dead .board-status { background: #d4dbcd; color: var(--ink); }
.board-grid {
  position: relative;
  display: grid;
  grid-template-columns: repeat(3, minmax(56px, 1fr));
  gap: clamp(.34rem, .8vw, .6rem);
}
.cell {
  display: grid;
  place-items: center;
  aspect-ratio: 1;
  min-width: 56px;
  min-height: 56px;
  padding: 0;
  border: 1px solid #bbc5b6;
  border-radius: clamp(.45rem, 1vw, .8rem);
  background: #f0f1e7;
  color: var(--ink);
  font-size: clamp(1.8rem, 5vw, 3.4rem);
  font-weight: 850;
  line-height: 1;
  transition: border-color 150ms ease, background-color 150ms ease, box-shadow 150ms ease;
}
.cell:not(:disabled):hover { border-color: var(--ink); background-color: #e8f5be; }
.cell.filled { background: #e6edda; color: var(--ink); opacity: 1; }
.cell.last-move { border-color: #677d45; background-color: #e6f4bc; box-shadow: inset 0 0 0 1px #677d45; }
.cell.last-move .x-mark { animation: mark-pop 180ms ease-out both; }
.cell.warn-kill {
  color: #674806;
  border: 2px solid #a6780c;
  background-color: #fff3c7;
  background-image: radial-gradient(#9d6b144d 1px, transparent 1px);
  background-size: 7px 7px;
}
.cell.warn-loss {
  color: #762c1f;
  border: 2px solid var(--danger);
  background-color: #f9d9d0;
  background-image: repeating-linear-gradient(135deg, transparent 0 5px, #a13c2529 5px 8px);
}
.cell.warn-kill:not(:disabled):hover { background-color: #ffe79a; border-color: #805a06; }
.cell.warn-loss:not(:disabled):hover { background-color: #f7bfb0; border-color: var(--danger); }
.cell.glowing {
  border-color: var(--ink);
  box-shadow: 0 0 0 3px var(--lime), inset 0 0 0 2px var(--ink);
  animation: tutorial-glow 1.3s ease-in-out infinite alternate;
}
@keyframes mark-pop {
  from { transform: scale(.72); }
  70% { transform: scale(1.1); }
  to { transform: scale(1); }
}
@keyframes tutorial-glow {
  to { box-shadow: 0 0 0 6px #c6e75d, inset 0 0 0 2px var(--ink); }
}
.board-card.dead .cell { background: #e1e4d9; color: #4f6257; }
.board-card.dead .cell.last-move { border-color: var(--ink); }
.x-mark { display: inline-block; color: inherit; line-height: 1; }
svg.x-mark { width: 43%; height: 43%; }
.win-line { position: absolute; z-index: 1; inset: 0; width: 100%; height: 100%; color: #a0452b; pointer-events: none; }
.win-line line { stroke: currentColor; stroke-linecap: round; }
.warning-area { display: grid; gap: .35rem; margin-block: 1rem; color: var(--muted); }
.warning-text { font-size: .94rem; }
.warning-text.caution, .warning-area .caution { color: #893d15; }
.warning-text.danger, .warning-area .danger { color: var(--danger); font-weight: 800; }
.game-actions { margin-top: .75rem; }
.result-card { margin-top: 1rem; background: #eaf3ce; border-color: #aebb93; }
.result-card h2 { font-size: clamp(1.35rem, 4vw, 2.1rem); letter-spacing: -.04em; }
.result-card p { margin-block: .35rem .65rem; }

.tutorial-layout { display: grid; grid-template-columns: minmax(0, 23rem) minmax(0, 1fr); gap: 1rem; align-items: start; max-width: 850px; }
.tutorial-layout > .boards-grid { width: 100%; }
.tutorial-bubble { display: grid; gap: .65rem; }
.tutorial-bubble h2 { line-height: 1.15; letter-spacing: -.035em; }
.tutorial-bubble p { color: var(--muted); }
.step-count { font-size: .8rem; font-weight: 800; color: var(--muted); }
.tutorial-controls { margin-top: .25rem; }
.lobby-card { display: grid; gap: .85rem; }
.room-link {
  width: 100%;
  min-height: 46px;
  margin: 0;
  padding: .55rem .7rem;
  overflow-wrap: anywhere;
  border: 1px solid var(--line);
  border-radius: .65rem;
  background: var(--paper);
  color: var(--ink);
}
.connection-status { color: var(--muted); font-size: .94rem; }
.toast {
  position: fixed;
  z-index: 3;
  inset: auto 1rem 1rem auto;
  max-width: min(25rem, calc(100% - 2rem));
  padding: .8rem 1rem;
  border-radius: .8rem;
  background: var(--ink);
  color: var(--white);
  box-shadow: 0 .5rem 2rem #243d3429;
  font-weight: 700;
}
.toast:empty { display: none; }
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 760px) {
  .hero-grid { grid-template-columns: 1fr; }
  .hero-art { min-height: 14rem; }
  .board-card { max-width: 24rem; margin-inline: auto; }
  .boards-grid { grid-template-columns: minmax(0, 1fr); max-width: 24rem; }
}
@media (max-width: 580px) {
  .topbar { min-height: 60px; }
  #app { padding-inline: 1rem; }
  .opponent-options, .tutorial-layout { grid-template-columns: 1fr; }
  .option-card {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    column-gap: .8rem;
    align-items: center;
  }
  .option-icon { grid-row: span 2; margin: 0; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
  .cell.glowing, .cell.last-move .x-mark { animation: none; }
}
