/* ============================================================
   AI村シミュレーター — Cozy Medieval（羊皮紙＋木＋暖色）
   外部画像を一切使わずCSSグラデーションだけで紙と木の質感を作る（PWAオフライン維持）。
   旧トークン名（--panel-bg 等）はエイリアスとして残す（既存コードの参照を壊さない）。
   ============================================================ */

:root {
  /* 紙 */
  --parchment:   #f4e7cd;
  --parchment-2: #e9d8b2;
  --parchment-3: #dcc596;
  /* 木 */
  --wood:        #6b4726;
  --wood-dark:   #3d2712;
  --wood-light:  #8f6136;
  /* インク */
  --ink:         #3a2a1b;
  --ink-dim:     #7a6449;
  --ink-faint:   #a4906f;
  /* アクセント */
  --gold:        #b8862b;
  --seal-red:    #9c3a2c;
  --leaf:        #5f7c3a;
  --sky:         #3f6f98;
  --ribbon:      #77519c;
  /* バー */
  --bar-hunger: #d98a2b;
  --bar-thirst: #4f8fbe;
  --bar-health: #6f9a4a;
  --bar-energy: #9a7ac0;

  --radius: 10px;
  --radius-sm: 6px;
  --shadow-soft: 0 3px 10px rgba(60,40,20,.22);
  --shadow-deep: 0 10px 30px rgba(40,25,10,.45);

  /* 旧トークンのエイリアス（削除しない） */
  --bg-day: #7ec0ee;
  --bg-night: #16213e;
  --panel-bg: var(--parchment);
  --panel-bg2: var(--parchment-2);
  --panel-border-light: var(--parchment-3);
  --panel-border-dark: var(--wood);
  --text-main: var(--ink);
  --text-dim: var(--ink-dim);
  --accent: var(--gold);
  --accent2: var(--seal-red);
  --good: var(--leaf);
  --bad: var(--seal-red);
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  background: var(--wood-dark);
  color: var(--ink);
  font-family: 'Zen Maru Gothic', 'Hiragino Maru Gothic ProN', 'Yu Gothic', sans-serif;
  font-size: 14px;
  /* ページは絶対にスクロールしない。スクロールするのはポップアップの中だけ。 */
  width: 100%; height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  scrollbar-color: var(--wood) var(--parchment-2);
}

/* ============================================================
   シェル: 画面は「世界」1枚。UIはその上に浮かぶだけ。
   100dvh に固定し overflow:hidden。iOSのアドレスバー伸縮でも高さが崩れない。
   セーフエリアは #app ではなく“浮かぶUI側”に効かせる（世界は端まで届かせる）。
   ============================================================ */
#app {
  position: fixed; inset: 0;
  width: 100%;
  height: 100vh; height: 100dvh;
  max-width: none; margin: 0; padding: 0;
  display: flex; flex-direction: column;
  overflow: hidden;
  background: var(--wood-dark);
}

