/* css/game.css — Hearthglow Hollow: Merge & Story
 * Archetype: Cozy Pastel Storybook (Cats & Soup / Animal Restaurant)
 * Strict 9-Slice Anti-Distortion Law + Native 16:9 PC Widescreen (>= 94% width)
 */
:root {
  --ink: #3A1308;
  --cocoa: #703B29;
  --plum: #6D595A;
  --stone: #B9B8B0;
  --ember: #CA6322;
  --terracotta: #9D5D41;
  --cream: #FFFDF7;
  --cream-warm: #F9EEDB;
  --honey: #E9C89B;
  --honey-deep: #D3A56E;
  --sage: #5E9C60;
  --sage-dark: #3B6D3D;
  --frost-bg: #DCEBF2;
  --frost-border: #8BB5CA;
  --font-display: 'Fredoka', 'M PLUS Rounded 1c', 'Segoe UI Rounded', sans-serif;
  --font-body: 'Quicksand', 'Segoe UI', sans-serif;
  --cell-size: min(calc((100vh - 252px) / 9.35), calc((50vw - 290px) / 7.3), 72px);
}

* {
  box-sizing: border-box;
  user-select: none;
  -webkit-user-drag: none;
}

.hidden {
  display: none !important;
}

html, body {
  margin: 0;
  padding: 0;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
  background: #2C1911;
  color: var(--ink);
  font-family: var(--font-body);
  font-weight: 600;
}

button {
  font-family: var(--font-display);
  cursor: pointer;
  overflow: visible !important;
  position: relative;
  transition: transform 0.12s cubic-bezier(0.22, 1, 0.36, 1), filter 0.12s ease;
}
button:hover:not(:disabled) {
  transform: translateY(-1.5px);
  filter: brightness(1.04) drop-shadow(0 4px 0 rgba(58, 19, 8, 0.35));
}
button:active:not(:disabled) {
  transform: translateY(2px);
}
button:disabled {
  opacity: 0.58;
  cursor: not-allowed;
}

/* STRICT 9-SLICE SPRITE CHROME (measured via art_cut_v2 in data/art_manifest.json) */
.btn-9slice {
  background: transparent !important;
  border-style: solid;
  border-width: 14px 16px 14px 16px;
  border-color: transparent;
  border-image: url('../assets/ui/btn_primary.png') 176 175 176 176 fill / 14px 16px 14px 16px stretch;
  border-radius: 0 !important;
  box-shadow: none !important;
  color: #3A1308;
  font-weight: 700;
  font-size: clamp(12px, 0.95vw, 15px);
  line-height: 1.15;
  padding: 0 8px;
  filter: drop-shadow(0 3px 0 rgba(58, 19, 8, 0.38));
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
}

.panel-9slice {
  background: transparent !important;
  border-style: solid;
  border-width: 18px 20px 18px 20px;
  border-color: transparent;
  border-image: url('../assets/ui/frame_panel.png') 115 111 116 114 fill / 18px 20px 18px 20px stretch;
  border-radius: 0 !important;
  box-shadow: none !important;
  color: var(--ink);
  filter: drop-shadow(0 6px 14px rgba(58, 19, 8, 0.25));
}

/* Pure sculpted cozy pastel button for secondary/compact actions */
.btn-cozy {
  background: linear-gradient(180deg, #FFFDF7 0%, #F3DEC0 100%);
  border: 2.5px solid var(--cocoa);
  border-radius: 12px;
  color: var(--ink);
  font-weight: 700;
  font-size: clamp(11px, 0.88vw, 14px);
  line-height: 1.15;
  padding: 6px 10px;
  box-shadow: 0 3px 0 rgba(58, 19, 8, 0.28);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
}
.btn-cozy.sage {
  background: linear-gradient(180deg, #86C888 0%, #589A5B 100%);
  border-color: #2E5930;
  color: #FFFDF7;
  text-shadow: 0 1.5px 0 #2E5930;
}
.btn-cozy.ember {
  background: linear-gradient(180deg, #F6A44C 0%, #CA6322 100%);
  border-color: #5C280B;
  color: #FFFDF7;
  text-shadow: 0 1.5px 0 #5C280B;
}

.btn-label {
  display: inline-block;
  line-height: 1.15;
}

/* Red-Dot Notification Badge — NEVER clipped */
.notify-badge {
  position: absolute;
  top: -7px;
  right: -7px;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: #E53935;
  border: 2px solid #FFFDF7;
  color: #FFFFFF;
  font-family: var(--font-body);
  font-size: 11px;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 30;
  pointer-events: none;
  box-shadow: 0 2px 5px rgba(58, 19, 8, 0.4);
  animation: badgePulse 1.6s infinite ease-in-out;
}
.notify-badge.hidden {
  display: none !important;
}
@keyframes badgePulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.16); }
}

