@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;600;700;800&family=JetBrains+Mono:wght@400;600&display=swap');

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

:root {
  --bg:        #0b0e14;
  --surface:   #1e222b;
  --surface2:  #2a2f3a;
  --border:    rgba(255,255,255,0.08);
  --accent:    #FF9800; /* VisuAlgo Orange (Action/Pivot) */
  --green:     #8BC34A; /* VisuAlgo Green (Comparison) */
  --accent-blue: #00d2ff;
  --gold:      #ffcc00;
  --red:       #ff4757;
  --txt:       #f8fafc;
  --txt2:      #94a3b8;
  --txt3:      #64748b;
  --code-bg:   #0d1117;
  --radius:    14px;
  --font:      'Outfit', sans-serif;
  --mono:      'JetBrains Mono', monospace;
}

html, body { height: 100%; overflow: hidden; background: var(--bg); color: var(--txt); font-family: var(--font); }

/* VIEWS */
.view { display: none; height: 100vh; width: 100vw; }
.view.active { display: flex; }

/* ── DASHBOARD ── */
#view-dashboard { flex-direction: row; }

.sidebar {
  width: 250px; min-width: 250px; background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 24px 16px; gap: 8px;
}

.logo-area { display: flex; align-items: center; gap: 12px; margin-bottom: 24px; }
.logo-icon {
  width: 42px; height: 42px; border-radius: 12px;
  background: linear-gradient(135deg, var(--accent), var(--green));
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 0.85rem; color: #000;
}
.logo-text { font-weight: 700; font-size: 0.95rem; line-height: 1.3; }
.logo-text span { color: var(--accent); font-weight: 400; font-size: 0.8rem; }

.nav-label { font-size: 0.65rem; font-weight: 700; letter-spacing: 1.5px; color: var(--txt3); text-transform: uppercase; margin: 12px 0 6px 8px; }

.nav-btn {
  width: 100%; text-align: left; background: transparent; border: none;
  color: var(--txt2); padding: 10px 14px; border-radius: 10px;
  cursor: pointer; font-family: var(--font); font-size: 0.875rem;
  transition: all .2s;
}
.nav-btn:hover { background: var(--surface2); color: var(--txt); }
.nav-btn.active { background: rgba(0,210,255,.1); color: var(--accent); }

.sidebar-footer { margin-top: auto; background: var(--surface2); border-radius: 12px; padding: 14px; }
.progress-label { font-size: 0.75rem; color: var(--txt2); margin-bottom: 8px; }
.progress-bar { height: 5px; background: var(--bg); border-radius: 3px; }
.progress-fill { height: 100%; background: var(--accent); border-radius: 3px; }
.progress-text { font-size: 0.7rem; color: var(--txt3); margin-top: 6px; }

.dashboard-main { flex: 1; overflow-y: auto; display: flex; flex-direction: column; }
.dash-header { padding: 32px 40px 16px; border-bottom: 1px solid var(--border); }
.dash-header h1 { font-size: 1.5rem; font-weight: 700; }
.dash-header p  { color: var(--txt2); font-size: 0.875rem; margin-top: 4px; }

.cards-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(270px,1fr)); gap: 20px; padding: 28px 40px; }

.algo-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 22px; cursor: pointer; transition: all .25s; display: flex; flex-direction: column; gap: 10px;
}
.algo-card:hover { border-color: var(--accent); transform: translateY(-4px); box-shadow: 0 12px 30px rgba(0,0,0,.4); }
.algo-card.locked { opacity: .45; cursor: not-allowed; }
.algo-card.locked:hover { transform: none; border-color: var(--border); box-shadow: none; }