.sr-only {
  position: absolute !important; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ---- 羊皮紙パネル ---- */
.pixel-panel {
  background:
    radial-gradient(120% 90% at 20% 0%, rgba(255,255,255,.38), transparent 60%),
    repeating-linear-gradient(94deg, rgba(150,120,80,.045) 0 2px, transparent 2px 5px),
    repeating-linear-gradient(3deg,  rgba(150,120,80,.035) 0 3px, transparent 3px 7px),
    var(--parchment);
  border: 2px solid var(--wood);
  border-radius: var(--radius);
  box-shadow: var(--shadow-soft), inset 0 0 0 1px rgba(255,255,255,.4), inset 0 0 28px rgba(150,110,60,.18);
  padding: 14px 16px;
  margin-bottom: 12px;
}
.pixel-panel h2 {
  margin: 0 0 10px 0;
  font-size: 15px; font-weight: 700;
  color: var(--wood-dark);
  letter-spacing: .04em;
  font-feature-settings: 'palt';
  border-bottom: 2px solid var(--parchment-3);
  padding-bottom: 6px;
}
.pixel-panel h2::before { content: '❧'; color: var(--gold); margin-right: 6px; }
.stat { color: var(--ink-dim); }
.stat b { color: var(--ink); }

/* ============ HUD（村の看板。3Dの上に浮かせる） ============
   木目の帯として画面を1本潰すのをやめ、上から溶け込むグラデーションの上に置く。 */
.hud {
  position: absolute; top: 0; left: 0; right: 0; z-index: 6;
  /* 世界を触れなくしないため、HUDの“帯”自体はイベントを素通しする。
     押せるのは中の丸ピルだけ（下の pointer-events:auto を参照）。 */
  pointer-events: none;
  display: flex; flex-direction: column; align-items: flex-start;
  gap: 6px;
  /* 右上の時計は #canvas-tools が使うので、その幅ぶんだけ空けておく */
  padding: max(8px, env(safe-area-inset-top)) 78px 26px max(10px, env(safe-area-inset-left));
  border: none; border-radius: 0;
  color: #f7ead0;
  background: linear-gradient(180deg, rgba(24,15,6,.55) 0%, rgba(24,15,6,.26) 58%, transparent 100%);
  text-shadow: 0 1px 3px rgba(0,0,0,.65);
}
.hud-brand, .hud-metric, .alert-chip, .hud-l2 { pointer-events: auto; }
.hud-top { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 14px; width: 100%; }
.hud-brand {
  display: flex; align-items: center; gap: 9px; min-width: 0;
  background: none; border: none; padding: 2px 4px 2px 0; margin: 0;
  color: inherit; font: inherit; text-align: left; cursor: pointer;
  min-height: 44px;
}
.hud-more { font-size: 11px; opacity: .75; transition: transform .2s ease; }
.hud-brand[aria-expanded="true"] .hud-more { transform: rotate(180deg); }
.hud-crest {
  width: 38px; height: 38px; flex: 0 0 38px;
  display: grid; place-items: center; font-size: 20px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #f0d79a, var(--gold));
  box-shadow: inset 0 -2px 4px rgba(0,0,0,.35), 0 2px 5px rgba(0,0,0,.3);
}
.hud-name { min-width: 0; display: block; }
#village-title {
  display: block;
  margin: 0; font-size: 16px; font-weight: 700; color: #fdf3dd;
  letter-spacing: .04em; text-shadow: 0 2px 0 rgba(0,0,0,.35);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 46vw;
}
.hud-sub { display: flex; flex-wrap: wrap; gap: 3px 8px; font-size: 10.5px; color: #e3cfa6; margin-top: 1px; }
.hud-sub b { color: #fdf3dd; }
.hud-stage {
  background: rgba(0,0,0,.28); border: 1px solid rgba(255,255,255,.18);
  border-radius: 999px; padding: 1px 8px; color: #f2dfae;
}
.hud-weather::before { content: '☁ '; opacity: .8; }

/* 常時見せるのは 人口 / 食料 / 村庫 の3つだけ。治安・暮らしは L2 に畳む。 */
.hud-metrics { display: flex; flex-wrap: nowrap; gap: 5px; margin-left: auto; }
.hud-metric {
  display: flex; align-items: center; gap: 4px;
  padding: 5px 10px; min-height: 32px;
  border-radius: 999px;
  background: rgba(28,19,9,.46);
  -webkit-backdrop-filter: blur(7px); backdrop-filter: blur(7px);
  border: 1px solid rgba(244,231,205,.26);
  color: #f2e2c2; text-shadow: 0 1px 2px rgba(0,0,0,.6);
  cursor: help;
}
.hud-metric.wide { min-width: 118px; }
.hud-metric i { font-style: normal; font-size: 13px; }
.hud-metric .hud-label { font-size: 10.5px; color: #d9c49b; }
.hud-metric b { font-size: 15px; font-weight: 700; color: #fff6e2; margin-left: auto; }
.hud-delta { font-size: 10px; font-style: normal; min-width: 22px; color: transparent; }
.hud-delta.good { color: #a9d16a; }
.hud-delta.bad { color: #f09a86; }
.hud-metric.warn { border-color: rgba(230,120,100,.95); box-shadow: 0 0 0 2px rgba(156,58,44,.35); }
@keyframes hudflash { 0% { transform: translateY(-3px); opacity: .2; } 100% { transform: none; opacity: 1; } }
.hud-delta.flash { animation: hudflash .5s ease-out; }

/* ⚠警告（4つめの常時表示。1行に収めて世界の見せ場を食わない） */
.hud-alerts { display: flex; flex-wrap: wrap; gap: 6px; max-width: 100%; max-height: 1.95em; overflow: hidden; }
.hud-alerts:empty { display: none; }
.alert-chip {
  font-size: 11px; padding: 3px 9px; border-radius: 999px;
  background: rgba(156,58,44,.86); color: #ffe9df;
  -webkit-backdrop-filter: blur(5px); backdrop-filter: blur(5px);
  border: 1px solid rgba(255,220,200,.32);
  box-shadow: 0 2px 4px rgba(0,0,0,.3);
  white-space: nowrap;
}
.alert-chip::before { content: '⚠ '; }
.alert-chip.mild { background: rgba(184,134,43,.86); color: #3a2a1b; }

/* L2: 畳まれた副次情報（村名をタップで開く） */
.hud-l2 {
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px;
  padding: 8px 10px; border-radius: 12px;
  background: rgba(28,19,9,.5);
  -webkit-backdrop-filter: blur(9px); backdrop-filter: blur(9px);
  border: 1px solid rgba(244,231,205,.22);
  animation: hudflash .18s ease-out;
}
.hud-l2[hidden] { display: none; }
.hud-l2-row {
  display: flex; align-items: center; gap: 6px;
  font-size: 11.5px; color: #d9c49b; padding: 0 6px;
}
.hud-l2-row b { color: #fdf3dd; font-size: 13px; }

/* ============ ポップアップ内の副タブ ============
   8枚の木札を画面に常時並べるのをやめ、アイコン列（#rail）で選んだ“群”の中だけを出す。 */
#tabs {
  display: flex; overflow-x: auto; gap: 5px;
  flex: 1 1 auto; min-width: 0;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  scroll-snap-type: x proximity;
}
#tabs::-webkit-scrollbar { display: none; }
/* 選ばれた群のタブだけを出す。出し分けは ui.js が hidden 属性で行う。 */
.tab-btn {
  display: inline-flex; align-items: center;
  scroll-snap-align: start;
  flex: 0 0 auto;
  background: rgba(28,19,9,.45);
  -webkit-backdrop-filter: blur(7px); backdrop-filter: blur(7px);
  color: #f0dcb8;
  border: 1px solid rgba(244,231,205,.3);
  border-radius: 999px;
  min-height: 40px; padding: 6px 14px;
  font-family: inherit; font-weight: 500; font-size: 12.5px;
  cursor: pointer; white-space: nowrap;
  transition: background .15s ease;
}
.tab-btn[hidden] { display: none; }
.tab-btn.active {
  background: linear-gradient(180deg, #f6e6c2, var(--parchment-2));
  color: var(--wood-dark); font-weight: 700;
  border-color: var(--gold);
}
.tab-section { display: none; }
.tab-section.active { display: block; }

/* ============ マップ（画面の主役） ============
   ダッシュボードではなくゲームに見せるため、3Dを画面の7割以上に広げ、
   「窓の中の絵」に見える太い枠と内側の影を外して端まで到達させる。 */
#map-wrap { text-align: center; position: relative; padding: 0; margin: 0; flex: 1 1 auto; min-height: 0; display: flex; }
#village-canvas-container {
  width: 100%; height: 100%; min-height: 0; flex: 1 1 auto;
  border-radius: 0;
  border: none;
  background: var(--bg-day);
  overflow: hidden; position: relative;
}
#village-canvas { display: block; width: 100%; height: 100%; touch-action: none; }

/* テロップ（映画の字幕帯）。画面上端の不透明な板は夜景の一番いい所を潰すので、
   下端寄りの暗い半透明バーにして、常に1行に収める（2行化がボタンとの重なりの直接原因だった）。 */
#telop {
  position: absolute; left: 50%; transform: translate(-50%, 6px);
  /* モード切替バー（#mode-bar）がレールの上に1段入ったので、字幕はその上へ逃がす。 */
  bottom: calc(122px + env(safe-area-inset-bottom)); max-width: min(52ch, calc(100% - 36px));
  padding: 7px 16px;
  background: rgba(30,22,14,.62);
  -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
  border: 1px solid rgba(244,231,205,.28); border-radius: 999px;
  font-size: 12.5px; font-weight: 500; color: #f7ead0;
  text-align: center; text-shadow: 0 1px 2px rgba(0,0,0,.6);
  pointer-events: auto; cursor: pointer;
  opacity: 0;
  transition: opacity .5s ease, transform .5s ease;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  box-shadow: 0 4px 14px rgba(0,0,0,.35); z-index: 3;
}
#telop.show { opacity: 1; transform: translate(-50%, 0); }
#telop.good { border-color: rgba(151,199,96,.8); }
#telop.bad, #telop.death { border-color: rgba(224,120,100,.85); color: #ffd9d0; }
#telop.law { border-color: rgba(186,150,224,.85); }
#telop.weather { border-color: rgba(126,180,224,.85); }
/* 「なぜ」は主張させない。辿れることだけ控えめに示す（世界の邪魔をしない） */
#telop.clickable::after { content: ' ›'; color: rgba(240,215,154,.55); font-size: 12px; }

/* 時の流れは世界の右上の隅に小さく置く（下辺はメニューとテロップが使う）。 */
#canvas-tools {
  /* レールと同じくシートより上。ポップアップを開いたまま時を進めたり止めたりできる。 */
  position: absolute; z-index: 45;
  right: max(8px, env(safe-area-inset-right));
  top: max(8px, env(safe-area-inset-top));
  display: flex; flex-direction: column; align-items: flex-end; gap: 6px;
}
.time-cycle {
  display: inline-flex; flex-direction: column; align-items: center; justify-content: center;
  min-width: 56px; min-height: 46px; gap: 1px; padding: 4px 8px;
  border-radius: 14px;
  background: rgba(28,19,9,.5);
  -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
  border: 1px solid rgba(244,231,205,.28);
  color: #f6e9d2; font-family: inherit; font-size: 10.5px; font-weight: 700;
  cursor: pointer; text-shadow: 0 1px 2px rgba(0,0,0,.6);
}
.time-cycle .tc-icon { font-size: 13px; letter-spacing: -1px; }
/* 本文は「1日13秒」のような実時間表記（倍率ではない）。折り返すとボタンが2段になって
   世界を隠すので nowrap にし、幅はテキストに合わせて伸ばす */
.time-cycle #tc-label { white-space: nowrap; }
.time-cycle.capped { border-color: rgba(230,160,80,.8); color: #ffdca8; }
#btn-autocam.off { opacity: .6; }

/* ============ 世界の上に浮かぶメニュー（8タブの置き換え） ============
   下辺中央に5つのアイコン。世界は下まで見えていて、UIはその上に“乗っている”だけ。 */
#rail {
  /* シート（#panels, z-index:40）が開いている間もレールは触れなければならない。
     ここが下に潜ると「開いたら群を切り替えられない」＝主要ナビが死ぬ。 */
  position: fixed; z-index: 50;
  left: 50%; transform: translateX(-50%);
  bottom: max(10px, env(safe-area-inset-bottom));
  display: flex; gap: 4px;
  padding: 4px;
  border-radius: 18px;
  background: rgba(28,19,9,.46);
  -webkit-backdrop-filter: blur(10px) saturate(1.1); backdrop-filter: blur(10px) saturate(1.1);
  border: 1px solid rgba(244,231,205,.24);
  box-shadow: 0 6px 20px rgba(0,0,0,.42);
  max-width: calc(100% - 16px);
}
.rail-btn {
  position: relative;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
  min-width: 56px; min-height: 48px; padding: 4px 6px;
  border: none; border-radius: 14px; background: transparent;
  color: #eddcbb; font-family: inherit; font-size: 10px; font-weight: 500;
  cursor: pointer; text-shadow: 0 1px 2px rgba(0,0,0,.5);
  transition: background .15s ease, color .15s ease;
}
.rail-btn i { font-style: normal; font-size: 19px; line-height: 1.1; }
.rail-btn:hover { background: rgba(244,231,205,.12); }
.rail-btn.active {
  background: linear-gradient(180deg, rgba(246,230,194,.94), rgba(233,216,178,.9));
  color: var(--wood-dark); font-weight: 700; text-shadow: none;
  box-shadow: inset 0 -3px 0 var(--gold);
}
.rail-badge {
  position: absolute; top: 2px; right: 6px;
  font-style: normal; font-size: 0;
}
.rail-badge:not(:empty) {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--seal-red); border: 1.5px solid #ffe9df;
  animation: railPing 1.6s ease-in-out infinite;
}
@keyframes railPing { 0%,100% { box-shadow: 0 0 0 0 rgba(156,58,44,.6); } 50% { box-shadow: 0 0 0 6px rgba(156,58,44,0); } }

/* ボタン（焼印風） */
.pixel-btn {
  background: linear-gradient(180deg, var(--parchment), var(--parchment-2));
  color: var(--ink);
  border: 2px solid var(--wood);
  border-radius: var(--radius-sm);
  padding: 6px 11px;
  font-family: inherit; font-weight: 500; font-size: 12px;
  cursor: pointer;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.6), 0 2px 3px rgba(60,40,20,.25);
  transition: transform .12s ease, background .15s ease;
}
.pixel-btn:hover { transform: translateY(-1px); }
.pixel-btn.active {
  background: linear-gradient(180deg, #e6bf6b, var(--gold));
  color: #2f2109; font-weight: 700;
}

/* 進捗（マップ最下部に吸着した極細の線） */
#progress-bar {
  position: absolute; left: 0; right: 0; bottom: 0;
  height: 4px; background: rgba(61,39,18,.55); z-index: 4;
}
#progress-fill { height: 100%; background: linear-gradient(90deg, var(--gold), #f0d79a); width: 0%; }

#select-panel { display: none !important; }

/* ============ 村の暮らし（概況） ============ */
.ov-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 10px; }
.ov-card {
  background: linear-gradient(180deg, rgba(255,255,255,.4), transparent), var(--parchment-2);
  border: 2px solid var(--wood); border-radius: var(--radius-sm);
  padding: 9px 11px;
}
.ov-card h3 { margin: 0 0 6px; font-size: 12px; color: var(--wood-dark); letter-spacing: .03em; }
.ov-row { display: flex; justify-content: space-between; gap: 8px; font-size: 12px; padding: 2px 0; }
.ov-row span { color: var(--ink-dim); }
.ov-row b { color: var(--ink); font-weight: 700; }
.job-row { display: flex; align-items: center; gap: 6px; margin: 3px 0; font-size: 12px; }
.job-row .job-name { width: 58px; color: var(--ink-dim); }
.job-bar { flex: 1; height: 9px; background: rgba(90,60,30,.18); border-radius: 999px; overflow: hidden; }
.job-bar i { display: block; height: 100%; background: linear-gradient(90deg, var(--wood-light), var(--gold)); }
.job-row .job-n { width: 26px; text-align: right; font-weight: 700; }

/* ============ 村人カード ============ */
#villager-grid, #fav-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(158px, 1fr)); gap: 10px;
}
.vcard {
  background: linear-gradient(180deg, rgba(255,255,255,.45), transparent 60%), var(--parchment-2);
  border: 2px solid var(--wood);
  border-radius: var(--radius-sm);
  padding: 8px 9px; font-size: 11.5px;
  cursor: pointer; position: relative;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.5);
  transition: transform .12s ease, box-shadow .12s ease;
}
.vcard:hover { transform: translateY(-2px); box-shadow: var(--shadow-soft); }
.vcard.dead { opacity: .62; background: var(--parchment-3); }
.vcard.fav { border-color: var(--gold); box-shadow: 0 0 0 2px rgba(184,134,43,.35); }
.vcard-head { display: flex; align-items: center; gap: 6px; margin-bottom: 3px; }
.vcard-name { font-size: 12.5px; font-weight: 700; color: var(--wood-dark); }
.vcard-job { font-size: 10px; color: #fdf1d8; background: var(--wood-light); border-radius: 999px; padding: 1px 7px; }
.vcard-titles { color: var(--ink-dim); font-size: 10px; min-height: 13px; }
.vcard-skills { font-size: 10.5px; }
.bar-row { display: flex; align-items: center; gap: 4px; margin: 2px 0; }
.bar-label { width: 30px; color: var(--ink-dim); font-size: 10px; }
.bar-track { flex: 1; height: 7px; background: rgba(90,60,30,.22); border-radius: 999px; overflow: hidden; box-shadow: inset 0 1px 2px rgba(60,40,20,.3); }
.bar-fill { height: 100%; border-radius: 999px; }
.vcard-action { margin-top: 4px; color: var(--ink); font-weight: 500; }
.vcard-star { position: absolute; top: 5px; right: 6px; font-size: 12px; color: var(--gold); }

/* ============ ドロワー（人物） ============ */
/* 下から出るボトムシート。上スワイプで全画面、下スワイプ／背景タップ／✕で閉じる。 */
.drawer { position: fixed; inset: 0; z-index: 60; pointer-events: none; }
.drawer.open { pointer-events: auto; }
.drawer-scrim {
  position: absolute; inset: 0; background: rgba(20,12,4,.26);
  opacity: 0; transition: opacity .25s ease;
}
.drawer.open .drawer-scrim { opacity: 1; }
.drawer-body {
  position: absolute; left: 0; right: 0; bottom: 0; top: auto;
  width: 100%; height: 58dvh;
  display: flex; flex-direction: column;
  transform: translateY(102%);
  transition: transform .28s cubic-bezier(.2,.8,.3,1), height .24s cubic-bezier(.2,.8,.3,1);
  background: rgba(246,234,210,.90);
  -webkit-backdrop-filter: blur(12px) saturate(1.15); backdrop-filter: blur(12px) saturate(1.15);
  border: 1px solid rgba(43,26,10,.5); border-bottom: none;
  border-radius: 18px 18px 0 0;
  box-shadow: 0 -12px 34px rgba(0,0,0,.45);
  padding: 0 12px calc(10px + env(safe-area-inset-bottom));
  touch-action: pan-y;
}
.drawer.open .drawer-body { transform: none; }
.drawer.expanded .drawer-body { height: 94dvh; }
.drawer .sheet-grip { background: rgba(90,60,30,.42); box-shadow: none; cursor: grab; }
.drawer-close {
  position: absolute; top: 12px; right: 10px; z-index: 2;
  width: 44px; height: 44px; border-radius: 50%;
  background: var(--parchment-2); border: 2px solid var(--wood); color: var(--ink);
  font-size: 14px; cursor: pointer;
}
#pd-head { padding-right: 52px; }

@media (min-width: 861px) {
  .drawer-body {
    left: 12px; right: auto; bottom: 12px;
    width: min(430px, 40vw); height: 66dvh;
    border-radius: 18px; border-bottom: 1px solid rgba(43,26,10,.5);
  }
  .drawer.expanded .drawer-body { height: calc(100dvh - 24px); }
}
.pd-name { font-size: 19px; font-weight: 700; color: var(--wood-dark); letter-spacing: .03em; }
.pd-meta { font-size: 11.5px; color: var(--ink-dim); margin-top: 2px; }
.pd-badges { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 5px; }
.badge {
  flex: 0 0 auto; white-space: nowrap;
  font-size: 10.5px; padding: 2px 8px; border-radius: 999px;
  background: var(--parchment-3); border: 1px solid var(--wood-light); color: var(--ink);
}
.badge.gold { background: linear-gradient(180deg,#eecd82,var(--gold)); color: #2f2109; border-color: #8a6318; }
.badge.seal { background: var(--seal-red); color: #ffe9df; border-color: #6d271d; }
.badge.lineage { background: var(--ribbon); color: #f5ecff; border-color: #4e3369; }

.drawer-tabs { display: flex; gap: 4px; margin: 9px 0 0; }
.dt-btn {
  flex: 1; min-height: 38px;
  background: linear-gradient(180deg, var(--wood-light), var(--wood));
  color: #f0dcb8; border: 2px solid #2a1a0a; border-bottom: none;
  border-radius: 7px 7px 0 0; font-family: inherit; font-size: 12px; cursor: pointer;
}
.dt-btn.active { background: linear-gradient(180deg,#fbf1da,var(--parchment)); color: var(--wood-dark); font-weight: 700; box-shadow: inset 0 -3px 0 var(--gold); }
.dt-body {
  flex: 1; overflow-y: auto; overscroll-behavior: contain;
  border: 2px solid var(--wood); border-radius: 0 0 var(--radius-sm) var(--radius-sm);
  background: rgba(255,255,255,.28); padding: 10px;
}
.dt-section { display: none; }
.dt-section.active { display: block; }
#pd-actions { display: flex; flex-wrap: wrap; gap: 6px; padding-top: 8px; }
#pd-actions .pixel-btn { flex: 1 1 auto; min-height: 40px; }

/* ドロワー内パーツ */
.pd-action-line {
  display: flex; align-items: center; gap: 8px;
  font-size: 15px; font-weight: 700; color: var(--wood-dark);
  background: var(--parchment-2); border: 2px solid var(--wood); border-radius: var(--radius-sm);
  padding: 8px 10px; margin-bottom: 8px;
}
.pd-action-line .big { font-size: 20px; }
.pd-reason { font-size: 11.5px; color: var(--ink-dim); font-weight: 400; }
.pd-carry { display: flex; gap: 10px; font-size: 12.5px; margin: 6px 0; }
.pd-carry span { background: var(--parchment-3); border-radius: 999px; padding: 2px 9px; }
.pd-sub { font-size: 11px; color: var(--ink-dim); margin: 10px 0 4px; letter-spacing: .05em; border-bottom: 1px dashed var(--parchment-3); }
.kv { display: flex; justify-content: space-between; font-size: 12px; padding: 2px 0; }
.kv span { color: var(--ink-dim); }

.score-row { margin: 7px 0; }
.score-head { display: flex; justify-content: space-between; font-size: 12px; font-weight: 700; color: var(--wood-dark); }
.score-track { height: 9px; background: rgba(90,60,30,.18); border-radius: 999px; overflow: hidden; margin: 3px 0; }
.score-fill { height: 100%; background: linear-gradient(90deg, var(--wood-light), var(--gold)); }
.score-row.top .score-fill { background: linear-gradient(90deg, var(--gold), #f0d79a); }
.score-why { font-size: 11px; color: var(--ink-dim); }
.danger-note {
  background: var(--seal-red); color: #ffe9df; padding: 7px 10px;
  border-radius: var(--radius-sm); font-weight: 700; font-size: 12.5px; margin-bottom: 8px;
}
.radar { display: block; margin: 4px auto; }

/* タイムライン（人生） */
.timeline { position: relative; padding-left: 14px; }
.timeline::before { content: ''; position: absolute; left: 4px; top: 4px; bottom: 4px; width: 2px; background: var(--parchment-3); }
.tl-item { position: relative; padding: 5px 0 5px 14px; font-size: 12px; }
.tl-item::before {
  content: ''; position: absolute; left: -4px; top: 11px;
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--parchment); border: 2px solid var(--wood-light);
}
.tl-item.big::before { background: var(--gold); border-color: var(--wood); }
.tl-item.bad::before { background: var(--seal-red); border-color: #6d271d; }
.tl-when { font-size: 10.5px; color: var(--ink-faint); }
.tl-text { color: var(--ink); }
.tomb {
  margin-top: 10px; text-align: center; padding: 12px;
  border: 2px solid var(--wood); border-radius: 6px 6px var(--radius-sm) var(--radius-sm);
  background: var(--parchment-3);
}
.tomb .tomb-mark { font-size: 22px; }
.life-summary { font-size: 12px; background: var(--parchment-2); border-left: 4px solid var(--gold); padding: 8px 10px; border-radius: 4px; margin-bottom: 8px; }

.chip-person {
  display: inline-block; margin: 3px 4px 0 0; padding: 4px 10px;
  background: var(--parchment-2); border: 2px solid var(--wood-light); border-radius: 999px;
  font-size: 11.5px; cursor: pointer;
}
.chip-person:hover { background: var(--parchment-3); }
.aff-row { display: flex; align-items: center; gap: 6px; font-size: 11.5px; margin: 3px 0; }
.aff-name { flex: 1; cursor: pointer; text-decoration: underline dotted var(--ink-faint); }
.aff-track { width: 84px; height: 7px; background: rgba(90,60,30,.18); border-radius: 999px; position: relative; overflow: hidden; }
.aff-fill { position: absolute; top: 0; height: 100%; }
.aff-fill.pos { background: var(--leaf); left: 50%; }
.aff-fill.neg { background: var(--seal-red); right: 50%; }
.aff-val { width: 34px; text-align: right; color: var(--ink-dim); }

.person-link { color: var(--wood-dark); font-weight: 700; text-decoration: underline dotted var(--gold); cursor: pointer; }
/* 控えめに。塗りをやめ、薄い文字だけにする（必要な人だけが気づけばよい） */
.why-btn {
  margin-left: 6px; font-size: 10px; padding: 1px 5px; cursor: pointer;
  background: transparent; border: none; border-radius: 999px;
  color: var(--ink-faint); opacity: .75;
  font-family: inherit;
}
.why-btn:hover { color: var(--wood-dark); opacity: 1; background: var(--parchment-3); }

/* ============ 因果ビュー ============ */
#causal-filters { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.chip {
  font-size: 11.5px; padding: 5px 12px; border-radius: 999px; cursor: pointer;
  background: var(--parchment-2); border: 2px solid var(--wood-light); color: var(--ink);
  font-family: inherit;
}
.chip.active { background: linear-gradient(180deg,#eecd82,var(--gold)); color: #2f2109; font-weight: 700; border-color: var(--wood); }
.causal-cols { display: grid; grid-template-columns: 268px 1fr; gap: 12px; align-items: start; }
#causal-list { max-height: 560px; overflow-y: auto; padding-right: 4px; }
.cev {
  padding: 7px 9px; margin-bottom: 6px; cursor: pointer;
  background: var(--parchment-2); border: 2px solid var(--wood-light);
  border-left-width: 5px; border-radius: var(--radius-sm); font-size: 11.5px;
}
.cev:hover { background: var(--parchment-3); }
.cev.sel { border-color: var(--gold); background: #fbf1da; }
.cev-when { font-size: 10px; color: var(--ink-faint); }
.cev.k-bad, .cev.k-death { border-left-color: var(--seal-red); }
.cev.k-law { border-left-color: var(--ribbon); }
.cev.k-good { border-left-color: var(--leaf); }
.cev.k-weather { border-left-color: var(--sky); }

#causal-chain { min-height: 200px; }
.chain-empty { color: var(--ink-dim); font-size: 12.5px; padding: 20px 6px; text-align: center; }
.chain-step {
  position: relative;
  background: linear-gradient(180deg, rgba(255,255,255,.5), transparent 60%), var(--parchment-2);
  border: 2px solid var(--wood); border-left-width: 5px;
  border-radius: var(--radius-sm); padding: 8px 11px;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.5);
}
.chain-step.k-bad, .chain-step.k-death { border-left-color: var(--seal-red); }
.chain-step.k-law { border-left-color: var(--ribbon); }
.chain-step.k-good { border-left-color: var(--leaf); }
.chain-step.k-weather { border-left-color: var(--sky); }
.chain-step.cond-card { background: rgba(255,255,255,.35); border-style: dashed; border-radius: 3px; }
.chain-step.root { border-color: var(--seal-red); box-shadow: 0 0 0 2px rgba(156,58,44,.22); }
.chain-head { display: flex; justify-content: space-between; gap: 8px; font-size: 10.5px; color: var(--ink-faint); }
.chain-conf { color: var(--gold); font-weight: 700; }
.chain-text { font-size: 13px; margin-top: 3px; color: var(--ink); }
.chain-link { display: flex; align-items: center; gap: 8px; padding-left: 16px; height: 30px; }
.chain-link::before { content: ''; width: 3px; height: 30px; background: var(--wood); }
.chain-link.inferred::before { background: repeating-linear-gradient(180deg, var(--wood) 0 4px, transparent 4px 8px); }
.chain-why { font-size: 11px; color: var(--ink-dim); }
/* 因果ビューのroot札に押す封蝋。.badge.seal（死因バッジ）と衝突しない名前にする */
.chain-seal {
  display: inline-block; width: 20px; height: 20px; border-radius: 50%; vertical-align: -4px;
  background: radial-gradient(circle at 35% 30%, #c05646, var(--seal-red));
  box-shadow: inset 0 -2px 4px rgba(0,0,0,.35); margin-right: 6px;
}
.chain-summary {
  margin-top: 12px; padding: 10px 12px; font-size: 12.5px; line-height: 1.7;
  background: var(--parchment-3); border-left: 5px solid var(--gold); border-radius: 4px;
}
.chain-effects { margin-top: 10px; }
.chain-note { font-size: 11px; color: var(--ink-dim); margin-bottom: 8px; }

/* ============ ログ・憲法・グラフ・家系図・年表 ============ */
#event-log { max-height: 440px; overflow-y: auto; display: flex; flex-direction: column-reverse; }
.log-line {
  padding: 6px 4px 6px 18px; position: relative;
  border-bottom: 1px dashed var(--parchment-3); font-size: 12.5px;
}
.log-line::before {
  content: ''; position: absolute; left: 4px; top: 11px;
  width: 8px; height: 8px; border-radius: 50%; background: var(--ink-faint);
}
.log-line .tick { color: var(--ink-faint); margin-right: 6px; font-size: 10.5px; }
.log-line.good::before { background: var(--leaf); }
.log-line.bad::before, .log-line.death::before { background: var(--seal-red); }
.log-line.law::before { background: var(--ribbon); }
.log-line.weather::before { background: var(--sky); }
.log-line.bad, .log-line.death { color: #7a2a1e; }

.law-item {
  padding: 8px 10px; margin-bottom: 6px; font-size: 12.5px;
  background: var(--parchment-2); border-left: 5px solid var(--ribbon); border-radius: 4px;
}
.law-item b { color: var(--wood-dark); }

#graph-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 10px; }
.graph-cell canvas {
  width: 100%; height: 108px; display: block;
  background: rgba(255,255,255,.4);
  border-radius: var(--radius-sm); border: 2px solid var(--wood-light);
}
.graph-cell h3 { font-size: 11.5px; margin: 4px 0; color: var(--wood-dark); }

#genealogy ul { list-style: none; padding-left: 16px; border-left: 2px dashed var(--parchment-3); margin: 4px 0; }
#genealogy li { margin: 4px 0; font-size: 12.5px; }
.gen-dead { color: var(--ink-faint); }
#chronicle-list { list-style: none; padding: 0; margin: 0; }
.chron-year { font-size: 12px; font-weight: 700; color: var(--wood-dark); margin: 12px 0 4px; border-bottom: 2px solid var(--parchment-3); }
.chron-year:first-child { margin-top: 0; }
#chronicle-list li.chron-year { padding-left: 0; margin-left: 0; }
#chronicle-list li.chron-year::before { content: none; }
#chronicle-list li { margin: 5px 0 5px 4px; font-size: 12.5px; padding-left: 12px; position: relative; }
#chronicle-list li::before { content: '◆'; position: absolute; left: 0; color: var(--gold); font-size: 8px; top: 4px; }

footer#app-footer { color: #c9b08a; font-size: 11px; padding: 6px 0 20px; text-align: center; }
footer#app-footer summary { cursor: pointer; }
footer#app-footer .footer-body { margin-top: 6px; line-height: 1.7; }

/* ============ 世代継承モーダル ============ */
.modal { position: fixed; inset: 0; z-index: 80; display: none; }
.modal.open { display: block; }
.modal-scrim { position: absolute; inset: 0; background: rgba(25,14,4,.68); }
.modal-body {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%,-50%);
  width: min(400px, 92vw); max-height: 88vh; overflow-y: auto;
  padding: 20px 18px; text-align: center;
  background:
    radial-gradient(120% 90% at 30% 0%, rgba(255,255,255,.4), transparent 60%),
    var(--parchment);
  border: 3px solid var(--wood-dark); border-radius: var(--radius);
  box-shadow: var(--shadow-deep);
}
.sc-candle { font-size: 30px; }
.sc-title { font-size: 17px; font-weight: 700; color: var(--wood-dark); margin: 6px 0 2px; }
.sc-meta { font-size: 12px; color: var(--ink-dim); }
.sc-hr { border: none; border-top: 2px solid var(--parchment-3); margin: 12px 0; }
.sc-story { font-size: 13px; line-height: 1.8; }
.sc-q { font-size: 12.5px; color: var(--ink-dim); margin: 10px 0 6px; }
.sc-cand { display: block; width: 100%; margin: 5px 0; min-height: 44px; text-align: left; }
.sc-foot { display: flex; gap: 6px; margin-top: 10px; }
.sc-foot .pixel-btn { flex: 1; min-height: 40px; }

/* ============ レスポンシブ ============ */
@media (max-width: 860px) {
  .causal-cols { grid-template-columns: 1fr; }
  #causal-list { max-height: 260px; }
}
@media (max-width: 560px) {
  .hud { padding: max(8px, env(safe-area-inset-top)) 70px 20px max(8px, env(safe-area-inset-left)); gap: 5px; }
  .hud-top { gap: 4px; }
  .hud-brand { flex: 1 1 100%; min-height: 40px; }
  .hud-metrics { margin-left: 0; width: 100%; gap: 4px; }
  .hud-metric {
    flex: 1 1 0; min-width: 0; padding: 4px 6px; gap: 3px;
    justify-content: center; border-radius: 999px; min-height: 30px;
  }
  .hud-metric b { font-size: 13.5px; margin-left: 2px; }
  .hud-metric .hud-delta { display: none; }
  .hud-l2 .hud-metric .hud-delta { display: inline; }
  .hud-metric i { font-size: 12px; }
  .hud-l2 { width: 100%; }
  .hud-l2 .hud-metric { flex: 1 1 40%; }
  .alert-chip { font-size: 10px; padding: 2px 8px; }
  #village-title { max-width: 52vw; font-size: 15px; }
  #villager-grid, #fav-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
  #graph-grid { grid-template-columns: 1fr; }
  .pixel-btn { min-height: 44px; padding: 10px 13px; }
  /* 折り返すとテロップが2行になり、ボタンと重なって本文が隠れる。必ず1行。 */
  #telop { font-size: 10.5px; white-space: nowrap; padding: 6px 12px; max-width: calc(100% - 24px); }
  .chip { min-height: 36px; display: inline-flex; align-items: center; }
  .council-body { width: 100%; max-width: none; border-radius: 14px 14px 0 0; }
  .rail-btn { min-width: 0; flex: 1 1 0; padding: 4px 2px; }
  #rail { left: 8px; right: 8px; transform: none; max-width: none; }
}

/* ごく狭い端末では、下辺のアイコン列が5つ並びきるよう文字を落とす */
@media (max-width: 340px) {
  .rail-btn span { display: none; }
  .rail-btn { min-height: 46px; }
}

@media (prefers-reduced-motion: reduce) {
  .drawer-body { transition: none; }
  .hud-delta.flash { animation: none; }
  #telop { transition: opacity .2s linear; }
  .pixel-btn:hover, .vcard:hover { transform: none; }
  .sheet, #panels-scrim, .hud-l2 { animation: none; }
  .rail-badge:not(:empty) { animation: none; }
}

/* ============================================================
   半透明ポップアップ（旧・下段ドック＋8タブの置き換え）
   世界のレイヤーは常に見えている。UIはその上に一時的に浮かぶだけ。
   ポップアップの中だけがスクロールする（ページは絶対に動かない）。
   ============================================================ */
/* 器そのものはクリックを受けない。受け取るのは scrim とシートだけ。
   こうしないと、器（inset:0）がレールの上に被さって主要ナビが押せなくなる。 */
#panels { position: fixed; inset: 0; z-index: 40; pointer-events: none; }
#panels-scrim, #panels .sheet { pointer-events: auto; }
#panels[hidden] { display: none; }
#panels-scrim {
  /* レールの帯だけは当たり判定から外す。ここを覆うと、シートを開いている間
     「ひと／できごと／くらし／集会」を押しても閉じるだけになってしまう。 */
  position: absolute; top: 0; left: 0; right: 0; bottom: 66px;
  background: rgba(18,11,3,.22);   /* 薄い。閉じるための当たり判定であって、目隠しではない */
  animation: scrimIn .18s ease-out;
}
@keyframes scrimIn { from { opacity: 0; } to { opacity: 1; } }

.sheet {
  /* 下端はレールぶん空ける（レールを覆うと群の切り替えができなくなる） */
  position: absolute; left: 0; right: 0; bottom: 66px;
  display: flex; flex-direction: column;
  max-height: 64dvh;
  padding: 0 8px max(10px, env(safe-area-inset-bottom));
  animation: sheetUp .22s cubic-bezier(.2,.8,.3,1);
  touch-action: pan-y;
}
@keyframes sheetUp { from { transform: translateY(28px); opacity: .3; } to { transform: none; opacity: 1; } }

.sheet-grip {
  flex: 0 0 auto; align-self: center;
  width: 44px; height: 5px; margin: 6px 0 5px;
  border-radius: 999px; background: rgba(244,231,205,.55);
  box-shadow: 0 1px 3px rgba(0,0,0,.5);
}
.sheet-head {
  flex: 0 0 auto;
  display: flex; align-items: center; gap: 8px;
  padding: 5px 4px 8px;
}
.sheet-close {
  flex: 0 0 auto;
  width: 44px; height: 44px; border-radius: 50%;
  display: grid; place-items: center;
  background: rgba(28,19,9,.5);
  -webkit-backdrop-filter: blur(7px); backdrop-filter: blur(7px);
  border: 1px solid rgba(244,231,205,.3);
  color: #f6e9d2; font-size: 15px; cursor: pointer;
}
.sheet-body {
  flex: 1 1 auto; min-height: 0;
  overflow-y: auto; overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 4px;
}
/* ポップアップの中の紙は半透明にする。ここを不透明にすると世界が消える。 */
#panels .pixel-panel {
  background: rgba(246,234,210,.80);
  -webkit-backdrop-filter: blur(11px) saturate(1.15); backdrop-filter: blur(11px) saturate(1.15);
  border: 1px solid rgba(43,26,10,.5);
  box-shadow: 0 8px 26px rgba(0,0,0,.42);
  margin-bottom: 8px;
}
#panels .pixel-panel:last-child { margin-bottom: 0; }
body.panels-open { overflow: hidden; }

/* ポップアップの中で入れ子スクロールを作らない（シートの本体だけがスクロールする）。
   旧レイアウトの max-height はページスクロール前提の値なので、ここで解除する。 */
#panels .causal-cols { grid-template-columns: 1fr; }
#panels #causal-list { max-height: 44dvh; }
#panels #event-log { max-height: none; }
#panels #graph-grid { grid-template-columns: 1fr; }

/* デスクトップでは右に浮かべる。世界は左3分の2がまるごと見えたまま。 */
@media (min-width: 861px) {
  .sheet {
    left: auto; right: 12px; top: 96px; bottom: 84px;
    width: min(440px, 40vw);
    max-height: none; padding: 0;
  }
}

/* 設定タブ */
.set-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 9px 0; border-bottom: 1px dashed var(--parchment-3);
}
.set-row:last-child { border-bottom: none; }
.set-label { font-size: 12.5px; font-weight: 700; color: var(--wood-dark); }
.set-label span { display: block; font-size: 11px; font-weight: 400; color: var(--ink-dim); margin-top: 2px; }
.set-row .pixel-btn { flex: 0 0 auto; min-height: 44px; }

/* ============ 追いつき再生のオーバーレイ ============ */
#catchup {
  position: absolute; inset: 0; z-index: 8;
  display: grid; place-items: center;
  background: rgba(20,13,5,.55);
  -webkit-backdrop-filter: blur(2px); backdrop-filter: blur(2px);
}
#catchup[hidden] { display: none; }
.cu-box {
  min-width: min(320px, 78vw); padding: 16px 20px;
  border-radius: var(--radius); border: 2px solid #2a1a0a;
  background: linear-gradient(180deg, var(--parchment), var(--parchment-2));
  box-shadow: var(--shadow-deep); text-align: center;
}
.cu-title { font-size: 14px; font-weight: 700; color: var(--wood-dark); }
.cu-track { height: 8px; margin: 10px 0 6px; border-radius: 999px; background: rgba(90,60,30,.22); overflow: hidden; }
.cu-fill { height: 100%; width: 0%; background: linear-gradient(90deg, var(--gold), #f0d79a); transition: width .18s linear; }
.cu-sub { font-size: 11px; color: var(--ink-dim); }

/* ============ 集会（プレイヤーの唯一の手） ============ */
.council-cue {
  /* 下辺はアイコン列とテロップが使うので、その上の段に浮かべる */
  position: absolute; z-index: 6;
  left: 50%; transform: translateX(-50%);
  bottom: calc(126px + env(safe-area-inset-bottom));
  display: inline-flex; align-items: center; gap: 7px;
  min-height: 44px; padding: 8px 15px;
  border-radius: 999px; cursor: pointer;
  font-family: inherit; font-size: 13px; font-weight: 700;
  background: linear-gradient(180deg, #a184c6, var(--ribbon));
  color: #fff6e2; border: 2px solid #2a1a0a;
  box-shadow: 0 4px 14px rgba(0,0,0,.4);
  animation: cuePulse 2.4s ease-in-out infinite;
}
.council-cue[hidden] { display: none; }
.council-cue .cc-when { font-size: 10.5px; font-weight: 500; opacity: .9; }
.council-cue.pushed { background: linear-gradient(180deg, #e0bd6e, var(--gold)); color: #2f2109; animation: none; }
@keyframes cuePulse { 0%,100% { box-shadow: 0 4px 14px rgba(0,0,0,.4); } 50% { box-shadow: 0 4px 14px rgba(0,0,0,.4), 0 0 0 7px rgba(119,81,156,.22); } }

.council-body { width: min(560px, 94vw); max-height: 88vh; overflow-y: auto; position: relative; text-align: left; }
.council-close { position: absolute; top: 10px; right: 10px; z-index: 2; }
.council-head { margin-bottom: 12px; }
.council-title { font-size: 17px; font-weight: 700; color: var(--wood-dark); }
.council-sub { font-size: 12px; color: var(--ink-dim); margin-top: 2px; }
.council-agenda {
  padding: 11px 13px; border-radius: var(--radius-sm);
  border: 2px solid var(--ribbon); background: rgba(119,81,156,.08);
}
.ca-label { font-size: 10.5px; color: var(--ribbon); font-weight: 700; letter-spacing: .06em; }
.ca-name { font-size: 15px; font-weight: 700; color: var(--wood-dark); margin: 2px 0; }
.ca-desc { font-size: 12px; color: var(--ink-dim); }
.ca-count { font-size: 12.5px; margin-top: 7px; }
.ca-count b { font-size: 16px; color: var(--wood-dark); }
.ca-faces { margin-top: 8px; display: flex; flex-direction: column; gap: 5px; }
.cf-row { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; }
.cf-tag { font-size: 10px; font-weight: 700; padding: 2px 7px; border-radius: 999px; color: #fff; }
.cf-tag.yes { background: var(--leaf); }
.cf-tag.no { background: var(--seal-red); }
.cface {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 11px; padding: 2px 8px 2px 3px; border-radius: 999px;
  background: var(--parchment-2); border: 1px solid var(--parchment-3);
  cursor: pointer;
}
.cface i { width: 11px; height: 11px; border-radius: 3px; border: 2px solid; display: inline-block; }
.cface.yes { border-color: rgba(95,124,58,.6); }
.cface.no { border-color: rgba(156,58,44,.6); }
.cface.more { cursor: default; color: var(--ink-dim); padding-left: 8px; }

.council-act { margin-top: 12px; }
.ca-hint { font-size: 12.5px; margin-bottom: 8px; }
.ca-pushed {
  font-size: 13px; padding: 10px 12px; border-radius: var(--radius-sm);
  background: rgba(184,134,43,.16); border: 2px solid var(--gold); margin-bottom: 8px;
}
.ca-laws { display: grid; gap: 6px; }
.btn-endorse { text-align: left; display: block; width: 100%; padding: 9px 12px; position: relative; }
.btn-endorse b { font-size: 13px; }
.btn-endorse .cl-desc { display: block; font-size: 11px; color: var(--ink-dim); margin-top: 2px; }
.btn-endorse .cl-votes {
  position: absolute; right: 10px; top: 9px;
  font-size: 11px; color: var(--ink-dim);
  background: var(--parchment-3); border-radius: 999px; padding: 1px 7px;
}
.cl-note { margin-top: 8px; font-size: 11px; }
.council-result {
  margin-top: 14px; padding: 10px 12px; border-radius: var(--radius-sm);
  border: 2px solid var(--parchment-3); background: rgba(255,255,255,.35); font-size: 12.5px;
}
.council-result.ok { border-color: var(--leaf); }
.council-result.ng { border-color: var(--seal-red); }
.cr-label { font-size: 10.5px; color: var(--ink-dim); }
.cr-dis { margin-top: 6px; display: flex; flex-wrap: wrap; gap: 4px; align-items: center; }

/* ============ グラフの凡例 ============ */
.graph-legend { font-size: 11px; color: var(--ink-dim); margin-bottom: 8px; }
.gl-key { display: inline-block; margin-left: 8px; padding-left: 12px; position: relative; }
.gl-key::before { content: ''; position: absolute; left: 0; top: 1px; width: 2px; height: 12px; }
.gl-law::before { background: rgba(119,81,156,.85); }
.gl-stage::before { background: rgba(184,134,43,.9); }
.gl-famine::before { background: rgba(156,58,44,.75); }
.gc-unit { font-size: 10px; color: var(--ink-faint); font-weight: 400; }

/* ============ 家系図（世代ごと） ============ */
.gen-block { margin-bottom: 12px; }
.gen-head {
  margin: 0 0 6px; font-size: 12px; color: var(--wood-dark);
  border-bottom: 2px solid var(--parchment-3); padding-bottom: 4px;
}
.gen-count { font-weight: 400; font-size: 11px; color: var(--ink-dim); margin-left: 8px; }
.gen-row { display: flex; flex-wrap: wrap; gap: 5px; }
.gen-chip {
  font-size: 11.5px; padding: 3px 9px; border-radius: 999px;
  background: var(--parchment-2); border: 1px solid var(--parchment-3);
  cursor: pointer; text-decoration: none; color: var(--ink);
}
.gen-chip:hover { background: #fbf1da; border-color: var(--gold); }
.gen-chip.gen-dead { opacity: .55; }

/* ============ 村史年表の重み ============ */
.chron-n { font-size: 10.5px; color: var(--ink-faint); margin-left: 8px; font-weight: 400; }
#chronicle-list li.chron-w3 { font-weight: 700; color: var(--wood-dark); }
#chronicle-list li.chron-w2 { color: var(--ink); }
#chronicle-list li.chron-w1 { color: var(--ink-dim); font-size: 12px; }
#chronicle-list li.chron-fold { color: var(--ink-faint); font-size: 11.5px; font-style: italic; }

/* 時の流れボタンの見た目は「世界の上に浮かぶUI」節（.time-cycle）に集約した。
   ここに旧・木札版が残っていて、後勝ちで新しい定義を打ち消していたので削除。 */

#log-filters, #chronicle-filters { display: flex; gap: 6px; margin-bottom: 8px; flex-wrap: wrap; }
.gen-born { font-size: 9.5px; color: var(--ink-faint); margin-left: 4px; }
.btn-endorse .cl-mom { display: block; font-size: 10.5px; color: var(--seal-red); margin-top: 3px; }
.cr-mine { margin-top: 7px; font-size: 12.5px; font-weight: 700; color: var(--wood-dark); }

/* ============================================================
   ★v13 3つの遊び方（👁観察 / 🏗建設 / 🧑住民）— MODES.md
   置き方の原則:
   ・切替バーは「親指の届く下辺」。レールのすぐ上に1段だけ積む（390x844で押せる高さ）。
   ・モードごとの操作盤（#mode-dock）はさらにその上。世界は透けたまま。
   ・区画プレビュー(#plot-overlay)は3Dの上に重ねるだけの薄い板で、
     pointer-events:none。カメラの回転（OrbitControls）を絶対に殺さない。
   下からの積み上げ:  rail(56) → mode-bar(46) → mode-dock → telop
   ============================================================ */
:root {
  --mode-bar-bottom: calc(max(10px, env(safe-area-inset-bottom)) + 62px);
  --mode-dock-bottom: calc(max(10px, env(safe-area-inset-bottom)) + 112px);
  --ok-green: #6fae4a;
  --no-red: #d0604c;
}

/* ---- 区画プレビュー（緑=置ける / 赤=置けない） ---- */
#plot-overlay {
  position: absolute; inset: 0; width: 100%; height: 100%;
  pointer-events: none;              /* ★触らない。タップは #village-canvas が受ける */
  z-index: 5; display: none;
}
body.mode-build #plot-overlay { display: block; }

/* ---- モード切替バー ---- */
#mode-bar {
  position: fixed; z-index: 51;
  left: 50%; transform: translateX(-50%);
  bottom: var(--mode-bar-bottom);
  display: flex; gap: 4px; padding: 4px;
  border-radius: 16px;
  background: rgba(28,19,9,.52);
  -webkit-backdrop-filter: blur(10px) saturate(1.1); backdrop-filter: blur(10px) saturate(1.1);
  border: 1px solid rgba(244,231,205,.28);
  box-shadow: 0 6px 20px rgba(0,0,0,.42);
  max-width: calc(100% - 16px);
}
.mode-btn {
  display: flex; align-items: center; justify-content: center; gap: 5px;
  min-width: 84px; min-height: 40px; padding: 4px 12px;
  border: none; border-radius: 13px; background: transparent;
  color: #eddcbb; font-family: inherit; font-size: 12px; font-weight: 600;
  cursor: pointer; text-shadow: 0 1px 2px rgba(0,0,0,.5);
  transition: background .15s ease, color .15s ease;
}
.mode-btn i { font-style: normal; font-size: 17px; line-height: 1; }
.mode-btn:hover { background: rgba(244,231,205,.12); }
.mode-btn.active {
  background: linear-gradient(180deg, rgba(246,230,194,.96), rgba(233,216,178,.92));
  color: var(--wood-dark); text-shadow: none; font-weight: 700;
  box-shadow: inset 0 -3px 0 var(--gold);
}

/* ---- モードの操作盤（世界の上に浮かぶ羊皮紙） ---- */
#mode-dock {
  position: fixed; z-index: 46;
  left: 50%; transform: translateX(-50%);
  bottom: var(--mode-dock-bottom);
  width: min(560px, calc(100% - 16px));
  max-height: min(46vh, 380px);
  overflow: hidden auto;
  -webkit-overflow-scrolling: touch;
  padding: 9px 10px 10px;
  border-radius: 14px;
  background:
    radial-gradient(120% 90% at 20% 0%, rgba(255,255,255,.30), transparent 60%),
    rgba(38,27,15,.80);
  -webkit-backdrop-filter: blur(12px) saturate(1.1); backdrop-filter: blur(12px) saturate(1.1);
  border: 1px solid rgba(244,231,205,.30);
  box-shadow: 0 10px 28px rgba(0,0,0,.5);
  color: #f6e9d2;
}
#mode-dock[hidden] { display: none; }
body.mdock-open #telop { display: none; }   /* 操作盤の下に字幕が潜るのを避ける */

.md-head { display: flex; align-items: center; gap: 8px; margin-bottom: 7px; }
.md-res { display: flex; gap: 8px; flex: 1 1 auto; min-width: 0; font-size: 12px;
  overflow-x: auto; overflow-y: hidden; scrollbar-width: none; }
.md-res::-webkit-scrollbar { display: none; }
.md-res .res {
  display: inline-flex; align-items: center; gap: 4px; flex: 0 0 auto; white-space: nowrap;
  padding: 3px 9px; border-radius: 999px;
  background: rgba(20,14,7,.5); border: 1px solid rgba(244,231,205,.22);
  font-weight: 700; color: #f7ead0;
}
.md-res .res.lack { border-color: rgba(224,120,100,.9); color: #ffc9bd; background: rgba(120,40,30,.4); }
.md-res .res small { font-weight: 400; opacity: .8; font-size: 10.5px; }
.md-x {
  border: 1px solid rgba(244,231,205,.28); background: rgba(20,14,7,.5);
  color: #f0dfbe; border-radius: 10px; min-width: 34px; min-height: 30px;
  font-family: inherit; font-size: 13px; cursor: pointer;
}

/* ---- 建築メニュー（7枚のカード。横に流れる） ---- */
.md-cards {
  display: flex; gap: 7px; overflow-x: auto; overflow-y: hidden;
  padding-bottom: 4px; scrollbar-width: thin;
}
.bcard {
  flex: 0 0 auto; width: 116px;
  display: flex; flex-direction: column; align-items: flex-start; gap: 2px;
  padding: 7px 8px; border-radius: 11px; text-align: left;
  background: linear-gradient(180deg, rgba(246,230,194,.94), rgba(226,207,166,.9));
  border: 2px solid rgba(61,39,18,.55); color: var(--ink);
  font-family: inherit; cursor: pointer;
  transition: transform .12s ease, box-shadow .12s ease;
}
.bcard:hover { transform: translateY(-2px); }
.bcard.sel {
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(184,134,43,.55), 0 6px 14px rgba(0,0,0,.35);
  background: linear-gradient(180deg, #f7e6bd, #eccf90);
}
.bcard.poor { opacity: .62; }
.bcard .bi { font-size: 19px; line-height: 1.1; }
.bcard .bn { font-size: 13px; font-weight: 700; color: var(--wood-dark); white-space: nowrap; }
.bcard .bc { display: flex; gap: 6px; font-size: 11px; font-weight: 700; color: var(--ink-dim); width: 100%; }
.bcard .bc em { font-style: normal; white-space: nowrap; }
.bcard .bc .lack { color: var(--seal-red); }
.bcard .be { font-size: 10px; line-height: 1.35; color: var(--ink-dim); font-weight: 400;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }

/* ---- 確定バー（3タップ目） ---- */
.md-confirm {
  margin-top: 8px; padding: 8px 9px; border-radius: 11px;
  background: rgba(20,14,7,.55); border: 1px solid rgba(244,231,205,.24);
  display: flex; flex-wrap: wrap; align-items: center; gap: 7px;
}
.md-confirm[hidden] { display: none; }
.md-confirm.ok  { border-color: rgba(111,174,74,.85); background: rgba(38,66,26,.5); }
.md-confirm.no  { border-color: rgba(208,96,76,.9);  background: rgba(88,30,22,.5); }
.mc-text { flex: 1 1 150px; min-width: 0; font-size: 12px; line-height: 1.45; }
.mc-text b { color: #fff6e2; font-size: 13px; }
.mc-reason { display: block; color: #ffc9bd; font-weight: 700; margin-top: 2px; }
.mc-btn {
  border: none; border-radius: 10px; padding: 9px 14px; min-height: 40px;
  font-family: inherit; font-size: 13px; font-weight: 700; cursor: pointer;
  background: linear-gradient(180deg, #8dc95f, var(--ok-green)); color: #16240c;
  box-shadow: 0 3px 8px rgba(0,0,0,.3);
}
.mc-btn[disabled] { background: rgba(120,110,95,.55); color: rgba(255,255,255,.45); cursor: not-allowed; box-shadow: none; }
.mc-btn.danger { background: linear-gradient(180deg, #e0806c, #b04a38); color: #2a0d07; }
.mc-cancel {
  border: 1px solid rgba(244,231,205,.3); background: rgba(20,14,7,.4);
  color: #eddcbb; border-radius: 10px; padding: 9px 12px; min-height: 40px;
  font-family: inherit; font-size: 12px; cursor: pointer;
}

/* ---- 住民モードの指示盤 ---- */
.pp-empty { font-size: 12.5px; line-height: 1.7; color: #f0dfbe; }
.pp-quick { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 7px; }
.pp-chip {
  border: 1px solid rgba(244,231,205,.3); background: rgba(246,230,194,.9);
  color: var(--ink); border-radius: 999px; padding: 6px 11px; min-height: 34px;
  font-family: inherit; font-size: 12px; font-weight: 600; cursor: pointer;
}
.pp-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 6px; }
.pp-name { font-size: 15px; font-weight: 700; color: #fff6e2; }
.pp-meta { font-size: 11px; color: #decfae; }
.pp-doing {
  margin-left: auto; font-size: 11.5px; color: #f7ead0;
  background: rgba(20,14,7,.5); border: 1px solid rgba(244,231,205,.22);
  border-radius: 999px; padding: 3px 10px; white-space: nowrap;
}
.pp-bars { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 3px 10px; margin-bottom: 8px; }
.pp-bar { display: flex; align-items: center; gap: 6px; font-size: 10.5px; color: #e3cfa6; }
.pp-bar span { width: 30px; flex: 0 0 auto; }
.pp-bar .trk { flex: 1 1 auto; height: 7px; border-radius: 999px; background: rgba(10,7,3,.5); overflow: hidden; }
.pp-bar .trk i { display: block; height: 100%; }
.pp-bar b { width: 22px; text-align: right; color: #fff6e2; font-size: 10.5px; }
.pp-sub { font-size: 10.5px; color: #cdbb96; letter-spacing: .05em; margin: 6px 0 5px; }
.pp-acts { display: flex; flex-direction: column; gap: 5px; }
.act-btn {
  display: flex; align-items: center; gap: 8px; width: 100%;
  padding: 8px 10px; min-height: 46px; border-radius: 11px; text-align: left;
  background: linear-gradient(180deg, rgba(246,230,194,.95), rgba(228,209,169,.92));
  border: 2px solid rgba(61,39,18,.5); color: var(--ink);
  font-family: inherit; cursor: pointer;
}
.act-btn:hover { border-color: var(--gold); }
.act-btn .ai { font-size: 17px; flex: 0 0 auto; }
.act-btn .al { flex: 1 1 auto; min-width: 0; }
.act-btn .al b { display: block; font-size: 13px; font-weight: 700; color: var(--wood-dark); }
.act-btn .al small { display: block; font-size: 10.5px; color: var(--ink-dim); line-height: 1.35; }
.act-btn .ar { flex: 0 0 auto; font-size: 10px; font-weight: 700; color: var(--ink-dim); text-align: right; }
.act-btn .ar.hot { color: var(--seal-red); }
.act-btn.dim { opacity: .68; }
.pp-more { margin-top: 7px; }
.pp-more summary { font-size: 11.5px; color: #e8d6b3; cursor: pointer; padding: 5px 2px; }
.pp-grid { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 5px; }
.pp-grid .act-mini {
  border: 1px solid rgba(244,231,205,.3); background: rgba(246,230,194,.86);
  color: var(--ink); border-radius: 9px; padding: 7px 10px; min-height: 36px;
  font-family: inherit; font-size: 11.5px; font-weight: 600; cursor: pointer;
}
.pp-verdict {
  margin-top: 7px; padding: 7px 10px; border-radius: 10px; font-size: 12px; line-height: 1.5;
  background: rgba(20,14,7,.5); border: 1px solid rgba(244,231,205,.24);
}
.pp-verdict.ok { border-color: rgba(111,174,74,.85); color: #ddf1c5; }
.pp-verdict.no { border-color: rgba(208,96,76,.9); color: #ffd0c5; }
.pp-verdict.sv { border-color: rgba(226,170,80,.9); color: #ffe2b0; }

/* ---- モードのトースト（置けない理由・断り文句） ---- */
#mode-toast {
  /* ★下端は「操作盤」で埋まっている。ここに出すと確定ボタンを自分で隠してしまうので、
     HUDの下（世界の上端）に出す。押したい物の上には絶対に被せない。 */
  position: fixed; z-index: 60;
  left: 50%; transform: translate(-50%, -8px);
  top: calc(max(8px, env(safe-area-inset-top)) + 96px);
  max-width: min(46ch, calc(100% - 28px));
  padding: 8px 15px; border-radius: 999px;
  background: rgba(24,16,8,.9);
  border: 1px solid rgba(244,231,205,.35);
  color: #f7ead0; font-size: 12.5px; font-weight: 600; text-align: center;
  box-shadow: 0 6px 18px rgba(0,0,0,.5);
  opacity: 0; pointer-events: none;
  transition: opacity .22s ease, transform .22s ease;
}
#mode-toast.show { opacity: 1; transform: translate(-50%, 0); }
@media (max-width: 560px) { #mode-toast { top: calc(max(8px, env(safe-area-inset-top)) + 100px); } }
#mode-toast.bad { border-color: rgba(224,120,100,.95); color: #ffd6cc; }
#mode-toast.good { border-color: rgba(151,199,96,.9); color: #e2f3cd; }

/* ---- 狭い画面（390x844）---- */
@media (max-width: 560px) {
  .mode-btn { min-width: 68px; padding: 4px 8px; font-size: 11.5px; }
  #mode-dock { width: calc(100% - 12px); max-height: min(44vh, 330px); padding: 8px 8px 9px; }
  .bcard { width: 106px; }
  .pp-bars { grid-template-columns: repeat(2, minmax(0,1fr)); }
}
@media (max-width: 340px) {
  .mode-btn { min-width: 58px; padding: 4px 6px; }
  .mode-btn span { font-size: 11px; }
}
@media (prefers-reduced-motion: reduce) {
  .bcard, .mode-btn, #mode-toast { transition: none; }
}
