:root {
  color-scheme: dark;
  --bg: #07110e;
  --panel: #0d1a16;
  --panel-2: #101f1a;
  --line: rgba(176, 219, 199, 0.14);
  --text: #ebf7f1;
  --muted: #8ca79a;
  --green: #70f2aa;
  --green-hot: #c7ffd9;
  --amber: #ffd373;
  --radius: 20px;
}

* { box-sizing: border-box; }
html { background: var(--bg); }
body {
  margin: 0;
  min-width: 320px;
  background:
    radial-gradient(circle at 77% 10%, rgba(44, 126, 85, .13), transparent 33rem),
    linear-gradient(180deg, #08130f 0%, #050b09 100%);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  min-height: 100vh;
}

button, input, select { font: inherit; }
button { color: inherit; }
.app-shell { width: min(1240px, calc(100% - 40px)); margin: 0 auto; padding: 30px 0 70px; }
.masthead { display: flex; justify-content: space-between; align-items: center; padding-bottom: 28px; border-bottom: 1px solid var(--line); }
.eyebrow, .kicker { margin: 0 0 7px; color: var(--green); text-transform: uppercase; font-size: 10px; line-height: 1; letter-spacing: .22em; font-weight: 800; }
h1 { margin: 0; font-family: Georgia, serif; font-size: 24px; font-weight: 500; letter-spacing: -.04em; }
h1 span { color: var(--green); font-style: italic; }
.status-pill { padding: 9px 13px; color: var(--muted); border: 1px solid var(--line); border-radius: 100px; font-size: 11px; letter-spacing: .04em; }
.status-pill i { display: inline-block; width: 7px; height: 7px; margin-right: 8px; border-radius: 50%; background: var(--green); box-shadow: 0 0 10px var(--green); }

.hero { display: grid; grid-template-columns: .78fr 1.22fr; gap: clamp(40px, 8vw, 100px); align-items: center; min-height: 570px; padding: 65px 3%; }
.intro h2 { max-width: 520px; margin: 0; font-family: Georgia, serif; font-size: clamp(42px, 5vw, 70px); line-height: .98; letter-spacing: -.055em; font-weight: 400; }
.lede { max-width: 450px; margin: 28px 0 0; color: var(--muted); font-size: 16px; line-height: 1.7; }
.scope-wrap { width: 100%; }
.scope-bezel { position: relative; aspect-ratio: 3 / 2; overflow: hidden; border: 1px solid #293a32; border-radius: 38px; background: #010705; box-shadow: 0 28px 80px rgba(0,0,0,.45), inset 0 0 0 10px #0b1511, inset 0 0 0 12px #26332e; }
.scope-bezel::before { content: ""; position: absolute; inset: 12px; z-index: 2; pointer-events: none; border-radius: 29px; box-shadow: inset 0 0 50px rgba(0,0,0,.8); }
#scopeCanvas { display: block; width: 100%; height: 100%; }
.scope-readout { position: absolute; z-index: 3; inset: auto 34px 26px; display: flex; justify-content: space-between; color: rgba(135, 245, 180, .58); font: 10px ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: .13em; }
.scope-caption { margin: 15px 0 0; color: #51685d; text-align: center; font-size: 9px; letter-spacing: .12em; }

.panel { border: 1px solid var(--line); border-radius: var(--radius); background: linear-gradient(145deg, rgba(17,34,28,.96), rgba(9,20,16,.96)); box-shadow: 0 18px 50px rgba(0,0,0,.18); }
.workbench { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.source-panel, .controls-panel { min-height: 410px; padding: 28px; }
.panel-heading { display: flex; align-items: center; justify-content: space-between; margin-bottom: 26px; }
.panel-heading > div, .output-copy { display: flex; align-items: center; gap: 13px; }
.step { display: grid; place-items: center; flex: 0 0 auto; width: 29px; height: 29px; border: 1px solid rgba(112,242,170,.35); border-radius: 50%; color: var(--green); font: 10px ui-monospace, monospace; }
h3 { margin: 0; font-family: Georgia, serif; font-size: 23px; font-weight: 400; letter-spacing: -.02em; }
.text-button { padding: 5px 0; border: 0; border-bottom: 1px solid rgba(112,242,170,.35); background: none; color: var(--green); cursor: pointer; font-size: 11px; }
.text-button:hover { color: var(--green-hot); }

.drop-zone { display: flex; min-height: 220px; flex-direction: column; align-items: center; justify-content: center; border: 1px dashed rgba(112,242,170,.28); border-radius: 15px; background: rgba(68,143,103,.035); text-align: center; cursor: pointer; transition: .2s ease; }
.drop-zone:hover, .drop-zone.dragging { border-color: var(--green); background: rgba(112,242,170,.07); transform: translateY(-1px); }
.drop-zone input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.upload-icon { display: grid; place-items: center; width: 48px; height: 48px; margin-bottom: 17px; border: 1px solid var(--line); border-radius: 50%; }
.upload-icon svg { width: 25px; fill: none; stroke: var(--green); stroke-width: 1.4; }
.drop-zone strong { font-family: Georgia, serif; font-size: 20px; font-weight: 400; }
.drop-zone > span:last-child { margin-top: 8px; color: var(--muted); font-size: 11px; }
.file-card { display: flex; align-items: center; gap: 13px; margin-top: 13px; padding: 10px; border: 1px solid var(--line); border-radius: 12px; }
.hidden { display: none !important; }
.file-thumb { display: grid; place-items: center; width: 51px; height: 43px; overflow: hidden; border-radius: 7px; background: #07100d; }
.file-thumb svg { width: 85%; height: 85%; }
.file-thumb svg * { fill: none !important; stroke: var(--green) !important; stroke-width: 2 !important; }
.file-thumb img { width: 100%; height: 100%; object-fit: contain; image-rendering: pixelated; }
.file-info { display: flex; min-width: 0; flex: 1; flex-direction: column; gap: 4px; }
.file-info strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; }
.file-info span { color: var(--muted); font-size: 10px; }
.file-card button { border: 0; background: none; color: var(--muted); cursor: pointer; font-size: 22px; }
.message { min-height: 17px; margin-top: 13px; color: var(--muted); font-size: 11px; }
.message.error { color: #ff9c8f; }
.gallery { margin-top: 22px; padding-top: 18px; border-top: 1px solid var(--line); }
.gallery-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.gallery-heading h4 { margin: 0 0 5px; color: #d7e7df; font: 650 11px ui-sans-serif, system-ui, sans-serif; }
.gallery-heading small, .gallery-heading > span, .gallery-empty { color: var(--muted); font-size: 9px; line-height: 1.4; }
.gallery-heading > span { flex: 0 0 auto; color: var(--green); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.gallery-empty { margin: 15px 0 0; }
.gallery-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; margin-top: 14px; }
.gallery-item { position: relative; display: flex; min-width: 0; align-items: center; gap: 9px; padding: 8px 34px 8px 8px; border: 1px solid var(--line); border-radius: 10px; background: rgba(2,11,7,.36); }
.gallery-open { display: flex; min-width: 0; flex: 1; align-items: center; gap: 9px; padding: 0; border: 0; background: transparent; color: inherit; cursor: pointer; text-align: left; }
.gallery-thumb { flex: 0 0 auto; width: 42px; height: 36px; overflow: hidden; border-radius: 6px; background: #020b07; }
.gallery-thumb img { width: 100%; height: 100%; object-fit: contain; image-rendering: pixelated; }
.gallery-copy { min-width: 0; }
.gallery-copy strong, .gallery-copy small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gallery-copy strong { color: #d7e7df; font-size: 10px; font-weight: 650; }
.gallery-copy small { margin-top: 4px; color: var(--muted); font-size: 8px; }
.gallery-delete { position: absolute; top: 50%; right: 8px; width: 24px; height: 24px; padding: 0; transform: translateY(-50%); border: 0; border-radius: 6px; background: transparent; color: var(--muted); cursor: pointer; font-size: 17px; }
.gallery-delete:hover, .gallery-delete:focus-visible { background: rgba(255,156,143,.1); color: #ff9c8f; }

.control-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 23px 18px; }
.control { display: flex; flex-direction: column; gap: 9px; }
.control.full { grid-column: 1 / -1; }
.control > span, .toggle-control b { display: flex; justify-content: space-between; color: #d7e7df; font-size: 11px; font-weight: 650; }
.control output { color: var(--green); font: 11px ui-monospace, monospace; }
.control small, .toggle-control small { color: var(--muted); font-size: 9px; line-height: 1.4; }
input[type="range"] { width: 100%; height: 3px; appearance: none; border-radius: 10px; background: linear-gradient(90deg, var(--green) var(--range-progress, 22%), rgba(255,255,255,.12) var(--range-progress, 22%)); outline: none; }
input[type="range"]::-webkit-slider-thumb { width: 14px; height: 14px; appearance: none; border: 3px solid #0c1b15; border-radius: 50%; background: var(--green); box-shadow: 0 0 0 1px var(--green); cursor: pointer; }
select { width: 100%; padding: 11px 12px; border: 1px solid var(--line); border-radius: 9px; appearance: none; background: #0a1511 url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14'%3E%3Cpath d='m3 5 4 4 4-4' fill='none' stroke='%238ca79a'/%3E%3C/svg%3E") no-repeat right 10px center; color: var(--text); font-size: 11px; }
.toggle-control { display: flex; align-items: center; justify-content: space-between; align-self: end; min-height: 38px; }
.toggle-control span { display: flex; flex-direction: column; gap: 3px; }
.toggle-control input { position: absolute; opacity: 0; }
.toggle-control i { position: relative; width: 40px; height: 22px; border-radius: 20px; background: #23322b; transition: .2s; cursor: pointer; }
.toggle-control i::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #869b91; transition: .2s; }
.toggle-control input:checked + i { background: rgba(112,242,170,.25); }
.toggle-control input:checked + i::after { left: 21px; background: var(--green); }
.gif-controls { display: grid; grid-column: 1 / -1; grid-template-columns: 1fr 1fr; gap: 20px 18px; margin: 2px -8px -8px; padding: 20px; border: 1px solid rgba(255,211,115,.18); border-radius: 13px; background: rgba(255,211,115,.025); }
.gif-controls-priority { margin: 0 0 26px; }
.gif-controls-heading { display: flex; grid-column: 1 / -1; justify-content: space-between; padding-bottom: 11px; border-bottom: 1px solid var(--line); }
.gif-controls-heading span { color: var(--amber); font: 10px ui-monospace, monospace; letter-spacing: .12em; text-transform: uppercase; }
.gif-controls-heading small { color: var(--muted); font-size: 9px; }

.output-panel { display: flex; justify-content: space-between; align-items: center; gap: 30px; margin-top: 18px; padding: 23px 28px; }
.output-copy p { margin: 5px 0 0; color: var(--muted); font-size: 11px; }
.actions { display: flex; gap: 10px; }
.button { display: inline-flex; align-items: center; justify-content: center; gap: 9px; min-width: 145px; padding: 13px 18px; border-radius: 10px; cursor: pointer; font-size: 11px; font-weight: 750; letter-spacing: .02em; }
.button:disabled { opacity: .35; cursor: not-allowed; }
.button.secondary { border: 1px solid var(--line); background: #0c1814; }
.button.primary { border: 1px solid var(--green); background: var(--green); color: #07110d; box-shadow: 0 0 25px rgba(112,242,170,.12); }
.button:not(:disabled):hover { transform: translateY(-1px); filter: brightness(1.08); }

.hookup { display: grid; grid-template-columns: .8fr 1.2fr; gap: 30px 70px; margin-top: 75px; padding: 0 3%; }
.hookup h3 { max-width: 330px; font-size: 31px; }
.signal-flow { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 10px 14px; color: #c9dcd3; font-size: 11px; }
.signal-flow span:nth-of-type(1) { grid-row: span 2; }
.signal-flow b { color: var(--green); font: 9px ui-monospace, monospace; text-transform: uppercase; }
.signal-flow i { height: 1px; background: linear-gradient(90deg, var(--green), transparent); }
.safety-note { grid-column: 2; margin: 0; padding-top: 20px; border-top: 1px solid var(--line); color: var(--muted); font-size: 11px; line-height: 1.7; }
.safety-note strong { color: var(--amber); }
#measurementStage { position: fixed; left: -10000px; top: 0; width: 1000px; height: 1000px; visibility: hidden; pointer-events: none; }

@media (max-width: 850px) {
  .hero { grid-template-columns: 1fr; padding: 55px 0; }
  .intro h2 { max-width: 670px; }
  .scope-wrap { max-width: 680px; margin: 0 auto; }
  .workbench { grid-template-columns: 1fr; }
  .hookup { grid-template-columns: 1fr; }
  .safety-note { grid-column: 1; }
}

@media (max-width: 560px) {
  .app-shell { width: min(100% - 24px, 1240px); padding-top: 18px; }
  .status-pill { display: none; }
  .hero { min-height: 0; gap: 40px; padding: 48px 0; }
  .intro h2 { font-size: 42px; }
  .scope-bezel { border-radius: 25px; }
  .source-panel, .controls-panel { padding: 21px; }
  .control-grid { grid-template-columns: 1fr; }
  .control.full { grid-column: 1; }
  .gif-controls { grid-template-columns: 1fr; }
  .gif-controls-heading { grid-column: 1; }
  .gallery-grid { grid-template-columns: 1fr; }
  .output-panel { align-items: stretch; flex-direction: column; }
  .actions { display: grid; grid-template-columns: 1fr 1fr; }
  .button { min-width: 0; }
}
