/* Layout: the board is the table; record and controls sit beside it, rules and the dev log below. */
:root {
  --bg: #e9edf0;
  --surface: #f7f9fa;
  --ink: #18212b;
  --muted: #5b6874;
  --line: #c9d2d9;
  --accent: #2f5bd3;
  --accent-ink: #ffffff;
  --mark: #f0b429;
  --danger: #c8372d;
  --sq-light: #dfe5ea;
  --sq-dark: #8197ab;
  --piece-w: #fbfcfd;
  --piece-w-edge: #1b232c;
  --piece-b: #1b232c;
  --piece-b-edge: #eef2f5;
  --zone: rgba(47, 91, 211, 0.18);
  --font-display: "Dela Gothic One", "Zen Kaku Gothic New", "Hiragino Sans", sans-serif;
  --font-body: "Zen Kaku Gothic New", "Hiragino Sans", "Yu Gothic", "Noto Sans JP", sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;
  --font-piece: "Noto Sans Symbols 2", "Segoe UI Symbol", "Apple Symbols", "DejaVu Sans", sans-serif;
  --board: min(92vw, 560px);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #11161b; --surface: #192129; --ink: #e3e8ec; --muted: #93a1ad; --line: #2b3640;
    --accent: #7aa2ff; --accent-ink: #0d1520; --mark: #e0a526; --danger: #ff6b5e;
    --sq-light: #a3b3c1; --sq-dark: #5d7488;
    --piece-w: #fbfcfd; --piece-w-edge: #10161c; --piece-b: #10161c; --piece-b-edge: #c9d4dd;
    --zone: rgba(122, 162, 255, 0.22);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #11161b; --surface: #192129; --ink: #e3e8ec; --muted: #93a1ad; --line: #2b3640;
  --accent: #7aa2ff; --accent-ink: #0d1520; --mark: #e0a526; --danger: #ff6b5e;
  --sq-light: #a3b3c1; --sq-dark: #5d7488;
  --piece-w: #fbfcfd; --piece-w-edge: #10161c; --piece-b: #10161c; --piece-b-edge: #c9d4dd;
  --zone: rgba(122, 162, 255, 0.22);
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.6;
}
.page {
  max-width: 1080px;
  margin: 0 auto;
  padding-block: 20px 48px;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  display: grid;
  gap: 24px;
}

/* header */
.top { display: flex; flex-wrap: wrap; align-items: end; justify-content: space-between; gap: 12px 24px; }
.brand h1 { font-family: var(--font-display); font-weight: 400; font-size: clamp(26px, 5vw, 38px); line-height: 1.1; margin: 0; letter-spacing: 0.01em; text-wrap: balance; }
.brand .sub { margin: 4px 0 0; color: var(--muted); font-size: 13px; }
.version { display: grid; gap: 2px; font-size: 12px; color: var(--muted); }
select, button { font: inherit; color: var(--ink); }
select {
  background: var(--surface); border: 1px solid var(--line); border-radius: 6px;
  padding: 6px 8px; max-width: 100%;
}
button {
  background: var(--surface); border: 1px solid var(--line); border-radius: 6px;
  padding: 7px 12px; cursor: pointer;
}
button:hover { border-color: var(--accent); }
button:focus-visible, select:focus-visible, .sq:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

/* table */
.table { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 24px; align-items: start; }
@media (max-width: 860px) { .table { grid-template-columns: minmax(0, 1fr); } }
.boardWrap { display: grid; gap: 8px; justify-items: center; }
.player { width: var(--board); display: flex; align-items: center; gap: 10px; min-height: 34px; flex-wrap: wrap; font-size: 13px; }
.player .who { font-weight: 700; display: inline-flex; align-items: center; gap: 6px; }
.player .dot { width: 12px; height: 12px; border-radius: 50%; border: 1.5px solid var(--piece-w-edge); }
.player .dot.w { background: var(--piece-w); }
.player .dot.b { background: var(--piece-b); border-color: var(--piece-b-edge); }
.player.active .who { color: var(--accent); }
.player .extra { color: var(--muted); font-family: var(--font-mono); font-size: 12px; }
.hand { display: flex; flex-wrap: wrap; gap: 4px; }
.hand button { padding: 0 6px; min-width: 38px; height: 34px; display: inline-flex; align-items: center; gap: 2px; }
.hand button.sel { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent); }
.hand .cnt { font-family: var(--font-mono); font-size: 11px; color: var(--muted); }
.hand .pc { font-size: 24px; }

