:root {
  /* Terminal frame colors */
  --bg-page: #0a0a0a;
  --bg-terminal: #0a0a0a;
  --green-base: #22c55e;
  --green-bright: #4ade80;
  --text-primary: #e2e8f0;
  --text-dim: #64748b;

  /* Appearance theme — overridden by warp-theme in localStorage */
  --primary: #ff1a8c;
  --accent:  #ffcc00;
  --scan-speed:   4s;
  --scan-opacity: 0.08;
  --glow-opacity: 0.35;

  /* Overlay text scale */
  --text-body: rgba(255,255,255,0.78);
  --text-mid:  rgba(255,255,255,0.55);
  --text-fade: rgba(255,255,255,0.35);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  width: 100%;
  height: 100dvh;
  height: calc(var(--vh, 1dvh) * 100);
  background: var(--bg-page);
  color: var(--text-primary);
  font-family: 'Fira Code', 'Consolas', monospace;
  overflow: hidden;
  overscroll-behavior: none;
}

/* ── Page Layout ── */
.page-wrapper {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100%;
  width: 100%;
  padding: 20px;
  position: relative;
}

/* ══════════════════════════════════════
   Menu Panel (Hamburger)
   ══════════════════════════════════════ */
.menu-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 1999;
}
.menu-overlay.open { display: block; }

.menu-panel {
  position: fixed;
  top: 50px;
  right: 16px;
  z-index: 2001;
  width: 300px;
  background: #1a1a2e;
  border: 1px solid #333;
  border-radius: 10px;
  padding: 16px;
  display: none;
  max-height: calc(100vh - 58px);
  overflow-y: auto;
  box-shadow: 0 8px 32px rgba(0,0,0,0.6);
}
.menu-panel.open { display: block; }

.menu-panel h3 {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--text-dim);
  margin: 16px 0 8px 0;
  border-top: 1px solid #222;
  padding-top: 14px;
}
.menu-panel h3:first-child { margin-top: 0; border-top: none; padding-top: 0; }

/* Preset swatches */
.preset-row {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: 10px;
}
.preset-btn {
  flex: 1;
  min-width: 56px;
  padding: 5px 4px;
  font-family: 'Share Tech Mono', 'Fira Code', monospace;
  font-size: 10px;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  border-radius: 3px;
  cursor: pointer;
  border: 1px solid;
  background: rgba(0,0,0,0.4);
  transition: all 0.15s;
  text-align: center;
}
.preset-btn:hover { filter: brightness(1.4); }
.preset-btn.active { filter: brightness(1.3); font-weight: bold; }

/* Color picker row */
.picker-row {
  display: flex;
  gap: 12px;
  margin-bottom: 10px;
  align-items: center;
}
.picker-group {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: #aaa;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.picker-group input[type="color"] {
  width: 28px; height: 22px;
  border: 1px solid #444;
  border-radius: 3px;
  background: none;
  cursor: pointer;
  padding: 1px;
}

/* Sliders */
.slider-2col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 8px;
}
.slider-group { margin-bottom: 8px; }
.slider-group label {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: #aaa;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 4px;
}
.slider-val { color: var(--green-base); }
.slider-group input[type="range"] {
  width: 100%;
  accent-color: var(--green-base);
}

.btn-copy-vars {
  display: block; width: 100%;
  font-family: 'Fira Code', monospace;
  font-size: 11px;
  padding: 7px;
  background: transparent;
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 3px;
  color: var(--text-dim);
  cursor: pointer;
  transition: all 0.2s;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  margin-top: 4px;
}
.btn-copy-vars:hover { border-color: var(--green-base); color: #ccc; }

/* Terminal section */
.theme-options {
  display: flex;
  gap: 6px;
  margin-bottom: 8px;
}
.theme-btn {
  flex: 1;
  padding: 7px 4px;
  background: #111;
  border: 2px solid #333;
  border-radius: 6px;
  color: #aaa;
  font-family: inherit;
  font-size: 11px;
  cursor: pointer;
  text-align: center;
  transition: all 0.15s;
}
.theme-btn:hover { border-color: #666; }
.theme-btn.active { border-color: var(--green-base); color: var(--green-base); }

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 7px 0;
}
.setting-row label { font-size: 12px; color: #ccc; }
.setting-row input[type="range"] { width: 110px; accent-color: var(--green-base); }
.setting-row .val { font-size: 11px; color: var(--green-base); min-width: 32px; text-align: right; }
.setting-row input[type="color"] {
  width: 28px; height: 22px;
  border: 1px solid #444;
  border-radius: 3px;
  background: none; cursor: pointer; padding: 0;
}
.setting-row input[type="checkbox"] {
  accent-color: var(--green-base);
  width: 16px; height: 16px;
}

/* Links section */
.links-section { display: flex; flex-direction: column; gap: 8px; }
.panel-link {
  font-size: 0.78rem;
  color: #555;
  text-decoration: none;
  font-family: 'Fira Code', monospace;
  transition: color 0.2s;
}
.panel-link:hover { color: var(--green-base); }

/* Scrollbar for panel */
.menu-panel::-webkit-scrollbar { width: 6px; }
.menu-panel::-webkit-scrollbar-track { background: transparent; }
.menu-panel::-webkit-scrollbar-thumb { background: #333; border-radius: 3px; }

/* ── Frame: Common ── */
#frameRoot {
  width: 100%;
  max-width: 1100px;
  height: 100%;
}

.terminal-frame {
  position: relative;
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
}

.screen-inset {
  flex: 1;
  min-height: 0;
}

#terminal {
  overflow: hidden;
  height: 100%;
}

.xterm { padding: 0; }

/* ── Connection Status (inside frame) ── */
.frame-status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--text-dim);
}
.status-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: #555;
  display: inline-block;
}
.status-dot.connected {
  background: var(--green-base);
  box-shadow: 0 0 6px var(--green-base);
}

