:root {
  --blue: #2563eb;
  --blue-dark: #1d4ed8;
  --blue-light: #dbeafe;
  --green: #16a34a;
  --green-light: #dcfce7;
  --amber: #d97706;
  --amber-light: #fef3c7;
  --gray-50: #f9fafb;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-400: #9ca3af;
  --gray-600: #4b5563;
  --gray-800: #1f2937;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.06);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--gray-50);
  color: var(--gray-800);
  line-height: 1.6;
  min-height: 100vh;
}

.header {
  background: linear-gradient(135deg, var(--blue) 0%, var(--blue-dark) 100%);
  color: white;
  padding: 1.25rem 1.5rem;
}

.header-inner { max-width: 1200px; margin: 0 auto; }
.header h1 { font-size: 1.5rem; font-weight: 700; }
.subtitle { opacity: .85; font-size: .9rem; margin-top: .15rem; }

.layout {
  display: grid;
  grid-template-columns: 240px 1fr;
  max-width: 1200px;
  margin: 0 auto;
  min-height: calc(100vh - 80px);
}

.sidebar {
  background: white;
  border-right: 1px solid var(--gray-200);
  padding: 1.25rem 1rem;
  position: sticky;
  top: 0;
  height: calc(100vh - 80px);
  overflow-y: auto;
}

.sidebar h2 {
  font-size: .75rem;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--gray-400);
  margin-bottom: .75rem;
}

.nav-list { list-style: none; }
.nav-btn {
  display: block;
  width: 100%;
  text-align: left;
  padding: .55rem .75rem;
  border: none;
  background: none;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: .9rem;
  color: var(--gray-600);
  transition: background .15s, color .15s;
}

.nav-btn:hover { background: var(--gray-100); color: var(--gray-800); }
.nav-btn.active { background: var(--blue-light); color: var(--blue); font-weight: 600; }

.strategy-mini {
  margin-top: 1.5rem;
  padding-top: 1rem;
  border-top: 1px solid var(--gray-200);
}

.strategy-mini h3 {
  font-size: .75rem;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--gray-400);
  margin-bottom: .5rem;
}

.mini-step {
  display: flex;
  align-items: center;
  gap: .4rem;
  font-size: .75rem;
  color: var(--gray-400);
  padding: .2rem 0;
  transition: color .2s;
}

.mini-step.active { color: var(--blue); font-weight: 600; }
.mini-step.done { color: var(--green); }

.mini-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--gray-200);
  flex-shrink: 0;
}

.mini-step.active .mini-dot { background: var(--blue); }
.mini-step.done .mini-dot { background: var(--green); }

.main { padding: 1.5rem; overflow-y: auto; }

.view { display: none; }
.view.active { display: block; }

.intro { color: var(--gray-600); margin-bottom: 1.25rem; max-width: 700px; }

h2 { font-size: 1.35rem; margin-bottom: .75rem; }
h3 { font-size: 1.05rem; margin-bottom: .5rem; color: var(--gray-800); }

.strategy-list {
  list-style: none;
  margin-bottom: 1.5rem;
  max-width: 600px;
}

.strategy-list li {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .45rem 0;
  font-size: .95rem;
}

.step-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--blue-light);
  color: var(--blue);
  font-weight: 700;
  font-size: .8rem;
  flex-shrink: 0;
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 1rem;
  margin-top: 1rem;
}

.card {
  background: white;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  padding: 1.25rem;
  cursor: pointer;
  transition: box-shadow .2s, border-color .2s;
}

.card:hover {
  box-shadow: var(--shadow);
  border-color: var(--blue);
}

.card h4 { margin-bottom: .35rem; color: var(--blue); }
.card p { font-size: .85rem; color: var(--gray-600); }

/* Algorithm view */
.algo-header { margin-bottom: 1rem; }

.inputs-panel {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  background: white;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  margin-bottom: 1rem;
}

.input-group {
  display: flex;
  flex-direction: column;
  gap: .25rem;
}

.input-group label {
  font-size: .8rem;
  font-weight: 600;
  color: var(--gray-600);
}

.input-group input {
  width: 100px;
  padding: .4rem .6rem;
  border: 1px solid var(--gray-200);
  border-radius: 6px;
  font-size: .95rem;
}

.input-group input:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 2px var(--blue-light);
}

