/* ===== RESET & BASE ===== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --green: #00ff41;
  --green-dim: #00aa2a;
  --green-dark: #004d14;
  --green-glow: rgba(0, 255, 65, 0.4);
  --amber: #ffb000;
  --red: #ff3333;
  --bg: #0a0a0a;
  --bg-panel: #0d1a0d;
  --bg-input: #050f05;
  --border: #00ff4133;
  --border-bright: #00ff4166;
  --font: 'Share Tech Mono', 'Courier New', monospace;
  --text-shadow: 0 0 8px var(--green-glow);
}

html, body {
  height: 100%;
  height: 100dvh;
  overflow: hidden;
  background: #000;
  font-family: var(--font);
  font-size: 14px;
  color: var(--green);
  position: fixed;
  width: 100%;
  touch-action: manipulation;
  -webkit-text-size-adjust: 100%;
}

/* ===== CRT CONTAINER ===== */
.crt {
  width: 100%;
  height: 100%;
  position: relative;
  overflow: hidden;
  background: var(--bg);
}

#screen {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  position: relative;
  z-index: 1;
  padding-top: env(safe-area-inset-top, 0px);
  padding-left: env(safe-area-inset-left, 0px);
  padding-right: env(safe-area-inset-right, 0px);
}

/* ===== CRT EFFECTS ===== */
.scanlines {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: repeating-linear-gradient(
    0deg,
    rgba(0, 0, 0, 0.12) 0px,
    rgba(0, 0, 0, 0.12) 1px,
    transparent 1px,
    transparent 3px
  );
  pointer-events: none;
  z-index: 100;
}

.crt-flicker {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  pointer-events: none;
  z-index: 101;
  animation: flicker 4s infinite;
}

@keyframes flicker {
  0%, 95%, 100% { opacity: 0; }
  96% { opacity: 0.02; background: var(--green); }
  97% { opacity: 0; }
  98% { opacity: 0.015; background: var(--green); }
}

/* Subtle screen curvature glow */
.crt::after {
  content: '';
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: radial-gradient(ellipse at center, transparent 60%, rgba(0,0,0,0.4) 100%);
  pointer-events: none;
  z-index: 99;
}

/* ===== HEADER ===== */
#header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-panel);
  flex-shrink: 0;
  min-height: 32px;
  flex-wrap: wrap;
  gap: 4px;
}

.classification {
  color: var(--red);
  font-weight: bold;
  font-size: 11px;
  letter-spacing: 1px;
  text-shadow: 0 0 6px rgba(255, 51, 51, 0.4);
}

#station-name {
  color: var(--green);
  text-shadow: var(--text-shadow);
  font-size: 13px;
  letter-spacing: 2px;
}

#clock {
  color: var(--green-dim);
  font-size: 12px;
}

/* ===== CONSOLE LAYOUT ===== */
#console {
  display: grid;
  grid-template-columns: 200px 1fr 300px;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

/* ===== PANELS ===== */
.panel-title {
  color: var(--green);
  font-size: 11px;
  letter-spacing: 2px;
  padding: 10px 12px 6px;
  border-bottom: 1px solid var(--border);
  text-shadow: var(--text-shadow);
}

#radio-panel, #tools-panel {
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

#tools-panel {
  border-right: none;
  border-left: 1px solid var(--border);
}

/* ===== FREQUENCY DISPLAY ===== */
#freq-display {
  padding: 12px;
}

.freq-label {
  color: var(--green-dim);
  font-size: 10px;
  letter-spacing: 1px;
  margin-bottom: 6px;
}

#freq-value {
  font-size: 32px;
  text-align: center;
  color: var(--green);
  text-shadow: 0 0 20px var(--green-glow), 0 0 40px var(--green-glow);
  padding: 8px 0;
  letter-spacing: 3px;
  border: 1px solid var(--border);
  background: var(--bg);
  margin-bottom: 8px;
  cursor: pointer;
}

#freq-value:hover {
  border-color: var(--green);
}

/* Frequency type-in input */
#freq-input-row {
  display: flex;
  gap: 4px;
  margin-bottom: 8px;
}

#freq-type-input {
  flex: 1;
  background: var(--bg);
  color: var(--green);
  border: 1px solid var(--green);
  font-family: var(--font);
  font-size: 18px;
  padding: 6px 8px;
  text-align: center;
  outline: none;
  text-shadow: var(--text-shadow);
  box-shadow: 0 0 10px var(--green-glow);
}

