/* ==========================================================================
   WINDOW BREAKER v2.0 — Studio Editorial Blueprint / Swiss Vellum / Cyber Lab
   ========================================================================== */

:root {
  --bg: #090c12;
  --bg-elevated: rgba(14, 19, 28, 0.86);
  --surface: rgba(19, 25, 37, 0.94);
  --border: rgba(235, 244, 255, 0.13);
  --border-strong: rgba(235, 244, 255, 0.28);
  --ink: #f0f4fa;
  --ink-muted: #8a97ab;
  --accent: #ff4422;
  --accent-soft: rgba(255, 68, 34, 0.18);
  --cyan: #00e5ff;
  --cyan-soft: rgba(0, 229, 255, 0.15);
  --violet: #a855f7;
  --gold: #ffb800;
  --shadow: 0 22px 60px rgba(0, 0, 0, 0.62);
  --font-sans: -apple-system, BlinkMacSystemFont, "SF Pro Display", "PingFang TC", "Noto Sans TC", "Segoe UI", sans-serif;
  --font-mono: "SF Mono", ui-monospace, "JetBrains Mono", Menlo, Monaco, Consolas, monospace;
}

[data-theme="paper"] {
  --bg: #f4efe4;
  --bg-elevated: rgba(249, 245, 236, 0.92);
  --surface: rgba(255, 253, 248, 0.97);
  --border: rgba(18, 22, 32, 0.14);
  --border-strong: rgba(18, 22, 32, 0.3);
  --ink: #121620;
  --ink-muted: #586274;
  --accent: #e03616;
  --accent-soft: rgba(224, 54, 22, 0.12);
  --cyan: #007a94;
  --cyan-soft: rgba(0, 122, 148, 0.12);
  --violet: #7c3aed;
  --gold: #c98200;
  --shadow: 0 18px 48px rgba(18, 22, 32, 0.14);
}

[data-theme="cyber"] {
  --bg: #070614;
  --bg-elevated: rgba(14, 11, 32, 0.88);
  --surface: rgba(18, 14, 40, 0.95);
  --border: rgba(0, 255, 157, 0.18);
  --border-strong: rgba(0, 255, 157, 0.38);
  --ink: #eafff5;
  --ink-muted: #8b85b3;
  --accent: #ff2a85;
  --accent-soft: rgba(255, 42, 133, 0.2);
  --cyan: #00ff9d;
  --cyan-soft: rgba(0, 255, 157, 0.16);
  --violet: #b967ff;
  --gold: #ffe600;
  --shadow: 0 22px 60px rgba(0, 0, 0, 0.72);
}

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

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-sans);
  transition: background-color 0.28s ease, color 0.28s ease;
}

#game-canvas {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  display: block;
}

.atmosphere-overlay {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 3;
  background: radial-gradient(circle at 50% 50%, transparent 58%, rgba(0, 0, 0, 0.28) 100%);
}
[data-theme="paper"] .atmosphere-overlay {
  background: radial-gradient(circle at 50% 50%, transparent 65%, rgba(120, 100, 70, 0.09) 100%);
}
[data-theme="cyber"] .atmosphere-overlay {
  background:
    repeating-linear-gradient(to bottom, transparent 0px, transparent 3px, rgba(0, 255, 157, 0.02) 3px, rgba(0, 255, 157, 0.02) 4px),
    radial-gradient(circle at 50% 50%, transparent 54%, rgba(0, 0, 0, 0.42) 100%);
}

.hidden {
  display: none !important;
}

/* ==========================================================================
   Edge Kinetic Stress Glows
   ========================================================================== */
.edge-glow {
  position: fixed;
  pointer-events: none;
  z-index: 6;
  opacity: 0;
  transition: opacity 0.1s ease-out;
}
.edge-top {
  top: 0; left: 0; right: 0; height: 18px;
  background: linear-gradient(to bottom, var(--accent), transparent);
}
.edge-bottom {
  bottom: 0; left: 0; right: 0; height: 18px;
  background: linear-gradient(to top, var(--cyan), transparent);
}
.edge-left {
  top: 0; bottom: 0; left: 0; width: 18px;
  background: linear-gradient(to right, var(--accent), transparent);
}
.edge-right {
  top: 0; bottom: 0; right: 0; width: 18px;
  background: linear-gradient(to left, var(--accent), transparent);
}

/* ==========================================================================
   Top Technical HUD
   ========================================================================== */
.hud-bar {
  position: fixed;
  top: 12px;
  left: 14px;
  right: 14px;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  pointer-events: none;
}

