.undef-terminal, .undef-terminal * { box-sizing: border-box; }

.undef-terminal {
  width: 100%;
  height: 100%;
  position: relative;
  overflow: hidden;
  overscroll-behavior: none;
  font-family: 'Fira Code', 'Consolas', monospace;
  color: #e2e8f0;
  --bg-page: #0a0a0a;
  --bg-terminal: #0a0a0a;
  --green-base: #22c55e;
  --green-bright: #4ade80;
  --text-primary: #e2e8f0;
  --text-dim: #64748b;
}

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

/* ── Gear Icon ── */
.undef-terminal .gear-btn {
  position: absolute;
  top: 16px;
  right: 16px;
  z-index: 2000;
  background: rgba(30, 30, 30, 0.8);
  border: 1px solid #444;
  border-radius: 8px;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s;
  color: #888;
  font-size: 24px;
  line-height: 1;
}
.undef-terminal .gear-btn:hover { border-color: var(--green-base); color: var(--green-base); }
.undef-terminal .gear-btn svg { width: 24px; height: 24px; fill: currentColor; }

/* ── Settings Panel ── */
.undef-terminal .settings-overlay {
  display: none;
  position: absolute;
  inset: 0;
  z-index: 1999;
}
.undef-terminal .settings-overlay.open { display: block; }

.undef-terminal .settings-panel {
  position: absolute;
  top: 68px;
  right: 16px;
  z-index: 2001;
  width: 300px;
  background: #1a1a2e;
  border: 1px solid #333;
  border-radius: 10px;
  padding: 20px;
  display: none;
  max-height: calc(100% - 90px);
  overflow-y: auto;
  box-shadow: 0 8px 32px rgba(0,0,0,0.6);
}
.undef-terminal .settings-panel.open { display: block; }

.undef-terminal .settings-panel h3 {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--text-dim);
  margin: 16px 0 8px 0;
}
.undef-terminal .settings-panel h3:first-child { margin-top: 0; }

.undef-terminal .theme-options {
  display: flex;
  gap: 6px;
}
.undef-terminal .theme-btn {
  flex: 1;
  padding: 8px 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;
}
.undef-terminal .theme-btn:hover { border-color: #666; }
.undef-terminal .theme-btn.active { border-color: var(--green-base); color: var(--green-base); }

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

/* ── Frame: Common ── */
/* Height chain: page-wrapper → frame-root → terminal-frame → screen-inset → terminal-div
   Must flow all the way down for FitAddon to measure both dimensions. */
.undef-terminal .frame-root {
  width: 100%;
  max-width: 1100px;
  height: 100%;
}

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

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

.undef-terminal .terminal-div {
  overflow: hidden;
  height: 100%;
}

.undef-terminal .xterm { padding: 0; }

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

/* Only one frame chrome variant is visible per active theme. */
.undef-terminal .frame-header,
.undef-terminal .frame-titlebar,
.undef-terminal .frame-statusbar,
.undef-terminal .frame-bottom {
  display: none;
}

.undef-terminal .frame-statusbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* ══════════════════════════════════════
   Theme A: CRT Monitor
   ══════════════════════════════════════ */
.undef-terminal.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);
}
.undef-terminal.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;
}
.undef-terminal.theme-crt .frame-bottom {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 6px 2px 6px;
}
.undef-terminal.theme-crt .frame-label {
  font-size: 10px;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: #555;
}
.undef-terminal.theme-crt .led {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: #333;
  box-shadow: inset 0 1px 2px rgba(0,0,0,0.5);
}
.undef-terminal.theme-crt .led.on {
  background: var(--green-base);
  box-shadow: 0 0 4px var(--green-base), 0 0 8px var(--green-base);
}

/* CRT scanlines */
.undef-terminal.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 */
.undef-terminal.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
   ══════════════════════════════════════ */
.undef-terminal.theme-bbs .terminal-frame {
  border: 2px solid #444;
  background: #111;
}
.undef-terminal.theme-bbs .frame-header {
  background: linear-gradient(90deg, #000080, #0000b0);
  padding: 4px 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.undef-terminal.theme-bbs .frame-header-title {
  font-size: 12px;
  font-weight: bold;
  color: #fff;
  letter-spacing: 1px;
}
.undef-terminal.theme-bbs .screen-inset {
  position: relative;
  overflow: hidden;
}
.undef-terminal.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;
}
.undef-terminal.theme-bbs .frame-statusbar-right .frame-status {
  display: none;
}

/* BBS scanlines */
.undef-terminal.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
   ══════════════════════════════════════ */
.undef-terminal.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;
}
.undef-terminal.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);
}
.undef-terminal.theme-glass .screen-inset {
  position: relative;
  overflow: hidden;
}
.undef-terminal.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 */
.undef-terminal.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 */
.undef-terminal.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 ── */
.undef-terminal .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;
}
.undef-terminal .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: undef-spin 0.8s linear infinite;
  margin-right: 10px;
}
@keyframes undef-spin { to { transform: rotate(360deg); } }

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

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

  .undef-terminal .frame-root {
    width: 100%;
    height: 100%;
  }

  .undef-terminal .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;
  }

  /* Force flex child to calculate height from parent, not content */
  .undef-terminal .screen-inset,
  .undef-terminal.theme-crt .screen-inset,
  .undef-terminal.theme-bbs .screen-inset,
  .undef-terminal.theme-glass .screen-inset {
    flex: 1;
    height: 0;
    border-radius: 0 !important;
  }

  .undef-terminal .terminal-div { height: 100%; }

  /* Gradient at the bottom edge of the terminal */
  .undef-terminal .screen-inset { position: relative; }
  .undef-terminal .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;
  }

  /* Hide decorative chrome */
  .undef-terminal .frame-bottom, .undef-terminal.theme-crt .frame-bottom,
  .undef-terminal .frame-header, .undef-terminal.theme-bbs .frame-header,
  .undef-terminal .frame-statusbar, .undef-terminal.theme-bbs .frame-statusbar,
  .undef-terminal.theme-glass .frame-statusbar,
  .undef-terminal .frame-titlebar, .undef-terminal.theme-glass .frame-titlebar {
    display: none !important;
  }

  .undef-terminal .gear-btn {
    top: 4px;
    right: 4px;
    width: 32px;
    height: 32px;
    background: rgba(0, 0, 0, 0.6);
  }
  .undef-terminal .gear-btn svg { width: 18px; height: 18px; }
}
