:root {
  --bg: #15181d;
  --panel: #1e2229;
  --panel-2: #272c35;
  --line: #333a45;
  --text: #e9e6df;
  --muted: #9aa1ad;
  --accent: #e0a94a;
  --accent-ink: #1b1508;
  --danger: #d9634f;
  --ok: #6fbf73;
  --sq-light: #ecdfc7;
  --sq-dark: #a97c5a;
  --radius: 12px;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f4f1ea;
    --panel: #ffffff;
    --panel-2: #f0ece3;
    --line: #dcd6c8;
    --text: #23262b;
    --muted: #6a707b;
    --accent: #b9781a;
    --accent-ink: #ffffff;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100dvh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  -webkit-tap-highlight-color: transparent;
}
.top {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px; max-width: 1120px; margin: 0 auto;
}
.brand { color: var(--text); text-decoration: none; font-weight: 700; font-size: 20px; letter-spacing: .02em; }
.brand-mark { color: var(--accent); font-size: 26px; vertical-align: -3px; font-family: "Segoe UI Symbol", "Noto Sans Symbols 2", "Apple Symbols", "DejaVu Sans", sans-serif; }

.btn {
  appearance: none; border: 1px solid var(--line); background: var(--panel-2); color: var(--text);
  padding: 10px 14px; border-radius: 10px; font: inherit; font-weight: 600; cursor: pointer;
  text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px;
}
.btn:hover { border-color: var(--muted); }
.btn:focus-visible, .chip input:focus-visible + span, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { color: var(--danger); }
.btn.danger.armed { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.ghost { background: transparent; }
.btn.small { min-height: 36px; padding: 6px 12px; font-size: 14px; }
.btn.big { width: 100%; font-size: 18px; padding: 14px; }
.btn:disabled { opacity: .5; cursor: default; }

/* Home screen */
.home { max-width: 560px; margin: 0 auto; padding: 8px 16px 40px; }
.home h1 { font-size: 30px; margin: 12px 0 4px; }
.lead { color: var(--muted); margin: 0 0 20px; }
fieldset { border: 0; padding: 0; margin: 0 0 22px; }
legend { font-weight: 700; margin-bottom: 8px; padding: 0; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip input { position: absolute; opacity: 0; pointer-events: none; }
.chip span {
  display: inline-flex; flex-direction: column; align-items: center; justify-content: center;
  min-width: 76px; min-height: 48px; padding: 6px 14px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--panel); cursor: pointer; font-weight: 600;
}
.chip span small { font-weight: 400; color: var(--muted); font-size: 12px; }
.chip input:checked + span { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); color: var(--accent); }
.custom { display: flex; gap: 12px; margin-top: 12px; flex-wrap: wrap; }
.custom label { display: flex; flex-direction: column; gap: 4px; font-size: 14px; color: var(--muted); flex: 1; min-width: 140px; }
input[type=number], .linkrow input {
  background: var(--panel); color: var(--text); border: 1px solid var(--line);
  border-radius: 10px; padding: 10px 12px; font: inherit; min-height: 44px; min-width: 0;
}
.switch { display: flex; align-items: center; gap: 10px; cursor: pointer; }
.switch input { width: 22px; height: 22px; accent-color: var(--accent); }
.switch small { color: var(--muted); }

