@import url('https://fonts.googleapis.com/css2?family=Cinzel:wght@400;500;600;700;800;900&family=Inter:wght@300;400;500;600;700&family=Sora:wght@300;400;500;600&display=swap');

:root {
  --bg-primary: #0b1020;
  --bg-secondary: #101728;
  --bg-tertiary: #151d30;
  --bg-card: rgba(15, 22, 38, 0.85);
  --bg-card-hover: rgba(19, 28, 48, 0.95);

  --red-primary: #4cc9f0;
  --red-bright: #8be9fd;
  --red-glow: #8be9fd;
  --red-dark: #1b2a3f;
  --red-muted: rgba(76, 201, 240, 0.3);

  --blue-hex: #38bdf8;
  --blue-glow: #8be9fd;
  --blue-dark: #0f2a3a;

  --white: #e6eaf2;
  --white-bright: #ffffff;
  --gray-100: rgba(230, 234, 242, 0.82);
  --gray-200: rgba(230, 234, 242, 0.7);
  --gray-300: rgba(230, 234, 242, 0.5);
  --gray-400: rgba(230, 234, 242, 0.28);
  --gray-500: rgba(11, 16, 32, 0.9);

  --gold: #c8a96b;
  --green-zaun: #6bff95;
  --green-shimmer: #9d4edd;

  --font-display: 'Cinzel', serif;
  --font-body: 'Inter', sans-serif;
  --font-mono: 'Sora', sans-serif;

  --section-padding: clamp(40px, 5vw, 90px);
  --content-max-width: 1280px;

  --glow-red: 0 0 20px rgba(76, 201, 240, 0.45), 0 0 50px rgba(76, 201, 240, 0.2);
  --glow-blue: 0 0 24px rgba(56, 189, 248, 0.5), 0 0 60px rgba(56, 189, 248, 0.22);
  --glow-text-red: 0 0 12px rgba(76, 201, 240, 0.7), 0 0 26px rgba(76, 201, 240, 0.35);
  --glow-text-blue: 0 0 12px rgba(56, 189, 248, 0.7), 0 0 26px rgba(56, 189, 248, 0.35);

  --header-height: 64px;
}

*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
  scrollbar-width: thin;
  scrollbar-color: var(--red-primary) var(--bg-primary);
}

html::-webkit-scrollbar {
  width: 6px;
}

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

html::-webkit-scrollbar-thumb {
  background: var(--red-primary);
  border-radius: 3px;
}

body {
  font-family: var(--font-body);
  background: radial-gradient(circle at top, rgba(76, 201, 240, 0.08), transparent 60%), var(--bg-primary);
  color: var(--white);
  overflow: hidden;
  line-height: 1.6;
  height: 100vh;
  display: flex;
  flex-direction: column;
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(180deg, rgba(11, 16, 32, 0.35), rgba(11, 16, 32, 0.95));
  opacity: 0.8;
  z-index: 0;
}

/* ===== CANVAS / PARTICLES ===== */
#matrix-canvas,
#data-streams-canvas {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

#matrix-canvas {
  z-index: 1;
  opacity: 0.06;
}

#data-streams-canvas {
  z-index: 2;
  opacity: 0.12;
}

.grid-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 1;
  background-image:
    linear-gradient(rgba(76, 201, 240, 0.04) 1px, transparent 1px),
    linear-gradient(90deg, rgba(76, 201, 240, 0.04) 1px, transparent 1px);
  background-size: 70px 70px;
}

.digital-dust {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 3;
  overflow: hidden;
}

.dust-particle {
  position: absolute;
  width: 2px;
  height: 2px;
  background: var(--red-primary);
  border-radius: 50%;
  opacity: 0;
  animation: dustFloat 10s infinite;
}

@keyframes dustFloat {
  0% { opacity: 0; transform: translateY(100vh) scale(0); }
  10% { opacity: 0.8; }
  90% { opacity: 0.2; }
  100% { opacity: 0; transform: translateY(-20px) scale(1); }
}