.hud-left, .hud-center, .hud-right {
  display: flex;
  align-items: center;
  gap: 7px;
  pointer-events: auto;
}

.window-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border-radius: 7px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  backdrop-filter: blur(14px);
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
}

.badge-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 9px var(--accent);
}
.badge-dot.cyan {
  background: var(--cyan);
  box-shadow: 0 0 9px var(--cyan);
}

.level-meta {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 5px 12px;
  border-radius: 7px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  backdrop-filter: blur(14px);
}

.level-code {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 800;
  color: var(--accent);
  letter-spacing: 0.06em;
}
.level-sep {
  color: var(--border-strong);
  font-family: var(--font-mono);
  font-size: 11px;
}
.level-title {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.hud-center {
  padding: 5px 12px;
  border-radius: 7px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  backdrop-filter: blur(14px);
  font-family: var(--font-mono);
  font-size: 11px;
}

.telemetry-item {
  display: flex;
  align-items: center;
  gap: 5px;
}
.t-label {
  color: var(--ink-muted);
  font-size: 9.5px;
  letter-spacing: 0.08em;
}
.t-val {
  font-weight: 700;
  min-width: 52px;
}
.t-val.inverted { color: var(--violet); }
.t-val.blurred { color: var(--cyan); }

.telemetry-sep {
  width: 1px;
  height: 12px;
  background: var(--border);
}

.hud-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 31px;
  padding: 0 10px;
  border-radius: 7px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  backdrop-filter: blur(14px);
  transition: transform 0.12s ease, border-color 0.15s ease, background 0.15s ease;
}
.hud-btn:hover {
  border-color: var(--border-strong);
  transform: translateY(-1px);
}
.hud-btn:active {
  transform: translateY(0);
}
.hud-btn.icon-only {
  width: 31px;
  padding: 0;
  justify-content: center;
  font-size: 14px;
}
.hud-btn.active {
  border-color: var(--cyan);
  background: var(--cyan-soft);
  color: var(--cyan);
}
.hud-btn.accent-btn {
  border-color: var(--cyan);
  background: var(--cyan-soft);
  color: var(--cyan);
  animation: pulse-cyan 2.1s infinite;
}

@keyframes pulse-cyan {
  0%, 100% { box-shadow: 0 0 0 0 rgba(0, 229, 255, 0.35); }
  50% { box-shadow: 0 0 0 7px rgba(0, 229, 255, 0); }
}

@media (max-width: 880px) {
  #telemetry-strip { display: none; }
  .hud-btn .btn-text { display: none; }
}
@media (max-width: 580px) {
  .level-title, .level-sep { display: none; }
}

/* ==========================================================================
   Cinematic Level Intro Banner
   ========================================================================== */
.level-banner {
  position: fixed;
  top: 64px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 22;
  padding: 12px 26px;
  border-radius: 10px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  backdrop-filter: blur(16px);
  text-align: center;
  pointer-events: none;
  animation: banner-in 2.3s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}
.lb-chapter {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.14em;
  color: var(--accent);
  margin-bottom: 3px;
}
.lb-main {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 10px;
}
.lb-code {
  font-family: var(--font-mono);
  font-size: 14px;
  font-weight: 800;
  color: var(--cyan);
}
.lb-title {
  font-size: 20px;
  font-weight: 800;
  letter-spacing: 0.03em;
}
.lb-sub {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-muted);
  margin-top: 2px;
}

@keyframes banner-in {
  0% { opacity: 0; transform: translate(-50%, -14px) scale(0.96); }
  12% { opacity: 1; transform: translate(-50%, 0) scale(1); }
  80% { opacity: 1; transform: translate(-50%, 0) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -10px) scale(0.98); }
}

/* ==========================================================================
   Bottom Hint Pill, Keyboard Gag & Achievement Toast
   ========================================================================== */
.hint-pill {
  position: fixed;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: calc(100vw - 28px);
  padding: 8px 14px;
  border-radius: 999px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  backdrop-filter: blur(16px);
  box-shadow: var(--shadow);
  font-size: 13px;
}

.hint-tag {
  flex-shrink: 0;
  padding: 2px 8px;
  border-radius: 4px;
  background: var(--accent-soft);
  color: var(--accent);
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
}

