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

:root {
  --bg:       #1a0e00;
  --amber:    #ffb000;
  --bright:   #ff8c00;
  --dim:      #7a5000;
  --green:    #00ff41;
  --red:      #ff3333;
  --glow:     0 0 6px #ffb000, 0 0 12px #ff8c0066;
  --glow-sm:  0 0 4px #ffb000aa;
  --font:     'IBM Plex Mono', 'Courier New', monospace;
}

html, body {
  width: 100%; height: 100%;
  background: var(--bg);
  color: var(--amber);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  overflow: hidden;
  user-select: none;
}

/* Allow selecting/copying terminal output and lesson panel text */
#terminal-output, #terminal-output *,
#lesson-body, #lesson-body *,
#lesson-title {
  user-select: text;
}

/* ===== CRT EFFECTS ===== */
.crt-scanlines {
  position: fixed; inset: 0; z-index: 9998; pointer-events: none;
  background: repeating-linear-gradient(
    to bottom,
    transparent 0px,
    transparent 2px,
    rgba(0,0,0,0.18) 2px,
    rgba(0,0,0,0.18) 4px
  );
}

.crt-vignette {
  position: fixed; inset: 0; z-index: 9997; pointer-events: none;
  background: radial-gradient(ellipse at center,
    transparent 60%,
    rgba(0,0,0,0.55) 100%
  );
}

/* ===== FLICKER ANIMATION ===== */
@keyframes flicker-wrong {
  0%   { opacity: 1; }
  10%  { opacity: 0.3; }
  20%  { opacity: 1; }
  30%  { opacity: 0.5; }
  40%  { opacity: 1; }
  50%  { opacity: 0.2; }
  60%  { opacity: 1; }
  100% { opacity: 1; }
}
@keyframes green-flash {
  0%   { background: rgba(0,255,65,0.18); }
  100% { background: transparent; }
}
@keyframes blink {
  0%, 49% { opacity: 1; }
  50%, 100% { opacity: 0; }
}
@keyframes typing {
  from { width: 0; }
}
@keyframes fadeIn {
  from { opacity: 0; } to { opacity: 1; }
}
@keyframes slideUp {
  from { transform: translateY(10px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}
@keyframes pulse-glow {
  0%, 100% { text-shadow: var(--glow-sm); }
  50%       { text-shadow: var(--glow); }
}
@keyframes shortcut-slide {
  0%   { transform: translateY(40px); opacity: 0; }
  15%  { transform: translateY(0);    opacity: 1; }
  75%  { transform: translateY(0);    opacity: 1; }
  100% { transform: translateY(40px); opacity: 0; }
}

body.flicker { animation: flicker-wrong 0.4s ease; }
body.success-flash #terminal-wrap { animation: green-flash 0.5s ease; }

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

/* ===== BOOT SCREEN ===== */
#boot-screen {
  position: fixed; inset: 0; z-index: 100;
  display: flex; flex-direction: column;
  justify-content: center; align-items: flex-start;
  padding: 15vh 10vw;
  background: var(--bg);
}

#boot-text {
  font-size: 13px;
  color: var(--amber);
  text-shadow: var(--glow-sm);
  white-space: pre-wrap;
  line-height: 1.8;
  max-width: 600px;
}

#boot-prompt {
  margin-top: 24px;
  color: var(--bright);
  text-shadow: var(--glow);
  font-size: 14px;
  animation: blink 1s step-end infinite;
}

/* ===== HEADER ===== */
#header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--dim);
  flex-shrink: 0;
  position: relative;
}

#logo {
  font-weight: 700;
  font-size: 13px;
  color: var(--bright);
  text-shadow: var(--glow);
  letter-spacing: 0.1em;
  animation: pulse-glow 3s ease-in-out infinite;
}

#progress-dots {
  display: flex; gap: 8px; flex: 1;
}
#progress-dots span {
  font-size: 16px;
  color: var(--dim);
  transition: color 0.3s, text-shadow 0.3s;
  cursor: default;
}
#progress-dots span.done {
  color: var(--amber);
  text-shadow: var(--glow-sm);
}
#progress-dots span.active {
  color: var(--bright);
  text-shadow: var(--glow);
  animation: pulse-glow 1.5s ease-in-out infinite;
}