#freq-input-row .console-btn {
  padding: 6px 12px;
  font-size: 12px;
}

/* Frequency +/- buttons */
#freq-adjust {
  display: flex;
  gap: 4px;
  margin-bottom: 8px;
}

.freq-btn {
  flex: 1;
  padding: 6px 4px !important;
  font-size: 16px !important;
  font-weight: bold;
  min-height: 36px;
}

#freq-slider {
  width: 100%;
  -webkit-appearance: none;
  appearance: none;
  height: 6px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 0;
  outline: none;
  cursor: pointer;
}

#freq-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 20px;
  background: var(--green);
  border: none;
  cursor: pointer;
  box-shadow: 0 0 10px var(--green-glow);
}

#freq-slider::-moz-range-thumb {
  width: 16px;
  height: 20px;
  background: var(--green);
  border: none;
  cursor: pointer;
  box-shadow: 0 0 10px var(--green-glow);
}

.freq-range {
  display: flex;
  justify-content: space-between;
  font-size: 10px;
  color: var(--green-dark);
  margin-top: 4px;
}

/* ===== SIGNAL METER ===== */
#signal-meter {
  padding: 12px;
}

#signal-bars {
  display: flex;
  gap: 3px;
  align-items: flex-end;
  height: 40px;
  padding: 4px 0;
}

#signal-bars .bar {
  flex: 1;
  background: var(--green-dark);
  border: 1px solid var(--border);
  transition: background 0.15s, height 0.15s, box-shadow 0.15s;
}

#signal-bars .bar:nth-child(1) { height: 15%; }
#signal-bars .bar:nth-child(2) { height: 25%; }
#signal-bars .bar:nth-child(3) { height: 35%; }
#signal-bars .bar:nth-child(4) { height: 42%; }
#signal-bars .bar:nth-child(5) { height: 50%; }
#signal-bars .bar:nth-child(6) { height: 58%; }
#signal-bars .bar:nth-child(7) { height: 67%; }
#signal-bars .bar:nth-child(8) { height: 76%; }
#signal-bars .bar:nth-child(9) { height: 88%; }
#signal-bars .bar:nth-child(10) { height: 100%; }

#signal-bars .bar.active {
  background: var(--green);
  box-shadow: 0 0 8px var(--green-glow);
}

#signal-bars .bar.active.strong {
  background: var(--green);
}

#signal-bars .bar.active.warn {
  background: var(--amber);
  box-shadow: 0 0 8px rgba(255, 176, 0, 0.4);
}

#signal-label {
  text-align: center;
  font-size: 11px;
  color: var(--green-dim);
  margin-top: 4px;
  letter-spacing: 1px;
}

/* ===== BUTTONS ===== */
#radio-buttons, #tool-buttons {
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.console-btn {
  background: var(--bg);
  color: var(--green);
  border: 1px solid var(--border-bright);
  padding: 10px 12px;
  font-family: var(--font);
  font-size: 13px;
  letter-spacing: 2px;
  cursor: pointer;
  text-shadow: var(--text-shadow);
  transition: all 0.15s;
  text-align: center;
  -webkit-tap-highlight-color: transparent;
}

.console-btn:hover:not(:disabled) {
  background: var(--green-dark);
  border-color: var(--green);
  box-shadow: 0 0 10px var(--green-glow), inset 0 0 10px rgba(0, 255, 65, 0.1);
}

.console-btn:active:not(:disabled) {
  background: var(--green);
  color: var(--bg);
}

.console-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.console-btn.active {
  background: var(--green-dark);
  border-color: var(--green);
}

/* ===== MAIN DISPLAY ===== */
#display {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

#display-header {
  display: flex;
  justify-content: space-between;
  padding: 8px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-panel);
  flex-shrink: 0;
}

#display-mode {
  color: var(--green);
  font-size: 12px;
  letter-spacing: 2px;
}

#display-status {
  color: var(--amber);
  font-size: 12px;
}

#display-content {
  flex: 1;
  overflow-y: auto;
  padding: 0;
  position: relative;
}

#output {
  padding: 16px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-wrap: break-word;
}

#output .line {
  margin-bottom: 2px;
}

#output .static-text {
  color: var(--green-dark);
  opacity: 0.6;
}

#output .system-text {
  color: var(--amber);
}

#output .error-text {
  color: var(--red);
}

#output .highlight-text {
  color: var(--green);
  text-shadow: 0 0 12px var(--green-glow);
}