.step-indicator {
  display: flex;
  gap: .35rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.phase-dot {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .75rem;
  font-weight: 700;
  background: var(--gray-100);
  color: var(--gray-400);
  cursor: pointer;
  transition: all .2s;
  border: 2px solid transparent;
}

.phase-dot.active {
  background: var(--blue);
  color: white;
  border-color: var(--blue-dark);
  transform: scale(1.1);
}

.phase-dot.done { background: var(--green-light); color: var(--green); }

.content-grid {
  display: grid;
  grid-template-columns: 1fr 1.4fr;
  gap: 1rem;
  margin-bottom: 1rem;
}

.explain-panel {
  background: white;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  padding: 1.25rem;
}

.explain-panel h3 {
  color: var(--blue);
  font-size: .95rem;
  margin-bottom: .5rem;
}

.explain-panel p { font-size: .9rem; color: var(--gray-600); }

.visual-panel {
  background: white;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  padding: 1.25rem;
  min-height: 320px;
  overflow: auto;
}

/* Pseudocode */
.pseudocode {
  font-family: "Courier New", Courier, monospace;
  font-size: .9rem;
  line-height: 1.8;
  background: var(--gray-800);
  color: #e5e7eb;
  padding: 1rem 1.25rem;
  border-radius: 8px;
  overflow-x: auto;
}

.pseudo-line {
  padding: .1rem .5rem;
  border-radius: 4px;
  transition: background .2s;
}

.pseudo-line.active {
  background: var(--amber);
  color: var(--gray-800);
  font-weight: 600;
}

.pseudo-line .kw { color: #93c5fd; }
.pseudo-line.active .kw { color: var(--blue-dark); }

/* Python code */
.python-code {
  font-family: "Courier New", Courier, monospace;
  font-size: .85rem;
  line-height: 1.7;
  background: #1e1e2e;
  color: #cdd6f4;
  padding: 1rem 1.25rem;
  border-radius: 8px;
}

.python-line.active {
  background: rgba(217, 119, 6, .3);
  display: block;
  margin: 0 -.5rem;
  padding: 0 .5rem;
  border-radius: 3px;
}

/* Flowchart */
.flowchart-svg { width: 100%; max-width: 400px; margin: 0 auto; display: block; }

.fc-node { transition: filter .3s; }
.fc-node.active { filter: drop-shadow(0 0 6px var(--amber)); }
.fc-node.active rect,
.fc-node.active ellipse,
.fc-node.active polygon { stroke: var(--amber); stroke-width: 3; }

.fc-label {
  font-family: -apple-system, sans-serif;
  font-size: 12px;
  fill: var(--gray-800);
  text-anchor: middle;
  dominant-baseline: central;
  pointer-events: none;
}

.fc-arrow { stroke: var(--gray-400); stroke-width: 1.5; fill: none; marker-end: url(#arrowhead); }

/* Trace table */
.trace-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .85rem;
}

.trace-table th {
  background: var(--blue);
  color: white;
  padding: .5rem .75rem;
  text-align: center;
  font-weight: 600;
}

.trace-table td {
  padding: .45rem .75rem;
  text-align: center;
  border-bottom: 1px solid var(--gray-200);
}

.trace-table tr.active-row { background: var(--amber-light); }
.trace-table td.active-cell {
  background: var(--amber);
  color: white;
  font-weight: 700;
}

.trace-table tr.hidden-row { display: none; }
.trace-table tr.visible-row { display: table-row; }

/* Console output */
.console {
  background: #1e1e2e;
  color: #a6e3a1;
  font-family: "Courier New", monospace;
  font-size: .9rem;
  padding: 1rem 1.25rem;
  border-radius: 8px;
  min-height: 80px;
}

.console-line { margin: .25rem 0; }
.console-line.active { color: #f9e2af; font-weight: 600; }
.console-prompt { color: #89b4fa; }

/* Triangle visual */
.triangle-visual { text-align: center; }
.triangle-visual svg { max-width: 280px; margin: 0 auto; display: block; }
.triangle-label { font-size: .85rem; fill: var(--gray-600); }

/* Power series bars */
.bars-container {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: .5rem;
  height: 180px;
  padding: 1rem 0;
}

.bar-group { display: flex; flex-direction: column; align-items: center; gap: .25rem; }

.bar {
  width: 40px;
  background: var(--blue-light);
  border-radius: 4px 4px 0 0;
  transition: height .4s, background .3s;
  min-height: 4px;
}

.bar.active { background: var(--amber); }
.bar.done { background: var(--green); }

.bar-label { font-size: .75rem; color: var(--gray-600); }
.bar-value { font-size: .8rem; font-weight: 700; color: var(--gray-800); }

.sum-display {
  text-align: center;
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--blue);
  margin-top: .75rem;
}

/* Prime numbers visual */
.primes-grid {
  display: flex;
  flex-wrap: wrap;
  gap: .4rem;
  justify-content: center;
  padding: .5rem 0;
}

.prime-chip {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  font-size: .85rem;
  font-weight: 600;
  background: var(--gray-100);
  color: var(--gray-400);
  transition: all .3s;
}

.prime-chip.checking { background: var(--amber-light); color: var(--amber); transform: scale(1.15); }
.prime-chip.is-prime { background: var(--green-light); color: var(--green); }
.prime-chip.not-prime { background: var(--gray-100); color: var(--gray-400); opacity: .5; }
.prime-chip.active { box-shadow: 0 0 0 3px var(--blue); }

.primes-sum {
  text-align: center;
  font-size: 1rem;
  margin-top: .75rem;
  color: var(--gray-600);
}

.primes-sum strong { color: var(--blue); }

/* Data structure panel */
.data-vars {
  display: flex;
  flex-wrap: wrap;
  gap: .75rem;
  justify-content: center;
}

.var-box {
  background: var(--blue-light);
  border: 2px solid var(--blue);
  border-radius: 8px;
  padding: .6rem 1rem;
  text-align: center;
  min-width: 80px;
}

.var-name { font-size: .75rem; color: var(--blue); font-weight: 600; }
.var-value { font-size: 1.1rem; font-weight: 700; color: var(--gray-800); }

.var-box.active { border-color: var(--amber); background: var(--amber-light); }

/* Problem analysis */
.problem-box {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 1rem;
  align-items: center;
  text-align: center;
}

.problem-section {
  background: var(--gray-100);
  border-radius: 8px;
  padding: 1rem;
}

.problem-section h4 { font-size: .85rem; color: var(--blue); margin-bottom: .5rem; }
.problem-section ul { list-style: none; font-size: .9rem; }
.problem-section li { padding: .2rem 0; }

.problem-arrow { font-size: 1.5rem; color: var(--blue); }

/* Result panel */
.result-panel {
  text-align: center;
  padding: 1.5rem;
}

.result-panel .result-value {
  font-size: 2rem;
  font-weight: 700;
  color: var(--green);
  margin: .5rem 0;
}

.result-panel .result-formula {
  font-size: 1rem;
  color: var(--gray-600);
}

.learn-box {
  background: var(--green-light);
  border-radius: 8px;
  padding: 1rem;
  margin-top: 1rem;
  text-align: left;
  font-size: .9rem;
  color: var(--gray-800);
}

/* Controls */
.controls {
  display: flex;
  align-items: center;
  gap: .75rem;
  flex-wrap: wrap;
  background: white;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  padding: .75rem 1rem;
}

.ctrl-btn {
  padding: .5rem 1rem;
  border: 1px solid var(--gray-200);
  border-radius: 6px;
  background: white;
  cursor: pointer;
  font-size: .85rem;
  transition: background .15s;
}

.ctrl-btn:hover:not(:disabled) { background: var(--gray-100); }
.ctrl-btn:disabled { opacity: .4; cursor: not-allowed; }
.ctrl-btn.primary { background: var(--blue); color: white; border-color: var(--blue); }
.ctrl-btn.primary:hover { background: var(--blue-dark); }

.speed-label { font-size: .85rem; color: var(--gray-600); }
.speed-label select {
  padding: .3rem .5rem;
  border: 1px solid var(--gray-200);
  border-radius: 4px;
  font-size: .85rem;
}

.step-counter {
  margin-left: auto;
  font-size: .85rem;
  color: var(--gray-400);
}

@media (max-width: 768px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar {
    position: static;
    height: auto;
    border-right: none;
    border-bottom: 1px solid var(--gray-200);
  }
  .content-grid { grid-template-columns: 1fr; }
  .nav-list { display: flex; flex-wrap: wrap; gap: .25rem; }
  .nav-btn { width: auto; }
}
