/* Gomory Slicer. Layout: title bar, then the 3D stage with its action bar beside a column of cards; the column drops below the stage on narrow screens. */
:root {
  color-scheme: dark;
  --bg: #0b0f19;
  --panel: #111726;
  --panel-2: #172033;
  --line: #222c42;
  --line-2: #2f3b57;
  --fg: #e3e8f2;
  --muted: #8d98b0;
  --dim: #5d6882;
  --amber: #f59e0b;
  --cyan: #06b6d4;
  --emerald: #10b981;
  --crimson: #ef4444;
  --blue: #60a5fa;
  --display: "Literata", "Iowan Old Style", Georgia, serif;
  --sans: "Instrument Sans", "Segoe UI", system-ui, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;
  --r: 6px;
}
[hidden] { display: none !important; }
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--fg); font: 14px/1.45 var(--sans); }
button, select, input { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--cyan); outline-offset: 2px; }

.app { display: grid; gap: 12px; padding-block: 12px 20px;
  padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }
.top { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 12px 24px; }
.eyebrow { font: 500 11px/1.2 var(--mono); letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
h1 { margin: 4px 0 0; font: 600 24px/1.15 var(--display); text-wrap: balance; }
h1 span { display: block; margin-top: 3px; font: 400 13px/1.3 var(--sans); color: var(--muted); }
.controls { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.lbl { font: 500 11px var(--mono); letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
select, .btn { background: var(--panel-2); border: 1px solid var(--line-2); border-radius: var(--r); padding: 6px 10px; min-height: 34px; }
select { max-width: 100%; }
.btn { display: inline-flex; align-items: center; gap: 7px; cursor: pointer; transition: border-color .15s, background .15s; white-space: nowrap; }
.btn:hover:not(:disabled) { border-color: var(--cyan); }
.btn:disabled { opacity: .4; cursor: default; }
.btn svg { width: 15px; height: 15px; flex: none; }
.btn.primary { background: rgba(6,182,212,.14); border-color: rgba(6,182,212,.55); color: #67e8f9; font-weight: 600; }
.btn.sm { min-height: 28px; padding: 3px 9px; font-size: 12px; }
.btn.on { border-color: var(--cyan); color: #67e8f9; }
.note { margin: 0; font-size: 13.5px; color: #c7cfdf; max-width: 120ch; }

.main { display: grid; grid-template-columns: minmax(0, 1fr) 360px; grid-template-areas: "stage side" "deriv side"; grid-template-rows: auto 1fr; gap: 12px; align-items: start; }
.stage-col { grid-area: stage; } .side { grid-area: side; } .deriv { grid-area: deriv; }
.deriv .math { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); column-gap: 14px; }
.deriv .math .why { grid-column: 1 / -1; }
.stage-col { display: grid; gap: 10px; min-width: 0; }
.stage { position: relative; height: clamp(420px, 68vh, 640px); border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: radial-gradient(120% 90% at 50% 40%, #111a2c 0%, var(--bg) 70%); }
.stage canvas { display: block; width: 100%; height: 100%; touch-action: none; }
.views { position: absolute; top: 10px; left: 10px; display: flex; flex-wrap: wrap; gap: 6px; max-width: calc(100% - 20px); }
.views .btn { background: rgba(17,23,38,.82); backdrop-filter: blur(4px); min-height: 28px; padding: 3px 10px; font-size: 12px; }
.legend { position: absolute; left: 10px; bottom: 10px; display: flex; flex-wrap: wrap; gap: 4px 12px; font: 11px var(--mono); color: var(--muted); background: rgba(11,15,25,.72); padding: 6px 9px; border-radius: 6px; max-width: calc(100% - 20px); pointer-events: none; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.bar { width: 14px; height: 3px; border-radius: 2px; display: inline-block; }
.amber { background: var(--amber); } .blue { background: var(--blue); } .emerald { background: var(--emerald); } .cyan { background: var(--cyan); } .white { background: #e5e7eb; }
.hint { position: absolute; right: 10px; top: 12px; font: 11px var(--mono); color: var(--dim); pointer-events: none; }

.actionbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); padding: 10px 12px; }
.status { display: inline-flex; align-items: center; gap: 8px; font: 700 11.5px var(--mono); letter-spacing: .05em; text-transform: uppercase; padding: 6px 10px; border-radius: 4px; border: 1px solid var(--line-2); }
.status i { width: 8px; height: 8px; border-radius: 50%; background: var(--amber); box-shadow: 0 0 8px var(--amber); }
.status.cut { color: #6ee7b7; border-color: rgba(16,185,129,.5); }
.status.cut i { background: var(--emerald); box-shadow: 0 0 8px var(--emerald); }
.status.busy i { background: var(--cyan); box-shadow: 0 0 8px var(--cyan); }
.prog { flex: 1 1 120px; height: 4px; border-radius: 2px; background: var(--line-2); overflow: hidden; min-width: 80px; }
.prog b { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--cyan), var(--emerald)); }

.side { display: grid; gap: 12px; min-width: 0; }
.card { border: 1px solid var(--line); border-radius: 8px; background: var(--panel); padding: 12px 14px; display: grid; gap: 10px; min-width: 0; }
.sec-h { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin: 0; font: 500 11px var(--mono); letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.sec-h em { font-style: normal; text-transform: none; letter-spacing: 0; color: var(--dim); }
.field { display: grid; gap: 4px; }
.field > span { display: flex; justify-content: space-between; font: 500 11px var(--mono); letter-spacing: .04em; color: var(--muted); }
.field > span output { color: var(--fg); font-variant-numeric: tabular-nums; }
input[type=range] { -webkit-appearance: none; appearance: none; width: 100%; background: transparent; height: 18px; margin: 0; }
input[type=range]::-webkit-slider-runnable-track { height: 4px; border-radius: 2px; background: var(--line-2); }
input[type=range]::-moz-range-track { height: 4px; border-radius: 2px; background: var(--line-2); }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 14px; height: 14px; margin-top: -5px; border-radius: 50%; background: var(--cyan); border: 2px solid var(--bg); box-shadow: 0 0 0 1px var(--cyan); }
input[type=range]::-moz-range-thumb { width: 12px; height: 12px; border-radius: 50%; background: var(--cyan); border: 2px solid var(--bg); }
.switch { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; font-size: 13px; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch i { width: 32px; height: 18px; border-radius: 9px; background: var(--line-2); position: relative; transition: background .15s; flex: none; }
.switch i::after { content: ""; position: absolute; left: 3px; top: 3px; width: 12px; height: 12px; border-radius: 50%; background: var(--fg); transition: transform .15s; }
.switch input:checked + i { background: var(--cyan); }
.switch input:checked + i::after { transform: translateX(14px); }
.switch:has(input:focus-visible) { outline: 2px solid var(--cyan); outline-offset: 2px; border-radius: 4px; }
.read { margin: 0; font: 12px/1.5 var(--mono); color: #c3cbdb; }
.read b { font-weight: 600; }
.sliders { display: grid; gap: 8px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { font: 12px var(--sans); padding: 4px 10px; border-radius: 999px; border: 1px dashed var(--line-2); background: none; cursor: pointer; }
.chip:hover { border-color: var(--cyan); color: #67e8f9; }

.cmp { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.cmp > div { border: 1px solid var(--line-2); border-radius: 6px; padding: 9px 10px; display: grid; gap: 4px; align-content: start; transition: border-color .3s, background .3s; }
.cmp > div.active { background: var(--panel-2); }
.cmp h4 { margin: 0; font: 600 12.5px var(--sans); }
.cmp .kv { font: 12px/1.45 var(--mono); color: var(--muted); }
.cmp .kv b { color: var(--fg); font-weight: 500; display: block; word-break: break-word; }
.tag { justify-self: start; font: 700 10.5px/1.3 var(--mono); letter-spacing: .03em; padding: 3px 6px; border-radius: 4px; margin-top: 2px; }
.tag.bad { color: #fbbf24; background: rgba(245,158,11,.12); border: 1px solid rgba(245,158,11,.45); }
.tag.good { color: #6ee7b7; background: rgba(16,185,129,.12); border: 1px solid rgba(16,185,129,.45); }

.checks { display: grid; gap: 4px; font: 12px var(--mono); }
.checks .row { display: grid; grid-template-columns: auto 1fr auto; gap: 8px; align-items: center; padding: 4px 6px; border-radius: 4px; }
.checks .row svg { width: 13px; height: 13px; }
.checks .ok { color: #a7f3d0; } .checks .ok svg { color: var(--emerald); }
.checks .bad { color: #fecaca; background: rgba(239,68,68,.1); } .checks .bad svg { color: var(--crimson); }
.checks .row.cutrow { border-top: 1px dashed var(--line-2); margin-top: 2px; }
.checks .row.off { opacity: .55; }
.checks .verdict { margin-top: 4px; font: 600 12px var(--sans); }
.checks .num { font-variant-numeric: tabular-nums; color: var(--muted); }

.deriv summary { list-style: none; display: flex; align-items: center; justify-content: space-between; cursor: pointer; gap: 8px; }
.deriv summary::-webkit-details-marker { display: none; }
.deriv summary svg { width: 15px; height: 15px; color: var(--muted); transition: transform .2s; flex: none; }
.deriv[open] summary svg { transform: rotate(180deg); }
.deriv summary .sec-h { flex: 1; }
.math { display: grid; gap: 6px; }
.math .eq { font: 500 13.5px/1.5 var(--display); font-style: italic; background: #0d1322; border: 1px solid var(--line); border-left: 3px solid var(--line-2); border-radius: 4px; padding: 6px 10px; overflow-x: auto; white-space: nowrap; }
.math .eq.final { border-left-color: var(--cyan); color: #a5f3fc; }
.math .eq.frac { border-left-color: var(--amber); }
.math .why { font-size: 12.5px; color: var(--muted); margin: 0; }
.math sub { font-size: .72em; }

@media (max-width: 1060px) {
  .main { grid-template-columns: minmax(0, 1fr); grid-template-areas: "stage" "side" "deriv"; grid-template-rows: auto; }
  .side { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
}
@media (max-width: 560px) {
  h1 { font-size: 20px; }
  .stage { height: 440px; }
  .hint { display: none; }
  .legend { font-size: 10px; gap: 3px 9px; }
  .side { grid-template-columns: minmax(0, 1fr); }
  .controls, .controls select { width: 100%; }
}
.pg-embedded .top > div:first-child { display: none; }
.pg-embedded .top { justify-content: flex-start; }
@media (prefers-reduced-motion: reduce) { .btn, .switch i, .switch i::after, .deriv summary svg { transition: none; } }
