:root {
  --bg: #f6ede4; --card: #fffaf5; --ink: #3a2a2a; --muted: #8a7570; --line: #ead9cc;
  --accent: #e2557a; --accent-ink: #fff; --p0: #e2557a; --p1: #4f7bd9; --good: #3c9d6b; --bad: #d4553f;
  --radius: 16px; color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #1f1a1d; --card: #2b2428; --ink: #f4e9e4; --muted: #b29f99; --line: #3d3338; color-scheme: dark; }
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 17px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding: env(safe-area-inset-top) 16px calc(80px + env(safe-area-inset-bottom));
}
#app { max-width: 560px; margin: 0 auto; }
h1 { font-size: 2.2rem; margin: .2em 0; }
h2 { margin: .4em 0 .1em; }
h3 { margin: .6em 0 .3em; }
a { color: var(--accent); }
button, input, textarea {
  font: inherit; color: inherit; border-radius: 12px; border: 2px solid var(--line); background: var(--card);
  padding: 12px 14px; min-height: 48px;
}
button { cursor: pointer; font-weight: 600; touch-action: manipulation; }
button:disabled { opacity: .55; cursor: default; }
button.primary, form button:not(.ghost) { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
button.ghost { background: transparent; border-color: transparent; padding: 8px 10px; }
input, textarea { width: 100%; min-width: 0; }
:focus-visible { outline: 3px solid var(--p1); outline-offset: 2px; }
label { display: block; font-weight: 600; margin: 10px 0 4px; }
.muted, small { color: var(--muted); }
.card { background: var(--card); border: 2px solid var(--line); border-radius: var(--radius); padding: 16px; margin: 12px 0; }
.error { color: var(--bad); font-weight: 600; }
form.stack > * { margin-top: 8px; }
form.stack button { width: 100%; }
.row { display: flex; gap: 8px; align-items: center; margin: 8px 0; }
.row > input { flex: 1; }
.wrap { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0; }

/* One line on any phone: back/brand | players (shrinks with …) | leave */
.bar { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 6px; padding: 8px 0; }
.bar > button, .brand { white-space: nowrap; }
.brand { font-weight: 800; }
.who { display: flex; gap: 6px; justify-content: center; min-width: 0; }
.chip { font-size: .85rem; padding: 4px 10px; border-radius: 99px; background: var(--card); border: 2px solid var(--line); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.wrap .chip { overflow: visible; }
.who .chip:first-child { flex: none; } /* "You" never truncates; the partner's name takes the … */
button.link { background: none; border: none; padding: 0; min-height: 0; color: var(--accent); text-decoration: underline; font-weight: 600; }
.lobby-head { margin: 4px 0 0; }
.chip::before { content: "●"; margin-right: 4px; color: var(--muted); }
.chip.on::before { color: var(--good); }
.invite .code { font-size: 2rem; letter-spacing: .2em; font-weight: 800; }

.cat { margin-top: 18px; }
.games { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.games button { text-align: left; display: flex; flex-direction: column; gap: 2px; min-height: 84px; }
.games .icon { font-size: 1.5rem; line-height: 1.2; }
.games small { font-weight: 400; }

.round { color: var(--muted); margin: 4px 0; }
.prompt { font-size: 1.25rem; font-weight: 600; margin: 10px 0; }
.big-msg { font-size: 1.3rem; font-weight: 700; text-align: center; }
.status { font-weight: 700; text-align: center; font-size: 1.1rem; }
.score { text-align: center; color: var(--muted); }
.choices { display: grid; gap: 10px; margin: 12px 0; }
.choices button { min-height: 72px; font-size: 1.1rem; }
.choices button.picked { border-color: var(--accent); box-shadow: inset 0 0 0 2px var(--accent); }
.choices button.right { border-color: var(--good); box-shadow: inset 0 0 0 2px var(--good); }
.tags { display: flex; gap: 4px; justify-content: center; margin-top: 6px; }
.tag { font-size: .75rem; padding: 2px 8px; border-radius: 99px; background: var(--p0); color: #fff; }
.tag.them { background: var(--p1); }
.cards { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.cards .card { margin: 0; border-color: var(--p0); }
.cards .card.them { border-color: var(--p1); }
.cards p { margin: 4px 0 0; overflow-wrap: anywhere; }
.next { display: block; margin: 16px auto; }
.emoji-big { font-size: 3rem; text-align: center; margin: 10px 0; }

/* minmax(0, 1fr): columns may shrink below their content, so boards never push the page sideways */
.board { display: grid; grid-template-columns: repeat(var(--w), minmax(0, 1fr)); gap: 6px; margin: 12px auto; max-width: 420px; }
/* .cell is used on <button> and plain <div>, so both get the same tile look */
.cell {
  aspect-ratio: 1; padding: 0; min-height: 0; font-size: clamp(1.2rem, 8vw, 2.6rem); display: grid; place-items: center;
  background: var(--card); border: 2px solid var(--line); border-radius: 12px;
}
/* Boards stay readable while waiting for the other player's move */
.board .cell:disabled { opacity: 1; }
.mark0 { color: var(--p0); } .mark1 { color: var(--p1); }
.board.big { gap: 3px; } .board.big .cell { border-radius: 6px; border-width: 1px; font-size: clamp(.9rem, 5vw, 1.4rem); }
.board.c4 { background: #3557a8; padding: 8px; border-radius: 18px; gap: 6px; }
.board.c4 .cell { border: none; border-radius: 50%; background: var(--bg); }
.board.felt { background: #2f7d55; padding: 6px; border-radius: 14px; gap: 4px; }
.board.felt .cell { background: #3a9265; border: none; border-radius: 6px; }
.hint { width: 22%; aspect-ratio: 1; border-radius: 50%; background: rgba(255, 255, 255, .55); display: block; }
.disc { width: 80%; aspect-ratio: 1; border-radius: 50%; display: block; }
.disc.inline { display: inline-block; width: 1em; vertical-align: -.15em; }
.disc.p0, .mark0 { background: var(--p0); color: #fff; }
.disc.p1, .mark1 { background: var(--p1); color: #fff; }
.cell.hit { background: var(--bad); color: #fff; }
.cell.miss { background: var(--line); color: var(--muted); }
.cell.ship { background: var(--p1); color: #fff; }
.cell.found { background: var(--good); color: #fff; }
.cell.given { font-weight: 800; background: var(--line); }
.memory .cell { font-size: clamp(1.4rem, 9vw, 2.4rem); }
.memory .cell.back { background: linear-gradient(135deg, var(--p0), var(--p1)); border-color: transparent; }
.memory .cell.back::after { content: "?"; color: rgba(255, 255, 255, .8); font-weight: 800; font-size: 1.4rem; }
.memory .cell.open { border-color: var(--ink); }
.memory .cell.m0 { border-color: var(--p0); } .memory .cell.m1 { border-color: var(--p1); }
.small-board { max-width: 300px; }

.tiles { display: grid; grid-template-columns: repeat(5, 1fr); gap: 4px; max-width: 280px; margin: 6px auto; }
.tile { aspect-ratio: 1; display: grid; place-items: center; border-radius: 8px; font-weight: 800; text-transform: uppercase; border: 2px solid var(--line); }
.tile.hit { background: var(--good); color: #fff; border-color: var(--good); }
.tile.near { background: #d9a83a; color: #fff; border-color: #d9a83a; }
.tile.miss { background: var(--muted); color: #fff; border-color: var(--muted); }
.tiles.mini { max-width: 140px; } .tiles.mini .tile { border-radius: 4px; }

.pads { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; max-width: 320px; margin: 12px auto; }
.pad { aspect-ratio: 1; opacity: .45; border: none; }
.pad.lit { opacity: 1; transform: scale(1.04); }
.pad0 { background: #e2557a; } .pad1 { background: #4f7bd9; } .pad2 { background: #3c9d6b; } .pad3 { background: #d9a83a; }
.react-zone { width: 100%; min-height: 220px; font-size: 1.5rem; border: none; color: #fff; background: var(--bad); }
.react-zone.go { background: var(--good); }
.react-zone.idle { background: var(--p1); }
.spot { display: grid; grid-template-columns: repeat(6, 1fr); gap: 2px; max-width: 250px; margin: 6px auto; }
.spot .cell { font-size: 1.15rem; border-width: 1px; border-radius: 6px; }

.rate { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; margin: 12px 0 4px; }
.rate button { padding: 0; font-size: 1.2rem; }
.rate button.picked { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.rate-legend { display: flex; justify-content: space-between; margin: 0; }

/* Dots and boxes: odd tracks are dots/line ends, even tracks are lines/boxes */
.dots { display: grid; grid-template-columns: repeat(var(--n), 14px 1fr) 14px; grid-template-rows: repeat(var(--n), 14px 1fr) 14px; max-width: 320px; aspect-ratio: 1; margin: 12px auto; }
.dot { background: var(--ink); border-radius: 50%; }
.ln { padding: 0; min-height: 0; border: none; border-radius: 6px; background: transparent; position: relative; }
.ln::after { content: ""; position: absolute; background: var(--line); border-radius: 4px; }
.ln.h::after { left: 2px; right: 2px; top: 4px; bottom: 4px; }
.ln.v::after { top: 2px; bottom: 2px; left: 4px; right: 4px; }
.ln:not(:disabled):hover::after { background: var(--muted); }
.ln.me::after { background: var(--p0); } .ln.them::after { background: var(--p1); }
.ln:disabled { opacity: 1; }
.box { display: grid; place-items: center; font-size: .8rem; font-weight: 700; color: #fff; margin: 3px; border-radius: 6px; }
.box.me { background: var(--p0); } .box.them { background: var(--p1); }

.slots, .letters { display: flex; justify-content: center; gap: 6px; flex-wrap: wrap; margin: 12px 0; }
.slot { width: 2.1rem; height: 2.6rem; display: grid; place-items: center; border-bottom: 3px solid var(--ink); font-size: 1.5rem; font-weight: 800; text-transform: uppercase; }
.letters .slot { border: 2px solid var(--line); border-radius: 10px; background: var(--card); font-size: 1.3rem; }
.keys { display: grid; grid-template-columns: repeat(7, 1fr); gap: 5px; }
.keys button { padding: 0; min-height: 44px; text-transform: uppercase; }

.canvas-wrap { position: relative; margin: 10px 0; }
canvas { width: 100%; aspect-ratio: 1; background: #fff; border-radius: var(--radius); border: 2px solid var(--line); touch-action: none; display: block; }
.toolbar { display: flex; gap: 6px; align-items: center; justify-content: space-between; margin: 8px 0; }
.palette { display: grid; grid-template-columns: repeat(9, minmax(0, 1fr)); gap: 6px; margin: 8px 0; }
.swatch { flex: 1; max-width: 44px; aspect-ratio: 1; min-height: 0; padding: 0; border-radius: 50%; border: 2px solid var(--line); }
.swatch.custom { position: relative; overflow: hidden; background: conic-gradient(red, yellow, lime, cyan, blue, magenta, red); }
.swatch.custom input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; padding: 0; border: none; min-height: 0; }
.swatch.on, .size.on { outline: 3px solid var(--ink); outline-offset: 2px; }
.size, .tool { flex: 1; min-width: 0; padding: 0; display: grid; place-items: center; }
.size i { background: var(--ink); border-radius: 50%; display: block; }
.toolbar .primary { flex: 2; padding: 0 8px; }

.row .grow { flex: 1; }
.card.deal { border-color: var(--accent); }
.note { background: var(--card); border: 2px dashed var(--accent); border-radius: 12px; padding: 8px 12px; margin: 8px 0; }
.log { display: flex; flex-direction: column; gap: 6px; margin: 10px 0; }
.msg { align-self: flex-start; background: var(--card); border: 2px solid var(--p1); border-radius: 14px; padding: 8px 12px; max-width: 85%; overflow-wrap: anywhere; }
.msg.me { align-self: flex-end; border-color: var(--p0); }
.msg small { display: block; }
.list { padding-left: 1.2em; }
.stmt { display: flex; gap: 8px; align-items: center; font-weight: 400; }
.stmt input[type=radio] { width: 24px; min-height: 24px; flex: none; }
.cat-table { width: 100%; border-collapse: collapse; }
.cat-table td, .cat-table th { border-bottom: 1px solid var(--line); padding: 6px 4px; text-align: left; overflow-wrap: anywhere; }

.reacts {
  position: fixed; left: 0; right: 0; bottom: 0; display: flex; justify-content: center; gap: 6px;
  padding: 8px 8px calc(8px + env(safe-area-inset-bottom)); background: var(--bg); border-top: 1px solid var(--line);
}
.reacts button { min-width: 48px; padding: 6px; font-size: 1.4rem; background: transparent; border-color: transparent; }
.float { position: fixed; bottom: 80px; font-size: 3rem; pointer-events: none; animation: rise 1.6s ease-out forwards; }
@keyframes rise { to { transform: translateY(-50vh) scale(1.4); opacity: 0; } }
#net { position: fixed; top: 0; left: 0; right: 0; background: var(--bad); color: #fff; text-align: center; padding: 6px; z-index: 5; }
#toast { position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; z-index: 5; max-width: 90vw; }
@media (prefers-reduced-motion: reduce) { .float { animation-duration: .01s; } .pad.lit { transform: none; } }