/* ===== LOADING SCREEN ===== */
.loading-screen {
  position: fixed;
  inset: 0;
  background: var(--bg-primary);
  z-index: 9999;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  transition: opacity 0.6s ease, visibility 0.6s ease;
}

.loading-screen.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.loading-text {
  font-family: var(--font-display);
  font-size: 1rem;
  color: var(--gold);
  letter-spacing: 8px;
  text-transform: uppercase;
  margin-bottom: 30px;
  animation: loadingPulse 1.5s ease-in-out infinite;
}

@keyframes loadingPulse {
  0%, 100% { opacity: 0.4; }
  50% { opacity: 1; }
}

.loading-bar {
  width: 200px;
  height: 2px;
  background: var(--gray-500);
  position: relative;
  overflow: hidden;
}

.loading-bar::after {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, var(--red-primary), transparent);
  animation: loadingSweep 1.5s ease-in-out infinite;
}

@keyframes loadingSweep {
  0% { left: -100%; }
  100% { left: 100%; }
}

/* ===== HEADER ===== */
.archive-header {
  position: relative;
  z-index: 10;
  display: grid;
  grid-template-columns: minmax(180px, 260px) 1fr auto;
  gap: 20px;
  align-items: center;
  padding: 14px clamp(20px, 3vw, 40px);
  height: var(--header-height);
  background: rgba(11, 16, 32, 0.92);
  border-bottom: 1px solid rgba(76, 201, 240, 0.15);
  backdrop-filter: blur(8px);
  flex-shrink: 0;
}

.brand {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.brand-mark {
  font-family: var(--font-display);
  font-size: 0.82rem;
  letter-spacing: 3px;
  color: var(--gold);
  text-transform: uppercase;
}

.brand-sub {
  font-family: var(--font-mono);
  font-size: 0.58rem;
  letter-spacing: 3px;
  text-transform: uppercase;
  color: var(--gray-200);
}

.nav-links {
  display: flex;
  justify-content: center;
  gap: clamp(12px, 2.5vw, 28px);
  font-family: var(--font-mono);
  font-size: 0.68rem;
  letter-spacing: 3px;
  text-transform: uppercase;
}

.nav-link {
  color: var(--gray-300);
  text-decoration: none;
  position: relative;
  padding-bottom: 6px;
  transition: color 0.3s ease;
}

.nav-link::after {
  content: '';
  position: absolute;
  left: 0;
  bottom: 0;
  width: 100%;
  height: 1px;
  background: rgba(76, 201, 240, 0.4);
  opacity: 0;
  transform: scaleX(0.7);
  transition: all 0.3s ease;
}

.nav-link:hover,
.nav-link--active {
  color: var(--red-primary);
}

.nav-link--active::after,
.nav-link:hover::after {
  opacity: 1;
  transform: scaleX(1);
}

.nav-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.icon-button {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px solid rgba(200, 169, 107, 0.4);
  background: rgba(11, 16, 32, 0.7);
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: all 0.3s ease;
}

.icon-button svg {
  width: 16px;
  height: 16px;
  stroke: var(--red-primary);
  fill: none;
  stroke-width: 1.5;
}

.icon-button:hover {
  border-color: var(--red-primary);
  box-shadow: var(--glow-red);
  transform: translateY(-2px);
}

/* ===== MAIN LAYOUT — FIXED VIEWPORT ===== */
.challenge-layout {
  position: relative;
  z-index: 5;
  display: grid;
  grid-template-columns: 300px 1fr;
  gap: 20px;
  padding: 16px clamp(16px, 3vw, 40px) 16px;
  flex: 1;
  min-height: 0; /* critical for nested flex/grid overflow */
  overflow: hidden;
}

/* ===== LEFT COLUMN ===== */
.left-column {
  display: flex;
  flex-direction: column;
  gap: 0;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding-right: 6px;
}

.left-column::-webkit-scrollbar {
  width: 4px;
}

.left-column::-webkit-scrollbar-track {
  background: transparent;
}

.left-column::-webkit-scrollbar-thumb {
  background: rgba(76, 201, 240, 0.3);
  border-radius: 3px;
}

.left-column::-webkit-scrollbar-thumb:hover {
  background: rgba(76, 201, 240, 0.5);
}

/* ===== PANELS (shared) ===== */
.panel {
  background: transparent;
  border: none;
  border-radius: 0;
  padding: 0;
  position: relative;
  box-shadow: none;
}

.panel-header {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 10px;
}

.panel-title {
  font-family: var(--font-display);
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 3px;
  color: var(--gold);
}

.panel-path {
  font-family: var(--font-mono);
  font-size: 0.6rem;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--gray-300);
}