/* TITLE SCREEN */
#title-screen {
  position: fixed;
  inset: 0;
  z-index: 90;
  background: url('../assets/art/bg_title.jpg') center center / cover no-repeat;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  padding: 24px 36px 46px;
}
#title-screen.hidden {
  display: none !important;
}
.title-top-bar {
  width: 100%;
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}
.title-center-card {
  max-width: 680px;
  width: 92%;
  text-align: center;
  padding: 22px 32px 26px;
  margin-top: auto;
  margin-bottom: auto;
  background: rgba(255, 251, 242, 0.88);
  border: 3.5px solid var(--cocoa);
  border-radius: 28px;
  box-shadow: 0 16px 38px rgba(42, 18, 8, 0.42);
  backdrop-filter: blur(6px);
}
.game-logo-title {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(32px, 3.3vw, 52px);
  font-weight: 800;
  color: #FFF9EE;
  -webkit-text-stroke: 2.2px #5A3E36;
  text-shadow: 0 4px 0 #5A3E36, 0 8px 18px rgba(58, 19, 8, 0.35);
  letter-spacing: 0.4px;
}
.game-logo-sub {
  margin: 8px 0 18px;
  font-size: clamp(15px, 1.25vw, 19px);
  color: var(--cocoa);
  font-weight: 700;
}
.loading-wrap {
  width: 100%;
  max-width: 420px;
  margin: 10px auto 14px;
}
.loading-track {
  width: 100%;
  height: 22px;
  background: #EAD4B5;
  border: 2.5px solid var(--cocoa);
  border-radius: 999px;
  overflow: hidden;
  padding: 2px;
}
.loading-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #F59E0B 0%, #FDE047 55%, #FB923C 100%);
  border-radius: 999px;
  transition: width 0.15s ease-out;
}
.loading-caption {
  font-size: 13px;
  color: var(--cocoa);
  margin-top: 6px;
  font-variant-numeric: tabular-nums;
}
#btn-play {
  min-width: 220px;
  min-height: 58px;
  font-size: 22px;
  margin-top: 6px;
}
#btn-play.hidden {
  display: none !important;
}

/* MAIN WIDESCREEN GAME SHELL */
#game-app {
  position: relative;
  width: 100vw;
  height: 100vh;
  display: flex;
  flex-direction: column;
  background:
    radial-gradient(circle at 75% 35%, rgba(250, 184, 92, 0.24), rgba(58, 19, 8, 0.68)),
    url('../assets/art/bg_title.jpg') center center / cover no-repeat;
}
#game-app.hidden {
  display: none !important;
}

