:root {
  --bg: #071018;
  --bg-elevated: #101a28;
  --bg-panel: rgba(16, 26, 40, 0.92);
  --line: rgba(148, 163, 184, 0.18);
  --text: #e8eef7;
  --muted: #93a4bb;
  --accent: #5eead4;
  --accent-2: #38bdf8;
  --compare: #fbbf24;
  --write: #c084fc;
  --pivot: #fb7185;
  --sorted: #34d399;
  --danger: #f87171;
  --shadow: 0 24px 60px rgba(0, 0, 0, 0.35);
  --radius: 18px;
  --bar-default: linear-gradient(180deg, #7dd3fc 0%, #2dd4bf 100%);
  --font: "IBM Plex Sans", system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background:
    radial-gradient(1200px 600px at 10% -10%, rgba(56, 189, 248, 0.16), transparent 50%),
    radial-gradient(900px 500px at 100% 0%, rgba(45, 212, 191, 0.12), transparent 46%),
    var(--bg);
  color: var(--text);
  font-family: var(--font);
}

button,
input {
  font: inherit;
}

button {
  appearance: none;
  -webkit-appearance: none;
}

.app {
  display: grid;
  grid-template-columns: minmax(260px, 320px) 1fr;
  grid-template-rows: auto minmax(0, 1fr);
  height: 100vh;
  height: 100dvh;
  max-height: 100vh;
  max-height: 100dvh;
  gap: 16px;
  padding: 16px;
  overflow: hidden;
}

.topbar {
  grid-column: 1 / -1;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 24px;
  padding: 0 4px;
  min-height: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-mark {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  object-fit: cover;
  border: 1px solid var(--line);
}

.eyebrow {
  margin: 0;
  color: var(--accent);
  font-size: 0.72rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  font-weight: 600;
}

h1 {
  margin: 2px 0 0;
  font-size: 1.35rem;
  letter-spacing: -0.03em;
}

.tagline {
  margin: 0;
  max-width: 420px;
  color: var(--muted);
  font-size: 0.95rem;
}

.panel,
.stage {
  background: var(--bg-panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
  min-height: 0;
}

.panel {
  padding: 16px 14px 14px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow: auto;
}

.panel h2 {
  margin: 0 0 10px;
  font-size: 0.78rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

.algo-card {
  margin-top: 0;
  padding: 14px;
  border-radius: 14px;
  background: #0b1522;
  border: 1px solid var(--line);
}

.algo-btn,
.btn {
  border: 1px solid var(--line);
  background: #0c1623;
  color: var(--text);
  border-radius: 12px;
  cursor: pointer;
  transition: transform 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}

.algo-btn {
  padding: 10px 8px;
  font-weight: 600;
}

.algo-btn:hover,
.btn:hover:not(:disabled) {
  border-color: rgba(94, 234, 212, 0.5);
  transform: translateY(-1px);
}

.algo-btn.is-active {
  background: linear-gradient(180deg, rgba(56, 189, 248, 0.22), rgba(45, 212, 191, 0.18));
  border-color: rgba(94, 234, 212, 0.7);
  color: #ecfeff;
}

.algo-card h3 {
  margin: 0 0 6px;
  font-size: 1rem;
}

.algo-card p {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.45;
}

.complexity {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin: 14px 0 0;
}

.complexity div {
  background: #101c2c;
  border-radius: 10px;
  padding: 8px 10px;
}

.complexity dt {
  color: var(--muted);
  font-size: 0.7rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.complexity dd {
  margin: 4px 0 0;
  font-family: var(--mono);
  font-size: 0.92rem;
}

.slider-field {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 0.9rem;
}

.slider-field:last-child {
  margin-bottom: 0;
}

.slider-field span {
  display: flex;
  justify-content: space-between;
}

.slider-field strong {
  color: var(--text);
  font-family: var(--mono);
  font-weight: 500;
}

input[type="range"] {
  appearance: none;
  height: 6px;
  border-radius: 999px;
  background: #1e2d42;
  outline: none;
}

input[type="range"]::-webkit-slider-thumb {
  appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid #042f2e;
  cursor: pointer;
}

.actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.btn {
  min-height: 42px;
  font-weight: 600;
}

.btn.primary {
  background: linear-gradient(180deg, #2dd4bf, #0ea5a4);
  color: #042f2e;
  border-color: transparent;
}

.btn.secondary {
  background: #152338;
}

.btn.ghost {
  background: transparent;
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.legend {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 10px;
  color: var(--muted);
  font-size: 0.85rem;
}

.legend li {
  display: flex;
  align-items: center;
  gap: 8px;
}

.swatch {
  width: 14px;
  height: 14px;
  border-radius: 4px;
}

.swatch.default {
  background: linear-gradient(180deg, #7dd3fc, #2dd4bf);
}
.swatch.compare {
  background: var(--compare);
}
.swatch.write {
  background: var(--write);
}
.swatch.pivot {
  background: var(--pivot);
}
.swatch.sorted {
  background: var(--sorted);
}
.swatch.reject {
  background: #334155;
}

.target-row {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
  display: flex;
  justify-content: space-between;
}

.target-row strong {
  color: var(--text);
  font-family: var(--mono);
}

.catalog-section {
  min-height: 0;
}

.catalog-hint {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.4;
}

.catalog {
  color: var(--muted);
  font-size: 0.8rem;
}

.catalog-group {
  margin-top: 10px;
}

.catalog-group:first-child {
  margin-top: 0;
}

.catalog-group strong {
  display: block;
  margin-bottom: 6px;
  color: var(--text);
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.chip-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.chip,
.chip-btn {
  appearance: none;
  -webkit-appearance: none;
  flex: 0 0 auto;
  width: auto;
  min-width: unset;
  height: 32px;
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0 12px;
  background: #0c1623;
  color: var(--text);
  font: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  line-height: 30px;
  cursor: pointer;
  white-space: nowrap;
}

.chip-btn.is-active,
.chip.ready.is-active,
.chip-btn:hover,
button.chip.ready:hover {
  border-color: rgba(94, 234, 212, 0.7);
  background: linear-gradient(180deg, rgba(56, 189, 248, 0.28), rgba(45, 212, 191, 0.2));
  color: #ecfeff;
}

.chip.planned {
  opacity: 0.45;
  cursor: default;
}

.stage {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.picker {
  flex-shrink: 0;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  background: #0d1724;
}

.picker-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.picker-row + .picker-row {
  margin-top: 8px;
}

.picker-label {
  flex: 0 0 78px;
  color: var(--muted);
  font-size: 0.7rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  font-weight: 600;
}

.family-tabs,
.algo-chips {
  flex: 1;
  min-width: 0;
}

.stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1px;
  background: var(--line);
  border-bottom: 1px solid var(--line);
}

.stat {
  background: #0d1724;
  padding: 10px 14px;
}

.stat span {
  display: block;
  color: var(--muted);
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.stat strong {
  display: block;
  margin-top: 4px;
  font-family: var(--mono);
  font-size: 1.2rem;
}

.progress {
  height: 4px;
  background: #152131;
}

.progress-bar {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--accent-2), var(--accent));
  transition: width 0.12s linear;
}

.bars {
  flex: 1;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 2px;
  padding: 16px 18px 18px;
  min-height: 0;
}

.viz {
  flex: 1;
  min-height: 0;
  display: flex;
}

.grid-view,
.tree-view,
.table-view,
.board-view {
  flex: 1;
  min-height: 0;
  min-width: 0;
}

.grid-view,
.board-view {
  display: grid;
  gap: 3px;
  padding: 14px;
}

.cell,
.square {
  min-width: 0;
  min-height: 0;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.65rem;
  font-family: var(--mono);
  background: #152033;
}

.cell.wall {
  background: #020617;
}
.cell.start,
.swatch.start {
  background: #2dd4bf;
  color: #042f2e;
}
.cell.end,
.swatch.end {
  background: #fb7185;
}
.cell.frontier,
.swatch.frontier {
  background: #38bdf8;
  color: #042f2e;
}
.cell.visit,
.swatch.visit {
  background: #475569;
}
.cell.path,
.swatch.path {
  background: #fbbf24;
  color: #111;
}

.tree-view svg {
  width: 100%;
  height: 100%;
}

.tree-view line {
  stroke: rgba(148, 163, 184, 0.4);
  stroke-width: 2;
}

.tree-node circle {
  fill: #152338;
  stroke: #5eead4;
  stroke-width: 2;
}

.tree-node text {
  fill: var(--text);
  font-size: 11px;
  text-anchor: middle;
  font-family: var(--mono);
}

.tree-node.active circle {
  fill: #fbbf24;
  stroke: #fbbf24;
}

.tree-node.visit circle {
  fill: #0e7490;
  stroke: #67e8f9;
}

.tree-node.found circle {
  fill: #34d399;
  stroke: #34d399;
}

.table-view {
  overflow: auto;
  padding: 12px;
}

.table-caption {
  margin: 0 0 10px;
  color: var(--muted);
  text-align: center;
}

.dp-table {
  border-collapse: collapse;
  margin: 0 auto;
  font-family: var(--mono);
}

.dp-table th,
.dp-table td {
  border: 1px solid var(--line);
  width: 34px;
  height: 34px;
  text-align: center;
}

.dp-table td.compare,
.dp-cell.compare {
  background: #fbbf24;
  color: #111;
}

.dp-table td.write,
.dp-cell.write {
  background: #7c3aed;
}

.dp-table td.found,
.dp-cell.found {
  background: #34d399;
  color: #042f2e;
}

.dp-row {
  display: flex;
  gap: 6px;
  overflow: auto;
}

.dp-cell {
  min-width: 48px;
  background: #152033;
  border-radius: 8px;
  padding: 6px;
  text-align: center;
}

.dp-cell span {
  display: block;
  color: var(--muted);
  font-size: 0.7rem;
}

.board-view {
  max-width: min(100%, 520px);
  margin: 0 auto;
  aspect-ratio: 1;
}

.square.light {
  background: #1e293b;
}
.square.dark {
  background: #0f172a;
}
.square.try {
  box-shadow: inset 0 0 0 2px #fbbf24;
}
.square.attack {
  background: #7f1d1d;
}
.square.place,
.square.solved,
.square.queen {
  background: #115e59;
  color: #5eead4;
  font-size: 1.3rem;
}

.bar {
  flex: 1;
  max-width: 28px;
  min-width: 3px;
  border-radius: 7px 7px 3px 3px;
  background: var(--bar-default);
  transform-origin: bottom;
  transition: background 0.08s linear, height 0.08s ease;
}

.bar.compare {
  background: var(--compare);
}
.bar.write {
  background: var(--write);
}
.bar.pivot {
  background: var(--pivot);
}
.bar.sorted {
  background: var(--sorted);
}
.bar.reject {
  background: #1e293b;
  opacity: 0.45;
}
.bar.found {
  background: var(--sorted);
}
.bar.window {
  background: var(--write);
}

@media (max-width: 900px) {
  .app {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(0, 1fr) auto;
    padding: 10px;
    gap: 10px;
  }

  .topbar {
    flex-direction: column;
    align-items: flex-start;
  }

  .panel {
    grid-row: 3;
    max-height: 34vh;
  }

  .picker-row {
    flex-direction: column;
    gap: 6px;
  }

  .picker-label {
    padding-top: 0;
  }

  .stage {
    grid-row: 2;
  }

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

  .stat {
    padding: 10px 12px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .bar,
  .algo-btn,
  .btn,
  .progress-bar {
    transition: none;
  }
}
