:root {
  --bg: #0b1220;
  --surface: #111a2f;
  --surface-alt: #16213d;
  --text: #e6edf8;
  --muted: #9aa7bd;
  --border: #253352;
  --accent: #06b6d4;
  --compare: #f97316;
  --swap: #22c55e;
  --done: #14b8a6;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: "Space Grotesk", "Segoe UI", sans-serif;
}

.container {
  width: min(1180px, 92vw);
  margin: 0 auto;
}

.header {
  padding: 1.5rem 0 0.8rem;
}

.back-link {
  color: var(--accent);
  text-decoration: none;
  font-weight: 700;
}

h1,
h2,
h3 {
  font-family: "Sora", sans-serif;
  margin: 0;
}

h1 {
  margin-top: 0.55rem;
  font-size: clamp(1.8rem, 3.4vw, 2.8rem);
}

.header p {
  margin: 0.45rem 0 0;
  color: var(--muted);
}

.grid {
  display: grid;
  grid-template-columns: 300px 1fr;
  gap: 1rem;
  padding-bottom: 2rem;
}

.panel {
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface);
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.35);
}

.controls-panel {
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
}

.controls-panel label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  color: var(--muted);
  font-size: 0.9rem;
}

select,
input,
button {
  font: inherit;
}

select,
input[type="range"] {
  width: 100%;
}

select,
input[type="text"] {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.45rem;
  background: var(--surface-alt);
  color: var(--text);
}

.buttons {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.45rem;
}

.preset-array-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.45rem;
}

.preset-array-btn {
  padding: 0.38rem 0.5rem;
  font-size: 0.82rem;
}

button {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-alt);
  color: var(--text);
  padding: 0.45rem 0.6rem;
  cursor: pointer;
  transition: transform 140ms ease, border-color 140ms ease;
}

button:hover {
  transform: translateY(-1px);
  border-color: #3f5f95;
}

button.primary {
  background: var(--accent);
  color: #052a31;
  border-color: transparent;
  font-weight: 700;
}

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
}

.status {
  margin: 0;
  font-size: 0.9rem;
  color: #c4d2e9;
  min-height: 2.1rem;
}

.scrubber {
  display: block;
  font-size: 0.92rem;
  color: #c4d2e9;
}

.scrubber input {
  margin-top: 0.45rem;
}

.visual-panel {
  padding: 0.9rem;
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  gap: 0.85rem;
}

.stats {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 0.55rem;
}

.stats article {
  background: rgba(7, 13, 28, 0.65);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.7rem;
}

.stats h3 {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.stats p {
  margin: 0.25rem 0 0;
  font-size: 1.35rem;
  font-weight: 700;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.8rem;
  font-size: 0.82rem;
  color: var(--muted);
}

.legend span {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.swatch {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  display: inline-block;
}

.swatch.default { background: #4a5775; }
.swatch.compare { background: var(--compare); }
.swatch.swap { background: var(--swap); }
.swatch.done { background: var(--done); }

.array-container {
  height: 450px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: rgba(7, 13, 28, 0.45);
  padding: 0.5rem;
  display: flex;
  align-items: flex-end;
  gap: 0.15rem;
}

.bar {
  flex: 1;
  min-width: 3px;
  background: #4a5775;
  border-radius: 5px 5px 0 0;
  transition: height 120ms linear, background-color 140ms ease;
}

.bar.compare {
  background: var(--compare);
}

.bar.swap {
  background: var(--swap);
}

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

.algo-note {
  color: var(--muted);
  font-size: 0.92rem;
  min-height: 1.2rem;
}

.comparison-panel {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: rgba(7, 13, 28, 0.55);
  padding: 0.8rem;
}

.diagnostics-panel {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: rgba(7, 13, 28, 0.55);
  padding: 0.8rem;
}

.diagnostics-grid {
  margin-top: 0.75rem;
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 0.55rem;
}

.diagnostics-grid article {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.7rem;
}

.diagnostics-grid h3 {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.diagnostics-grid p {
  margin: 0.25rem 0 0;
  font-size: 1.1rem;
  font-weight: 700;
}

.comparison-head {
  display: flex;
  justify-content: space-between;
  gap: 0.8rem;
  align-items: flex-start;
}

.comparison-head h2 {
  font-size: 1rem;
}

.comparison-head p {
  margin: 0.25rem 0 0;
  color: var(--muted);
  font-size: 0.84rem;
}

.comparison-summary {
  margin: 0;
  text-align: right;
  max-width: 26ch;
}

.comparison-summary-block {
  display: grid;
  gap: 0.45rem;
  justify-items: end;
}

.metric-select {
  width: min(220px, 100%);
}

.comparison-history-head {
  margin-top: 1rem;
}

.comparison-history-list {
  margin-top: 0.75rem;
  display: grid;
  gap: 0.6rem;
}

.comparison-history-item {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: rgba(7, 13, 28, 0.45);
  padding: 0.75rem 0.85rem;
}

.comparison-history-item p {
  margin: 0.2rem 0 0;
  color: var(--muted);
}

.table-wrap {
  overflow-x: auto;
  margin-top: 0.75rem;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  border-bottom: 1px solid rgba(37, 51, 82, 0.9);
  padding: 0.5rem 0.4rem;
  text-align: left;
}

th {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

td {
  font-size: 0.9rem;
  color: var(--text);
}

.empty-row {
  text-align: center;
  color: var(--muted);
}

.demo-strip {
  margin-top: 1rem;
  border: 1px solid rgba(114, 130, 179, 0.45);
  border-radius: 10px;
  background: rgba(125, 147, 255, 0.09);
  padding: 0.8rem 1rem;
  color: var(--muted);
}

.demo-strip strong {
  color: var(--text);
}

.teaching-cut-list {
  margin: 0.65rem 0 0;
  padding-left: 1.1rem;
  color: var(--muted);
  display: grid;
  gap: 0.35rem;
  font-size: 0.9rem;
}

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

  .array-container {
    height: 320px;
  }

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

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

  .comparison-head {
    flex-direction: column;
  }

  .comparison-summary-block {
    width: 100%;
    justify-items: stretch;
  }

  .comparison-summary {
    text-align: left;
    max-width: none;
  }

  .preset-array-row {
    grid-template-columns: 1fr;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
  }
}

/* Portfolio minimal mode: keep the core sorter workflow visible and hide narrative dashboard bloat. */
.visual-panel .diagnostics-panel {
  display: none;
}

.comparison-panel .comparison-history-head,
.comparison-panel .comparison-history-list,
.comparison-panel .diagnostics-panel {
  display: none;
}
