

/* ==========================================================================
   1. GLOBAL VARIABLES & THEME CONFIGURATION
   ========================================================================== */
:root {
  --theme-bg: #000;
  --theme-default: #0f0;
  --theme-selection: #0f0;
  --theme-text: #fff;
  --theme-grid: rgba(0, 255, 0, 0.45);
  --theme-menu-bg: rgba(0, 60, 30, 0.95);
  --theme-menu-item-hover-bg: rgba(0, 255, 0, 0.2);
  --theme-looper-recording: #f00;
  --theme-looper-stop: #f55;
  --theme-looper-panic: #f00;
  --theme-mode-bar-bg: transparent;
  --scanline-color: rgba(0, 0, 0, 0.25);
}

/* ==========================================================================
   2. MAIN LAYOUT & BODY STYLES
   ========================================================================== */
body {
    margin: 0;
    padding: 0;
    background-color: var(--theme-bg);
    overflow: hidden;
    font-family: monospace;
    display: flex;
    flex-direction: column;
    height: 100vh;
    touch-action: none;
    overscroll-behavior: none;
}

/* 
   CRT Scanline Overlay Effect 
   Creates a retro monitor look with subtle horizontal lines and a vignette.
*/
body::after {
    content: " ";
    display: block;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    right: 0;
    background: linear-gradient(rgba(18, 16, 16, 0) 50%, var(--scanline-color) 50%), linear-gradient(90deg, rgba(255, 0, 0, 0.06), rgba(0, 255, 0, 0.02), rgba(0, 0, 255, 0.06));
    z-index: 99999;
    background-size: 100% 2px, 3px 100%;
    pointer-events: none;
}

/* 
   Drag & Drop Visual Feedback 
   Shows a border when dragging files into the window.
*/
body.dragging::before {
    content: "";
    position: fixed;
    top: 0; 
    left: 0; 
    right: 0; 
    bottom: 0;
    border: 5px dashed var(--theme-selection);
    background-color: rgba(0, 255, 0, 0.1);
    z-index: 100000;
    pointer-events: none;
}

/* Initial Load State - Hide UI until audio engine is ready */
.audio-uninitialized #top-ui-wrapper,
.audio-uninitialized #bottom-elements-wrapper,
.audio-uninitialized #worm-game-button {
  visibility: hidden;
}

/* ==========================================================================
   3. TOP UI BAR
   Contains looper controls, panic button, help, etc.
   ========================================================================== */
#top-ui-wrapper {
  flex-shrink: 0;
  z-index: 20;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px;
  gap: 10px;
}

#top-right-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  z-index: 30;
  flex-shrink: 0;
}

/* Utility class for responsive text hiding */
.short-text { display: none; }

/* ==========================================================================
   4. CANVAS CONTAINER
   Holds the stack of canvases for rendering: WebGL, Visualizer, Objects, UI.
   ========================================================================== */
.canvas-container {
    position: relative;
    flex-grow: 1;
    margin: 0 10px 10px 10px;
    border-radius: 50px; /* CRT monitor curvature style */
    overflow: hidden;
    box-shadow: inset 0 0 15px rgba(0,0,0,0.5);
    z-index: 5;
}

.canvas-container canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: block;
}

#gl-canvas { z-index: 0; }
#visualizer-canvas { z-index: 1; background-color: transparent; }
#objects-canvas { z-index: 2; }
#ui-canvas { z-index: 3; cursor: none; }

/* ==========================================================================
   5. BUTTONS & CONTROLS (GLOBAL)
   Styles for various interactive buttons in the top bar.
   ========================================================================== */
#panic-button-container,
#output-record-button-container,
#help-button-container,
#rec-button-container,
#stop-all-button-container,
#party-button-container {
  pointer-events: auto;
}

/* Generic Focus Ring Replacement */
button:focus, a:focus, div[tabindex]:focus {
    outline: 2px solid var(--theme-selection);
    outline-offset: 2px;
}