.hint-text {
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.hint-action-btn {
  flex-shrink: 0;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  background: transparent;
  color: var(--ink-muted);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
}
.hint-action-btn:hover {
  color: var(--ink);
  border-color: var(--ink);
}

.kbd-toast {
  position: fixed;
  top: 56px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 32;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.03em;
  box-shadow: 0 8px 24px rgba(255, 68, 34, 0.42);
  animation: toast-shake 0.32s ease;
}

@keyframes toast-shake {
  0%, 100% { transform: translateX(-50%); }
  20% { transform: translateX(calc(-50% - 7px)); }
  40% { transform: translateX(calc(-50% + 7px)); }
  60% { transform: translateX(calc(-50% - 4px)); }
  80% { transform: translateX(calc(-50% + 4px)); }
}

.ach-toast {
  position: fixed;
  top: 56px;
  right: 16px;
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 16px;
  border-radius: 10px;
  background: var(--surface);
  border: 1px solid var(--gold);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
  animation: ach-slide 0.35s cubic-bezier(0.16, 1, 0.3, 1);
}
.ach-icon {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 184, 0, 0.18);
  color: var(--gold);
  font-size: 18px;
}
.ach-eyebrow {
  font-family: var(--font-mono);
  font-size: 9.5px;
  font-weight: 800;
  letter-spacing: 0.12em;
  color: var(--gold);
}
.ach-name {
  font-size: 13px;
  font-weight: 700;
}
.ach-desc {
  font-size: 11px;
  color: var(--ink-muted);
}

@keyframes ach-slide {
  from { opacity: 0; transform: translateX(24px); }
  to { opacity: 1; transform: translateX(0); }
}

/* ==========================================================================
   Satellite Window Banner
   ========================================================================== */
.satellite-banner {
  position: fixed;
  top: 10px;
  left: 10px;
  right: 10px;
  z-index: 25;
  padding: 9px 13px;
  border-radius: 8px;
  background: var(--bg-elevated);
  border: 1px solid var(--cyan);
  backdrop-filter: blur(12px);
  pointer-events: none;
}
.sat-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 700;
  color: var(--cyan);
  letter-spacing: 0.08em;
}
.sat-desc {
  margin-top: 3px;
  font-size: 12px;
  color: var(--ink);
}
.sat-status {
  margin-top: 3px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-muted);
}

/* ==========================================================================
   Modals & Title Overlay
   ========================================================================== */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(6, 9, 14, 0.72);
  backdrop-filter: blur(12px);
}
[data-theme="paper"] .overlay {
  background: rgba(244, 239, 228, 0.76);
}

.title-card, .modal-card, .clear-card {
  width: 100%;
  max-width: 660px;
  padding: 30px;
  border-radius: 16px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  box-shadow: var(--shadow);
}

.title-top-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.title-eyebrow, .modal-eyebrow {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.14em;
  color: var(--accent);
}

.title-version-pill {
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--cyan-soft);
  border: 1px solid rgba(0, 229, 255, 0.35);
  color: var(--cyan);
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
}

.title-main {
  margin: 0;
  font-size: 36px;
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.15;
}

.title-sub {
  display: block;
  margin-top: 5px;
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-muted);
  letter-spacing: 0.14em;
}

.title-lead {
  margin: 14px 0 22px;
  font-size: 14.5px;
  line-height: 1.65;
  color: var(--ink-muted);
}
.title-lead strong {
  color: var(--ink);
}

.feature-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-bottom: 22px;
}

.feature-item {
  padding: 12px 14px;
  border-radius: 10px;
  background: rgba(128, 140, 160, 0.07);
  border: 1px solid var(--border);
}
.f-glyph {
  font-family: var(--font-mono);
  font-size: 16px;
  color: var(--accent);
  margin-bottom: 4px;
}
.f-title {
  font-size: 13px;
  font-weight: 700;
  margin-bottom: 2px;
}
.f-desc {
  font-size: 12px;
  color: var(--ink-muted);
  line-height: 1.4;
}

.title-actions, .clear-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.primary-btn, .secondary-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 44px;
  padding: 0 20px;
  border-radius: 9px;
  font-family: var(--font-sans);
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.14s ease, box-shadow 0.15s ease, background 0.15s ease;
}

.primary-btn {
  flex: 1;
  border: none;
  background: var(--accent);
  color: #fff;
  box-shadow: 0 8px 24px rgba(255, 68, 34, 0.34);
}
.primary-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 12px 28px rgba(255, 68, 34, 0.46);
}

.secondary-btn {
  border: 1px solid var(--border-strong);
  background: transparent;
  color: var(--ink);
}
.secondary-btn:hover {
  background: rgba(128, 140, 160, 0.12);
}
.secondary-btn.small {
  height: 34px;
  padding: 0 14px;
  font-size: 12px;
}

.title-footnote {
  margin-top: 15px;
  font-size: 12px;
  color: var(--ink-muted);
  text-align: center;
}

