:root {
  --bg: #f3ede0;
  --card: #fffdf7;
  --card-2: #f8f2e4;
  --ink: #2c2a26;
  --muted: #7b7468;
  --line: #e1d8c3;
  --accent: #8a5a2b;
  --accent-ink: #fff8ec;
  --good: #3f7a4f;
  --bad: #b4452f;
  --gold: #a87a1c;
  --body: #b5573a;
  --brain: #3d6e9b;
  --spirit: #5c8a4e;
  --village: #5a78d0;
  --shadow: 0 1px 2px rgba(60, 40, 10, .08), 0 4px 14px rgba(60, 40, 10, .06);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1c1a17;
    --card: #26231f;
    --card-2: #2d2a25;
    --ink: #ece6d8;
    --muted: #a39b8b;
    --line: #3a362f;
    --accent: #d09a5b;
    --accent-ink: #1c1a17;
    --good: #7fc08f;
    --bad: #e58c78;
    --gold: #d9aa4a;
    --body: #d9795b;
    --brain: #6aa3d4;
    --spirit: #86b878;
    --village: #93aaf0;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: "Hiragino Sans", "Noto Sans JP", "Yu Gothic", "Meiryo", sans-serif;
  font-size: 15px; line-height: 1.65;
}
button { font: inherit; color: inherit; cursor: pointer; }
h1, h2, h3 { margin: 0; line-height: 1.35; }
h2 { font-size: 1.05rem; }
h3 { font-size: .95rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.hidden { display: none !important; }

/* ---- レイアウト ---- */
.wrap { max-width: 1120px; margin: 0 auto; padding: 0 16px 48px; }
.top { padding: 14px 0 6px; display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 16px; }
.top h1 { font-size: 1.25rem; letter-spacing: .06em; }
.top .vname { color: var(--muted); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0 10px; }
.chip { background: var(--card); border: 1px solid var(--line); border-radius: 999px; padding: 2px 12px; font-size: .85rem; white-space: nowrap; }
.chip b { font-weight: 700; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; overflow-x: auto; }
.tab { background: none; border: 0; padding: 8px 14px; border-bottom: 3px solid transparent; color: var(--muted); white-space: nowrap; }
.tab[aria-current="true"] { color: var(--ink); border-bottom-color: var(--accent); font-weight: 700; }
.grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr)); }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; box-shadow: var(--shadow); }
.card > h2, .card > h3 { margin-bottom: 8px; }
.stack > * + * { margin-top: 12px; }

/* ---- ボタン ---- */
.btn { background: var(--card-2); border: 1px solid var(--line); border-radius: 8px; padding: 6px 14px; }
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { color: var(--bad); }
.btn.sm { padding: 2px 10px; font-size: .85rem; }
.btn:focus-visible, .tab:focus-visible, .hcard:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.actions { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.act { text-align: left; padding: 12px 14px; border-radius: 10px; border: 1px solid var(--line); background: var(--card-2); }
.act:hover:not(:disabled) { border-color: var(--accent); background: var(--card); }
.act:disabled { opacity: .45; cursor: not-allowed; }
.act b { display: block; font-size: 1.02rem; }
.act span { font-size: .8rem; color: var(--muted); }
.free { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; padding-top: 12px; border-top: 1px dashed var(--line); }

/* ---- 世帯カード ---- */
.hcard { text-align: left; width: 100%; background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; box-shadow: var(--shadow); }
.hcard:hover { border-color: var(--accent); }
.hcard .hn { font-weight: 700; font-size: 1.02rem; }
.hcard .row { display: flex; justify-content: space-between; gap: 8px; font-size: .88rem; }
.badge { display: inline-block; font-size: .72rem; padding: 0 8px; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); margin-left: 4px; vertical-align: 1px; }
.badge.new { color: var(--good); border-color: var(--good); }
.badge.wait { color: var(--gold); border-color: var(--gold); }

