:root {
  --bg: #f3efe6;
  --panel: #fffaf2;
  --text: #22211b;
  --muted: #6f6a58;
  --line: #d6ccb6;
  --accent: #3b4a2a;
  --accent-text: #fff;
  --board: #e2b968;
  --board-line: #4b3412;
  --threat: #d32f2f;
  --cand: #1565c0;
  --good: #2e7d32;
  --bad: #c62828;
  --shadow: 0 2px 10px rgba(40, 40, 10, .15);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #191a16; --panel: #25261f; --text: #ecebe0; --muted: #aaa792; --line: #45463a;
    --accent: #9fb57a; --accent-text: #191a16; --shadow: 0 2px 10px rgba(0, 0, 0, .4);
  }
}
:root[data-theme="dark"] {
  --bg: #191a16; --panel: #25261f; --text: #ecebe0; --muted: #aaa792; --line: #45463a;
  --accent: #9fb57a; --accent-text: #191a16; --shadow: 0 2px 10px rgba(0, 0, 0, .4);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg); color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", "Hiragino Sans", "Noto Sans JP", "Yu Gothic UI", sans-serif;
  font-size: 16px; line-height: 1.5; -webkit-tap-highlight-color: transparent; overflow-x: hidden;
}
button, select, input { font: inherit; color: inherit; }
button {
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 14px; cursor: pointer; min-height: 44px;
}
button:active { transform: translateY(1px); }
button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: bold; }
button:disabled { opacity: .45; cursor: default; }
select { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; width: 100%; }
a { color: var(--accent); }

.screen { display: none; min-height: 100vh; padding: 0 16px 24px; max-width: 1100px; margin: 0 auto; }
.screen.active { display: block; }

/* ホーム */
.home-head { text-align: center; padding: 48px 0 24px; }
.home-icon { display: block; width: 96px; height: 96px; margin: 0 auto 12px; border-radius: 22px; box-shadow: var(--shadow); }
.home-head h1 { margin: 0; font-size: 30px; letter-spacing: .1em; }
.home-head .sub { margin: 4px 0 0; color: var(--muted); }
.menu { display: flex; flex-direction: column; gap: 12px; max-width: 360px; margin: 0 auto; }
.big { font-size: 18px; padding: 14px; }
.notice { margin: 0; padding: 10px 12px; border-radius: 10px; border: 2px solid var(--bad); background: var(--panel); color: var(--bad); font-weight: bold; }
.small-menu { margin-top: 24px; }
.ver { text-align: center; color: var(--muted); font-size: 13px; margin-top: 24px; }

/* 見出しバー */
.bar { display: flex; align-items: center; gap: 8px; padding: 10px 0; position: sticky; top: 0; background: var(--bg); z-index: 5; }
.bar h2 { margin: 0; font-size: 18px; flex: 1; }
.back { min-height: 38px; padding: 6px 12px; }

