/**
 * Size It: Stack It to 100m - Viewport-Optimized Stylesheet
 * Responsive Scale Blackjack layout designed to fit on mobile and desktop without awkward scrolling.
 */

:root {
  --stack-gold: #f59e0b;
  --stack-gold-glow: rgba(245, 158, 11, 0.4);
  --stack-success: #10b981;
  --stack-success-glow: rgba(16, 185, 129, 0.35);
  --stack-bust: #ef4444;
  --stack-bust-glow: rgba(239, 68, 68, 0.4);
  --stack-target-line: #ff4757;
  --stack-cyan: #06b6d4;
  --stack-cyan-glow: rgba(6, 182, 212, 0.35);
  --stack-line: rgba(22, 32, 46, 0.12);
  --stack-surface: #ffffff;
  --stack-surface-raise: rgba(22, 32, 46, 0.05);
}

html.dark {
  --stack-gold: #fbbf24;
  --stack-gold-glow: rgba(251, 191, 36, 0.45);
  --stack-success: #34d399;
  --stack-success-glow: rgba(52, 211, 153, 0.35);
  --stack-bust: #f87171;
  --stack-bust-glow: rgba(248, 113, 113, 0.45);
  --stack-target-line: #ff6b81;
  --stack-cyan: #22d3ee;
  --stack-cyan-glow: rgba(34, 211, 238, 0.35);
  --stack-line: rgba(255, 255, 255, 0.14);
  --stack-surface: #141c27;
  --stack-surface-raise: rgba(255, 255, 255, 0.06);
}

/* Base resets */
html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* Header */
.stack-header {
  height: 48px;
  min-height: 48px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 14px;
  z-index: 50;
  flex-shrink: 0;
  gap: 8px;
  box-sizing: border-box;
}

.stack-header-left {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.stack-header .brand-logo {
  display: flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  color: var(--text);
}

.stack-header .brand-icon {
  width: 26px;
  height: 26px;
  display: block;
}

.stack-header .brand-title {
  font-size: 14px;
  font-weight: 800;
  line-height: 1.1;
  letter-spacing: -0.02em;
}

.stack-header .brand-badge {
  font-size: 10px;
  font-weight: 700;
  color: var(--stack-cyan);
  text-transform: uppercase;
}

.stack-header-right {
  display: flex;
  align-items: center;
  gap: 6px;
}

.icon-btn {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.15s ease;
  font-size: 12px;
  font-weight: 800;
}

.icon-btn:hover {
  background: var(--surface-raise);
  border-color: var(--line-strong);
}

/* Sub-HUD Bar */
.stack-sub-hud {
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  padding: 6px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-shrink: 0;
  font-size: 12px;
}

.stack-hud-left {
  display: flex;
  align-items: center;
  gap: 8px;
}

.stack-target-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: rgba(255, 71, 87, 0.12);
  border: 1px solid rgba(255, 71, 87, 0.35);
  padding: 3px 8px;
  border-radius: 999px;
  font-weight: 800;
  color: var(--stack-target-line);
}

.stack-stage-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-weight: 700;
  color: var(--text-dim);
}

.stage-dots {
  display: flex;
  gap: 4px;
}

.stage-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--line);
  border: 1px solid var(--line-strong);
}

.stage-dot.active {
  background: var(--stack-cyan);
  border-color: var(--stack-cyan);
  box-shadow: 0 0 6px var(--stack-cyan-glow);
}

.stage-dot.completed {
  background: var(--stack-success);
  border-color: var(--stack-success);
}

.stage-dot.busted {
  background: var(--stack-bust);
  border-color: var(--stack-bust);
}

.stack-hud-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.hud-chip {
  display: flex;
  align-items: baseline;
  gap: 3px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.hud-chip-label {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-dim);
}

.hud-chip-val {
  font-size: 13px;
  font-weight: 900;
  color: var(--text);
}

/* Mode Bar (Standard / Micro / Titan) */
.stack-mode-bar {
  background: var(--surface-raise-2);
  border-bottom: 1px solid var(--line);
  padding: 4px 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  flex-shrink: 0;
}

.stack-mode-btn {
  background: transparent;
  border: 1px solid transparent;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  color: var(--text-dim);
  cursor: pointer;
  transition: all 0.15s ease;
}

.stack-mode-btn:hover {
  color: var(--text);
}

