/* Mirror Sanctum — 16-Bit Ancient Temple Light-Beam Puzzle Styling */
:root {
  --bg-deep: #120d0a;
  --bg-panel: #1e1611;
  --bg-panel-2: #2a1e16;
  --border-gold: #b8873a;
  --border-soft: rgba(217, 170, 88, 0.34);
  --text-main: #f9eed8;
  --text-dim: #c9b593;
  --accent-gold: #ffd54f;
  --accent-ruby: #ff4769;
  --accent-sapphire: #38bdf8;
  --accent-emerald: #34d399;
  --accent-amethyst: #c084fc;
}

*, *::before, *::after {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  min-height: 100%;
  overflow-x: hidden;
  background: radial-gradient(circle at 50% 10%, #2a1d13 0%, #120d0a 65%, #090604 100%);
  color: var(--text-main);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  user-select: none;
}

#app {
  width: 100%;
  max-width: 1020px;
  margin: 0 auto;
  padding: 8px 12px 66px; /* bottom padding clears studio-bar.js */
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.hidden {
  display: none !important;
}

/* Challenge Banner */
.challenge-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 7px 12px;
  background: linear-gradient(90deg, rgba(192, 132, 252, 0.2), rgba(255, 213, 79, 0.16));
  border: 1px solid rgba(192, 132, 252, 0.55);
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  color: #f3e8ff;
}

.icon-btn-sm {
  background: rgba(0, 0, 0, 0.35);
  color: var(--text-main);
  border: 1px solid var(--border-soft);
  border-radius: 6px;
  padding: 2px 7px;
  cursor: pointer;
}

/* Top Temple HUD */
.temple-hud {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 12px;
  background: linear-gradient(180deg, #271c14 0%, #1a120d 100%);
  border: 1px solid var(--border-gold);
  border-radius: 10px;
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.5), inset 0 1px 0 rgba(255, 213, 79, 0.18);
}

.brand-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}

.brand-gem {
  font-size: 22px;
  filter: drop-shadow(0 0 8px rgba(192, 132, 252, 0.65));
}

.brand-text h1 {
  margin: 0;
  font-size: 15px;
  letter-spacing: 1.5px;
  font-weight: 800;
  color: var(--accent-gold);
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.8);
}

.chamber-subtitle {
  font-size: 11px;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 240px;
}

