:root {
  --ink: #1d1b2e; --ink2: #2a2742; --paper: #f3e9d2; --paper2: #e6d8b8; --tram: #c8282a; --brass: #e8b84a; --muted: #7a6f5a;
  --hulo: #3fae5a; --energy: #e8b84a; --hunger: #e0883a; --stress: #d04a5a; --academic: #4a86c8;
  --mono: ui-monospace, "Cascadia Mono", "SF Mono", Consolas, "Liberation Mono", "Courier New", monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--ink); color: var(--paper); font-family: var(--mono); font-size: 15px; overscroll-behavior: none; touch-action: manipulation; }
#app { position: fixed; inset: 0; display: flex; flex-direction: column; padding-top: env(safe-area-inset-top); padding-bottom: env(safe-area-inset-bottom); user-select: none; -webkit-user-select: none; }
button { font-family: inherit; }

/* HUD */
#hud { flex: none; display: flex; flex-wrap: wrap; align-items: center; gap: 6px 14px; padding: 6px 10px; background: var(--ink2); border-bottom: 3px solid #000; font-size: 12px; }
.hud-left { display: flex; flex-direction: column; min-width: 120px; }
.hud-time { font-weight: 700; font-size: 14px; color: var(--brass); }
.hud-chap { color: #a9a2c4; font-size: 11px; }
.hud-bars { display: flex; flex-wrap: wrap; gap: 4px 12px; flex: 1; }
.bar { display: flex; align-items: center; gap: 5px; min-width: 120px; }
.bar .lbl { font-style: normal; width: 54px; color: #cfc8e6; }
.bar .track { flex: 1; height: 9px; background: #0d0b18; border: 1px solid #000; min-width: 50px; position: relative; }
.bar .fill { height: 100%; width: 0; transition: width .25s linear; }
.rm .bar .fill { transition: none; }
.b-hulo .fill { background: var(--hulo); } .b-energy .fill { background: var(--energy); } .b-hunger .fill { background: var(--hunger); }
.b-stress .fill { background: var(--stress); } .b-academic .fill { background: var(--academic); }
.bar .num { width: 28px; text-align: right; font-size: 11px; }
.hud-state { font-size: 10px; color: #8fe0a0; font-style: normal; margin-left: 2px; }
[data-hulo="panic"] .hud-state, [data-hulo="zero"] .hud-state { color: #ff8a8a; }
.hud-right { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.hud-money { color: var(--brass); font-weight: 700; } .hud-rep { color: #cfc8e6; }
.hud-btn { background: var(--ink); color: var(--paper); border: 2px solid #000; padding: 4px 8px; cursor: pointer; font-size: 14px; }
.hud-btn:hover, .hud-btn:focus-visible { background: var(--tram); outline: none; }

/* Stage */
#stage { position: relative; flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; background: #0a0912; overflow: hidden; }
#view { image-rendering: pixelated; image-rendering: crisp-edges; background: #000; box-shadow: 0 0 0 4px #000; max-width: 100%; max-height: 100%; }
#prompt { position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%); background: var(--paper); color: var(--ink); border: 3px solid var(--ink); padding: 7px 14px; font-weight: 700; cursor: pointer; z-index: 3; box-shadow: 3px 3px 0 #000; max-width: 92%; text-align: center; }
#dialogue { position: absolute; left: 50%; bottom: 8px; transform: translateX(-50%); width: min(760px, 96%); display: flex; gap: 12px; background: var(--paper); color: var(--ink); border: 4px solid var(--ink); box-shadow: 5px 5px 0 #000; padding: 10px 12px; z-index: 5; min-height: 120px; }
#dialogue[hidden] { display: none; }
.dleft { flex: none; display: flex; align-items: flex-start; }
.portrait { width: 56px; height: 80px; image-rendering: pixelated; background: var(--paper2); border: 3px solid var(--ink); }
.portrait.big { width: 70px; height: 100px; }
.dright { flex: 1; min-width: 0; }
.dname { font-weight: 800; color: var(--tram); margin-bottom: 4px; font-size: 15px; }
.dtext { font-size: 15px; line-height: 1.45; min-height: 3em; }
.dchoices { display: flex; flex-direction: column; gap: 5px; margin-top: 8px; }
.dchoice { text-align: left; padding: 7px 10px; background: var(--ink); color: var(--paper); border: 2px solid #000; cursor: pointer; font-size: 14px; }
.dchoice:hover, .dchoice:focus-visible { background: var(--tram); outline: 2px solid var(--brass); }
.dhint { margin-top: 6px; font-size: 11px; color: var(--muted); text-align: right; }

/* Toasts */
#toasts { position: absolute; top: 56px; right: 8px; display: flex; flex-direction: column; gap: 6px; z-index: 20; pointer-events: none; max-width: min(380px, 80vw); }
.toast { background: var(--paper); color: var(--ink); border: 3px solid var(--ink); border-left-width: 8px; padding: 6px 10px; font-size: 13px; box-shadow: 3px 3px 0 #000; animation: slide .2s ease-out; }
.rm .toast { animation: none; }
.toast.quest { border-left-color: var(--academic); } .toast.warn { border-left-color: var(--hunger); } .toast.bad { border-left-color: var(--tram); }
.toast.good { border-left-color: var(--hulo); } .toast.achieve { border-left-color: var(--brass); background: #fff3c4; font-weight: 700; }
@keyframes slide { from { transform: translateX(30px); opacity: 0; } to { transform: none; opacity: 1; } }

/* Fade */
#fade { position: absolute; inset: 0; background: #000; opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 40; }
#fade.on { opacity: 1; pointer-events: all; } .rm #fade { transition: none; }

/* Overlays */
#layer { position: absolute; inset: 0; pointer-events: none; z-index: 30; }
.ov-panel { pointer-events: all; position: absolute; inset: 0; margin: auto; width: min(560px, 96vw); max-height: 92%; height: fit-content; display: flex; flex-direction: column; background: var(--paper); color: var(--ink); border: 4px solid var(--ink); box-shadow: 6px 6px 0 #000; }
.ov-panel.wide { width: min(780px, 96vw); }
.ov-panel.under { display: none; }
#layer:has(.ov-panel) { pointer-events: all; background: rgba(10, 9, 18, .72); }
.ov-head { display: flex; align-items: center; justify-content: space-between; padding: 8px 12px; background: var(--tram); color: #fff; border-bottom: 4px solid var(--ink); }
.ov-head h2 { margin: 0; font-size: 17px; }
.ov-x { background: transparent; color: #fff; border: 0; font-size: 18px; cursor: pointer; padding: 2px 8px; }
.ov-x:hover, .ov-x:focus-visible { background: var(--ink); outline: none; }
.ov-body { padding: 12px; overflow-y: auto; }
.ov-body h3 { margin: 12px 0 6px; font-size: 14px; border-bottom: 2px dashed var(--muted); padding-bottom: 3px; }
.muted { color: var(--muted); font-size: 12.5px; margin: 4px 0; }
.btn { background: var(--ink); color: var(--paper); border: 3px solid #000; padding: 8px 14px; cursor: pointer; font-size: 14px; box-shadow: 3px 3px 0 #000; }
.btn:hover:not(:disabled), .btn:focus-visible { background: var(--tram); outline: 2px solid var(--brass); }
.btn:active:not(:disabled) { transform: translate(2px, 2px); box-shadow: 1px 1px 0 #000; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--tram); } .btn.primary:hover { background: #e03a3c; }
.btn.small { padding: 4px 10px; font-size: 12px; } .btn.big { font-size: 16px; padding: 12px 22px; }
.menu-list { display: flex; flex-direction: column; gap: 8px; }
.row-btns { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; } .row-btns.wrap { justify-content: center; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 7px 0; border-bottom: 1px dotted var(--muted); }
.row input[type=range] { width: 55%; } .row select { background: var(--paper2); border: 2px solid var(--ink); padding: 4px; font-family: inherit; }
.row input[type=checkbox] { width: 22px; height: 22px; }
.tbl { width: 100%; border-collapse: collapse; } .tbl th { text-align: left; padding: 4px 8px 4px 0; white-space: nowrap; } .tbl td { padding: 4px 0; }
.slot { display: flex; justify-content: space-between; align-items: center; gap: 8px; border: 3px solid var(--ink); padding: 8px; margin-bottom: 8px; background: var(--paper2); }
.slot-main { display: flex; flex-direction: column; font-size: 13px; } .slot-acts { display: flex; gap: 6px; }

/* Inventory */
.inv-wrap { display: flex; gap: 12px; flex-wrap: wrap; }
.inv-grid { display: grid; grid-template-columns: repeat(4, 64px); gap: 6px; }
.slot-cell { position: relative; width: 64px; height: 64px; background: var(--paper2); border: 3px solid var(--ink); cursor: pointer; padding: 0; }
.slot-cell.empty { opacity: .45; cursor: default; } .slot-cell.sel { outline: 3px solid var(--tram); } .slot-cell:hover:not(.empty) { background: #fff3c4; }
.ico { font-size: 28px; line-height: 1; } .ico.big { font-size: 44px; }
.qty { position: absolute; right: 3px; bottom: 1px; font-size: 11px; }
.inv-detail { flex: 1; min-width: 200px; } .inv-detail h3 { border: 0; margin-top: 0; }
.chips { display: flex; flex-wrap: wrap; gap: 5px; margin: 8px 0; }
.chip { padding: 3px 9px; border: 2px solid var(--ink); background: var(--paper2); cursor: pointer; font-size: 12px; } .chip.on { background: var(--ink); color: var(--paper); }

/* Journal, status */
.chap { font-weight: 800; color: var(--tram); } .quest { border-left: 6px solid var(--academic); padding: 4px 10px; margin: 8px 0; background: var(--paper2); }
.quest.done { border-left-color: var(--hulo); opacity: .8; } .quest ul { margin: 6px 0; padding-left: 4px; list-style: none; font-size: 13px; } .quest li.ok { text-decoration: line-through; color: var(--muted); }
.status-top { display: flex; gap: 12px; align-items: center; margin-bottom: 8px; } .status-top h3 { border: 0; margin: 0; }
.ach { list-style: none; padding: 0; font-size: 12.5px; columns: 2; } .ach li { margin: 3px 0; color: var(--muted); } .ach li.ok { color: var(--ink); font-weight: 700; }
.ov-body .bar { margin: 4px 0; } .ov-body .bar .lbl { color: var(--ink); } .ov-body .bar .track { background: #cfc3a4; }

/* Map */
.worldmap { position: relative; width: 100%; aspect-ratio: 16 / 9; background: repeating-linear-gradient(45deg, #d8c9a4, #d8c9a4 10px, #d2c29b 10px, #d2c29b 20px); border: 3px solid var(--ink); }
.worldmap svg { position: absolute; inset: 0; width: 100%; height: 100%; }
.node { position: absolute; transform: translate(-50%, -50%); background: var(--paper); border: 3px solid var(--ink); padding: 6px 8px; cursor: pointer; font-size: 12px; display: flex; flex-direction: column; align-items: center; box-shadow: 2px 2px 0 #000; }
.node:hover, .node:focus-visible { background: #fff3c4; outline: 2px solid var(--tram); } .node.here { background: var(--tram); color: #fff; } .node small { font-size: 10px; }

/* Shop */
.shop-head { display: flex; justify-content: space-between; gap: 10px; align-items: center; } .shop-msg { margin: 0; min-height: 2.6em; font-size: 13px; } .shop-money { color: var(--tram); white-space: nowrap; }
.shop-row { display: flex; align-items: center; gap: 10px; padding: 7px 4px; border-bottom: 1px dotted var(--muted); } .shop-info { flex: 1; display: flex; flex-direction: column; min-width: 0; } .shop-info small { color: var(--muted); font-size: 11px; }

.credits, .ending .ov-body { line-height: 1.5; } .tagline { font-size: 17px; font-weight: 800; color: var(--tram); }

/* Main menu */
#menu { position: absolute; inset: 0; z-index: 35; display: none; flex-direction: column; align-items: center; justify-content: center; gap: 18px; background: radial-gradient(circle at 50% 30%, #3a2f5e 0%, var(--ink) 70%); padding: 16px; overflow: auto; }
#menu.on { display: flex; }
.title { text-align: center; } .title h1 { margin: 6px 0 2px; font-size: clamp(38px, 9vw, 72px); letter-spacing: 6px; color: var(--brass); text-shadow: 4px 4px 0 var(--tram), 8px 8px 0 #000; }
.title p { margin: 0; color: #cfc8e6; } .title-sprite { width: 70px; height: 100px; image-rendering: pixelated; }
.menu-list.main { width: min(300px, 90vw); } .foot { color: #8f89ad; text-align: center; }

/* Minigames */
#mini { position: absolute; inset: 0; z-index: 32; background: rgba(10, 9, 18, .86); display: flex; align-items: center; justify-content: center; padding: 8px; }
#mini[hidden] { display: none; }
.mini-panel { background: var(--paper); color: var(--ink); border: 4px solid var(--ink); box-shadow: 6px 6px 0 #000; width: min(640px, 100%); max-height: 100%; overflow-y: auto; }
.mini-head { display: flex; justify-content: space-between; align-items: center; background: var(--academic); color: #fff; padding: 6px 12px; border-bottom: 4px solid var(--ink); } .mini-head h2 { margin: 0; font-size: 16px; }
.mini-body { padding: 12px; } .mini-canvas { width: 100%; height: auto; display: block; background: #1f1830; border: 3px solid var(--ink); image-rendering: auto; touch-action: none; }
.mini-intro ul { padding-left: 18px; line-height: 1.5; } .mini-status { margin: 6px 0; min-height: 1.4em; font-weight: 700; } .mini-status.big { font-size: 16px; }
.mini-result.win h3 { color: #2a7a3a; } .mini-result.lose h3 { color: var(--tram); }
.timebar { height: 10px; background: #cfc3a4; border: 2px solid var(--ink); margin: 6px 0; } .timebar .fill { height: 100%; background: var(--tram); width: 100%; } .timebar.prog .fill { background: var(--hulo); width: 0; }
.bits { display: flex; gap: 6px; justify-content: center; margin: 10px 0; } .bitcol { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.bit { width: 44px; height: 54px; font-size: 22px; font-weight: 800; background: var(--paper2); border: 3px solid var(--ink); cursor: pointer; } .bit.on { background: var(--hulo); color: #fff; }
.code-out { text-align: center; font-weight: 700; }
.codebox { background: #1d1b2e; color: #d8f0d8; padding: 8px; border: 3px solid #000; margin: 8px 0; display: flex; flex-direction: column; text-align: left; font-family: var(--mono); font-size: 13px; white-space: pre-wrap; }
.codeline { text-align: left; background: transparent; color: #d8f0d8; border: 0; padding: 4px 6px; cursor: pointer; font-family: var(--mono); font-size: 13px; } .codeline:hover, .codeline:focus-visible { background: #3a3a6a; outline: 1px solid var(--brass); }
.opts { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; } .opt { padding: 8px 12px; border: 3px solid var(--ink); background: var(--paper2); cursor: pointer; font-family: var(--mono); font-size: 13px; } .opt:hover, .opt:focus-visible { background: #fff3c4; outline: 2px solid var(--tram); }
.seq { background: #1d1b2e; color: #d8f0d8; padding: 8px 8px 8px 28px; min-height: 40px; font-size: 13px; }
.pockets { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 8px 0; } .pocket { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 10px 4px; border: 3px solid var(--ink); background: var(--paper2); cursor: pointer; } .pocket small { font-size: 11px; }
.pocket:hover, .pocket:focus-visible { background: #fff3c4; outline: 2px solid var(--tram); }
.scene { display: flex; align-items: center; gap: 10px; } .conductor { background: var(--ink); color: var(--paper); padding: 8px 12px; border-radius: 0; flex: 1; min-height: 3em; margin: 0; }
.knock { background: #fff3c4; border: 3px solid var(--ink); padding: 8px; margin: 8px 0; display: flex; align-items: center; justify-content: space-between; gap: 8px; } .knock[hidden] { display: none; }

/* Touch controls */
#touch { position: absolute; inset: auto 0 6px 0; display: none; justify-content: space-between; align-items: flex-end; padding: 0 10px; pointer-events: none; z-index: 4; }
.touch-on #touch { display: flex; } #touch[hidden] { display: none !important; }
.dpad { display: grid; grid-template-columns: repeat(3, 52px); grid-template-rows: repeat(3, 52px); grid-template-areas: ". u ." "l . r" ". d ."; gap: 2px; pointer-events: all; }
.dpad .tbtn:nth-child(1) { grid-area: u; } .dpad .tbtn:nth-child(2) { grid-area: l; } .dpad .tbtn:nth-child(3) { grid-area: r; } .dpad .tbtn:nth-child(4) { grid-area: d; }
.tacts { display: grid; grid-template-columns: repeat(2, 52px); gap: 6px; pointer-events: all; }
.tbtn { width: 52px; height: 52px; border-radius: 50%; border: 3px solid #000; background: rgba(243, 233, 210, .55); color: var(--ink); font-size: 18px; font-weight: 800; touch-action: none; }
.tbtn.main { background: rgba(200, 40, 42, .8); color: #fff; grid-column: span 2; width: 100%; border-radius: 26px; }
.touch-on #dialogue { bottom: 150px; } .touch-on #prompt { bottom: 150px; }
.touch-on:has(#dialogue:not([hidden])) #touch { display: none; }

@media (max-width: 640px) {
  #hud { font-size: 11px; padding: 4px 6px; gap: 4px 8px; } .bar { min-width: 96px; } .bar .lbl { width: 46px; } .hud-left { min-width: 90px; }
  #dialogue { font-size: 13px; gap: 8px; padding: 8px; min-height: 100px; } .portrait { width: 42px; height: 60px; } .dtext { font-size: 13.5px; }
  .inv-grid { grid-template-columns: repeat(4, 54px); } .slot-cell { width: 54px; height: 54px; } .ach { columns: 1; }
}
@media (prefers-reduced-motion: reduce) { .toast { animation: none; } #fade { transition: none; } .bar .fill { transition: none; } }
:focus-visible { outline: 3px solid var(--brass); outline-offset: 1px; }
