/* Benny's Workshop — cozy North Pole UI. Mobile-first: evergreen + snow + warm
   parchment, with the SAME red/amber/green triage colours as the game it grew
   from — that traffic-light read is the whole skill, so it stays sharp while the
   chrome goes festive. Cozy background, loud panic foreground. */
:root {
  --pine: #2f9e5f;
  --pine-deep: #17663d;
  --pine-soft: #dcefe3;
  --bg: #ecf3f1;
  --card: #fffdf7;
  --ink: #26382f;
  --ink-soft: #6c8377;
  --crit: #e5604d;   /* rush     */
  --urg: #e8a13b;    /* special  */
  --min: #57b894;    /* simple   */
  --gold: #e8b04b;   /* sparkle / cheer accent */
  --blue: #3d8bd4;   /* frost — build button */
  --green: #46a86e;  /* ship button */
  --shadow: rgba(20, 60, 40, 0.18);
  --radius: 16px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%; overflow: hidden;
  font-family: 'Nunito', system-ui, sans-serif; color: var(--ink); background: var(--pine-deep);
  -webkit-font-smoothing: antialiased; overscroll-behavior: none;
  -webkit-touch-callout: none; touch-action: manipulation;
}
button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }

#app {
  position: relative; max-width: 560px; margin: 0 auto; height: 100dvh;
  display: flex; flex-direction: column; background: var(--bg);
  box-shadow: 0 0 60px rgba(0,0,0,0.08); overflow: hidden;
}

/* ---------- HUD ---------- */
#hud {
  flex: 0 0 auto; display: flex; flex-direction: column; gap: 5px;
  padding: calc(6px + env(safe-area-inset-top)) calc(10px + env(safe-area-inset-right)) 6px calc(10px + env(safe-area-inset-left));
  /* deep evergreen at the very top so the iOS status bar (white text) reads cleanly over the notch */
  background: linear-gradient(180deg, var(--pine-deep), var(--pine));
  color: #fff; box-shadow: 0 3px 10px var(--shadow); z-index: 5;
}
.hud-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.hud-left { display: flex; align-items: center; gap: 7px; flex: 0 0 auto; }
.hud-left .logo { font-size: 22px; }
.hud-left img.logo { width: 30px; height: 30px; border-radius: 50%; object-fit: cover;
  box-shadow: 0 0 0 2px rgba(255,255,255,.7); }
.hud-left .title { font-family: 'Baloo 2', sans-serif; font-weight: 800; font-size: 17px; white-space: nowrap; }
.hud-stats { display: flex; align-items: center; gap: 7px; flex: 1 1 auto; justify-content: flex-end; min-width: 0; }
.stat { display: flex; align-items: center; gap: 4px; background: rgba(255,255,255,.16);
  padding: 4px 8px; border-radius: 999px; font-weight: 800; font-size: 13px; white-space: nowrap; }
.stat.nurses.none { background: rgba(229,96,77,.55); }

/* full-width Christmas Spirit bar under the top row */
.rep-bar { display: flex; align-items: center; gap: 7px; }
.rep-bar .rep-icon { font-size: 13px; flex: 0 0 auto; }
.rep-bar .bar { flex: 1 1 auto; height: 11px; background: rgba(255,255,255,.26); border-radius: 999px; overflow: hidden; }
.rep-bar #rep-fill { height: 100%; width: 100%; background: var(--min); border-radius: 999px; transition: width .25s, background .25s; }
.rep-bar .rep-label { flex: 0 0 auto; font-weight: 800; font-size: 12px; min-width: 24px; text-align: right; }
.rep-bar.low .rep-icon { animation: lowThump .5s infinite; }
@keyframes lowThump { 50% { transform: scale(1.18); } }
@keyframes repPulse { 50% { background: rgba(229,96,77,.5); } }