.hud-stats {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.stat-pill {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 3px 9px;
  background: rgba(0, 0, 0, 0.38);
  border: 1px solid var(--border-soft);
  border-radius: 7px;
  min-width: 62px;
}

.stat-label {
  font-size: 9px;
  letter-spacing: 0.8px;
  color: var(--text-dim);
  font-weight: 700;
}

.stat-val {
  font-size: 13px;
  font-weight: 800;
  color: var(--text-main);
  font-variant-numeric: tabular-nums;
}

.stat-stars .stat-val {
  color: var(--accent-gold);
}

.hud-nav {
  display: flex;
  align-items: center;
  gap: 5px;
  flex-wrap: wrap;
}

.nav-btn {
  background: linear-gradient(180deg, #35251a, #241911);
  color: var(--text-main);
  border: 1px solid var(--border-soft);
  border-radius: 7px;
  padding: 6px 9px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  transition: transform 0.1s ease, border-color 0.15s ease, background 0.15s ease;
}

.nav-btn:hover {
  border-color: var(--accent-gold);
  background: linear-gradient(180deg, #432f20, #2e2016);
}

.nav-btn:active {
  transform: scale(0.96);
}

.nav-daily {
  border-color: rgba(192, 132, 252, 0.65);
  background: linear-gradient(180deg, #3b224f, #261436);
  color: #f3e8ff;
}

.nav-daily:hover {
  border-color: #d8b4fe;
  background: linear-gradient(180deg, #4c2a68, #321a47);
}

.nav-icon-only {
  padding: 6px 8px;
}

/* Main Stage */
.stage-wrap {
  display: flex;
  flex-direction: column;
  gap: 7px;
  width: 100%;
}

.chamber-tip-bar {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 6px 11px;
  background: rgba(34, 24, 17, 0.85);
  border: 1px solid rgba(217, 170, 88, 0.25);
  border-radius: 8px;
  font-size: 12.5px;
  color: #ebd9b8;
  line-height: 1.35;
}

.tip-icon {
  flex-shrink: 0;
}

.canvas-frame {
  position: relative;
  width: 100%;
  border-radius: 12px;
  overflow: hidden;
  border: 2px solid var(--border-gold);
  background: #140e0a;
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.65), 0 0 24px rgba(255, 209, 71, 0.08);
  display: flex;
  justify-content: center;
  align-items: center;
}

#game-canvas {
  display: block;
  width: 100%;
  height: auto;
  max-height: 62vh;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  cursor: pointer;
  touch-action: manipulation;
}

/* Contextual Statue Pill (in flow below canvas so it never obscures tiles or clips) */
.statue-pill {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px;
  padding: 6px 12px;
  margin: 0 auto;
  background: rgba(24, 16, 10, 0.94);
  border: 1px solid var(--accent-gold);
  border-radius: 10px;
  font-size: 12px;
  font-weight: 700;
  color: var(--accent-gold);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.55);
  max-width: 100%;
  text-align: center;
}

.pill-action-btn {
  background: linear-gradient(180deg, #ffd54f, #d99b26);
  color: #1c1208;
  border: none;
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 11px;
  font-weight: 800;
  cursor: pointer;
}

.guardian-pill {
  position: absolute;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 6;
  padding: 6px 14px;
  background: rgba(127, 29, 29, 0.94);
  border: 1px solid #f87171;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
  color: #fee2e2;
  box-shadow: 0 4px 16px rgba(220, 38, 38, 0.45);
  white-space: nowrap;
  max-width: calc(100% - 16px);
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Bottom Controls Bar */
.controls-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
}

.ctrl-btn {
  background: linear-gradient(180deg, #332419, #21170f);
  color: var(--text-main);
  border: 1px solid var(--border-soft);
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: transform 0.1s ease, border-color 0.15s ease;
}

.ctrl-btn:hover {
  border-color: var(--accent-gold);
}

.ctrl-btn:active {
  transform: scale(0.96);
}

.ctrl-btn kbd {
  font-family: inherit;
  font-size: 10px;
  padding: 1px 5px;
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.45);
  color: var(--text-dim);
  border: 1px solid rgba(255, 255, 255, 0.14);
}

.ctrl-hint {
  border-color: rgba(192, 132, 252, 0.6);
  background: linear-gradient(180deg, #3a234f, #241435);
  color: #f3e8ff;
}

.ctrl-nav {
  padding: 8px 12px;
}

/* Overlays & Modals */
.overlay {
  position: absolute;
  inset: 0;
  z-index: 20;
  background: rgba(10, 7, 5, 0.78);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14px;
}

#chambers-modal, #archive-modal, #leaderboard-modal {
  position: fixed;
  z-index: 50;
}

.title-card, .modal-card {
  width: 100%;
  max-width: 480px;
  max-height: 88vh;
  overflow-y: auto;
  background: linear-gradient(180deg, #271b13 0%, #17100b 100%);
  border: 2px solid var(--border-gold);
  border-radius: 14px;
  padding: 20px;
  box-shadow: 0 20px 55px rgba(0, 0, 0, 0.85), inset 0 1px 0 rgba(255, 213, 79, 0.25);
  text-align: center;
}

.modal-wide {
  max-width: 680px;
  text-align: left;
}

.modal-med {
  max-width: 460px;
  text-align: left;
}

.title-eyebrow {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 2px;
  color: var(--accent-amethyst);
  margin-bottom: 4px;
}

.title-logo {
  margin: 0 0 8px;
  font-size: 32px;
  font-weight: 900;
  letter-spacing: 2.5px;
  background: linear-gradient(180deg, #fff5c0 0%, #ffd54f 55%, #d9822b 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 3px 10px rgba(255, 196, 54, 0.35));
}

.title-desc {
  margin: 0 auto 12px;
  font-size: 13.5px;
  line-height: 1.45;
  color: var(--text-dim);
  max-width: 400px;
}

.title-features {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
  margin-bottom: 16px;
}

.title-features span {
  font-size: 11.5px;
  font-weight: 700;
  padding: 4px 9px;
  border-radius: 999px;
  background: rgba(255, 213, 79, 0.1);
  border: 1px solid rgba(255, 213, 79, 0.28);
  color: #fce9b2;
}

.title-actions {
  display: flex;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.title-progress {
  font-size: 12px;
  color: var(--text-dim);
}

/* Buttons */
.btn-primary, .btn-secondary, .btn-gold {
  border: none;
  border-radius: 9px;
  padding: 10px 18px;
  font-size: 14px;
  font-weight: 800;
  cursor: pointer;
  transition: transform 0.1s ease, filter 0.15s ease;
}

.btn-lg {
  padding: 12px 22px;
  font-size: 15px;
}

.btn-primary {
  background: linear-gradient(180deg, #ffd54f 0%, #e0911f 100%);
  color: #1c1106;
  box-shadow: 0 4px 16px rgba(255, 193, 54, 0.35);
}

.btn-secondary {
  background: linear-gradient(180deg, #432d4f 0%, #2a1a36 100%);
  color: #f5e9ff;
  border: 1px solid rgba(192, 132, 252, 0.55);
}

.btn-gold {
  background: linear-gradient(180deg, #38bdf8 0%, #0284c7 100%);
  color: #061826;
}

.btn-primary:hover, .btn-secondary:hover, .btn-gold:hover {
  filter: brightness(1.08);
}

.btn-primary:active, .btn-secondary:active, .btn-gold:active {
  transform: scale(0.97);
}

/* Victory Modal */
.victory-card h2 {
  margin: 2px 0 4px;
  font-size: 26px;
  letter-spacing: 1.5px;
  color: var(--accent-gold);
}

.victory-rays {
  font-size: 28px;
  line-height: 1;
}

.victory-subtitle {
  font-size: 13px;
  color: var(--text-dim);
  margin-bottom: 8px;
}

.victory-stars {
  font-size: 36px;
  letter-spacing: 6px;
  color: var(--accent-gold);
  text-shadow: 0 0 18px rgba(255, 213, 79, 0.65);
  margin-bottom: 12px;
}

.victory-metrics {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}

.v-metric {
  background: rgba(0, 0, 0, 0.38);
  border: 1px solid var(--border-soft);
  border-radius: 8px;
  padding: 8px 6px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

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

.v-val {
  font-size: 14px;
  font-weight: 800;
  color: var(--text-main);
}

.cliffhanger-box {
  background: linear-gradient(90deg, rgba(255, 213, 79, 0.14), rgba(192, 132, 252, 0.14));
  border: 1px solid rgba(255, 213, 79, 0.42);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 12.5px;
  color: #fdeab3;
  margin-bottom: 14px;
}

.daily-submit-box {
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid rgba(192, 132, 252, 0.4);
  border-radius: 8px;
  padding: 10px;
  margin-bottom: 12px;
}

.daily-submit-label {
  font-size: 12px;
  font-weight: 700;
  color: #e9d5ff;
  margin-bottom: 6px;
}

.daily-submit-row {
  display: flex;
  gap: 6px;
}

.daily-submit-row input {
  flex: 1;
  min-width: 0;
  padding: 8px 10px;
  border-radius: 7px;
  border: 1px solid var(--border-soft);
  background: #140e0a;
  color: var(--text-main);
  font-size: 13px;
}

.submit-status {
  font-size: 11.5px;
  color: var(--accent-emerald);
  margin-top: 5px;
  min-height: 15px;
}

.victory-actions {
  display: flex;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
}

.share-feedback {
  margin-top: 8px;
  font-size: 12px;
  color: var(--accent-emerald);
  min-height: 16px;
}

/* Modal Headers */
.modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
  border-bottom: 1px solid var(--border-soft);
  padding-bottom: 10px;
}

.modal-header h2 {
  margin: 0;
  font-size: 18px;
  color: var(--accent-gold);
}

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

.close-modal-btn {
  background: rgba(0, 0, 0, 0.45);
  color: var(--text-main);
  border: 1px solid var(--border-soft);
  border-radius: 8px;
  padding: 5px 10px;
  font-size: 14px;
  font-weight: 800;
  cursor: pointer;
}

/* Chambers Grid */
.wings-scroll {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.wing-block {
  background: rgba(0, 0, 0, 0.28);
  border: 1px solid var(--border-soft);
  border-radius: 10px;
  padding: 10px 12px;
}

.wing-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.wing-title {
  font-size: 14px;
  font-weight: 800;
}

.wing-sub {
  font-size: 11px;
  color: var(--text-dim);
}

.chamber-tiles-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(76px, 1fr));
  gap: 6px;
}

.ch-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 7px 5px;
  border-radius: 8px;
  background: linear-gradient(180deg, #322419, #20160f);
  border: 1px solid var(--border-soft);
  color: var(--text-main);
  cursor: pointer;
  transition: transform 0.1s ease, border-color 0.15s ease;
}

.ch-card:hover:not(:disabled) {
  border-color: var(--accent-gold);
  transform: translateY(-1px);
}

.ch-card.active {
  border-color: var(--accent-gold);
  box-shadow: 0 0 12px rgba(255, 213, 79, 0.35);
}

.ch-card:disabled {
  opacity: 0.42;
  cursor: not-allowed;
}

.ch-num {
  font-size: 14px;
  font-weight: 800;
}

.ch-stars {
  font-size: 11px;
  color: var(--accent-gold);
  letter-spacing: 1px;
}

.ch-name {
  font-size: 9.5px;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

/* Archive & Themes */
.archive-stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 8px;
  margin-bottom: 16px;
}

.arch-stat {
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid var(--border-soft);
  border-radius: 8px;
  padding: 10px;
  text-align: center;
}

.arch-val {
  font-size: 20px;
  font-weight: 900;
  color: var(--accent-gold);
}

.arch-lbl {
  font-size: 11px;
  color: var(--text-dim);
  margin-top: 2px;
}

.section-title {
  margin: 0 0 10px;
  font-size: 14px;
  color: var(--text-main);
}

.themes-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(145px, 1fr));
  gap: 8px;
}

.theme-card {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 10px;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid var(--border-soft);
  cursor: pointer;
  text-align: left;
  color: var(--text-main);
}

.theme-card.selected {
  border-color: var(--accent-gold);
  box-shadow: 0 0 14px rgba(255, 213, 79, 0.3);
}

.theme-card.locked {
  opacity: 0.52;
  cursor: not-allowed;
}

.theme-swatch {
  height: 28px;
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.18);
}

.theme-name {
  font-size: 13px;
  font-weight: 800;
}

.theme-req {
  font-size: 11px;
  color: var(--text-dim);
}

/* Leaderboard */
.lb-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
  max-height: 320px;
  overflow-y: auto;
}

.lb-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.34);
  border: 1px solid rgba(217, 170, 88, 0.22);
  font-size: 13px;
}

.lb-rank {
  font-weight: 800;
  color: var(--accent-gold);
  width: 28px;
}

.lb-name {
  flex: 1;
  font-weight: 700;
}

.lb-score {
  font-weight: 800;
  color: var(--accent-sapphire);
}

.lb-empty {
  text-align: center;
  padding: 18px;
  color: var(--text-dim);
  font-size: 13px;
}

.lb-footer {
  display: flex;
  justify-content: center;
}

/* Mobile Responsive (390x844 — Zero Horizontal Overflow!) */
@media (max-width: 680px) {
  #app {
    padding: 6px 6px 68px;
    gap: 6px;
  }

  .temple-hud {
    padding: 7px 8px;
    gap: 6px;
  }

  .brand-text h1 {
    font-size: 13px;
    letter-spacing: 1px;
  }

  .chamber-subtitle {
    font-size: 10.5px;
    max-width: 190px;
  }

  .hud-stats {
    width: 100%;
    justify-content: space-between;
    gap: 4px;
  }

  .stat-pill {
    flex: 1;
    min-width: 0;
    padding: 3px 4px;
  }

  .stat-val {
    font-size: 12px;
  }

  .hud-nav {
    width: 100%;
    justify-content: space-between;
    gap: 4px;
  }

  .nav-btn {
    flex: 1;
    justify-content: center;
    padding: 6px 5px;
    font-size: 11px;
  }

  .nav-icon-only {
    flex: 0 0 auto;
    padding: 6px 9px;
  }

  .chamber-tip-bar {
    font-size: 11.5px;
    padding: 5px 8px;
  }

  #game-canvas {
    max-height: 55vh;
  }

  .controls-bar {
    gap: 5px;
  }

  .ctrl-btn {
    padding: 7px 10px;
    font-size: 12px;
  }

  .ctrl-btn kbd {
    display: none;
  }

  .statue-pill {
    font-size: 11px;
    padding: 5px 10px;
    gap: 6px;
  }

  #title-overlay, #victory-overlay {
    position: fixed;
    z-index: 45;
  }

  .title-logo {
    font-size: 24px;
  }

  .title-card, .modal-card {
    padding: 15px;
  }
}
