:root {
  --bg: #16101c;
  --surface: #201729;
  --surface-2: #2b1f36;
  --surface-3: #362844;
  --ink: #faf4e8;
  --ink-2: rgba(250, 244, 232, 0.74);
  --brass: #e5a93c;
  --brass-dark: #8c5c19;
  --emerald: #34a86c;
  --flame: #ff6b3d;
  --mint: #4bd4b0;
  --sky: #38bdf8;
  --coral: #f08080;
  --line: rgba(229, 169, 60, 0.34);
  --line-soft: rgba(250, 244, 232, 0.14);
}
* { box-sizing: border-box; }
html, body {
  margin: 0;
  min-height: 100dvh;
  background: radial-gradient(circle at 50% 0%, #261b30 0%, var(--bg) 68%);
  color: var(--ink);
  font-family: Pretendard, "Apple SD Gothic Neo", system-ui, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
.hidden { display: none !important; }

/* 16:9 Unified Factory Cabinet (Matches Original Reel Factory 1280x720 Layout) */
#app.cabinet {
  max-width: 1280px;
  margin: 0 auto;
  padding: 8px 12px 16px;
  display: grid;
  gap: 8px;
}

/* Top HUD Bar */
.hud {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 7px 12px;
  border-radius: 10px;
  background: var(--surface);
  border: 1.5px solid var(--line);
}
.hud-left, .hud-center, .hud-right {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 7px;
}
.brand-title {
  color: var(--brass);
  font-size: 15px;
  letter-spacing: -0.02em;
}
.chapter-title {
  color: #f6c967;
  font-weight: 800;
  font-size: 13.5px;
}
.prod-badge {
  font-size: 11px;
  font-weight: 800;
  padding: 2px 7px;
  border-radius: 999px;
  background: rgba(75, 212, 176, 0.16);
  border: 1px solid rgba(75, 212, 176, 0.45);
  color: var(--mint);
}
.home-back {
  color: var(--ink-2);
  text-decoration: none;
  font-size: 12px;
  font-weight: 700;
  padding: 4px 8px;
  border-radius: 7px;
  border: 1px solid var(--line-soft);
}
.home-back:hover { border-color: var(--brass); color: var(--ink); }
.pill {
  padding: 4px 9px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 800;
  background: var(--surface-2);
  border: 1px solid var(--line-soft);
}
.pill-gold { color: #fde047; }
.pill-heart { color: #fda4af; }
.pill-spins { color: #cbd5e1; }
.pill-surge { color: var(--sky); }

/* Upper Factory Diorama Stage — Proper 16:9-friendly Height, Never Squashed */
.stage-area {
  position: relative;
  border-radius: 12px;
  overflow: hidden;
  border: 1.5px solid var(--line);
  background: #140e18;
  height: clamp(330px, 47vh, 430px);
}
#battle-canvas {
  display: block;
  width: 100%;
  height: 100%;
}

/* Top-Left Stage Overlay (Timer + Steam Surge) */
.stage-overlay-left {
  position: absolute;
  top: 10px;
  left: 12px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
  z-index: 4;
}
.timer-pill {
  padding: 5px 11px;
  border-radius: 8px;
  background: rgba(20, 14, 26, 0.86);
  border: 1px solid var(--line);
  font-weight: 800;
  font-size: 12.5px;
  color: var(--ink);
}
.btn-surge {
  padding: 7px 14px;
  border-radius: 9px;
  border: 1.5px solid rgba(253, 224, 71, 0.7);
  background: rgba(26, 18, 34, 0.88);
  color: #fde047;
  font-weight: 800;
  font-size: 12.5px;
  cursor: pointer;
  transition: transform 0.12s ease, background 0.15s ease;
}
.btn-surge.is-ready {
  background: linear-gradient(135deg, #d97706, #dc2626);
  color: #fff;
  box-shadow: 0 0 14px rgba(245, 158, 11, 0.45);
}
.btn-surge:hover:not(:disabled) { transform: scale(1.03); }
.btn-surge:disabled { opacity: 0.45; cursor: not-allowed; }

/* Right Floating L1 / L2 / L3 Enemy HP Cards */
.lane-hp-stack {
  position: absolute;
  top: 18px;
  right: 14px;
  width: min(230px, 28vw);
  display: grid;
  gap: 8px;
  z-index: 4;
  pointer-events: none;
}
.lane-hp-card {
  padding: 6px 9px;
  border-radius: 8px;
  background: rgba(22, 16, 28, 0.84);
  border: 1px solid rgba(229, 169, 60, 0.35);
  display: grid;
  gap: 4px;
}
.lane-hp-card.is-cleared {
  opacity: 0.55;
  border-color: rgba(75, 212, 176, 0.45);
}
.lane-hp-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 11.5px;
  color: var(--ink-2);
}
.lane-hp-head strong { color: var(--ink); font-size: 11.5px; }
.lane-hp-track {
  height: 10px;
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.1);
  overflow: hidden;
}
.lane-hp-fill {
  height: 100%;
  border-radius: 5px;
  background: linear-gradient(90deg, #f07d85, #f59e8b);
  transition: width 0.12s linear;
}
.lane-hp-card.is-boss .lane-hp-fill {
  background: linear-gradient(90deg, #ef4444, #f97316);
}

/* Lower Permanent 3-Column Control Deck */
.control-deck {
  display: grid;
  grid-template-columns: 215px minmax(0, 1fr) 205px;
  gap: 8px;
  align-items: stretch;
}
.deck-box {
  padding: 10px;
  border-radius: 12px;
  background: var(--surface);
  border: 1.5px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.deck-box-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12.5px;
  color: var(--brass);
}

/* Left Column: Relics + Live Log */
.relic-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}
.relic-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  font-weight: 700;
  padding: 3px 7px;
  border-radius: 7px;
  background: rgba(229, 169, 60, 0.14);
  border: 1px solid rgba(229, 169, 60, 0.42);
  color: var(--brass);
}
.relic-empty { font-size: 11px; color: var(--ink-2); opacity: 0.65; }
.activity-log {
  flex: 1;
  min-height: 120px;
  max-height: 225px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding-top: 4px;
  border-top: 1px solid var(--line-soft);
  font-size: 11px;
  line-height: 1.45;
  color: var(--ink-2);
}
.log-entry {
  padding: 2px 0;
}
.log-entry.is-triple { color: #fde047; font-weight: 700; }
.log-entry.is-swap { color: var(--sky); }
.log-entry.is-win { color: var(--mint); font-weight: 700; }

/* Center Column: Status + 3x3 Slot Reel Grid */
.status-banner-line {
  text-align: center;
  font-size: 12.5px;
  font-weight: 800;
  color: #f6c967;
  padding: 4px 8px;
  border-radius: 7px;
  background: rgba(229, 169, 60, 0.1);
}
.prep-panel {
  display: grid;
  gap: 6px;
}
.reel-grid {
  display: grid;
  gap: 6px;
}
.reel-col-controls, .reel-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 16px minmax(0, 1fr) 16px minmax(0, 1fr) 118px;
  gap: 4px;
  align-items: center;
}
.col-ctrl {
  display: flex;
  justify-content: center;
  gap: 4px;
}
.col-ctrl-spacer {
  text-align: center;
  font-size: 11px;
  color: var(--ink-2);
}
.flow-arrow {
  text-align: center;
  color: var(--brass);
  font-weight: 900;
  font-size: 13px;
  opacity: 0.72;
  user-select: none;
}
.reel-row {
  padding: 2px;
  border-radius: 10px;
  transition: background 0.18s ease;
}
.reel-row.is-triple {
  background: rgba(253, 224, 71, 0.14);
  outline: 1.5px solid #fde047;
}
.reel-cell {
  position: relative;
  min-height: 76px;
  padding: 6px 8px;
  border-radius: 10px;
  border: 2px solid var(--u-color, var(--line-soft));
  background: linear-gradient(180deg, rgba(46, 34, 58, 0.96), rgba(33, 24, 43, 0.96));
  color: var(--ink);
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: grab;
  text-align: left;
  overflow: hidden;
  transition: transform 0.12s ease, box-shadow 0.15s ease;
}
.reel-cell:hover { transform: translateY(-1px); box-shadow: 0 4px 12px rgba(0, 0, 0, 0.35); }
.reel-cell.selected {
  border-color: #fde047;
  box-shadow: 0 0 0 2.5px rgba(253, 224, 71, 0.5);
}
.reel-cell.drag-over {
  border-color: var(--mint);
  box-shadow: 0 0 0 2.5px rgba(75, 212, 176, 0.55);
  transform: scale(1.02);
}
.reel-cell.tile-target {
  border-color: var(--mint);
  border-style: dashed;
}

/* Slot Reel Spinning & Landing Animations */
.reel-cell.is-spinning .cell-img {
  animation: reelBlurSpin 0.11s linear infinite;
  filter: blur(1.2px) brightness(1.1);
}
.reel-cell.just-landed {
  animation: reelLandBounce 0.28s cubic-bezier(0.22, 1.4, 0.36, 1);
}
@keyframes reelBlurSpin {
  0% { transform: translateY(-10px) scaleY(1.12); opacity: 0.7; }
  50% { transform: translateY(0px) scaleY(0.96); opacity: 1; }
  100% { transform: translateY(10px) scaleY(1.12); opacity: 0.7; }
}
@keyframes reelLandBounce {
  0% { transform: translateY(-7px); }
  60% { transform: translateY(3px); }
  100% { transform: translateY(0); }
}

.cell-tile {
  position: absolute;
  top: 4px;
  right: 5px;
  padding: 1px 5px;
  border-radius: 5px;
  font-size: 9.5px;
  font-weight: 900;
  color: #18111c;
  display: inline-flex;
  align-items: center;
  gap: 2px;
}
.cell-img {
  width: 56px;
  height: 56px;
  flex: none;
  object-fit: contain;
  filter: drop-shadow(0 3px 4px rgba(0, 0, 0, 0.45));
}
.cell-emoji {
  width: 52px;
  height: 52px;
  place-items: center;
  font-size: 28px;
  flex: none;
}
.cell-info {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.cell-name {
  font-size: 12.5px;
  font-weight: 800;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cell-sub {
  font-size: 10.5px;
  color: var(--ink-2);
}

/* Lane DPS Bar on Right of 3x3 Row */
.lane-dps {
  padding: 5px 7px;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.28);
  display: grid;
  gap: 3px;
}
.lane-dps-head {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--ink-2);
}
.lane-dps strong { color: #f6c967; font-size: 12px; }
.lane-dps.triple-dps strong { color: #fde047; }
.lane-dps-bar {
  height: 7px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.1);
  overflow: hidden;
}
.lane-dps-fill {
  height: 100%;
  border-radius: 4px;
  background: linear-gradient(90deg, #f07d85, #f59e0b);
}
.lane-dps.triple-dps .lane-dps-fill {
  background: linear-gradient(90deg, #fde047, #4bd4b0);
}

.strip-summary {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
  margin-top: 2px;
}
.strip-chip {
  font-size: 10.5px;
  color: var(--ink-2);
  padding: 4px 8px;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid var(--line-soft);
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Right Column: Swap Counter + Big Brass Lever + Launch */
.lever-box {
  justify-content: space-between;
  align-items: stretch;
}
.swap-counters {
  text-align: center;
  padding: 6px 4px;
  border-radius: 8px;
  background: rgba(56, 189, 248, 0.1);
  border: 1px solid rgba(56, 189, 248, 0.3);
  color: var(--sky);
  font-weight: 800;
  font-size: 13px;
  display: grid;
  gap: 3px;
}
.sub-counter {
  font-size: 11px;
  color: var(--ink-2);
  font-weight: 700;
}
.btn-lever {
  flex: 1;
  min-height: 104px;
  border-radius: 12px;
  border: 2px solid #f6c967;
  background: linear-gradient(180deg, #a87224 0%, #6d4714 100%);
  color: #fff8e7;
  font-weight: 900;
  font-size: 17px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  box-shadow: inset 0 2px 0 rgba(255, 240, 200, 0.35), 0 5px 14px rgba(0, 0, 0, 0.4);
  transition: transform 0.14s ease, filter 0.14s ease;
}
.btn-lever small {
  font-size: 11px;
  font-weight: 700;
  color: rgba(255, 248, 231, 0.85);
}
.btn-lever:hover:not(:disabled) { filter: brightness(1.08); }
.btn-lever.is-pulled {
  transform: translateY(5px) scale(0.97);
  filter: brightness(1.15);
}
.lever-img {
  width: 44px;
  height: 44px;
  object-fit: contain;
  filter: drop-shadow(0 3px 4px rgba(0, 0, 0, 0.45));
  transition: transform 0.16s cubic-bezier(0.22, 1.4, 0.36, 1);
  transform-origin: 25% 75%;
}
.btn-lever.is-pulled .lever-img {
  transform: rotate(36deg) translateY(3px);
}
.btn-lever:disabled {
  background: #2b2232;
  border-color: rgba(255, 255, 255, 0.15);
  color: rgba(255, 255, 255, 0.35);
  cursor: not-allowed;
  box-shadow: none;
}

.btn-launch {
  padding: 13px 12px;
  border-radius: 10px;
  border: 2px solid #6ee7b7;
  background: linear-gradient(180deg, #34a86c 0%, #237a4d 100%);
  color: #fff;
  font-weight: 900;
  font-size: 15px;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.35);
  transition: transform 0.12s ease, filter 0.12s ease;
}
.btn-launch:hover:not(:disabled) { filter: brightness(1.08); transform: translateY(-1px); }
.btn-launch:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-lg { width: 100%; padding: 14px; font-size: 15.5px; }

.btn-secondary, .btn-mini {
  border-radius: 8px;
  border: 1px solid var(--line-soft);
  font-weight: 800;
  cursor: pointer;
  color: var(--ink);
  background: var(--surface-2);
}
.btn-secondary { padding: 11px 14px; font-size: 13.5px; }
.btn-mini { padding: 3px 7px; font-size: 10.5px; }
.btn-mini.is-held { background: var(--brass); color: #18111c; }
.btn-secondary:disabled, .btn-mini:disabled { opacity: 0.4; cursor: not-allowed; }

/* Shop Panel inside Center Deck */
.shop-panel { display: grid; gap: 8px; }
.shop-topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 13px;
}
.shop-col-wrap { display: flex; align-items: center; gap: 6px; }
.shop-col-picker { display: flex; gap: 4px; }
.tile-place-hint {
  margin: 0;
  padding: 7px 10px;
  border-radius: 8px;
  background: rgba(75, 212, 176, 0.16);
  border: 1px solid var(--mint);
  font-size: 12px;
  font-weight: 700;
}
.shop-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(155px, 1fr));
  gap: 7px;
}
.shop-card {
  text-align: left;
  padding: 9px;
  border-radius: 10px;
  border: 1.5px solid var(--line-soft);
  border-left: 4px solid var(--item-color, var(--brass));
  background: var(--surface-2);
  color: var(--ink);
  cursor: pointer;
  display: grid;
  gap: 4px;
}
.shop-card:hover:not(:disabled) { border-color: var(--brass); }
.shop-card.bought, .shop-card:disabled { opacity: 0.42; cursor: not-allowed; }
.shop-head { display: flex; justify-content: space-between; align-items: center; gap: 6px; font-size: 12px; }
.shop-title-wrap { display: inline-flex; align-items: center; gap: 6px; min-width: 0; }
.shop-icon { width: 32px; height: 32px; object-fit: contain; flex: none; }
.mini-icon, .tile-mini-icon { width: 14px; height: 14px; object-fit: contain; vertical-align: middle; }
.shop-cost { color: #fde047; font-weight: 800; }
.shop-card p { margin: 0; font-size: 10.5px; color: var(--ink-2); line-height: 1.4; }
.shop-actions { display: grid; grid-template-columns: 1fr 1.4fr; gap: 8px; }

/* Overlays */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(14, 9, 18, 0.84);
  backdrop-filter: blur(6px);
  display: grid;
  place-items: center;
  padding: 16px;
}
#title-overlay {
  background: #15111a;
  backdrop-filter: none;
}
.overlay-card {
  width: min(680px, 100%);
  max-height: 92dvh;
  overflow-y: auto;
  padding: 22px;
  border-radius: 18px;
  background: var(--surface);
  border: 1.5px solid rgba(229, 169, 60, 0.55);
  display: grid;
  gap: 12px;
}
.eyebrow { margin: 0; font-size: 11px; font-weight: 800; letter-spacing: 0.12em; color: var(--brass); }
.overlay-card h1, .overlay-card h2 { margin: 0; font-size: 26px; }
.desc { margin: 0; font-size: 13px; color: var(--ink-2); line-height: 1.6; }
.chapter-strip { display: flex; flex-wrap: wrap; gap: 5px; }
.ch-chip {
  font-size: 10.5px;
  padding: 3px 7px;
  border-radius: 999px;
  border: 1px solid var(--line-soft);
  background: rgba(0, 0, 0, 0.25);
}
.contract-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 8px; }
.contract-card {
  text-align: left;
  padding: 10px;
  border-radius: 12px;
  border: 1.5px solid var(--line-soft);
  background: var(--surface-2);
  color: var(--ink);
  cursor: pointer;
  display: grid;
  gap: 4px;
}
.contract-card.selected { border-color: var(--brass); background: rgba(229, 169, 60, 0.15); }
.contract-card strong { font-size: 13px; }
.contract-card span { font-size: 11px; color: var(--ink-2); line-height: 1.4; }

/* Responsive Stack for Mobile / Narrow Windows */
@media (max-width: 960px) {
  .control-deck {
    grid-template-columns: 1fr;
  }
  .lever-box {
    display: grid;
    grid-template-columns: minmax(65px, .65fr) repeat(2, minmax(0, 1fr));
    align-items: stretch;
  }
  .dispatch-preview { grid-column: 1 / -1; grid-row: 1; }
  .btn-lever { min-height: 64px; }
  .stage-area { height: clamp(260px, 42vh, 360px); }
}


.dispatch-preview {
  display: grid;
  gap: 3px;
  padding: 6px 8px;
  border-radius: 8px;
  border: 1px solid #bd914d;
  background: #281b13;
  color: #fff0c9;
  font-size: 11px;
  line-height: 1.4;
  word-break: keep-all;
}
.dispatch-preview strong { color: #ffda83; font-size: 12px; }