/* Game */
.game { max-width: 1120px; margin: 0 auto; padding: 0 12px 24px; }
.invite {
  background: var(--panel); border: 1px solid var(--accent); border-radius: var(--radius);
  padding: 14px 16px; margin: 0 auto 14px; max-width: 720px;
}
.invite h2 { margin: 0 0 2px; font-size: 20px; }
.invite p { margin: 0 0 10px; color: var(--muted); }
.linkrow { display: flex; gap: 8px; flex-wrap: wrap; }
.linkrow input { flex: 1 1 220px; }
.apps { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.warn { color: var(--accent) !important; font-size: 14px; margin: 10px 0 0 !important; }

.layout { display: flex; flex-direction: column; gap: 12px; align-items: center; }
.boardcol { --size: min(100vw - 24px, 100dvh - 170px, 720px); width: var(--size); }
.clocks, .side { width: 100%; max-width: 720px; }
.side { display: flex; flex-direction: column; gap: 10px; }
@media (min-width: 900px) {
  .layout {
    display: grid; grid-template-columns: auto 320px; grid-template-rows: auto 1fr;
    grid-template-areas: "board clocks" "board side";
    justify-content: center; align-items: start; gap: 10px 20px;
  }
  .boardcol { grid-area: board; --size: min(100vw - 400px, 100dvh - 90px, 760px); }
  .clocks { grid-area: clocks; }
  .side { grid-area: side; }
}

/* Both clocks side by side: White on the left, Black on the right */
.clocks { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.clockbox { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 8px 12px; min-width: 0; }
.clockbox .who { display: flex; align-items: center; gap: 6px; font-size: 14px; font-weight: 600; color: var(--muted); }
.clockbox .name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.clockbox .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--line); flex: none; }
.clockbox .dot.on { background: var(--ok); }
.clockbox .clock { font: 700 26px/1.25 ui-monospace, "SF Mono", Menlo, Consolas, monospace; color: var(--muted); }
.clockbox .clock:empty { display: none; }
.clockbox.active { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.clockbox.active .who, .clockbox.active .clock { color: var(--text); }
.clockbox.low.active { border-color: var(--danger); box-shadow: inset 0 0 0 1px var(--danger); }
.clockbox.low.active .clock { color: var(--danger); }

.board {
  width: var(--size); height: var(--size);
  display: grid; grid-template-columns: repeat(8, 1fr); grid-template-rows: repeat(8, 1fr);
  border-radius: 6px; overflow: hidden; user-select: none; -webkit-user-select: none; touch-action: none;
  box-shadow: 0 6px 24px rgba(0, 0, 0, .35);
}
.sq { position: relative; display: flex; align-items: center; justify-content: center; }
.sq.light { background: var(--sq-light); }
.sq.dark { background: var(--sq-dark); }
.sq.last::before { content: ""; position: absolute; inset: 0; background: rgba(240, 200, 60, .42); }
.sq.sel::before { content: ""; position: absolute; inset: 0; background: rgba(90, 160, 90, .6); }
.sq.check::before { content: ""; position: absolute; inset: 0; background: radial-gradient(circle, rgba(230, 50, 30, .9) 20%, rgba(230, 50, 30, 0) 75%); }
.sq.target { cursor: pointer; }
.sq.target::after {
  content: ""; position: absolute; width: 30%; height: 30%; border-radius: 50%; background: rgba(20, 30, 20, .28);
}
.sq.target.occupied::after { width: 88%; height: 88%; background: none; border: calc(var(--size) / 8 * .09) solid rgba(20, 30, 20, .28); box-sizing: border-box; }
.piece {
  position: relative; z-index: 1; line-height: 1; pointer-events: none;
  font-size: calc(var(--size) / 8 * .8);
  font-family: "Segoe UI Symbol", "Noto Sans Symbols 2", "Noto Sans Symbols2", "Apple Symbols", "Arial Unicode MS", "DejaVu Sans", sans-serif;
}
.piece.w { color: #fbfaf6; text-shadow: 0 0 1.5px #111, 0 0 1.5px #111, 1px 1px 0 #111, -1px -1px 0 #111, 1px -1px 0 #111, -1px 1px 0 #111; }
.piece.b { color: #1c1b1a; text-shadow: 0 0 1.5px #eee, 0 0 1.5px #eee; }
.sq.mine { cursor: grab; }
.sq.dragging .piece { opacity: .25; }
.coord { position: absolute; font-size: calc(var(--size) / 8 * .17); font-weight: 700; line-height: 1; pointer-events: none; }
.coord.rank { top: 4%; left: 5%; }
.coord.file { bottom: 4%; right: 6%; }
.sq.light .coord { color: var(--sq-dark); }
.sq.dark .coord { color: var(--sq-light); }
.ghost-piece { position: fixed; z-index: 30; pointer-events: none; transform: translate(-50%, -55%); }

.status { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; font-weight: 700; font-size: 17px; }
.status.turn { border-color: var(--accent); }
.status small { display: block; font-weight: 400; color: var(--muted); font-size: 14px; }
.offers:empty, .moves:empty { display: none; }
.offer { background: var(--panel); border: 1px solid var(--accent); border-radius: var(--radius); padding: 10px 14px; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.offer span { flex: 1 1 160px; }
.rules { color: var(--muted); font-size: 14px; padding: 0 2px; }
.moves {
  list-style: none; margin: 0; padding: 8px 10px; background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); max-height: 220px; overflow-y: auto;
  display: grid; grid-template-columns: 2.4em 1fr 1fr; gap: 2px 8px;
  font: 15px/1.5 ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}
.moves .n { color: var(--muted); text-align: right; }
.moves .cur { color: var(--accent); font-weight: 700; }
@media (max-width: 899px) { .moves { max-height: 110px; } }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.actions .btn { flex: 1 1 auto; }

.promo { position: fixed; inset: 0; background: rgba(0, 0, 0, .55); display: flex; align-items: center; justify-content: center; z-index: 40; }
.promo-box { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; display: flex; gap: 8px; --size: min(90vw, 480px); }
.promo-box button { width: calc(var(--size) / 5); height: calc(var(--size) / 5); border-radius: 10px; border: 1px solid var(--line); background: var(--sq-light); cursor: pointer; display: flex; align-items: center; justify-content: center; }
.promo-box button:hover { background: var(--accent); }
.promo-box .piece { font-size: calc(var(--size) / 5 * .8); }

.toast {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-weight: 600; z-index: 50;
  max-width: calc(100vw - 32px); text-align: center; box-shadow: 0 6px 20px rgba(0, 0, 0, .35);
}