.panel-status {
  font-family: var(--font-mono);
  font-size: 0.6rem;
  color: var(--green-zaun);
  letter-spacing: 2px;
  text-transform: uppercase;
}

/* ===== ARCHIVE BROWSER ===== */
.panel-archive {
  flex-shrink: 0;
  padding-bottom: 16px;
  border-bottom: 1px solid rgba(76, 201, 240, 0.08);
  margin-bottom: 16px;
}

.folder-grid {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.folder-card {
  background: transparent;
  border: 1px solid transparent;
  padding: 12px 8px 10px;
  border-radius: 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  transition: all 0.3s ease;
  color: var(--white);
  text-align: center;
  position: relative;
}

.folder-card:hover {
  transform: translateY(-3px);
  background: rgba(76, 201, 240, 0.04);
  border-color: rgba(76, 201, 240, 0.15);
}

.folder-card.is-active {
  background: rgba(76, 201, 240, 0.06);
  border-color: rgba(76, 201, 240, 0.2);
}

.folder-card.is-locked {
  opacity: 0.35;
  pointer-events: none;
}

/* Retro folder icon */
.folder-icon {
  width: 48px;
  height: 40px;
  flex-shrink: 0;
  transition: all 0.3s ease;
  filter: drop-shadow(0 1px 3px rgba(0, 0, 0, 0.4));
}

.folder-icon svg {
  width: 100%;
  height: 100%;
}

.folder-body {
  fill: rgba(200, 169, 107, 0.15);
  stroke: rgba(200, 169, 107, 0.5);
  stroke-width: 1.5;
  transition: all 0.3s ease;
}

.folder-crease {
  stroke: rgba(200, 169, 107, 0.3);
  stroke-width: 1;
  transition: all 0.3s ease;
}

.folder-line {
  fill: rgba(200, 169, 107, 0.2);
  transition: all 0.3s ease;
}

/* Hover state — glow cyan */
.folder-card:hover .folder-body {
  fill: rgba(76, 201, 240, 0.12);
  stroke: rgba(76, 201, 240, 0.6);
}

.folder-card:hover .folder-crease {
  stroke: rgba(76, 201, 240, 0.35);
}

.folder-card:hover .folder-line {
  fill: rgba(76, 201, 240, 0.25);
}

.folder-card:hover .folder-icon {
  filter: drop-shadow(0 2px 8px rgba(76, 201, 240, 0.3));
  transform: scale(1.08);
}

/* Active state — brighter */
.folder-card.is-active .folder-body {
  fill: rgba(76, 201, 240, 0.15);
  stroke: var(--red-primary);
}

.folder-card.is-active .folder-crease {
  stroke: rgba(76, 201, 240, 0.45);
}

.folder-card.is-active .folder-line {
  fill: rgba(76, 201, 240, 0.3);
}

.folder-card.is-active .folder-icon {
  filter: drop-shadow(0 2px 10px rgba(76, 201, 240, 0.4));
}

/* Locked state — dimmed */
.folder-card.is-locked .folder-body {
  fill: rgba(200, 169, 107, 0.05);
  stroke: rgba(200, 169, 107, 0.15);
}

.folder-card.is-locked .folder-line {
  fill: rgba(200, 169, 107, 0.06);
}

.folder-label {
  font-family: var(--font-display);
  font-size: 0.62rem;
  letter-spacing: 2px;
  text-transform: uppercase;
  line-height: 1.2;
}

.folder-meta {
  font-family: var(--font-mono);
  font-size: 0.48rem;
  color: var(--gray-300);
  letter-spacing: 1.5px;
  text-transform: uppercase;
}

/* ===== FILE LIST ===== */
.file-list {
  position: relative;
  z-index: 1;
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 0;
}

.file-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 0;
  border-bottom: 1px solid rgba(76, 201, 240, 0.1);
  background: transparent;
  font-family: var(--font-mono);
  font-size: 0.6rem;
  letter-spacing: 1.5px;
  text-transform: uppercase;
}

