/* =============================================================
   DSA Visualizer — Complete Stylesheet
   dark/light theme · responsive · LeetCode × GFG hybrid
   ============================================================= */

/* ---------- CSS Variables ---------- */
:root {
  --bg: #0f172a;
  --bg-alt: #1e293b;
  --bg-card: #1e293b;
  --bg-hover: #334155;
  --text: #e2e8f0;
  --text-muted: #94a3b8;
  --text-dim: #64748b;
  --border: #334155;
  --accent: #6366f1;
  --accent-light: #818cf8;
  --green: #22c55e;
  --red: #ef4444;
  --orange: #f59e0b;
  --blue: #3b82f6;
  --purple: #8b5cf6;
  --font: 'Inter', -apple-system, sans-serif;
  --mono: 'JetBrains Mono', 'Fira Code', monospace;
  --radius: 8px;
  --shadow: 0 4px 24px rgba(0,0,0,0.3);
  --transition: 0.2s ease;
}

[data-theme="light"] {
  --bg: #f8fafc;
  --bg-alt: #ffffff;
  --bg-card: #ffffff;
  --bg-hover: #f1f5f9;
  --text: #1e293b;
  --text-muted: #64748b;
  --text-dim: #94a3b8;
  --border: #e2e8f0;
  --shadow: 0 4px 24px rgba(0,0,0,0.08);
}

/* ---------- Reset ---------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; scroll-behavior: smooth; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}
a { color: var(--accent); text-decoration: none; }
code { font-family: var(--mono); font-size: 0.9em; }
.muted { color: var(--text-muted); font-size: 0.9em; }

/* ---------- Skeleton ---------- */
.skeleton {
  background: linear-gradient(90deg, var(--bg-hover) 25%, var(--bg-alt) 50%, var(--bg-hover) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: var(--radius);
}
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

/* ---------- Navbar ---------- */
.navbar {
  background: var(--bg-alt);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}
.navbar-inner {
  max-width: 1400px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.65rem 1.5rem;
}
.brand { display: flex; align-items: center; gap: 0.5rem; font-weight: 800; font-size: 1.2rem; }
.brand-logo { font-size: 1.5rem; }
.brand-accent { color: var(--accent); }
.nav-links { flex: 1; display: flex; justify-content: center; }
.problem-select {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.4rem 1rem;
  font-family: var(--font);
  font-size: 0.95rem;
  max-width: 340px;
  cursor: pointer;
}
.problem-select:focus { outline: 2px solid var(--accent); outline-offset: 2px; }
.nav-actions { display: flex; align-items: center; gap: 1rem; }
.progress-badge { font-size: 0.85rem; color: var(--text-muted); white-space: nowrap; }
.icon-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.4rem 0.7rem;
  cursor: pointer;
  font-size: 1.1rem;
  color: var(--text);
  transition: var(--transition);
}
.icon-btn:hover { background: var(--bg-hover); }

/* ---------- Layout ---------- */
.layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
  max-width: 1400px;
  margin: 1.5rem auto;
  padding: 0 1.5rem;
}
.panel {
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.5rem;
  overflow: hidden;
}