/* Panic Button */
#panic-button {
  width: 62px;
  height: 40px;
  border: 1px solid var(--theme-looper-panic);
  background: rgba(255,0,0,0.4);
  color: var(--theme-text);
  font-size: 16px;
  font-weight: bold;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  text-shadow: 0 0 2px #000;
  border-radius: 8px;
}
#panic-button:hover {
  border-color: var(--theme-selection);
  box-shadow: 0 0 8px var(--theme-selection);
}

/* Output Record Button */
#output-record-button {
  width: 40px;
  height: 40px;
  font-size: 22px;
  color: var(--theme-default);
  border: 2px solid var(--theme-grid);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  box-sizing: border-box;
  text-shadow: 0 0 3px var(--theme-default);
}
#output-record-button:hover {
  border-color: var(--theme-selection);
  box-shadow: 0 0 5px var(--theme-selection);
  text-shadow: 0 0 5px var(--theme-selection);
}
#output-record-button.recording {
  color: var(--theme-looper-recording);
  border-color: var(--theme-looper-recording);
  animation: pulse 1.5s infinite;
}

/* Help Button */
#help-button {
  width: 40px;
  height: 40px;
  font-size: 22px;
  font-weight: bold;
  color: var(--theme-default);
  border: 2px solid var(--theme-grid);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  box-sizing: border-box;
  text-shadow: 0 0 3px var(--theme-default);
}
#help-button:hover {
  border-color: var(--theme-selection);
  box-shadow: 0 0 5px var(--theme-selection);
  text-shadow: 0 0 5px var(--theme-selection);
}

/* Worm Game Button */
#worm-game-button {
    position: absolute;
    right: 10px;
    bottom: 10px;
    z-index: 15;
    user-select: none;
    color: var(--theme-default);
    font-size: 24px;
    font-weight: bold;
    cursor: pointer;
    text-align: center;
    border-radius: 8px;
    width: 57px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    text-shadow: 0 0 3px var(--theme-default);
}
#worm-game-button:hover {
  border-color: var(--theme-selection);
  box-shadow: 0 0 8px var(--theme-selection);
  text-shadow: 0 0 5px var(--theme-selection);
}

/* Party Button */
#party-button {
  height: 40px;
  width: 65px;
  border: 2px solid var(--theme-selection);
  color: var(--theme-selection);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  font-size: 16px;
  border-radius: 8px;
  text-shadow: 0 0 3px var(--theme-selection);
}
#party-button:hover {
  box-shadow: 0 0 8px var(--theme-selection);
  background: rgba(0, 255, 255, 0.1);
  text-shadow: 0 0 5px var(--theme-selection);
}
#party-button.copied {
  background: rgba(0, 255, 255, 0.3);
}

/* Looper Control Buttons */
#looper-controls-container {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1 1 auto;
  min-width: 0;
  justify-content: center;
}

.looper-button {
  width: 40px;
  height: 40px;
  border: 2px solid var(--theme-grid);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease-in-out;
  border-radius: 8px;
  background: transparent;
}
.looper-button:hover {
  border-color: var(--theme-selection);
  box-shadow: 0 0 5px var(--theme-selection);
  text-shadow: 0 0 5px var(--theme-selection);
}

/* Looper Icons */
#rec-button .icon { 
    width: 22px; 
    height: 22px; 
    border-radius: 50%; 
    background-color: var(--theme-default); 
    transition: all 0.2s ease-in-out; 
    /* Font styles for when text is present */
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 14px;
    color: var(--theme-bg); /* Use background color for high contrast text */
}
#rec-button.recording .icon { border-radius: 50%; background-color: #f00; }
#stop-all-button .icon {
  width: 0;
  height: 0;
  background-color: transparent;
  border-style: solid;
  border-width: 10px 0 10px 18px;
  border-color: transparent transparent transparent var(--theme-default);
  transition: all 0.2s ease-in-out;
  box-sizing: border-box;
}
#stop-all-button.playing .icon {
  width: 20px;
  height: 20px;
  border-width: 0;
  background-color: var(--theme-default);
}

@keyframes pulse {
  0% { box-shadow: 0 0 5px var(--theme-looper-recording); }
  50% { box-shadow: 0 0 15px var(--theme-looper-recording); }
  100% { box-shadow: 0 0 5px var(--theme-looper-recording); }
}