#skip-btn {
  background: none;
  border: 1px solid var(--dim);
  color: var(--dim);
  font-family: var(--font);
  font-size: 11px;
  padding: 4px 10px;
  cursor: pointer;
  letter-spacing: 0.05em;
  transition: all 0.2s;
}
#skip-btn:hover {
  border-color: var(--amber);
  color: var(--amber);
  text-shadow: var(--glow-sm);
}
#back-to-tutorial-btn {
  background: none;
  border: 1px solid var(--green);
  color: var(--green);
  font-family: var(--font);
  font-size: 11px;
  padding: 4px 10px;
  cursor: pointer;
  letter-spacing: 0.05em;
  transition: all 0.2s;
  text-shadow: 0 0 6px var(--green);
}
#back-to-tutorial-btn:hover {
  background: rgba(0,255,65,0.1);
  text-shadow: var(--glow-sm);
}

#mute-btn {
  background: none;
  border: none;
  color: var(--dim);
  font-size: 14px;
  padding: 4px 6px;
  cursor: pointer;
  transition: all 0.2s;
  line-height: 1;
}
#mute-btn:hover { color: var(--green); }

#chapter-select-btn {
  background: none;
  border: 1px solid var(--dim);
  color: var(--dim);
  font-family: var(--font);
  font-size: 11px;
  padding: 4px 10px;
  cursor: pointer;
  letter-spacing: 0.05em;
  transition: all 0.2s;
}
#chapter-select-btn:hover,
#chapter-select-btn.active {
  border-color: var(--amber);
  color: var(--amber);
  text-shadow: var(--glow-sm);
}

#chapter-dropdown {
  position: absolute;
  top: 42px;
  right: 12px;
  background: #0a0f0a;
  border: 1px solid var(--dim);
  z-index: 100;
  min-width: 280px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.8);
}
.chapter-option {
  padding: 10px 14px;
  cursor: pointer;
  font-size: 12px;
  color: var(--dim);
  border-bottom: 1px solid rgba(255,255,255,0.05);
  display: flex;
  align-items: center;
  gap: 8px;
  transition: background 0.15s;
}
.chapter-option:last-child { border-bottom: none; }
.chapter-option:hover { background: rgba(0,255,65,0.06); color: var(--green); }
.chapter-option.current { color: var(--amber); }
.chapter-option.done { color: var(--green); opacity: 0.7; }
.chapter-option .chapter-status { font-size: 10px; width: 12px; flex-shrink: 0; }
.chapter-option .chapter-lesson-count {
  margin-left: auto;
  font-size: 10px;
  opacity: 0.5;
}

/* ===== MAIN APP LAYOUT ===== */
#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

/* ===== LESSON PANEL ===== */
#lesson-panel {
  padding: 14px 18px 12px;
  border-bottom: 1px solid var(--dim);
  background: rgba(255,176,0,0.03);
  flex-shrink: 0;
  animation: slideUp 0.3s ease;
}

#chapter-label {
  font-size: 10px;
  color: var(--dim);
  letter-spacing: 0.15em;
  text-transform: uppercase;
  margin-bottom: 4px;
}

#lesson-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--bright);
  text-shadow: var(--glow-sm);
  margin-bottom: 8px;
}

#lesson-body {
  font-size: 13px;
  color: var(--amber);
  line-height: 1.7;
}

#lesson-body code {
  background: rgba(255,176,0,0.12);
  color: var(--bright);
  padding: 1px 5px;
  border-radius: 2px;
  font-family: var(--font);
}

#lesson-body .challenge {
  margin-top: 10px;
  padding: 8px 12px;
  border-left: 2px solid var(--bright);
  color: var(--bright);
  font-size: 13px;
}

#lesson-body .hint-text {
  margin-top: 8px;
  color: var(--dim);
  font-size: 12px;
  font-style: italic;
  animation: fadeIn 0.4s ease;
}

#lesson-body .show-me-btn {
  display: inline-block;
  margin-top: 8px;
  background: none;
  border: 1px solid var(--dim);
  color: var(--dim);
  font-family: var(--font);
  font-size: 11px;
  padding: 3px 10px;
  cursor: pointer;
  transition: all 0.2s;
}
#lesson-body .show-me-btn:hover {
  border-color: var(--bright);
  color: var(--bright);
}

/* ===== LESSON ACTIONS ===== */
#lesson-actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

