:root {
  color-scheme: light;
  --bg: #f5f8fb;
  --panel: #ffffff;
  --panel-2: #edf4fb;
  --text: #142033;
  --muted: #5f6f82;
  --line: #d8e2ee;
  --accent: #2fb6a3;
  --accent-2: #f4b942;
  --danger: #ef6f6c;
  --blue: #1d75bd;
  --green: #7bd88f;
  --code: #111827;
  --shadow: 0 16px 42px rgba(30, 64, 105, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

.site-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  min-height: 72px;
  padding: 12px 28px;
  border-bottom: 1px solid #0b5f9d;
  background: linear-gradient(135deg, #0f5f9e, #1688c9);
  box-shadow: 0 10px 28px rgba(15, 95, 158, 0.24);
}

.site-brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  color: #f8fbff;
  text-decoration: none;
  white-space: nowrap;
}

.brand-badge {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.95);
  color: #0f5f9e;
  font-weight: 900;
  font-size: 0.82rem;
  box-shadow: inset 0 -1px 0 rgba(15, 95, 158, 0.15);
}

.brand-copy {
  display: grid;
  gap: 3px;
  place-items: start;
}

.brand-copy strong {
  color: #ffffff;
  line-height: 1.1;
  font-size: 1rem;
}

.brand-copy small {
  color: rgba(239, 246, 255, 0.88);
  font-size: 0.78rem;
  line-height: 1.2;
  white-space: normal;
}

.main-menu {
  display: flex;
  flex-wrap: wrap;
  justify-content: end;
  gap: 8px;
}

.main-menu a {
  border: 1px solid transparent;
  border-radius: 8px;
  color: rgba(239, 246, 255, 0.84);
  padding: 8px 10px;
  text-decoration: none;
  font-size: 0.9rem;
}

.main-menu a:hover,
.main-menu a:focus {
  border-color: rgba(255, 255, 255, 0.28);
  background: rgba(255, 255, 255, 0.12);
  color: #ffffff;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: 310px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: auto;
  padding: 24px;
  border-right: 1px solid var(--line);
  background: var(--panel);
}

h1,
h2,
h3,
h4,
p {
  margin: 0;
}

h1 {
  font-size: 1.25rem;
}

.topbar p,
.visual-header p,
.code-toolbar p {
  color: var(--muted);
  font-size: 0.88rem;
}

.search-box {
  display: grid;
  gap: 8px;
  margin-bottom: 12px;
  color: var(--muted);
  font-size: 0.82rem;
}

input,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  padding: 11px 12px;
  outline: none;
}

input:focus,
select:focus {
  border-color: var(--accent);
}

.filter-stack {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  margin-bottom: 18px;
}

.category-list {
  display: grid;
  gap: 8px;
}

.category-list button {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 42px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  padding: 9px 10px;
  text-align: left;
}

.category-list button.active,
.category-list button:hover {
  background: var(--panel-2);
  border-color: var(--line);
  color: var(--text);
}

.category-list b {
  color: var(--accent);
  font-size: 0.78rem;
  white-space: nowrap;
}

.workspace {
  min-width: 0;
  padding: 24px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
}

.eyebrow,
.tag {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  border-radius: 999px;
  background: rgba(47, 182, 163, 0.14);
  color: var(--accent);
  padding: 4px 8px;
  font-size: 0.76rem;
  font-weight: 700;
}

.topbar h2 {
  margin-top: 6px;
  font-size: clamp(1.7rem, 3vw, 2.6rem);
}

.top-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.icon-button,
.controls button,
.language-tabs button {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  padding: 8px 12px;
}

.icon-button {
  min-width: 42px;
  font-size: 1.1rem;
}

.icon-button:hover,
.controls button:hover,
.language-tabs button:hover,
.language-tabs .active {
  border-color: var(--accent);
  color: var(--accent);
}

.layout-grid {
  display: grid;
  grid-template-columns: minmax(280px, 380px) minmax(0, 1fr);
  gap: 18px;
}

.catalog-panel,
.detail-panel,
.visual-card,
.learning-panel,
.code-section {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.catalog-panel {
  height: fit-content;
  max-height: calc(100vh - 142px);
  overflow: auto;
  padding: 16px;
}

.section-title,
.visual-header,
.code-toolbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  margin-bottom: 14px;
}

.section-title span {
  color: var(--muted);
  font-size: 0.84rem;
}

.algorithm-list {
  display: grid;
  gap: 10px;
}

.algorithm-card,
.placeholder-card {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  padding: 14px;
  text-align: left;
}

.algorithm-card {
  display: grid;
  gap: 14px;
}

.algorithm-card:hover,
.algorithm-card.active {
  border-color: var(--accent);
  background: var(--panel-2);
}