/* the night's progress toward dawn (Christmas-Eve dusk → midnight → sunrise) */
#shift-progress { height: 4px; background: rgba(255,255,255,.18); border-radius: 999px; overflow: hidden; }
#shift-fill { height: 100%; width: 0%; border-radius: 999px; transition: width .5s linear;
  background: linear-gradient(90deg, #3a4a8c 0%, #7a5aa8 55%, #f0a24a 100%); }
.hud-btn { font-size: 17px; background: rgba(255,255,255,.18); width: 32px; height: 30px; border-radius: 9px; }
.hud-btn:active { transform: scale(.92); }
.hud-btn.backup { min-width: 34px; width: auto; padding: 0 7px; font-size: 15px; font-weight: 800; }
.hud-btn.backup.ready { background: var(--green); box-shadow: 0 0 0 2px rgba(70,168,110,.4); animation: backupPulse 1.6s infinite; }
.hud-btn.backup.cooldown { background: rgba(255,255,255,.12); opacity: .7; font-size: 12px; }
.hud-btn.backup.disabled { opacity: .4; }
@keyframes backupPulse { 50% { box-shadow: 0 0 0 5px rgba(70,168,110,.15); } }

@media (max-width: 430px) {
  .hud-left .title { display: none; }
  .stat { padding: 4px 7px; font-size: 12px; }
}

/* ---------- Board ---------- */
/* The board fills the space under the HUD and splits it between the three
   regions, so benches + overflow stay on screen without page scrolling. */
#board {
  flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; gap: 3px;
  padding: 6px calc(8px + env(safe-area-inset-right)) calc(8px + env(safe-area-inset-bottom)) calc(8px + env(safe-area-inset-left));
  overflow: hidden;
}
.board-label {
  font-family: 'Baloo 2', sans-serif; font-size: 12.5px; margin: 2px 2px 2px; color: var(--pine-deep);
  display: flex; align-items: center; gap: 6px;
}
.count-badge { background: var(--pine-soft); color: var(--pine-deep); font-size: 11px; font-weight: 800;
  padding: 0 7px; border-radius: 999px; }