/* TOP HUD RIBBON */
.top-hud {
  height: 58px;
  width: 100%;
  padding: 6px 22px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: linear-gradient(180deg, #FFFDF7 0%, #F3DFC1 100%);
  border-bottom: 3px solid var(--cocoa);
  box-shadow: 0 4px 12px rgba(58, 19, 8, 0.22);
  z-index: 25;
}
.hud-left, .hud-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: nowrap;
}
.hud-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 40px;
  padding: 0 11px;
  background: #FFFDF7;
  border: 2px solid var(--cocoa);
  border-radius: 999px;
  box-shadow: inset 0 -2px 0 #EED7B7;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
  font-weight: 700;
  font-size: 14px;
}
.hud-pill img {
  width: 24px;
  height: 24px;
  object-fit: contain;
}
.hud-level-badge {
  background: linear-gradient(180deg, #F6A44C, #CA6322);
  color: #FFFDF7;
  border: 2px solid #5A2B0E;
  padding: 3px 10px;
  border-radius: 999px;
  font-family: var(--font-display);
  font-size: 14px;
  text-shadow: 0 1px 0 #5A2B0E;
}
.xp-mini-bar {
  width: 54px;
  height: 8px;
  background: #E8D2B5;
  border-radius: 99px;
  overflow: hidden;
  border: 1px solid var(--cocoa);
}
.xp-mini-fill {
  height: 100%;
  background: #5E9C60;
  width: 0%;
}
.regen-tag {
  font-size: 11px;
  color: var(--terracotta);
  font-weight: 700;
}
.hud-mini-plus {
  width: 22px;
  height: 22px;
  border-radius: 999px;
  border: 1.5px solid #2E5930;
  background: #6EB370;
  color: #fff;
  font-size: 14px;
  line-height: 1;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.hud-action-btn {
  height: 40px;
  padding: 0 10px;
  border-radius: 12px;
  border: 2px solid var(--cocoa);
  background: linear-gradient(180deg, #FFFDF7 0%, #F1DAC0 100%);
  color: var(--ink);
  font-size: clamp(11px, 0.85vw, 13px);
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  box-shadow: 0 2px 0 rgba(58, 19, 8, 0.25);
}
.hud-action-btn img {
  width: 22px;
  height: 22px;
  object-fit: contain;
}
.hud-action-btn.armed {
  background: linear-gradient(180deg, #FDE047 0%, #F59E0B 100%);
  border-color: #7C2D12;
  box-shadow: 0 0 12px rgba(245, 158, 11, 0.65);
}
.hud-action-btn.locked-preview {
  opacity: 0.68;
  background: #EAE2D6;
}
.hud-icon-only {
  width: 40px;
  padding: 0;
  justify-content: center;
}

/* MAIN 16:9 WIDESCREEN SPLIT (>= 94% WIDTH) */
#game-stage {
  flex: 1;
  width: 96vw;
  max-width: 1860px;
  margin: 0 auto;
  padding: 10px 6px 12px;
  display: grid;
  grid-template-columns: minmax(0, 53fr) minmax(0, 47fr);
  gap: 14px;
  min-height: 0;
}

/* LEFT WING (53%): ORDERS + WARMTH + 7x9 BOARD & PANTRY */
.left-wing {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 0;
  min-width: 0;
}

.orders-strip {
  background: rgba(255, 252, 245, 0.94);
  border: 2.5px solid var(--cocoa);
  border-radius: 18px;
  padding: 7px 10px;
  box-shadow: 0 4px 10px rgba(58, 19, 8, 0.18);
}
.orders-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 5px;
  font-size: 13px;
  color: var(--cocoa);
  font-weight: 700;
}
.streak-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: #FCE8C8;
  border: 1.5px solid #C88A4B;
  border-radius: 999px;
  padding: 2px 9px;
  font-size: 12px;
  color: var(--ink);
}
.streak-pill img {
  width: 16px;
  height: 16px;
}
.orders-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}
.order-card {
  min-width: 0;
  background: linear-gradient(180deg, #FFFDF9 0%, #F7EAD5 100%);
  border: 2px solid #B58863;
  border-radius: 14px;
  padding: 6px 8px;
  display: flex;
  align-items: center;
  gap: 7px;
  position: relative;
}
.order-card.ready {
  border-color: #EAB308;
  background: linear-gradient(180deg, #FFFDF2 0%, #FEF3C7 100%);
  box-shadow: 0 0 0 2px rgba(250, 204, 21, 0.45), 0 4px 12px rgba(217, 119, 6, 0.22);
  animation: orderReadyGlow 2.1s ease-in-out infinite;
}
@keyframes orderReadyGlow {
  0%, 100% { box-shadow: 0 0 0 2px rgba(250, 204, 21, 0.42), 0 4px 12px rgba(217, 119, 6, 0.2); }
  50% { box-shadow: 0 0 0 3px rgba(250, 204, 21, 0.8), 0 4px 16px rgba(245, 158, 11, 0.42); }
}
.order-card.ready .order-serve-btn {
  animation: servePulse 1.6s ease-in-out infinite;
}
@keyframes servePulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.04); }
}
.order-portrait {
  width: 44px;
  height: 50px;
  object-fit: contain;
  flex-shrink: 0;
  background: #EAD3B3;
  border-radius: 10px;
  border: 1.5px solid var(--cocoa);
}
.order-body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.order-top-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 4px;
  font-size: 12px;
  font-weight: 700;
}
.order-reqs {
  display: flex;
  align-items: center;
  gap: 5px;
}
.req-slot {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: #FFFDF7;
  border: 1.5px solid #C59B76;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}
.req-slot.met {
  border-color: #438A46;
  background: #E9F9E7;
}
.req-slot img {
  width: 28px;
  height: 28px;
  object-fit: contain;
}
.req-lvl {
  position: absolute;
  bottom: -3px;
  right: -3px;
  background: var(--cocoa);
  color: #fff;
  font-size: 9px;
  padding: 0 3px;
  border-radius: 4px;
}
.req-check {
  position: absolute;
  top: -5px;
  left: -5px;
  width: 15px;
  height: 15px;
  border-radius: 99px;
  background: #438A46;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
}
.order-reward-tag {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 12px;
  font-weight: 800;
  color: #874312;
}
.order-reward-tag img {
  width: 15px;
  height: 15px;
}
.order-serve-btn {
  padding: 4px 8px;
  font-size: 11px;
  min-height: 28px;
}

/* HEARTH WARMTH BAR */
.warmth-bar-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(255, 250, 240, 0.94);
  border: 2.5px solid var(--cocoa);
  border-radius: 14px;
  padding: 5px 12px;
}
.warmth-label {
  font-family: var(--font-display);
  font-size: 13px;
  color: var(--cocoa);
  white-space: nowrap;
}
.warmth-track {
  flex: 1;
  height: 16px;
  background: #E9D6BC;
  border: 2px solid var(--cocoa);
  border-radius: 999px;
  overflow: hidden;
  padding: 1px;
}
.warmth-fill {
  height: 100%;
  width: 25%;
  border-radius: 999px;
  background: linear-gradient(90deg, #F59E0B 0%, #FB923C 55%, #FDE047 100%);
  transition: width 0.22s ease-out;
}
.warmth-pct {
  font-size: 12px;
  font-weight: 800;
  min-width: 42px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* WORKBENCH: 7x9 BOARD + SIDE INSPECTOR/PANTRY */
.workbench-row {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: auto minmax(220px, 1fr);
  gap: 10px;
  align-items: stretch;
}

.board-frame {
  background: linear-gradient(180deg, #DFB786 0%, #C7935E 100%);
  border: 3.5px solid var(--cocoa);
  border-radius: 20px;
  padding: 8px;
  box-shadow: inset 0 2px 6px rgba(255, 250, 238, 0.55), 0 8px 18px rgba(58, 19, 8, 0.28);
  display: flex;
  align-items: center;
  justify-content: center;
}
#merge-grid {
  display: grid;
  grid-template-columns: repeat(7, var(--cell-size));
  grid-template-rows: repeat(9, var(--cell-size));
  gap: 4px;
  position: relative;
}
.board-cell {
  width: var(--cell-size);
  height: var(--cell-size);
  border-radius: 11px;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1.5px solid rgba(112, 59, 41, 0.25);
  transition: transform 0.1s ease, box-shadow 0.12s ease;
}
.board-cell.even {
  background: #FFFDF6;
}
.board-cell.odd {
  background: #F5E5CA;
}
.board-cell.selected {
  box-shadow: 0 0 0 3px #CA6322, inset 0 0 10px rgba(245, 158, 11, 0.3);
  z-index: 4;
}
.board-cell.hint-glow {
  animation: hintPulse 1.05s infinite ease-in-out;
  box-shadow: 0 0 0 3px #5E9C60;
}
@keyframes hintPulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.06); }
}
.board-cell.frost_locked {
  background: linear-gradient(145deg, #DCEEF7 0%, #B8D8EA 100%);
  border: 2px solid #7CA9C4;
}
.board-cell.frost_locked::after {
  content: "";
  position: absolute;
  inset: 2px;
  border-radius: 9px;
  background: linear-gradient(135deg, rgba(255,255,255,0.55) 0%, rgba(167,208,232,0.32) 100%);
  pointer-events: none;
}
.board-cell.crate {
  background: repeating-linear-gradient(-45deg, #B88456, #B88456 8px, #A57246 8px, #A57246 16px);
  border: 2px solid #6E4423;
  box-shadow: inset 0 2px 4px rgba(255,255,255,0.28);
}
.crate-emblem {
  width: 62%;
  height: 62%;
  border-radius: 8px;
  background: rgba(255, 249, 238, 0.85);
  border: 1.5px solid #6E4423;
  display: flex;
  align-items: center;
  justify-content: center;
}
.crate-emblem img {
  width: 75%;
  height: 75%;
  object-fit: contain;
  opacity: 0.85;
}
.cell-entity-img {
  width: 82%;
  height: 82%;
  object-fit: contain;
  pointer-events: none;
  filter: drop-shadow(0 2px 3px rgba(58, 19, 8, 0.24));
}
.board-cell.generator-cell {
  background: radial-gradient(circle, #FFF8E1 0%, #F4D599 100%);
  border: 2px solid #B66A27;
}
.cell-tier-tag {
  position: absolute;
  bottom: 2px;
  right: 2px;
  background: rgba(58, 19, 8, 0.82);
  color: #FFFDF7;
  font-size: 10px;
  font-weight: 800;
  padding: 0 4px;
  border-radius: 5px;
  line-height: 1.3;
  pointer-events: none;
}
.gen-bolt-badge {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 17px;
  height: 17px;
  background: #FFFDF7;
  border: 1.5px solid var(--cocoa);
  border-radius: 99px;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}
.gen-bolt-badge img {
  width: 12px;
  height: 12px;
}
.gen-cd-overlay {
  position: absolute;
  inset: 0;
  border-radius: 9px;
  background: rgba(58, 19, 8, 0.58);
  color: #FFFDF7;
  font-size: 12px;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

/* SIDE WORKBENCH: INSPECTOR + PANTRY */
.side-workbench {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
  min-height: 0;
}
.inspector-card {
  background: rgba(255, 252, 245, 0.95);
  border: 2.5px solid var(--cocoa);
  border-radius: 16px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 7px;
}
.inspector-head {
  display: flex;
  align-items: center;
  gap: 9px;
}
.inspector-preview {
  width: 52px;
  height: 52px;
  border-radius: 12px;
  background: #F6E6CC;
  border: 2px solid #C59B76;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.inspector-preview img {
  width: 42px;
  height: 42px;
  object-fit: contain;
}
.inspector-title {
  font-family: var(--font-display);
  font-size: 14px;
  color: var(--ink);
}
.inspector-sub {
  font-size: 12px;
  color: var(--plum);
  line-height: 1.25;
}
.inspector-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
}
.inspector-actions > * {
  min-width: 0;
  max-width: 100%;
}

.pantry-card {
  flex: 1;
  min-height: 0;
  background: rgba(255, 252, 245, 0.95);
  border: 2.5px solid var(--cocoa);
  border-radius: 16px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 7px;
}
.pantry-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-family: var(--font-display);
  font-size: 13px;
  color: var(--cocoa);
}
.pantry-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
  overflow-y: auto;
  padding-right: 2px;
}
.pantry-slot {
  aspect-ratio: 1 / 1;
  background: #F6E7CE;
  border: 2px dashed #BD926A;
  border-radius: 11px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  cursor: pointer;
}
.pantry-slot.filled {
  border-style: solid;
  border-color: var(--cocoa);
  background: #FFFDF7;
}
.pantry-slot img {
  width: 78%;
  height: 78%;
  object-fit: contain;
}

/* RIGHT WING (47%): LIVE DIORAMA + STORY RIBBON + RESTORATION / FESTIVAL */
.right-wing {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 0;
  min-width: 0;
}

.diorama-shell {
  flex: 1.25;
  min-height: 240px;
  position: relative;
  border-radius: 20px;
  border: 3.5px solid var(--cocoa);
  overflow: hidden;
  background: #231915;
  box-shadow: 0 8px 20px rgba(58, 19, 8, 0.3);
}
#diorama-canvas {
  width: 100%;
  height: 100%;
  display: block;
}
.diorama-top-overlay {
  position: absolute;
  top: 10px;
  left: 12px;
  right: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  pointer-events: none;
}
.chapter-pill {
  pointer-events: auto;
  background: rgba(255, 251, 242, 0.92);
  border: 2px solid var(--cocoa);
  border-radius: 999px;
  padding: 5px 14px;
  font-family: var(--font-display);
  font-size: 14px;
  color: var(--ink);
  box-shadow: 0 3px 8px rgba(58, 19, 8, 0.25);
}
#btn-hold-before {
  pointer-events: auto;
}

