/* ============================================================
   城壁工場都市 — 画面デザイン
   明るい紙色のパネルに、会社の色（紅・蒼）と黄色の操作色。
   押せるものは下に厚みのある「つまみ」、読むものは平らな面。
   ============================================================ */
:root {
  --ink: #1d2430;
  --ink-2: #485263;
  --muted: #687080;
  --paper: #ffffff;
  --paper-2: #f4f1ea;
  --paper-3: #ebe6db;
  --line: #e2dccf;
  --lip: #d3ccbd;
  --p1: #e2513a;
  --p1-d: #b33822;
  --p1-t: #fdebe7;
  --p2: #2e7be0;
  --p2-d: #1d5bb0;
  --p2-t: #e6f0fc;
  --sun: #ffc93c;
  --sun-d: #d99b0c;
  --danger: #e2513a;
  --radius: 16px;
  --shadow: 0 10px 30px rgba(24, 34, 52, 0.16), 0 2px 6px rgba(24, 34, 52, 0.08);
  /* 読む文字は判読性の高いUDゴシック、見出しと数字は丸ゴシックでポップに */
  --font: "BIZ UDPGothic", "Hiragino Sans", "Yu Gothic UI", "Meiryo", system-ui, sans-serif;
  --font-pop: "M PLUS Rounded 1c", "Hiragino Maru Gothic ProN", var(--font);
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  background: #b9c9d6;
  color: var(--ink);
  font-family: var(--font);
  font-weight: 700;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
}
#stage { position: fixed; inset: 0; }
#stage canvas { display: block; touch-action: none; }
.hidden { display: none !important; }
b { font-weight: 900; }
button svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* ---------- ボタン ---------- */
button {
  font-family: inherit;
  font-size: 15px;
  font-weight: 800;
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 18px;
  cursor: pointer;
  box-shadow: 0 3px 0 var(--lip);
  transition: transform 0.08s, box-shadow 0.08s, background 0.15s;
}
button:hover { background: #fffaf0; }
button:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--lip); }
button:disabled { opacity: 0.38; cursor: default; transform: none; box-shadow: 0 3px 0 var(--lip); }
button:focus-visible { outline: 3px solid rgba(46, 123, 224, 0.45); outline-offset: 2px; }
button.big, #dialogYes, #btnAgain, #btnRuleNext {
  background: var(--sun);
  border-color: var(--sun-d);
  box-shadow: 0 4px 0 var(--sun-d);
}
button.big:hover, #dialogYes:hover, #btnAgain:hover, #btnRuleNext:hover { background: #ffd35e; }
button.big:active, #dialogYes:active, #btnAgain:active, #btnRuleNext:active { box-shadow: 0 1px 0 var(--sun-d); }
button.big { font-size: 18px; padding: 15px 24px; border-radius: 14px; }
button.big.alt { background: var(--paper); border-color: var(--line); box-shadow: 0 4px 0 var(--lip); }
button.big.alt:active { box-shadow: 0 1px 0 var(--lip); }
button.ghost { background: var(--paper-2); border-color: transparent; box-shadow: none; color: var(--ink-2); }
button.ghost:hover { background: var(--paper-3); }
button.ghost:active { box-shadow: none; }
button.big.ghost { background: transparent; box-shadow: none; border-color: transparent; color: var(--ink-2); font-size: 16px; padding: 10px; }
button.icon { padding: 7px; border-radius: 10px; display: grid; place-items: center; box-shadow: none; }

/* ---------- 画面（メニュー・ダイアログの土台） ---------- */
.screen {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: safe center;
  padding: 16px;
  z-index: 20;
  overflow-y: auto;
}
#rules, #dialog, #result, #editor { background: rgba(29, 36, 48, 0.42); backdrop-filter: blur(4px); }

.panel, .menu-card {
  background: var(--paper);
  border-radius: 22px;
  box-shadow: var(--shadow);
  padding: 24px 26px;
  max-width: 560px;
  width: 100%;
}

