:root {
  --bg-deep: #070b14;
  --bg-panel: rgba(15, 23, 42, 0.88);
  --bg-card: #1e293b;
  --border-subtle: rgba(255, 255, 255, 0.1);
  --accent: #38bdf8;
  --accent-glow: rgba(56, 189, 248, 0.35);
  --gold: #fbbf24;
  --danger: #f43f5e;
  --success: #22c55e;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
}

* {
  box-sizing: border-box;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  margin: 0;
  padding: 0;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: radial-gradient(circle at 50% 20%, #1e293b 0%, #070b14 100%);
  color: var(--text-main);
  font-family: 'Segoe UI', system-ui, -apple-system, BlinkMacSystemFont, Roboto, sans-serif;
  touch-action: none;
}

/* =========================================================
   Responsive Dual-Layout Container (Mobile 9:16 & Desktop 16:9)
   ========================================================= */
#app {
  width: 100vw;
  height: 100vh;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 10px 14px;
  max-width: 520px;
  margin: 0 auto;
  position: relative;
}

.left-column {
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 2;
}

.right-column {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: relative;
  min-height: 0;
}

/* Desktop / Landscape 16:9 Widescreen Layout (CrazyGames QA Standard) */
@media (min-aspect-ratio: 11/10) and (min-width: 640px) {
  #app {
    max-width: 1360px;
    flex-direction: row;
    align-items: stretch;
    gap: clamp(10px, 1.8vw, 20px);
    padding: clamp(8px, 1.5vw, 16px) clamp(10px, 2vw, 24px);
  }
  .left-column {
    width: clamp(285px, 37vw, 390px);
    flex-shrink: 0;
    justify-content: space-between;
    background: var(--bg-panel);
    border: 1px solid var(--border-subtle);
    border-radius: 20px;
    padding: clamp(10px, 1.4vw, 16px);
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.5);
  }
  .right-column {
    flex: 1;
    background: rgba(11, 17, 32, 0.65);
    border: 1px solid var(--border-subtle);
    border-radius: 20px;
    padding: clamp(6px, 1vw, 12px);
    box-shadow: inset 0 4px 20px rgba(0, 0, 0, 0.6);
  }
}

/* Compact vertical mode for embedded mobile viewports */
@media (max-height: 680px) and (max-width: 639px) {
  #app {
    padding: 6px 8px;
    gap: 4px;
  }
  .left-column {
    gap: 5px;
  }
  .level-pill {
    padding: 4px 8px;
    font-size: 11px;
  }
  .coin-pill {
    padding: 3px 8px;
    font-size: 11px;
  }
  .icon-btn {
    height: 28px;
    padding: 0 7px;
    font-size: 11px;
  }
  .order-section {
    min-height: 54px;
    padding: 6px 8px;
  }
  .order-box {
    padding: 4px 8px;
    min-width: 82px;
  }
  .order-hole {
    width: 18px;
    height: 18px;
  }
  .dock-slots {
    padding: 5px 6px;
    gap: 4px;
  }
  .dock-slot {
    width: 34px;
    height: 34px;
  }
  .rules-bar {
    padding: 4px 8px;
    font-size: 11px;
  }
  .power-btn {
    padding: 5px 2px 4px;
  }
  .power-icon {
    font-size: 16px;
  }
  .power-name {
    font-size: 10px;
  }
}

/* =========================================================
   Top Header & Controls
   ========================================================= */