.boardFrame { position: relative; width: var(--board); max-width: 100%; }
.board {
  display: grid; width: 100%;
  border: 2px solid var(--ink); border-radius: 4px; overflow: hidden;
  user-select: none; -webkit-user-select: none; touch-action: manipulation;
}
.sq {
  position: relative; aspect-ratio: 1; border: 0; padding: 0; margin: 0; border-radius: 0;
  display: grid; place-items: center; cursor: pointer; background: var(--sq-light);
}
.sq.dark { background: var(--sq-dark); }
.sq.zone::before { content: ""; position: absolute; inset: 0; background: var(--zone); pointer-events: none; }
.sq.last::after { content: ""; position: absolute; inset: 0; background: var(--mark); opacity: 0.38; pointer-events: none; }
.sq.sel { outline: 4px solid var(--accent); outline-offset: -4px; z-index: 1; }
.sq.danger::before { content: ""; position: absolute; top: 0; right: 0; width: 34%; height: 34%; background: var(--danger); clip-path: polygon(0 0, 100% 0, 100% 100%); pointer-events: none; z-index: 2; }
.sq .camp { position: absolute; left: 0; right: 0; height: 0; border-top: 2px dashed var(--ink); opacity: 0.35; pointer-events: none; z-index: 1; }
.sq .camp.t { top: -1px; }
.sq .camp.b { bottom: -1px; }
.sq .dropcheck { position: absolute; left: 6%; bottom: 6%; width: 22%; height: 22%; border: 2px solid var(--danger); transform: rotate(45deg) scale(0.75); pointer-events: none; z-index: 2; opacity: 0.9; }
.sq.target { outline: 3px solid var(--danger); outline-offset: -3px; }
.sq.target.sel { outline-color: var(--accent); }
.sq.check { background: radial-gradient(circle, var(--danger) 0%, transparent 72%), var(--sq-light); }
.sq.dark.check { background: radial-gradient(circle, var(--danger) 0%, transparent 72%), var(--sq-dark); }
.sq .coord { position: absolute; font-family: var(--font-mono); font-size: 10px; line-height: 1; color: var(--ink); opacity: 0.55; pointer-events: none; }
.sq .coord.f { right: 3px; bottom: 2px; }
.sq .coord.r { left: 3px; top: 3px; }
.sq .tgt { position: absolute; width: 28%; height: 28%; border-radius: 50%; background: var(--ink); opacity: 0.28; pointer-events: none; z-index: 2; }
.sq .tgt.cap { width: 86%; height: 86%; background: transparent; border: 4px solid var(--ink); opacity: 0.3; }
.sq .tgt.risky { width: 34%; height: 34%; border-radius: 0; background: var(--danger); opacity: 0.85; clip-path: polygon(20% 0, 50% 30%, 80% 0, 100% 20%, 70% 50%, 100% 80%, 80% 100%, 50% 70%, 20% 100%, 0 80%, 30% 50%, 0 20%); border: 0; }
.sq .tgt.cap.risky { width: 40%; height: 40%; }
.pc {
  position: relative; z-index: 1; font-family: var(--font-piece); font-variant-emoji: text;
  font-size: calc(var(--board) / var(--cols) * 0.74); line-height: 1; pointer-events: none;
}
.pc.w { color: var(--piece-w); text-shadow: 0 0 1px var(--piece-w-edge), 1px 0 0 var(--piece-w-edge), -1px 0 0 var(--piece-w-edge), 0 1px 0 var(--piece-w-edge), 0 -1px 0 var(--piece-w-edge), 0 2px 3px rgba(0,0,0,0.25); }
.pc.b { color: var(--piece-b); text-shadow: 0 0 1px var(--piece-b-edge), 0 2px 3px rgba(0,0,0,0.25); }
.pc.svgpc { display: grid; place-items: center; width: 1em; height: 1em; }
.pc.svgpc svg { width: 0.86em; height: 0.86em; overflow: visible; filter: drop-shadow(0 2px 2px rgba(0,0,0,0.25)); }
.pc.svgpc.w svg path { fill: var(--piece-w); stroke: var(--piece-w-edge); stroke-width: 2.2; stroke-linejoin: round; }
.pc.svgpc.b svg path { fill: var(--piece-b); stroke: var(--piece-b-edge); stroke-width: 1.6; stroke-linejoin: round; }
.pc.svgpc svg path.inner { fill: none; stroke-width: 2.6; stroke-linecap: round; }
.pc.svgpc.b svg path.inner { stroke: var(--piece-b-edge); }
.overlay .row button .pc { font-size: 40px; }
.pc .tag {
  position: absolute; right: -0.35em; bottom: -0.15em; font-family: var(--font-mono); font-size: 0.32em;
  background: var(--accent); color: var(--accent-ink); border-radius: 3px; padding: 0 0.25em; text-shadow: none;
}
.sq.moved .pc { animation: land 160ms ease-out; }
@keyframes land { from { transform: scale(1.12); } to { transform: scale(1); } }
@media (prefers-reduced-motion: reduce) { .sq.moved .pc { animation: none; } }

