:root {
  --bg: #0f1419; --panel: #1a212b; --panel-border: #2a3441;
  --text: #e6edf3; --muted: #9aa7b4; --accent: #4cc2ff;
}
* { box-sizing: border-box; }
body {
  margin: 0; min-height: 100vh;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--text); line-height: 1.5;
}
header { padding: 26px 20px 10px; max-width: 1380px; margin: 0 auto; }
h1 { margin: 0 0 4px; font-size: 1.6rem; }
h2 { margin: 0 0 10px; font-size: 1.02rem; }
.muted { color: var(--muted); font-weight: 400; }
.small { font-size: 0.82rem; }
.crumbs { margin: 2px 0 0; font-size: 0.85rem; }
.crumbs a { color: var(--accent); text-decoration: none; }
.subtitle { color: var(--muted); max-width: 90ch; margin: 10px 0 0; }

main {
  max-width: 1380px; margin: 14px auto 0; padding: 0 20px;
  display: grid; grid-template-columns: 330px 1fr; gap: 16px;
  align-items: start;
}
.panel { background: var(--panel); border: 1px solid var(--panel-border); border-radius: 12px; padding: 18px; }
.viewport { padding: 0; overflow: hidden; height: min(76vh, 820px); position: sticky; top: 12px; }
.viewport canvas { width: 100%; height: 100%; display: block; }

.loading {
  position: absolute; inset: 0; z-index: 2;
  display: flex; flex-direction: column; gap: 10px; align-items: center; justify-content: center;
  background: var(--panel); color: var(--muted); font-size: 0.92rem; text-align: center; padding: 20px;
}
.loading .spin {
  width: 34px; height: 34px; border-radius: 50%;
  border: 3px solid var(--panel-border); border-top-color: var(--accent);
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.ctl { margin-bottom: 14px; }
.ctl label { display: block; font-size: 0.85rem; font-weight: 600; margin-bottom: 5px; }
.ctl .row { display: flex; gap: 10px; align-items: center; }
.ctl input[type="range"] { flex: 1; accent-color: var(--accent); }
.ctl input[type="number"], .ctl select {
  width: 86px; background: #0f1620; color: var(--text);
  border: 1px solid var(--panel-border); border-radius: 8px; padding: 6px 8px; font: inherit; font-size: 0.88rem;
}
.ctl select { width: auto; }
.check { display: inline-flex; align-items: center; gap: 7px; font-size: 0.85rem; font-weight: 600; }
.check input { accent-color: var(--accent); width: 15px; height: 15px; }

.cards { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat { background: #0f1620; border: 1px solid var(--panel-border); border-radius: 10px; padding: 10px 12px; }
.stat .v { font-size: 1.05rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat .l { color: var(--muted); font-size: 0.72rem; margin-top: 2px; }

.cutlist { width: 100%; border-collapse: collapse; font-size: 0.8rem; margin-bottom: 12px; }
.cutlist th {
  text-align: left; color: var(--muted); font-size: 0.72rem; font-weight: 600;
  padding: 4px 6px 4px 0; border-bottom: 1px solid var(--panel-border);
}
.cutlist td { padding: 6px 6px 6px 0; border-bottom: 1px solid var(--panel-border); vertical-align: top; }
.cutlist td.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.cutlist .note { font-size: 0.7rem; font-weight: 400; line-height: 1.35; margin-top: 1px; }
.sbars { display: flex; flex-direction: column; gap: 3px; margin: 7px 0 5px; }
.sbar { height: 5px; background: #0b1119; border: 1px solid var(--panel-border); border-radius: 3px; overflow: hidden; }
.sbar i { display: block; height: 100%; background: var(--accent); opacity: 0.75; }

.cutlist .grain { display: flex; flex-wrap: wrap; gap: 2px 9px; margin-top: 3px; font-size: 0.68rem; font-weight: 400; align-items: center; }
.cutlist .grain label { display: inline-flex; align-items: center; gap: 3px; cursor: pointer; color: var(--text); }
.cutlist .grain input { accent-color: var(--accent); width: 11px; height: 11px; margin: 0; }
.trim { display: inline-flex; align-items: center; gap: 6px; font-size: 0.82rem; color: var(--muted); font-weight: 600; white-space: nowrap; }
.trim input { width: 58px !important; }
.nestnums { margin-top: 8px; }
.btns { display: flex; gap: 8px; }
.btns .btn { flex: 1; width: auto; }
.btn {
  width: 100%; background: #0f1620; color: var(--accent); font: inherit; font-size: 0.85rem;
  font-weight: 600; border: 1px solid var(--panel-border); border-radius: 8px;
  padding: 8px 12px; cursor: pointer; transition: border-color .15s;
}
.btn:hover { border-color: var(--accent); }
.btn:disabled { opacity: 0.55; cursor: wait; }

footer { max-width: 1380px; margin: 0 auto; padding: 18px 20px 44px; color: var(--muted); font-size: 0.85rem; }
footer a, footer code { color: var(--accent); }

@media (max-width: 900px) {
  main { grid-template-columns: 1fr; }
  /* relative (not static) so the loading overlay stays anchored to the viewport */
  .viewport { position: relative; top: 0; height: 60vh; order: -1; }
}