.story-ribbon {
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(255, 252, 245, 0.95);
  border: 2.5px solid var(--cocoa);
  border-radius: 16px;
  padding: 7px 12px;
}
.story-portrait {
  width: 52px;
  height: 58px;
  object-fit: contain;
  background: #F4DFC0;
  border: 2px solid var(--cocoa);
  border-radius: 12px;
  flex-shrink: 0;
}
.story-text-wrap {
  flex: 1;
  min-width: 0;
}
.story-speaker {
  font-family: var(--font-display);
  font-size: 13px;
  color: var(--ember);
}
.story-line {
  font-size: 13px;
  color: var(--ink);
  line-height: 1.3;
}

.restoration-panel {
  background: rgba(255, 252, 245, 0.96);
  border: 2.5px solid var(--cocoa);
  border-radius: 18px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 7px;
  flex-shrink: 0;
}
.restoration-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.restoration-title {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-display);
  font-size: 15px;
  color: var(--ink);
}
.restoration-title img {
  width: 22px;
  height: 22px;
}
.tasks-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 7px;
  overflow-y: auto;
}
.task-card {
  min-width: 0;
  background: #FFF9EE;
  border: 2px solid #C9A077;
  border-radius: 13px;
  padding: 7px 9px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.task-card.done {
  background: #EDF7EC;
  border-color: #7BB47D;
  opacity: 0.85;
}
.task-card.locked-phase {
  opacity: 0.58;
  background: #EFE8DD;
}
.task-info {
  min-width: 0;
  flex: 1;
}
.task-phase-tag {
  font-size: 10px;
  font-weight: 800;
  color: var(--terracotta);
  text-transform: uppercase;
}
.task-name {
  font-size: 12.5px;
  font-weight: 700;
  color: var(--ink);
  line-height: 1.2;
}

/* DRAG GHOST */
#drag-ghost {
  position: fixed;
  width: 68px;
  height: 68px;
  pointer-events: none;
  z-index: 80;
  transform: translate3d(-999px, -999px, 0);
}
#drag-ghost.hidden {
  display: none !important;
}
#drag-ghost img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  filter: drop-shadow(0 8px 12px rgba(58, 19, 8, 0.4));
}