/* ==========================================================================
   6. LOOP TRACKS OVERVIEW
   The horizontal scrolling list of loops (F1-F12)
   ========================================================================== */
#looper-overview-container {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  pointer-events: auto;
  overflow: hidden;
  flex: 1;
  min-width: 0;
}
.loop-track {
  width: 70px;
  height: 40px;
  box-sizing: border-box;
  border: 2px solid var(--theme-grid);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-size: 16px;
  color: var(--theme-default);
  transition: border-color 0.2s, background-color 0.2s, box-shadow 0.2s;
  border-radius: 8px;
  flex-shrink: 0;
  text-shadow: 0 0 3px var(--theme-default);
}
.loop-track:hover {
  border-color: var(--theme-selection);
  text-shadow: 0 0 5px var(--theme-selection);
}
.loop-track-icon {
  width: 10px;
  height: 10px;
  flex-shrink: 0;
}
.loop-track-icon.play {
  width: 0;
  height: 0;
  border-top: 6px solid transparent;
  border-bottom: 6px solid transparent;
  border-left: 10px solid var(--theme-default);
}
.loop-track-icon.stop {
  background-color: var(--theme-default);
}
.loop-track-icon.rec {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background-color: var(--theme-looper-recording);
  box-shadow: 0 0 5px var(--theme-looper-recording);
}

.loop-scroll-button {
  width: 30px;
  font-size: 20px;
  font-weight: bold;
  color: var(--theme-default);
  text-shadow: 0 0 3px var(--theme-default);
}
.loop-scroll-button.disabled {
  color: var(--theme-grid);
  cursor: default;
  pointer-events: none;
  box-shadow: none;
  border-color: var(--theme-grid);
  text-shadow: none;
}

/* ==========================================================================
   7. BOTTOM UI BAR (Mode Selection)
   Contains REPL toggle and navigation for edit modes (Space, Patch, etc.)
   ========================================================================== */
#bottom-elements-wrapper {
  position: relative;
  flex-shrink: 0;
  z-index: 10;
}
#bottom-bar-container {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 10px;
}

#mode-bar-container {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 5px 0;
  pointer-events: auto;
  user-select: none;
  background-color: var(--theme-mode-bar-bg);
  max-width: 100%;
  overflow: hidden;
}

.mode-button {
  font-family: monospace;
  font-size: 20px;
  color: var(--theme-default);
  padding: 0 10px;
  text-align: center;
  height: 45px;
  line-height: 45px;
  border: 1px solid transparent;
  cursor: pointer;
  text-shadow: 0 0 3px var(--theme-default);
  transition: color 0.2s, text-shadow 0.2s;
  border-radius: 8px;
  flex-shrink: 0; 
  white-space: nowrap;
}
.mode-button:hover {
  color: var(--theme-selection);
  text-shadow: 0 0 5px var(--theme-selection);
}
.mode-button.active {
  color: var(--theme-selection);
  border-color: var(--theme-selection);
  text-shadow: 0 0 10px var(--theme-selection);
  box-shadow: 0 0 10px var(--theme-selection);
}
.mode-button.focused {
  box-shadow: inset 0 -2px 0 0 var(--theme-selection);
}

/* Specific styling for SYNTH/SAMPLE to prevent layout shift during toggle */
.mode-button[data-mode="SYNTH"],
.mode-button[data-mode="SAMPLE"] {
  min-width: 6ch;
  display: flex;
  justify-content: center;
  align-items: center;
}

.mode-scroll-button {
  height: 45px;
  width: 35px;
  font-size: 20px;
  font-weight: bold;
  color: var(--theme-default);
  flex-shrink: 0;
  border: 2px solid var(--theme-grid);
  cursor: none;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease-in-out;
  border-radius: 8px;
  background: transparent;
  box-sizing: border-box;
  text-shadow: 0 0 3px var(--theme-default);
}
.mode-scroll-button:hover {
  border-color: var(--theme-selection);
  box-shadow: 0 0 5px var(--theme-selection);
  text-shadow: 0 0 5px var(--theme-selection);
}
.mode-scroll-button.disabled {
  color: var(--theme-grid);
  cursor: default;
  pointer-events: none;
  box-shadow: none;
  border-color: var(--theme-grid);
  text-shadow: none;
}

