/* Colors are protan-safe: blue for the room, vermilion for the result, amber
   for what gets cut. Each one also has a label or line style. */
:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --fg: #1a1d21;
  --muted: #5b6470;
  --border: #dde1e6;
  --grid: #e6e9ed;
  --accent: #0072b2;
  --accent-fg: #ffffff;
  --before: #0072b2;
  --after: #d55e00;
  --target: #8a939e;
  --boom: rgba(255, 176, 0, 0.4);
  --cut-line: #a86f00;
  --noise: #5b6470;
  --warn-bg: #fff4d6;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111418;
    --card: #1a1f25;
    --fg: #e8eaed;
    --muted: #9aa3ad;
    --border: #2c333b;
    --grid: #262c33;
    --accent: #56b4e9;
    --accent-fg: #0b1420;
    --before: #56b4e9;
    --after: #f08a4b;
    --target: #8a939e;
    --boom: rgba(255, 176, 0, 0.3);
    --cut-line: #ffb000;
    --noise: #9aa3ad;
    --warn-bg: #3a2f12;
  }
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
}

.page {
  max-width: 880px;
  margin: 0 auto;
  padding: 24px 16px 48px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

h1 {
  margin: 0 0 8px;
  font-size: 2rem;
  line-height: 1.2;
}

h2 {
  margin: 0 0 16px;
  font-size: 1.25rem;
  display: flex;
  align-items: center;
  gap: 12px;
}

.lede {
  margin: 0;
  color: var(--muted);
  font-size: 1.05rem;
}

.step {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-fg);
  font-size: 0.9rem;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
}

.muted {
  color: var(--muted);
}

.hint {
  margin: 16px 0;
  color: var(--muted);
  font-size: 0.95rem;
}

.credit {
  margin: 0;
  font-size: 0.85rem;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

.mode {
  border: 0;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.mode-option {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
}

.mode-option:has(input:checked) {
  border-color: var(--accent);
  box-shadow: inset 0 0 0 1px var(--accent);
}

.mode-option input {
  margin-top: 4px;
}

.mode-option > span {
  display: flex;
  flex-direction: column;
}

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

.btn {
  min-height: 44px;
  padding: 8px 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card);
  color: var(--fg);
  font: inherit;
  cursor: pointer;
}

.btn:disabled {
  opacity: 0.5;
  cursor: default;
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-fg);
  font-weight: 600;
}

.ab {
  display: inline-flex;
}

.ab-btn {
  min-width: 80px;
  border-radius: 0;
}

.ab-btn + .ab-btn {
  border-left: 0;
}

.ab-btn:first-child {
  border-radius: 8px 0 0 8px;
}

.ab-btn:last-child {
  border-radius: 0 8px 8px 0;
}

.ab-btn[aria-pressed="true"] {
  background: var(--fg);
  border-color: var(--fg);
  color: var(--card);
  font-weight: 600;
}

.progress {
  margin-top: 16px;
  height: 8px;
  border-radius: 4px;
  background: var(--grid);
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  width: 0;
  background: var(--accent);
}

.status {
  margin: 16px 0 0;
  min-height: 1.5em;
}

.status.warn {
  padding: 8px 12px;
  border-radius: 8px;
  background: var(--warn-bg);
}

.advanced {
  margin-top: 16px;
}

.advanced summary {
  cursor: pointer;
  color: var(--muted);
}

.legend {
  list-style: none;
  margin: 0 0 8px;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 4px 16px;
  font-size: 0.9rem;
}

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

.swatch {
  display: inline-block;
  width: 24px;
  height: 12px;
}

.swatch-before {
  border-top: 3px solid var(--before);
  height: 0;
}

.swatch-after {
  border-top: 3px solid var(--after);
  height: 0;
}

.swatch-target {
  border-top: 2px dashed var(--target);
  height: 0;
}

.swatch-noise {
  border-top: 2px dotted var(--noise);
  height: 0;
}

.swatch-boom {
  background: var(--boom);
  border: 1px solid var(--cut-line);
}

.chart {
  display: block;
  width: 100%;
  height: 280px;
  touch-action: pan-y;
}

.chart-short {
  height: 160px;
}

.chart-title {
  margin: 16px 0 8px;
  font-size: 1rem;
}

.readout {
  margin: 8px 0 16px;
  font-size: 0.9rem;
  min-height: 1.5em;
}

.controls {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin-bottom: 16px;
}

.control {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
}

.control-label {
  font-size: 0.9rem;
  color: var(--muted);
}

.control input[type="range"] {
  width: 100%;
  min-height: 44px;
}

.control select {
  min-height: 44px;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card);
  color: var(--fg);
  font: inherit;
}

.filters {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
}

.filters th,
.filters td {
  text-align: left;
  padding: 8px;
  border-bottom: 1px solid var(--border);
}

.filters th {
  font-size: 0.85rem;
  color: var(--muted);
  font-weight: 500;
}

.export {
  margin: 0 0 16px;
  padding: 12px 16px;
  border-radius: 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  font-size: 0.85rem;
  overflow-x: auto;
  white-space: pre;
}

.prose p {
  margin: 0 0 16px;
}

.prose p:last-child {
  margin-bottom: 0;
}

@media (min-width: 640px) {
  .page {
    padding: 48px 24px 64px;
  }

  .card {
    padding: 24px;
  }

  .mode {
    flex-direction: row;
  }

  .mode-option {
    flex: 1;
  }

  .controls {
    flex-direction: row;
    align-items: flex-end;
  }

  .chart {
    height: 320px;
  }

  .chart-short {
    height: 180px;
  }
}