#output .dim-text {
  color: var(--green-dim);
}

#output .classified-text {
  color: var(--red);
  text-shadow: 0 0 8px rgba(255, 51, 51, 0.3);
}

#output .story-text {
  color: var(--green);
  text-shadow: var(--text-shadow);
  line-height: 1.8;
}

/* ===== TYPING / CAPTURE AREA ===== */
#typing-area {
  padding: 16px;
  border-top: 1px solid var(--border);
}

#transmission-text {
  font-size: 16px;
  line-height: 1.8;
  margin-bottom: 12px;
  min-height: 60px;
  letter-spacing: 1px;
}

#transmission-text .char-clear {
  color: var(--green);
  text-shadow: 0 0 12px var(--green-glow);
}

#transmission-text .char-static {
  color: var(--green-dark);
  opacity: 0.5;
}

#transmission-text .char-captured {
  color: var(--green);
  background: rgba(0, 255, 65, 0.15);
  text-shadow: 0 0 12px var(--green-glow);
}

#transmission-text .char-missed {
  color: var(--red);
  opacity: 0.5;
}

#capture-prompt {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
}

.prompt-label {
  color: var(--amber);
  font-size: 14px;
  flex-shrink: 0;
}

#capture-input {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border-bright);
  color: var(--green);
  font-family: var(--font);
  font-size: 16px;
  padding: 8px 12px;
  outline: none;
  text-shadow: var(--text-shadow);
  letter-spacing: 1px;
}

#capture-input:focus {
  border-color: var(--green);
  box-shadow: 0 0 10px var(--green-glow);
}

#capture-timer {
  margin-top: 8px;
  height: 4px;
  background: var(--bg);
  border: 1px solid var(--border);
  position: relative;
  overflow: hidden;
}

#capture-timer .timer-fill {
  position: absolute;
  top: 0; left: 0; bottom: 0;
  background: var(--green);
  transition: width 0.1s linear;
  box-shadow: 0 0 8px var(--green-glow);
}

#capture-timer .timer-fill.urgent {
  background: var(--amber);
  box-shadow: 0 0 8px rgba(255, 176, 0, 0.4);
}

#capture-timer .timer-fill.critical {
  background: var(--red);
  box-shadow: 0 0 8px rgba(255, 51, 51, 0.4);
  animation: pulse-red 0.5s infinite;
}

@keyframes pulse-red {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

/* ===== WORD CAPTURE BUTTONS (MOBILE) ===== */
#word-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
  justify-content: center;
}

.word-btn {
  background: var(--bg);
  color: var(--green);
  border: 1px solid var(--border-bright);
  padding: 12px 18px;
  font-family: var(--font);
  font-size: 14px;
  cursor: pointer;
  letter-spacing: 1px;
  transition: all 0.1s;
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
}

.word-btn:active {
  background: var(--green-dark);
  border-color: var(--green);
}

.word-btn.correct {
  background: rgba(0, 255, 65, 0.25);
  border-color: var(--green);
  color: var(--green);
  text-shadow: var(--text-shadow);
}

.word-btn.wrong {
  background: rgba(255, 51, 51, 0.25);
  border-color: var(--red);
  color: var(--red);
}

/* ===== DECODE CONTROLS ===== */
#decode-controls {
  padding: 12px;
}

#decode-controls select {
  width: 100%;
  background: var(--bg);
  color: var(--green);
  border: 1px solid var(--border-bright);
  font-family: var(--font);
  font-size: 12px;
  padding: 6px;
  margin-bottom: 12px;
  outline: none;
}

#caesar-controls {
  margin-bottom: 12px;
}

#shift-slider {
  width: 100%;
  -webkit-appearance: none;
  appearance: none;
  height: 6px;
  background: var(--bg);
  border: 1px solid var(--border);
  outline: none;
}

#shift-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 18px;
  background: var(--green);
  cursor: pointer;
}

#shift-value {
  text-align: center;
  font-size: 24px;
  color: var(--green);
  text-shadow: var(--text-shadow);
  margin-top: 4px;
}

#decode-preview {
  margin-top: 10px;
  padding: 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  font-size: 11px;
  color: var(--green-dim);
  max-height: 120px;
  overflow-y: auto;
  word-wrap: break-word;
  white-space: pre-wrap;
}

/* ===== MISSION TRACKER ===== */
#mission-tracker {
  margin-top: auto;
  border-top: 1px solid var(--border);
}

