@font-face { font-family: 'Berkshire Swash'; src: url(fonts/BerkshireSwash-Regular.woff2) format('woff2'); font-display: block; }
@font-face { font-family: 'Nunito'; src: url(fonts/Nunito.woff2) format('woff2'); font-weight: 200 1000; font-display: block; }
@font-face { font-family: 'Courier Prime'; src: url(fonts/CourierPrime-Regular.woff2) format('woff2'); font-display: swap; }
@font-face { font-family: 'Courier Prime'; src: url(fonts/CourierPrime-Bold.woff2) format('woff2'); font-weight: 700; font-display: swap; }
@font-face { font-family: 'Caveat'; src: url(fonts/Caveat.woff2) format('woff2'); font-weight: 400 700; font-display: swap; }

:root {
  --paper: #f7ecd6; --paper2: #efdcb8; --ink: #3a2415; --ink2: #6b4a30; --line: #5a3a22;
  --red: #9e2a2b; --red2: #c43d3a; --green: #2f5d3a; --gold: #d9a441; --wood: #7a4a2a; --wood2: #a0673c;
  --bg: #2a1a12; --noel: #3fd47a; --amber: #ffb347; --hand: #c9463d;
  --title: 'Berkshire Swash', 'Nunito', serif; --body: 'Nunito', system-ui, sans-serif; --mono: 'Courier Prime', 'Courier New', monospace;
  --sat: env(safe-area-inset-top, 0px); --sab: env(safe-area-inset-bottom, 0px); --sal: env(safe-area-inset-left, 0px); --sar: env(safe-area-inset-right, 0px);
  --tab-h: 64px;
}
body.act2 { --paper: #f1ead8; --paper2: #dfe3cc; --bg: #1f2620; --wood: #5d4a33; --wood2: #7c6648; --gold: #c9a14a; }
body.act3 { --paper: #fbf7f1; --paper2: #f0e1d7; --bg: #1a1d2e; --wood: #7a2224; --wood2: #b8322f; --gold: #e0b44c; --ink: #2b1d1d; }
body.act4 { --paper: #1d2142; --paper2: #2a2f5c; --ink: #e8e6ff; --ink2: #b8b4e8; --line: #8a7cf0; --bg: #0b0d22; --wood: #3a2f6e; --wood2: #5544a0; --gold: #f0c35a; --red: #c3366e; }

* { box-sizing: border-box; }
html { overflow: hidden; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); font-family: var(--body);
  touch-action: manipulation; user-select: none; -webkit-user-select: none; -webkit-tap-highlight-color: transparent; }
body.booting #app { visibility: hidden; }
button { font-family: var(--body); font-weight: 800; color: var(--ink); cursor: pointer; }
[hidden] { display: none !important; }
img { -webkit-user-drag: none; }

#app { position: fixed; inset: 0; }
.screen { position: absolute; inset: 0; }

/* ---- generic buttons: wooden plaques ---- */
.paper button, .title-buttons button, .row button {
  min-height: 44px; padding: 8px 18px; font-size: 17px; border-radius: 12px; border: 2px solid var(--line);
  background: linear-gradient(#fff6e2, #ecd6ae); box-shadow: 0 3px 0 var(--line); color: #3a2415; text-wrap: balance;
}
.paper button:active, .title-buttons button:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--line); }
button.big { font-size: 20px; min-height: 52px; padding: 10px 26px; background: linear-gradient(#e0574e, #a8302d); color: #fff8ec; text-shadow: 0 1px 0 #5a1515; }
button.mitten { background: linear-gradient(#e46a55, #b23a30); color: #fff7ea; }
button.eye { background: linear-gradient(#5fe39a, #23864d); color: #04250f; }
button:disabled { opacity: 0.5; cursor: default; }
button:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }
.quiet-btn { background: none; border: none; color: inherit; opacity: 0.8; font-size: 15px; text-decoration: underline; min-height: 44px; }
.row { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; margin-top: 14px; }

.paper { background: var(--paper); color: var(--ink); border: 3px solid var(--line); border-radius: 18px; padding: 20px 22px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.45); position: relative; }
.paper::after { content: ''; position: absolute; top: -3px; right: 18px; width: 22px; height: 38px; background: var(--red);
  clip-path: polygon(0 0, 100% 0, 100% 100%, 50% 78%, 0 100%); }
body.act4 .paper { box-shadow: 0 0 0 1px #6f62e0 inset, 0 0 30px rgba(120,100,255,0.35); }
h2 { font-family: var(--title); font-weight: 400; font-size: 32px; margin: 0 0 10px; text-align: center; color: var(--red); text-wrap: balance; }
body.act4 h2 { color: var(--gold); }
p { text-wrap: pretty; }

/* ---- title ---- */
#title canvas, #actcard canvas, #ending canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.title-box { position: absolute; left: 50%; top: max(6vh, calc(var(--sat) + 12px)); transform: translateX(-50%); text-align: center; width: min(92vw, 560px); }
.game-name { font-family: var(--title); font-weight: 400; color: #fff4dc; font-size: clamp(44px, 9vw, 86px); margin: 0; line-height: 1;
  text-shadow: 0 3px 0 #6b1d1d, 0 0 24px rgba(255,200,120,0.6), 0 6px 18px rgba(0,0,0,0.6); }
.tagline { text-shadow: 0 1px 2px #000, 0 0 10px rgba(0,0,0,0.8) !important; color: #fff3dc; font-size: clamp(15px, 2.4vw, 19px); margin: 8px 0 18px; text-shadow: 0 2px 6px #000; font-style: italic; }
.title-buttons { display: flex; flex-direction: column; gap: 10px; align-items: center; }
.title-buttons button { min-width: 220px; }
.title-slot { color: #f5e6c8; font-size: 14px; text-shadow: 0 1px 4px #000; min-height: 1.2em; display: inline-block; padding: 2px 10px; border-radius: 10px; background: rgba(20,12,8,0.55); }
.title-slot:empty { display: none; }
.corner-btn { position: absolute; right: calc(12px + var(--sar)); bottom: calc(12px + var(--sab)); width: 48px; height: 48px; border-radius: 50%;
  border: 2px solid #f5e6c8; background: rgba(40,20,10,0.6); color: #f5e6c8; display: grid; place-items: center; }
.corner-btn svg, .icon-btn svg { width: 24px; height: 24px; }

/* ---- paper screens ---- */
.paper-screen { display: grid; place-items: center; background: radial-gradient(circle at 50% 30%, #3d2a1c, var(--bg)); overflow-y: auto; padding: calc(12px + var(--sat)) 12px calc(12px + var(--sab)); }
.paper.wide { width: min(96vw, 760px); max-height: calc(100% - 8px); overflow-y: auto; }
.slot-list { display: flex; flex-direction: column; gap: 10px; }
.slot { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border: 2px solid var(--line); border-radius: 12px; background: var(--paper2); }
.slot .slot-info { flex: 1; min-width: 0; }
.slot .slot-name { font-weight: 900; }
.slot .slot-sum { font-size: 14px; color: var(--ink2); }
.slot button { min-height: 44px; padding: 6px 14px; font-size: 15px; }
.howto-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.howto-card { background: var(--paper2); border: 2px solid var(--line); border-radius: 12px; padding: 10px; text-align: center; font-size: 15px; }
.howto-card img { width: 64px; height: 64px; object-fit: contain; }
.howto-card b { display: block; margin: 4px 0; }
.controls-list { columns: 2 240px; font-size: 14px; padding-left: 18px; margin: 12px 0 0; }
.controls-list li { break-inside: avoid; margin-bottom: 3px; }

/* ---- act title card ---- */
#actcard { display: grid; place-items: center; }
.actcard-box { width: min(92vw, 540px); text-align: center; }
.act-no { font-family: var(--title); font-size: 22px; margin: 0; color: var(--ink2); }
.act-title { font-size: clamp(34px, 7vw, 52px); }
.act-intro p { font-style: italic; margin: 6px 0; font-size: 17px; }
.legacy-note { margin-top: 12px; padding: 10px; border: 2px dashed var(--gold); border-radius: 12px; font-size: 15px; display: flex; gap: 10px; align-items: center; text-align: left; }
.legacy-note img { width: 96px; height: 72px; object-fit: cover; border: 3px solid var(--gold); border-radius: 4px; flex: none; }

/* ---- the act screen ---- */
#game { display: grid; background: var(--bg); padding: var(--sat) var(--sar) 0 var(--sal);
  grid-template-columns: 1fr; grid-template-rows: auto auto 1fr auto; grid-template-areas: 'top' 'center' 'shop' 'tabs'; }
#topbar { grid-area: top; background: linear-gradient(var(--wood2), var(--wood)); color: #fff6e6; border-bottom: 3px solid rgba(0,0,0,0.35); padding: 4px 8px; }
.tb-row { display: flex; align-items: center; gap: 8px; min-width: 0; }
.tb-row1 { min-height: 46px; }
.rank-title { font-family: var(--title); font-size: 21px; flex: 1; min-width: 0; line-height: 1.1; white-space: nowrap; overflow: hidden; text-shadow: 0 2px 0 rgba(0,0,0,0.4); }
.icon-btn { width: 44px; height: 44px; flex: none; border-radius: 12px; border: 2px solid rgba(255,240,210,0.7); background: rgba(0,0,0,0.25); color: #fff6e6; display: grid; place-items: center; padding: 0; }
.declare { position: relative; flex: none; height: 44px; min-width: 44px; border-radius: 12px; border: 2px solid #fff3d6; background: linear-gradient(#fff8e8, #f0dcb0); color: #7a1d1d;
  display: flex; align-items: center; gap: 6px; padding: 0 10px 0 4px; font-size: 14px; box-shadow: 0 0 0 0 rgba(255,210,120,0.0); transition: box-shadow 0.3s; }
.declare .declare-ico { width: 36px; height: 36px; background: url(assets/shared/icon-declare.webp) center/contain no-repeat; flex: none; }
.declare .declare-label { white-space: nowrap; }
.declare.locked { filter: saturate(0.4) brightness(0.85); }
.declare .declare-locks { position: absolute; inset: 0; pointer-events: none; }
.declare .declare-locks { overflow: hidden; border-radius: 10px; }
.declare .declare-locks .chain { position: absolute; left: -2px; right: -2px; top: 50%; height: 12px; margin-top: -6px; background: url(assets/locks/chain-run.webp) left center/auto 100% repeat-x; opacity: 0.95; }
.declare .declare-locks .chain.c1 { transform: rotate(9deg); } .declare .declare-locks .chain.c2 { transform: rotate(-9deg); }
.declare .declare-locks .pad { position: absolute; width: 20px; height: 20px; bottom: 1px; background: url(assets/locks/padlock-small.webp) center/contain no-repeat; }
.declare .hold-ring { position: absolute; right: -6px; top: -6px; width: 20px; height: 20px; border-radius: 50%; display: none;
  background: conic-gradient(var(--noel) calc(var(--hold, 0) * 1turn), rgba(0,0,0,0.3) 0); }
.declare.holding .hold-ring { display: block; }
.declare.glow { box-shadow: 0 0 0 4px rgba(255,214,120,0.9), 0 0 22px rgba(255,214,120,0.9); }
.declare.clank { animation: clank 0.5s; }
@keyframes clank { 0%,100% { transform: none; } 20% { transform: translateX(-4px) rotate(-3deg); } 50% { transform: translateX(4px) rotate(3deg); } 75% { transform: translateX(-2px); } }

.tb-row2 { gap: 10px; min-height: 34px; font-weight: 900; font-size: 16px; }
.stat { display: flex; align-items: center; gap: 4px; white-space: nowrap; }
.stat img { width: 24px; height: 24px; }
.stat.rate { font-size: 13px; opacity: 0.9; font-weight: 700; }
.prog-wrap { flex: 1; min-width: 70px; position: relative; }
.prog-bar { height: 18px; border-radius: 9px; background: rgba(0,0,0,0.35); border: 2px solid rgba(255,240,210,0.6); overflow: hidden; }
.prog-fill { height: 100%; width: 0; background: linear-gradient(90deg, #2f7d43, #d9b44a); transition: width 0.2s; }
.prog-label { position: absolute; inset: 0; display: flex; justify-content: center; align-items: center; font-size: 11px; font-weight: 900; text-shadow: 0 1px 2px #000; white-space: nowrap; overflow: hidden; }

#shelf { display: none; }
#center { grid-area: center; display: flex; flex-direction: column; min-height: 0; }
#stageWrap { position: relative; width: 100%; aspect-ratio: 4 / 3; overflow: hidden; background: #000; touch-action: none; cursor: pointer; }
#stage { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#banner { position: absolute; left: 50%; top: 4%; transform: translateX(-50%); background: rgba(255,246,226,0.95); color: #6b1d1d; border: 2px solid var(--line);
  border-radius: 12px; padding: 4px 12px; font-weight: 900; font-size: clamp(12px, 2.6vw, 17px); white-space: nowrap; max-width: 94%; overflow: hidden; text-overflow: ellipsis; pointer-events: none; }
#banner.gold { background: linear-gradient(#ffe8a0, #e8b84a); animation: pulse 1s infinite; }
@keyframes pulse { 50% { transform: translateX(-50%) scale(1.05); } }
#tapHint { position: absolute; left: 50%; top: 42%; transform: translateX(-50%); pointer-events: none; text-align: center; color: #fff; font-weight: 900; font-size: 20px; text-shadow: 0 2px 4px #000; }
#tapHint .hand { display: block; width: 44px; height: 44px; margin: 0 auto 4px; border-radius: 50%; background: radial-gradient(circle, #fff 30%, rgba(255,255,255,0) 70%); animation: bounce 0.8s infinite; }
@keyframes bounce { 50% { transform: translateY(-12px); } }
.ticker { position: absolute; left: 0; right: 0; bottom: 0; background: rgba(10,20,12,0.72); color: var(--noel); font-family: var(--mono); font-size: clamp(11px, 2.2vw, 14px);
  padding: 3px 8px; pointer-events: none; min-height: 1.6em; text-wrap: balance; line-height: 1.25; }
.ticker:empty, .ticker.empty { display: none; }
#jobStrip { display: flex; align-items: center; gap: 8px; padding: 3px 8px; background: rgba(0,0,0,0.4); color: #fff6e6; min-height: 28px; }
.job-name { font-weight: 900; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 52%; }
.work-bar { flex: 1; height: 14px; border-radius: 7px; background: #fff; border: 2px solid #5a1d1d; overflow: hidden;
  background: repeating-linear-gradient(135deg, #fff 0 8px, #f1d6d6 8px 16px); }
.work-fill { height: 100%; width: 0; background: repeating-linear-gradient(135deg, #d23a34 0 8px, #ffffff 8px 16px); }
.work-bar.gold { box-shadow: 0 0 10px #ffd36a; border-color: #b07a10; }
.work-bar.gold .work-fill { background: repeating-linear-gradient(135deg, #e8b84a 0 8px, #fff2c0 8px 16px); }
.counter { font-size: 12px; font-weight: 800; white-space: nowrap; opacity: 0.95; }

#shop { grid-area: shop; display: flex; flex-direction: column; min-height: 0; background: var(--paper); border-top: 3px solid var(--line); }
#shopTabs { display: none; }
#panel { flex: 1; overflow-y: auto; overscroll-behavior: contain; padding: 6px 8px 10px; -webkit-overflow-scrolling: touch; }
.sec { display: none; }
.sec.on { display: block; }
.sec-head { font-family: var(--title); font-size: 20px; color: var(--red); margin: 2px 2px 6px; }
body.act4 .sec-head { color: var(--gold); }
#tabbar { grid-area: tabs; display: flex; background: linear-gradient(var(--wood), #3a2415); padding-bottom: var(--sab); border-top: 2px solid rgba(0,0,0,0.4); }
.tab { flex: 1; min-width: 0; height: var(--tab-h); border: none; background: none; color: #f3e2c4; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: 12px; position: relative; padding: 0 2px; }
.tab img { width: 30px; height: 30px; object-fit: contain; }
.tab span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.tab.on { background: rgba(255,240,210,0.18); color: #fff; box-shadow: inset 0 -4px 0 var(--gold); }
.tab .dot { position: absolute; top: 8px; right: calc(50% - 22px); width: 10px; height: 10px; border-radius: 50%; background: #ff5040; border: 2px solid #fff; display: none; }
.tab.dotted .dot { display: block; }
.tab.glow { animation: glow 1s infinite; }
@keyframes glow { 50% { background: rgba(255,214,120,0.45); } }

/* ---- shop items ---- */
.item { display: flex; align-items: center; gap: 8px; width: 100%; text-align: left; padding: 6px 8px; margin-bottom: 6px; min-height: 56px;
  border: 2px solid var(--line); border-radius: 12px; background: linear-gradient(#fff6e2, #ecd6ae); color: #3a2415; position: relative; font-weight: 700; }
body.act4 .item { background: linear-gradient(#f2efff, #cfc9f5); }
.item img { width: 44px; height: 44px; object-fit: contain; flex: none; }
.item .it-main { flex: 1; min-width: 0; }
.item .it-name { font-weight: 900; font-size: 15px; line-height: 1.15; }
.item .it-desc { font-size: 12.5px; color: #6b4a30; line-height: 1.2; text-wrap: balance; }
.item .it-name { text-wrap: balance; }
.howto-card { text-wrap: balance; }
.item .it-side { text-align: right; flex: none; font-size: 13px; font-weight: 900; }
.item .it-cost { display: flex; align-items: center; gap: 3px; justify-content: flex-end; white-space: nowrap; }
.item .it-cost img { width: 18px; height: 18px; }
.item .it-count { font-size: 12px; color: #6b4a30; white-space: nowrap; }
.item.cant { opacity: 0.62; }
.item.cant .it-cost { color: #a03030; }
.item.owned { opacity: 0.75; background: linear-gradient(#e8f0d8, #cfdcb4); }
.item.locked { opacity: 0.5; filter: grayscale(0.7); }
.item.flash { animation: flash 0.35s; }
@keyframes flash { 50% { background: #fff; transform: scale(1.02); } }
.item.shake { animation: shake 0.35s; }
@keyframes shake { 25% { transform: translateX(-5px); } 75% { transform: translateX(5px); } }
.item.glowing { box-shadow: 0 0 0 3px var(--gold), 0 0 14px var(--gold); }
.item.sel { box-shadow: 0 0 0 3px var(--red2) inset; }
.item .tally { font-family: var(--mono); font-size: 12px; background: linear-gradient(#e8c66a, #b88a2a); color: #3a2415; border-radius: 4px; padding: 0 4px; border: 1px solid #7a5a1a; }
.item .tally.goldplate { background: linear-gradient(#fff2a0, #e0a020); }
.item .mini-bar { position: absolute; left: 58px; right: 10px; bottom: 3px; height: 3px; background: rgba(0,0,0,0.12); border-radius: 2px; overflow: hidden; }
.item .mini-bar i { display: block; height: 100%; background: var(--red2); width: 0; }
.ribbon { position: absolute; top: -2px; right: 8px; background: var(--red2); color: #fff; font-size: 10.5px; font-weight: 900; padding: 1px 6px 2px; border-radius: 0 0 6px 6px; white-space: nowrap; }
.ribbon.pad::before { content: ''; display: inline-block; width: 11px; height: 11px; margin-right: 3px; vertical-align: -1px; background: url(assets/locks/padlock-small.webp) center/contain no-repeat; }
.item .warn { font-size: 12px; color: #a01818; font-weight: 900; }
.noel-plate { width: 44px; height: 44px; flex: none; border-radius: 8px; background: linear-gradient(135deg, #e8c46a, #9a6a1a); border: 2px solid #5a3a10; display: grid; place-items: center; color: #3a2408; font-family: var(--mono); font-weight: 700; font-size: 20px; box-shadow: inset 0 0 0 2px rgba(255,240,180,0.6); }

/* helpers: twins side by side */
.meter { position: sticky; top: -6px; z-index: 2; background: var(--paper); padding: 4px 2px 6px; margin: -6px -2px 6px; border-bottom: 2px solid var(--line); min-height: 32px; }
.meter-bar { height: 6px; border-radius: 3px; background: var(--noel); overflow: hidden; position: relative; }
.meter-bar i { display: block; height: 100%; background: var(--hand); }
.meter-bar .tick { position: absolute; top: -3px; width: 3px; height: 12px; background: #222; }
.meter-line { font-size: 12.5px; font-weight: 900; margin-top: 3px; display: flex; gap: 6px; align-items: center; }
.meter-line .warm { color: #b8481f; } .meter-line .od { color: #1c8a4a; }
.meter-ring { width: 16px; height: 16px; border-radius: 50%; background: conic-gradient(var(--noel) calc(var(--hold, 0) * 1turn), rgba(0,0,0,0.15) 0); flex: none; }
.meter.warmglow { box-shadow: 0 6px 12px -6px rgba(255,140,60,0.8); }
.twins { display: flex; gap: 6px; margin-bottom: 6px; }
.twins .item { flex: 1 1 0; min-width: 0; margin: 0; padding: 4px 6px 4px 4px; gap: 6px; min-height: 58px; align-items: center; }
.twins .item img { width: 40px; height: 40px; }
.twins .item .badge { width: 16px; height: 16px; }
.twins .item .it-main { min-width: 0; }
.twins .item .it-name { font-size: 12.5px; line-height: 1.1; text-wrap: balance; }
.twins .item .it-row { display: flex; justify-content: space-between; gap: 4px; align-items: center; font-size: 13px; font-weight: 900; }
.twins .item .it-row .it-cost { display: inline-flex; }
.twins .item .it-desc { font-size: 11.5px; }
.twins .item .it-count { font-size: 12px; color: #6b4a30; }
.twins .hand-side { border-left: 6px solid var(--hand); }
.twins .noel-side { border-left: 6px solid var(--noel); }
.badge { position: absolute; top: 2px; left: 2px; width: 18px; height: 18px; }
.legacy-row { display: flex; gap: 8px; align-items: center; border: 3px solid var(--gold); border-radius: 12px; padding: 4px 8px; margin-bottom: 6px; background: linear-gradient(#fff5d6, #f2dca4); color: #3a2415; font-size: 13px; font-weight: 800; }
.legacy-row img { width: 60px; height: 45px; object-fit: cover; border-radius: 3px; border: 2px solid #8a6a1a; }

.noel-head { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.noel-head canvas { width: 64px; height: 64px; flex: none; }
.noel-head .ins { font-weight: 900; font-size: 18px; display: flex; gap: 4px; align-items: center; }
.noel-head .ins img { width: 24px; height: 24px; }
.noel-head .thinking { font-family: var(--mono); font-size: 12.5px; color: #1d6a3c; }
body.act4 .noel-head .thinking { color: var(--noel); }
.asleep-note { font-size: 14px; color: var(--ink2); font-style: italic; }

/* ---- cards ---- */
#cardLayer, #pauseLayer { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(10,5,2,0.55); z-index: 20; padding: calc(10px + var(--sat)) 10px calc(10px + var(--sab)); }
#pauseLayer { z-index: 30; }
.card { width: min(94vw, 520px); max-height: 100%; overflow-y: auto; text-align: center; animation: slidein 0.35s cubic-bezier(.2,1.4,.5,1); }
@keyframes slidein { from { transform: translateY(40px) scale(0.9); opacity: 0; } }
.card.flip { animation: flip 0.4s; }
@keyframes flip { 50% { transform: rotateY(90deg); } }
.card .portrait { width: 112px; height: 112px; object-fit: contain; margin: -4px auto 4px; display: block; }
.card .portrait-c { width: 112px; height: 112px; margin: -4px auto 4px; display: block; }
.card .speech { font-size: 17px; font-style: italic; margin: 6px 0; }
.card .speech.noel { font-family: var(--mono); font-style: normal; color: #1d6a3c; font-size: 16px; }
body.act4 .card .speech.noel { color: var(--noel); }
.card .big-title { font-family: var(--title); font-size: clamp(26px, 6vw, 38px); color: var(--red); margin: 6px 0; line-height: 1.1; text-wrap: balance; }
body.act4 .card .big-title { color: var(--gold); }
.card .unlocks { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin: 6px 0; font-size: 14px; font-weight: 800; }
.card .unlocks div { display: flex; flex-direction: column; align-items: center; width: 92px; }
.card .unlocks img { width: 56px; height: 56px; object-fit: contain; }
.card .wish { background: var(--paper2); border-radius: 12px; padding: 8px; margin: 8px 0; font-size: 15px; }
.card .choice-row { display: flex; gap: 10px; justify-content: center; margin-top: 10px; }
.card .choice-row button { flex: 1; max-width: 220px; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px; }
.card .choice-row button img { width: 36px; height: 36px; }
.card .choice-row button small { font-size: 12.5px; font-weight: 700; opacity: 0.95; }
.card .stats { font-size: 14px; color: var(--ink2); margin: 6px 0; }
.card .lock-rows { text-align: left; margin: 8px 0; }
.card .lock-row { display: flex; gap: 8px; align-items: center; padding: 4px; border-bottom: 1px dashed var(--line); }
.card .lock-row img { width: 48px; height: 48px; object-fit: contain; }
.card .lock-row .lr-main { flex: 1; font-size: 14px; }
.card .lock-row button { min-height: 44px; font-size: 14px; padding: 4px 12px; }
.card .hands-bar { height: 16px; border-radius: 8px; background: var(--noel); position: relative; overflow: hidden; margin: 6px 0 2px; border: 2px solid var(--line); }
.card .hands-bar i { position: absolute; left: 0; top: 0; bottom: 0; background: var(--hand); }
.card .hands-bar b { position: absolute; top: -2px; bottom: -2px; width: 3px; background: #111; }
.card .costs { font-size: 13px; text-align: left; margin: 6px 0; }
.card .postcard { width: 100%; border-radius: 6px; border: 6px solid #fff; box-shadow: 0 2px 8px rgba(0,0,0,0.4); }
.card .postcard-msg { font-family: 'Caveat', cursive; font-size: 26px; line-height: 1.15; color: #23305a; margin: 8px 0; transform: rotate(-1.5deg); }
.card .act-win-small { font-size: 13px; opacity: 0.8; }
.card .third { margin-top: 10px; }

/* ---- pause ---- */
#pauseBox h2 { margin-bottom: 6px; }
#pauseBox .col { display: flex; flex-direction: column; gap: 8px; align-items: stretch; max-width: 320px; margin: 0 auto; }
#pauseBox label { display: flex; align-items: center; justify-content: space-between; gap: 10px; font-weight: 800; min-height: 44px; }
#pauseBox input[type=range] { width: 150px; accent-color: var(--red); }
#pauseBox input[type=checkbox] { width: 26px; height: 26px; accent-color: var(--red); }
.credits { font-size: 13.5px; text-align: left; line-height: 1.4; }

/* ---- endings ---- */
.ending-text { transition: opacity 1s; position: absolute; left: 50%; bottom: calc(5% + var(--sab)); transform: translateX(-50%); width: min(90vw, 760px); text-align: center; color: #fff8ea;
  font-size: clamp(17px, 3.2vw, 24px); text-shadow: 0 2px 8px #000, 0 0 2px #000; pointer-events: none; }
.ending-text h3 { font-family: var(--title); font-weight: 400; font-size: clamp(30px, 7vw, 54px); margin: 0 0 10px; color: #ffe8b8; }
.ending-text p { margin: 6px 0; opacity: 0; transition: opacity 1.4s; }
.ending-text p.on, .ending-text h3.on { opacity: 1; }
.ending-text h3 { opacity: 0; transition: opacity 1.4s; }
.ending-credits { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(0,0,0,0.6); color: #fff2dc; text-align: center; font-size: 17px; line-height: 1.7; }
#endingSkip { position: absolute; right: calc(12px + var(--sar)); bottom: calc(12px + var(--sab)); color: #fff; }
.endings-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; margin-top: 10px; }
.frame { border: 6px solid #b8892a; border-radius: 6px; background: #2a1a12; aspect-ratio: 4/3; position: relative; overflow: hidden; display: grid; place-items: center; color: #f5e6c8; font-weight: 900; text-align: center; font-size: 14px; }
.frame img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.frame .fname { position: absolute; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,0.6); padding: 3px; font-size: 13px; }
.frame .early-rib { position: absolute; top: 6px; left: -22px; transform: rotate(-35deg); background: var(--red2); color: #fff; font-size: 11px; padding: 1px 26px; }
.frame .frost { position: absolute; top: 0; right: 0; width: 34px; height: 34px; background: linear-gradient(225deg, #bfe6ff 50%, transparent 50%); }
.frame .wrapped { width: 56px; height: 56px; background: url(assets/act1/presents-2.webp) center/contain no-repeat; display: grid; place-items: center; font-size: 28px; color: #fff; text-shadow: 0 2px 4px #000; }
.frame .hint { position: absolute; bottom: 6px; left: 4px; right: 4px; font-size: 12px; font-style: italic; }
.noel-line { font-family: var(--mono); text-align: center; color: #1d6a3c; }
.noel-line.small { font-size: 13px; opacity: 0.7; }

#toasts { position: absolute; left: 50%; bottom: calc(84px + var(--sab)); transform: translateX(-50%); z-index: 15; display: flex; flex-direction: column; gap: 6px; align-items: center; pointer-events: none; width: min(92vw, 420px); }
.toast { background: rgba(255,246,226,0.97); color: #3a2415; border: 2px solid var(--line); border-radius: 12px; padding: 6px 12px; font-weight: 800; font-size: 14px; text-align: center; animation: slidein 0.3s; }
.toast.noel { font-family: var(--mono); color: #0f5a2c; background: rgba(230,255,236,0.97); }

/* ---- desktop: three columns ---- */
@media (min-width: 900px) and (min-height: 501px) {
  #game { grid-template-columns: 250px 1fr 360px; grid-template-rows: auto 1fr; grid-template-areas: 'top top top' 'shelf center shop'; }
  #topbar .tb-row1, #topbar .tb-row2 { display: contents; }
  #topbar { display: flex; align-items: center; gap: 12px; padding: 6px 12px; }
  .rank-title { flex: 0 1 auto; max-width: 30%; font-size: 24px; }
  .prog-wrap { flex: 1; }
  #btnDeclare { order: 10; } #btnGear { order: 11; } #btnMute { order: 12; }
  .declare { padding-right: 14px; font-size: 14.5px; }
  #shelf { display: block; grid-area: shelf; overflow-y: auto; background: var(--paper); border-right: 3px solid var(--line); padding: 8px; }
  #center { justify-content: center; padding: 10px; min-width: 0; }
  #stageWrap { width: min(100%, calc((100vh - 130px) * 4 / 3)); margin: 0 auto; border-radius: 10px; border: 3px solid rgba(0,0,0,0.5); }
  #jobStrip { width: min(100%, calc((100vh - 130px) * 4 / 3)); margin: 6px auto 0; border-radius: 10px; }
  #shop { border-top: none; border-left: 3px solid var(--line); }
  #shopTabs { display: flex; background: linear-gradient(var(--wood), #3a2415); }
  #shopTabs .tab { height: 58px; flex-direction: column; font-size: 13px; gap: 1px; }
  #shopTabs .tab img { width: 26px; height: 26px; }
  #shopTabs .tab span { overflow: visible; }
  #tabbar { display: none; }
  .sec-jobs { display: block !important; }
}
/* ---- phones: landscape, short; and small landscape windows (800x600) ---- */
@media (orientation: landscape) and (max-height: 500px), (orientation: landscape) and (max-width: 899px) {
  #game { grid-template-columns: auto minmax(280px, 1fr); grid-template-rows: auto auto 1fr; grid-template-areas: 'center top' 'center tabs' 'center shop'; padding-bottom: var(--sab); }
  #center { justify-content: center; background: #000; }
  #stageWrap { width: min(calc((100vh - 28px - var(--sat) - var(--sab)) * 4 / 3), calc(100vw - 280px - var(--sal) - var(--sar))); height: auto; }
  .tb-row1 { gap: 4px; }
  #jobStrip { height: 28px; min-height: 28px; }
  #topbar { padding: 2px 6px; }
  .tb-row1 { min-height: 44px; }
  .rank-title { font-size: 15px; white-space: normal; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
  .declare .declare-label { display: none; }
  .declare { padding: 0 4px; }
  .tb-row2 { min-height: 30px; font-size: 14px; gap: 6px; }
  .stat.rate { display: none; }
  #tabbar { --tab-h: 48px; padding-bottom: 0; }
  .tab span { display: none; }
  .tab img { width: 28px; height: 28px; }
  #shop { border-top: none; border-left: 3px solid var(--line); }
}
/* ---- portrait phones: icon-only Declare ---- */
@media (max-width: 899px) and (orientation: portrait), (max-width: 899px) and (min-height: 501px) {
  .declare .declare-label { display: none; }
  .declare { padding: 0 4px; }
}
@media (max-width: 380px) { .rank-title { font-size: 17px; } .tb-row2 { font-size: 14px; gap: 6px; } .stat.rate { font-size: 11.5px; } .tab { font-size: 11px; } }
@media (prefers-reduced-motion: reduce) { * { animation-duration: 0.01s !important; transition-duration: 0.01s !important; } }
body.reduced * { animation-duration: 0.01s !important; transition-duration: 0.01s !important; }
.paper button.quiet-btn { background: none; border: none; box-shadow: none; color: var(--ink2); text-decoration: underline; font-size: 15px; min-height: 44px; }
body.act4 .noel-line, body.act4 .card .speech.noel { color: var(--noel); }
@media (min-width: 560px) { .endings-grid { grid-template-columns: repeat(3, 1fr); } }
gh-feedback { font-family: 'Nunito', system-ui, sans-serif; }

/* short landscape: a compact title */
@media (orientation: landscape) and (max-height: 500px) {
  .title-box { top: calc(8px + var(--sat)); width: min(94vw, 640px); }
  .game-name { font-size: 40px; }
  .tagline { margin: 2px 0 8px; font-size: 14px; }
  .title-buttons { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; justify-items: stretch; width: min(90vw, 480px); margin: 0 auto; }
  .title-buttons button { min-width: 0; min-height: 44px; font-size: 16px; padding: 6px 12px; }
  .title-slot { margin: 6px 0 0; }
}
.noel-plate { line-height: 1; overflow: visible; }

@media (max-width: 899px) { .pl-word { display: none; } }
.noel-head .thinking, .noel-line, .credits, .legacy-row, .item .warn, .card p { text-wrap: balance; }
.item .it-name, .item .it-desc { overflow-wrap: break-word; text-wrap: balance; }
@media (orientation: landscape) and (max-height: 500px), (orientation: landscape) and (max-width: 899px) { .rank-title { font-size: 14px; display: block; text-wrap: balance; max-height: 3.4em; -webkit-line-clamp: unset; line-height: 1.12; } }
.nw { white-space: nowrap; }

.sec-helpers.on { display: flex; flex-direction: column; }
@media (max-width: 899px), (max-height: 500px) { .sec-helpers .legacy-row { order: 10; margin-top: 2px; } .sec-helpers .sec-head { display: none; } }
.twins .item .it-row img { width: 17px; height: 17px; }
.twins .item.locked .it-row { font-size: 12px; }

/* cards: the button row stays in reach; short landscape drops the big portrait */
.card > .row:last-child { position: sticky; bottom: -20px; background: var(--paper); padding: 8px 0 12px; margin-bottom: -12px; }
@media (orientation: landscape) and (max-height: 500px) {
  .card { padding: 12px 16px; }
  .card .portrait, .card .portrait-c { width: 64px; height: 64px; }
  .card .big-title { font-size: 24px; margin: 2px 0; }
  .card .costs { font-size: 12px; margin: 2px 0; }
  .card .lock-row img { width: 36px; height: 36px; }
}

@media (orientation: landscape) and (max-height: 500px) {
  .card .unlocks { display: none; }
  .card .wish { padding: 4px 8px; margin: 4px 0; font-size: 14px; }
  .card .speech { margin: 2px 0; font-size: 15px; }
  .card .stats { margin: 2px 0; }
  .card .choice-row { margin-top: 4px; }
  .card .choice-row button { padding: 4px 8px; }
  .card .choice-row button img { width: 26px; height: 26px; }
  .card .portrait[style] { width: 96px !important; height: 96px !important; }
}
.card .wish, .card .choice-row small { text-wrap: balance; }
.sec-jobs .item { padding-bottom: 10px; }
.item.locked .tally { display: none; }
.item.locked .it-side::before { content: ''; display: block; width: 22px; height: 22px; background: url(assets/locks/padlock-small.webp) center/contain no-repeat; }
.rank-no { font-family: var(--body); font-weight: 900; opacity: 0.85; }
@media (max-width: 520px) { .rank-no { display: none; } }

.title-links a { position: absolute; bottom: calc(14px + var(--sab)); font-family: var(--body); font-weight: 800; font-size: 13px; color: rgba(255,243,220,0.8); text-decoration: none; padding: 6px 10px; border-radius: 10px; background: rgba(20,12,8,0.45); }
.title-links a:hover { color: #fff; text-decoration: underline; }
.title-links .tl-left { left: calc(12px + var(--sal)); }
.title-links .tl-right { right: calc(72px + var(--sar)); }
@media (max-width: 520px) { .title-links a { font-size: 11.5px; padding: 4px 8px; } }