.stack-mode-btn.active {
  background: var(--surface);
  color: var(--stack-cyan);
  border-color: var(--stack-cyan);
  box-shadow: 0 1px 4px rgba(6, 182, 212, 0.2);
}

/* Main Container */
.stack-main {
  flex: 1;
  max-width: 980px;
  margin: 0 auto;
  width: 100%;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-sizing: border-box;
}

/* Playfield Grid */
.stack-playfield {
  display: grid;
  grid-template-columns: minmax(280px, 1.1fr) minmax(280px, 1fr);
  gap: 12px;
  align-items: stretch;
}

@media (max-width: 768px) {
  .stack-playfield {
    grid-template-columns: 1fr;
    gap: 10px;
  }
}

/* =========================================================================
   TOWER SECTION & GAUGE RULER
   ========================================================================= */

.stack-tower-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.04);
  height: 380px;
  position: relative;
}

@media (max-width: 768px) {
  .stack-tower-panel {
    height: 250px;
  }
}

.tower-panel-header {
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-raise-2);
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
  font-weight: 800;
  color: var(--text-dim);
  flex-shrink: 0;
}

.tower-header-altitude {
  display: flex;
  align-items: baseline;
  gap: 6px;
  font-size: 13px;
  color: var(--text);
}

.tower-header-altitude strong {
  font-size: 15px;
  font-weight: 900;
  color: var(--stack-cyan);
}

.tower-arena {
  flex: 1;
  display: flex;
  position: relative;
  overflow: hidden;
  background-image: 
    linear-gradient(to right, rgba(6, 182, 212, 0.04) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(6, 182, 212, 0.04) 1px, transparent 1px);
  background-size: 16px 16px;
}

/* Thermometer / Ruler Gauge on Left */
.stack-gauge-col {
  width: 72px;
  border-right: 1px solid var(--line);
  background: rgba(22, 32, 46, 0.02);
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  flex-shrink: 0;
  user-select: none;
  padding: 0 4px;
  box-sizing: border-box;
}

html.dark .stack-gauge-col {
  background: rgba(255, 255, 255, 0.02);
}

.gauge-track {
  position: absolute;
  left: 8px;
  right: 8px;
  bottom: 10px;
  top: 10px;
  background: var(--surface-raise-2);
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid var(--line);
}

.gauge-fill {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 0%;
  background: linear-gradient(to top, var(--stack-cyan), #3b82f6);
  border-radius: 4px;
  transition: height 0.4s cubic-bezier(0.34, 1.56, 0.64, 1), background 0.3s ease;
}

.gauge-fill.zone-sweet {
  background: linear-gradient(to top, #10b981, #059669);
  box-shadow: 0 0 10px rgba(16, 185, 129, 0.5);
}

.gauge-fill.zone-bust {
  background: linear-gradient(to top, #ef4444, #b91c1c);
  box-shadow: 0 0 12px rgba(239, 68, 68, 0.6);
}

/* Sweet Spot Bracket (90m - 100m) */
.gauge-sweet-spot {
  position: absolute;
  left: 0;
  right: 0;
  border: 1px dashed var(--stack-success);
  background: rgba(16, 185, 129, 0.15);
  pointer-events: none;
  z-index: 2;
}

/* Target 100m Line */
.gauge-target-mark {
  position: absolute;
  left: 0;
  right: 0;
  height: 2px;
  background: var(--stack-target-line);
  box-shadow: 0 0 8px var(--stack-target-line);
  z-index: 3;
}

.gauge-target-tag {
  position: absolute;
  right: 2px;
  transform: translateY(-50%);
  font-size: 9px;
  font-weight: 900;
  color: #fff;
  background: var(--stack-target-line);
  padding: 1px 4px;
  border-radius: 3px;
  white-space: nowrap;
}

/* Ruler Tick Labels alongside track */
.gauge-ruler-ticks {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 10px;
  top: 10px;
  pointer-events: none;
}

.gauge-tick-lbl {
  position: absolute;
  right: 2px;
  transform: translateY(50%);
  font-size: 8px;
  font-weight: 700;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
}

/* Vertical Stack Column on Right */
.stack-tower-scroll {
  flex: 1;
  position: relative;
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column-reverse;
  padding: 10px 14px 20px 14px;
  gap: 8px;
  box-sizing: border-box;
}

.stack-ground-line {
  height: 8px;
  width: 100%;
  background: repeating-linear-gradient(
    -45deg,
    var(--line-strong),
    var(--line-strong) 4px,
    transparent 4px,
    transparent 8px
  );
  border-top: 2px solid var(--line-strong);
  margin-top: 4px;
  flex-shrink: 0;
}

.tower-item-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 10px;
  display: flex;
  align-items: center;
  gap: 10px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.05);
  animation: dropItemIn 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
  flex-shrink: 0;
}

@keyframes dropItemIn {
  from {
    transform: translateY(-20px) scale(0.9);
    opacity: 0;
  }
  to {
    transform: translateY(0) scale(1);
    opacity: 1;
  }
}

.tower-item-num {
  font-size: 10px;
  font-weight: 800;
  color: var(--text-dim);
  width: 18px;
  text-align: center;
}

.tower-item-svg-box {
  width: 44px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.tower-item-svg-box svg {
  max-width: 100%;
  max-height: 100%;
  color: var(--text);
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.2));
}