.overlay {
  position: absolute; inset: 0; display: grid; place-items: center;
  background: color-mix(in srgb, var(--bg) 70%, transparent); z-index: 5;
}
.overlay .box { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 14px; display: grid; gap: 10px; text-align: center; }
.overlay .row { display: flex; gap: 8px; justify-content: center; }
.overlay .row button { width: 58px; height: 58px; font-family: var(--font-piece); font-size: 38px; line-height: 1; padding: 0; }

/* side panel */
.side { display: grid; gap: 16px; min-width: 0; }
.status {
  background: var(--surface); border: 1px solid var(--line); border-left: 5px solid var(--accent);
  border-radius: 6px; padding: 12px 14px; font-weight: 700; font-size: 17px;
}
.status.over { border-left-color: var(--mark); }
.status .detail { display: block; font-weight: 400; font-size: 13px; color: var(--muted); margin-top: 2px; }
.controls { display: grid; gap: 10px; }
.field { display: grid; grid-template-columns: 6.5em minmax(0, 1fr); align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.buttons { display: flex; flex-wrap: wrap; gap: 8px; }
.check { display: flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--muted); flex-wrap: wrap; }
.check input { accent-color: var(--accent); }
.key { display: inline-block; width: 12px; height: 12px; vertical-align: -1px; background: var(--sq-light); border: 1px solid var(--line); position: relative; }
.key.danger { background: linear-gradient(225deg, var(--danger) 0 40%, var(--sq-light) 40%); }
.key.target { box-shadow: inset 0 0 0 2px var(--danger); }
.key.dropcheck { background: var(--sq-light); }
.key.dropcheck::after { content: ""; position: absolute; inset: 2px; border: 2px solid var(--danger); transform: rotate(45deg) scale(0.7); }
.key.risky { background: var(--danger); clip-path: polygon(20% 0, 50% 30%, 80% 0, 100% 20%, 70% 50%, 100% 80%, 80% 100%, 50% 70%, 20% 100%, 0 80%, 30% 50%, 0 20%); border: 0; }
.info:empty { display: none; }
.info { background: var(--surface); border: 1px solid var(--line); border-radius: 6px; padding: 10px 12px; font-size: 13px; }
.moves h2, .notes h2 { font-size: 13px; letter-spacing: 0.08em; color: var(--muted); margin: 0 0 6px; font-weight: 700; }
#moveList {
  margin: 0; padding: 0; list-style: none; max-height: 260px; overflow-y: auto;
  font-family: var(--font-mono); font-size: 13px; font-variant-numeric: tabular-nums;
  display: grid; gap: 1px;
}
#moveList li { display: grid; grid-template-columns: 2.6em 1fr 1fr; gap: 8px; padding: 1px 4px; border-radius: 3px; }
#moveList .no { color: var(--muted); text-align: right; }
#moveList li:nth-child(odd) { background: color-mix(in srgb, var(--line) 35%, transparent); }

