/* Python IDE Styles - Simple Two Column Layout */

:root {
  --bg: #0A0E13;
  --panel: #121821;
  --panel-alt: #1A222C;
  --border: #26323D;
  --text: #E7EEF4;
  --text-dim: #8496A6;
  --text-faint: #54636F;
  --net: #4FD1C5;
  --net-dim: #1E4A47;
  --host: #F2A65A;
  --host-dim: #4A331B;
  --danger: #E4626F;
  --danger-dim: #4A2027;
  --blue: #5B9BF2;
  --violet: #B98CF2;
  --green: #8FD17A;
  --green-dim: #294222;
  --mono: 'IBM Plex Mono', ui-monospace, monospace;
  --display: 'Space Grotesk', sans-serif;
  --code-font: 'Fira Code', monospace;
}

/* Reset and Base */
* {
  box-sizing: border-box;
}

.ide-page {
  font-family: var(--mono);
  margin: 0;
  padding: 0;
  background-color: var(--bg);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
}

/* IDE Container */
.ide-container {
  height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Header */
.ide-header {
  background-color: var(--panel);
  padding: 1rem 2rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.header-left h1 {
  margin: 0;
  font-size: 1.5rem;
  font-family: var(--display);
  color: var(--text);
  font-weight: 700;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 1rem;
}

/* Main Layout */
.ide-main {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 8px 1fr; /* Editor, Vertical Handle, Right Panel */
  gap: 0;
  height: calc(100vh - 80px);
}

/* Panel Styles */
.editor-panel {
  background-color: var(--bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0; /* Allow shrinking */
  height: 100%; /* Ensure full height usage */
}

.right-panel {
  background-color: var(--bg);
  display: flex;
  flex-direction: column;
}

.output-panel,
.execution-panel {
  display: flex;
  flex-direction: column;
  border-bottom: 1px solid var(--border);
  min-height: 0; /* Important for flex children to shrink */
  overflow: hidden; /* Prevent panel overflow, but let container scroll */
}

.output-panel {
  flex: 2 1 66.7%; /* Default to 2/3 of space but allow grow/shrink */
  min-height: 200px; /* Increased minimum height for better usability */
  max-height: calc(66vh - 100px); /* Adjusted max height for new proportion */
}

/* 80s CRT Monitor styling for output panel header — kept as-is */
.output-panel .panel-header {
  background: linear-gradient(180deg, #003300, #001100);
  border-bottom: 2px solid #00ff00;
  box-shadow: 0 0 10px rgba(0, 255, 0, 0.3);
}

.output-panel .panel-title {
  color: #00cc00;
  text-shadow: 0 0 1px #00cc00;
  font-family: 'Courier New', var(--code-font), monospace;
  font-weight: bold;
  letter-spacing: 1px;
}

.output-panel .btn {
  background: rgba(0, 204, 0, 0.1);
  border: 1px solid #00cc00;
  color: #00cc00;
  text-shadow: 0 0 0.5px #00cc00;
}

.output-panel .btn:hover {
  background: rgba(0, 204, 0, 0.2);
  box-shadow: 0 0 4px rgba(0, 204, 0, 0.5);
}

.execution-panel {
  flex: 1 1 33.3%; /* Default to 1/3 of space but allow grow/shrink */
  min-height: 120px; /* Reduced but still usable minimum height */
  border-bottom: none;
}

/* Ember sparks spawned from the cursor while dragging a resize handle */
.spark-canvas {
  position: fixed;
  inset: 0;
  z-index: 1200;
  pointer-events: none;
}

/* Resize Handle - Enhanced */
.resize-handle {
  height: 8px;
  background-color: var(--panel);
  cursor: row-resize;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  transition: all 0.2s ease;
  flex-shrink: 0; /* Don't allow the handle to shrink */
}

.resize-handle:hover {
  background-color: var(--net);
  border-color: var(--net);
  height: 10px;
}

.resize-handle:active,
.resize-handle.active {
  background-color: var(--host);
  border-color: var(--host);
}

.resize-line {
  width: 80px;
  height: 2px;
  background-color: var(--text-faint);
  border-radius: 1px;
  transition: all 0.2s ease;
  pointer-events: none; /* Allow clicks to pass through to handle */
  position: relative;
}

.resize-line::before,
.resize-line::after {
  content: '';
  position: absolute;
  width: 4px;
  height: 2px;
  background-color: inherit;
  border-radius: 1px;
  top: 0;
}

.resize-line::before {
  left: -8px;
}

.resize-line::after {
  right: -8px;
}

.resize-handle:hover .resize-line {
  background-color: var(--text);
  width: 100px;
}

.resize-handle:active .resize-line,
.resize-handle.active .resize-line {
  background-color: var(--text);
  width: 120px;
}

/* Vertical Resize Handle - Enhanced */
.vertical-resize-handle {
  width: 8px;
  background-color: var(--panel);
  cursor: col-resize;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  border-left: 1px solid var(--border);
  border-right: 1px solid var(--border);
  transition: all 0.2s ease;
  flex-shrink: 0;
}

.vertical-resize-handle:hover {
  background-color: var(--net);
  border-color: var(--net);
  width: 10px;
}

.vertical-resize-handle:active,
.vertical-resize-handle.active {
  background-color: var(--host);
  border-color: var(--host);
}

.vertical-resize-line {
  height: 80px;
  width: 2px;
  background-color: var(--text-faint);
  border-radius: 1px;
  transition: all 0.2s ease;
  pointer-events: none;
  position: relative;
}

.vertical-resize-line::before,
.vertical-resize-line::after {
  content: '';
  position: absolute;
  height: 4px;
  width: 2px;
  background-color: inherit;
  border-radius: 1px;
  left: 0;
}

.vertical-resize-line::before {
  top: -8px;
}

.vertical-resize-line::after {
  bottom: -8px;
}

.vertical-resize-handle:hover .vertical-resize-line {
  background-color: var(--text);
  height: 100px;
}

.vertical-resize-handle:active .vertical-resize-line,
.vertical-resize-handle.active .vertical-resize-line {
  background-color: var(--text);
  height: 120px;
}

.panel-header {
  background-color: var(--panel);
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.panel-title {
  font-family: var(--display);
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--text);
}

/* Editor Styles */
.editor-container {
  flex: 1;
  position: relative;
  min-height: 0; /* Allow flex shrinking */
  overflow: hidden; /* Prevent container overflow */
}

/* CodeMirror keeps Fira Code — it's a code-editing font choice, not
   page chrome, and is already themed via the monokai CodeMirror theme. */
.CodeMirror {
  height: 100% !important;
  font-family: var(--code-font) !important;
  font-size: 14px;
  background-color: var(--bg) !important;
  overflow-y: auto !important; /* Vertical scrolling only */
  overflow-x: hidden !important; /* No horizontal scrolling */
  word-wrap: break-word; /* Wrap long lines */
}

.CodeMirror-scroll {
  overflow-x: hidden !important; /* Force no horizontal scroll in CodeMirror */
  overflow-y: auto !important; /* Allow vertical scrolling */
}

/* Ensure CodeMirror uses our custom scrollbar styling */
.CodeMirror-scroll {
  scrollbar-width: thin;
  scrollbar-color: var(--border) var(--bg);
}

.CodeMirror-gutters {
  background-color: var(--bg) !important;
  border-right: 1px solid var(--border) !important;
}

/* Indent guides — a faint vertical line every 4 characters (matching
   indentUnit/tabSize in python-ide-pyodide.js), so a wrong indent level
   is visible at a glance instead of only surfacing as a confusing error
   after Run. `ch` units scale with the editor's own adjustable font size
   rather than a hardcoded pixel width. Measured against the actual
   rendered editor: .CodeMirror-lines has zero left padding and its own
   left edge is exactly where column 0 starts, so no offset is needed —
   the gradient's own column 0 lines up with the code's column 0. */
.CodeMirror-lines {
  background-image: repeating-linear-gradient(
    90deg,
    var(--border) 0,
    var(--border) 1px,
    transparent 1px,
    transparent 4ch
  );
}

/* Custom Scrollbar Styling for Retro Theme */
.CodeMirror-scrollbar-filler,
.CodeMirror-gutter-filler {
  background-color: transparent !important;
}

/* Hide CodeMirror's default scrollbars - use webkit custom ones instead */
.CodeMirror-vscrollbar {
  display: none !important;
}

.CodeMirror-hscrollbar {
  display: none !important;
}

/* Custom scrollbar for webkit browsers (Chrome, Safari, Edge) */
.output-container::-webkit-scrollbar,
.CodeMirror::-webkit-scrollbar,
.CodeMirror-scroll::-webkit-scrollbar {
  width: 12px;
  height: 0px; /* Hide horizontal scrollbar */
}

.output-container::-webkit-scrollbar-track,
.CodeMirror::-webkit-scrollbar-track,
.CodeMirror-scroll::-webkit-scrollbar-track {
  background: var(--bg);
  border-radius: 6px;
}

.output-container::-webkit-scrollbar-thumb,
.CodeMirror::-webkit-scrollbar-thumb,
.CodeMirror-scroll::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 6px;
  border: 2px solid var(--bg);
}

.output-container::-webkit-scrollbar-thumb:hover,
.CodeMirror::-webkit-scrollbar-thumb:hover,
.CodeMirror-scroll::-webkit-scrollbar-thumb:hover {
  background: var(--text-faint);
}

/* Hide horizontal scrollbar specifically for CodeMirror */
.CodeMirror::-webkit-scrollbar:horizontal,
.CodeMirror-scroll::-webkit-scrollbar:horizontal {
  display: none;
}

/* Force consistent scrollbar styling - override any default scrollbars */
.CodeMirror-scrollbar-filler,
.CodeMirror-gutter-filler,
.CodeMirror-vscrollbar,
.CodeMirror-hscrollbar {
  background: transparent !important;
}

/* ============================================================
   80s CRT Monitor Aesthetic — output panel. Kept exactly as-is;
   this is the one visual element explicitly NOT re-skinned to
   house-style, everything below to the "end CRT block" marker
   is untouched from the original.
   ============================================================ */

/* CRT monitor green glow scrollbar for output */
.output-container::-webkit-scrollbar-thumb {
  background: linear-gradient(to bottom, #003300, #001100);
  border: 1px solid #00cc00;
  box-shadow: 0 0 3px rgba(0, 204, 0, 0.5);
}

.output-container::-webkit-scrollbar-thumb:hover {
  background: linear-gradient(to bottom, #004400, #002200);
  box-shadow: 0 0 5px rgba(0, 204, 0, 0.8);
}

.output-container,
.execution-container {
  flex: 1;
  padding: 1rem;
  overflow-y: auto;
  overflow-x: hidden;
  position: relative;
  min-height: 0;
  max-height: 100%;
  /* Force proper scrolling bounds */
  height: 0; /* This forces flex to calculate height properly */
}

.output-container {
  background: #001100;
  border: 2px solid #333;
  border-radius: 8px;
  position: relative;
  /* CRT Screen curvature effect */
  background:
    radial-gradient(ellipse at center,
      rgba(0, 255, 0, 0.15) 0%,
      rgba(0, 255, 0, 0.05) 40%,
      rgba(0, 0, 0, 0.4) 100%),
    linear-gradient(180deg,
      rgba(0, 255, 0, 0.02) 0%,
      rgba(0, 0, 0, 0.8) 100%),
    #000800;
}

/* CRT Scanlines effect */
.output-container::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  pointer-events: none;
  background: repeating-linear-gradient(
    0deg,
    rgba(0, 255, 0, 0.03) 0px,
    rgba(0, 255, 0, 0.03) 1px,
    transparent 1px,
    transparent 3px
  );
  z-index: 1;
}

/* CRT Screen flicker animation */
.output-container::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  pointer-events: none;
  background: rgba(0, 255, 0, 0.02);
  animation: flicker 0.15s infinite linear alternate;
  z-index: 1;
}

@keyframes flicker {
  0% { opacity: 1; }
  98% { opacity: 1; }
  99% { opacity: 0.98; }
  100% { opacity: 1; }
}

/* 80s CRT Monitor Scrollbar */
.output-container::-webkit-scrollbar {
  width: 8px;
}

.output-container::-webkit-scrollbar-track {
  background: #002200;
  border-radius: 3px;
  border: 1px solid #003300;
}

.output-container::-webkit-scrollbar-thumb {
  background: linear-gradient(180deg, #00cc00, #009900);
  border-radius: 3px;
  box-shadow: inset 0 0 3px rgba(0, 0, 0, 0.5);
}

.output-container::-webkit-scrollbar-thumb:hover {
  background: linear-gradient(180deg, #00dd00, #00aa00);
}

/* Keep execution container with normal styling */
.execution-container::-webkit-scrollbar {
  width: 6px;
}

.execution-container::-webkit-scrollbar-track {
  background: #2d2d30;
  border-radius: 3px;
}

.output-container::-webkit-scrollbar-thumb,
.execution-container::-webkit-scrollbar-thumb {
  background: #3e3e42;
  border-radius: 3px;
}

.output-container::-webkit-scrollbar-thumb:hover,
.execution-container::-webkit-scrollbar-thumb:hover {
  background: #4e4e52;
}

/* 80s CRT Monitor Output Text */
#output {
  margin: 0;
  font-family: 'Courier New', 'Fira Code', monospace;
  font-size: 14px;
  line-height: 1.3;
  white-space: pre-wrap;
  color: #00cc00; /* Darker green phosphor */
  background: transparent;
  word-wrap: break-word;
  text-shadow: 0 0 1px #00cc00;
  position: relative;
  z-index: 2;
  /* Reduced CRT text glow effect */
  filter: brightness(1.05);
}

/* 80s Terminal styling for different output types */
.output-system {
  color: #00cc66;
  font-style: italic;
  text-shadow: 0 0 1px #00cc66;
}

.output-error {
  color: #ff4400;
  font-weight: bold;
  text-shadow: 0 0 1px #ff4400;
  animation: errorBlink 1s infinite alternate;
}

.output-success {
  color: #33cc33;
  text-shadow: 0 0 1px #33cc33;
}

/* Error blinking animation for that authentic 80s feel */
@keyframes errorBlink {
  0% { opacity: 1; }
  100% { opacity: 0.7; }
}

/* ============================================================
   end CRT block
   ============================================================ */

/* Brief, wordless CRT glitch on the output panel — real-time feedback
   for a chunky paste. One-shot, ~200ms, no lasting visual state. */
@keyframes lofipy-glitch {
  0% { transform: translate(0); filter: none; }
  10% { transform: translate(-2px, 1px); filter: hue-rotate(15deg) contrast(1.2); }
  20% { transform: translate(2px, -1px); filter: hue-rotate(-15deg); }
  35% { transform: translate(-1px, 0); filter: contrast(1.3); }
  50% { transform: translate(1px, 1px); filter: none; }
  70% { transform: translate(-1px, 0); filter: hue-rotate(8deg); }
  100% { transform: translate(0); filter: none; }
}
.output-container.lofipy-glitching {
  animation: lofipy-glitch 220ms steps(2, end);
}

/* Execution Trace Styles */
.execution-content {
  font-family: var(--mono);
  font-size: 11px;
  line-height: 1.4;
  height: 100%;
  padding-right: 0.5rem;
  word-wrap: break-word;
}

.trace-line {
  display: flex;
  align-items: flex-start;
  margin-bottom: 0.4rem;
  padding: 0.2rem 0;
  word-break: break-word;
}

.trace-prompt {
  color: var(--net);
  font-weight: normal;
  margin-right: 0.75rem;
  min-width: 1.5rem;
  flex-shrink: 0;
}

.trace-text {
  color: var(--text-dim);
  flex: 1;
}

.trace-variable {
  color: var(--blue);
  font-weight: 500;
}

.trace-value {
  color: var(--host);
}

.trace-function {
  color: var(--violet);
  font-weight: 500;
}

.trace-output {
  color: var(--net);
  background-color: var(--net-dim);
  padding: 0.25rem 0.5rem;
  border-radius: 3px;
  margin: 0.25rem 0;
}

.trace-step {
  color: var(--blue);
  font-style: italic;
}

/* Button Styles */
.btn {
  padding: 0.5rem 1rem;
  border: 1px solid transparent;
  border-radius: 6px;
  font-family: var(--display);
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.2s ease;
  font-weight: 700;
}

.btn.primary {
  background-color: var(--net-dim);
  border-color: var(--net);
  color: var(--net);
}

.btn.primary:hover {
  background-color: var(--net);
  color: var(--bg);
}

/* Enhanced Run Button States */
.btn.primary.running {
  background-color: var(--green) !important;
  border-color: var(--green) !important;
  color: var(--bg) !important;
  animation: runPulse 1.5s infinite;
  box-shadow: 0 0 10px rgba(143, 209, 122, 0.4);
}

.btn.primary.running:hover {
  background-color: var(--green) !important;
  transform: none;
}

/* Run button pulse animation */
@keyframes runPulse {
  0% { box-shadow: 0 0 10px rgba(143, 209, 122, 0.4); }
  50% { box-shadow: 0 0 20px rgba(143, 209, 122, 0.6); }
  100% { box-shadow: 0 0 10px rgba(143, 209, 122, 0.4); }
}

.btn.ghost {
  background-color: var(--panel-alt);
  color: var(--text-dim);
  border: 1px solid var(--border);
}

.btn.ghost:hover {
  border-color: var(--text-dim);
  color: var(--text);
  transform: translateY(-1px);
}

.btn.mini {
  padding: 0.25rem 0.5rem;
  font-size: 0.75rem;
}

.editor-actions {
  display: flex;
  gap: 0.5rem;
}

/* Input Modal */
.input-modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.7);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
}

.input-modal-content {
  background-color: var(--panel);
  border-radius: 12px;
  width: 400px;
  max-width: 90vw;
  border: 1px solid var(--border);
}

.input-modal-header {
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border);
}

.input-modal-header h3 {
  margin: 0;
  font-family: var(--display);
  color: var(--text);
  font-size: 1.1rem;
}

.input-modal-body {
  padding: 1.5rem;
}

.input-modal-body p {
  margin: 0 0 1rem 0;
  color: var(--text-dim);
}

.input-modal-body input {
  width: 100%;
  padding: 0.75rem;
  background-color: var(--panel-alt);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-family: var(--mono);
  font-size: 14px;
}

.input-modal-body input:focus {
  outline: none;
  border-color: var(--net);
  box-shadow: 0 0 0 3px rgba(79, 209, 197, 0.2);
}

.input-modal-footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 0.75rem;
  justify-content: flex-end;
}

/* Responsive Design */
@media (max-width: 768px) {
  .ide-main {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr 1fr;
  }

  .panel-header {
    padding: 0.5rem 1rem;
  }

  .ide-header {
    padding: 0.75rem 1rem;
  }

  .header-left h1 {
    font-size: 1.25rem;
  }

  .trace-line {
    font-size: 10px;
  }
}
