:root {
  --ink: #2b2233; --parch: #f2e6c9; --parch2: #e6d6b0; --blue: #3b6fd4; --blue2: #6f9bf0; --blue3: #254a94;
  --red: #d4453b; --gold: #f5c542; --green: #5da64a;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --round: ui-rounded, "SF Pro Rounded", system-ui, sans-serif;
  --type: "American Typewriter", "Courier New", monospace;
  --sat: env(safe-area-inset-top, 0px); --sar: env(safe-area-inset-right, 0px);
  --sab: env(safe-area-inset-bottom, 0px); --sal: env(safe-area-inset-left, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; }
html, body { margin: 0; padding: 0; height: 100%; overflow: hidden; background: #1c1a26; overscroll-behavior: none; touch-action: none; position: fixed; inset: 0; width: 100%; }
body { height: 100dvh; font-family: var(--serif); color: var(--ink); }
#world { position: fixed; left: 0; top: 0; display: block; touch-action: none; background: #1c1a26; }
#hud, #screens { position: fixed; inset: 0; pointer-events: none; overflow: hidden; height: 100dvh; }
#hud > *, #screens > * { pointer-events: auto; }
button { font: inherit; color: inherit; touch-action: none; }

/* ---------- storybook parts ---------- */
.parch { background: var(--parch); border: 2px solid var(--ink); border-radius: 10px; box-shadow: 3px 3px 0 var(--ink); }
.btn { position: relative; display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-width: 44px; min-height: 44px; padding: 4px 8px; background: var(--parch); border: 2px solid var(--ink); border-radius: 9px; box-shadow: 2px 2px 0 var(--ink); cursor: pointer; font-family: var(--serif); font-size: 14px; font-weight: 700; color: var(--ink); transition: transform .05s; }
.btn:active, .btn.down { transform: translate(2px, 2px); box-shadow: none; }
.btn.blue { background: var(--blue); color: var(--parch); }
.btn.red { background: var(--red); color: var(--parch); }
.btn.grey { opacity: .55; filter: saturate(.35); }
.btn canvas { display: block; pointer-events: none; }
.rnd { font-family: var(--round); font-variant-numeric: tabular-nums; }

/* top bar */
#top { position: absolute; top: calc(var(--sat) + 6px); left: calc(var(--sal) + 8px); right: calc(var(--sar) + 8px); display: flex; gap: 6px; align-items: center; pointer-events: none; }
#top > * { pointer-events: auto; }
.chip { display: flex; align-items: center; gap: 5px; height: 36px; padding: 0 9px 0 5px; font: 700 17px var(--round); font-variant-numeric: tabular-nums; }
.chip canvas { width: 26px; height: 26px; }
.chip.flash { animation: shake .45s, redflash .45s; }
@keyframes shake { 0%,100% { transform: translateX(0) } 20% { transform: translateX(-4px) } 40% { transform: translateX(4px) } 60% { transform: translateX(-3px) } 80% { transform: translateX(3px) } }
@keyframes redflash { 0%,100% { background: var(--parch) } 30% { background: #f19a8f } }
#top .sp { flex: 1; pointer-events: none; }
#pauseBtn { padding: 0; width: 44px; height: 44px; }
#pauseBtn canvas { width: 30px; height: 30px; }

/* to do tab */
#todo { position: absolute; top: calc(var(--sat) + 54px); left: calc(var(--sal) + 8px); width: min(270px, calc(100vw - 100px)); padding: 0; z-index: 3; overflow: hidden; }
#todo .t-head { display: flex; align-items: center; gap: 8px; min-height: 36px; padding: 5px 10px 5px 8px; cursor: pointer; font-size: 13px; line-height: 1.15; }
#todo .t-list { display: none; padding: 2px 10px 8px 8px; border-top: 2px dashed rgba(43,34,51,.35); }
#todo.open .t-list { display: block; }
#todo.open { z-index: 6; }
#todo .t-title { font: 700 12px var(--round); opacity: .75; margin: 4px 0 2px; }
.box { flex: none; width: 16px; height: 16px; border: 2px solid var(--ink); border-radius: 4px; background: #fffaf0; position: relative; }
.box.done::after { content: ""; position: absolute; left: 3px; top: -1px; width: 5px; height: 10px; border: solid var(--green); border-width: 0 3px 3px 0; transform: rotate(40deg); animation: tick .35s cubic-bezier(.3,1.6,.5,1); }
@keyframes tick { from { transform: rotate(40deg) scale(0); } to { transform: rotate(40deg) scale(1); } }
.t-row { display: flex; align-items: center; gap: 8px; padding: 4px 0; font-size: 13px; line-height: 1.15; }
.t-row.done span { text-decoration: line-through; opacity: .6; }
.chev { margin-left: auto; width: 0; height: 0; border-left: 5px solid transparent; border-right: 5px solid transparent; border-top: 6px solid var(--ink); transition: transform .15s; }
#todo.open .chev { transform: rotate(180deg); }

/* toasts */
#toasts { position: absolute; top: calc(var(--sat) + 96px); left: calc(var(--sal) + 8px); right: calc(var(--sar) + 8px); max-width: 480px; display: flex; flex-direction: column; gap: 6px; pointer-events: none; z-index: 4; }
.toast { pointer-events: auto; padding: 7px 10px; font-size: 13.5px; line-height: 1.22; border-left-width: 7px; transform: translateY(-14px); opacity: 0; transition: transform .22s cubic-bezier(.3,1.5,.5,1), opacity .18s; cursor: pointer; }
.toast.in { transform: none; opacity: 1; }
.toast.out { transform: translateY(-10px); opacity: 0; }
.toast.bad { border-left-color: var(--red); } .toast.warn { border-left-color: #e0a020; } .toast.good { border-left-color: var(--green); } .toast.info { border-left-color: var(--blue2); }
.toast.clerk { display: grid; grid-template-columns: 46px 1fr; gap: 8px; align-items: center; border-left-color: var(--blue); padding: 6px 10px 6px 6px; }
.toast.clerk .who { font: 700 11px var(--round); opacity: .7; margin-bottom: 1px; }
.toast.clerk .line { font-size: 14px; font-style: italic; }
.toast.clerk .face { width: 46px; height: 46px; background: #e6d6b0; border: 2px solid var(--ink); border-radius: 8px; display: grid; place-items: center; overflow: hidden; }
.toast.clerk .face canvas { width: 42px; height: 42px; }
.toast .arrowgo { float: right; margin-left: 6px; font: 700 12px var(--round); opacity: .6; }

/* memo */
#memo { position: absolute; top: calc(var(--sat) + 236px); right: calc(var(--sar) + 8px); width: min(236px, 62vw); z-index: 5; transform: translateX(130%) rotate(10deg); transform-origin: 100% 0; transition: transform .45s cubic-bezier(.25,1.45,.5,1), visibility 0s .5s; pointer-events: none; visibility: hidden; }
#memo.in { transform: rotate(2.2deg); pointer-events: auto; visibility: visible; transition: transform .45s cubic-bezier(.25,1.45,.5,1), visibility 0s; }
#memo .sheet { position: relative; background: #fbf7e8; border: 2px solid var(--ink); box-shadow: 4px 4px 0 var(--ink); padding: 9px 11px 34px; font-family: var(--type); }
#memo .sheet::before { content: ""; position: absolute; left: 14px; top: -9px; width: 14px; height: 26px; border: 3px solid #8c8a94; border-radius: 8px; background: transparent; }
#memo .head { display: flex; align-items: center; gap: 7px; padding-bottom: 6px; border-bottom: 2px solid var(--ink); }
#memo .head canvas { width: 30px; height: 30px; flex: none; }
#memo .firm { font: 700 11px/1.15 var(--type); }
#memo .subj { font: 700 14px/1.2 var(--type); margin: 8px 0 5px; }
#memo .body { font: 12px/1.38 var(--type); }
#memo .ring { position: absolute; right: 10px; bottom: 8px; width: 34px; height: 34px; border-radius: 50%; border: 4px solid rgba(150,100,60,.25); transform: scale(1, .92); }
#memo .stamp { position: absolute; right: 36px; bottom: 6px; width: 26px; height: 26px; border: 3px solid rgba(212,69,59,.6); border-radius: 50%; transform: rotate(-14deg); }

/* speech bubbles */
#bubbles { position: absolute; inset: 0; pointer-events: none !important; z-index: 2; }
.bubble { position: absolute; left: 0; top: 0; max-width: 176px; padding: 5px 9px 6px; background: var(--parch); border: 2px solid var(--ink); border-radius: 12px; font: 13px/1.22 var(--serif); color: var(--ink); text-align: center; pointer-events: none; will-change: transform; opacity: 0; transition: opacity .15s; }
.bubble.show { opacity: 1; }
.bubble::after { content: ""; position: absolute; left: var(--tx, 50%); bottom: -7px; width: 10px; height: 10px; background: var(--parch); border: solid var(--ink); border-width: 0 2px 2px 0; transform: translateX(-50%) rotate(45deg); }
.bubble.goblin { background: #eef0e2; }

/* bottom block */
#bottom { position: absolute; left: calc(var(--sal) + 8px); right: calc(var(--sar) + 8px); bottom: calc(var(--sab) + 8px); max-width: 700px; display: flex; flex-direction: column; gap: 8px; pointer-events: none; z-index: 3; }
#bottom > * { pointer-events: none; }
.edge-row { display: flex; justify-content: flex-end; gap: 8px; }
.edge-row .btn { pointer-events: auto; min-width: 52px; min-height: 52px; padding: 4px; }
.edge-row .btn canvas { width: 34px; height: 34px; }
.edge-row .btn .badge { position: absolute; right: -6px; top: -8px; min-width: 22px; height: 22px; padding: 0 4px; border-radius: 11px; background: var(--red); color: #fff; border: 2px solid var(--ink); font: 700 12px/18px var(--round); text-align: center; }
.edge-row .btn.hide { display: none; }
.bottom-row { display: flex; gap: 8px; align-items: flex-end; }
#mini { flex: none; pointer-events: auto; padding: 0; width: 90px; height: 138px; overflow: hidden; position: relative; touch-action: none; }
#mini canvas { display: block; position: absolute; left: 3px; top: 3px; border-radius: 6px; touch-action: none; }
#panel { pointer-events: auto; flex: 1; min-width: 0; padding: 7px 8px 8px; min-height: var(--mh, 138px); display: flex; flex-direction: column; gap: 5px; position: relative; }
#panel .tip { margin: auto 0; font-size: 13.5px; font-style: italic; line-height: 1.3; padding: 4px 6px; }
.p-head { display: flex; align-items: center; gap: 8px; min-height: 44px; }
.p-icon { flex: none; width: 44px; height: 44px; background: #e6d6b0; border: 2px solid var(--ink); border-radius: 8px; display: grid; place-items: center; position: relative; }
.p-icon canvas { width: 38px; height: 38px; }
.p-name { font: 700 15px/1.1 var(--serif); }
.p-hp { display: flex; align-items: center; gap: 6px; margin-top: 3px; font: 11px var(--round); font-variant-numeric: tabular-nums; }
.hpbar { flex: 1; height: 8px; min-width: 40px; background: #4a4352; border: 2px solid var(--ink); border-radius: 4px; overflow: hidden; }
.hpbar i { display: block; height: 100%; background: #6cc24a; }
.hpbar i.mid { background: #f2c230; } .hpbar i.low { background: #e0463c; } .hpbar i.build { background: #6f9bf0; }
.p-grow { flex: 1; min-width: 0; }
.p-close { flex: none; width: 44px; height: 44px; padding: 0; font: 700 20px var(--round); }
.p-desc { font-size: 12px; font-style: italic; line-height: 1.25; }
.p-sel { font-size: 12px; line-height: 1.25; margin-top: -1px; }
.p-note { font: 12px var(--round); display: flex; align-items: center; gap: 4px; }
.p-note canvas { width: 16px; height: 16px; }
.p-stats { font: 11px var(--round); display: flex; flex-wrap: wrap; gap: 2px 10px; font-variant-numeric: tabular-nums; }
.p-cmds { display: flex; flex-wrap: wrap; gap: 6px; margin-top: auto; align-items: stretch; }
.p-cmds.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); }
.p-queue { display: flex; gap: 5px; }
.cmd { flex-direction: column; gap: 1px; min-width: 56px; min-height: 60px; padding: 3px 4px 2px; font-size: 11px; line-height: 1.1; }
.cmd canvas { width: 34px; height: 34px; }
.cmd .lab { font: 700 11px var(--serif); }
.cmd .badge, .qchip .badge { position: absolute; right: -5px; top: -7px; min-width: 20px; height: 20px; padding: 0 4px; border-radius: 10px; background: var(--blue); color: var(--parch); border: 2px solid var(--ink); font: 700 11px/16px var(--round); text-align: center; }
.cmd .sup { position: absolute; left: 3px; top: 2px; display: flex; align-items: center; gap: 1px; font: 700 10px var(--round); }
.cmd .sup canvas { width: 11px; height: 11px; }
.cmd .done { position: absolute; right: 2px; top: 1px; font: 700 14px var(--round); color: var(--green); }
.price { display: flex; gap: 3px; font: 700 10px var(--round); font-variant-numeric: tabular-nums; align-items: center; white-space: nowrap; }
.price span { display: flex; align-items: center; gap: 1px; }
.price canvas { width: 11px; height: 11px; }
.cmd.wide { flex-direction: row; justify-content: flex-start; gap: 4px; min-height: 48px; padding: 3px 4px; text-align: left; overflow: hidden; }
.cmd.wide canvas { width: 30px; height: 30px; }
.cmd.wide .lab { font-size: 11.5px; white-space: nowrap; }
.cmd.wide .col { display: flex; flex-direction: column; gap: 2px; min-width: 0; align-items: flex-start; }
.cmd.wide canvas { flex: none; }
.big { flex: 1; min-height: 54px; font-size: 15px; white-space: nowrap; gap: 4px; padding: 4px 6px; }
.big canvas { width: 24px; height: 24px; }
.qchip { position: relative; width: 46px; height: 46px; padding: 0; }
.qchip canvas { width: 32px; height: 32px; }
.qchip svg { position: absolute; inset: 1px; width: 42px; height: 42px; pointer-events: none; }
.qchip svg circle { fill: none; stroke-width: 4; }
.qchip svg .bg { stroke: rgba(43,34,51,.18); } .qchip svg .fg { stroke: var(--blue); stroke-linecap: round; transform: rotate(-90deg); transform-origin: 50% 50%; }
.grp { position: relative; width: 52px; flex: none; min-height: 52px; padding: 3px 2px 2px; flex-direction: column; gap: 2px; }
.grp canvas { width: 32px; height: 32px; }
.grp .hpbar { width: 40px; flex: none; height: 6px; min-width: 0; }
.grp .badge { position: absolute; right: -5px; top: -7px; min-width: 20px; height: 20px; padding: 0 4px; border-radius: 10px; background: var(--blue); color: var(--parch); border: 2px solid var(--ink); font: 700 11px/16px var(--round); text-align: center; }
.groups { display: flex; flex-wrap: wrap; gap: 8px 8px; padding-top: 6px; }

@keyframes pulse { 0%,100% { box-shadow: 2px 2px 0 var(--ink), 0 0 0 0 rgba(245,197,66,.9); transform: scale(1); } 50% { box-shadow: 2px 2px 0 var(--ink), 0 0 0 7px rgba(245,197,66,0); transform: scale(1.07); } }
.btn.pulse { animation: pulse 1.1s infinite; border-color: var(--ink); background: #ffe27a; }

/* layouts */
@media (min-width: 700px) {
  #bottom { max-width: 640px; }
  #panel { flex-direction: row; gap: 14px; }
  #panel .p-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 5px; }
  #panel .p-side { flex: 1.1; min-width: 0; display: flex; flex-direction: column; gap: 6px; justify-content: flex-end; }
}
@media (max-width: 699px) { #panel .p-main, #panel .p-side { display: contents; } #panel { display: flex; } }
@media (max-height: 460px) {
  #todo { top: calc(var(--sat) + 52px); }
  #toasts { top: calc(var(--sat) + 52px); left: calc(var(--sal) + 290px); width: 300px; right: auto; }
  #memo { top: calc(var(--sat) + 74px); }
}

/* ---------- screens ---------- */
.screen { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: calc(var(--sat) + 14px) calc(var(--sar) + 14px) calc(var(--sab) + 12px) calc(var(--sal) + 14px); overflow-y: auto; touch-action: pan-y; }
.screen.veil { background: rgba(43,34,51,.55); }
.card { width: min(420px, 100%); padding: 16px 16px 14px; display: flex; flex-direction: column; gap: 10px; text-align: center; }
.card h1 { margin: 0; font: 800 36px/1 var(--serif); letter-spacing: 0; }
.card h2 { margin: 0; font: 800 26px/1.05 var(--serif); }
.sub { font: italic 15px/1.25 var(--serif); }
.tag { align-self: center; padding: 1px 10px 2px; font: 700 12px var(--round); background: var(--gold); border: 2px solid var(--ink); border-radius: 999px; transform: rotate(-3deg); box-shadow: 2px 2px 0 var(--ink); }
.choices { display: flex; flex-direction: column; gap: 6px; text-align: left; }
.choice { display: flex; flex-direction: column; align-items: flex-start; gap: 0; width: 100%; padding: 6px 10px; font-weight: 400; text-align: left; min-height: 48px; }
.choice b { font-size: 15px; } .choice i { font-size: 12.5px; opacity: .85; }
.choice.on { background: var(--blue); color: var(--parch); }
.row { display: flex; gap: 8px; justify-content: center; align-items: center; }
.play { min-height: 56px; font-size: 20px; width: 100%; }
.howlist { text-align: left; margin: 0; padding-left: 18px; font-size: 14px; line-height: 1.3; }
.howlist li { margin: 0 0 5px; }
.small { font: 12px var(--round); opacity: .8; }
.tgl { padding: 0 10px; gap: 6px; }
.tgl canvas { width: 28px; height: 28px; }
.tgl.off { opacity: .6; }
.statrow { display: flex; justify-content: space-between; gap: 12px; padding: 3px 4px; border-bottom: 1px dotted rgba(43,34,51,.4); font: 14px var(--serif); }
.statrow b { font: 700 14px var(--round); font-variant-numeric: tabular-nums; }
.clerkline { display: grid; grid-template-columns: 52px 1fr; gap: 10px; align-items: center; text-align: left; font-style: italic; font-size: 14px; line-height: 1.25; }
.clerkline .face { width: 52px; height: 52px; background: #e6d6b0; border: 2px solid var(--ink); border-radius: 8px; display: grid; place-items: center; }
.clerkline .face canvas { width: 46px; height: 46px; }
#curtain { background: var(--parch); box-shadow: inset 0 0 0 10px var(--parch2), inset 0 0 0 12px var(--ink); }
#curtain .face { width: 84px; height: 84px; margin-bottom: 18px; background: var(--parch2); border: 3px solid var(--ink); border-radius: 50%; box-shadow: 3px 3px 0 var(--ink); display: grid; place-items: center; animation: bob 1.4s infinite; }
#curtain .face canvas { width: 64px; height: 64px; }
#curtain .tipline { max-width: 320px; font: italic 19px/1.3 var(--serif); text-align: center; }
.dots { display: flex; gap: 8px; margin-top: 22px; }
.dots i { width: 10px; height: 10px; border-radius: 50%; background: var(--ink); animation: bob 1s infinite; }
.dots i:nth-child(2) { animation-delay: .15s; } .dots i:nth-child(3) { animation-delay: .3s; }
@keyframes bob { 0%,100% { transform: translateY(0); opacity: .35; } 40% { transform: translateY(-7px); opacity: 1; } }
#title { justify-content: space-between; }
#title .logo { display: flex; flex-direction: column; align-items: center; gap: 4px; padding-top: 6px; text-align: center; }
#title h1 { margin: 0; font: 800 44px/0.95 var(--serif); color: var(--parch); -webkit-text-stroke: 9px var(--ink); paint-order: stroke fill; text-shadow: 3px 4px 0 var(--ink); }
#title .ribbon { margin-top: 8px; padding: 3px 14px 4px; background: var(--parch); border: 2px solid var(--ink); border-radius: 6px; box-shadow: 3px 3px 0 var(--ink); font: italic 14px var(--serif); }
#title .card { margin-top: auto; margin-bottom: 4px; }
@media (max-height: 460px) {
  #title { flex-direction: row; justify-content: space-around; align-items: center; gap: 12px; }
  #title .card { margin: 0; width: min(380px, 52vw); gap: 6px; padding: 10px; }
  #title .logo { flex: 1; }
  #title .studio { position: absolute; bottom: 6px; left: 14px; }
  .choice { min-height: 40px; padding: 3px 10px; }
  .play { min-height: 46px; }
}
#title .studio { font: 12px var(--round); color: #f2e6c9; text-shadow: 0 1px 0 #2b2233; padding-top: 6px; }
.confetti { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.confetti i { position: absolute; top: -30px; width: 12px; height: 12px; border-radius: 3px; animation: fall linear infinite; }
@keyframes fall { to { transform: translateY(110vh) rotate(540deg); } }
.leaf { position: absolute; top: -30px; width: 14px; height: 9px; background: #c9893c; border: 2px solid var(--ink); border-radius: 80% 0 80% 0; animation: leaf 7s linear infinite; }
@keyframes leaf { 0% { transform: translate(0,0) rotate(0); } 50% { transform: translate(36px, 55vh) rotate(160deg); } 100% { transform: translate(-10px, 110vh) rotate(360deg); } }
.fade-in { animation: fadein .3s both; }
@keyframes fadein { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