/* notes */
.notes { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr); gap: 24px; border-top: 1px solid var(--line); padding-top: 20px; }
@media (max-width: 860px) { .notes { grid-template-columns: minmax(0, 1fr); } }
.rules ul { margin: 0; padding-left: 1.2em; display: grid; gap: 6px; max-width: 60ch; }
.log .hint { margin: 0 0 10px; color: var(--muted); font-size: 13px; }
#devlog { margin: 0; padding: 0; list-style: none; display: grid; gap: 12px; }
#devlog li { display: grid; grid-template-columns: 3.2em minmax(0, 1fr); gap: 4px 10px; }
#devlog .n { font-family: var(--font-mono); font-weight: 600; color: var(--accent); font-size: 13px; padding-top: 2px; }
#devlog .what { font-weight: 700; }
#devlog .feel { grid-column: 2; color: var(--muted); font-size: 13.5px; }

/* how-to-play guide */
#guide:empty { display: none; }
#guide { display: grid; gap: 14px; }
#guide .lead { margin: 0; max-width: 62ch; }
#guide .cards { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
#guide .card { display: grid; grid-template-columns: auto minmax(0, 1fr); grid-template-rows: auto 1fr; gap: 2px 10px; align-items: start; padding: 8px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); }
#guide .card .dia { grid-row: span 2; }
#guide .card .who { display: flex; align-items: center; gap: 4px; font-size: 13px; }
#guide .card .who .pc { font-size: 22px; }
#guide .card .note { font-size: 12px; color: var(--muted); line-height: 1.45; }
.dia { display: grid; grid-template-columns: repeat(5, 11px); grid-template-rows: repeat(5, 11px); gap: 1px; background: var(--line); border: 1px solid var(--line); }
.dia i, #guide .legend i { display: block; width: 11px; height: 11px; background: var(--sq-light); }
.dia i.me { background: var(--ink); }
.dia i.mv, #guide .legend i.mv { background: var(--accent); }
.dia i.ray, #guide .legend i.ray { background: color-mix(in srgb, var(--accent) 45%, var(--sq-light)); }
.dia i.mv2, #guide .legend i.mv2 { background: repeating-linear-gradient(45deg, var(--accent) 0 2px, var(--sq-light) 2px 4px); }
.dia i.cap, #guide .legend i.cap { background: var(--danger); }
#guide .legend span { white-space: nowrap; }
#guide .legend { margin: 0; display: flex; flex-wrap: wrap; gap: 4px 12px; align-items: center; font-size: 12px; color: var(--muted); }
#guide .legend i { display: inline-block; vertical-align: -1px; margin-right: 3px; border: 1px solid var(--line); }
.rulesdl { margin: 0; display: grid; grid-template-columns: 5.5em minmax(0, 1fr); gap: 6px 12px; max-width: 64ch; }
.rulesdl dt { font-weight: 700; }
.rulesdl dd { margin: 0; }
#guide h3 { font-size: 13px; letter-spacing: 0.08em; color: var(--muted); margin: 4px 0 0; }
#guide .tips { margin: 0; padding-left: 1.2em; display: grid; gap: 4px; font-size: 13.5px; max-width: 64ch; }
