:root {
  --bg: #14110f; --bg2: #1d1814; --panel: #241e19; --panel2: #2d2620; --line: #3d342b;
  --text: #f6f0e4; --muted: #b3a999; --accent: #ffcc29; --accent-ink: #1a1400; --red: #ff5043; --green: #3ddc84; --blue: #4cc9f0;
  --health: #ff5043; --water: #4cc9f0; --food: #ff9f1c; --morale: #ff6b9d; --sanity: #b388ff; --defense: #9fb0c0; --trust: #2ec4b6;
  --radius: 14px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --display: "Arial Black", "Segoe UI Black", "Helvetica Neue", Impact, system-ui, sans-serif;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: radial-gradient(1200px 600px at 50% -200px, #2b2118, var(--bg) 60%) fixed, var(--bg); color: var(--text); font: 16px/1.45 var(--font); min-height: 100vh; min-height: 100dvh; overflow-x: hidden; }
body.noscroll { overflow: hidden; }
[hidden] { display: none !important; }
h1, h2, h3, p, ul, ol { margin: 0; }
button { font: inherit; color: inherit; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: -999px; top: 0; background: var(--accent); color: var(--accent-ink); padding: 8px 12px; z-index: 100; }
.skip:focus { left: 8px; top: 8px; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.muted { color: var(--muted); } .small { font-size: .85rem; } .center { text-align: center; }

/* ---- top bar */
.topbar { display: flex; align-items: center; justify-content: space-between; padding: 8px max(12px, env(safe-area-inset-left)) 8px 14px; max-width: 1080px; margin: 0 auto; }
.brand { font: 900 .8rem/1 var(--display); letter-spacing: .08em; color: var(--accent); text-transform: uppercase; }
#top-actions { display: flex; gap: 6px; }
.icon-btn { width: 44px; height: 44px; border-radius: 12px; border: 1px solid var(--line); background: var(--panel); font-size: 1.2rem; cursor: pointer; }
.icon-btn:hover { background: var(--panel2); }
main { max-width: 1080px; margin: 0 auto; padding: 0 14px 28px; }

/* ---- buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 48px; padding: 10px 18px; border-radius: 12px; border: 2px solid var(--line); background: var(--panel); font-weight: 700; cursor: pointer; text-align: center; width: 100%; }
.btn:hover:not(:disabled) { background: var(--panel2); border-color: #5a4c3d; }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); box-shadow: 0 4px 0 #b88f00; }
.btn.primary:hover:not(:disabled) { background: #ffd84d; border-color: #ffd84d; }
.btn.primary:active:not(:disabled) { box-shadow: 0 1px 0 #b88f00; transform: translateY(3px); }
.btn.big { min-height: 56px; font-size: 1.1rem; }
.btn.small { min-height: 40px; padding: 6px 12px; width: auto; font-size: .9rem; }
.btn.danger { border-color: var(--red); color: var(--red); }
.link { background: none; border: 0; color: var(--accent); text-decoration: underline; cursor: pointer; padding: 10px 6px; min-height: 44px; font-size: .95rem; }

/* ---- title */
.title { display: grid; gap: 14px; max-width: 520px; margin: 0 auto; padding-top: 6px; }
.hazard { height: 14px; border-radius: 4px; background: repeating-linear-gradient(-45deg, var(--accent) 0 14px, #1a1400 14px 28px); }
.title h1 { display: grid; line-height: .92; text-align: center; font-family: var(--display); text-transform: uppercase; }
.title .t1 { font-size: clamp(2rem, 11vw, 3.4rem); letter-spacing: .02em; }
.title .t2 { font-size: clamp(3rem, 18vw, 5.6rem); color: var(--accent); text-shadow: 0 5px 0 #7a5d00, 0 0 30px rgba(255, 204, 41, .25); letter-spacing: -.02em; animation: shake 6s infinite; }
.lead { text-align: center; color: var(--muted); font-size: 1.05rem; }
.lead b { color: var(--text); }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.challenge { border-color: var(--accent); display: grid; gap: 10px; text-align: center; }
.code-row { display: flex; gap: 8px; } .code-row .btn { width: 76px; }
.code-input { flex: 1; min-width: 0; min-height: 48px; border-radius: 12px; border: 2px solid var(--line); background: var(--bg2); color: var(--text); padding: 0 14px; font: 700 1rem var(--font); letter-spacing: .12em; text-transform: uppercase; }
.code-input::placeholder { letter-spacing: .06em; color: #7d7466; }
.link-row { display: flex; flex-wrap: wrap; justify-content: center; gap: 2px 10px; }
.about { text-align: center; color: var(--muted); font-size: .8rem; padding: 6px 0; }

/* ---- pages */
.page { display: grid; gap: 14px; max-width: 640px; margin: 0 auto; }
.page-head { display: flex; align-items: center; gap: 12px; }
.page-head h2 { font: 900 1.3rem var(--display); text-transform: uppercase; }
.how { display: grid; gap: 12px; padding-left: 1.2rem; }
.how li { padding-left: 4px; }
.grid-list { list-style: none; padding: 0; display: grid; gap: 8px; }
.ach { display: flex; gap: 12px; align-items: center; padding: 10px 12px; border-radius: 12px; background: var(--panel); border: 1px solid var(--line); }
.ach b, .ach small { display: block; } .ach small { color: var(--muted); }
.ach-icon { font-size: 1.8rem; width: 40px; text-align: center; flex: none; }
.ach.locked { opacity: .6; } .ach.locked .ach-icon { filter: grayscale(1); }
.ach.got { border-color: #6b5410; background: #2a2210; }
.setting { display: flex; gap: 12px; align-items: flex-start; padding: 12px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; cursor: pointer; }
.setting input { width: 26px; height: 26px; accent-color: var(--accent); flex: none; margin-top: 2px; }
.setting small { display: block; color: var(--muted); }

/* ---- shop */
.shop { padding-bottom: 86px; }
.shop-head { position: sticky; top: 0; z-index: 20; padding: 6px 0 2px; background: linear-gradient(var(--bg) 90%, transparent); }
.shop-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 6px; }
.shop-title { display: grid; line-height: 1.1; min-width: 0; } .shop-title b { font: 900 .92rem var(--display); letter-spacing: .05em; color: var(--accent); white-space: nowrap; }
.shop-meters { display: flex; align-items: baseline; gap: 14px; }
.clock { font: 900 1.5rem/1 var(--display); font-variant-numeric: tabular-nums; }
.clock.urgent { color: var(--red); animation: pulse .5s infinite alternate; }
.money { font: 900 1.5rem/1 var(--display); color: var(--green); font-variant-numeric: tabular-nums; }
.money.broke { color: var(--muted); }
.timebar { height: 8px; border-radius: 6px; background: var(--panel2); overflow: hidden; }
.timebar i { display: block; height: 100%; background: var(--accent); width: 100%; }
.timebar.urgent i { background: var(--red); }
.tabs { display: flex; gap: 6px; overflow-x: auto; padding: 4px 0 10px; scrollbar-width: none; margin-right: -14px; padding-right: 14px; }
.tabs::-webkit-scrollbar { display: none; }
.tab { flex: none; min-height: 40px; padding: 6px 14px; border-radius: 999px; border: 2px solid var(--line); background: var(--panel); font-weight: 700; font-size: .9rem; cursor: pointer; }
.tab[aria-selected="true"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.legend { margin: 0 0 8px; line-height: 1.3; } .legend b { color: var(--text); font-size: .75rem; }
.items { list-style: none; padding: 0; display: grid; gap: 8px; grid-template-columns: 1fr; }
.item { display: grid; grid-template-columns: 44px 1fr auto; gap: 10px; align-items: center; padding: 10px; border-radius: var(--radius); background: var(--panel); border: 1px solid var(--line); transition: border-color .15s; }
.item.have { border-color: #6b5410; }
.item.sale { border-color: var(--accent); background: linear-gradient(135deg, #2f2508, var(--panel)); }
.item.pop { animation: pop .25s; }
.item-icon { font-size: 2rem; text-align: center; }
.item-name { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.item-desc { color: var(--muted); font-size: .85rem; line-height: 1.3; }
.item-body { min-width: 0; }
.chips { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 5px; }
.chip { display: inline-flex; align-items: center; gap: 2px; padding: 1px 8px; border-radius: 999px; font-size: .8rem; background: var(--panel2); border: 1px solid var(--line); white-space: nowrap; }
.chip.pos { color: #8ff0b4; border-color: #1f6b3f; } .chip.neg { color: #ff9a92; border-color: #7a2a24; }
.chips.big .chip { font-size: .95rem; padding: 3px 10px; }
.tag { padding: 1px 8px; border-radius: 6px; font-size: .72rem; font-weight: 800; text-transform: uppercase; letter-spacing: .04em; align-self: center; }
.tag.use { background: #3a2e22; color: #ffd9a8; } .tag.daily { background: #1f3340; color: #a9e4ff; } .tag.gear { background: #2c2a40; color: #cdbdff; }
.tag.sale-tag { background: var(--accent); color: var(--accent-ink); }
.item-buy { display: grid; justify-items: end; gap: 4px; }
.qty { font-weight: 900; color: var(--accent); min-height: 1.2em; font-size: .95rem; }
.buy { min-width: 76px; min-height: 48px; padding: 6px 12px; border-radius: 12px; border: 2px solid var(--green); background: #12301f; color: #b9f7d0; font-weight: 900; cursor: pointer; display: grid; place-items: center; line-height: 1.05; }
.buy s { display: block; font-size: .75rem; color: var(--muted); font-weight: 600; }
.buy:hover:not(:disabled) { background: #1a4b2f; }
.buy:disabled { border-color: var(--line); background: var(--panel2); color: var(--muted); cursor: not-allowed; }
.buy.owned { border-color: #6b5410; color: var(--accent); }
.buy.owned::after { content: "✓"; }
.buy.owned .price { display: none; }
.minus { min-width: 44px; min-height: 36px; border-radius: 10px; border: 2px solid var(--line); background: var(--panel2); font-weight: 900; font-size: 1.1rem; cursor: pointer; }
.shop-foot { position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; display: flex; gap: 8px; align-items: center; padding: 10px max(14px, env(safe-area-inset-right)) calc(10px + env(safe-area-inset-bottom)) 14px; background: rgba(20, 17, 15, .96); border-top: 1px solid var(--line); backdrop-filter: blur(8px); }
.shop-foot .btn.primary { width: auto; min-width: 118px; } .shop-foot .btn.small { min-height: 48px; }
.foot-left { flex: 1; min-width: 0; display: grid; font-weight: 700; font-size: .92rem; }
.est { color: var(--muted); font-size: .85rem; } .est .warn { color: var(--red); font-weight: 800; }

/* ---- sheets */
.sheet { position: fixed; inset: 0; z-index: 60; display: flex; align-items: flex-end; justify-content: center; }
.sheet-back { position: absolute; inset: 0; background: rgba(0, 0, 0, .7); }
.sheet-panel { position: relative; width: 100%; max-width: 560px; max-height: 88dvh; overflow-y: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 20px 20px 0 0; padding: 16px 16px calc(16px + env(safe-area-inset-bottom)); display: grid; gap: 12px; animation: up .2s ease-out; }
.sheet-head { display: flex; justify-content: space-between; align-items: center; } .sheet-head h2 { font: 900 1.2rem var(--display); text-transform: uppercase; }
.sheet .row { display: grid; gap: 8px; }
.flight { list-style: none; padding: 0; display: grid; gap: 6px; }
.flight li { display: flex; justify-content: space-between; gap: 10px; padding: 10px 12px; border-radius: 10px; background: var(--bg2); border-left: 5px solid var(--green); }
.flight li.bad { border-left-color: var(--red); } .flight li.bad b { color: var(--red); }
.ready { font-size: 1.1rem; } .ready b { color: var(--accent); }
.tips { margin: 0; padding-left: 1.2rem; display: grid; gap: 6px; color: var(--muted); }
.timeup { font: 900 1.1rem var(--display); color: var(--red); text-align: center; }
.bag { display: grid; gap: 8px; } .bag h3 { font-size: .85rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin-top: 4px; }
.bag-list, .gear-list { list-style: none; padding: 0; display: grid; gap: 8px; }
.bag-row { display: grid; grid-template-columns: 40px 1fr auto; gap: 10px; align-items: center; padding: 8px; background: var(--bg2); border-radius: 12px; }
.gear-list { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); } .gear-list li { padding: 8px 10px; background: var(--bg2); border-radius: 10px; font-size: .88rem; }

/* ---- days */
.day-head { display: grid; grid-template-columns: auto 1fr auto; gap: 12px; align-items: center; margin: 4px 0 10px; }
.day-num { display: flex; align-items: baseline; gap: 6px; } .day-num b { font: 900 2.2rem/1 var(--display); color: var(--accent); }
.daybar { height: 10px; border-radius: 6px; background: var(--panel2); overflow: hidden; } .daybar i { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), #ff8a1c); transition: width .5s; }
.day-cols { display: grid; gap: 12px; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px 8px; padding: 10px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
.stat { position: relative; display: grid; grid-template-columns: auto 1fr; gap: 3px 4px; align-items: center; padding: 3px 4px; border-radius: 8px; font-size: .95rem; }
.stat-l { font-size: 1.05rem; } .stat-n { display: none; }
.stat b { text-align: right; font-variant-numeric: tabular-nums; }
.stat .bar { grid-column: 1 / -1; height: 8px; border-radius: 5px; background: var(--bg2); overflow: hidden; }
.stat .bar i { display: block; height: 100%; width: 0; border-radius: 5px; transition: width .6s cubic-bezier(.2, .8, .2, 1); background: var(--c, var(--accent)); }
.s-health { --c: var(--health); } .s-water { --c: var(--water); } .s-food { --c: var(--food); } .s-morale { --c: var(--morale); } .s-sanity { --c: var(--sanity); } .s-defense { --c: var(--defense); } .s-trust { --c: var(--trust); }
.stat.low b { color: var(--red); } .stat.low .bar i { animation: pulse .6s infinite alternate; background: var(--red); }
.s-money { color: #b9f7d0; }
.float { position: absolute; right: 4px; top: -8px; font-weight: 900; opacity: 0; pointer-events: none; }
.float.pos { color: var(--green); } .float.neg { color: var(--red); }
.float.go { animation: floatup 1.1s ease-out; }
.flash-pos { animation: flashp .8s; } .flash-neg { animation: flashn .8s; }
.report { display: grid; gap: 6px; margin-top: 10px; padding: 10px 12px; border-radius: var(--radius); background: var(--bg2); border: 1px dashed var(--line); }
.rep-line { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; font-size: .88rem; } .rep-l { color: var(--muted); margin-right: 4px; }
.event { display: grid; gap: 12px; }
.ev-icon { font-size: 3.2rem; line-height: 1; text-align: center; }
.ev-text { font-size: 1.15rem; line-height: 1.4; }
.day.fresh .event { animation: cardin .35s ease-out; }
.choices { display: grid; gap: 8px; }
.choice { display: flex; gap: 12px; align-items: center; text-align: left; width: 100%; min-height: 56px; padding: 10px 12px; border-radius: 12px; border: 2px solid var(--line); background: var(--panel2); cursor: pointer; font-weight: 600; }
.choice:hover:not(:disabled) { border-color: var(--accent); background: #3a3020; }
.choice:active:not(:disabled) { transform: translateY(1px); }
.choice .num { flex: none; width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center; background: var(--accent); color: var(--accent-ink); font-weight: 900; }
.ctext { display: grid; gap: 3px; min-width: 0; } .ctext small { font-weight: 500; }
.choice.locked { opacity: .55; cursor: not-allowed; background: var(--bg2); } .choice.locked .num { background: var(--line); color: var(--muted); }
.why { color: var(--muted); } .hints { display: grid; gap: 2px; }
.hint { font-weight: 700; } .hint.fatal { color: var(--red); } .hint.risky { color: #ffb15c; } .hint.ends { color: var(--accent); }
.outcome { display: grid; gap: 10px; border-color: #6b5410; animation: cardin .3s ease-out; }
.outcome.died { border-color: var(--red); background: #2b1512; }
.you-chose { color: var(--muted); font-size: .9rem; font-style: italic; }
.outcome-text { font-size: 1.1rem; }
.death-msg { color: #ff9a92; font-weight: 700; }
.event.death .ev-text { text-align: center; }

/* ---- ending */
.ending { max-width: 620px; margin: 0 auto; display: grid; gap: 12px; text-align: center; padding-top: 4px; }
.end-top { display: flex; align-items: center; justify-content: center; gap: 10px; }
.end-emoji { font-size: 3rem; animation: pop .6s; } .end-label { font: 900 .9rem var(--display); letter-spacing: .12em; padding: 4px 12px; border-radius: 6px; background: var(--panel2); }
.end-title { font: 900 clamp(2rem, 9vw, 3.2rem)/1 var(--display); text-transform: uppercase; animation: cardin .6s ease-out; }
.t-victory .end-title { color: var(--accent); } .t-death .end-title { color: var(--red); } .t-dark .end-title { color: #d46bff; } .t-special .end-title { color: var(--blue); }
.t-death .end-label { background: #4a1914; } .t-victory .end-label { background: #4a3a08; }
.end-desc { color: #e8dfce; font-size: 1.08rem; }
.end-days { display: flex; align-items: baseline; justify-content: center; gap: 8px; } .end-days b { font: 900 3.4rem/1 var(--display); } .end-days span { color: var(--muted); }
.strip { font-size: 1.1rem; letter-spacing: 1px; word-break: break-all; line-height: 1.3; }
.new-badge { display: inline-block; justify-self: center; padding: 6px 14px; border-radius: 999px; background: var(--accent); color: var(--accent-ink); font-weight: 900; animation: pop .5s; }
.facts { list-style: none; padding: 0; display: grid; gap: 4px; color: var(--muted); font-size: .92rem; }
.actions { display: grid; gap: 8px; margin-top: 4px; }
.share-text { width: 100%; background: var(--bg2); color: var(--muted); border: 1px solid var(--line); border-radius: 12px; padding: 10px; font: .85rem/1.4 var(--font); resize: vertical; text-align: left; }
.ending .card { text-align: left; } .ending h3 { margin-bottom: 8px; }

/* ---- toasts */
#toasts { position: fixed; left: 0; right: 0; top: 56px; z-index: 80; display: grid; justify-items: center; gap: 8px; pointer-events: none; padding: 0 12px; }
.toast { background: #fff; color: #1b1814; padding: 10px 16px; border-radius: 12px; font-weight: 800; box-shadow: 0 6px 24px rgba(0, 0, 0, .5); animation: toastin .25s ease-out; max-width: 92vw; }
.toast.ach { background: var(--accent); color: var(--accent-ink); }
.toast.out { opacity: 0; transition: opacity .4s; }

/* ---- animations */
@keyframes pop { 0% { transform: scale(.94); } 60% { transform: scale(1.04); } 100% { transform: scale(1); } }
@keyframes pulse { to { opacity: .55; } }
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
@keyframes cardin { from { transform: translateY(14px) scale(.98); opacity: 0; } }
@keyframes toastin { from { transform: translateY(-14px); opacity: 0; } }
@keyframes floatup { 0% { opacity: 1; transform: translateY(0); } 100% { opacity: 0; transform: translateY(-22px); } }
@keyframes flashp { 0% { background: rgba(61, 220, 132, .35); } 100% { background: transparent; } }
@keyframes flashn { 0% { background: rgba(255, 80, 67, .4); transform: translateX(-3px); } 30% { transform: translateX(3px); } 60% { transform: translateX(-2px); } 100% { background: transparent; transform: none; } }
@keyframes shake { 0%, 92%, 100% { transform: none; } 94% { transform: translateX(-3px) rotate(-.6deg); } 96% { transform: translateX(3px) rotate(.6deg); } 98% { transform: translateX(-2px); } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }

/* ---- grids never grow past the screen */
.title, .page, .ending, .sheet-panel, .day-cols, .event, .outcome, .stats, .challenge, .bag, .actions { grid-template-columns: minmax(0, 1fr); }
.stats { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.day-side, .day-main, .item-body, .ctext { min-width: 0; }
@media (max-width: 359px) {
  .title .t2 { font-size: 2.7rem; } .title .t1 { font-size: 1.9rem; }
  .shop-title span { display: none; } .shop-title b { font-size: .78rem; white-space: normal; }
  .clock, .money { font-size: 1.25rem; } .shop-meters { gap: 8px; }
  .item { grid-template-columns: 36px 1fr auto; gap: 8px; padding: 8px; } .buy { min-width: 64px; }
  .shop-foot { padding-left: 8px; padding-right: 8px; } .shop-foot .btn.primary { min-width: 100px; padding: 8px 10px; }
  .stat { font-size: .85rem; }
}
/* ---- bigger screens */
@media (min-width: 720px) {
  main { padding: 0 24px 40px; }
  .items { grid-template-columns: 1fr 1fr; }
  .shop-foot { justify-content: center; } .shop-foot .foot-left { flex: none; min-width: 240px; }
  .sheet { align-items: center; } .sheet-panel { border-radius: 20px; }
  .actions { grid-template-columns: 1fr 1fr; } .actions .primary, .actions .btn.big:nth-child(2) { grid-column: auto; }
}
@media (min-width: 900px) {
  .stats { grid-template-columns: 1fr 1fr; gap: 10px 14px; padding: 14px; }
  .stat-n { display: inline; } .stat { font-size: .95rem; }
  .s-money { grid-column: 1 / -1; }
  .day-cols { grid-template-columns: 340px 1fr; gap: 20px; align-items: start; }
  .day-side { position: sticky; top: 8px; }
  .items { grid-template-columns: 1fr 1fr 1fr; }
  .ev-text { font-size: 1.3rem; }
  .title { max-width: 560px; }
}