/* ---------- Problem Panel ---------- */
.problem-title-row {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 0.5rem;
}
.problem-title { font-size: 1.4rem; font-weight: 700; }
.difficulty-badge {
  padding: 0.2rem 0.8rem;
  border-radius: 20px;
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.difficulty-easy { background: #1a2e1a; color: #4ade80; }
.difficulty-medium { background: #2e2a1a; color: #fbbf24; }
.difficulty-hard { background: #2e1a1a; color: #f87171; }
[data-theme="light"] .difficulty-easy { background: #dcfce7; color: #16a34a; }
[data-theme="light"] .difficulty-medium { background: #fef9c3; color: #ca8a04; }
[data-theme="light"] .difficulty-hard { background: #fee2e2; color: #dc2626; }

.problem-tags { display: flex; gap: 0.4rem; flex-wrap: wrap; margin-bottom: 1rem; }
.tag {
  background: var(--bg-hover);
  color: var(--text-muted);
  padding: 0.15rem 0.6rem;
  border-radius: 12px;
  font-size: 0.75rem;
  font-weight: 500;
}
.pattern-tag { background: var(--accent); color: #fff; }

.problem-section { margin-bottom: 1.5rem; }
.problem-section h3 { font-size: 0.95rem; font-weight: 600; margin-bottom: 0.5rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; }
.problem-section ul { padding-left: 1.2rem; color: var(--text-muted); font-size: 0.9rem; }
.problem-section li { margin-bottom: 0.3rem; }
.problem-section p { font-size: 0.95rem; color: var(--text-muted); line-height: 1.7; }

.example-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.8rem 1rem;
  margin-bottom: 0.6rem;
}
.example-header { font-weight: 600; font-size: 0.85rem; margin-bottom: 0.4rem; color: var(--text-muted); }
.example-row { font-size: 0.88rem; margin-bottom: 0.25rem; }
.example-label { font-weight: 500; color: var(--text-dim); }

/* ---------- Code Area ---------- */
.code-tabs { display: flex; gap: 0.25rem; margin-bottom: 0.5rem; align-items: center; }
.code-tab {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px 6px 0 0;
  padding: 0.35rem 0.9rem;
  font-family: var(--font);
  font-size: 0.8rem;
  cursor: pointer;
  color: var(--text-muted);
  transition: var(--transition);
}
.code-tab.active { background: var(--bg-alt); color: var(--accent); border-color: var(--accent); border-bottom-color: transparent; }
.code-hint { margin-left: auto; font-size: 0.75rem; color: var(--text-dim); }

#code-editor {
  width: 100%;
  min-height: 200px;
  background: #0d1117;
  color: #c9d1d9;
  border: 1px solid var(--border);
  border-radius: 0 0 var(--radius) var(--radius);
  padding: 1rem;
  font-family: var(--mono);
  font-size: 0.85rem;
  line-height: 1.6;
  resize: vertical;
  tab-size: 4;
}
[data-theme="light"] #code-editor { background: #f6f8fa; color: #24292f; }

.code-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.5rem;
  flex-wrap: wrap;
}
.dynamic-inputs { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.inline-field { display: flex; align-items: center; gap: 0.3rem; font-size: 0.8rem; color: var(--text-muted); }
.inline-field input {
  width: 60px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.2rem 0.4rem;
  color: var(--text);
  font-family: var(--mono);
  font-size: 0.8rem;
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.45rem 1rem;
  border-radius: var(--radius);
  font-family: var(--font);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  transition: var(--transition);
  white-space: nowrap;
}
.btn-primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-primary:hover { background: var(--accent-light); }
.btn-ghost { background: transparent; color: var(--text-muted); border-color: var(--border); }
.btn-ghost:hover { background: var(--bg-hover); }
.btn-success { background: var(--green); color: #fff; border-color: var(--green); }
.btn-success:hover { background: #16a34a; }
.btn-success:disabled { opacity: 0.6; cursor: default; }

/* ---------- Output ---------- */
.output-area {
  margin-top: 0.5rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.8rem 1rem;
  min-height: 50px;
  font-family: var(--mono);
  font-size: 0.85rem;
}
.output-placeholder, .output-loading { color: var(--text-dim); }
.output-error { color: var(--red); }
.output-stdout { color: var(--text); margin-bottom: 0.3rem; }
.output-result { color: var(--green); font-weight: 600; }
.output-expected { color: var(--text-muted); margin-top: 0.2rem; }

/* ---------- Visualizer Panel ---------- */
.viz-header { display: flex; align-items: center; gap: 1rem; margin-bottom: 1rem; }
.viz-header h2 { font-size: 1.1rem; font-weight: 700; }
.viz-subtitle {
  font-size: 0.8rem;
  color: var(--accent);
  background: rgba(99,102,241,0.15);
  padding: 0.2rem 0.8rem;
  border-radius: 20px;
  font-weight: 500;
}

/* Controls */
.control-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}
.field { display: flex; flex-direction: column; gap: 0.15rem; font-size: 0.75rem; color: var(--text-muted); }
.field input, .field select {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.3rem 0.5rem;
  color: var(--text);
  font-family: var(--mono);
  font-size: 0.8rem;
}
.control-row { display: flex; align-items: center; gap: 0.4rem; flex-wrap: wrap; margin-bottom: 0.5rem; }
.speed-field { flex-direction: row; align-items: center; gap: 0.4rem; }
.speed-field input[type="range"] { width: 70px; }
.iter-indicator { font-family: var(--mono); font-size: 0.85rem; color: var(--text-muted); min-width: 70px; text-align: center; }
.preset-row { display: flex; align-items: center; gap: 0.4rem; flex-wrap: wrap; }
.preset-label { font-size: 0.8rem; color: var(--text-dim); }
.chip {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 0.2rem 0.7rem;
  font-size: 0.75rem;
  cursor: pointer;
  color: var(--text-muted);
  transition: var(--transition);
  white-space: nowrap;
}
.chip:hover { background: var(--bg-hover); color: var(--text); }

/* Viz Canvas */
.viz-canvas {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  min-height: 280px;
}
.viz-status-bar {
  font-size: 0.9rem;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
  text-align: center;
}
#viz-svg { width: 100%; height: auto; min-height: 140px; }

.decision-panel {
  margin-top: 0.5rem;
  text-align: center;
}
.decision-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  flex-wrap: wrap;
}
.compare-badge {
  background: var(--bg-hover);
  padding: 0.2rem 0.8rem;
  border-radius: 20px;
  font-size: 0.8rem;
  font-family: var(--mono);
}
.decision-badge {
  padding: 0.2rem 0.8rem;
  border-radius: 20px;
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
}
.decision-left { background: #1a2e3a; color: #60a5fa; }
.decision-right { background: #2e1a1a; color: #f87171; }
.decision-found { background: #1a2e1a; color: #4ade80; }
.decision-not_found { background: #2e1a1a; color: #fca5a5; }
[data-theme="light"] .decision-left { background: #dbeafe; color: #2563eb; }
[data-theme="light"] .decision-right { background: #fee2e2; color: #dc2626; }
[data-theme="light"] .decision-found { background: #dcfce7; color: #16a34a; }
[data-theme="light"] .decision-not_found { background: #ffe4e6; color: #e11d48; }

/* ---------- Step Log ---------- */
.step-log { margin-top: 1rem; }
.step-log h3 { font-size: 0.95rem; font-weight: 600; margin-bottom: 0.5rem; }
.step-table-wrap { max-height: 260px; overflow-y: auto; border: 1px solid var(--border); border-radius: var(--radius); }
.step-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
  font-family: var(--mono);
}
.step-table th {
  background: var(--bg-alt);
  color: var(--text-muted);
  font-weight: 600;
  text-align: left;
  padding: 0.4rem 0.6rem;
  position: sticky;
  top: 0;
  z-index: 1;
  border-bottom: 1px solid var(--border);
}
.step-table td {
  padding: 0.3rem 0.6rem;
  border-bottom: 1px solid var(--border);
  color: var(--text-muted);
}
.step-table tr:hover { background: var(--bg-hover); cursor: pointer; }
.step-table tr.highlight { background: rgba(99,102,241,0.15); }
.step-table tr.found-row { background: rgba(34,197,94,0.1); }

/* ---------- GFG Panels ---------- */
.gfg-panels {
  max-width: 1400px;
  margin: 0 auto 2rem;
  padding: 0 1.5rem;
}
.gfg-title { font-size: 1.2rem; font-weight: 700; margin-bottom: 1rem; }
.accordion { border: 1px solid var(--border); border-radius: 12px; overflow: hidden; }
.accordion-item { border-bottom: 1px solid var(--border); }
.accordion-item:last-child { border-bottom: none; }
.accordion-header {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--bg-alt);
  border: none;
  padding: 0.8rem 1.2rem;
  font-family: var(--font);
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  transition: var(--transition);
}
.accordion-header:hover { background: var(--bg-hover); }
.accordion-header.active { color: var(--accent); }
.accordion-icon { font-size: 1.2rem; font-weight: 700; }
.accordion-body {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease;
  background: var(--bg);
  padding: 0 1.2rem;
}
.accordion-body.open { max-height: 800px; padding: 1rem 1.2rem; }
.accordion-body p { font-size: 0.9rem; color: var(--text-muted); line-height: 1.7; }
.accordion-body ul { padding-left: 1.2rem; color: var(--text-muted); font-size: 0.9rem; }
.accordion-body li { margin-bottom: 0.3rem; }

/* ---------- Footer ---------- */
.footer {
  text-align: center;
  padding: 1.5rem;
  color: var(--text-dim);
  font-size: 0.8rem;
  border-top: 1px solid var(--border);
}
.footer code { background: var(--bg-hover); padding: 0.1rem 0.4rem; border-radius: 4px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.7rem 1.5rem;
  font-size: 0.9rem;
  font-weight: 500;
  box-shadow: var(--shadow);
  opacity: 0;
  transition: all 0.3s ease;
  z-index: 200;
  pointer-events: none;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast-success { border-color: var(--green); color: var(--green); }
.toast-error { border-color: var(--red); color: var(--red); }

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .navbar-inner { flex-wrap: wrap; }
  .problem-select { max-width: 100%; }
  .control-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 600px) {
  .control-grid { grid-template-columns: 1fr; }
  .code-actions { flex-direction: column; align-items: stretch; }
  .dynamic-inputs { justify-content: center; }
}