.top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.brand-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.level-pill {
  background: linear-gradient(135deg, #0284c7, #2563eb);
  color: #fff;
  padding: 6px 12px;
  border-radius: 12px;
  font-weight: 800;
  font-size: 13px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.4);
  border: 1px solid rgba(255, 255, 255, 0.25);
  transition: transform 0.12s;
}
.level-pill:hover {
  transform: scale(1.04);
}
.diff-tag {
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 6px;
  font-weight: 900;
  text-transform: uppercase;
}
.diff-easy { background: rgba(34, 197, 94, 0.25); color: #86efac; border: 1px solid rgba(34, 197, 94, 0.5); }
.diff-normal { background: rgba(56, 189, 248, 0.2); color: #7dd3fc; border: 1px solid rgba(56, 189, 248, 0.4); }
.diff-hard { background: rgba(249, 115, 22, 0.25); color: #fdba74; border: 1px solid rgba(249, 115, 22, 0.5); }
.diff-boss { background: rgba(244, 63, 94, 0.3); color: #fda4af; border: 1px solid rgba(244, 63, 94, 0.6); animation: pulseBanner 0.9s infinite alternate; }

.chapter-tabs {
  display: flex;
  gap: 5px;
  margin-bottom: 12px;
  flex-wrap: wrap;
  justify-content: center;
}
.chap-tab {
  background: #0f172a;
  border: 1px solid #334155;
  color: #94a3b8;
  padding: 5px 9px;
  border-radius: 8px;
  font-size: 11px;
  font-weight: 800;
  cursor: pointer;
}
.chap-tab.active {
  background: var(--accent);
  color: #090d16;
  border-color: #fff;
}

.coin-pill {
  background: rgba(251, 191, 36, 0.15);
  border: 1px solid rgba(251, 191, 36, 0.45);
  color: #fde68a;
  padding: 5px 10px;
  border-radius: 12px;
  font-weight: 800;
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 4px;
}

.icon-btns {
  display: flex;
  gap: 6px;
}

.icon-btn {
  background: #1e293b;
  border: 1px solid var(--border-subtle);
  color: var(--text-main);
  height: 34px;
  padding: 0 10px;
  border-radius: 10px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  transition: background 0.15s, border-color 0.15s;
}
.icon-btn:hover {
  background: #334155;
  border-color: var(--accent);
}

/* =========================================================
   Target Order Section (Screw/Bus Jam Style)
   ========================================================= */
.order-section {
  background: rgba(15, 23, 42, 0.75);
  border-radius: 16px;
  padding: 10px 12px;
  border: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 74px;
  box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.4);
}

.active-boxes {
  display: flex;
  gap: 10px;
  align-items: center;
}

.order-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 6px 12px;
  border-radius: 12px;
  border: 2px solid rgba(255, 255, 255, 0.35);
  min-width: 102px;
  box-shadow: 0 6px 14px rgba(0, 0, 0, 0.35);
  transition: transform 0.2s;
}

.order-box-title {
  font-size: 10px;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 5px;
  color: #fff;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.7);
}

.order-slots {
  display: flex;
  gap: 6px;
}

.order-hole {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.45);
  border: 2px inset rgba(255, 255, 255, 0.3);
  transition: transform 0.2s, background 0.2s;
}
.order-hole.filled {
  background: #ffffff;
  border-color: #ffffff;
  transform: scale(1.12);
  box-shadow: 0 0 10px rgba(255, 255, 255, 0.9);
}

.queue-preview {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 5px;
}
.queue-label {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 600;
}
.queue-dots {
  display: flex;
  gap: 4px;
  align-items: center;
}
.queue-dot {
  width: 16px;
  height: 16px;
  border-radius: 5px;
  border: 1.5px solid rgba(255, 255, 255, 0.6);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.4);
}

/* =========================================================
   Waiting Dock (5 ~ 7 Slots)
   ========================================================= */