/* 設定 */
.form { max-width: 560px; margin: 0 auto; display: flex; flex-direction: column; gap: 16px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.label { font-weight: bold; }
.label small, .check small { font-weight: normal; color: var(--muted); }
.seg { display: flex; gap: 6px; flex-wrap: wrap; }
.seg button { flex: 1; min-width: 80px; display: flex; flex-direction: column; align-items: center; line-height: 1.2; }
.seg button small { font-size: 11px; color: var(--muted); }
.seg button.on { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.seg button.on small { color: inherit; opacity: .85; }
.seg.wrap button { flex: 1 1 30%; }
.preview-box { width: 220px; max-width: 70%; margin: 0 auto; }

/* 背景 */
body.bg-washi { background-color: #f6f0e1; background-image: radial-gradient(rgba(150,120,60,.10) 1px, transparent 1.5px), radial-gradient(rgba(120,90,40,.07) 1px, transparent 1.5px); background-size: 7px 7px, 11px 11px; background-position: 0 0, 3px 5px; }
body.bg-tatami { background-color: #c9c58f; background-image: repeating-linear-gradient(0deg, rgba(90,95,40,.16) 0 2px, transparent 2px 6px), repeating-linear-gradient(90deg, rgba(255,255,230,.10) 0 1px, transparent 1px 40px); }
body.bg-night { background-color: #0f1626; background-image: radial-gradient(rgba(255,255,255,.55) 1px, transparent 1.5px), radial-gradient(rgba(255,255,255,.35) 1px, transparent 1.5px); background-size: 90px 90px, 53px 53px; background-position: 10px 20px, 40px 7px; }
body.bg-plain { background: #fff; }
body.bg-washi .bar { background: #f6f0e1; }
body.bg-tatami .bar { background: #c9c58f; }
body.bg-night .bar { background: #0f1626; }
body.bg-plain .bar { background: #fff; }

.check { display: flex; gap: 8px; align-items: flex-start; padding: 4px 0; }
.check input { width: 20px; height: 20px; margin-top: 2px; flex: none; }
.note { color: var(--muted); font-size: 14px; margin: 0; }
.about h3 { margin: 8px 0 0; font-size: 16px; }

/* 対局 */
.game-wrap { display: flex; flex-direction: column; gap: 10px; }
@media (min-width: 900px) {
  .game-wrap { flex-direction: row; align-items: flex-start; }
  .board-col { flex: 0 0 min(640px, calc(100vh - 150px)); }
  .side-col { flex: 1; }
}
.players { display: flex; gap: 8px; margin-bottom: 6px; }
.pl { flex: 1; display: flex; align-items: center; gap: 6px; padding: 6px 10px; border-radius: 10px; background: var(--panel); border: 1px solid var(--line); font-size: 14px; }
.pl.turn { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent) inset; }
.pl { flex-wrap: wrap; row-gap: 0; }
.pl-name { font-weight: bold; flex: 1; white-space: nowrap; }
.pl-cap { color: var(--muted); font-size: 12px; flex-basis: 100%; padding-left: 22px; }
.stone-ico { width: 16px; height: 16px; border-radius: 50%; flex: none; }
.stone-ico.black { background: radial-gradient(circle at 35% 30%, #666, #000 70%); }
.stone-ico.white { background: radial-gradient(circle at 35% 30%, #fff, #d7d7d7 80%); border: 1px solid #999; }

.evalbox { margin-bottom: 6px; }
.evalbar { position: relative; height: 12px; border-radius: 6px; background: #f6f6f6; border: 1px solid #888; overflow: hidden; }
.evalfill { position: absolute; left: 0; top: 0; bottom: 0; width: 50%; background: #222; transition: width .4s; }
.evalmid { position: absolute; left: 50%; top: 0; bottom: 0; width: 1px; background: #c33; }
.evaltext { font-size: 14px; text-align: center; margin-top: 2px; }

.board-box { width: 100%; max-width: calc(100vh - 150px); margin: 0 auto; }
@media (max-width: 899px) { .board-box { max-width: 100%; } }
.board { width: 100%; height: auto; display: block; touch-action: manipulation; user-select: none; border-radius: 6px; box-shadow: var(--shadow); }

.status { padding: 8px 12px; border-radius: 10px; background: var(--panel); border: 1px solid var(--line); font-weight: bold; min-height: 44px; }
.status.thinking::after { content: ''; display: inline-block; width: 1em; animation: dots 1.2s steps(4) infinite; overflow: hidden; vertical-align: bottom; }
@keyframes dots { 0% { width: 0 } 100% { width: 1.2em } }
.info { margin-top: 8px; padding: 8px 12px; border-radius: 10px; background: var(--panel); border: 1px solid var(--line); font-size: 14px; }
.info.threat { border-color: var(--threat); }
.info b.c { color: var(--cand); }
.info b.t { color: var(--threat); }
.controls { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.controls button { flex: 1 1 28%; }
button.toggle.on { background: var(--cand); color: #fff; border-color: var(--cand); }
button.threat-btn.on { background: var(--threat); border-color: var(--threat); }
.result { margin-top: 12px; padding: 14px; border-radius: 12px; background: var(--panel); border: 2px solid var(--accent); text-align: center; }
.result-main { font-size: 22px; font-weight: bold; }
.result-sub { color: var(--muted); font-size: 14px; margin-top: 4px; white-space: pre-line; }