#mission-list {
  padding: 8px 12px;
}

.mission-item {
  font-size: 11px;
  padding: 4px 0;
  color: var(--green-dark);
  display: flex;
  align-items: center;
  gap: 6px;
}

.mission-item.completed {
  color: var(--green-dim);
}

.mission-item.active {
  color: var(--green);
  text-shadow: var(--text-shadow);
}

.mission-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--green-dark);
  flex-shrink: 0;
}

.mission-item.completed .mission-dot {
  background: var(--green-dim);
}

.mission-item.active .mission-dot {
  background: var(--green);
  box-shadow: 0 0 6px var(--green-glow);
  animation: pulse-dot 1.5s infinite;
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* ===== INPUT BAR ===== */
#input-bar {
  display: flex;
  align-items: center;
  padding: 8px 16px;
  border-top: 1px solid var(--border);
  background: var(--bg-panel);
  flex-shrink: 0;
}

.prompt-symbol {
  color: var(--amber);
  margin-right: 8px;
  font-size: 16px;
  text-shadow: 0 0 8px rgba(255, 176, 0, 0.4);
}

#command-input {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--green);
  font-family: var(--font);
  font-size: 16px;
  outline: none;
  text-shadow: var(--text-shadow);
  caret-color: var(--green);
}

#command-input::placeholder {
  color: var(--green-dark);
  opacity: 0.5;
}

/* ===== CRT KEYBOARD ===== */
#crt-keyboard {
  flex-shrink: 0;
  background: var(--bg-panel);
  border-top: 1px solid var(--border);
  padding: 6px 4px;
  padding-bottom: calc(6px + env(safe-area-inset-bottom, 0px));
}

.kb-row {
  display: flex;
  gap: 3px;
  justify-content: center;
  margin: 2px 0;
}

.kb-key {
  background: var(--bg);
  color: var(--green);
  border: 1px solid var(--border-bright);
  font-family: var(--font);
  font-size: 15px;
  min-width: 32px;
  min-height: 44px;
  padding: 8px 6px;
  cursor: pointer;
  text-shadow: var(--text-shadow);
  flex: 1;
  max-width: 42px;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.08s, color 0.08s;
  user-select: none;
  -webkit-user-select: none;
}

.kb-key:active, .kb-key.pressed {
  background: var(--green);
  color: var(--bg);
  text-shadow: none;
}

.kb-key-wide {
  flex: 1.5;
  max-width: 64px;
  font-size: 11px;
  letter-spacing: 1px;
}

.kb-key-space {
  flex: 4;
  max-width: none;
  font-size: 11px;
  letter-spacing: 2px;
}

.kb-key-enter {
  flex: 2;
  max-width: none;
  font-size: 12px;
  letter-spacing: 2px;
  background: var(--green-dark);
  border-color: var(--green-dim);
}

.kb-key-enter:active {
  background: var(--green);
  color: var(--bg);
}

/* ===== HIDDEN ===== */
.hidden {
  display: none !important;
}

/* ===== CURSOR BLINK ===== */
@keyframes blink {
  0%, 49% { opacity: 1; }
  50%, 100% { opacity: 0; }
}

.cursor {
  display: inline-block;
  width: 8px;
  height: 16px;
  background: var(--green);
  animation: blink 1s infinite;
  vertical-align: text-bottom;
  margin-left: 2px;
}

/* ===== STATIC ANIMATION ===== */
@keyframes static-noise {
  0% { background-position: 0 0; }
  100% { background-position: 100% 100%; }
}

.static-overlay {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  opacity: 0.03;
  pointer-events: none;
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 2px,
    rgba(0, 255, 65, 0.03) 2px,
    rgba(0, 255, 65, 0.03) 4px
  );
  animation: static-noise 0.5s infinite linear;
}

/* ===== SCROLLBAR ===== */
::-webkit-scrollbar {
  width: 6px;
}

::-webkit-scrollbar-track {
  background: var(--bg);
}

::-webkit-scrollbar-thumb {
  background: var(--green-dark);
  border: 1px solid var(--border);
}

::-webkit-scrollbar-thumb:hover {
  background: var(--green-dim);
}

/* ===== INTRO SCREEN ===== */
.intro-prompt {
  text-align: center;
  padding: 20px;
  animation: pulse-green 2s infinite;
}

