:root {
  --bg: #f4efe6;
  --surface: #fffdf8;
  --surface-2: #efe7d8;
  --ink: #2a2622;
  --ink-soft: #6b625a;
  --line: #ddd2bf;
  --accent: #2f5d50;
  --accent-ink: #ffffff;
  --accent-soft: #dcebe5;
  --warn: #b5482f;
  --good: #2f7a4f;
  --board-green: #2e7d5b;
  --board-green-line: #1f5a40;
  --wood: #e3bf83;
  --wood-dark: #b98a45;
  --wood-line: #6d4b1e;
  --hint: #f2b134;
  --radius: 14px;
  --shadow: 0 2px 10px rgba(60, 40, 20, .10);
  --font: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Yu Gothic UI", "Meiryo", sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1d1c;
    --surface: #252826;
    --surface-2: #2f3330;
    --ink: #ecebe6;
    --ink-soft: #a9a69d;
    --line: #3d423e;
    --accent: #6cbfa3;
    --accent-ink: #10201a;
    --accent-soft: #23392f;
    --warn: #e57a5f;
    --good: #6fcf94;
    --board-green: #24684b;
    --board-green-line: #164530;
    --wood: #c9a46b;
    --wood-dark: #9d7438;
    --wood-line: #4d3412;
    --shadow: 0 2px 10px rgba(0, 0, 0, .35);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.6;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
  min-height: 100dvh;
  overscroll-behavior: none;
}
button { font-family: inherit; font-size: inherit; color: inherit; }
[hidden] { display: none !important; }

/* ---------- 上の帯 ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 8px;
  padding: calc(env(safe-area-inset-top) + 6px) 10px 6px;
  background: var(--accent); color: var(--accent-ink);
  box-shadow: var(--shadow);
}
.topbar-title { flex: 1; margin: 0; font-size: 18px; font-weight: 700; letter-spacing: .04em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-btn {
  width: 42px; height: 42px; display: grid; place-items: center;
  border: 0; background: transparent; border-radius: 50%; cursor: pointer;
}
.topbar-btn:active { background: rgba(255,255,255,.18); }

#app { max-width: 880px; margin: 0 auto; padding: 14px 16px calc(env(safe-area-inset-bottom) + 24px); }

/* ---------- メニュー ---------- */
.menu-intro { color: var(--ink-soft); font-size: 14px; margin: 2px 2px 14px; }
.menu-section { margin-bottom: 22px; }
.menu-section h2 { font-size: 16px; margin: 0 2px 10px; color: var(--ink-soft); font-weight: 700; }
.menu-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.game-card {
  display: flex; flex-direction: column; align-items: stretch; text-align: left;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px; box-shadow: var(--shadow); cursor: pointer; min-height: 100%;
}
.game-card:active { transform: scale(.98); }
.game-card .icon { width: 56px; height: 56px; margin-bottom: 8px; }
.game-card .name { font-weight: 700; font-size: 16px; line-height: 1.35; }
.game-card .desc { font-size: 13px; color: var(--ink-soft); line-height: 1.5; margin-top: 4px; flex: 1; }
.game-card .rec { font-size: 12px; color: var(--accent); margin-top: 8px; font-weight: 600; }

/* ---------- 共通の部品 ---------- */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.panel + .panel { margin-top: 14px; }
.panel h2 { margin: 0 0 10px; font-size: 18px; }
.panel h3 { margin: 16px 0 6px; font-size: 15px; }
.howto { font-size: 14px; color: var(--ink-soft); }
.howto p { margin: 0 0 6px; }
.howto ul { margin: 0; padding-left: 1.2em; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 46px; padding: 0 18px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface); cursor: pointer; font-weight: 700;
}
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.wide { width: 100%; }
.btn:disabled { opacity: .4; cursor: default; transform: none; }

.choice-group { margin: 12px 0; }
.choice-label { font-size: 14px; font-weight: 700; margin-bottom: 6px; }
.choices { display: flex; flex-wrap: wrap; gap: 8px; }
.choice {
  min-height: 42px; padding: 0 16px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--surface-2); cursor: pointer; font-weight: 600; font-size: 15px;
}
.choice[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

/* ---------- ゲーム画面 ---------- */
.play { display: flex; flex-direction: column; gap: 12px; }
.status {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 8px 12px; min-height: 52px; font-weight: 700;
}
.status .msg { flex: 1; }
.status .thinking::after { content: ""; display: inline-block; width: 1.2em; text-align: left; animation: dots 1.2s steps(4) infinite; }
@keyframes dots { 0% { content: ""; } 25% { content: "・"; } 50% { content: "・・"; } 75% { content: "・・・"; } }
.score { display: flex; gap: 12px; font-size: 15px; white-space: nowrap; }
.score .chip { display: inline-flex; align-items: center; gap: 5px; }
.score .dot { width: 14px; height: 14px; border-radius: 50%; display: inline-block; border: 1px solid rgba(0,0,0,.35); }

.board-wrap { display: flex; justify-content: center; }
.board-wrap > svg, .board-wrap > .board { width: min(100%, calc(100dvh - 260px)); max-width: 640px; height: auto; touch-action: manipulation; user-select: none; -webkit-user-select: none; }

.toolbar { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.toolbar .btn { flex: 1 1 0; min-width: 88px; max-width: 200px; padding: 0 8px; font-size: 15px; white-space: nowrap; }

.cell-hit { cursor: pointer; }
.hint-ring { fill: none; stroke: var(--hint); stroke-width: 3; animation: pulse 1s ease-in-out infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .35; } }

/* ---------- 重ねて出す画面 ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 50; background: rgba(20, 16, 12, .45);
  display: grid; place-items: center; padding: 20px;
}
.dialog {
  width: min(420px, 100%); background: var(--surface); border-radius: 18px; padding: 22px 20px 18px;
  box-shadow: 0 10px 40px rgba(0,0,0,.3); text-align: center;
  max-height: calc(100dvh - 40px); overflow-y: auto;
}
.dialog h2 { margin: 0 0 6px; font-size: 24px; }
.dialog p { margin: 0 0 16px; color: var(--ink-soft); white-space: pre-line; }
.dialog .actions { display: flex; flex-direction: column; gap: 10px; }
.result-win { color: var(--good); }
.result-lose { color: var(--warn); }

/* ---------- 設定・戦績 ---------- */
.setting-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.setting-row:last-child { border-bottom: 0; }
.stats-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.stats-table th, .stats-table td { padding: 8px 6px; border-bottom: 1px solid var(--line); text-align: right; }
.stats-table th:first-child, .stats-table td:first-child { text-align: left; }

.toast {
  position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 20px); transform: translateX(-50%);
  background: var(--ink); color: var(--bg); padding: 10px 18px; border-radius: 999px; z-index: 60;
  font-size: 14px; font-weight: 600; box-shadow: var(--shadow); max-width: calc(100% - 32px); text-align: center;
}
