/* 逆轉人生 — 樣式：暖色紙張、夕陽橙、手機直向 */
:root {
  color-scheme: light;
  --paper: #f7efe2; --paper2: #fffaf2; --ink: #3b2c22; --ink2: #7a6656; --line: #e6d6c0;
  --sun: #ee8a3c; --sun2: #f6b067; --teal: #3f8f8a; --red: #c8483b; --green: #3d8a4f;
  --hp: #e0605a; --joy: #f0a73a; --iq: #4a8fd6; --cha: #b46ad6; --sk: #3f8f8a;
  --r: 14px; --shadow: 0 6px 20px rgba(80, 50, 20, .14);
  --safe-b: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: #e9dcc7; color: var(--ink); font: 15px/1.55 "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", "Heiti TC", sans-serif; }
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }
button:disabled { cursor: default; }
#app { position: relative; max-width: 480px; height: 100%; margin: 0 auto; overflow: hidden; overflow: clip; background: var(--paper); box-shadow: 0 0 40px rgba(0, 0, 0, .15); }
.screen { position: absolute; inset: 0; display: none; flex-direction: column; }
.screen.on { display: flex; }
.paper { background: var(--paper); }
h4 { margin: 18px 2px 8px; font-size: 13px; color: var(--ink2); letter-spacing: .08em; }
.neg { color: var(--red) !important; } .pos { color: var(--green) !important; }
.mini { display: block; font-size: 12px; color: var(--ink2); margin: 4px 2px; }
.empty { color: var(--ink2); text-align: center; padding: 18px 8px; font-size: 14px; }
.note { background: #fff4e3; border: 1px dashed var(--sun2); border-radius: 12px; padding: 10px 12px; font-size: 13px; }
.warnbox { background: #fdecea; color: var(--red); border-radius: 10px; padding: 8px 12px; font-size: 13px; margin: 8px 0; }

/* ── 按鈕 ── */
.big, .ghost, .go { display: block; width: 100%; padding: 14px 16px; border-radius: 999px; font-weight: 700; font-size: 16px; margin-top: 10px; transition: transform .1s; }
.big, .go { background: linear-gradient(180deg, var(--sun2), var(--sun)); color: #fff; box-shadow: 0 4px 0 #c96b25, var(--shadow); }
.ghost { background: rgba(255, 255, 255, .82); color: var(--ink); border: 1.5px solid var(--line); }
.big:active, .go:active, .ghost:active { transform: translateY(2px); }

/* ── 標題 ── */
#title { background: #f4c48e; }
#title .key { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; object-position: center 70%; }
.t-head { position: relative; text-align: center; padding-top: 12vh; color: #fff; text-shadow: 0 2px 14px rgba(120, 60, 20, .55); }
.t-head h1 { margin: 0; font: 900 52px/1.1 "Noto Serif TC", "Songti TC", "PMingLiU", serif; letter-spacing: .12em; }
.t-head p { margin: 8px 0 0; font-size: 18px; letter-spacing: .5em; font-weight: 700; }
.t-foot { position: absolute; left: 0; right: 0; bottom: 0; padding: 60px 24px calc(28px + var(--safe-b)); background: linear-gradient(180deg, transparent, rgba(60, 35, 20, .55)); }
.snd { position: absolute; top: 14px; right: 14px; z-index: 2; padding: 6px 12px; border-radius: 999px; font-size: 13px; background: rgba(255, 255, 255, .78); color: var(--ink); box-shadow: 0 2px 8px rgba(0, 0, 0, .15); }
.t-note { color: #fff; text-align: center; font-size: 13px; margin: 12px 0 0; text-shadow: 0 1px 6px rgba(0, 0, 0, .5); }

/* ── 頁 ── */
.page-head { display: flex; align-items: center; gap: 8px; padding: 14px 14px 6px; }
.page-head h2 { margin: 0; font-size: 20px; }
.back { font-size: 28px; line-height: 1; width: 36px; height: 36px; border-radius: 50%; background: #fff; box-shadow: var(--shadow); }
.page-body { flex: 1; overflow-y: auto; padding: 8px 16px calc(24px + var(--safe-b)); }
.start { display: flex; gap: 12px; align-items: center; width: 100%; text-align: left; background: var(--paper2); border: 1.5px solid var(--line); border-radius: var(--r); padding: 12px; margin: 8px 0; box-shadow: var(--shadow); }
.start .s-ic { font-size: 30px; width: 44px; text-align: center; }
.start .s-tx { display: flex; flex-direction: column; } .start small { color: var(--ink2); font-size: 12.5px; }
.start.locked { opacity: .6; box-shadow: none; }
button.start:not(.locked):active { transform: scale(.98); }

/* ── HUD ── */
#hud { padding: 10px 12px 8px; background: linear-gradient(180deg, #fde3c3, var(--paper)); border-bottom: 1px solid var(--line); }
.hud-top { display: flex; align-items: center; gap: 10px; }
.hud-av { width: 58px; height: 58px; border-radius: 50%; object-fit: cover; border: 3px solid #fff; box-shadow: var(--shadow); background: #f3e9d8; }
.hud-id { flex: 1; min-width: 0; }
.hud-id b { font-size: 17px; margin-right: 6px; }
.age-chip { display: inline-block; background: var(--sun); color: #fff; font-weight: 700; font-size: 12px; padding: 1px 9px; border-radius: 99px; vertical-align: 2px; }
.hud-tag { font-size: 12.5px; color: var(--ink2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hud-money { text-align: right; font-size: 12px; line-height: 1.25; }
.hud-money div { margin: 1px 0; } .hud-money small { color: var(--ink2); margin-right: 4px; } .hud-money b { font-size: 14.5px; }
.bars { display: grid; grid-template-columns: 1fr 1fr; gap: 3px 14px; margin-top: 8px; }
.st { display: grid; grid-template-columns: 58px 1fr 24px; align-items: center; gap: 6px; font-size: 12px; }
.st em { font-style: normal; font-weight: 700; text-align: right; font-size: 12px; }
.bar { display: block; height: 7px; background: rgba(120, 90, 60, .14); border-radius: 9px; overflow: hidden; }
.bar i { display: block; height: 100%; border-radius: 9px; background: var(--sun); transition: width .5s; }
.bar.hp i { background: var(--hp); } .bar.joy i { background: var(--joy); } .bar.iq i { background: var(--iq); } .bar.cha i { background: var(--cha); }
.bar.sk i { background: var(--sk); } .bar.rel i { background: #e57f9a; }

/* ── 日誌 ── */
#feed { flex: 1; overflow-y: auto; padding: 10px 12px 18px; scroll-behavior: smooth; }
.yr { display: grid; grid-template-columns: 42px 1fr; gap: 8px; margin-bottom: 8px; }
.yr-age { font-weight: 800; color: var(--sun); text-align: center; font-size: 17px; line-height: 1; padding-top: 6px; }
.yr-age small { display: block; font-size: 10px; color: var(--ink2); font-weight: 400; margin-top: 2px; }
.yr-l { border-left: 2px solid var(--line); padding: 2px 0 4px 10px; font-size: 13.5px; }
.yr-l p { margin: 3px 0; }
.yr-l p.ev b { color: var(--teal); margin-right: 4px; }
.yr-l p.ev b::before { content: '【'; } .yr-l p.ev b::after { content: '】'; }
.yr.cur .yr-l { background: var(--paper2); border: 1.5px solid var(--sun2); border-radius: 12px; padding: 6px 10px; box-shadow: var(--shadow); }
.mute { color: var(--ink2); }

/* ── 底部 ── */
#dock { display: grid; grid-template-columns: 1fr 1fr 88px 1fr 1fr; align-items: end; padding: 4px 8px calc(8px + var(--safe-b)); background: var(--paper2); border-top: 1px solid var(--line); }
.tab { display: flex; flex-direction: column; align-items: center; font-size: 12px; color: var(--ink2); padding: 6px 0 2px; }
.tab i { font-style: normal; font-size: 22px; line-height: 1.2; }
.tab:active { transform: scale(.94); }
.next-wrap { display: flex; flex-direction: column; align-items: center; }
#btnNext { width: 72px; height: 72px; margin-top: -26px; border-radius: 50%; background: radial-gradient(circle at 35% 30%, #ffd29b, var(--sun) 70%); color: #fff; box-shadow: 0 5px 0 #c96b25, 0 8px 22px rgba(200, 100, 30, .45); border: 4px solid var(--paper2); display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1; }
#btnNext b { font-size: 24px; } #btnNext small { font-size: 12px; font-weight: 700; }
#btnNext:active { transform: translateY(3px); box-shadow: 0 2px 0 #c96b25; }
#btnNext.pop { animation: pop .35s; }
@keyframes pop { 50% { transform: scale(1.12); } }
.energy { display: flex; gap: 4px; height: 14px; align-items: center; margin-top: 4px; order: 2; }
.energy i { width: 9px; height: 9px; border-radius: 50%; background: var(--line); }
.energy i.on { background: var(--teal); box-shadow: 0 0 0 2px rgba(63, 143, 138, .2); }
.e-note { font-size: 10px; color: var(--ink2); white-space: nowrap; }

/* ── 抽屜 ── */
.sheet { position: absolute; inset: 0; background: rgba(50, 30, 15, .35); opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 20; }
.sheet.on { opacity: 1; pointer-events: auto; }
.sheet-card { position: absolute; left: 0; right: 0; bottom: 0; max-height: 86%; display: flex; flex-direction: column; background: var(--paper); border-radius: 20px 20px 0 0; transform: translateY(100%); transition: transform .25s ease-out; box-shadow: 0 -8px 30px rgba(0, 0, 0, .2); }
.sheet.on .sheet-card { transform: none; }
.sheet-head { display: flex; align-items: baseline; gap: 10px; padding: 14px 16px 8px; border-bottom: 1px solid var(--line); }
.sheet-head b { font-size: 18px; } .sheet-head span { font-size: 12.5px; color: var(--ink2); flex: 1; }
.sheet-head .x { font-size: 18px; width: 32px; height: 32px; border-radius: 50%; background: #fff; }
.sheet-body { overflow-y: auto; padding: 0 14px calc(22px + var(--safe-b)); }
.acts { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.act { display: flex; gap: 8px; align-items: center; text-align: left; background: var(--paper2); border: 1.5px solid var(--line); border-radius: 12px; padding: 10px; }
.act i { font-style: normal; font-size: 24px; }
.act span { display: flex; flex-direction: column; min-width: 0; } .act b { font-size: 14px; } .act small { font-size: 11.5px; color: var(--ink2); line-height: 1.35; }
.act:not(:disabled):active { transform: scale(.97); background: #fff; }
.act:disabled { opacity: .45; }

/* 朋友 */
.fam { display: flex; align-items: center; gap: 10px; background: var(--paper2); border-radius: 12px; padding: 8px 10px; margin: 6px 0; border: 1px solid var(--line); }
.fam img { width: 42px; height: 42px; border-radius: 50%; object-fit: cover; }
.fam span { display: flex; flex-direction: column; } .fam small { color: var(--ink2); font-size: 12px; }
.fam .fam-hp { margin-left: auto; flex-direction: row; align-items: center; gap: 6px; width: 110px; font-size: 12px; } .fam-hp .bar { flex: 1; }
.fam.off { opacity: .5; }
.friend { background: var(--paper2); border: 1.5px solid var(--line); border-radius: var(--r); padding: 10px; margin: 8px 0; box-shadow: var(--shadow); }
.friend.good { border-color: #9fd1a8; } .friend.bad { border-color: #eaa49b; } .friend.mid { border-color: #ecd08e; }
.f-top { display: flex; gap: 10px; align-items: center; }
.f-top img { width: 52px; height: 52px; border-radius: 50%; object-fit: cover; border: 2px solid #fff; box-shadow: var(--shadow); }
.f-id { flex: 1; min-width: 0; } .f-id small { display: block; color: var(--ink2); font-size: 11.5px; }
.tags span { display: inline-block; font-size: 11px; background: #f1e4d1; border-radius: 99px; padding: 0 7px; margin: 2px 3px 0 0; }
.f-rel { width: 80px; text-align: right; } .f-rel small { font-size: 11px; color: var(--ink2); }
.f-info { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; margin: 8px 0 6px; }
.f-info span { background: #fff; border-radius: 8px; text-align: center; font-size: 12.5px; font-weight: 700; padding: 3px 0; }
.f-info span small { display: block; font-weight: 400; font-size: 10.5px; color: var(--ink2); }
.f-info span.q { color: #c9b8a4; }
.f-btns { display: flex; gap: 5px; }
.f-btns button { flex: 1; background: #fff; border: 1px solid var(--line); border-radius: 9px; padding: 6px 0; font-size: 12.5px; }
.f-btns button.warn { flex: 0 0 38px; }
.f-btns button:disabled { opacity: .4; }
.f-btns button:not(:disabled):active { background: #fde3c3; }

/* 資產 */
.as-sum { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-top: 12px; }
.as-sum div, .end-grid div { background: var(--paper2); border-radius: 12px; padding: 8px; text-align: center; border: 1px solid var(--line); }
.as-sum small, .end-grid small { display: block; font-size: 11px; color: var(--ink2); }
.as-sum b { font-size: 15px; }
.row { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 2px 8px; background: var(--paper2); border-radius: 12px; padding: 9px 12px; margin: 6px 0; border: 1px solid var(--line); }
.row > span { font-size: 14px; } .row > b { font-size: 15px; }
.row.out > b { color: var(--red); }
.row .tb, .row .mini, .row .lock { flex-basis: 100%; }
.flow { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.flow .row { padding: 6px 9px; margin: 4px 0; } .flow .row > span { font-size: 12px; } .flow .row > b { font-size: 13px; color: var(--green); } .flow .row.out > b { color: var(--red); }
.tb { display: flex; gap: 5px; flex-wrap: wrap; margin-top: 6px; }
.tb button { background: #fff; border: 1.5px solid var(--line); border-radius: 9px; padding: 5px 10px; font-size: 13px; font-weight: 700; }
.tb button:not(:disabled):active { background: #fde3c3; }
.tb button:disabled { opacity: .4; }
.tb.col { flex-direction: column; margin: 0; } .tb.end { justify-content: center; margin-top: 18px; } .tb.end button { padding: 10px 22px; }
.lock { display: block; font-size: 11.5px; color: #a2876c; }
.homes { display: grid; gap: 6px; }
.home { display: flex; justify-content: space-between; gap: 8px; background: var(--paper2); border: 1px solid var(--line); border-radius: 12px; padding: 9px 10px; }
.home b { font-size: 14px; } .home small { display: block; font-size: 11.5px; color: var(--ink2); }
.me-grid { display: grid; gap: 6px; } .me-grid .st { grid-template-columns: 70px 1fr 28px; font-size: 13px; }
.achs { display: flex; flex-wrap: wrap; gap: 6px; }
.achs span { background: var(--paper2); border: 1px solid var(--line); border-radius: 99px; padding: 3px 10px; font-size: 12.5px; }
.achs.all span { border-radius: 10px; display: flex; flex-direction: column; flex: 1 1 45%; }
.achs.all span small { font-size: 11px; color: var(--ink2); } .achs span.no { opacity: .5; }

/* ── 事件彈窗 ── */
.modal { position: absolute; inset: 0; z-index: 30; background: rgba(45, 28, 15, .5); display: flex; align-items: flex-end; opacity: 0; pointer-events: none; transition: opacity .2s; }
.modal.on { opacity: 1; pointer-events: auto; }
.card { width: 100%; max-height: 94%; overflow-y: auto; background: var(--paper); border-radius: 22px 22px 0 0; transform: translateY(40px); transition: transform .25s ease-out; padding-bottom: calc(14px + var(--safe-b)); }
.modal.on .card { transform: none; }
.scene { position: relative; }
.scene > img { display: block; width: 100%; aspect-ratio: 16 / 10; object-fit: cover; border-radius: 22px 22px 0 0; }
.scene .age-chip { position: absolute; top: 12px; left: 12px; font-size: 13px; padding: 2px 11px; box-shadow: var(--shadow); }
.who { position: absolute; left: 14px; bottom: -22px; display: flex; align-items: flex-end; gap: 6px; }
.who img { width: 60px; height: 60px; border-radius: 50%; object-fit: cover; border: 3px solid var(--paper); box-shadow: var(--shadow); }
.who span { background: var(--paper); border-radius: 99px; padding: 1px 10px; font-size: 13px; font-weight: 700; margin-bottom: 4px; box-shadow: var(--shadow); }
.c-body { padding: 14px 18px 4px; }
.scene + .c-body { padding-top: 28px; }
.c-body h3 { margin: 0 0 6px; font-size: 20px; }
.c-text { margin: 0 0 12px; font-size: 15.5px; }
.c-res { margin: 4px 0 8px; font-size: 15px; background: var(--paper2); border-left: 4px solid var(--sun); border-radius: 8px; padding: 10px 12px; }
.choices { display: flex; flex-direction: column; gap: 8px; }
.choice { text-align: left; background: #fff; border: 1.5px solid var(--line); border-radius: 13px; padding: 12px 14px; box-shadow: 0 2px 0 var(--line); }
.choice span { display: block; font-weight: 700; } .choice small { display: block; font-size: 12px; color: var(--ink2); margin-top: 2px; }
.choice small.need { color: #b08b63; }
.choice:not(:disabled):active { transform: translateY(2px); box-shadow: none; background: #fff4e6; }
.choice:disabled { opacity: .5; box-shadow: none; }
.chips { display: flex; flex-wrap: wrap; gap: 5px; margin: 6px 0; }
.chip { font-size: 12px; font-weight: 700; padding: 2px 9px; border-radius: 99px; }
.chip.up { background: #e1f2e4; color: var(--green); } .chip.dn { background: #fbe4e0; color: var(--red); }

/* ── 提示 ── */
#toasts { position: absolute; top: 10px; left: 10px; right: 10px; z-index: 40; display: flex; flex-direction: column; gap: 6px; pointer-events: none; }
.toast { background: rgba(255, 250, 242, .97); border: 1.5px solid var(--sun2); border-radius: 14px; padding: 9px 12px; box-shadow: var(--shadow); font-size: 13.5px; opacity: 0; transform: translateY(-10px); transition: all .3s; }
.toast.on { opacity: 1; transform: none; }
.toast p { margin: 0; }

/* ── 結算 ── */
.end-hero { position: relative; margin: 0 -16px; }
.end-hero > img { display: block; width: 100%; aspect-ratio: 16 / 9; object-fit: cover; }
.end-who { position: absolute; left: 16px; right: 16px; bottom: -30px; display: flex; align-items: flex-end; gap: 10px; }
.end-who img { width: 76px; height: 76px; border-radius: 50%; border: 4px solid var(--paper); object-fit: cover; box-shadow: var(--shadow); filter: sepia(.25); }
.end-who div { background: var(--paper); border-radius: 12px; padding: 4px 12px; box-shadow: var(--shadow); }
.end-who b { font-size: 18px; display: block; } .end-who span { font-size: 13px; color: var(--ink2); }
.grade { display: flex; align-items: center; gap: 14px; margin-top: 44px; background: var(--paper2); border-radius: var(--r); padding: 12px 14px; border: 1.5px solid var(--line); box-shadow: var(--shadow); }
.grade > b { font: 900 48px/1 "Noto Serif TC", serif; width: 64px; text-align: center; color: var(--sun); }
.grade.g-S > b { color: #d4a017; } .grade.g-D > b { color: #8a7a6a; }
.grade span { font-size: 12px; color: var(--ink2); } .grade p { margin: 2px 0 0; font-weight: 700; }
.end-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-top: 12px; }
.end-grid b { font-size: 13.5px; }
.unlock { background: linear-gradient(135deg, #fff1d8, #ffe2bd); border: 2px solid var(--sun2); border-radius: var(--r); padding: 4px 14px 8px; margin-top: 14px; }
.unlock p { margin: 6px 0; } .unlock small { color: var(--ink2); }
.end-btns { margin-top: 18px; }
.feed-full { padding-top: 10px; }