/* タイトル：左に1枚のカード、奥に街 */
#menu { align-items: flex-start; padding-left: max(16px, 6vw); background: linear-gradient(90deg, rgba(29, 36, 48, 0.28), rgba(29, 36, 48, 0) 46%); }
.menu-card { max-width: 440px; padding: 30px 30px 26px; }
.title-block { margin-bottom: 22px; }
.subtitle { font-size: 12px; letter-spacing: 0.3em; color: #b07a00; font-family: var(--font-pop); font-weight: 900; }
h1 {
  margin: 6px 0 0;
  font-size: clamp(34px, 4.2vw, 46px);
  line-height: 1.15;
  font-weight: 900;
  letter-spacing: 0.04em;
  color: var(--ink);
}
h1::after { content: ""; display: block; width: 56px; height: 6px; border-radius: 3px; margin-top: 12px; background: linear-gradient(90deg, var(--p1) 50%, var(--p2) 50%); }
.tagline { color: var(--ink-2); margin: 14px 0 0; font-size: 15px; line-height: 1.75; font-weight: 400; }
.tagline .gap { display: block; height: 0.7em; } /* 舞台の2行と、ルールの2行のあいだを少しあける */
.menu-buttons { display: flex; flex-direction: column; gap: 12px; }
.menu-buttons button { width: 100%; text-align: left; }

.setup h2 { margin: 0 0 16px; font-size: 20px; font-weight: 900; }
.row { margin-bottom: 14px; }
.row label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; letter-spacing: 0.04em; }
.seg { display: flex; gap: 4px; flex-wrap: wrap; background: var(--paper-2); padding: 4px; border-radius: 12px; }
.seg button {
  flex: 1;
  min-width: 64px;
  font-size: 14px;
  font-weight: 700;
  padding: 9px 6px;
  border-radius: 9px;
  background: transparent;
  border-color: transparent;
  box-shadow: none;
  color: var(--ink-2);
}
.seg button:hover { background: rgba(255, 255, 255, 0.6); }
.seg button:active { transform: none; box-shadow: none; }
.seg button.on { background: var(--paper); color: var(--ink); box-shadow: 0 1px 3px rgba(24, 34, 52, 0.16), 0 2px 0 var(--lip); }
.note { font-size: 13px; color: var(--muted); margin: 4px 0 0; }
.setup-buttons, .dialog-buttons { display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; margin-top: 18px; }
.setup-buttons .big { min-width: 160px; }
#menu:has(#setup:not(.hidden)) .tagline { display: none; }
#menu:has(#setup:not(.hidden)) .title-block { margin-bottom: 14px; }

/* ---------- ルール ---------- */
.rules-panel { display: flex; flex-direction: column; gap: 14px; max-height: calc(100vh - 32px); }
.rules-head { display: flex; align-items: center; gap: 12px; }
.rules-head h2 { margin: 0; font-size: 20px; font-weight: 900; }
.rules-head span { color: var(--muted); font-size: 13px; margin-left: auto; }
.rules-figure {
  display: flex;
  justify-content: center;
  align-items: center;
  background: #2a3140;
  border-radius: 14px;
  min-height: 200px;
  padding: 12px;
  flex: none;
}
.rules-figure svg { width: 100%; max-width: 280px; height: auto; }
.rules-text { line-height: 1.9; font-size: 16px; font-weight: 400; min-height: 120px; overflow-y: auto; flex: 1 1 auto; color: var(--ink-2); }
.rules-text b { color: var(--ink); background: linear-gradient(transparent 62%, rgba(255, 201, 60, 0.55) 62%); }
.rules-text .p1 { color: var(--p1); font-weight: 900; }
.rules-text .p2 { color: var(--p2); font-weight: 900; }
.rules-nav { display: flex; align-items: center; gap: 10px; }
.dots-nav { flex: 1; display: flex; justify-content: center; gap: 6px; }
.dots-nav i { width: 8px; height: 8px; border-radius: 4px; background: var(--paper-3); transition: width 0.2s, background 0.2s; }
.dots-nav i.on { width: 22px; background: var(--sun); }

.dialog-panel { max-width: 440px; }

