/* レイアウト: 方眼ノートの1ページ。左に盤（紙面）、右に余白のメモ欄（スコア・操作・ルール）。
   明るいテーマ = ノートと赤青鉛筆 / 暗いテーマ = 黒板とチョーク */
:root {
  --paper: #f4f7fa;
  --paper-2: #ffffff;
  --grid: rgba(64, 112, 160, 0.12);
  --grid-strong: rgba(64, 112, 160, 0.22);
  --ink: #1c2331;
  --muted: #5a6475;
  --faint: rgba(28, 35, 49, 0.16);
  --p1: #2456c8;
  --p1-soft: rgba(36, 86, 200, 0.13);
  --p2: #cf3a2b;
  --p2-soft: rgba(207, 58, 43, 0.13);
  --gold: #b07a00;
  --gold-soft: rgba(176, 122, 0, 0.16);
  --focus: #2456c8;
  --c1: #2456c8;
  --c2: #cf3a2b;
  --font-display: "Dela Gothic One", "Hiragino Sans", "Yu Gothic", "Noto Sans JP", sans-serif;
  --font-body: "Zen Kaku Gothic New", "Hiragino Sans", "Yu Gothic", "Noto Sans JP", sans-serif;
  --font-hand: "Klee One", "Hiragino Mincho ProN", "Yu Mincho", serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #1d2924;
    --paper-2: #24322c;
    --grid: rgba(230, 240, 230, 0.05);
    --grid-strong: rgba(230, 240, 230, 0.09);
    --ink: #e8ece4;
    --muted: #a3aea5;
    --faint: rgba(232, 236, 228, 0.18);
    --p1: #82b4ff;
    --p1-soft: rgba(130, 180, 255, 0.17);
    --p2: #ff8f7c;
    --p2-soft: rgba(255, 143, 124, 0.17);
    --gold: #f1c75b;
    --gold-soft: rgba(241, 199, 91, 0.18);
    --focus: #82b4ff;
    --c1: #5a8ee8;
    --c2: #e2685a;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #1d2924;
  --paper-2: #24322c;
  --grid: rgba(230, 240, 230, 0.05);
  --grid-strong: rgba(230, 240, 230, 0.09);
  --ink: #e8ece4;
  --muted: #a3aea5;
  --faint: rgba(232, 236, 228, 0.18);
  --p1: #82b4ff;
  --p1-soft: rgba(130, 180, 255, 0.17);
  --p2: #ff8f7c;
  --p2-soft: rgba(255, 143, 124, 0.17);
  --gold: #f1c75b;
  --gold-soft: rgba(241, 199, 91, 0.18);
  --focus: #82b4ff;
  --c1: #5a8ee8;
  --c2: #e2685a;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  background-color: var(--paper);
  background-image:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 22px 22px;
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.6;
  -webkit-tap-highlight-color: transparent;
}

.app {
  max-width: 1120px;
  margin: 0 auto;
  padding-block: 20px 40px;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  grid-template-areas: "head head" "board side";
  gap: 18px 36px;
}
.head { grid-area: head; display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.title { font-family: var(--font-display); font-weight: 400; font-size: clamp(26px, 4vw, 36px); line-height: 1.1; margin: 0; letter-spacing: 0.02em; text-wrap: balance; }
.title .amp { color: var(--p2); }
.title .dot { color: var(--p1); }
.ruleset-tag { font-family: var(--font-hand); font-weight: 600; color: var(--muted); font-size: 15px; }

.board-wrap { grid-area: board; min-width: 0; display: flex; flex-direction: column; gap: 12px; }
.intro { padding: 12px 16px; border-radius: 12px; background: var(--paper-2); border: 2px solid var(--ink); display: grid; gap: 8px; }
.intro-title { margin: 0; font-family: var(--font-display); font-size: 18px; }
.intro ol { margin: 0; padding-left: 1.3em; display: grid; gap: 4px; }
.status {
  font-family: var(--font-hand); font-weight: 600; font-size: 19px; min-height: 1.6em;
  display: flex; align-items: center; gap: 10px;
}
.status .chip { width: 14px; height: 14px; border-radius: 50%; flex: none; }
.event {
  margin: -6px 0 0; font-size: 13.5px; color: var(--muted); line-height: 1.5;
  min-height: 3em; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.board-holder { position: relative; border-radius: 14px; outline: 3px solid transparent; outline-offset: 4px; transition: outline-color 0.2s; }
.board-holder.turn-p1 { outline-color: var(--p1); }
.board-holder.turn-p2 { outline-color: var(--p2); }
.toast {
  position: absolute; left: 50%; top: 42%; transform: translate(-50%, -50%) scale(0.8);
  font-family: var(--font-display); font-size: clamp(30px, 7vw, 52px); white-space: nowrap;
  padding: 6px 18px; border-radius: 12px; background: var(--paper-2); border: 3px solid currentColor;
  opacity: 0; pointer-events: none;
}
.toast.p1 { color: var(--p1); }
.toast.p2 { color: var(--p2); }
.toast.show { animation: toast 1.3s ease-out both; }
@keyframes toast {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(0.7); }
  15% { opacity: 1; transform: translate(-50%, -50%) scale(1.08); }
  70% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -62%) scale(1); }
}
@media (prefers-reduced-motion: reduce) { .toast.show { animation: none; opacity: 0; } }
.board {
  width: 100%;
  max-width: min(100%, 76vh);
  aspect-ratio: 1 / 1;
  margin: 0 auto;
  touch-action: manipulation;
  user-select: none;
}
.board svg { width: 100%; height: 100%; display: block; overflow: visible; }

