:root {
  --bg: #0e1120;
  --bg2: #151a30;
  --card: #181d35;
  --line: #2a3156;
  --text: #e9ecf8;
  --muted: #98a0c3;
  --accent: #7c8cff;
  --accent-text: #0e1120;
  --cell: #232a4a;
  --cell-hi: #2d3560;
  --board: #121630;
  --danger: #ff6b6b;
  --ok: #5fe0a0;
  --goal: #ffd166;
  --goal-cell: #3a3550;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #eef0f8; --bg2: #e4e7f4; --card: #ffffff; --line: #d5d9ec; --text: #1a1f38; --muted: #5e6690;
    --accent: #4b5bdc; --accent-text: #ffffff; --cell: #dfe3f3; --cell-hi: #cfd5ef; --board: #c4cae6;
    --goal: #d18a00; --goal-cell: #f6ead0;
    color-scheme: light;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: radial-gradient(1200px 600px at 50% -200px, var(--bg2), var(--bg)) fixed, var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
main { max-width: 560px; margin: 0 auto; padding: 0 16px 64px; } /* bottom room so the fixed 🤖 button never covers the last button */

.top { max-width: 560px; margin: 0 auto; padding: 14px 16px; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.brand { display: inline-flex; align-items: center; gap: 10px; color: var(--text); text-decoration: none; font-weight: 800; font-size: 20px; letter-spacing: .3px; }
.logo { display: inline-grid; grid-template-columns: repeat(3, 8px); gap: 4px; }
.logo i { width: 8px; height: 8px; border-radius: 50%; display: block; }
.logo i:nth-child(1) { background: #ff6b6b; } .logo i:nth-child(2) { background: #ffb547; } .logo i:nth-child(3) { background: #2ed3b7; }
.roomTag { font: 600 13px/1 ui-monospace, Consolas, monospace; letter-spacing: 2px; padding: 6px 10px; border: 1px solid var(--line); border-radius: 999px; color: var(--muted); }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 16px; margin: 0 0 14px; box-shadow: 0 6px 24px rgba(0,0,0,.18); }
h2 { font-size: 18px; margin: 0 0 12px; }
.muted { color: var(--muted); } .small { font-size: 13px; } .center { text-align: center; }
.banner { background: color-mix(in srgb, var(--accent) 18%, transparent); border: 1px solid var(--accent); padding: 12px 14px; border-radius: 12px; margin-bottom: 14px; }

.field { display: block; font-size: 14px; color: var(--muted); margin-bottom: 14px; }
input {
  width: 100%; margin-top: 6px; font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--line);
  border-radius: 10px; padding: 11px 12px; outline: none; min-width: 0;
}
input:focus { border-color: var(--accent); }

.btn {
  font-family: inherit; font-weight: 600; font-size: 15px; line-height: 1.1; color: var(--text); background: var(--cell); border: 1px solid var(--line);
  border-radius: 12px; padding: 0 16px; min-height: 46px; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  touch-action: manipulation; user-select: none;
}
.btn:hover:not(:disabled) { background: var(--cell-hi); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: transparent; }
.btn.primary:hover:not(:disabled) { filter: brightness(1.08); background: var(--accent); }
.btn.ghost { background: transparent; }
.btn.block { width: 100%; }
.btn.on { background: var(--text); color: var(--bg); border-color: transparent; }
.stack { display: grid; gap: 10px; }
.joinRow, .shareRow { display: flex; gap: 8px; }
.joinRow input { margin: 0; width: 110px; flex: 0 0 auto; text-transform: uppercase; letter-spacing: 3px; font-weight: 700; text-align: center; }
.joinRow .btn { flex: 1; }
.shareRow input { margin: 0; flex: 1; font-size: 16px; color: var(--muted); }
.seg { display: inline-flex; gap: 6px; }
.seg.wide { display: grid; grid-template-columns: repeat(3, 1fr); }
.seg.wide .btn { padding: 0 6px; }

.swatches { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 8px; }
.swatch { width: 38px; height: 38px; border-radius: 50%; border: 3px solid transparent; cursor: pointer; padding: 0; position: relative; box-shadow: inset 0 0 0 2px rgba(0,0,0,.15); }
.swatch.sel { border-color: var(--text); }
.swatch.taken { opacity: .25; cursor: not-allowed; }
.swatch.taken::after { content: ""; position: absolute; left: 50%; top: 4px; bottom: 4px; width: 2px; background: var(--text); transform: rotate(45deg); }

.bigCode { font: 800 46px/1.1 ui-monospace, Consolas, monospace; letter-spacing: 10px; margin: 4px 0 12px; padding-left: 10px; }
.plist { list-style: none; margin: 0 0 14px; padding: 0; display: grid; gap: 8px; }
.plist li { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 12px; background: var(--bg); border: 1px solid var(--line); }
.plist .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dot { width: 18px; height: 18px; border-radius: 50%; flex: 0 0 auto; box-shadow: 0 0 12px currentColor; background: currentColor; }
.tag { font-size: 12px; color: var(--muted); border: 1px solid var(--line); border-radius: 999px; padding: 2px 8px; }
.off { opacity: .5; }
.xbtn { background: none; border: 0; color: var(--muted); font-size: 18px; cursor: pointer; padding: 4px 6px; }

/* game */
.status { text-align: center; font-weight: 700; font-size: 17px; padding: 10px 12px; border-radius: 12px; margin-bottom: 10px; background: var(--card); border: 1px solid var(--line); }
.status.mine { background: color-mix(in srgb, var(--turn, var(--accent)) 22%, var(--card)); border-color: var(--turn, var(--accent)); }
.goal { text-align: center; font-size: 14px; color: var(--muted); margin: -4px 0 10px; }
.chips { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin-bottom: 10px; }
.chip { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-radius: 12px; background: var(--card); border: 1px solid var(--line); min-width: 0; }
.chip.turn { border-color: var(--turn); box-shadow: 0 0 0 1px var(--turn) inset; }
.chip .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; font-size: 14px; }
.chip .walls { font: 700 13px/1 ui-monospace, Consolas, monospace; color: var(--muted); white-space: nowrap; }
.chip.out { opacity: .4; text-decoration: line-through; }