/* 4-PHASE ULTIMATE CUT-IN RIBBON (Hearth Warmth Surge) */
#cutin-banner {
  position: fixed;
  inset: 0;
  z-index: 75;
  background: rgba(42, 18, 8, 0.34);
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}
#cutin-banner.hidden {
  display: none !important;
}
.cutin-strip {
  width: 100%;
  max-width: 960px;
  background: linear-gradient(90deg, rgba(112,59,41,0.96) 0%, rgba(202,99,34,0.96) 50%, rgba(112,59,41,0.96) 100%);
  border-top: 4px solid #FDE047;
  border-bottom: 4px solid #FDE047;
  padding: 12px 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 22px;
  box-shadow: 0 12px 34px rgba(58, 19, 8, 0.5);
  animation: cutinSlide 0.24s cubic-bezier(0.22, 1, 0.36, 1);
}
@keyframes cutinSlide {
  from { transform: translateX(-120px) scale(0.92); opacity: 0; }
  to { transform: translateX(0) scale(1); opacity: 1; }
}
.cutin-portrait {
  width: 94px;
  height: 108px;
  object-fit: contain;
  filter: drop-shadow(0 4px 10px rgba(0,0,0,0.4));
}
.cutin-title {
  font-family: var(--font-display);
  font-size: clamp(24px, 2.4vw, 36px);
  color: #FFF9EE;
  -webkit-text-stroke: 1.8px #3A1308;
  text-shadow: 0 3px 0 #3A1308;
}
.cutin-sub {
  font-size: 15px;
  color: #FEF3C7;
  font-weight: 700;
}