@keyframes pulse-green {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

/* ===== MOBILE RESPONSIVE ===== */
@media (max-width: 900px) {
  #console {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr auto;
  }

  #radio-panel {
    border-right: none;
    border-bottom: 1px solid var(--border);
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    padding: 4px 0;
  }

  #radio-panel > .panel-title {
    display: none;
  }

  #freq-display {
    flex: 1;
    min-width: 180px;
    padding: 8px 12px;
  }

  #freq-value {
    font-size: 22px;
    padding: 4px 0;
  }

  #freq-adjust {
    margin-bottom: 4px;
  }

  .freq-btn {
    min-height: 44px !important;
  }

  #signal-meter {
    flex: 1;
    min-width: 140px;
    padding: 8px 12px;
  }

  #signal-bars {
    height: 28px;
  }

  #radio-buttons {
    flex-direction: row;
    padding: 8px 12px;
    min-width: 160px;
  }

  #tools-panel {
    border-left: none;
    border-top: 1px solid var(--border);
    order: 3;
  }

  #tools-panel > .panel-title {
    display: none;
  }

  #tool-buttons {
    flex-direction: row;
    flex-wrap: wrap;
    padding: 8px 12px;
  }

  .console-btn {
    padding: 12px 14px;
    font-size: 13px;
    min-height: 48px;
  }

  #tool-buttons .console-btn {
    flex: 1;
    min-width: 80px;
  }

  #mission-tracker {
    display: none;
  }

  #decode-controls {
    padding: 8px 12px;
  }

  #decode-controls select {
    padding: 10px 8px;
    font-size: 14px;
    min-height: 44px;
  }

  #header-left, #header-right {
    flex: 1;
  }

  #header-center {
    display: none;
  }

  html, body {
    font-size: 13px;
  }

  #transmission-text {
    font-size: 14px;
  }

  #freq-slider::-webkit-slider-thumb {
    width: 28px;
    height: 32px;
  }

  #freq-slider::-moz-range-thumb {
    width: 28px;
    height: 32px;
  }

  #shift-slider::-webkit-slider-thumb {
    width: 24px;
    height: 28px;
  }

  #input-bar {
    padding: 10px 16px;
    min-height: 48px;
  }
}

@media (max-width: 500px) {
  #header {
    padding: 4px 10px;
  }

  .classification {
    font-size: 9px;
  }

  #clock {
    font-size: 10px;
  }

  #freq-value {
    font-size: 18px;
  }

  #radio-panel {
    flex-direction: column;
  }

  #radio-buttons {
    flex-direction: row;
    width: 100%;
  }

  #display-content {
    padding: 0;
  }

  #output {
    padding: 10px;
    font-size: 12px;
  }

  #transmission-text {
    font-size: 13px;
  }

  #capture-input {
    font-size: 16px;
    padding: 8px 10px;
  }

  .kb-key {
    font-size: 14px;
    min-height: 40px;
    padding: 6px 4px;
  }

  .word-btn {
    padding: 10px 14px;
    font-size: 13px;
    min-height: 44px;
  }
}

/* ===== LANDSCAPE COMPACT ===== */
@media (orientation: landscape) and (max-height: 500px) {
  #header {
    padding: 2px 12px;
    min-height: 24px;
  }

  .classification { font-size: 9px; }
  #clock { font-size: 10px; }

  #radio-panel {
    padding: 2px 0;
  }

  #freq-display {
    padding: 4px 10px;
  }

  #freq-value {
    font-size: 16px;
    padding: 2px 0;
    margin-bottom: 4px;
  }

  #freq-adjust {
    margin-bottom: 2px;
  }

  .freq-btn {
    min-height: 36px !important;
  }

  #signal-meter {
    padding: 4px 10px;
  }

  #signal-bars {
    height: 20px;
  }

  #radio-buttons, #tool-buttons {
    padding: 4px 10px;
  }

  .console-btn {
    padding: 6px 10px;
    min-height: 36px;
  }

  #display-header {
    padding: 4px 12px;
  }

  #output {
    padding: 8px;
    font-size: 12px;
  }

  #typing-area {
    padding: 8px;
  }

  #transmission-text {
    font-size: 12px;
    min-height: 40px;
    margin-bottom: 6px;
  }

  #input-bar {
    padding: 4px 12px;
    min-height: 36px;
  }

  .kb-key {
    min-height: 34px;
    padding: 4px 3px;
    font-size: 13px;
  }

  .word-btn {
    padding: 6px 10px;
    min-height: 36px;
    font-size: 12px;
  }
}