.boardWrap { background: var(--board); border-radius: 18px; padding: 6px; border: 1px solid var(--line); }
#board { display: block; width: 100%; height: auto; touch-action: manipulation; user-select: none; -webkit-user-select: none; }
#board .cell { fill: var(--cell); }
#board .cell.target { fill: var(--cell-hi); cursor: pointer; }
#board .goalCell { fill: var(--goal-cell); stroke: var(--goal); stroke-width: 3; }
#board .goalCell.target { cursor: pointer; stroke-width: 6; }
#board .moveHint { pointer-events: none; }
#board .pawn { transition: transform .25s ease; }
#board .pulse { animation: pulse 1.6s ease-in-out infinite; transform-box: fill-box; transform-origin: center; }
@keyframes pulse { 0%, 100% { opacity: .55; transform: scale(1); } 50% { opacity: 0; transform: scale(1.5); } }
#board .ghost { pointer-events: none; }
.hint { min-height: 22px; text-align: center; color: var(--muted); font-size: 14px; margin: 8px 0; }
.hint.bad { color: var(--danger); }
.controls { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-bottom: 12px; }
.controls .btn { padding: 0 14px; }
.log { list-style: none; padding: 0; margin: 0 0 14px; font-size: 13px; color: var(--muted); display: grid; gap: 2px; text-align: center; }

.overlay { position: fixed; inset: 0; background: rgba(5,7,15,.6); display: grid; place-items: center; padding: 16px; z-index: 20; backdrop-filter: blur(3px); }
.win { width: min(380px, 100%); text-align: center; }
.winDot { width: 64px; height: 64px; border-radius: 50%; margin: 6px auto 12px; background: currentColor; box-shadow: 0 0 40px currentColor; }
.toast {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translate(-50%, 30px); opacity: 0;
  background: var(--text); color: var(--bg); padding: 12px 16px; border-radius: 12px; font-weight: 600; font-size: 14px;
  transition: .2s; pointer-events: none; max-width: calc(100vw - 32px); z-index: 30; text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.bad { background: var(--danger); color: #fff; }
.autoBtn { position: fixed; right: 12px; bottom: 12px; z-index: 20; width: 34px; height: 34px; padding: 0; border-radius: 50%;
  font-size: 16px; line-height: 1; background: var(--card); border: 1px solid var(--line); opacity: .55; cursor: pointer; }
.autoBtn:hover { opacity: 1; }
.autoBtn.on { opacity: 1; background: var(--accent); border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 35%, transparent); }
.autoBtn[hidden] { display: none; }

/* chat: below the game on phones, a sidebar on the right on wide screens */
.chat { display: flex; flex-direction: column; max-width: 528px; height: 280px; margin: 0 auto 64px; background: var(--card);
  border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
@media (max-width: 559px) { .chat { margin: 0 16px 64px; } }
.chat[hidden] { display: none; }
.chatHead { font-weight: 700; padding: 10px 12px; border-bottom: 1px solid var(--line); }
.chatList { list-style: none; margin: 0; padding: 8px 12px; flex: 1; overflow-y: auto; font-size: 14px; overflow-wrap: anywhere; }
.chatMsg { padding: 3px 0; line-height: 1.35; }
.chatMsg .dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: currentColor; margin-right: 6px; vertical-align: 1px; }
.chatMsg b { margin-right: 2px; }
.chatEmpty { color: var(--muted); }
.chatForm { display: flex; gap: 6px; padding: 8px; border-top: 1px solid var(--line); }
.chatForm[hidden] { display: none; }
.chatForm input { flex: 1; min-width: 0; font-size: 16px; }
@media (min-width: 1240px) {
  .chat { position: fixed; top: 70px; right: 16px; bottom: 60px; width: 300px; height: auto; margin: 0; }
}

details.rules summary { list-style: none; cursor: pointer; }
details.rules summary::-webkit-details-marker { display: none; }
details.rules summary h2 { display: inline; }
details.rules summary::after { content: " +"; color: var(--muted); font-weight: 700; }
details.rules[open] summary::after { content: " \2013"; }
details.rules ul { margin: 12px 0 0; padding-left: 20px; color: var(--muted); }
details.rules li { margin-bottom: 6px; }
details.rules b { color: var(--text); }

@media (min-width: 520px) { .chips { grid-template-columns: repeat(4, minmax(0, 1fr)); } .chips.two { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