.dock-section {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.dock-header {
  display: flex;
  justify-content: space-between;
  width: 100%;
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 5px;
  padding: 0 4px;
  font-weight: 600;
}

.dock-slots {
  display: flex;
  gap: 6px;
  background: #070b14;
  padding: 8px 10px;
  border-radius: 16px;
  border: 2px solid #334155;
  box-shadow: inset 0 4px 12px rgba(0, 0, 0, 0.8);
  transition: border-color 0.2s, box-shadow 0.2s;
  width: 100%;
  justify-content: center;
}
.dock-slots.danger-glow {
  border-color: var(--danger);
  box-shadow: 0 0 16px rgba(244, 63, 94, 0.5), inset 0 4px 12px rgba(0, 0, 0, 0.8);
}

.dock-slot {
  width: 42px;
  height: 42px;
  border-radius: 11px;
  background: rgba(30, 41, 59, 0.65);
  border: 1.5px dashed rgba(148, 163, 184, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  transition: transform 0.15s;
}
.dock-slot.vip-locked {
  background: rgba(251, 191, 36, 0.08);
  border: 1.5px dashed rgba(251, 191, 36, 0.55);
  cursor: pointer;
}
.dock-slot.vip-locked:hover {
  background: rgba(251, 191, 36, 0.22);
  transform: scale(1.06);
}
.vip-tag {
  font-size: 9px;
  color: var(--gold);
  font-weight: 900;
  text-align: center;
  line-height: 1.15;
}

/* =========================================================
   Status / Tutorial Tip Bar
   ========================================================= */
.rules-bar {
  font-size: 12px;
  color: #e2e8f0;
  text-align: center;
  background: rgba(56, 189, 248, 0.1);
  border: 1px solid rgba(56, 189, 248, 0.25);
  padding: 7px 10px;
  border-radius: 12px;
  line-height: 1.4;
}

/* =========================================================
   Power-up Buttons (IAA + Coin Hybrid)
   ========================================================= */
.powerup-bar {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.power-btn {
  background: linear-gradient(180deg, #334155 0%, #1e293b 100%);
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 14px;
  padding: 8px 4px 6px;
  color: var(--text-main);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  cursor: pointer;
  position: relative;
  transition: transform 0.12s, border-color 0.15s, box-shadow 0.15s;
}
.power-btn:hover {
  transform: translateY(-2px);
  border-color: var(--accent);
  box-shadow: 0 6px 14px rgba(0, 0, 0, 0.4);
}
.power-btn:active {
  transform: translateY(0);
}
.power-btn.active-tool {
  background: linear-gradient(180deg, #e11d48 0%, #9f1239 100%);
  border-color: #fda4af;
  box-shadow: 0 0 16px rgba(244, 63, 94, 0.6);
}
.power-icon {
  font-size: 20px;
  line-height: 1;
}
.power-name {
  font-size: 11px;
  font-weight: 800;
}
.cost-badge {
  font-size: 9px;
  font-weight: 900;
  padding: 1px 6px;
  border-radius: 6px;
  margin-top: 1px;
}
.cost-ad {
  background: linear-gradient(90deg, #f59e0b, #eab308);
  color: #090d16;
}
.cost-coin {
  background: rgba(56, 189, 248, 0.2);
  color: #7dd3fc;
  border: 1px solid rgba(56, 189, 248, 0.4);
}
.shortcut-key {
  position: absolute;
  top: 4px;
  left: 6px;
  font-size: 9px;
  color: rgba(255, 255, 255, 0.4);
  font-weight: 700;
}

/* =========================================================
   Maze Canvas Stage
   ========================================================= */
#mazeCanvas {
  border-radius: 18px;
  box-shadow: 0 12px 35px rgba(0, 0, 0, 0.7);
  background: #090e1a;
  cursor: pointer;
  max-width: 100%;
  max-height: 100%;
}

.hammer-banner {
  position: absolute;
  top: 14px;
  background: rgba(225, 29, 72, 0.95);
  color: #fff;
  padding: 7px 16px;
  border-radius: 24px;
  font-size: 13px;
  font-weight: 800;
  box-shadow: 0 6px 20px rgba(225, 29, 72, 0.6);
  display: none;
  align-items: center;
  gap: 10px;
  z-index: 15;
  animation: pulseBanner 0.9s infinite alternate;
}
@keyframes pulseBanner {
  from { transform: scale(1); }
  to { transform: scale(1.05); }
}

/* Toast message */
#toastBox {
  position: fixed;
  top: 18px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(15, 23, 42, 0.95);
  border: 1px solid var(--accent);
  color: #fff;
  padding: 8px 18px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 700;
  z-index: 200;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.25s;
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.6);
}

/* =========================================================
   Modals (Level Select, Result, Pause, Ad Blocker Overlay)
   ========================================================= */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(7, 11, 20, 0.85);
  backdrop-filter: blur(6px);
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}

.modal-card {
  background: #1e293b;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 22px;
  padding: 24px 22px;
  width: 100%;
  max-width: 380px;
  text-align: center;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.75);
  animation: popIn 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}
@keyframes popIn {
  from { transform: scale(0.9); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.modal-title {
  font-size: 24px;
  font-weight: 900;
  margin-bottom: 8px;
}

.modal-desc {
  font-size: 13px;
  color: #cbd5e1;
  margin-bottom: 18px;
  line-height: 1.5;
}

.modal-btn {
  width: 100%;
  padding: 13px 16px;
  border-radius: 14px;
  border: none;
  font-size: 14px;
  font-weight: 800;
  cursor: pointer;
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: transform 0.12s, filter 0.12s;
}
.modal-btn:hover {
  transform: scale(1.02);
  filter: brightness(1.06);
}
.btn-gold {
  background: linear-gradient(90deg, #f59e0b, #fbbf24);
  color: #090d16;
  box-shadow: 0 4px 15px rgba(245, 158, 11, 0.4);
}
.btn-blue {
  background: linear-gradient(90deg, #0284c7, #38bdf8);
  color: #fff;
}
.btn-dark {
  background: #334155;
  color: #f8fafc;
}

/* Level Select Grid */
.level-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  margin-bottom: 16px;
  max-height: 260px;
  overflow-y: auto;
  padding: 4px;
}
.lvl-btn {
  background: #0f172a;
  border: 1.5px solid #334155;
  color: #fff;
  border-radius: 10px;
  padding: 10px 4px;
  font-weight: 800;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s;
}
.lvl-btn.unlocked {
  background: #1e293b;
  border-color: var(--accent);
}
.lvl-btn.current {
  background: linear-gradient(135deg, #0284c7, #2563eb);
  border-color: #fff;
  box-shadow: 0 0 10px var(--accent-glow);
}
.lvl-btn.locked {
  opacity: 0.4;
  cursor: not-allowed;
}

/* Tutorial Spotlight & Mechanic Guide Modal */
.tut-badge {
  display: inline-block;
  background: rgba(56, 189, 248, 0.2);
  border: 1px solid var(--accent);
  color: #7dd3fc;
  font-size: 11px;
  font-weight: 900;
  padding: 3px 10px;
  border-radius: 20px;
  margin-bottom: 10px;
  letter-spacing: 0.5px;
}

.tut-visual-box {
  background: #090e1a;
  border: 1.5px solid #334155;
  border-radius: 16px;
  padding: 16px 12px;
  margin: 10px 0 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  font-size: 28px;
  box-shadow: inset 0 4px 12px rgba(0,0,0,0.6);
}

.tut-arrow {
  font-size: 20px;
  color: var(--gold);
  font-weight: 900;
}

.guide-list {
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 16px;
  max-height: 290px;
  overflow-y: auto;
  padding-right: 4px;
}

.guide-item {
  background: #0f172a;
  border: 1px solid #334155;
  border-radius: 12px;
  padding: 9px 12px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.guide-icon {
  font-size: 24px;
  width: 36px;
  text-align: center;
  flex-shrink: 0;
}

.guide-text {
  font-size: 12px;
  color: #e2e8f0;
  line-height: 1.4;
}

.power-btn.tut-pulse {
  border-color: var(--gold);
  box-shadow: 0 0 18px rgba(251, 191, 36, 0.65);
  animation: pulseBanner 0.7s infinite alternate;
}

/* Ad Loading Spinner */
.spinner {
  width: 36px;
  height: 36px;
  border: 4px solid rgba(56, 189, 248, 0.25);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 12px auto;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}