#repl-toggle-button-container {
  flex-shrink: 0;
  display: flex;
  gap: 5px;
  align-items: center;
}

#repl-toggle-button {
  width: 35px;
  height: 40px;
  border: 0px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease-in-out;
  border-radius: 8px;
  background: transparent;
  box-sizing: border-box;
  font-size: 20px;
  font-weight: bold;
  color: var(--theme-default);
  text-shadow: 0 0 3px var(--theme-default);
}

#repl-toggle-button:hover {
  border-color: var(--theme-selection);
  box-shadow: 0 0 5px var(--theme-selection);
  text-shadow: 0 0 5px var(--theme-selection);
}

/* ==========================================================================
   8. PARAMETER POPUP MENU
   Draggable floating menu for editing synth parameters.
   ========================================================================== */
#menu-popup-container {
  position: fixed;
  bottom: 65px; /* Above bottom bar */
  z-index: 50;
  background-color: var(--theme-menu-bg);
  border: 2px solid var(--theme-selection);
  border-radius: 8px;
  padding: 15px;
  pointer-events: auto;
  user-select: none;
  min-width: 250px;
  box-shadow: 0 0 15px var(--theme-selection), inset 0 0 8px rgba(0,0,0,0.7);
  background-image: linear-gradient(rgba(0,0,0,0.2) 50%, transparent 50%);
  background-size: 100% 3px;
}

.menu-header {
  display: flex;
  height: 36px;
  margin: -15px -15px 10px -15px;
  background-color: var(--theme-selection);
  border-radius: 6px 6px 0 0;
  overflow: hidden;
}
.menu-drag-area {
  flex-grow: 1;
  height: 100%;
  cursor: grab;
  opacity: 0.6;
  transition: opacity 0.2s;
  display: flex;       
  align-items: center; 
  padding-left: 25px; /* Increased from 10px to match param item offset (15px container padding + 10px item padding) */
  font-size: 16px;     
  font-weight: bold;   
  color: var(--theme-menu-bg);
}
.menu-drag-area:hover { opacity: 0.8; }
.menu-drag-area:active { cursor: grabbing; opacity: 1; }

.menu-controls {
  display: flex;
  height: 100%;
}
.menu-control-button {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  font-weight: bold;
  color: var(--theme-menu-bg);
  background-color: transparent;
  cursor: pointer;
  opacity: 0.8;
  transition: color 0.2s, opacity 0.2s;
}
.menu-control-button:hover {
  background-color: transparent;
  opacity: 1;
  color: var(--theme-text);
  text-shadow: 0 0 5px var(--theme-text);
}
.menu-control-button.randomize-btn.active {
    color: var(--theme-text);
    opacity: 1;
    background-color: rgba(255, 255, 255, 0.2);
}

.param-item {
  font-size: 22px;
  padding: 0 10px;
  height: 40px;
  line-height: 40px;
  cursor: pointer;
  color: var(--theme-default);
  text-shadow: 0 0 3px var(--theme-default);
  border-radius: 8px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  user-select: none;
}
.param-item:hover, .param-item.active {
  background-color: var(--theme-menu-item-hover-bg);
  color: var(--theme-selection);
  text-shadow: 0 0 5px var(--theme-selection);
}

.param-flag {
  margin-right: 10px;
  cursor: pointer;
  opacity: 0.5;
  transition: opacity 0.2s;
  font-size: 18px;
}
.param-flag:hover {
  opacity: 1;
}
.param-flag.active {
  opacity: 1;
  color: var(--theme-selection);
  text-shadow: 0 0 5px var(--theme-selection);
}