.count-badge.over { background: var(--crit); color: #fff; animation: repPulse .7s infinite; }

/* mailroom — wrapping compact letters (tap to admit); no cumbersome scroll.
   Capped so a big surge scrolls within the strip instead of eating the benches. */
#incoming-wrap { flex: 0 1 auto; min-height: 0; display: flex; flex-direction: column; max-height: 30%; }
.incoming {
  display: flex; flex-wrap: wrap; gap: 6px; align-content: flex-start;
  overflow-y: auto; min-height: 30px; scrollbar-width: thin;
}
.incoming::-webkit-scrollbar { width: 5px; }
.incoming::-webkit-scrollbar-thumb { background: #c4d8d0; border-radius: 3px; }
.empty-note { color: var(--ink-soft); font-weight: 700; font-size: 12px; padding: 6px 2px; white-space: nowrap; }

/* benches — the main area; only THIS scrolls, and only if you have lots of benches */
#beds-wrap { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }
/* columns + row height are set by ui.layoutBeds() so every bench always fits */
#beds { flex: 1 1 auto; min-height: 0; overflow: hidden; align-content: start; }
#beds .slot { min-height: 0; }
#halls-wrap { flex: 0 0 auto; }

/* responsive columns: as many as fit, denser on wider screens */
.slots { display: grid; grid-template-columns: repeat(auto-fill, minmax(116px, 1fr)); gap: 7px; }
.slots.halls { grid-template-columns: repeat(auto-fill, minmax(98px, 1fr)); }

.slot {
  min-height: 94px; border-radius: 12px; display: flex; align-items: center; justify-content: stretch; overflow: hidden;
  background: rgba(255,255,255,.5); border: 2px dashed #b7d0c8; padding: 3px; transition: border-color .15s, background .15s;
}
.slots.halls .slot { min-height: 82px; }
.slot[data-empty="1"] { align-items: center; justify-content: center; }
.slot-empty { color: var(--ink-soft); font-weight: 700; font-size: 11px; text-align: center; }
.slot.hall { border-style: dotted; background: rgba(61,139,212,.08); }
.slot.drop-ok { border-color: var(--pine); background: var(--pine-soft); box-shadow: 0 0 0 3px rgba(47,158,95,.25) inset; }
body.is-dragging .slot[data-empty="1"] { border-color: var(--pine); background: rgba(220,239,227,.6); }

/* ---------- Order card (a child's letter) ---------- */
.pcard {
  background: var(--card); border-radius: 10px; padding: 5px 7px; width: 100%;
  box-shadow: 0 2px 6px var(--shadow); border-left: 5px solid #ccc; display: flex; flex-direction: column; gap: 3px;
  touch-action: none; user-select: none;
}
.incoming .pcard { width: 104px; flex: 0 0 auto; cursor: grab; padding: 4px 6px; }
.pcard.crit { border-left-color: var(--crit); }
.pcard.urg { border-left-color: var(--urg); }
.pcard.min { border-left-color: var(--min); }
.pcard-head { display: flex; align-items: center; gap: 4px; }
.pcard-head .chip { font-size: 10px; flex: 0 0 auto; }
.pcard-head .pface { font-size: 15px; flex: 0 0 auto; }
.pcard-head .pname { font-weight: 700; font-size: 10.5px; color: var(--ink-soft);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1 1 auto; }
/* the toy is the key build info: own line, prominent, wraps up to 2 lines */
.pcond { font-size: 11.5px; font-weight: 800; color: var(--ink); line-height: 1.14;
  display: -webkit-box; -webkit-line-clamp: 2; line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.stab { height: 6px; background: #e7eded; border-radius: 999px; overflow: hidden; }
.stab-fill { height: 100%; width: 100%; background: var(--min); border-radius: 999px; transition: width .12s linear; }
.stab.critical { animation: repPulse .5s infinite; box-shadow: 0 0 0 2px rgba(229,96,77,.35); }

.pcard-act { margin-top: 0; }
.act-btn { width: 100%; font-family: 'Baloo 2', sans-serif; font-weight: 800; font-size: 12px; color: #fff;
  padding: 5px; border-radius: 8px; box-shadow: 0 2px 0 rgba(0,0,0,.12); transition: transform .07s; }
.act-btn:active { transform: translateY(2px); box-shadow: none; }
.act-btn.start { background: var(--blue); }
.act-btn.discharge { background: var(--green); animation: readyGlow 1.1s infinite; }
@keyframes readyGlow { 50% { box-shadow: 0 0 0 3px rgba(70,168,110,.35), 0 3px 0 rgba(0,0,0,.12); } }
.act-wait { text-align: center; font-size: 11px; font-weight: 800; color: var(--ink-soft); padding: 4px; animation: repPulse 1s infinite; }
.act-prog-label { font-size: 10px; font-weight: 800; color: var(--pine-deep); text-align: center; margin-bottom: 2px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.act-prog { height: 6px; background: #e7eded; border-radius: 999px; overflow: hidden; }
.act-prog-fill { height: 100%; width: 0%; background: var(--pine); border-radius: 999px; }

/* drag states */
.pcard.drag-source { opacity: .35; }
.pcard.ghost {
  position: fixed; transform: translate(-50%, -50%) rotate(-3deg) scale(1.05); pointer-events: none;
  z-index: 60; box-shadow: 0 14px 34px rgba(0,0,0,.35); opacity: .97;
}

/* ---------- flash ---------- */
#flash { position: fixed; inset: 0; pointer-events: none; z-index: 45; opacity: 0; }
#flash.show { animation: flashFade .36s ease; }
#flash.code { background: radial-gradient(circle, transparent 40%, rgba(229,96,77,.55)); }
#flash.leave { background: radial-gradient(circle, transparent 45%, rgba(232,161,59,.45)); }
@keyframes flashFade { 0% { opacity: 1; } 100% { opacity: 0; } }

/* ---------- overlay / menus ---------- */
#overlay { position: fixed; inset: 0; z-index: 50; display: none; align-items: center; justify-content: center;
  padding: 18px; background: rgba(15,45,30,.62); }
#overlay.show { display: flex; animation: fade .2s; }
@keyframes fade { from { opacity: 0; } }
.panel {
  background: var(--bg); border-radius: 22px; padding: 22px 20px; max-width: 400px; width: 100%; text-align: center;
  box-shadow: 0 20px 50px rgba(0,0,0,.4); animation: rise .25s ease; max-height: 92vh; overflow-y: auto;
}
@keyframes rise { from { transform: translateY(16px) scale(.97); opacity: 0; } }
.panel h1 { font-family: 'Mountains of Christmas', 'Baloo 2', cursive; font-weight: 700; margin: 4px 0 4px; font-size: 34px; color: var(--pine-deep); }
.logo-big { font-size: 52px; }
/* framed character illustration at the top of a panel (Benny on start, Santa on win) */
.hero { margin: -6px -4px 8px; border-radius: 16px; overflow: hidden; box-shadow: 0 6px 16px var(--shadow); }
.hero img { display: block; width: 100%; height: 172px; object-fit: cover; object-position: center 25%; }
.hero.santa img { object-position: center 15%; background: #2a0f12; }
.tagline { color: var(--ink-soft); font-weight: 700; margin: 0 0 12px; }
.howto { text-align: left; background: var(--card); border-radius: 14px; padding: 12px 14px; margin: 12px 0;
  box-shadow: inset 0 0 0 1px #e2ece4; }
.howto p { margin: 7px 0; font-size: 13.5px; line-height: 1.4; }
.best { font-weight: 800; color: var(--pine-deep); margin: 12px 0; }
.tiny { font-size: 12px; } .muted { color: var(--ink-soft); }
.big-btn { width: 100%; font-family: 'Baloo 2', sans-serif; font-weight: 800; font-size: 19px; color: #fff;
  background: linear-gradient(180deg, var(--pine), var(--pine-deep)); padding: 15px; border-radius: 14px;
  box-shadow: 0 4px 0 #0f4a2c; transition: transform .08s; }
.big-btn:active { transform: translateY(3px); box-shadow: 0 1px 0 #0f4a2c; }
.ghost-btn { width: 100%; margin-top: 10px; font-weight: 800; color: var(--pine-deep); padding: 11px; border-radius: 12px;
  box-shadow: inset 0 0 0 2px var(--pine); }
.score-big { font-family: 'Baloo 2', sans-serif; font-size: 52px; font-weight: 800; color: var(--pine-deep); margin: 6px 0; }
.stats-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 14px 0; }
.stats-grid > div { background: var(--card); border-radius: 12px; padding: 10px 4px; box-shadow: 0 2px 6px var(--shadow); }
.stats-grid b { display: block; font-size: 22px; font-family: 'Baloo 2', sans-serif; color: var(--ink); }
.stats-grid span { font-size: 11px; color: var(--ink-soft); font-weight: 700; }

/* ---------- app cross-promo (the point of the whole game) ---------- */
.app-cta {
  display: flex; align-items: center; gap: 12px; text-align: left; text-decoration: none;
  margin-top: 14px; padding: 12px 14px; border-radius: 16px;
  background: linear-gradient(135deg, #b8172c 0%, #8f0f22 100%); color: #fff;
  box-shadow: 0 4px 14px rgba(143,15,34,.4); border: 2px solid rgba(255,255,255,.22);
  transition: transform .08s;
}
.app-cta:active { transform: translateY(2px); }
.app-cta-elf { font-size: 34px; flex: 0 0 auto; filter: drop-shadow(0 2px 2px rgba(0,0,0,.3)); }
img.app-cta-elf { width: 46px; height: 46px; border-radius: 50%; object-fit: cover;
  box-shadow: 0 0 0 2px rgba(255,255,255,.35); }
.app-cta-text { display: flex; flex-direction: column; gap: 1px; line-height: 1.25; }
.app-cta-text b { font-family: 'Baloo 2', sans-serif; font-size: 16px; }
.app-cta-text span { font-size: 12.5px; color: rgba(255,255,255,.92); font-weight: 700; }
.app-cta-text i { font-style: normal; font-weight: 800; color: #ffe6a8; }
.app-cta-note { text-align: center; font-size: 11.5px; font-weight: 700; color: rgba(255,255,255,.6); margin: 6px 0 0; }

/* ---------- toasts ---------- */
#toast-layer { position: fixed; top: 58px; left: 50%; transform: translateX(-50%); z-index: 55;
  display: flex; flex-direction: column; gap: 6px; align-items: center; pointer-events: none; width: 100%; max-width: 560px; }
.toast { background: var(--pine-deep); color: #fff; font-weight: 800; font-size: 13px; padding: 8px 16px;
  border-radius: 999px; box-shadow: 0 6px 16px var(--shadow); max-width: 92%; text-align: center;
  animation: toastIn .25s ease, toastOut .3s ease 1.9s forwards; }
.toast.good { background: var(--green); }
.toast.bad { background: var(--crit); }
.toast.warn { background: var(--urg); color: #4a3410; }
@keyframes toastIn { from { transform: translateY(-10px); opacity: 0; } }
@keyframes toastOut { to { transform: translateY(-10px); opacity: 0; } }

/* ================= EPIC: sparkle rescue, juice, upgrades ================= */

/* day → night ambient tint over the play area (Christmas-Eve sky) */
#ambient { position: absolute; inset: 0; pointer-events: none; z-index: 4; opacity: 0;
  background: linear-gradient(180deg, rgba(24,32,74,0), rgba(9,13,42,0.92)); transition: opacity 2.5s linear; }

/* screen shake on rescues / avalanches */
@keyframes shakeAnim {
  10%{transform:translate(-2px,1px)} 20%{transform:translate(3px,-2px)} 30%{transform:translate(-4px,2px)}
  40%{transform:translate(3px,1px)} 50%{transform:translate(-2px,-1px)} 60%{transform:translate(3px,2px)}
  70%{transform:translate(-3px,-1px)} 80%{transform:translate(2px,-2px)} 90%{transform:translate(-1px,1px)} }
#app.shake { animation: shakeAnim .45s ease; }

/* MAGIC FADING card — a solid flashing block that fills its cell; impossible to miss */
.pcard.coding {
  align-self: stretch; justify-content: center; background: #e5493a; color: #fff; border-left-color: #fff;
  box-shadow: inset 0 0 0 2px rgba(255,255,255,.9); animation: codeFlash .5s infinite;
}
.pcard.coding .pname { color: rgba(255,255,255,.9); }
.pcard.coding .pcond { color: #fff; }
@keyframes codeFlash { 0%, 100% { background: #e5493a; } 50% { background: #ff9d5b; box-shadow: inset 0 0 0 3px #fff; } }
.act-code-label { font-size: 11px; font-weight: 900; color: #fff; text-align: center; letter-spacing: .4px; }
.act-revive { height: 8px; background: rgba(255,255,255,.4); border-radius: 999px; overflow: hidden; margin: 3px 0; }
.act-revive-fill { height: 100%; width: 0%; background: linear-gradient(90deg,#ffd23f,#57e39b); border-radius: 999px; }
.act-btn.cpr { background: #fff; color: #d3392a; animation: cprGlow .5s infinite; }
@keyframes cprGlow { 50% { transform: scale(1.04); } }

/* pulsing warm edge on the whole screen while ANY toy is fading */
#code-alert { position: fixed; inset: 0; pointer-events: none; z-index: 44; opacity: 0; }
body.codes-active #code-alert { opacity: 1; animation: codeVignette .8s infinite; }
@keyframes codeVignette {
  0%, 100% { box-shadow: inset 0 0 32px 3px rgba(229,60,45,.28); }
  50% { box-shadow: inset 0 0 85px 18px rgba(229,60,45,.62); }
}

/* floating +points / -penalty numbers */
#fx { position: fixed; inset: 0; pointer-events: none; z-index: 58; }
.floatnum { position: absolute; transform: translate(-50%,0); font-family:'Baloo 2',sans-serif; font-weight: 800;
  font-size: 20px; color: var(--green); text-shadow: 0 2px 3px rgba(0,0,0,.35); white-space: nowrap;
  animation: floatUp 1.2s ease-out forwards; }
.floatnum.bad { color: var(--crit); } .floatnum.warn { color: var(--urg); }
.floatnum.save { color: #2f9d5e; font-size: 24px; }
@keyframes floatUp { 0%{opacity:0;transform:translate(-50%,6px) scale(.8)} 15%{opacity:1} 100%{opacity:0;transform:translate(-50%,-48px) scale(1.05)} }

/* combo / announce banner */
#combo-banner { position: fixed; top: 26%; left: 0; right: 0; z-index: 57; pointer-events: none; text-align: center;
  font-family:'Mountains of Christmas','Baloo 2',cursive; font-weight: 700; font-size: 38px; color: #fff; opacity: 0;
  text-shadow: 0 3px 0 rgba(0,0,0,.25), 0 0 24px rgba(255,255,255,.45); padding: 0 12px; }
#combo-banner.show { animation: bannerPop 1.4s ease; }
@keyframes bannerPop { 0%{opacity:0;transform:scale(.6)} 15%{opacity:1;transform:scale(1.12)} 80%{opacity:1;transform:scale(1)} 100%{opacity:0;transform:scale(1)} }

/* workshop upgrade choices */
.upgrades { display: grid; gap: 10px; margin: 12px 0 2px; }
.upgrade-choice { display: flex; flex-direction: column; align-items: center; gap: 2px; background: var(--card);
  border-radius: 14px; padding: 12px 10px; box-shadow: 0 3px 0 #d6e6db, 0 6px 12px var(--shadow);
  text-align: center; transition: transform .08s; border: 3px solid transparent; cursor: pointer; }
.upgrade-choice:active { transform: translateY(2px); }
.upgrade-choice:hover { border-color: var(--pine); }
.up-emoji { font-size: 30px; }
.up-name { font-family:'Baloo 2',sans-serif; font-weight: 800; font-size: 16px; color: var(--pine-deep); }
.up-desc { font-size: 12px; color: var(--ink-soft); font-weight: 700; }