/* ---- 進捗バー ---- */
.meter { height: 8px; background: var(--card-2); border: 1px solid var(--line); border-radius: 999px; overflow: hidden; }
.meter > i { display: block; height: 100%; background: var(--accent); }

/* ---- 能力バー ---- */
.stats { display: grid; gap: 8px; }
.statgroup .statcat { font-size: .75rem; color: var(--muted); letter-spacing: .1em; }
.bar { display: grid; grid-template-columns: 5.2em 1fr 2.2em; align-items: center; gap: 8px; font-size: .86rem; }
.bt { height: 8px; background: var(--card-2); border: 1px solid var(--line); border-radius: 999px; overflow: hidden; display: block; }
.bf { display: block; height: 100%; background: var(--muted); }
.c-body .bf { background: var(--body); }
.c-brain .bf { background: var(--brain); }
.c-spirit .bf { background: var(--spirit); }
.bv { text-align: right; font-variant-numeric: tabular-nums; }

/* ---- プレイ画面 ---- */
.play { display: grid; gap: 14px; grid-template-columns: minmax(0, 1fr); }
@media (min-width: 860px) { .play { grid-template-columns: 340px minmax(0, 1fr); } }
.who { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.who .nm { font-size: 1.15rem; font-weight: 700; }
.money { font-variant-numeric: tabular-nums; font-weight: 700; }
.money.neg { color: var(--bad); }
/* 1年進めた直後: 資金の増減がふわっと浮かんで消える */
dd.money { position: relative; }
.money-fx { position: absolute; left: 0; top: -2px; margin-left: 6.5em; font-size: .9rem; white-space: nowrap; pointer-events: none; animation: vg-money-fx 1.8s ease-out forwards; }
.money-fx.up { color: var(--good); }
.money-fx.down { color: var(--bad); }
@keyframes vg-money-fx { 0% { opacity: 0; transform: translateY(6px); } 15% { opacity: 1; transform: translateY(0); } 70% { opacity: 1; } 100% { opacity: 0; transform: translateY(-14px); } }
dd.money.pulse { animation: vg-pulse .5s ease-out; }
@keyframes vg-pulse { 0% { transform: scale(1); } 40% { transform: scale(1.08); } 100% { transform: scale(1); } }
/* 1年進めた直後: 世帯の絵の家族がぴょんぴょん跳ねて、音符が浮かぶ */
.scene-box.home .hop { animation: vg-hop .45s ease-out 2; }
@keyframes vg-hop { 0%, 100% { transform: translateY(0); } 45% { transform: translateY(-12px); } }
.scene-box.home .cheer-note { opacity: 0; animation: vg-note 1.4s ease-out forwards; }
@keyframes vg-note { 0% { opacity: 0; transform: translateY(4px); } 25% { opacity: 1; } 100% { opacity: 0; transform: translateY(-14px); } }
@media (prefers-reduced-motion: reduce) {
  .money-fx, dd.money.pulse, .scene-box.home .hop { animation: none; }
  .scene-box.home .cheer-note { display: none; }
}
.kv { display: grid; grid-template-columns: 6em 1fr; gap: 2px 8px; font-size: .88rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.kid { padding: 8px 0; border-top: 1px dashed var(--line); }
.kid:first-child { border-top: 0; }
.tag { font-size: .75rem; padding: 0 8px; border-radius: 6px; background: var(--card-2); border: 1px solid var(--line); margin-right: 4px; }
.tag.heir { color: var(--gold); border-color: var(--gold); }

/* ---- ログ ---- */
.log { max-height: 460px; overflow: auto; font-size: .92rem; }
.log .ln { padding: 3px 0 3px 10px; border-left: 3px solid var(--line); margin: 2px 0; }
.log .ln .yr { color: var(--muted); font-size: .78rem; margin-right: 8px; font-variant-numeric: tabular-nums; }
.log .k-money { color: var(--muted); font-size: .84rem; }
.log .k-good { border-left-color: var(--good); }
.log .k-bad { border-left-color: var(--bad); }
.log .k-great { border-left-color: var(--gold); font-weight: 700; }
.log .k-story { border-left-color: var(--accent); }
.log .fresh { background: color-mix(in srgb, var(--accent) 10%, transparent); }

/* ---- テーブル / 表 ---- */
table { border-collapse: collapse; width: 100%; font-size: .9rem; }
th, td { padding: 4px 8px; text-align: left; border-bottom: 1px solid var(--line); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr.me td { background: color-mix(in srgb, var(--accent) 14%, transparent); font-weight: 700; }
.sample { color: var(--muted); }

/* ---- モーダル / トースト ---- */
#modal-root:empty { display: none; }
.overlay { position: fixed; inset: 0; background: rgba(20, 14, 6, .55); display: flex; align-items: flex-start; justify-content: center; padding: 4vh 12px; overflow: auto; z-index: 10; }
.modal { background: var(--card); border: 1px solid var(--line); border-radius: 12px; width: min(560px, 100%); padding: 18px 20px; box-shadow: 0 10px 40px rgba(0, 0, 0, .35); }
.modal.wide { width: min(760px, 100%); }
.modal h2 { margin-bottom: 10px; font-size: 1.1rem; }
.modal .foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }
.opt { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; background: var(--card-2); display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; align-items: center; }
.opt + .opt { margin-top: 8px; }
.opt .desc { grid-column: 1 / -1; font-size: .84rem; color: var(--muted); }
.opt.off { opacity: .6; }
#toast-root { position: fixed; left: 0; right: 0; bottom: 18px; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; z-index: 20; padding: 0 12px; }
.toast { background: var(--ink); color: var(--bg); padding: 8px 16px; border-radius: 10px; font-size: .9rem; max-width: 520px; box-shadow: var(--shadow); }
.toast.great { background: var(--gold); color: #fff; }
input[type="text"], input[type="number"], textarea { font: inherit; color: inherit; background: var(--card-2); border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; width: 100%; }
textarea { min-height: 90px; font-size: .8rem; }
.row-gap { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.pill-list { display: flex; flex-wrap: wrap; gap: 6px; }
.note { font-size: .84rem; color: var(--muted); border-left: 3px solid var(--line); padding-left: 10px; }
@media (max-width: 480px) { .bar { grid-template-columns: 4.6em 1fr 2em; } body { font-size: 14.5px; } }

/* ---- 村の絵 ---- */
.scene-box { border-radius: 12px; overflow: hidden; background: #dcebb6; aspect-ratio: 5 / 3; width: 100%; }
.scene-box svg { display: block; width: 100%; height: 100%; }

/* ---- ログイン ---- */
.auth { max-width: 440px; margin: 24px auto; }
.auth form { display: grid; gap: 10px; }
.auth label { display: grid; gap: 4px; font-size: .88rem; color: var(--muted); }
.auth .err { color: var(--bad); font-size: .9rem; min-height: 1.4em; }

/* ---- セーブ ---- */
.savebar { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; }
.savenote { font-size: .72rem; color: var(--muted); }

/* ---- 別の世帯による村の出来事 ---- */
.log .k-village { border-left-color: var(--village); background: color-mix(in srgb, var(--village) 9%, transparent); }
.log .k-village .src { display: inline-block; font-size: .72rem; color: var(--village); border: 1px solid var(--village); border-radius: 999px; padding: 0 7px; margin-right: 6px; }
.log .k-village.fresh { background: color-mix(in srgb, var(--village) 18%, transparent); }
.toast.village { background: var(--village); color: #fff; }

.btn.off { color: var(--muted); border-style: dashed; }

/* 「自分を高める」の右上の小さな変更ボタン */
.actwrap { position: relative; display: grid; }
.actwrap .act { padding-right: 52px; }
.actwrap .actchange { position: absolute; top: 6px; right: 6px; font-size: .72rem; padding: 0 8px; }

/* ---- フッター(規約へのリンク) ---- */
.footer { display: flex; flex-wrap: wrap; gap: 4px 16px; margin-top: 28px; padding-top: 12px; border-top: 1px solid var(--line); }
.footer a, .auth a, .card a { color: var(--accent); }

.tag.remote { color: var(--village); border-color: var(--village); }
.policy { margin: 0 0 8px; }
.tag.now { color: var(--good); border-color: var(--good); font-weight: 700; margin-left: 6px; }

/* ---- 世帯の絵 ---- */
.scene-box.home { aspect-ratio: 1000 / 188; }

/* ---- 家系図 ---- */
/* 家系図: 上から下へ枝分かれする木 */
.ftree { overflow-x: auto; padding: 4px 0 8px; }
.ftree ul { position: relative; display: flex; justify-content: center; margin: 0; padding: 16px 0 0; }
.ftree > ul { width: max-content; min-width: 100%; padding-top: 0; }
.ftree li { position: relative; list-style: none; display: flex; flex-direction: column; align-items: center; padding: 16px 4px 0; }
.ftree > ul > li { padding-top: 0; }
/* 兄弟をつなぐ横線と、そこから各自へおりる線 */
.ftree li::before, .ftree li::after { content: ''; position: absolute; top: 0; right: 50%; width: 50%; height: 16px; border-top: 2px solid var(--line); }
.ftree li::after { right: auto; left: 50%; border-left: 2px solid var(--line); }
.ftree li:only-child::before, .ftree li:only-child::after, .ftree > ul > li::before, .ftree > ul > li::after { display: none; }
.ftree li:only-child { padding-top: 0; } /* ひとりっ子は、夫婦からおりる線にそのままつながる */
.ftree li:first-child::before, .ftree li:last-child::after { border: 0 none; }
.ftree li:last-child::before { border-right: 2px solid var(--line); border-radius: 0 6px 0 0; }
.ftree li:first-child::after { border-radius: 6px 0 0 0; }
/* 夫婦から子供たちへおりる線 */
.ftree ul ul::before { content: ''; position: absolute; top: 0; left: 50%; height: 16px; border-left: 2px solid var(--line); }
.fnode { position: relative; display: inline-flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 10px; border: 2px solid var(--line); border-radius: 10px; background: var(--card); text-align: center; font-size: .9rem; max-width: 220px; }
.fnode.couple { border-color: var(--accent); background: var(--card-2); }
.fnode.couple.current { box-shadow: 0 0 0 3px rgba(212, 140, 90, .25); }
.fnode.couple.current > div:first-child b { color: var(--accent); }
/* 夫婦: 当主の枠 ═ 配偶者の枠。左の空きで当主の枠を真ん中にし、子供への線は ═ の真ん中から下ろす */
.ftree .fpair { display: flex; align-items: center; }
.ftree .fpair.wed .fnode { width: 150px; box-sizing: border-box; }
.ftree .fspace { width: 150px; flex: none; }
.ftree .fwed { width: 22px; flex: none; border-top: 4px double var(--accent); }
.ftree .fspace-line { visibility: hidden; }
.fnode.spouse { border-color: var(--accent); background: var(--card-2); }
.fnode.spouse.remote { border-color: var(--village); }
.ftree li.fcouple > ul { padding-left: 172px; } /* 子供たちを、═ の真ん中の下に寄せる(枠150+線22) */
.ftree li.fcouple > ul::before { left: calc(50% + 86px); }
/* 跡継ぎの枝が深くて左に空白ができるとき、枝を左へ寄せる(js/ftree.js)。横線は、寄せたぶんだけ左と右にのばす */
.ftree li.fshift::before { width: auto; left: var(--bl); }
.ftree li.fshift.fext::after { border-top: 2px solid var(--line); border-radius: 0 6px 0 0; width: var(--ext); }
.fnode .tag { margin: 0 4px 0 0; }
/* サウンドの設定 */
.soundrow { display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.soundrow input[type=range] { flex: 1; max-width: 240px; accent-color: var(--accent); }
.soundrow input[type=checkbox] { accent-color: var(--accent); }
.fnone { margin-top: 6px; }
.tag.fate.heir { color: var(--gold); border-color: var(--gold); }
.tag.fate.remote { color: var(--village); border-color: var(--village); }
.tag.fate.local { color: var(--good); border-color: var(--good); }

/* 村の長老の案内(チュートリアル) */
#guide-root { position: fixed; left: 0; right: 0; bottom: 12px; display: flex; justify-content: center; padding: 0 12px; z-index: 15; pointer-events: none; }
.guide { position: relative; z-index: 1; pointer-events: auto; display: flex; gap: 12px; align-items: flex-start; width: 100%; max-width: 560px; background: var(--card); color: var(--ink); border: 2px solid var(--accent); border-radius: 14px; padding: 10px 12px; box-shadow: 0 6px 24px rgba(40, 25, 5, .28); animation: guide-in .35s ease-out; }
.guide .gface { flex: 0 0 64px; height: 64px; border-radius: 50%; background: var(--card-2); border: 1px solid var(--line); overflow: hidden; display: flex; align-items: center; justify-content: center; }
.guide .gface svg { width: 64px; height: 64px; }
.guide .gbody { flex: 1; min-width: 0; }
.guide .gname { font-weight: 700; color: var(--accent); font-size: 14px; }
.guide .gsay { margin: 4px 0 8px; line-height: 1.65; font-size: 15px; }
.guide .gfoot { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
.tut-hl { position: relative; z-index: 1; outline: 3px solid var(--gold); outline-offset: 3px; border-radius: 10px; animation: tut-glow 1.4s ease-in-out infinite; }
body:has(#guide-root .guide) #app, body:has(#guide-root .guide) .overlay { padding-bottom: 210px; }
body:has(#guide-root .guide) #toast-root { bottom: auto; top: 12px; } /* 知らせが吹き出しに重ならないように、案内中は画面の上に出す */
@keyframes guide-in { from { transform: translateY(16px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes tut-glow { 0%, 100% { box-shadow: 0 0 0 0 rgba(217, 170, 74, .0); } 50% { box-shadow: 0 0 0 8px rgba(217, 170, 74, .35); } }
@media (prefers-reduced-motion: reduce) { .guide, .tut-hl { animation: none; } }
@media (max-width: 520px) { .guide .gface { flex-basis: 48px; height: 48px; } .guide .gface svg { width: 48px; height: 48px; } .guide .gsay { font-size: 14px; } }
/* 案内中は、光っているところ以外を薄い灰色でおおい、押せないようにする */
.tut-dim { position: fixed; inset: 0; pointer-events: none; }
.tut-dim .hole { position: fixed; border-radius: 14px; box-shadow: 0 0 0 200vmax rgba(40, 38, 34, .5); pointer-events: none; }
.tut-dim .lid { position: fixed; pointer-events: auto; }
.bar.withgain { grid-template-columns: 5.2em 1fr 2.2em 2.4em; }
.bgain { color: var(--good); font-weight: 700; font-variant-numeric: tabular-nums; animation: guide-in .5s ease-out; }
/* 広告と画面の下の欄(#app の外に、1回だけ置く) */
.wrap.foot-wrap { padding-bottom: 0; }
#footer-root .wrap { padding-bottom: 32px; }
#footer-root .footer { margin-top: 12px; }
.adbox { margin: 8px 0 0; padding: 6px 8px 8px; border: 1px dashed var(--line); border-radius: 10px; background: var(--card-2); min-height: 60px; }
.adlabel { font-size: 11px; color: var(--muted); margin-bottom: 4px; }
