:root {
  --bg: #f4efe6;
  --surface: #fffdf8;
  --surface-2: #efe8db;
  --ink: #1f1b16;
  --muted: #74695c;
  --line: #e2d8c8;
  --accent: #e0482a;
  --accent-ink: #fff;
  --good: #1f8a52;
  --bad: #c0392b;
  --big: #3b2fa8;
  --health: #e25563;
  --happy: #f0a500;
  --smarts: #3a7bd5;
  --looks: #c35bd6;
  --r-n: #8a8f98;
  --r-r: #2f80ed;
  --r-sr: #8e44ec;
  --r-ssr: #e2a400;
  --shadow: 0 6px 24px rgba(60, 40, 10, .10);
  --radius: 16px;
  --font: "Twemoji Country Flags", "M PLUS Rounded 1c", "Hiragino Maru Gothic ProN", "Hiragino Sans", "Yu Gothic UI", "Meiryo", system-ui, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15130f; --surface: #1f1c17; --surface-2: #2a261f; --ink: #f2ece2; --muted: #a89c8c; --line: #3a342b;
    --accent: #ff6a4a; --good: #43c482; --bad: #ff6b5e; --big: #9d93ff; --shadow: 0 6px 24px rgba(0, 0, 0, .4);
  }
}
:root[data-theme="dark"] {
  --bg: #15130f; --surface: #1f1c17; --surface-2: #2a261f; --ink: #f2ece2; --muted: #a89c8c; --line: #3a342b;
  --accent: #ff6a4a; --good: #43c482; --bad: #ff6b5e; --big: #9d93ff; --shadow: 0 6px 24px rgba(0, 0, 0, .4);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--ink); font-family: var(--font);
  -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
button { font: inherit; color: inherit; }
#app { max-width: 560px; margin: 0 auto; height: 100%; position: relative; }
.screen { display: none; height: 100%; }
.screen.active { display: flex; flex-direction: column; }
.muted { color: var(--muted); }
[hidden] { display: none !important; }

/* ボタン */
.btn {
  appearance: none; border: 1.5px solid var(--line); background: var(--surface); border-radius: 999px;
  padding: 12px 20px; font-weight: 700; cursor: pointer; transition: transform .08s, background .2s; min-height: 46px;
}
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; box-shadow: 0 4px 0 rgba(0,0,0,.18); }
.btn.primary:active { box-shadow: 0 1px 0 rgba(0,0,0,.18); transform: translateY(3px); }
.btn.ghost { background: transparent; }
.btn.big { font-size: 1.15rem; padding: 16px 24px; }
.btn:disabled { opacity: .45; cursor: not-allowed; }

/* タイトル */
.title-wrap { margin: auto; padding: 32px 16px; text-align: center; width: 100%; }
.globe { font-size: 84px; animation: spin 12s linear infinite; display: inline-block; filter: drop-shadow(0 8px 16px rgba(0,0,0,.15)); }
@keyframes spin { 50% { transform: rotate(12deg) scale(1.04); } }
.logo { font-size: clamp(2.6rem, 12vw, 3.6rem); margin: 8px 0 4px; font-weight: 800; letter-spacing: .02em; }
.logo span { color: var(--accent); }
.tagline { color: var(--muted); margin: 0 0 28px; font-weight: 700; }
.title-btns { display: grid; gap: 10px; max-width: 320px; margin: 0 auto; }
.fine { font-size: .78rem; color: var(--muted); margin-top: 24px; line-height: 1.6; }