/* MODALS (Spring Overshoot + Strict minmax(0,1fr) Grids) */
#modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 105;
  background: rgba(38, 18, 10, 0.62);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  backdrop-filter: blur(3px);
}
#modal-backdrop.hidden {
  display: none !important;
}
.modal-window {
  width: min(880px, 94vw);
  max-height: 88vh;
  display: flex;
  flex-direction: column;
  padding: 12px 18px 16px;
  animation: modalSpring 0.25s cubic-bezier(0.22, 1.25, 0.36, 1);
}
@keyframes modalSpring {
  0% { transform: scale(0.85); opacity: 0; }
  70% { transform: scale(1.03); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding-bottom: 8px;
  border-bottom: 2px solid rgba(112, 59, 41, 0.22);
  margin-bottom: 10px;
}
.modal-title {
  font-family: var(--font-display);
  font-size: clamp(20px, 1.8vw, 26px);
  color: #FFF9EE;
  -webkit-text-stroke: 1.6px #5A3E36;
  text-shadow: 0 2px 0 #5A3E36;
  margin: 0;
}
.modal-body {
  flex: 1;
  overflow-y: auto;
  padding-right: 4px;
}
.modal-grid-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}
.modal-grid-3 {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}
.modal-grid-4 {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}
.modal-grid-2 > *, .modal-grid-3 > *, .modal-grid-4 > * {
  min-width: 0;
  max-width: 100%;
}