/* SVG 要素 */
.dot { fill: var(--ink); }
.guide { stroke: var(--faint); stroke-width: 2.5; stroke-dasharray: 2 9; stroke-linecap: round; }
.hit { stroke: transparent; stroke-width: 44; stroke-linecap: round; cursor: pointer; outline: none; }
.hit:focus-visible + .ghost, .hit:hover + .ghost { opacity: 0.45; }
.ghost { stroke-width: 9; stroke-linecap: round; opacity: 0; pointer-events: none; transition: opacity 0.1s; }
.line { stroke-width: 9; stroke-linecap: round; pointer-events: none; }
.line.p1, .ghost.p1 { stroke: var(--p1); }
.line.p2, .ghost.p2 { stroke: var(--p2); }
.line.p3 { stroke: var(--muted); stroke-width: 7; stroke-dasharray: 1 0; opacity: 0.75; }
.line.fresh { animation: draw 0.22s ease-out both; }
.line.recent { stroke-width: 11; }
.halo { stroke-width: 24; stroke-linecap: round; opacity: 0.18; pointer-events: none; }
.halo.p1 { stroke: var(--p1); }
.halo.p2 { stroke: var(--p2); }
@keyframes draw { from { stroke-dashoffset: var(--len); } to { stroke-dashoffset: 0; } }
.box-fill.p1 { fill: url(#hatch1); }
.box-fill.p2 { fill: url(#hatch2); }
.box-glyph { font-family: var(--font-hand); font-weight: 600; font-size: 40px; text-anchor: middle; dominant-baseline: central; pointer-events: none; }
.box-glyph.p1 { fill: var(--p1); }
.box-glyph.p2 { fill: var(--p2); }
.box.fresh { animation: pop 0.35s ease-out both; transform-box: fill-box; transform-origin: center; }
@keyframes pop { from { opacity: 0; transform: scale(0.6); } to { opacity: 1; transform: scale(1); } }
.lean { stroke-width: 0; pointer-events: none; }
.lean.p1 { fill: var(--p1-soft); }
.lean.p2 { fill: var(--p2-soft); }
.lean.locked { stroke-width: 2.5; stroke-dasharray: 5 6; }
.lean.locked.p1 { stroke: var(--p1); }
.lean.locked.p2 { stroke: var(--p2); }
.fuse { stroke-width: 6; stroke-linecap: round; stroke-dasharray: 2 7; opacity: 0.9; pointer-events: none; }
.fuse.p1 { stroke: var(--p1); }
.fuse.p2 { stroke: var(--p2); }
.box-glyph.ghosted { opacity: 0.32; font-size: 30px; }
.box-value { font-family: var(--font-display); font-size: 30px; text-anchor: middle; dominant-baseline: central; fill: var(--muted); pointer-events: none; }
.box-value.neg { fill: var(--p2); }
.box-value.gold { fill: var(--gold); }
.box-bg.gold { fill: var(--gold-soft); stroke: var(--gold); stroke-width: 2; stroke-opacity: 0.5; }
.box-badge { font-family: var(--font-display); font-size: 17px; fill: var(--gold); dominant-baseline: central; pointer-events: none; }
.box-badge.neg { fill: var(--p2); }
.fire-mark { font-family: var(--font-hand); font-weight: 600; font-size: 22px; text-anchor: middle; dominant-baseline: central; pointer-events: none; }
.fire-mark.p1 { fill: var(--p1); }
.fire-mark.p2 { fill: var(--p2); }
.danger-box { opacity: 0.85; pointer-events: none; stroke-width: 3; stroke-dasharray: 6 5; fill: none; }
.danger-box.p1 { stroke: var(--p1); }
.danger-box.p2 { stroke: var(--p2); }
.danger-mark { font-family: var(--font-display); font-size: 34px; text-anchor: middle; dominant-baseline: central; pointer-events: none; }
.danger-mark.p1 { fill: var(--p1); }
.danger-mark.p2 { fill: var(--p2); }
.ghost.selected { opacity: 0.7 !important; }
.settings .check { color: var(--ink); font-size: 13px; display: flex; gap: 6px; align-items: center; }
.preview-box { opacity: 0.6; pointer-events: none; }
.preview-box.p1 { fill: var(--p1-soft); }
.preview-box.p2 { fill: var(--p2-soft); }
.box-glyph.preview { opacity: 0.45; }
.coord { font-family: var(--font-body); font-size: 15px; fill: var(--muted); text-anchor: middle; dominant-baseline: central; opacity: 0.7; }

/* サイド */
.side { grid-area: side; display: flex; flex-direction: column; gap: 22px; min-width: 0; }
.scores { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.player {
  position: relative; padding: 12px 14px 10px; border-radius: 10px;
  background: var(--paper-2); border: 2px solid transparent;
  display: grid; grid-template-columns: auto 1fr; grid-template-rows: auto auto; column-gap: 10px; align-items: center;
}
.player .swatch { width: 12px; height: 12px; border-radius: 50%; grid-row: 1; }
.player .name { font-weight: 700; font-size: 14px; grid-row: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.player .pts { grid-column: 1 / -1; font-family: var(--font-display); font-size: 40px; line-height: 1.15; font-variant-numeric: tabular-nums; }
.player .sub { grid-column: 1 / -1; font-size: 12px; color: var(--muted); min-height: 1.5em; }
.player.p1 .swatch { background: var(--p1); }
.player.p2 .swatch { background: var(--p2); }
.player.p1 .pts { color: var(--p1); }
.player.p2 .pts { color: var(--p2); }
.player.active.p1 { border-color: var(--p1); }
.player.active.p2 { border-color: var(--p2); }

.controls { display: flex; flex-wrap: wrap; gap: 8px; }
button, select {
  font: inherit; color: var(--ink); background: var(--paper-2);
  border: 1.5px solid var(--faint); border-radius: 8px; padding: 7px 12px; cursor: pointer;
}
button:hover, select:hover { border-color: var(--muted); }
button:focus-visible, select:focus-visible { outline: 2.5px solid var(--focus); outline-offset: 2px; }
button.primary { background: var(--ink); color: var(--paper); border-color: var(--ink); font-weight: 700; }
button:disabled { opacity: 0.45; cursor: default; }
select:disabled { opacity: 0.5; }

.settings { display: grid; grid-template-columns: auto 1fr; gap: 8px 12px; align-items: center; }
.settings label { font-size: 13px; color: var(--muted); }
.settings select { width: 100%; min-width: 0; }

.section-label { font-size: 12px; letter-spacing: 0.12em; color: var(--muted); font-weight: 700; margin: 0 0 6px; }
.howto { margin: 0; padding-left: 1.3em; display: grid; gap: 4px; }
.howto li { padding-left: 2px; }
.tips { margin-top: 14px; padding: 10px 12px; border-radius: 8px; background: var(--paper-2); border: 1.5px dashed var(--faint); }
.tips-label { margin: 0 0 4px; font-family: var(--font-hand); font-weight: 600; font-size: 15px; }
.tips ul { margin: 0; padding-left: 1.2em; display: grid; gap: 4px; font-size: 13.5px; }
.diagrams { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; margin-top: 12px; }
.diagrams figure { margin: 0; display: grid; gap: 4px; align-content: start; }
.diagrams svg { width: 100%; max-width: 92px; height: auto; display: block; }
.diagrams figcaption { font-size: 12px; line-height: 1.45; color: var(--muted); }
.diagrams figcaption b { color: var(--ink); font-weight: 700; }
.d-line { stroke-width: 8; stroke-linecap: round; }
.d-line.p1 { stroke: var(--p1); }
.d-line.p2 { stroke: var(--p2); }
.d-new { stroke-dasharray: 3 9; }
.d-fill.p1 { fill: var(--p1-soft); }
.d-fill.p2 { fill: var(--p2-soft); }
.d-glyph { font-family: var(--font-hand); font-weight: 600; font-size: 30px; text-anchor: middle; dominant-baseline: central; }
.d-glyph.p1 { fill: var(--p1); }
.d-glyph.p2 { fill: var(--p2); }
.note { font-family: var(--font-hand); font-weight: 600; color: var(--muted); font-size: 14px; margin: 6px 0 0; }

.result {
  font-family: var(--font-display); font-size: 22px; text-align: center; padding: 6px 0;
}

.review { display: grid; gap: 10px; }
.puzzle { display: grid; gap: 10px; padding: 12px 14px; border-radius: 10px; background: var(--paper-2); border: 2px solid var(--gold); }
.puzzle p { margin: 0; }
.puzzle ol { margin: 0; padding-left: 1.4em; display: grid; gap: 3px; font-size: 13.5px; }
.puzzle .ok { color: var(--p1); font-weight: 700; }
.puzzle .ng { color: var(--p2); font-weight: 700; }
.review-chart { position: relative; }
.review-chart svg { width: 100%; height: auto; display: block; overflow: visible; touch-action: none; }
.rv-zero { stroke: var(--muted); stroke-width: 1; opacity: 0.5; }
.rv-line { fill: none; stroke: var(--ink); stroke-width: 2; stroke-linejoin: round; }
.rv-area1 { fill: var(--c1); opacity: 0.18; }
.rv-area2 { fill: var(--c2); opacity: 0.18; }
.rv-mark { stroke: var(--paper-2); stroke-width: 2; }
.rv-mark.p1 { fill: var(--c1); }
.rv-mark.p2 { fill: var(--c2); }
.rv-num { font-size: 9px; font-weight: 700; fill: #fff; text-anchor: middle; dominant-baseline: central; pointer-events: none; }
.rv-axis { font-size: 10px; fill: var(--muted); }
.rv-cross { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 2 3; }
.rv-tip { position: absolute; top: 0; transform: translateX(-50%); background: var(--ink); color: var(--paper); font-size: 12px; padding: 3px 7px; border-radius: 6px; white-space: nowrap; pointer-events: none; }
.review ol { margin: 0; padding-left: 1.4em; display: grid; gap: 4px; font-size: 13.5px; }
.review .muted { color: var(--muted); font-size: 12.5px; margin: 0; }
.log { max-height: 180px; overflow-y: auto; font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.log ol { margin: 0; padding-left: 2.2em; }
.log .p1 { color: var(--p1); }
.log .p2 { color: var(--p2); }

@media (max-width: 860px) {
  .app { grid-template-columns: minmax(0, 1fr); grid-template-areas: "head" "board" "side"; gap: 14px; padding-block: 12px 32px; }
  .event {
  margin: -6px 0 0; font-size: 13.5px; color: var(--muted); line-height: 1.5;
  min-height: 3em; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.board-holder { position: relative; border-radius: 14px; outline: 3px solid transparent; outline-offset: 4px; transition: outline-color 0.2s; }
.board-holder.turn-p1 { outline-color: var(--p1); }
.board-holder.turn-p2 { outline-color: var(--p2); }
.toast {
  position: absolute; left: 50%; top: 42%; transform: translate(-50%, -50%) scale(0.8);
  font-family: var(--font-display); font-size: clamp(30px, 7vw, 52px); white-space: nowrap;
  padding: 6px 18px; border-radius: 12px; background: var(--paper-2); border: 3px solid currentColor;
  opacity: 0; pointer-events: none;
}
.toast.p1 { color: var(--p1); }
.toast.p2 { color: var(--p2); }
.toast.show { animation: toast 1.3s ease-out both; }
@keyframes toast {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(0.7); }
  15% { opacity: 1; transform: translate(-50%, -50%) scale(1.08); }
  70% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -62%) scale(1); }
}
@media (prefers-reduced-motion: reduce) { .toast.show { animation: none; opacity: 0; } }
.board { max-width: 100%; }
}
@media (prefers-reduced-motion: reduce) {
  .line.fresh, .box.fresh { animation: none; }
}