.param-label {
  width: 120px; /* Fixed width */
  flex: 0 0 120px;
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.param-value-wrapper {
  display: flex;
  align-items: center;
}
.param-button {
  visibility: visible;
  padding: 0 10px;
  font-size: 24px;
  font-weight: bold;
  color: var(--theme-grid);
  transition: color 0.2s;
}
.param-item:hover .param-button,
.param-item.active .param-button,
.param-item.editing .param-button {
  color: var(--theme-selection);
}

.param-item .param-value {
  width: 120px;
  max-width: 120px;
  min-width: 120px; /* Force rigid width */
  flex: 0 0 120px;
  height: 30px;
  padding: 0 5px;
  color: var(--theme-default);
  text-shadow: 0 0 3px var(--theme-default);
  
  /* Flexbox for centering content properly */
  display: flex;
  justify-content: center;
  align-items: center;
  
  /* Overflow handling */
  overflow: hidden;
  position: relative;
  background: transparent;
}

.param-value.has-overflow {
  justify-content: flex-start; /* Align left to allow scrolling from start */
}

/* Inner container for potentially scrolling text */
.param-val-inner {
    white-space: nowrap;
    display: inline-block;
}

.param-val-inner.rolling {
    animation: roll-text-continuous 10s linear infinite;
    will-change: transform;
    /* Spacing is handled by the duplicated text */
}

@keyframes roll-text-continuous {
    /* 
       To scroll RIGHT-TO-LEFT (standard marquee), 
       we start at 0 (first text visible)
       and move to -distance (where second text takes first text's place).
    */
    0% { transform: translateX(0); }
    100% { transform: translateX(calc(-1 * var(--scroll-dist))); }
}

.param-item.active .param-value, .param-item.editing .param-value {
  color: var(--theme-selection);
  text-shadow: 0 0 8px var(--theme-selection);
}
.param-item.editing .param-value {
  cursor: text;
}
.param-item.editing .param-value:hover {
  text-shadow: 0 0 12px var(--theme-selection);
}
.param-value input {
  background: rgba(0,0,0,0.5);
  color: var(--theme-text);
  border: 1px solid var(--theme-selection);
  outline: none;
  width: 100px;
  font-family: monospace;
  font-size: 22px;
  text-align: center;
  padding: 2px 0;
  border-radius: 4px;
  text-shadow: 0 0 2px var(--theme-text);
}

/* Action Button Styles (e.g., Random, Reset) */
.param-item.is-action-button .param-button {
  display: none;
}
.param-item.is-action-button.has-no-value {
  justify-content: center;
}
.param-item.is-action-button.has-no-value .param-value-wrapper {
  display: none;
}
.param-item.is-action-button.has-no-value .param-label {
  width: auto;
  flex: 1 1 auto;
  text-align: center;
}
.param-item.is-action-button:not(.has-no-value) .param-value {
  min-width: unset;
  flex: 0 1 auto; /* Reset fixed width for action buttons like RESET */
  width: auto;
  max-width: none;
  text-align: right;
  padding-right: 10px;
  justify-content: flex-end;
}

/* Toggle Button Styles (e.g., Synth/Sample) */
.param-item.is-toggle-button .param-label {
    display: none;
}
.param-item.is-toggle-button .param-value-wrapper {
    justify-content: center;
    flex-grow: 1;
}
.param-item.is-toggle-button .param-value {
    display: flex;
    gap: 10px;
    width: auto; /* Reset fixed width for toggles */
    max-width: none;
    min-width: unset;
    flex: 0 1 auto;
    text-align: center;
}
.param-item.is-toggle-button .param-value span {
    padding: 0 10px;
    color: var(--theme-grid);
    border: 1px solid transparent;
    border-radius: 6px;
}
.param-item.is-toggle-button .param-value span.active {
    color: var(--theme-selection);
    border-color: var(--theme-selection);
    text-shadow: 0 0 5px var(--theme-selection);
}
.param-item.is-toggle-button:hover .param-value span:not(.active) {
     color: var(--theme-default);
}

/* No Label Styles (for STATE) */
.param-item.no-label {
  justify-content: center;
}
.param-item.no-label .param-value-wrapper {
  flex: 1;
  justify-content: space-between;
}
.param-item.no-label .param-value {
  flex: 1;
  max-width: none;
  min-width: 0;
  width: auto;
}

/* ==========================================================================
   9. REPL TERMINAL
   Command-line interface for advanced control.
   ========================================================================== */
@keyframes repl-cursor-blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0; }
}