.shop-card {
  background: linear-gradient(180deg, #FFFDF8 0%, #F6E6CC 100%);
  border: 2.5px solid #B58863;
  border-radius: 16px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 8px;
  position: relative;
}
.shop-badge {
  position: absolute;
  top: -8px;
  left: 12px;
  background: linear-gradient(90deg, #CA6322, #F59E0B);
  color: #FFFDF7;
  font-family: var(--font-display);
  font-size: 10px;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1.5px solid #5A2B0E;
}
.shop-card-top {
  display: flex;
  align-items: center;
  gap: 10px;
}
.shop-icon {
  width: 52px;
  height: 52px;
  object-fit: contain;
  flex-shrink: 0;
}

.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 12px;
  background: rgba(255, 250, 240, 0.85);
  border: 1.5px solid #D4B28C;
  border-radius: 12px;
  margin-bottom: 8px;
}
.settings-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* FTUE TUTORIAL BAR & COACH CARD (Docked cleanly inside Diorama bottom so zero HUD/Tasks overlap) */
#tutorial-bar {
  position: absolute;
  bottom: 12px;
  left: 12px;
  right: 12px;
  z-index: 35;
  background: rgba(255, 253, 247, 0.95);
  border: 2.5px solid var(--cocoa);
  border-radius: 16px;
  padding: 8px 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  box-shadow: 0 8px 20px rgba(38, 16, 8, 0.35);
}
#tutorial-bar.hidden {
  display: none !important;
}
#tutorial-bar img {
  width: 50px;
  height: 56px;
  object-fit: contain;
}