.tower-item-info {
  flex: 1;
  min-width: 0;
}

.tower-item-title {
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text);
}

.tower-item-contrib {
  font-size: 11px;
  font-weight: 800;
  color: var(--stack-cyan);
}

.tower-item-elevation {
  font-size: 11px;
  font-weight: 800;
  color: var(--text-dim);
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* Tower Empty State */
.tower-empty-placeholder {
  margin: auto;
  text-align: center;
  color: var(--text-dim);
  padding: 20px;
}

.tower-empty-placeholder svg {
  width: 48px;
  height: 48px;
  opacity: 0.3;
  margin-bottom: 6px;
}

/* Busted reaction */
.stack-tower-panel.busted {
  border-color: var(--stack-bust);
  box-shadow: 0 0 16px var(--stack-bust-glow);
}

.stack-tower-panel.busted .tower-item-card {
  filter: grayscale(1);
  border-color: var(--stack-bust);
}

/* =========================================================================
   DEALER CARD & ACTION CONTROLS
   ========================================================================= */

.stack-dealer-panel {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.dealer-box {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.04);
  flex: 1;
  justify-content: space-between;
  min-height: 220px;
}

@media (max-width: 768px) {
  .dealer-box {
    min-height: 180px;
    padding: 10px;
  }
}

.dealer-top-row {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 11px;
}

.dealer-cat-tag {
  font-weight: 700;
  padding: 2px 8px;
  background: var(--surface-raise-2);
  border-radius: 999px;
  color: var(--text-dim);
}

.dealer-secret-tag {
  font-weight: 800;
  color: var(--stack-cyan);
}

.dealer-svg-canvas {
  width: 100%;
  height: 100px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 6px 0;
}

@media (max-width: 768px) {
  .dealer-svg-canvas {
    height: 75px;
  }
}

.dealer-svg-canvas svg {
  max-width: 90%;
  max-height: 100%;
  color: var(--text);
  filter: drop-shadow(0 3px 8px rgba(0, 0, 0, 0.15));
}

.dealer-meta-details {
  width: 100%;
}

.dealer-name {
  font-size: 16px;
  font-weight: 800;
  margin: 0 0 2px 0;
  color: var(--text);
}

.dealer-sub {
  font-size: 12px;
  color: var(--text-dim);
  margin: 0 0 6px 0;
}

.dealer-concealed-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: rgba(6, 182, 212, 0.08);
  border: 1px dashed var(--stack-cyan);
  padding: 3px 10px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 800;
  color: var(--stack-cyan);
}

/* Action Controls Dock */
.stack-controls-dock {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.controls-main-row {
  display: grid;
  grid-template-columns: 1fr 1.3fr;
  gap: 8px;
}

.stack-btn {
  border: none;
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 13px;
  font-weight: 800;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: all 0.15s ease;
  user-select: none;
}

.btn-pass-action {
  background: var(--surface-raise-2);
  color: var(--text);
  border: 1px solid var(--line);
}

.btn-pass-action:hover:not(:disabled) {
  background: var(--surface-raise);
  border-color: var(--line-strong);
}

.btn-pass-action:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.btn-stack-action {
  background: var(--stack-cyan);
  color: #fff;
  box-shadow: 0 3px 10px var(--stack-cyan-glow);
}

.btn-stack-action:hover:not(:disabled) {
  background: #0891b2;
  transform: translateY(-1px);
}

.btn-hold-action {
  background: var(--stack-success);
  color: #fff;
  box-shadow: 0 3px 10px var(--stack-success-glow);
  padding: 11px 16px;
  font-size: 14px;
}

.btn-hold-action:hover:not(:disabled) {
  background: #059669;
  transform: translateY(-1px);
}

.btn-hold-action:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* Recent Actions Bar */
.stack-quick-log {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 11px;
}

.quick-log-title {
  font-weight: 800;
  color: var(--text-dim);
  margin-bottom: 4px;
  display: flex;
  justify-content: space-between;
}

.quick-log-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
  max-height: 70px;
  overflow-y: auto;
}