#repl-container {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 15%;
    background-color: rgba(0, 20, 10, 0.85); /* Semi-transparent overlay */
    color: #0f0;
    font-family: 'Courier New', Courier, monospace;
    font-size: 16px;
    
    /* Removed border when inactive to prevent pixel bleed at top edge */
    border-bottom: none;

    display: flex;
    flex-direction: column;
    z-index: 100; /* Layer above objects canvas */
    text-transform: uppercase;
    cursor: text;
    text-shadow: 0 0 4px currentColor;
    
    /* Translate further up to ensure even sub-pixel rendering doesn't show the container */
    transform: translateY(-105%);
    transition: transform 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94), height 0.3s ease;
    
    pointer-events: none;
    
    box-sizing: border-box;
    padding-top: 5px;
    padding-left: 5px;
}

#repl-container.active {
    transform: translateY(0);
    pointer-events: auto;
    /* Add border only when active */
    border-bottom: 2px solid var(--theme-selection);
}

#repl-container.fullscreen {
    height: 100%;
    background-color: rgba(0, 15, 5, 0.95);
    border-bottom: none;
    padding: 15px;
}

#repl-container.fullscreen #repl-output {
    max-height: none;
    flex-grow: 1;
    height: auto;
}

#repl-output {
    padding: 10px;
    flex-grow: 1;
    overflow-y: auto;
    /* Use standard auto overflow to handle both dimensions if content is large */
    overflow: auto; 
    line-height: 1.25;
    user-select: text;
}

/* REPL Output Entries */
.repl-entry {
    white-space: pre-wrap !important; 
    word-wrap: break-word;
    font-family: 'Courier New', Courier, monospace; /* Enforce monospace for alignment */
}

#repl-output .repl-in {
    color: rgba(0, 255, 0, 0.6);
}

#repl-output .repl-stack {
    color: rgba(0, 255, 255, 0.8);
    font-style: italic;
}

#repl-output .repl-prompt {
    user-select: none;
    margin-right: 8px;
    color: rgba(0, 255, 0, 0.6);
}

/* REPL Input Line */
#repl-input-wrapper {
    display: flex;
    align-items: center;
    padding: 5px 10px;
    background-color: transparent; /* Ensures input line matches container */
    position: relative;
    flex-shrink: 0;
}

#repl-prompt {
    margin-right: 8px;
    color: #0f0;
}

#repl-cursor {
    position: absolute;
    display: none;
    width: 0.55em;
    background-color: var(--theme-default);
    animation: repl-cursor-blink 1.2s step-end infinite;
    pointer-events: none;
}

#repl-container.focused #repl-cursor {
    display: block;
}

#repl-input {
    flex-grow: 1;
    background-color: transparent !important; /* Ensure full transparency */
    border: none;
    outline: none;
    color: #0f0;
    font-family: 'Courier New', Courier, monospace;
    font-size: 16px;
    text-transform: uppercase;
    text-shadow: 0 0 4px currentColor;
    /* Remove default browser styling */
    -webkit-appearance: none;
    appearance: none;
}

#repl-input:focus {
    caret-color: transparent; /* Custom cursor used */
}

/* ==========================================================================
   10. HELP MODAL & INJECTED CONTENT
   Styles for the help/tutorial overlay.
   ========================================================================== */
#help-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background-color: var(--theme-bg); /* Theme-aware background */
    color: var(--theme-text);
    z-index: 100;
    overflow-y: auto;
    font-family: monospace;
    box-sizing: border-box;
}

/* Ensure the help modal gets a theme-aware outline when focused (for keyboard scrolling) */
#help-modal:focus {
    outline: 2px solid var(--theme-selection);
    outline-offset: -2px; /* Pull outline inside to be visible full-screen */
}

#help-modal-content-wrapper {
    padding: 40px;
    max-width: 900px;
    margin: 0 auto;
}

/* Override styles for injected help content (help.html, reference.html, tutorial.html) */
/* We use !important to override the inline <style> blocks within those HTML files */