.file-tag {
  color: var(--gold);
  font-size: 0.5rem;
  letter-spacing: 2px;
}

.file-name {
  color: var(--teal);
  font-family: var(--font-mono);
  font-size: 0.6rem;
  letter-spacing: 1.5px;
  text-transform: uppercase;
}

a.file-download {
  color: var(--teal);
  text-decoration: none;
  cursor: pointer;
  transition: color 0.2s, text-decoration 0.2s;
}

a.file-download:hover {
  color: var(--gold);
  text-decoration: underline;
}

/* ===== INTEL & SUBMISSION PANEL ===== */
.panel-intel {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.intel-toggle {
  width: 100%;
  text-align: center;
  padding: 10px 0;
  background: rgba(76, 201, 240, 0.04);
  border: 1px solid rgba(76, 201, 240, 0.15);
  border-radius: 2px;
  color: var(--red-primary);
  font-family: var(--font-mono);
  font-size: 0.68rem;
  letter-spacing: 4px;
  text-transform: uppercase;
  cursor: pointer;
  transition: all 0.3s ease;
  position: relative;
  margin-bottom: 14px;
}

.intel-toggle::before {
  content: '🔒 ';
  font-size: 0.7rem;
}

.intel-toggle:hover {
  color: var(--white-bright);
  background: rgba(76, 201, 240, 0.1);
  border-color: var(--red-primary);
  box-shadow: 0 0 16px rgba(76, 201, 240, 0.2);
}

.intel-block {
  position: relative;
  z-index: 1;
  margin-bottom: 14px;
}

.intel-label {
  font-family: var(--font-mono);
  font-size: 0.58rem;
  letter-spacing: 3px;
  text-transform: uppercase;
  color: var(--gray-300);
  margin-bottom: 6px;
}

/* ===== FLAG FORM ===== */
.flag-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: auto;
  padding-top: 8px;
}

.flag-input {
  background: transparent;
  border: none;
  border-bottom: 1px solid rgba(76, 201, 240, 0.25);
  border-radius: 0;
  padding: 8px 0;
  color: var(--white);
  font-family: var(--font-mono);
  font-size: 0.72rem;
  letter-spacing: 2px;
  text-transform: uppercase;
  outline: none;
  transition: border-color 0.3s ease;
}

.flag-input:focus {
  border-color: var(--red-primary);
}

.flag-input::placeholder {
  color: var(--gray-400);
}

.flag-input.input-error {
  border-color: rgba(230, 57, 70, 0.6);
  box-shadow: 0 0 12px rgba(230, 57, 70, 0.25);
}

.flag-button {
  padding: 10px 0;
  font-family: var(--font-display);
  text-transform: uppercase;
  letter-spacing: 3px;
  font-size: 0.72rem;
  border-radius: 0;
  border: 1px solid rgba(200, 169, 107, 0.3);
  background: rgba(200, 169, 107, 0.06);
  color: var(--gold);
  cursor: pointer;
  transition: all 0.3s ease;
  text-align: center;
}

.flag-button:hover {
  color: var(--white-bright);
  background: rgba(200, 169, 107, 0.15);
  border-color: var(--gold);
  box-shadow: 0 0 16px rgba(200, 169, 107, 0.25);
}

.flag-feedback {
  min-height: 16px;
  font-family: var(--font-mono);
  font-size: 0.6rem;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--gray-300);
}