.card-tags { display: flex; gap: 6px; flex-wrap: wrap; }
.tag { font-size: 0.68rem; font-weight: 700; padding: 3px 9px; border-radius: 20px; }
.tag-search  { background: rgba(0,210,255,.12); color: var(--accent); }
.tag-sort    { background: rgba(0,255,136,.12); color: var(--green); }
.tag-graph   { background: rgba(255,99,71,.12); color: #ff9f7f; }
.tag-ml      { background: rgba(150,90,255,.12); color: #b090ff; }
.tag-opt     { background: rgba(255,204,0,.12); color: var(--gold); }
.tag-crypto  { background: rgba(255,255,255,.08); color: var(--txt2); }
.tag-easy    { background: rgba(0,255,136,.12); color: var(--green); }
.tag-medium  { background: rgba(255,204,0,.12); color: var(--gold); }
.tag-hard    { background: rgba(255,71,87,.12); color: var(--red); }
.tag-locked  { background: rgba(255,255,255,.06); color: var(--txt3); }

.card-title { font-size: 1rem; font-weight: 700; }
.card-desc  { font-size: 0.82rem; color: var(--txt2); line-height: 1.5; flex: 1; }
.card-footer { display: flex; justify-content: space-between; align-items: center; margin-top: 4px; }
.card-complexity { font-family: var(--mono); font-size: 0.8rem; color: var(--gold); }
.card-cta { font-size: 0.78rem; color: var(--accent); font-weight: 600; }


/* ── EXPLORER ── */
#view-explorer { flex-direction: column; }
.explorer-wrap { display: flex; flex-direction: column; height: 100vh; }

.explorer-bar {
  height: 52px; background: var(--surface); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 16px; padding: 0 24px;
}
.back-btn { background: transparent; border: none; color: var(--accent); font-family: var(--font); font-size: 0.875rem; cursor: pointer; font-weight: 600; }
.explorer-breadcrumb { font-weight: 600; font-size: 0.9rem; }
.exp-bar-right { margin-left: auto; display: flex; gap: 10px; }
.ops-chip        { background: rgba(0,255,136,.1); color: var(--green); font-size: 0.75rem; font-weight: 700; padding: 4px 10px; border-radius: 20px; }
.complexity-chip { background: rgba(255,204,0,.1); color: var(--gold); font-size: 0.75rem; font-weight: 700; padding: 4px 10px; border-radius: 20px; font-family: var(--mono); }

.viz-panel { flex: 1; display: flex; flex-direction: column; overflow: hidden; background: var(--code-bg); }

/* ── STUDIO SPLIT-SCREEN ── */
.explorer-split {
  display: flex; flex: 1; overflow: hidden; height: calc(100vh - 52px);
}

.split-side { height: 100%; display: flex; flex-direction: column; }
.split-left { 
  width: 40%; min-width: 350px; border-right: 1px solid var(--border); 
  background: var(--surface); z-index: 5;
}
.split-right { 
  width: 60%; flex: 1; background: var(--code-bg); position: relative;
}

.panel-header {
  padding: 16px 20px; border-bottom: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 12px;
}
.panel-header h3 { font-size: 0.9rem; font-weight: 700; color: var(--txt2); text-transform: uppercase; letter-spacing: 1px; }

.code-controls { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.minimal-select {
  background: var(--surface2); border: 1px solid var(--border); color: var(--txt);
  padding: 6px 12px; border-radius: 8px; font-size: 0.8rem; cursor: pointer; flex: 1;
}

.code-display {
  flex: 1; overflow-y: auto; padding: 20px;
  font-family: var(--mono); font-size: 0.85rem; line-height: 1.8;
  color: #e6edf3; background: #0d1117;
}

/* ── SIMULATION STUDIO (RIGHT) ── */
.viz-studio {
  display: flex; flex-direction: column; height: 100%; position: relative;
}

.viz-container {
  flex: 1; position: relative; overflow: hidden;
  display: flex; align-items: center; justify-content: center;
}

.narrative-hud {
  position: absolute; top: 75px; left: 50%; transform: translateX(-50%);
  width: auto; min-width: 350px; max-width: 80%;
  padding: 14px 24px; border: 1px solid rgba(255,152,0,0.3);
  border-radius: 16px; z-index: 50; text-align: center;
  box-shadow: 0 10px 40px rgba(0,0,0,0.6);
  animation: slideDownFade 0.4s ease-out;
}
@keyframes slideDownFade {
  from { opacity: 0; transform: translate(-50%, -10px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

.playback-bar {
  padding: 16px 30px; border-top: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center; /* CENTERED */
  gap: 40px;
  background: rgba(15, 23, 42, 0.9); backdrop-filter: blur(15px);
}

/* ── SIMULATION HEADER (NEW) ── */
.simulation-header {
  position: absolute; top: 0; left: 0; right: 0;
  padding: 12px 20px; z-index: 100;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: flex-start;
}
.data-input-group { display: flex; gap: 24px; align-items: center; }
.sub-input { display: flex; align-items: center; gap: 10px; }
.sub-input label { font-size: 0.65rem; font-weight: 700; color: var(--gold); text-transform: uppercase; }
.input-flex { display: flex; gap: 6px; }

.neo-input {
  background: rgba(0,0,0,0.3); border: 1px solid var(--border); border-radius: 8px;
  color: var(--txt); padding: 8px 12px; font-family: var(--mono); font-size: 0.85rem;
  transition: all 0.2s;
}
.neo-input:focus { border-color: var(--accent); outline: none; background: rgba(255,152,0,0.05); }
.target-w { width: 70px; text-align: center; }

.playback-controls { display: flex; gap: 8px; }
.p-btn {
  min-width: 44px; width: auto; padding: 0 16px; height: 44px; 
  border-radius: 12px; border: none; font-size: 0.85rem; font-weight: 600;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  gap: 8px; transition: all 0.2s;
}
.p-btn.primary-glow {
  background: var(--accent); color: #000;
  box-shadow: 0 0 15px rgba(255,152,0,0.4);
}
.p-btn.secondary { background: var(--surface2); color: var(--txt2); border: 1px solid var(--border); }
.p-btn.primary-glow:hover { transform: scale(1.05); filter: brightness(1.1); }
.p-btn:disabled { opacity: 0.3; cursor: not-allowed; }

.neo-range { flex: 1; height: 4px; background: var(--surface2); border-radius: 2px; accent-color: var(--accent); }
.playback-info { font-family: var(--mono); font-size: 0.8rem; color: var(--txt3); white-space: nowrap; }

/* ── STEP MODAL (DURING SIMULATION) ── */
#step-modal {
  position: fixed; inset: 0; background: rgba(0,0,0,0.6);
  backdrop-filter: blur(4px); z-index: 2000;
  display: none; align-items: center; justify-content: center; padding: 20px;
}
#step-modal.active { display: flex; }

.modal-box {
  background: var(--surface); border: 1px solid var(--accent);
  padding: 30px; border-radius: 20px; max-width: 450px; width: 100%;
  text-align: center; box-shadow: 0 20px 40px rgba(0,0,0,0.6);
  animation: popIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
@keyframes popIn { from { transform: scale(0.8); opacity: 0; } to { transform: scale(1); opacity: 1; } }

.modal-icon { font-size: 3rem; margin-bottom: 15px; }
.modal-body { color: var(--txt2); font-size: 0.95rem; line-height: 1.6; }

/* ── INTRO MODAL ── */
.intro-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.85);
  backdrop-filter: blur(10px); z-index: 1000;
  display: none; align-items: center; justify-content: center; padding: 20px;
}
.intro-overlay.active { display: flex; }

.intro-box {
  width: 100%; max-width: 700px; max-height: 85vh; overflow-y: auto;
  padding: 40px; border-radius: 24px; border: 1px solid rgba(255,255,255,0.1);
  position: relative; animation: zoomIn .3s ease-out;
}
@keyframes zoomIn { from { transform: scale(0.95); opacity: 0; } to { transform: scale(1); opacity: 1; } }

.close-x {
  position: absolute; top: 20px; right: 24px; font-size: 2rem;
  background: transparent; border: none; color: var(--txt3); cursor: pointer;
}

.intro-footer { margin-top: 30px; display: flex; justify-content: center; }

.glassmorphism {
  background: rgba(30, 41, 59, 0.7);
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
}

/* ── Global Nav Fixes ── */
.nav-back-btn { background: transparent; border: none; color: var(--txt2); cursor: pointer; font-size: 0.9rem; font-weight: 600; }
.nav-back-btn:hover { color: var(--accent); }
.nav-complexity { margin-left: auto; font-size: 0.8rem; font-family: var(--mono); color: var(--txt3); }
.nav-complexity span { color: var(--gold); font-weight: 700; }

.code-tabs { display: flex; align-items: center; gap: 4px; padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--border); }
.tab-btn { background: transparent; border: 1px solid transparent; color: var(--txt2); padding: 5px 14px; border-radius: 8px; cursor: pointer; font-family: var(--font); font-size: 0.82rem; transition: all .2s; }
.tab-btn.active { background: rgba(0,210,255,.1); border-color: rgba(0,210,255,.2); color: var(--accent); }
.algo-select { margin-left: auto; background: var(--surface2); border: 1px solid var(--border); color: var(--txt); padding: 5px 10px; border-radius: 8px; font-family: var(--font); font-size: 0.82rem; cursor: pointer; }

.code-display {
  height: 150px; overflow-y: auto; padding: 14px 20px;
  font-family: var(--mono); font-size: 0.85rem; line-height: 1.7;
  color: #e6edf3; background: #0d1117; border-bottom: 1px solid var(--border);
}
.code-line { display: block; padding: 1px 6px; border-radius: 4px; white-space: pre; }
.code-line.highlight { 
  background: rgba(255,152,0,0.25); 
  color: #fff; 
  font-weight: 600;
  border-left: 3px solid var(--accent);
  padding-left: 10px;
}

.viz-canvas {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 15px; padding: 15px; position: relative; overflow: hidden;
}
.ptr-row { position: absolute; top: 10px; width: calc(100% - 40px); height: 30px; }
.ptr { position: absolute; transition: left .35s ease; font-size: 0.75rem; font-weight: 700; text-align: center; line-height: 1; }
.ptr span { display: block; font-size: 0.6rem; }
.ptr-l { color: var(--accent); }
.ptr-m { color: var(--gold); }
.ptr-h { color: var(--red); }

.chest-row { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; margin-top: 40px; }
.chest {
  width: 52px; height: 52px; background: var(--surface2); border: 1px solid var(--border);
  border-radius: 10px; display: flex; align-items: center; justify-content: center;
  font-family: var(--mono); font-size: 1rem; font-weight: 600; color: var(--txt);
  transition: all .3s cubic-bezier(.175,.885,.32,1.275);
}
.chest.active { 
  border-color: var(--accent); 
  box-shadow: 0 0 20px rgba(255,152,0,0.4); 
  transform: scale(1.1); 
  background: rgba(255,152,0,0.1);
}
.chest.inactive { opacity: .15; filter: grayscale(1); }
.chest.found { 
  background: rgba(139,195,74,0.2); 
  border-color: var(--green); 
  box-shadow: 0 0 25px rgba(139,195,74,0.5); 
  color: var(--green); 
  transform: scale(1.15);
}
.chest.sorted { 
  background: rgba(100,116,139,0.1); 
  border-color: var(--txt3); 
  color: var(--txt3);
}
.chest.swap-hi { 
  border-color: #a855f7; 
  box-shadow: 0 0 15px rgba(168,85,247,0.4); 
}

/* Narrative HUD shifted to bottom of viz-panel later */

/* Layers and controls moved to viz-studio / split-right blocks */

/* ── Renderers ── */
.renderer-layer {
  display: none;
  width: 100%;
  height: 320px;
  align-items: center;
  justify-content: center;
  flex-direction: column;
}

.renderer-layer.active {
  display: flex !important;
}

/* ── HEAP DUAL VIEW (NEW) ── */
.heap-viz-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  width: 100%;
}
.chest-row-mini {
  display: flex; gap: 6px; justify-content: center; height: 40px;
}
.chest-row-mini .chest {
  width: 36px; height: 36px; font-size: 0.8rem; border-radius: 6px;
}


#graph-canvas, #cartesian-canvas, #tree-canvas {
  width: 100%;
  height: 100%;
  max-width: 600px;
  background: #0d1117;
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,0.05);
  box-shadow: inset 0 0 40px rgba(0,0,0,0.5);
}