.algorithm-card h4,
.placeholder-card h4 {
  margin-top: 9px;
  font-size: 1rem;
}

.algorithm-card p,
.placeholder-card p {
  margin-top: 7px;
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.45;
}

.card-meta,
.meta-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.card-meta span,
.meta-row span,
.step-pill {
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  padding: 4px 8px;
  font-size: 0.76rem;
}

.detail-panel {
  min-width: 0;
  padding: 18px;
}

.hero-strip {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 18px;
  border-radius: 8px;
  background: var(--panel-2);
  margin-bottom: 18px;
}

.hero-strip h3 {
  max-width: 900px;
  margin-bottom: 12px;
  line-height: 1.35;
}

.visual-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 18px;
  align-items: start;
}

.visual-card,
.learning-panel,
.code-section {
  padding: 18px;
}

.visual-stage {
  display: grid;
  place-items: center;
  min-height: 350px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  overflow: hidden;
}

.bar-stage {
  display: flex;
  align-items: end;
  justify-content: center;
  gap: 9px;
  width: 100%;
  height: 310px;
  padding: 24px;
}

.bar-wrap {
  display: grid;
  align-items: end;
  justify-items: center;
  gap: 7px;
  height: 100%;
  min-width: 34px;
  max-width: 60px;
  flex: 1;
}

.bar-wrap b {
  color: var(--muted);
  font-size: 0.75rem;
}

.bar {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: end;
  width: 100%;
  border-radius: 8px 8px 4px 4px;
  background: var(--blue);
  color: #07111f;
  font-weight: 800;
  transition: height 220ms ease, background 180ms ease, transform 180ms ease;
  padding: 8px 4px;
}

.bar small {
  min-height: 16px;
  color: #07111f;
  font-size: 0.66rem;
  font-weight: 900;
}

.bar.compare,
.graph-node.queued {
  background: var(--accent-2);
}

.bar.swap,
.bar.found,
.graph-node.active,
.block.active,
.node-link.active span {
  background: var(--danger);
  transform: translateY(-6px);
}

.bar.sorted,
.graph-node.visited {
  background: var(--green);
}

.bar.active,
.bar.mid {
  background: var(--accent);
}

.bar.low,
.bar.high,
.bar.range {
  outline: 2px solid var(--accent-2);
}

.explain-panel {
  display: grid;
  gap: 12px;
  margin: 14px 0;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
}

.step-note {
  min-height: 32px;
  color: var(--muted);
  line-height: 1.5;
}

.state-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.state-summary span {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  color: var(--muted);
  padding: 7px 9px;
  font-size: 0.82rem;
}

.state-summary b {
  color: var(--text);
  margin-right: 4px;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  color: var(--muted);
  font-size: 0.78rem;
}

.legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.legend i {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  border: 1px solid var(--line);
  background: var(--panel);
}

.legend i.compare,
.legend i.queued {
  background: var(--accent-2);
}

.legend i.swap,
.legend i.found,
.legend i.active {
  background: var(--danger);
}

.legend i.sorted,
.legend i.visited {
  background: var(--green);
}

.legend i.range {
  border-color: var(--accent-2);
  background: transparent;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.speed {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 180px;
  color: var(--muted);
}

.speed input {
  padding: 0;
}

.progress-bar {
  height: 8px;
  margin: 14px 0;
  border-radius: 999px;
  background: var(--panel-2);
  overflow: hidden;
}

.progress-bar span {
  display: block;
  height: 100%;
  background: var(--accent);
  transition: width 180ms ease;
}

.input-row {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 0.86rem;
}

.learning-panel {
  display: grid;
  gap: 18px;
}

.learning-panel ol,
.learning-panel ul {
  margin: 10px 0 0;
  padding-left: 20px;
  color: var(--muted);
  line-height: 1.55;
}

.structure-row,
.node-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 24px;
}

.structure-row.stack {
  flex-direction: column-reverse;
}

.block,
.node-link span {
  display: grid;
  place-items: center;
  min-width: 70px;
  min-height: 54px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
  transition: transform 180ms ease, background 180ms ease;
}

.node-link span small {
  color: var(--muted);
  font-size: 0.68rem;
}

.block small {
  min-height: 14px;
  color: var(--muted);
  font-size: 0.7rem;
}

.node-link {
  display: flex;
  align-items: center;
  gap: 10px;
}

.node-link b,
.node-link em {
  color: var(--muted);
  font-style: normal;
}

.graph-stage,
.tree-stage {
  width: min(100%, 520px);
  max-height: 340px;
}