/* ===== TERMINAL PANEL ===== */
.panel-terminal {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.terminal-header {
  position: relative;
  z-index: 1;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-family: var(--font-mono);
  letter-spacing: 2px;
  text-transform: uppercase;
  font-size: 0.62rem;
  color: var(--gray-200);
  margin-bottom: 8px;
  flex-shrink: 0;
}

.terminal-status {
  color: var(--green-zaun);
}

.terminal-screen {
  position: relative;
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 20px 24px;
  border-radius: 0;
  background: rgba(8, 12, 20, 0.85);
  border: 1px solid rgba(76, 201, 240, 0.08);
  overflow: hidden;
  min-height: 0;
}

.terminal-screen::before {
  content: '';
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(
    0deg,
    rgba(255, 197, 120, 0.03),
    rgba(255, 197, 120, 0.03) 2px,
    transparent 2px,
    transparent 4px
  );
  pointer-events: none;
  opacity: 0.55;
}

.terminal-screen::after {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 20% 20%, rgba(255, 201, 120, 0.06), transparent 60%);
  mix-blend-mode: screen;
  opacity: 0.6;
  animation: terminalFlicker 6s ease-in-out infinite;
  pointer-events: none;
}

@keyframes terminalFlicker {
  0%, 100% { opacity: 0.45; }
  50% { opacity: 0.7; }
}

.terminal-output {
  position: relative;
  z-index: 1;
  font-family: 'Courier New', monospace;
  font-size: 0.82rem;
  color: #f5b55a;
  text-shadow: 0 0 12px rgba(245, 181, 90, 0.45);
  line-height: 1.7;
  white-space: pre-wrap;
  flex: 1;
  overflow-y: auto;
  padding-right: 8px;
  min-height: 0;
}

.terminal-output::-webkit-scrollbar {
  width: 5px;
}

.terminal-output::-webkit-scrollbar-track {
  background: transparent;
}

.terminal-output::-webkit-scrollbar-thumb {
  background: rgba(245, 181, 90, 0.3);
  border-radius: 3px;
}

.terminal-output::-webkit-scrollbar-thumb:hover {
  background: rgba(245, 181, 90, 0.5);
}

.terminal-input-form {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: 'Courier New', monospace;
  font-size: 0.82rem;
  color: #f5b55a;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid rgba(245, 181, 90, 0.1);
  flex-shrink: 0;
}

.terminal-label {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.terminal-prompt {
  flex-shrink: 0;
  color: #f5b55a;
  text-shadow: 0 0 8px rgba(245, 181, 90, 0.5);
}

.terminal-input {
  flex: 1;
  background: transparent;
  border: none;
  color: inherit;
  font: inherit;
  outline: none;
  letter-spacing: 1px;
  min-width: 0;
}

.terminal-input:focus {
  outline: none;
  box-shadow: none;
}

@keyframes cursorBlink {
  0%, 49% { opacity: 1; }
  50%, 100% { opacity: 0; }
}

/* ===== RESPONSIVE ===== */
@media (max-width: 1024px) {
  body {
    overflow: auto;
    height: auto;
    min-height: 100vh;
  }

  .challenge-layout {
    grid-template-columns: 1fr;
    height: auto;
    min-height: calc(100vh - var(--header-height));
  }

  .left-column {
    overflow: visible;
  }

  .panel-terminal {
    min-height: 500px;
  }

  .folder-grid {
    grid-template-columns: repeat(4, 1fr);
  }
}

@media (max-width: 768px) {
  .archive-header {
    grid-template-columns: 1fr;
    text-align: center;
    gap: 10px;
    height: auto;
    padding: 12px 16px;
  }

  .nav-links {
    flex-wrap: wrap;
    justify-content: center;
  }

  .nav-actions {
    justify-content: center;
  }

  .challenge-layout {
    padding: 12px 14px;
    gap: 14px;
  }

  .folder-grid {
    grid-template-columns: 1fr 1fr;
  }

  .panel-terminal {
    min-height: 400px;
  }
}

@media (max-width: 480px) {
  .folder-grid {
    grid-template-columns: 1fr;
  }

  .terminal-screen {
    padding: 14px 16px;
  }

  .nav-links {
    font-size: 0.58rem;
    gap: 8px;
  }
}