/* ガチャ */
.gacha-wrap { margin: auto; padding: 24px 16px; width: 100%; text-align: center; }
.gacha-step { font-weight: 800; letter-spacing: .12em; color: var(--muted); font-size: .85rem; margin: 0 0 14px; }
.slot {
  background: var(--surface); border: 2px solid var(--line); border-radius: 24px; padding: 26px 16px 18px; margin: 0 auto 18px;
  max-width: 360px; box-shadow: var(--shadow); position: relative; overflow: hidden;
}
.slot-flag { font-size: 96px; line-height: 1.1; }
.slot-name { font-size: 1.5rem; font-weight: 800; margin-top: 6px; min-height: 1.6em; }
.slot.spinning .slot-flag { filter: blur(1px); }
.slot.r-UR { border-color: transparent; background: linear-gradient(var(--surface), var(--surface)) padding-box, linear-gradient(120deg, #ff4d4d, #ffb84d, #f9f871, #4dff88, #4dc3ff, #b84dff) border-box; animation: glow 2s ease-in-out infinite; }
.slot.r-SSR { border-color: var(--r-ssr); box-shadow: 0 0 0 4px rgba(226,164,0,.2), var(--shadow); }
.slot.r-SR { border-color: var(--r-sr); box-shadow: 0 0 0 4px rgba(142,68,236,.18), var(--shadow); }
.slot.r-R { border-color: var(--r-r); }
@keyframes glow { 50% { box-shadow: 0 0 32px rgba(255,200,80,.6); } }
.pop { animation: pop .5s cubic-bezier(.2, 1.6, .4, 1); }
@keyframes pop { from { transform: scale(.6); opacity: 0; } }
.rarity { display: inline-block; font-weight: 800; padding: 3px 12px; border-radius: 999px; color: #fff; font-size: .9rem; letter-spacing: .06em; }
.rarity.N { background: var(--r-n); } .rarity.R { background: var(--r-r); } .rarity.SR { background: var(--r-sr); } .rarity.SSR { background: var(--r-ssr); }
.rarity.UR { background: linear-gradient(90deg, #ff4d4d, #ffb84d, #4dc3ff, #b84dff); }
.facts { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 14px auto; max-width: 360px; text-align: left; }
.fact { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 8px 12px; }
.fact b { display: block; font-size: 1.05rem; }
.fact small { color: var(--muted); font-size: .72rem; }
.prob { color: var(--muted); font-size: .9rem; margin: 8px 0 0; }
.gacha-btns { display: grid; gap: 10px; max-width: 320px; margin: 16px auto 0; }
.fam-card { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 14px; max-width: 360px; margin: 10px auto; text-align: left; line-height: 1.7; }
.name-edit { display: flex; gap: 8px; align-items: center; margin-top: 8px; }
.name-edit input { flex: 1; min-width: 0; font: inherit; padding: 8px 12px; border-radius: 10px; border: 1.5px solid var(--line); background: var(--bg); color: var(--ink); }

/* HUD */
#s-game { background: var(--bg); }
.hud { background: var(--surface); border-bottom: 1px solid var(--line); padding: 10px 16px 10px; padding-top: max(10px, env(safe-area-inset-top)); flex: none; }
.hud-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.who { display: flex; align-items: center; gap: 10px; min-width: 0; }
.who-flag { font-size: 34px; }
.who-name { font-weight: 800; font-size: 1.05rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.who-sub { font-size: .75rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 56vw; }
.age { text-align: right; font-weight: 800; font-size: 2rem; line-height: 1; flex: none; }
.age small { font-size: .9rem; margin-left: 2px; }
.age .year { font-size: .72rem; color: var(--muted); font-weight: 700; margin-top: 2px; }
.money-row { display: flex; justify-content: space-between; gap: 8px; margin: 8px 0 6px; font-size: .88rem; flex-wrap: wrap; }
.bars { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 14px; }
.bar { font-size: .72rem; font-weight: 700; }
.bar-top { display: flex; justify-content: space-between; }
.bar-track { height: 7px; background: var(--surface-2); border-radius: 99px; overflow: hidden; margin-top: 2px; }
.bar-fill { height: 100%; border-radius: 99px; transition: width .5s ease; }
.delta { font-size: .7rem; margin-left: 4px; }
.delta.up { color: var(--good); } .delta.down { color: var(--bad); }

/* パネル */
.panel-wrap { flex: 1; overflow: hidden; position: relative; }
.panel { display: none; height: 100%; overflow-y: auto; padding: 12px 16px 150px; -webkit-overflow-scrolling: touch; }
.panel.active { display: block; }
.log { display: flex; flex-direction: column; gap: 2px; }
.yr { margin-top: 12px; }
.yr-h { font-weight: 800; font-size: .82rem; color: var(--muted); display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.yr-h::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.ev { padding: 6px 10px; border-radius: 10px; line-height: 1.55; font-size: .93rem; border-left: 3px solid transparent; }
.ev.g { border-left-color: var(--good); }
.ev.b { border-left-color: var(--bad); }
.ev.s { color: var(--muted); font-size: .86rem; }
.ev.big { background: var(--surface); font-weight: 700; border-left-color: var(--big); box-shadow: 0 1px 0 var(--line); }
.ev.death { background: #1f1b16; color: #fff; font-weight: 800; text-align: center; border-radius: 12px; padding: 12px; }
.ev.fresh { animation: fadein .5s ease both; }
@keyframes fadein { from { opacity: 0; transform: translateY(6px); } }

.sec-h { font-weight: 800; font-size: .85rem; color: var(--muted); margin: 16px 0 8px; letter-spacing: .04em; }
.sec-h:first-child { margin-top: 4px; }
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.act {
  appearance: none; text-align: left; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 10px 12px;
  cursor: pointer; min-height: 60px; display: flex; flex-direction: column; justify-content: center; gap: 2px; transition: transform .08s;
}
.act:active { transform: scale(.97); }
.act b { font-size: .92rem; }
.act small { color: var(--muted); font-size: .72rem; line-height: 1.35; }
.act:disabled { opacity: .45; cursor: not-allowed; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 8px; }
.card .row { display: flex; justify-content: space-between; gap: 8px; font-size: .9rem; padding: 3px 0; }
.card .row span:first-child { color: var(--muted); }
.person { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.person .pn { font-weight: 800; }
.person .pr { font-size: .75rem; color: var(--muted); }
.relbar { height: 5px; background: var(--surface-2); border-radius: 99px; overflow: hidden; margin-top: 6px; }
.relbar div { height: 100%; background: var(--good); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.chip { appearance: none; border: 1px solid var(--line); background: var(--bg); border-radius: 999px; padding: 6px 12px; font-size: .8rem; font-weight: 700; cursor: pointer; }
.chip:disabled { opacity: .4; cursor: not-allowed; }
.dead { opacity: .55; }
.toggle { display: flex; align-items: center; gap: 8px; font-size: .85rem; margin: 6px 0 10px; }
.mig { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.mig .f { font-size: 1.5rem; }
.mig .info { flex: 1; min-width: 0; }
.mig .info b { display: block; font-size: .92rem; }
.mig .info small { color: var(--muted); font-size: .72rem; }
.pbar { width: 64px; height: 6px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.pbar div { height: 100%; background: var(--accent); }

/* 年を重ねるボタン・タブ */
.age-dock { position: absolute; left: 0; right: 0; bottom: calc(64px + env(safe-area-inset-bottom)); padding: 10px 16px; pointer-events: none;
  background: linear-gradient(transparent, var(--bg) 40%); }
.age-btn { width: 100%; font-size: 1.1rem; min-height: 54px; pointer-events: auto; }
.tabs { position: absolute; left: 0; right: 0; bottom: 0; display: grid; grid-template-columns: repeat(6, 1fr); background: var(--surface);
  border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
.tabs button { appearance: none; border: 0; background: none; padding: 7px 0 8px; font-size: .64rem; font-weight: 700; color: var(--muted); cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 1px; min-height: 64px; justify-content: center; }
.tabs button i { font-style: normal; font-size: 1.25rem; filter: grayscale(.7); }
.tabs button.on { color: var(--accent); }
.tabs button.on i { filter: none; }
.tabs button .dot { width: 6px; height: 6px; background: var(--accent); border-radius: 50%; }

/* モーダル */
.modal { position: fixed; inset: 0; background: rgba(20, 14, 6, .55); display: flex; align-items: flex-end; justify-content: center; z-index: 50; animation: fade .2s; }
@keyframes fade { from { opacity: 0; } }
.sheet { background: var(--surface); width: 100%; max-width: 560px; border-radius: 24px 24px 0 0; padding: 20px 16px calc(20px + env(safe-area-inset-bottom)); animation: up .28s cubic-bezier(.2, .9, .3, 1); max-height: 88vh; overflow-y: auto; }
@keyframes up { from { transform: translateY(40px); opacity: .4; } }
.sheet-kicker { font-size: .75rem; font-weight: 800; color: var(--accent); letter-spacing: .1em; }
.sheet h2 { margin: 4px 0 8px; font-size: 1.3rem; }
.sheet p { margin: 0 0 16px; line-height: 1.7; white-space: pre-line; }
.opts { display: grid; gap: 8px; }
.opt { appearance: none; text-align: left; background: var(--bg); border: 1.5px solid var(--line); border-radius: 14px; padding: 12px 14px; cursor: pointer; font-weight: 700; }
.opt small { display: block; color: var(--muted); font-weight: 400; font-size: .78rem; margin-top: 2px; }
.opt:active { border-color: var(--accent); }
.toast { position: fixed; left: 50%; top: 16px; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 10px 18px; border-radius: 999px; font-weight: 700; font-size: .88rem; z-index: 60; animation: fade .2s; max-width: 90vw; text-align: center; }

/* エンディング */
#s-end { overflow-y: auto; }
.end-wrap { padding: 28px 16px 48px; text-align: center; }
.tomb { font-size: 64px; }
.end-name { font-size: 1.6rem; font-weight: 800; margin: 6px 0 2px; }
.end-sub { color: var(--muted); margin: 0 0 14px; }
.epitaph { font-style: italic; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 12px; margin: 0 auto 16px; max-width: 420px; line-height: 1.7; }
.rank { font-size: 4rem; font-weight: 800; line-height: 1; color: var(--accent); }
.score { color: var(--muted); font-weight: 700; margin-bottom: 18px; }
.end-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; text-align: left; margin-bottom: 16px; }
.achs { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; margin: 8px 0 20px; }
.ach { background: var(--surface); border: 1px solid var(--line); border-radius: 999px; padding: 5px 12px; font-size: .8rem; font-weight: 700; }
.end-btns { display: grid; gap: 10px; max-width: 340px; margin: 0 auto; }
.grave { display: flex; gap: 10px; align-items: center; text-align: left; }
.grave .f { font-size: 1.6rem; }
.compare { font-size: .85rem; color: var(--muted); margin: -8px 0 16px; }

@media (min-width: 561px) {
  #app { border-left: 1px solid var(--line); border-right: 1px solid var(--line); }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