/* ══════════════════════════════════════
   Theme A: CRT Monitor
   ══════════════════════════════════════ */
.theme-crt .terminal-frame {
  background: linear-gradient(145deg, #111 0%, #0d0d0d 50%, #111 100%);
  border-radius: 18px;
  padding: 28px 28px 12px 28px;
  box-shadow:
    0 0 0 2px #111,
    0 4px 20px rgba(0,0,0,0.8),
    inset 0 2px 4px rgba(255,255,255,0.05);
}
.theme-crt .screen-inset {
  background: #000;
  border-radius: 8px;
  padding: 6px;
  box-shadow: inset 0 0 20px rgba(0,0,0,0.9), inset 0 0 4px rgba(0,0,0,0.5);
  position: relative;
  overflow: hidden;
}
.theme-crt .frame-bottom {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 6px 2px 6px;
}
.theme-crt .frame-label {
  font-size: 10px;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: #555;
}
.theme-crt .led {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: #333;
  box-shadow: inset 0 1px 2px rgba(0,0,0,0.5);
}
.theme-crt .led.on {
  background: var(--green-base);
  box-shadow: 0 0 4px var(--green-base), 0 0 8px var(--green-base);
}

/* CRT scanlines */
.theme-crt.fx-scanlines .screen-inset::after {
  content: '';
  position: absolute; inset: 0;
  background: repeating-linear-gradient(
    0deg, transparent, transparent 2px,
    rgba(0,0,0,0.15) 2px, rgba(0,0,0,0.15) 4px
  );
  pointer-events: none; z-index: 10;
}
/* CRT vignette */
.theme-crt.fx-vignette .screen-inset::before {
  content: '';
  position: absolute; inset: 0;
  background: radial-gradient(ellipse at center, transparent 50%, rgba(0,0,0,0.4) 100%);
  pointer-events: none; z-index: 10;
  border-radius: 8px;
}

/* ══════════════════════════════════════
   Theme B: BBS/DOS Frame
   ══════════════════════════════════════ */
.theme-bbs .terminal-frame {
  border: 2px solid #444;
  background: #111;
}
.theme-bbs .frame-header {
  background: linear-gradient(90deg, #000080, #0000b0);
  padding: 4px 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.theme-bbs .frame-header-title {
  font-size: 12px;
  font-weight: bold;
  color: #fff;
  letter-spacing: 1px;
}
.theme-bbs .screen-inset { position: relative; overflow: hidden; }
.theme-bbs .frame-statusbar {
  background: linear-gradient(90deg, #000080, #0000a0);
  padding: 3px 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 11px;
  color: #aaa;
}

/* BBS scanlines */
.theme-bbs.fx-scanlines .screen-inset::after {
  content: '';
  position: absolute; inset: 0;
  background: repeating-linear-gradient(
    0deg, transparent, transparent 2px,
    rgba(0,0,0,0.1) 2px, rgba(0,0,0,0.1) 4px
  );
  pointer-events: none; z-index: 10;
}

/* ══════════════════════════════════════
   Theme C: Floating Glass
   ══════════════════════════════════════ */
.theme-glass .terminal-frame {
  border-radius: 12px;
  background: rgba(20, 20, 30, 0.85);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid rgba(255,255,255,0.08);
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
  overflow: hidden;
}
.theme-glass .frame-titlebar {
  padding: 8px 14px;
  text-align: center;
  font-size: 11px;
  color: #777;
  letter-spacing: 1px;
  border-bottom: 1px solid rgba(255,255,255,0.05);
}
.theme-glass .screen-inset { position: relative; overflow: hidden; }
.theme-glass .frame-statusbar {
  padding: 4px 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 11px;
  color: #555;
  border-top: 1px solid rgba(255,255,255,0.05);
}

/* Glass glow */
.theme-glass.fx-glow .terminal-frame {
  box-shadow: 0 8px 32px rgba(0,0,0,0.5), 0 0 40px rgba(34,197,94,0.06);
}

/* Glass scanlines */
.theme-glass.fx-scanlines .screen-inset::after {
  content: '';
  position: absolute; inset: 0;
  background: repeating-linear-gradient(
    0deg, transparent, transparent 2px,
    rgba(0,0,0,0.08) 2px, rgba(0,0,0,0.08) 4px
  );
  pointer-events: none; z-index: 10;
}

/* ── Loading Overlay ── */
.loading {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(13, 17, 23, 0.95);
  padding: 30px 50px;
  border: 2px solid var(--green-base);
  border-radius: 8px;
  text-align: center;
  z-index: 100;
  font-size: 13px;
}
.loading-spinner {
  display: inline-block;
  width: 20px; height: 20px;
  border: 2px solid var(--text-dim);
  border-top-color: var(--green-base);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-right: 10px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ══════════════════════════════════════
   Mobile / Responsive Adjustments
   ══════════════════════════════════════ */
@media (max-width: 768px), (max-height: 600px) {
  .page-wrapper {
    padding: 0;
    align-items: flex-start;
  }

  #frameRoot { width: 100%; height: 100%; }

  .terminal-frame {
    display: flex;
    flex-direction: column;
    width: 100%; height: 100%;
    border-radius: 0 !important;
    border: none !important;
    padding: 4px !important;
    box-shadow: none !important;
  }

  .screen-inset,
  .theme-crt .screen-inset,
  .theme-bbs .screen-inset,
  .theme-glass .screen-inset {
    flex: 1; height: 0;
    border-radius: 0 !important;
  }

  #terminal { height: 100%; }

  .screen-inset { position: relative; }
  .screen-inset::after {
    content: '';
    position: absolute;
    bottom: 0; left: 0; right: 0;
    height: 40px;
    background: linear-gradient(to bottom, transparent, var(--bg-terminal, #0a0a0a));
    pointer-events: none; z-index: 10;
  }

  .frame-bottom, .theme-crt .frame-bottom,
  .frame-header, .theme-bbs .frame-header,
  .frame-statusbar, .theme-bbs .frame-statusbar, .theme-glass .frame-statusbar,
  .frame-titlebar, .theme-glass .frame-titlebar {
    display: none !important;
  }

}

/* ══════════════════════════════════════
   Game State Panel (right sidebar)
   ══════════════════════════════════════ */
.game-panel {
  position: fixed;
  top: 50px;
  right: 0;
  bottom: 0;
  width: 200px;
  background: #111118;
  border-left: 1px solid #222;
  font-family: 'Fira Code', 'Consolas', monospace;
  font-size: 11px;
  z-index: 900;
  display: none;
  transition: transform 0.2s ease;
}
.game-panel.gp-active { display: flex; flex-direction: column; }
.game-panel.gp-collapsed { transform: translateX(100%); }
.game-panel.gp-collapsed .game-panel-content { display: none; }

.game-panel-toggle {
  position: absolute;
  left: -24px;
  top: 8px;
  width: 24px;
  height: 32px;
  background: #111118;
  border: 1px solid #222;
  border-right: none;
  border-radius: 4px 0 0 4px;
  color: #555;
  font-size: 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  line-height: 1;
}
.game-panel-toggle:hover { color: var(--green-base); }

.game-panel-content {
  flex: 1;
  overflow-y: auto;
  padding: 8px 10px;
}

.gp-section { margin-bottom: 12px; }
.gp-title {
  font-size: 10px;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--text-dim);
  border-bottom: 1px solid #222;
  padding-bottom: 4px;
  margin-bottom: 6px;
}
.gp-row {
  display: flex;
  justify-content: space-between;
  padding: 2px 0;
  color: #999;
}
.gp-row span:last-child {
  color: var(--green-base);
  text-align: right;
}

/* Shrink page-wrapper when panel is visible */
.game-panel.gp-active:not(.gp-collapsed) ~ .page-wrapper {
  padding-right: 210px;
}

/* Mobile: overlay panel instead of side-by-side */
@media (max-width: 768px) {
  .game-panel {
    width: 200px;
    background: rgba(17, 17, 24, 0.95);
    backdrop-filter: blur(4px);
  }
  .game-panel.gp-active:not(.gp-collapsed) ~ .page-wrapper {
    padding-right: 0; /* don't shrink terminal on mobile — panel overlaps */
  }
  .game-panel.gp-collapsed .game-panel-toggle {
    /* Keep toggle visible when collapsed on mobile */
    display: flex;
  }
}

/* ── Mobile keyboard toggle (touch-only devices) ── */
.kbd-btn {
  position: fixed;
  bottom: 16px; right: 16px;
  z-index: 2000;
  background: rgba(0, 0, 0, 0.75);
  border: 1px solid #444;
  border-radius: 10px;
  width: 48px; height: 48px;
  display: none;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--green-base);
  font-size: 22px;
  line-height: 1;
  touch-action: manipulation;
}
@media (hover: none) and (pointer: coarse) {
  .kbd-btn { display: flex; }
}