#lesson-actions button {
  background: none;
  border: 1px solid var(--dim);
  color: var(--dim);
  font-family: var(--font);
  font-size: 11px;
  padding: 3px 10px;
  cursor: pointer;
  transition: all 0.2s;
  letter-spacing: 0.05em;
}

#lesson-actions button:hover {
  border-color: var(--green);
  color: var(--green);
}

#skip-lesson-btn:hover {
  border-color: var(--amber, #ffa500) !important;
  color: var(--amber, #ffa500) !important;
}

.oracle-enter-prompt {
  color: var(--dim);
  opacity: 0.7;
  font-size: 11px;
  margin-top: 6px;
  letter-spacing: 0.08em;
  animation: blink-cursor 1s step-end infinite;
}

@keyframes blink-cursor {
  50% { opacity: 0.2; }
}

/* ===== TERMINAL ===== */
#terminal-wrap {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  position: relative;
  padding: 12px 16px 8px;
}

#terminal-output {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding-bottom: 4px;
  scrollbar-width: thin;
  scrollbar-color: var(--dim) transparent;
}

#terminal-output::-webkit-scrollbar { width: 4px; }
#terminal-output::-webkit-scrollbar-thumb { background: var(--dim); }

.output-line {
  white-space: pre-wrap;
  word-break: break-all;
  line-height: 1.6;
  animation: fadeIn 0.15s ease;
}
.output-line.cmd    { color: var(--amber); }
.output-line.result { color: var(--amber); }
.output-line.error  { color: var(--red); }
.output-line.success { color: var(--green); text-shadow: 0 0 6px #00ff4166; }
.output-line.system { color: var(--dim); font-style: italic; }
.output-line.bright { color: var(--bright); }

/* ===== CTRL+R SEARCH OVERLAY ===== */
#search-overlay {
  padding: 6px 0;
  border-top: 1px solid var(--dim);
  font-size: 13px;
  color: var(--amber);
  flex-shrink: 0;
}
.search-label { color: var(--dim); }
#search-result { color: var(--bright); margin-left: 4px; }

/* ===== INPUT ROW ===== */
#terminal-input-row {
  display: flex;
  align-items: center;
  gap: 0;
  padding-top: 6px;
  border-top: 1px solid var(--dim);
  flex-shrink: 0;
  position: relative;
}

#prompt-user { color: var(--bright); text-shadow: var(--glow-sm); }
#prompt-sep  { color: var(--dim); }
#prompt-path { color: var(--amber); }
#prompt-dollar { color: var(--bright); margin: 0 6px 0 1px; }

#input-display-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  font-size: 14px;
  color: var(--amber);
  text-shadow: var(--glow-sm);
  white-space: pre;
  cursor: text;
  min-height: 20px;
}

#input-before { white-space: pre; }
#input-after  { white-space: pre; }

#cursor-block {
  color: var(--amber);
  text-shadow: var(--glow);
  animation: blink 1s step-end infinite;
  font-size: 14px;
  line-height: 1;
}

/* Real input — invisible, always focused */
#real-input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
  pointer-events: none;
}

/* ===== SHORTCUT BANNER ===== */
#shortcut-banner {
  position: fixed;
  bottom: 60px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0,255,65,0.1);
  border: 1px solid var(--green);
  color: var(--green);
  text-shadow: 0 0 8px #00ff41;
  padding: 10px 20px;
  font-size: 13px;
  font-family: var(--font);
  z-index: 500;
  text-align: center;
  pointer-events: none;
  border-radius: 2px;
  animation: shortcut-slide 2.5s ease forwards;
}

/* ===== MATRIX ===== */
#matrix-canvas {
  position: fixed; inset: 0; z-index: 200;
  background: black;
}

/* ===== SCROLLBAR ===== */
* { scrollbar-width: thin; scrollbar-color: var(--dim) transparent; }

/* ===== MOBILE WARNING ===== */
@media (max-width: 600px) {
  #lesson-body .challenge::before {
    content: "⚠ Keyboard shortcuts need a physical keyboard. Connect one for the full experience.\A\A";
    white-space: pre;
    color: var(--dim);
    font-size: 11px;
  }
  #terminal-wrap { font-size: 12px; }
}

/* ===== ORACLE NARRATIVE STYLES ===== */
.oracle-msg { color: var(--green); line-height: 1.7; }
.output-line.oracle { color: var(--amber); font-style: italic; text-shadow: 0 0 6px rgba(255,170,0,0.3); }
