:root {
  --bg: #0a0d12;
  --panel: #11161e;
  --panel2: #161d27;
  --line: #232c3a;
  --fg: #e6ecf5;
  --dim: #8b98ab;
  --accent: #ffa500;
  --accent2: #4ea1ff;
  --warn: #ff5f56;
  --ok: #3ddc84;
  --r: 10px;
}

* { box-sizing: border-box; }

/* An author `display` rule beats the UA stylesheet's [hidden]{display:none} whatever
   its specificity, so any element we style with display:flex would ignore its own
   hidden attribute. Make hidden authoritative. */
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 15px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overflow: hidden;
}

/* ---------- top bar ---------- */
.topbar {
  display: flex; align-items: center; gap: 16px;
  padding: 10px 16px;
  background: linear-gradient(180deg, #131a24, #0e131a);
  border-bottom: 1px solid var(--line);
  height: 54px;
}
.brand { font-weight: 650; letter-spacing: .2px; white-space: nowrap; }
.brand .mark { margin-right: 6px; }
.tagline { color: var(--dim); font-size: 13px; flex: 1; min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- layout ---------- */
main { display: flex; height: calc(100% - 54px); }
.panel {
  width: 336px; flex: none; overflow-y: auto;
  background: var(--panel); border-right: 1px solid var(--line);
  padding: 14px;
}
.stage { position: relative; flex: 1; min-width: 0; }
canvas#view { width: 100%; height: 100%; display: block; touch-action: none; }

/* ---------- blocks ---------- */
.block { margin-bottom: 22px; }
.block h2 {
  font-size: 11px; text-transform: uppercase; letter-spacing: .09em;
  color: var(--dim); margin: 0 0 10px; font-weight: 650;
}

/* ---------- drop zone ---------- */
.drop {
  border: 1.5px dashed var(--line); border-radius: var(--r);
  padding: 18px 14px; text-align: center; background: var(--panel2);
  transition: border-color .15s, background .15s;
}
.drop.over { border-color: var(--accent); background: #1d2432; }
.drop p { margin: 4px 0; }
.dim { color: var(--dim); }
.tiny { font-size: 12px; line-height: 1.45; }
code { background: #0c1119; padding: 1px 5px; border-radius: 4px; font-size: 12px; }

.demos { margin-top: 12px; }
.demo-row { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }

.fileinfo {
  margin-top: 12px; padding: 10px; border-radius: var(--r);
  background: var(--panel2); border: 1px solid var(--line); font-size: 13px;
}
.fileinfo b { color: var(--accent); }

/* ---------- controls ---------- */
.ctl { margin-bottom: 15px; }
.ctl label {
  display: flex; justify-content: space-between; align-items: baseline;
  font-size: 13px; margin-bottom: 5px; gap: 8px;
}
.ctl output { color: var(--accent); font-variant-numeric: tabular-nums; font-weight: 600; }
.helptext { margin: 5px 0 0; }

input[type=range] {
  width: 100%; appearance: none; height: 4px; border-radius: 3px;
  background: var(--line); outline: none;
}
input[type=range]::-webkit-slider-thumb {
  appearance: none; width: 15px; height: 15px; border-radius: 50%;
  background: var(--accent); cursor: pointer; border: 2px solid #0a0d12;
}
input[type=range]::-moz-range-thumb {
  width: 15px; height: 15px; border-radius: 50%; background: var(--accent);
  cursor: pointer; border: 2px solid #0a0d12;
}

.switch { display: flex; align-items: center; gap: 9px; font-size: 14px; cursor: pointer; }
.switch input { width: 16px; height: 16px; accent-color: var(--accent); cursor: pointer; }

.row { display: flex; gap: 8px; margin-top: 14px; }
.row > * { flex: 1; }

button {
  font: inherit; font-size: 13px; border-radius: 8px; padding: 8px 12px;
  cursor: pointer; border: 1px solid var(--line); transition: background .15s, border-color .15s;
}
button.primary { background: var(--accent); color: #201400; border-color: var(--accent); font-weight: 600; }
button.primary:hover { background: #ffb733; }
button.ghost { background: var(--panel2); color: var(--fg); }
button.ghost:hover { border-color: var(--accent); }
button.chip {
  background: var(--panel2); color: var(--fg); padding: 5px 10px; font-size: 12px;
}
button.chip:hover { border-color: var(--accent); color: var(--accent); }
button:disabled { opacity: .45; cursor: not-allowed; }

.warn {
  margin-top: 10px; padding: 10px; border-radius: 8px; font-size: 12.5px;
  background: #2a1512; border: 1px solid #66302a; color: #ffbdb6; line-height: 1.5;
}
.warn b { color: var(--warn); }
.warn .num { font-variant-numeric: tabular-nums; }

/* ---------- stage overlays ---------- */
.hint {
  position: absolute; left: 14px; bottom: 12px; color: var(--dim);
  font-size: 12px; pointer-events: none; text-shadow: 0 1px 3px #000;
}
.busy {
  position: absolute; top: 14px; left: 50%; transform: translateX(-50%);
  background: rgba(17,22,30,.94); border: 1px solid var(--line);
  padding: 7px 14px; border-radius: 20px; font-size: 13px;
  display: flex; align-items: center; gap: 8px;
}
.spin {
  width: 12px; height: 12px; border: 2px solid var(--line);
  border-top-color: var(--accent); border-radius: 50%;
  animation: spin .7s linear infinite; display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

.results {
  position: absolute; top: 14px; right: 14px;
  background: rgba(17,22,30,.93); border: 1px solid var(--line);
  border-radius: var(--r); padding: 12px 14px; min-width: 190px;
  backdrop-filter: blur(8px);
}
.stat { display: flex; justify-content: space-between; gap: 16px; padding: 3px 0; font-size: 13px; }
.stat .k { color: var(--dim); }
.stat .v { font-variant-numeric: tabular-nums; font-weight: 600; }
.stat.big { border-top: 1px solid var(--line); border-bottom: 1px solid var(--line);
  margin: 6px 0; padding: 8px 0; }
.stat.big .v { color: var(--accent); font-size: 19px; }
.stat.big .k em { font-style: normal; color: var(--fg); }

.taper {
  position: absolute; right: 14px; bottom: 14px; margin: 0;
  background: rgba(17,22,30,.93); border: 1px solid var(--line);
  border-radius: var(--r); padding: 8px 10px; width: 210px;
  backdrop-filter: blur(8px);
}
.taper figcaption { font-size: 11px; color: var(--dim); margin-bottom: 4px; }
canvas#taper { width: 100%; height: 120px; display: block; }

/* ---------- dialog ---------- */
dialog {
  max-width: 620px; border: 1px solid var(--line); border-radius: 14px;
  background: var(--panel); color: var(--fg); padding: 26px; line-height: 1.65;
}
dialog::backdrop { background: rgba(0,0,0,.66); }
dialog h2 { margin-top: 0; }
dialog h3 { margin: 22px 0 6px; font-size: 15px; color: var(--accent); }
dialog p { margin: 9px 0; }
dialog a { color: var(--accent2); }
dialog form { margin-top: 20px; text-align: right; }

/* ---------- responsive ---------- */
@media (max-width: 860px) {
  body { overflow: auto; }
  main { flex-direction: column-reverse; height: auto; }
  .panel { width: 100%; border-right: none; border-top: 1px solid var(--line); max-height: none; }
  .stage { height: 62vh; min-height: 340px; }
  .tagline { display: none; }
  .taper { display: none; }
  .results { top: auto; bottom: 12px; right: 12px; min-width: 0; padding: 9px 11px; }
  .results .stat:not(.big) { display: none; }
}