/* Chapter & Level Select Modal */
.modal-card.wide {
  max-width: 820px;
  max-height: 88vh;
  display: flex;
  flex-direction: column;
}
.modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 16px;
}
.modal-title {
  margin: 4px 0 0;
  font-size: 22px;
  font-weight: 800;
}
.close-btn {
  width: 32px;
  height: 32px;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  font-size: 15px;
}
.close-btn:hover { border-color: var(--ink); }

.chapter-container {
  overflow-y: auto;
  padding-right: 6px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.chapter-block-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.1em;
  color: var(--cyan);
  margin-bottom: 8px;
  padding-bottom: 4px;
  border-bottom: 1px solid var(--border);
}

.chapter-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 9px;
}

.level-card {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 11px 12px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: rgba(128, 140, 160, 0.06);
  text-align: left;
  color: var(--ink);
  cursor: pointer;
  transition: border-color 0.15s ease, transform 0.12s ease, background 0.15s ease;
}
.level-card:hover {
  border-color: var(--accent);
  transform: translateY(-1px);
  background: var(--accent-soft);
}
.level-card.current {
  border-color: var(--accent);
  box-shadow: inset 0 0 0 1px var(--accent);
}
.level-card.cleared {
  border-color: rgba(0, 229, 255, 0.45);
}
.lc-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-family: var(--font-mono);
  font-size: 10.5px;
}
.lc-code {
  color: var(--accent);
  font-weight: 700;
}
.lc-tag {
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 9.5px;
  background: rgba(128, 140, 160, 0.16);
  color: var(--ink-muted);
}
.lc-tag.multi {
  background: var(--cyan-soft);
  color: var(--cyan);
}
.lc-tag.meta {
  background: rgba(168, 85, 247, 0.18);
  color: var(--violet);
}
.lc-name {
  font-size: 13.5px;
  font-weight: 700;
}
.lc-desc {
  font-size: 11px;
  color: var(--ink-muted);
  line-height: 1.35;
}

/* Achievements Grid */
.ach-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  max-height: 55vh;
  overflow-y: auto;
}
.ach-card {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 11px 12px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: rgba(128, 140, 160, 0.05);
  opacity: 0.55;
}
.ach-card.unlocked {
  opacity: 1;
  border-color: rgba(255, 184, 0, 0.5);
  background: rgba(255, 184, 0, 0.08);
}

.modal-footer {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  color: var(--ink-muted);
}

/* Clear & Victory Cards */
.clear-card {
  max-width: 480px;
  text-align: center;
}
.clear-badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 4px;
  background: var(--accent-soft);
  color: var(--accent);
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.1em;
  margin-bottom: 10px;
}
.clear-badge.cyan {
  background: var(--cyan-soft);
  color: var(--cyan);
}
.clear-title {
  margin: 0;
  font-size: 26px;
  font-weight: 800;
}
.clear-quote {
  margin: 10px 0 20px;
  font-size: 14px;
  line-height: 1.6;
  color: var(--ink-muted);
}
.clear-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 22px;
}
.stat-box {
  padding: 10px 8px;
  border-radius: 8px;
  background: rgba(128, 140, 160, 0.08);
  border: 1px solid var(--border);
}
.stat-label {
  display: block;
  font-size: 11px;
  color: var(--ink-muted);
  margin-bottom: 4px;
}
.stat-val {
  font-family: var(--font-mono);
  font-size: 15px;
  font-weight: 700;
}

/* Popup Alert & Sandbox Bar */
.popup-alert {
  position: fixed;
  top: 58px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 45;
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: 580px;
  padding: 10px 14px;
  border-radius: 10px;
  background: var(--surface);
  border: 1px solid var(--cyan);
  box-shadow: var(--shadow);
  font-size: 12px;
}
.popup-alert-body {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.popup-alert-body span { color: var(--ink-muted); }

.sandbox-bar {
  position: fixed;
  bottom: 66px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 25;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  border-radius: 10px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  backdrop-filter: blur(14px);
}
.sb-btn {
  padding: 6px 11px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: rgba(128, 140, 160, 0.1);
  color: var(--ink);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}
.sb-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}
.sb-btn.active {
  background: var(--cyan-soft);
  border-color: var(--cyan);
  color: var(--cyan);
}

@media (max-width: 720px) {
  .chapter-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 560px) {
  .feature-grid, .chapter-grid, .ach-grid { grid-template-columns: 1fr; }
  .title-card { padding: 20px; }
  .title-main { font-size: 26px; }
}