.quick-log-entry {
  display: flex;
  justify-content: space-between;
  padding: 2px 6px;
  background: var(--surface-raise-2);
  border-radius: 4px;
}

.quick-log-entry.pass {
  opacity: 0.5;
  text-decoration: line-through;
}

/* =========================================================================
   MODALS (Stage Result, Run Complete, Help)
   ========================================================================= */

.stack-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14px;
  z-index: 1000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.stack-modal-backdrop.open {
  opacity: 1;
  pointer-events: auto;
}

.stack-modal-card {
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: 18px;
  width: 100%;
  max-width: 440px;
  padding: 20px;
  box-sizing: border-box;
  box-shadow: 0 16px 36px rgba(0, 0, 0, 0.25);
  text-align: center;
  transform: scale(0.95);
  transition: transform 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.stack-modal-backdrop.open .stack-modal-card {
  transform: scale(1);
}

.modal-icon-badge {
  font-size: 38px;
  margin-bottom: 6px;
}

.modal-card-title {
  font-size: 20px;
  font-weight: 900;
  margin: 0 0 4px 0;
}

.modal-card-desc {
  font-size: 13px;
  color: var(--text-dim);
  margin: 0 0 14px 0;
}

.modal-metrics-grid {
  background: var(--surface-raise-2);
  border-radius: 10px;
  padding: 10px;
  margin-bottom: 14px;
  display: flex;
  justify-content: space-around;
  align-items: center;
}

.modal-metric {
  display: flex;
  flex-direction: column;
}

.metric-label {
  font-size: 10px;
  font-weight: 700;
  color: var(--text-dim);
  text-transform: uppercase;
}

.metric-val {
  font-size: 18px;
  font-weight: 900;
  color: var(--text);
}

.modal-metric.highlight .metric-val {
  color: var(--stack-cyan);
}

.modal-stages-list {
  list-style: none;
  padding: 0;
  margin: 0 0 14px 0;
  display: flex;
  flex-direction: column;
  gap: 5px;
  text-align: left;
  font-size: 12px;
}

.modal-stage-row {
  display: flex;
  justify-content: space-between;
  padding: 5px 8px;
  background: var(--surface-raise-2);
  border-radius: 6px;
}

.modal-action-row {
  display: flex;
  gap: 8px;
  justify-content: center;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%) translateY(40px);
  background: var(--text);
  color: var(--bg);
  padding: 8px 18px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
  z-index: 2000;
  opacity: 0;
  pointer-events: none;
  transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2);
}

.toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

/* Editorial / SEO section */
.stack-editorial {
  max-width: 800px;
  margin: 20px auto 0 auto;
  padding: 0 8px;
}

.stack-editorial h1,
.stack-editorial h2 {
  font-size: 20px;
  font-weight: 800;
  margin: 24px 0 10px 0;
  color: var(--text);
}

.stack-editorial p {
  font-size: 14px;
  line-height: 1.6;
  color: var(--text-dim);
  margin: 0 0 12px 0;
}

.stack-steps-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 10px;
  margin: 14px 0 20px 0;
}

.stack-step-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
}

.stack-step-num {
  display: inline-block;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--stack-cyan);
  color: #fff;
  font-size: 11px;
  font-weight: 800;
  line-height: 22px;
  text-align: center;
  margin-bottom: 6px;
}

.stack-step-title {
  font-size: 13px;
  font-weight: 800;
  margin: 0 0 4px 0;
  color: var(--text);
}

.stack-step-text {
  font-size: 11px;
  color: var(--text-dim);
  line-height: 1.4;
  margin: 0;
}

.stack-faq-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 14px;
  margin-bottom: 10px;
}

.stack-faq-q {
  font-size: 14px;
  font-weight: 800;
  margin: 0 0 4px 0;
  color: var(--text);
}

.stack-faq-a {
  font-size: 12px;
  line-height: 1.5;
  color: var(--text-dim);
  margin: 0;
}