.board-grid {
  display: grid;
  grid-template-columns: repeat(8, 30px);
  grid-template-rows: repeat(8, 30px);
  gap: 2px;
  background: #333;
  padding: 4px;
  border-radius: 4px;
}

.board-cell {
  width: 30px;
  height: 30px;
  background: #eee;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
}

.board-cell.black {
  background: #999;
}

.board-cell.queen {
  animation: drop 0.3s ease-out;
}

@keyframes drop {
  from { transform: scale(0); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

/* ── Narrative HUD ── */
/* Narrative hud moved to top of viz-container */

#narrative-text {
  color: #fff;
  font-size: 1rem;
  font-weight: 500;
  margin: 0;
  line-height: 1.5;
  text-shadow: 0 2px 4px rgba(0,0,0,0.5);
}

#narrative-text strong {
  color: var(--accent);
  font-weight: 700;
}

@keyframes fadeInNarrative {
  from { opacity: 0; transform: translateY(5px); }
  to { opacity: 1; transform: translateY(0); }
}

.narrative-text-animate {
  animation: fadeInNarrative 0.3s ease-out;
}

/* ── Radix Buckets ── */
.chest-row-radix {
  display: flex; gap: 8px; justify-content: center; height: 60px; margin-bottom: 20px; width: 100%; position: relative;
}

.radix-buckets-container {
  display: flex; gap: 10px; width: 100%; justify-content: center; margin-top: 10px;
}

.radix-bucket {
  width: 54px; min-height: 120px; background: rgba(255,255,255,0.03);
  border: 1px dashed rgba(255,255,255,0.1); border-radius: 8px;
  display: flex; flex-direction: column-reverse; align-items: center; padding: 6px; gap: 6px; position: relative;
}

.radix-bucket::after {
  content: attr(data-label); position: absolute; bottom: -22px; font-size: 0.75rem; color: var(--txt3); font-family: var(--mono);
}

.chest.radix-item {
  width: 46px; height: 46px; font-size: 0.85rem; border-radius: 6px;
}

.digit-active { color: #ff5252; font-weight: 800; text-decoration: underline; }