/* ---------- 街の形 ---------- */
.shape-preview { display: flex; gap: 14px; align-items: center; margin-top: 10px; }
.mini, .editor-grid { display: grid; background: #6f7680; border-radius: 8px; padding: 3px; gap: 1px; }
.mini { width: 104px; height: 104px; flex: none; }
.mini i, .editor-grid i { border-radius: 2px; background: #8fcf6a; }
.mini i.wall, .editor-grid i.wall { background: #a39684; box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.18); }
.shape-side { display: flex; flex-direction: column; gap: 6px; align-items: flex-start; }
.shape-side span { font-size: 12px; color: var(--muted); }
button.small { padding: 6px 12px; font-size: 13px; }
.editor-panel { max-width: 520px; display: flex; flex-direction: column; gap: 12px; }
.editor-help { margin: 0; font-size: 14px; line-height: 1.75; color: var(--ink-2); font-weight: 400; }
.editor-grid { width: min(100%, 440px, calc(100vh - 330px)); aspect-ratio: 1; margin: 0 auto; touch-action: none; user-select: none; cursor: pointer; padding: 4px; gap: 2px; }
.editor-grid i:hover { filter: brightness(1.08); }
.editor-msg { margin: 0; min-height: 1.4em; text-align: center; font-size: 13px; color: var(--muted); }
.editor-msg.bad { color: var(--danger); font-weight: 700; }
.dialog-panel h3 { margin: 0 0 10px; font-size: 19px; font-weight: 900; }
.dialog-panel p { line-height: 1.8; margin: 0; font-size: 15px; font-weight: 400; color: var(--ink-2); }
.dialog-panel p b { color: var(--danger); }

/* ---------- 結果 ---------- */
.result-panel { max-width: 460px; text-align: center; }
.result-title { font-size: 32px; font-weight: 900; margin: 4px 0 16px; }
.result-title.p1 { color: var(--p1); }
.result-title.p2 { color: var(--p2); }
.result-table {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 8px 22px;
  text-align: left;
  margin: 0 auto;
  max-width: 360px;
  font-size: 15px;
  background: var(--paper-2);
  border-radius: 14px;
  padding: 14px 18px;
}
.result-table .h { color: var(--muted); font-size: 12px; }
.result-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.result-table .total { font-size: 24px; font-weight: 900; border-top: 2px solid var(--line); padding-top: 8px; }
.result-table .c1 { color: var(--p1); }
.result-table .c2 { color: var(--p2); }
.result-panel .dialog-buttons { justify-content: center; }

/* ---------- 対局中：上の得点板 ---------- */
#hud { position: fixed; inset: 0; pointer-events: none; z-index: 10; }
#hud > * { pointer-events: auto; }
.scoreboard {
  position: absolute;
  top: max(12px, env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  width: min(660px, calc(100vw - 24px)); /* 札の中の名前と得点が離れすぎないよう、札の幅を詰める */
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 10px;
  align-items: stretch;
  pointer-events: none;
}
/* 会社の札：左から 紋章｜会社名・役割・数｜得点。得点の欄は幅を決めておき、数が増えても札の形が変わらない */
.player {
  position: relative;
  display: grid;
  grid-template-columns: 40px minmax(0, 1fr) auto;
  grid-template-areas: "emb name score" "emb role score" "emb stats stats"; /* 数の行は得点の下まで使い、桁が増えても切れない */
  column-gap: 12px;
  align-items: center;
  align-content: center;
  background: var(--paper);
  border-radius: var(--radius);
  padding: 9px 14px 15px; /* 下の余白：手番・パスの札が数の行に重ならないように */
  min-width: 0;
  min-height: 70px;
  box-shadow: var(--shadow);
  outline: 3px solid transparent;
  transition: outline-color 0.25s, transform 0.25s;
}
.player.p2 { grid-template-columns: auto minmax(0, 1fr) 40px; grid-template-areas: "score name emb" "score role emb" "stats stats emb"; text-align: right; }
.player.active { transform: translateY(2px); }
.player.active.p1 { outline-color: var(--p1); }
.player.active.p2 { outline-color: var(--p2); }
.emblem {
  grid-area: emb;
  width: 40px;
  height: 40px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  /* 画数の多い「紅」「蒼」がつぶれないよう、読みやすい書体の太字で大きめに */
  font-weight: 700;
  font-size: 23px;
  line-height: 1;
  padding-bottom: 2px;
  color: #fff;
}
.p1 .emblem { background: var(--p1); box-shadow: inset 0 -3px 0 var(--p1-d); }
.p2 .emblem { background: var(--p2); box-shadow: inset 0 -3px 0 var(--p2-d); }
.pname { grid-area: name; font-weight: 800; font-size: 15px; line-height: 1.25; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--ink); }
.prole { grid-area: role; font-size: 11px; font-weight: 700; line-height: 1.3; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pstats { grid-area: stats; font-size: 11px; color: var(--muted); display: flex; gap: 10px; margin-top: 3px; white-space: nowrap; overflow: hidden; }
.pstats span { display: inline-flex; align-items: baseline; gap: 3px; }
.player.p2 .pstats { justify-content: flex-end; }
.pstats b { color: var(--ink-2); font-size: 13px; font-variant-numeric: tabular-nums; }
.pscore { grid-area: score; display: flex; align-items: baseline; justify-content: flex-end; gap: 2px; line-height: 1; min-width: 3.4em; }
.p2 .pscore { justify-content: flex-start; }
.pscore b { font-size: 34px; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.pscore small { font-size: 12px; color: var(--muted); }
.hide-score .pscore, .hide-score .share, .hide-score .pstats { display: none; }
.pscore .cap { font-size: 10px; font-weight: 700; color: var(--muted); margin-right: 3px; writing-mode: vertical-rl; letter-spacing: 0.05em; line-height: 1; align-self: center; }
.pstats span { white-space: nowrap; }
.p1 .pscore b { color: var(--p1); }
.p2 .pscore b { color: var(--p2); }
.turn-tag {
  position: absolute;
  bottom: -11px;
  font-size: 12px;
  font-weight: 700;
  color: #fff;
  padding: 3px 10px;
  border-radius: 999px;
  opacity: 0;
  transform: translateY(-4px);
  transition: opacity 0.2s, transform 0.2s;
}
.p1 .turn-tag { left: 14px; background: var(--p1); }
.p2 .turn-tag { right: 14px; background: var(--p2); }
.player.active .turn-tag { opacity: 1; transform: none; }
/* 直前にパスした会社：次の手が打たれるまで札を出しておく */
.pass-tag {
  position: absolute;
  bottom: -11px;
  font-size: 12px;
  font-weight: 700;
  color: #fff;
  background: #5b6470;
  padding: 3px 10px;
  border-radius: 999px;
  opacity: 0;
  transform: translateY(-4px);
  transition: opacity 0.2s, transform 0.2s;
}
.p1 .pass-tag { left: 14px; }
.p2 .pass-tag { right: 14px; }
.player.passed .pass-tag { opacity: 1; transform: none; animation: passPulse 1.6s ease-in-out infinite; }
@keyframes passPulse { 50% { background: #7d8794; } }
.dock button.endpass { background: #fff3cf; color: #8a5a00; }
/* 中央：手数と「検討中」はそれぞれ別の札。手数の札は位置を固定し、検討中はその下に出る */
.turn-info {
  align-self: start;
  margin-top: 21px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  width: 76px;
  white-space: nowrap;
}
#moveNo, #thinking {
  width: 100%;
  text-align: center;
  font-weight: 700;
  border-radius: 999px;
  padding: 6px 0;
  box-shadow: var(--shadow);
  font-variant-numeric: tabular-nums;
}
#moveNo { font-size: 13px; color: var(--ink-2); background: var(--paper); }
#thinking { font-size: 12px; padding: 4px 0; color: #8a5a00; background: #fff3cf; }
.dots::after { content: ""; animation: dots 1.2s steps(4) infinite; }
@keyframes dots { 0% { content: ""; } 25% { content: "・"; } 50% { content: "・・"; } 75% { content: "・・・"; } }
/* 得点の割合 */
.share {
  grid-column: 1 / -1;
  display: flex;
  height: 6px;
  border-radius: 3px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.6);
  margin-top: 14px;
  box-shadow: 0 1px 3px rgba(24, 34, 52, 0.15);
}
.share i { display: block; height: 100%; width: 50%; transition: width 0.6s cubic-bezier(0.3, 1.2, 0.5, 1); }
#share1 { background: var(--p1); }
#share2 { background: var(--p2); }

/* ---------- 対局中：下の操作 ---------- */
#message {
  position: absolute;
  bottom: calc(96px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  background: rgba(29, 36, 48, 0.86);
  color: #fff;
  border-radius: 999px;
  padding: 9px 20px;
  font-size: 15px;
  white-space: nowrap;
  max-width: calc(100vw - 32px);
  overflow: hidden;
  text-overflow: ellipsis;
  pointer-events: none;
  backdrop-filter: blur(6px);
}
#message:empty { display: none; }
.dock {
  position: absolute;
  bottom: max(14px, env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 2px;
  background: var(--paper);
  border-radius: 20px;
  padding: 6px;
  box-shadow: var(--shadow);
  max-width: calc(100vw - 16px);
  overflow-x: auto;
  scrollbar-width: none;
}
.dock .sep { width: 1px; align-self: stretch; margin: 8px 4px; background: var(--line); flex: none; }
.dock button {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  min-width: 68px;
  padding: 7px 8px 6px;
  font-size: 12px;
  font-weight: 700;
  border: 0;
  border-radius: 14px;
  background: transparent;
  box-shadow: none;
  color: var(--ink-2);
  white-space: nowrap;
}
.dock button:hover { background: var(--paper-2); color: var(--ink); }
.dock button:active { transform: scale(0.95); box-shadow: none; }
.dock button:disabled { box-shadow: none; }
.dock button.on { background: #fff3cf; color: #8a5a00; }
/* 切り替えボタン：右上の小札で今の状態（オン・オフ）を示す */
.dock button.toggle { position: relative; }
.dock button.toggle::after {
  content: 'OFF';
  position: absolute;
  top: 3px;
  right: 3px;
  padding: 0 4px;
  border-radius: 6px;
  font-size: 9px;
  line-height: 14px;
  background: var(--paper-2);
  color: var(--ink-2);
  opacity: 0.85;
}
.dock button.toggle.on::after { content: 'ON'; background: #2f9e5b; color: #fff; opacity: 1; }
.dock button.toggle:not(.on) svg { opacity: 0.4; }
#camHint {
  position: absolute;
  bottom: calc(78px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  font-size: 12px;
  color: rgba(255, 255, 255, 0.92);
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
  white-space: nowrap;
  pointer-events: none;
  display: none;
}
/* 拡大縮小ボタン（画面の右端） */
#zoomCtl {
  position: absolute;
  right: 14px;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  flex-direction: column;
  background: var(--paper);
  border-radius: 14px;
  box-shadow: var(--shadow);
  overflow: hidden;
}
#zoomCtl button {
  width: 42px;
  height: 42px;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  color: var(--ink-2);
  display: grid;
  place-items: center;
}
#zoomCtl button + button { border-top: 1px solid var(--line); }
#zoomCtl button:hover { background: var(--paper-2); color: var(--ink); }
#zoomCtl button:active { transform: none; background: var(--paper-2); }
#zoomCtl svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; }
@media (hover: none) { #zoomCtl { display: none; } } /* 指で触る端末はピンチで足りる */
@media (hover: hover) { #camHint { display: block; } #message { bottom: calc(108px + env(safe-area-inset-bottom)); } }

/* ---------- 演出 ---------- */
#fxLayer { position: fixed; inset: 0; pointer-events: none; z-index: 15; overflow: hidden; }
/* 終了時の番号は街の上の目印なので、得点板・下のボタン・画面より奥に出す */
#labelLayer { position: fixed; inset: 0; pointer-events: none; z-index: 9; overflow: hidden; }
.pop {
  position: absolute;
  font-weight: 900;
  font-size: 28px;
  transform: translate(-50%, -50%);
  animation: popUp 1.1s ease-out forwards;
  -webkit-text-stroke: 5px #fff;
  paint-order: stroke fill;
  filter: drop-shadow(0 3px 4px rgba(0, 0, 0, 0.25));
  white-space: nowrap;
}
@keyframes popUp {
  0% { opacity: 0; transform: translate(-50%, -30%) scale(0.4); }
  15% { opacity: 1; transform: translate(-50%, -60%) scale(1.25); }
  30% { transform: translate(-50%, -70%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -150%) scale(1); }
}
/* 帯：画面を横切るリボン */
.banner {
  --c: #ffc93c;
  position: absolute;
  left: 0;
  right: 0;
  top: 34%;
  display: flex;
  justify-content: center;
  animation: bannerLife 4s forwards;
}
.banner .band {
  background: var(--c);
  color: #fff;
  padding: 14px 48px 16px;
  text-align: center;
  box-shadow: 0 12px 30px rgba(24, 34, 52, 0.28);
  border-radius: 6px;
  animation: bandIn 4s cubic-bezier(0.2, 1.2, 0.4, 1) forwards;
  max-width: calc(100vw - 24px);
}
.banner b { display: block; font-size: clamp(28px, 5.4vw, 52px); letter-spacing: 0.06em; line-height: 1.15; white-space: nowrap; }
.banner small { display: block; font-size: clamp(14px, 1.8vw, 17px); font-weight: 700; font-family: var(--font); margin-top: 4px; opacity: 0.95; }
@keyframes bannerLife { 0%, 90% { opacity: 1; } 100% { opacity: 0; } }
@keyframes bandIn {
  0% { transform: scaleX(0.2) scaleY(0.6); opacity: 0; }
  7% { transform: scaleX(1.03) scaleY(1); opacity: 1; }
  11%, 90% { transform: none; }
  100% { transform: translateY(-16px); }
}
.flash { position: absolute; inset: 0; animation: flash 0.45s ease-out forwards; }
@keyframes flash { from { opacity: 0.6; } to { opacity: 0; } }

#toast {
  position: fixed;
  top: 112px;
  left: 50%;
  transform: translateX(-50%) translateY(-10px);
  background: var(--paper);
  color: var(--ink);
  border-radius: 14px;
  border-left: 5px solid var(--danger);
  box-shadow: var(--shadow);
  padding: 12px 20px;
  font-size: 15px;
  line-height: 1.65;
  opacity: 0;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 30;
  pointer-events: none;
  max-width: min(520px, calc(100vw - 32px));
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.info { border-left-color: var(--sun); }

/* 終了時の番号 */
.count-label {
  position: absolute;
  transform: translate(-50%, -100%);
  min-width: 30px;
  padding: 2px 9px;
  border-radius: 999px;
  text-align: center;
  color: #fff;
  font-weight: 900;
  font-size: 14px;
  line-height: 1.35;
  border: 2px solid #fff;
  box-shadow: 0 3px 8px rgba(24, 34, 52, 0.3);
  animation: labelIn 0.35s cubic-bezier(0.2, 1.6, 0.4, 1);
  pointer-events: none;
}
.count-label.c1 { background: var(--p1); }
.count-label.c2 { background: var(--p2); }
.count-label.yard { border-color: var(--sun); }
.count-label small { display: block; font-size: 10px; font-weight: 800; color: #fff3cf; }
@keyframes labelIn { from { transform: translate(-50%, -60%) scale(0.2); opacity: 0; } }

/* 終了時の得点表 */
#tally {
  position: fixed;
  top: 116px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 16px;
  background: var(--paper);
  border-radius: 20px;
  padding: 12px 22px;
  z-index: 12;
  box-shadow: var(--shadow);
}
#tally .t { text-align: center; min-width: 130px; }
#tally .tn { font-size: 13px; font-weight: 700; }
#tally .c1 .tn, #tally .c1 b { color: var(--p1); }
#tally .c2 .tn, #tally .c2 b { color: var(--p2); }
#tally b { display: block; font-size: 44px; font-variant-numeric: tabular-nums; line-height: 1.1; transition: transform 0.15s; }
#tally small { font-size: 12px; color: var(--muted); }
#tally .vs { color: var(--muted); font-weight: 900; }
#tally[data-now="1"] .c1 b, #tally[data-now="2"] .c2 b { transform: scale(1.12); }

/* ---------- 画面が低いとき ---------- */
@media (max-height: 720px) {
  .menu-card { padding: 22px 24px 20px; }
  .title-block { margin-bottom: 14px; }
  h1 { font-size: clamp(28px, 3.6vw, 38px); }
  .tagline { margin-top: 8px; font-size: 13px; }
  .row { margin-bottom: 9px; }
  .setup h2 { margin-bottom: 10px; font-size: 18px; }
  button.big { padding: 12px 22px; font-size: 16px; }
  .rules-figure { min-height: 150px; }
  .rules-figure svg { max-width: 210px; }
  .rules-text { min-height: 0; font-size: 14px; line-height: 1.75; }
}

/* ---------- スマホ ---------- */
@media (max-width: 640px) {
  #menu { align-items: center; padding-left: 16px; background: none; }
  .menu-card { padding: 22px 20px; }
  .scoreboard { grid-template-columns: 1fr 1fr; gap: 8px; width: calc(100vw - 16px); top: max(8px, env(safe-area-inset-top)); }
  .turn-info { display: none; }
  /* スマホ：数の行だけ札の下いっぱいに広げる */
  .player { padding: 8px 8px 14px; column-gap: 6px; min-height: 0; grid-template-columns: 26px minmax(0, 1fr) auto; grid-template-areas: "emb name score" "emb role score" "stats stats stats"; }
  .player.p2 { grid-template-columns: auto minmax(0, 1fr) 26px; grid-template-areas: "score name emb" "score role emb" "stats stats stats"; }
  .emblem { width: 26px; height: 26px; font-size: 17px; border-radius: 8px; }
  .pname { font-size: 13px; }
  .prole { font-size: 9px; letter-spacing: -0.03em; }
  .pstats { gap: 8px; font-size: 10px; margin-top: 5px; padding-top: 4px; border-top: 1px solid var(--line); }
  .pstats b { font-size: 12px; }
  .pscore b { font-size: 24px; letter-spacing: -0.03em; }
  .pscore { min-width: 2.4em; }
  .pscore small { display: none; }
  .dock { border-radius: 16px; padding: 4px; }
  .dock button { min-width: 54px; padding: 6px 4px 5px; font-size: 11px; }
  .dock .sep { margin: 6px 2px; }
  .dock button.toggle::after { top: 1px; right: 1px; padding: 0 3px; }
  #message { bottom: calc(82px + env(safe-area-inset-bottom)); font-size: 13px; }
  #toast { top: 96px; }
  #tally { top: 96px; gap: 8px; padding: 8px 12px; }
  #tally .t { min-width: 96px; }
  #tally b { font-size: 32px; }
  .setup-buttons, .dialog-buttons { justify-content: center; }
}

/* ポップな丸ゴシックを使う所（大きい文字だけ） */
h1, h2, h3, .result-title, button.big, .pscore b, #tally b, .banner b, .pop, .count-label, .rules-head h2 { font-family: var(--font-pop); }
body { font-weight: 400; }
button { font-weight: 700; }

/* ============================================================
   崖の上の囲碁 — 絵本のような画面
   生成りの紙に、こげ茶のインク。見出しは端正な明朝、本文はやわらかい丸ゴシック、
   ひとことは手書き風。押せるものは、ふっくらした紙のつまみ。
   ============================================================ */
:root {
  --ink: #3b2c1f;
  --ink-2: #5d4a37;
  --muted: #8a7660;
  --paper: #fdf8ec;
  --paper-2: #f5ecd6;
  --paper-3: #ecdfc0;
  --line: #e0cda6;
  --lip: #cdb48a;
  --p1: #c8452f;
  --p1-d: #9c3020;
  --p1-t: #fbe6dc;
  --p2: #2f6fa8;
  --p2-d: #22527e;
  --p2-t: #e2edf6;
  --sun: #f2c35b;
  --sun-d: #c48d2c;
  --danger: #c8452f;
  --radius: 18px;
  --shadow: 0 10px 28px rgba(70, 48, 24, 0.18), 0 2px 6px rgba(70, 48, 24, 0.1);
  --font: "Zen Maru Gothic", "Hiragino Maru Gothic ProN", "Yu Gothic UI", "Meiryo", system-ui, sans-serif;
  --font-pop: "Kaisei Decol", "Hiragino Mincho ProN", "Yu Mincho", serif;
  --font-hand: "Klee One", "Zen Maru Gothic", serif;
  /* 紙のざらつき */
  --grain: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='160' height='160'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0.45  0 0 0 0 0.33  0 0 0 0 0.2  0 0 0 0.09 0'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
}
html, body { background: #cfe3ee; font-weight: 500; }
b { font-weight: 700; }

/* 紙の札とパネル：内側にもう一本、細い縁取り */
.panel, .menu-card, .player, .dock, .turn-info > * {
  background-color: var(--paper);
  background-image: var(--grain);
}
.panel, .menu-card {
  border: 1.5px solid var(--line);
  box-shadow: var(--shadow), inset 0 0 0 5px var(--paper), inset 0 0 0 6px rgba(205, 180, 138, 0.55);
}
button { font-weight: 700; border-radius: 14px; background-color: var(--paper); background-image: var(--grain); }
button:hover { background-color: #fffbf1; }
button.big, #dialogYes, #btnAgain, #btnRuleNext { background-color: var(--sun); font-family: var(--font-pop); letter-spacing: 0.06em; }
button.big:hover, #dialogYes:hover, #btnAgain:hover, #btnRuleNext:hover { background-color: #f6cf73; }
button.big.alt { background-color: var(--paper); }

/* タイトル：空の明るい側から光が差すように */
#menu { background: linear-gradient(90deg, rgba(253, 248, 236, 0.55), rgba(253, 248, 236, 0) 50%); }
.subtitle { font-family: var(--font-pop); font-size: 14px; letter-spacing: 0.32em; color: #a0742a; font-weight: 700; font-style: italic; }
h1 {
  font-family: var(--font-pop);
  font-weight: 700;
  font-size: clamp(38px, 4.6vw, 52px);
  letter-spacing: 0.08em;
  color: #34261a;
  text-shadow: 0 2px 0 rgba(255, 255, 255, 0.6);
}
/* 見出しの下の飾り：紅と蒼の糸を、ゆるい波で */
h1::after {
  width: 120px;
  height: 10px;
  border-radius: 0;
  background: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='120' height='10'><path d='M2 6 Q 17 0 32 5 T 60 5' fill='none' stroke='%23c8452f' stroke-width='2.6' stroke-linecap='round'/><path d='M60 5 Q 75 10 90 5 T 118 4' fill='none' stroke='%232f6fa8' stroke-width='2.6' stroke-linecap='round'/></svg>") no-repeat;
}
.tagline { font-family: var(--font-hand); font-size: 14px; line-height: 1.9; letter-spacing: -0.01em; color: var(--ink-2); }
h2, h3, .rules-head h2, .result-title, .dialog-panel h3 { font-family: var(--font-pop); letter-spacing: 0.05em; }
.note, .editor-help { font-family: var(--font-hand); }
#rules, #dialog, #result, #editor { background: rgba(72, 52, 30, 0.32); }

/* 遊んでいるときの札：数字は端正な明朝で */
.pscore b, #tally b, .banner b, .pop, .count-label { font-family: var(--font-pop); }
.player { border: 1.5px solid var(--line); }
.emblem { font-family: var(--font-pop); }
.dock { border: 1.5px solid var(--line); }
.dock button { background-image: none; }
.dock button.on { background-color: #fff1cf; }

/* ---------- 手番をひと目で ----------
   手番の札：会社の色で縁取り、色の光がゆっくり脈打つ。下に「紅の番」の札。
   手番でない札：少し淡くする。どれも大きさは変えない（縁と影と色だけ） */
.player.active.p1 { background-color: #fdeee6; outline: 3px solid var(--p1); animation: turnGlow1 1.8s ease-in-out infinite; }
.player.active.p2 { background-color: #e9f1f8; outline: 3px solid var(--p2); animation: turnGlow2 1.8s ease-in-out infinite; }
@keyframes turnGlow1 { 0%, 100% { box-shadow: var(--shadow), 0 0 0 0 rgba(200, 69, 47, 0); } 50% { box-shadow: var(--shadow), 0 0 0 6px rgba(200, 69, 47, 0.28); } }
@keyframes turnGlow2 { 0%, 100% { box-shadow: var(--shadow), 0 0 0 0 rgba(47, 111, 168, 0); } 50% { box-shadow: var(--shadow), 0 0 0 6px rgba(47, 111, 168, 0.28); } }
.scoreboard:has(.player.active) .player:not(.active) { opacity: 0.55; filter: saturate(0.55); }
.player { transition: outline-color 0.25s, transform 0.25s, opacity 0.25s, filter 0.25s; }
.turn-tag { font-family: var(--font-pop); font-size: 13px; letter-spacing: 0.08em; padding: 3px 12px; box-shadow: 0 2px 6px rgba(70, 48, 24, 0.25); }
/* 考え中：役割の行が差し替わり、紋章がゆっくりうなずく */
.player.thinking .prole { color: var(--ink-2); font-family: var(--font-hand); }
.player.thinking .emblem { animation: ponder 1.4s ease-in-out infinite; }
@keyframes ponder { 0%, 100% { transform: rotate(0); } 30% { transform: rotate(-8deg); } 60% { transform: rotate(6deg); } }
.prole .dots { display: inline-block; width: 2.2em; text-align: left; }

/* 番号の札が煙突や塔の陰に入ったとき */
.count-label { transition: opacity 0.15s; }
.count-label.behind { opacity: 0; }

/* 終わったあとの集計：得点欄の数字が増えるたびに弾む */
.pscore b.bump { display: inline-block; animation: scoreBump 0.22s ease-out; }
@keyframes scoreBump { 0% { transform: scale(1); } 40% { transform: scale(1.35); } 100% { transform: scale(1); } }
