/* Layout: the wooden board is the hero on a stone-grey table; a narrow column holds the scoreboard, last move, game record and rules. */
:root {
  --table: #e4e8e3;      /* stone table */
  --surface: #f5f7f3;
  --ink: #1c2725;
  --muted: #5d6b67;
  --rule: #cdd5ce;
  --brass: #9c6b12;      /* points, goals */
  --alert: #c4402a;      /* danger (semantic) */
  --go: #2f7d4b;         /* reinforcement / good (semantic) */
  --maple: #e9d0a3;      /* board woods */
  --walnut: #7a4e32;
  --frame: #3b2617;
  --ebony: #1d1a17;
  --ebony-hi: #4b433b;
  --ivory: #f2ebdd;
  --ivory-edge: #b7a78e;
  --hl: #f0bf45;
  --last: rgba(240, 191, 69, 0.33);
  --shadow: rgba(20, 24, 22, 0.28);
  --font-display: "Dela Gothic One", "Hiragino Sans", "Noto Sans JP", system-ui, sans-serif;
  --font-body: "Zen Kaku Gothic New", "Hiragino Sans", "Noto Sans JP", system-ui, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --table: #121816; --surface: #1a2220; --ink: #e4ebe7; --muted: #95a39e; --rule: #2c3734;
    --brass: #d9aa45; --alert: #ff7a5c; --go: #6cc48a;
    --maple: #cfb185; --walnut: #5f3b25; --frame: #24170e;
    --last: rgba(240, 191, 69, 0.28); --shadow: rgba(0, 0, 0, 0.5);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --table: #121816; --surface: #1a2220; --ink: #e4ebe7; --muted: #95a39e; --rule: #2c3734;
  --brass: #d9aa45; --alert: #ff7a5c; --go: #6cc48a;
  --maple: #cfb185; --walnut: #5f3b25; --frame: #24170e;
  --last: rgba(240, 191, 69, 0.28); --shadow: rgba(0, 0, 0, 0.5);
  color-scheme: dark;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--table);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.6;
}
.app {
  max-width: 1080px; margin: 0 auto;
  padding-block: 20px 32px;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}

/* header */
.top { display: flex; flex-wrap: wrap; gap: 12px 24px; align-items: flex-end; justify-content: space-between; }
.brand { display: grid; gap: 2px; }
h1 { font-family: var(--font-display); font-weight: 400; font-size: clamp(1.6rem, 4vw, 2.2rem); line-height: 1.1; margin: 0; letter-spacing: 0.04em; text-wrap: balance; }
.tagline { color: var(--muted); font-size: .85rem; margin: 0; }
.controls { display: flex; flex-wrap: wrap; gap: 8px 10px; align-items: center; }
.controls label { font-size: .8rem; color: var(--muted); display: flex; gap: 6px; align-items: center; letter-spacing: .04em; }
select, button {
  font: inherit; font-size: .88rem; line-height: 1.2;
  padding: 7px 10px; border-radius: 6px;
  border: 1px solid var(--rule); background: var(--surface); color: var(--ink);
}
#variant { max-width: 200px; }
button { cursor: pointer; }
button.primary { background: var(--ink); color: var(--surface); border-color: var(--ink); }
button:hover { border-color: var(--brass); }
select:focus-visible, button:focus-visible, input:focus-visible, summary:focus-visible { outline: 2px solid var(--brass); outline-offset: 2px; }
.chk { cursor: pointer; }
.chk input { accent-color: var(--brass); }

/* play area */
.play { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 24px; margin-top: 20px; align-items: start; }
@media (max-width: 800px) { .play { grid-template-columns: minmax(0, 1fr); } }
.board-wrap { width: 100%; max-width: 640px; margin: 0 auto; position: relative; }
.goal { text-align: center; font-size: .8rem; color: var(--muted); margin: 6px 0; letter-spacing: .12em; }
.board {
  display: grid; aspect-ratio: 1; width: 100%; max-width: 100%;
  border: 8px solid var(--frame); border-radius: 4px;
  box-shadow: 0 10px 30px var(--shadow), inset 0 0 0 1px rgba(255,255,255,.06);
  user-select: none; touch-action: manipulation;
}
.sq { position: relative; display: flex; align-items: center; justify-content: center; min-width: 0; min-height: 0; overflow: hidden; }
.sq.light { background: var(--maple); }
.sq.dark { background: var(--walnut); cursor: pointer; }
.sq.last { box-shadow: inset 0 0 0 999px var(--last); }
.sq.hinted { box-shadow: inset 0 0 0 4px var(--go); }
.sq.target::after {
  content: ""; width: 30%; height: 30%; border-radius: 50%;
  background: var(--hl); opacity: .9; position: absolute;
}
.sq.target.cap::after { background: var(--alert); }
.sq.target.bank::after { background: var(--go); width: 40%; height: 40%; box-shadow: 0 0 0 3px rgba(255,255,255,.45); }
.sq.target.risk::after { background: var(--alert); box-shadow: 0 0 0 3px rgba(255, 255, 255, .5); }
.sq.target.risk::before {
  content: attr(data-risk); position: absolute; right: 4%; top: 3%; z-index: 2;
  font-family: var(--font-display); font-size: clamp(9px, 1.9vw, 14px); line-height: 1; color: #fff;
  background: var(--alert); padding: 2px 4px; border-radius: 4px;
}
.sq .coord { position: absolute; font-family: var(--font-mono); font-size: 10px; pointer-events: none; opacity: .7; }
.sq .coord.rank { left: 3px; top: 2px; }
.sq .coord.file { right: 4px; bottom: 1px; }
.sq.dark .coord { color: var(--maple); }
.sq.light .coord { color: var(--walnut); }