/* CELEBRATION / TOAST / VFX OVERLAYS */
#vfx-overlay-canvas {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 70;
}
#fx-dom-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 120;
}
.flying-loot-icon {
  position: fixed;
  width: 28px;
  height: 28px;
  object-fit: contain;
  pointer-events: none;
}
/* [VPS #541/#529/#498] Dock toast cleanly at bottom-center with pointer-events:none so it NEVER overlaps Chapter title or Modal headings */
#toast-banner {
  position: fixed;
  bottom: 22px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 125;
  pointer-events: none;
  max-width: min(680px, 88vw);
  text-align: center;
  background: #FFFDF7;
  border: 2.5px solid var(--cocoa);
  border-radius: 999px;
  padding: 7px 18px;
  font-family: var(--font-display);
  font-size: 14px;
  color: var(--ink);
  box-shadow: 0 6px 18px rgba(58, 19, 8, 0.34);
}
.frost-lock-badge {
  position: absolute;
  top: 2px;
  left: 2px;
  z-index: 4;
  background: rgba(14, 116, 144, 0.9);
  color: #F0F9FF;
  font-size: 10px;
  font-weight: 800;
  line-height: 1;
  padding: 2px 4px;
  border-radius: 6px;
  border: 1px solid #BAE6FD;
  pointer-events: none;
}
.reward-crate-badge {
  position: absolute;
  top: 2px;
  right: 2px;
  z-index: 4;
  background: #F59E0B;
  color: #3A1308;
  font-size: 9px;
  font-weight: 800;
  line-height: 1;
  padding: 2px 4px;
  border-radius: 6px;
  border: 1px solid #FEF08A;
  pointer-events: none;
}
#toast-banner.hidden {
  display: none !important;
}

/* PREVIEW-ONLY [DEV F2] PANEL */
#dev-f2-pill {
  position: fixed;
  bottom: 8px;
  right: 10px;
  z-index: 130;
  background: rgba(58, 19, 8, 0.82);
  color: #FDE047;
  border: 1.5px solid #F59E0B;
  border-radius: 8px;
  font-size: 11px;
  padding: 3px 8px;
}
#debug-panel {
  position: fixed;
  bottom: 38px;
  right: 10px;
  z-index: 130;
  width: 280px;
  background: #2B1810;
  color: #FFFDF7;
  border: 2px solid #F59E0B;
  border-radius: 14px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  box-shadow: 0 10px 26px rgba(0,0,0,0.5);
}
#debug-panel.hidden {
  display: none !important;
}
#debug-panel button {
  font-size: 12px;
  padding: 5px 8px;
  border-radius: 8px;
  border: 1px solid #C2824A;
  background: #4A2B1D;
  color: #FFFDF7;
  text-align: left;
}

/* RESPONSIVE < 900PX FALLBACK */
@media (max-width: 900px) {
  :root {
    --cell-size: min(calc((100vw - 64px) / 7.4), 52px);
  }
  html, body, #game-app {
    overflow-y: auto;
    height: auto;
    min-height: 100vh;
  }
  .top-hud {
    height: auto;
    flex-wrap: wrap;
    padding: 8px 12px;
  }
  #game-stage {
    grid-template-columns: minmax(0, 1fr);
    height: auto;
  }
  .workbench-row {
    grid-template-columns: minmax(0, 1fr);
  }
  .diorama-shell {
    min-height: 260px;
  }
}

/* [VPS #628/#643] Inline +BONUS indicator when Energy stacks above cap */
.energy-bonus-pill {
  display: inline-block;
  margin-left: 4px;
  padding: 1px 5px;
  border-radius: 999px;
  background: linear-gradient(180deg, #F59E0B, #D97706);
  color: #FFFDF7;
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.03em;
  vertical-align: middle;
  cursor: pointer;
}
.order-tag-pill {
  display: inline-block;
  margin-left: 4px;
  padding: 1px 5px;
  border-radius: 6px;
  background: #EDE9FE;
  color: #5B21B6;
  border: 1px solid #C4B5FD;
  font-size: 9px;
  font-weight: 800;
  vertical-align: middle;
}
.bet-hint-line {
  grid-column: 1 / -1;
  font-size: 10.5px;
  font-weight: 700;
  color: #703B29;
  opacity: 0.88;
  margin-top: 2px;
  line-height: 1.25;
}