#help-modal-content body { 
    background: transparent !important; 
    color: var(--theme-text) !important; 
}

#help-modal-content h1 { 
    color: var(--theme-selection) !important; 
    text-shadow: none !important; 
    border-bottom-color: var(--theme-selection) !important; 
}

#help-modal-content h2, 
#help-modal-content h3,
#help-modal-content h4 { 
    color: var(--theme-default) !important; 
    text-shadow: none !important; 
    border-bottom-color: var(--theme-grid) !important;
}

#help-modal-content p, 
#help-modal-content li, 
#help-modal-content ul, 
#help-modal-content ol, 
#help-modal-content td,
#help-modal-content .description { 
    color: var(--theme-text) !important; 
}

#help-modal-content a {
    color: var(--theme-selection) !important;
    text-shadow: none !important;
}

#help-modal-content .key { 
    background: var(--theme-menu-bg) !important; 
    padding: 2px 6px; 
    color: var(--theme-text) !important; 
    border: 1px solid var(--theme-grid) !important; 
    text-shadow: none !important;
}

#help-modal-content .param { 
    color: var(--theme-selection) !important; 
    background: transparent !important;
    border: none !important;
    font-weight: bold;
    text-shadow: none !important;
}

#help-modal-content li:before { 
    color: var(--theme-selection) !important; 
}
#help-modal-content li li:before { 
    color: var(--theme-default) !important; 
}

#help-modal-content .button { 
    border-color: var(--theme-selection) !important; 
    color: var(--theme-selection) !important; 
    background-color: var(--theme-menu-bg) !important;
    text-shadow: none !important;
}
#help-modal-content .button:hover { 
    background-color: var(--theme-menu-item-hover-bg) !important; 
    color: var(--theme-text) !important;
}

#help-modal-content .button.secondary { 
    border-color: var(--theme-default) !important; 
    color: var(--theme-default) !important; 
}
#help-modal-content .button.secondary:hover { 
    background-color: var(--theme-menu-item-hover-bg) !important; 
}

#help-modal-content .back-link { 
    border-color: var(--theme-selection) !important; 
    color: var(--theme-selection) !important; 
    background-color: var(--theme-bg) !important; 
}
#help-modal-content .back-link:hover { 
    background-color: var(--theme-menu-item-hover-bg) !important; 
}

#help-modal-content table { 
    border-color: var(--theme-grid) !important; 
    background-color: transparent !important; 
}
#help-modal-content th { 
    background-color: var(--theme-menu-item-hover-bg) !important; 
    color: var(--theme-selection) !important; 
    border-color: var(--theme-grid) !important;
}
#help-modal-content td { 
    color: var(--theme-text) !important; 
    border-color: var(--theme-grid) !important; 
}

#help-modal-content .accordion-toggle {
    color: var(--theme-default) !important;
    border-bottom-color: var(--theme-grid) !important;
    text-shadow: none !important;
}
#help-modal-content .accordion-toggle::after { 
    color: var(--theme-selection) !important; 
}

#help-modal-content .workflow { 
    background: var(--theme-menu-bg) !important; 
    border-color: var(--theme-grid) !important; 
    color: var(--theme-text) !important;
}
#help-modal-content code {
    background: var(--theme-menu-item-hover-bg) !important;
    color: var(--theme-text) !important;
    font-family: monospace;
    padding: 2px 4px;
    border-radius: 3px;
}

#help-modal-content .warning {
    color: var(--theme-looper-panic) !important;
    border-color: var(--theme-looper-panic) !important;
    background: rgba(255, 0, 0, 0.1) !important;
}

/* Apply theme aware focus to injected buttons/links inside the help modal */
#help-modal-content .button:focus,
#help-modal-content .back-link:focus,
#help-modal-content a:focus {
    outline: 2px solid var(--theme-selection);
    outline-offset: 2px;
}

/* ==========================================================================
   11. RESPONSIVE UTILITIES
   ========================================================================== */
@media (max-width: 650px) {
  .full-text { display: none; }
  .short-text { display: block; font-size: 20px; font-weight: bold; }
  #party-button, #panic-button, #worm-game-button {
    width: 22px !important;
  }
}