.piece {
  width: 78%; height: 78%; border-radius: 50%;
  position: relative; transition: transform .12s ease;
  display: flex; align-items: center; justify-content: center;
  font-size: clamp(12px, 3.6vw, 26px); font-weight: 700; line-height: 1;
  aspect-ratio: 1; flex: none;
}
.piece.p0 { background: radial-gradient(circle at 35% 30%, var(--ebony-hi), var(--ebony) 62%); box-shadow: 0 3px 0 #000, 0 5px 8px rgba(0,0,0,.45); color: #e9b949; }
.piece.p1 { background: radial-gradient(circle at 35% 30%, #fff, var(--ivory) 62%); box-shadow: 0 3px 0 var(--ivory-edge), 0 5px 8px rgba(0,0,0,.35); color: #b0412a; }
.piece.movable { outline: 3px solid var(--hl); outline-offset: 2px; }
.piece.mustcap { outline-color: var(--alert); }
.piece.selected { transform: translateY(-4px) scale(1.06); outline: 3px solid #fff !important; outline-offset: 2px; }
.piece.danger { box-shadow: 0 0 0 3px var(--alert), 0 0 12px 2px rgba(196,64,42,.7) !important; animation: pulse 1.2s ease-in-out infinite; }
.piece.prey::before { content: ""; position: absolute; inset: 30%; border-radius: 50%; border: 3px dashed var(--alert); }
.piece.spawn { animation: spawn 1.4s ease-out 2; box-shadow: 0 0 0 3px var(--go), 0 0 14px 3px rgba(47,125,75,.75) !important; }
@keyframes pulse { 50% { transform: scale(0.94); } }
@keyframes spawn { 0% { transform: scale(.4); opacity: .3; } 40% { transform: scale(1.1); opacity: 1; } 100% { transform: scale(1); } }

.toast {
  position: absolute; left: 50%; top: 45%; transform: translate(-50%, -50%) scale(.8);
  background: rgba(24, 20, 16, .92); color: #f0c35a;
  font-family: var(--font-display); font-weight: 400; font-size: clamp(1rem, 4.6vw, 1.4rem);
  width: max-content; max-width: 92%; white-space: pre-line; text-align: center; line-height: 1.4;
  padding: 12px 22px; border-radius: 10px; pointer-events: none; opacity: 0;
}
.toast.show { animation: toast 1.6s ease forwards; }
@keyframes toast { 0% { opacity: 0; transform: translate(-50%, -50%) scale(.8); } 15% { opacity: 1; transform: translate(-50%, -50%) scale(1); } 75% { opacity: 1; } 100% { opacity: 0; } }

/* side column */
.side { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.status { font-weight: 700; font-size: 1.05rem; padding: 12px 14px; background: var(--surface); border-left: 4px solid var(--brass); border-radius: 0 8px 8px 0; min-height: 3em; }
.lastmove { font-weight: 400; font-size: .85rem; color: var(--muted); margin-top: 4px; }
.warn { color: var(--alert); font-size: .85rem; font-weight: 700; display: block; margin-top: 4px; }
.counts { padding: 4px 2px; font-size: .9rem; display: grid; gap: 2px; }
.score { display: grid; gap: 4px; margin-bottom: 8px; padding-bottom: 10px; border-bottom: 1px solid var(--rule); }
.scoreline { display: flex; align-items: center; font-family: var(--font-display); font-size: 1.1rem; letter-spacing: .04em; }
.star { color: var(--rule); font-size: 1.35rem; margin-left: 4px; line-height: 1; }
.star.on { color: var(--brass); }
.muted { color: var(--muted); }
.history {
  margin: 0; padding: 8px 8px 8px 36px; max-height: 240px; overflow: auto;
  font-family: var(--font-mono); font-size: .8rem; font-variant-numeric: tabular-nums;
  background: var(--surface); border-radius: 8px;
}
.history li.note { list-style: none; margin-left: -28px; color: var(--muted); font-family: var(--font-body); }
.rules { font-size: .9rem; line-height: 1.7; border-top: 1px solid var(--rule); padding-top: 8px; }
.rules summary { cursor: pointer; font-weight: 700; letter-spacing: .04em; }
.rules ul { padding-left: 1.2em; margin: 6px 0; }
.rules p { margin: 6px 0; }
.hint { color: var(--muted); font-size: .85rem; }
.dot { display: inline-block; width: .8em; height: .8em; border-radius: 50%; vertical-align: -0.05em; margin-right: 6px; flex: none; }
.dot.p0 { background: var(--ebony); border: 1px solid #000; }
.dot.p1 { background: var(--ivory); border: 1px solid var(--ivory-edge); }

@media (prefers-reduced-motion: reduce) {
  .piece, .piece.danger, .piece.spawn, .toast.show { animation: none !important; transition: none !important; }
  .toast.show { opacity: 1; }
}
.history:empty { display: none; }
.sq.repblock::after { content: "⟲"; position: absolute; color: rgba(255,255,255,.55); font-size: clamp(14px, 3vw, 24px); }