.queen-board {
  display: grid;
  width: min(86vw, 340px);
  aspect-ratio: 1;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.grid-cell {
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 0;
  border: 1px solid rgba(0, 0, 0, 0.1);
  color: #07111f;
  font-weight: 900;
  font-size: 1.25rem;
}

.grid-cell.light {
  background: #e7edf4;
}

.grid-cell.dark {
  background: #9fb3c8;
}

.grid-cell.queen {
  background: var(--green);
}

.grid-cell.active {
  outline: 3px solid var(--accent-2);
  outline-offset: -3px;
}

.grid-cell.conflict {
  background: var(--danger);
}

.edge {
  stroke: var(--line);
  stroke-width: 2;
}

.edge.active {
  stroke: var(--danger);
  stroke-width: 4;
}

.edge-label,
.distance-label {
  fill: var(--muted);
  font-size: 12px;
  text-anchor: middle;
}

.graph-node {
  fill: var(--panel-2);
  stroke: var(--line);
  stroke-width: 2;
  transition: fill 180ms ease;
}

.node-label {
  fill: var(--text);
  font-weight: 800;
  font-size: 13px;
  text-anchor: middle;
}

.code-section {
  margin-top: 18px;
}

.language-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: end;
}

pre {
  margin: 0;
  max-height: 520px;
  overflow: auto;
  border-radius: 8px;
  background: var(--code);
  color: #e5edf7;
  padding: 18px;
  line-height: 1.55;
  font-size: 0.9rem;
}

.kw {
  color: #7dd3fc;
}

.str {
  color: #facc15;
}

.num {
  color: #86efac;
}

.comment {
  color: #8b98a8;
}

.ad-slot {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 76px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: repeating-linear-gradient(135deg, transparent, transparent 10px, rgba(127, 148, 167, 0.06) 10px, rgba(127, 148, 167, 0.06) 20px);
  color: var(--muted);
  font-size: 0.76rem;
  overflow: hidden;
}

.ad-slot.is-configured {
  background: var(--panel);
}

.ad-slot.is-configured > span {
  position: absolute;
  top: 6px;
  left: 8px;
  z-index: 1;
  padding: 2px 5px;
  border-radius: 4px;
  background: var(--panel);
  opacity: 0.72;
}

.ad-slot.is-placeholder {
  padding: 12px;
  text-align: center;
}

.adsbygoogle {
  min-width: 100%;
}

.ad-sidebar {
  margin-top: 18px;
}

.ad-leaderboard {
  min-height: 92px;
  margin-bottom: 18px;
}

.ad-detail {
  min-height: 250px;
}

.empty-state {
  color: var(--muted);
  padding: 24px;
  text-align: center;
}

.organic-content,
.content-page {
  background: var(--bg);
  color: var(--text);
  border-top: 1px solid var(--line);
}

.organic-inner,
.content-page main,
.content-page > header:not(.site-header),
.content-page footer {
  width: min(1060px, calc(100% - 32px));
  margin: 0 auto;
}

.organic-inner {
  padding: 48px 0 56px;
}

.content-kicker {
  color: var(--accent);
  font-size: 0.82rem;
  font-weight: 800;
  text-transform: uppercase;
}

.organic-content h2,
.content-page h1,
.content-page h2 {
  margin-top: 10px;
  line-height: 1.2;
}

.organic-content p,
.content-page p,
.content-page li {
  color: var(--muted);
  line-height: 1.7;
}

.organic-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
  margin: 28px 0;
}

.organic-grid article,
.content-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 18px;
}

.topic-list {
  display: grid;
  gap: 10px;
  padding-left: 20px;
}

.content-page a {
  color: var(--accent);
}

.content-page > header:not(.site-header) {
  padding: 32px 0 18px;
}

.content-page main {
  display: grid;
  gap: 18px;
  padding: 20px 0 44px;
}

.content-page footer {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  padding: 22px 0 36px;
  border-top: 1px solid var(--line);
  color: var(--muted);
}

.content-page footer a {
  color: var(--muted);
}

@media (max-width: 1180px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .category-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .layout-grid,
  .visual-grid {
    grid-template-columns: 1fr;
  }

  .catalog-panel {
    max-height: none;
  }
}

@media (max-width: 720px) {
  .site-header {
    position: static;
    align-items: flex-start;
    flex-direction: column;
    padding: 14px 16px;
  }

  .main-menu {
    justify-content: start;
    width: 100%;
  }

  .main-menu a {
    padding: 7px 9px;
  }

  .workspace,
  .sidebar {
    padding: 16px;
  }

  .topbar,
  .section-title,
  .visual-header,
  .code-toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .top-actions,
  .language-tabs {
    justify-content: start;
  }

  .category-list {
    grid-template-columns: 1fr;
  }

  .bar-stage {
    gap: 5px;
    padding: 14px;
  }

  .bar-wrap {
    min-width: 24px;
  }

  .bar {
    font-size: 0.75rem;
  }

  .visual-stage {
    min-height: 280px;
  }

  .controls button {
    flex: 1;
  }

  .speed {
    width: 100%;
  }

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