/* ============================================================================
   PHOSPHENE — Web Companion
   Aesthetic: phosphor-lab instrument. Dark oscilloscope panel, amber + cyan
   glow, graph-paper grid, the embedded display rendered as a screen-under-test.
   ========================================================================== */

:root {
    /* Phosphor palette (dark default) */
    --base:        #08090c;
    --base-2:      #0c0e13;
    --panel:       rgba(18, 21, 28, 0.72);
    --panel-solid: #11141b;
    --ink:         #e9eef2;
    --ink-dim:     #8a93a3;
    --ink-faint:   #565f70;
    --line:        rgba(140, 160, 190, 0.14);
    --line-strong: rgba(140, 160, 190, 0.28);

    --amber:       #ffb000;   /* primary phosphor */
    --amber-soft:  #ffc864;
    --cyan:        #34e3d0;   /* signal / secondary */
    --cyan-soft:   #7ff2e6;
    --good:        #54d18a;
    --warn:        #ffc14d;
    --bad:         #ff5d5d;

    --grid:        rgba(120, 140, 170, 0.05);

    --r-lg: 14px;
    --r-md: 10px;
    --r-sm: 6px;

    --sp: 8px;   /* 8px spatial grid */

    --f-display: 'Bricolage Grotesque', 'Arial Black', sans-serif;
    --f-body:    'IBM Plex Sans', system-ui, sans-serif;
    --f-mono:    'IBM Plex Mono', ui-monospace, monospace;

    --shadow: 0 24px 60px -20px rgba(0, 0, 0, 0.7);
}

:root[data-theme="light"] {
    --base:        #f3efe6;
    --base-2:      #ece6d8;
    --panel:       rgba(255, 253, 248, 0.78);
    --panel-solid: #fbf8f1;
    --ink:         #1b1a16;
    --ink-dim:     #6a6557;
    --ink-faint:   #9a9384;
    --line:        rgba(60, 55, 40, 0.14);
    --line-strong: rgba(60, 55, 40, 0.26);
    --amber:       #c4670c;
    --amber-soft:  #e08a2b;
    --cyan:        #0c8f86;
    --cyan-soft:   #1aa99c;
    --grid:        rgba(60, 55, 40, 0.05);
    --shadow: 0 24px 50px -24px rgba(60, 50, 30, 0.4);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
    font-family: var(--f-body);
    background: var(--base);
    color: var(--ink);
    min-height: 100vh;
    line-height: 1.5;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
}

/* ── Atmosphere: gradient mesh + graph grid + grain ──────────────────────── */
.bg-field {
    position: fixed; inset: 0; z-index: -2;
    background:
        radial-gradient(60% 50% at 12% 8%,  rgba(255, 176, 0, 0.16), transparent 60%),
        radial-gradient(55% 50% at 92% 18%, rgba(52, 227, 208, 0.12), transparent 60%),
        radial-gradient(70% 60% at 80% 100%, rgba(255, 176, 0, 0.08), transparent 60%),
        linear-gradient(180deg, var(--base), var(--base-2));
    background-attachment: fixed;
}
.bg-field::after {
    content: ""; position: absolute; inset: 0;
    background-image:
        linear-gradient(var(--grid) 1px, transparent 1px),
        linear-gradient(90deg, var(--grid) 1px, transparent 1px);
    background-size: 32px 32px;
    mask-image: radial-gradient(120% 100% at 50% 0%, #000 55%, transparent 100%);
}
.bg-grain {
    position: fixed; inset: 0; z-index: -1; pointer-events: none; opacity: 0.045;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* ── Masthead ────────────────────────────────────────────────────────────── */
.masthead {
    display: flex; align-items: center; justify-content: space-between;
    padding: calc(var(--sp) * 3) clamp(16px, 4vw, 56px);
    position: sticky; top: 0; z-index: 20;
    backdrop-filter: blur(8px);
    border-bottom: 1px solid var(--line);
}
.mark { display: flex; align-items: center; gap: 12px; }
.mark-glyph {
    width: 16px; height: 16px; border-radius: 50%;
    background: var(--amber);
    box-shadow: 0 0 0 3px rgba(255,176,0,.18), 0 0 18px 2px var(--amber);
    animation: pulse 3.2s ease-in-out infinite;
}
@keyframes pulse { 0%,100%{opacity:.65;transform:scale(.9)} 50%{opacity:1;transform:scale(1.05)} }
.mark-text { font-family: var(--f-mono); font-weight: 600; letter-spacing: .34em; font-size: .82rem; }

.masthead-nav { display: flex; gap: 8px; }
.ghost-btn {
    font-family: var(--f-mono); font-size: .72rem; letter-spacing: .14em;
    color: var(--ink-dim); background: transparent;
    border: 1px solid var(--line-strong); border-radius: var(--r-sm);
    padding: 8px 12px; cursor: pointer; text-decoration: none;
    display: inline-flex; align-items: center; gap: 8px;
    transition: color .18s, border-color .18s, background .18s;
}
.ghost-btn:hover { color: var(--ink); border-color: var(--amber); background: rgba(255,176,0,.06); }
.theme-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--amber); box-shadow: 0 0 8px var(--amber); }

/* ── Hero ────────────────────────────────────────────────────────────────── */
.hero {
    padding: clamp(40px, 9vw, 110px) clamp(16px, 4vw, 56px) clamp(24px, 4vw, 56px);
    max-width: 1080px;
}
.hero-kicker {
    font-family: var(--f-mono); font-size: .72rem; letter-spacing: .3em;
    color: var(--cyan); margin-bottom: 20px;
}
.hero-title {
    font-family: var(--f-display); font-weight: 800;
    font-size: clamp(2.8rem, 11vw, 7.5rem); line-height: 0.92;
    letter-spacing: -0.02em;
    animation: rise .8s cubic-bezier(.2,.8,.2,1) both;
}
.hero-title em { font-style: normal; color: var(--amber); text-shadow: 0 0 36px rgba(255,176,0,.4); }
.hero-sub {
    margin-top: 24px; max-width: 52ch; color: var(--ink-dim);
    font-size: clamp(.95rem, 1.4vw, 1.12rem);
    animation: rise .8s .12s cubic-bezier(.2,.8,.2,1) both;
}
@keyframes rise { from { opacity: 0; transform: translateY(22px); } to { opacity: 1; transform: none; } }

/* ── Workspace grid ──────────────────────────────────────────────────────── */
.workspace {
    display: grid; gap: clamp(12px, 1.6vw, 20px);
    grid-template-columns: minmax(280px, 1fr) minmax(320px, 1.25fr) minmax(280px, 1fr);
    align-items: start;
    padding: 0 clamp(16px, 4vw, 56px) clamp(40px, 6vw, 80px);
    max-width: 1500px;
}
.stack { display: flex; flex-direction: column; gap: clamp(12px, 1.6vw, 20px); }

@media (max-width: 1080px) {
    .workspace { grid-template-columns: 1fr 1fr; }
    .stack:nth-child(2) { grid-column: 1 / -1; order: -1; }
}
@media (max-width: 720px) {
    .workspace { grid-template-columns: 1fr; }
    .stack:nth-child(2) { order: 0; }
}

/* ── Panels (instrument cards with corner ticks) ─────────────────────────── */
.panel {
    position: relative;
    background: var(--panel);
    backdrop-filter: blur(10px);
    border: 1px solid var(--line);
    border-radius: var(--r-lg);
    padding: calc(var(--sp) * 2.5);
    box-shadow: var(--shadow);
    animation: rise .6s cubic-bezier(.2,.8,.2,1) both;
}
.panel[data-corner]::before,
.panel[data-corner]::after {
    content: ""; position: absolute; width: 10px; height: 10px;
    border: 1px solid var(--amber); opacity: .5;
}
.panel[data-corner]::before { top: 8px; left: 8px; border-right: 0; border-bottom: 0; }
.panel[data-corner]::after { bottom: 8px; right: 8px; border-left: 0; border-top: 0; }

.panel-title {
    font-family: var(--f-mono); font-weight: 600;
    font-size: .78rem; letter-spacing: .18em; text-transform: uppercase;
    color: var(--ink-dim); margin-bottom: calc(var(--sp) * 2);
    display: flex; align-items: center; gap: 10px;
}
.panel-title .idx { color: var(--amber); }

/* ── Drop zone (oscilloscope) ────────────────────────────────────────────── */
.drop-zone {
    position: relative; overflow: hidden;
    border: 1px dashed var(--line-strong); border-radius: var(--r-md);
    padding: calc(var(--sp) * 4) var(--sp); text-align: center;
    cursor: pointer; transition: border-color .2s, background .2s, transform .2s;
    background: rgba(0,0,0,.18);
}
:root[data-theme="light"] .drop-zone { background: rgba(0,0,0,.03); }
.drop-zone:hover, .drop-zone:focus-visible { border-color: var(--amber); outline: none; transform: translateY(-1px); }
.drop-zone.drag { border-color: var(--cyan); background: rgba(52,227,208,.07); box-shadow: inset 0 0 40px rgba(52,227,208,.12); }
.scope-line {
    position: absolute; left: 0; right: 0; top: 50%; height: 1px;
    background: linear-gradient(90deg, transparent, var(--cyan), transparent);
    opacity: .5; animation: sweep 3s linear infinite;
}
@keyframes sweep { 0%{transform:translateY(-30px);opacity:0} 50%{opacity:.6} 100%{transform:translateY(30px);opacity:0} }
.drop-main { font-size: 1.02rem; position: relative; }
.drop-or { color: var(--ink-dim); font-size: .88rem; margin-top: 4px; position: relative; }
.link { color: var(--amber); cursor: pointer; border-bottom: 1px solid currentColor; }
.drop-meta { margin-top: 14px; font-family: var(--f-mono); font-size: .72rem; color: var(--ink-faint); position: relative; }

/* ── Fields ──────────────────────────────────────────────────────────────── */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: calc(var(--sp) * 2); }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field label, .field-row > .field label {
    font-family: var(--f-mono); font-size: .7rem; letter-spacing: .1em;
    text-transform: uppercase; color: var(--ink-dim);
    display: flex; justify-content: space-between; gap: 8px;
}
.field-hint { font-family: var(--f-mono); font-size: .68rem; color: var(--ink-faint); }

select, input[type="range"] {
    width: 100%; font-family: var(--f-body); color: var(--ink);
    background: var(--panel-solid); border: 1px solid var(--line-strong);
    border-radius: var(--r-sm); padding: 10px; font-size: .9rem;
    transition: border-color .18s, box-shadow .18s;
}
select:focus { outline: none; border-color: var(--amber); box-shadow: 0 0 0 3px rgba(255,176,0,.16); }

input[type="range"] {
    -webkit-appearance: none; appearance: none; height: 4px; padding: 0;
    background: var(--line-strong); border: none; cursor: pointer; border-radius: 4px;
}
input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none; width: 16px; height: 16px; border-radius: 50%;
    background: var(--amber); box-shadow: 0 0 10px var(--amber); cursor: pointer;
}
input[type="range"]::-moz-range-thumb {
    width: 16px; height: 16px; border: none; border-radius: 50%;
    background: var(--amber); box-shadow: 0 0 10px var(--amber); cursor: pointer;
}
.mono { font-family: var(--f-mono); color: var(--amber); }

.advanced { margin-top: 4px; border-top: 1px solid var(--line); padding-top: calc(var(--sp) * 1.5); }
.advanced > summary {
    cursor: pointer; font-family: var(--f-mono); font-size: .72rem;
    letter-spacing: .14em; text-transform: uppercase; color: var(--ink-dim);
    list-style: none; user-select: none; margin-bottom: var(--sp);
}
.advanced > summary::before { content: "+ "; color: var(--amber); }
.advanced[open] > summary::before { content: "− "; }
.check { display: flex; align-items: center; gap: 8px; font-size: .82rem; align-self: end; padding-bottom: 10px; cursor: pointer; }
.check input { accent-color: var(--amber); }

/* ── Display preview screen ──────────────────────────────────────────────── */
.panel-display { display: flex; flex-direction: column; }
.screen-shell { display: flex; flex-direction: column; align-items: center; gap: 12px; }
.screen-bezel {
    position: relative; width: 100%; aspect-ratio: 2 / 1;
    background: #000; border-radius: var(--r-md);
    border: 1px solid var(--line-strong);
    padding: 6px; display: flex; align-items: center; justify-content: center;
    overflow: hidden;
    box-shadow: inset 0 0 0 2px rgba(0,0,0,.6), inset 0 0 50px rgba(0,0,0,.8);
}
#previewCanvas {
    image-rendering: pixelated;
    max-width: 100%; max-height: 100%;
    width: auto; height: auto;
    background: #000; border-radius: 2px;
}
.screen-bezel.bloom #previewCanvas { filter: drop-shadow(0 0 3px rgba(255,176,0,.5)) drop-shadow(0 0 8px rgba(255,176,0,.25)); }
.screen-scan {
    position: absolute; inset: 0; pointer-events: none; opacity: 0;
    background: repeating-linear-gradient(0deg, rgba(0,0,0,.35) 0 1px, transparent 1px 3px);
    transition: opacity .2s;
}
.screen-bezel.scan .screen-scan { opacity: .55; }
.screen-bezel.grid::after {
    content: ""; position: absolute; inset: 6px; pointer-events: none;
    background-image:
        linear-gradient(rgba(120,160,200,.18) 1px, transparent 1px),
        linear-gradient(90deg, rgba(120,160,200,.18) 1px, transparent 1px);
    background-size: 8px 8px;
}
.screen-empty {
    position: absolute; font-family: var(--f-mono); font-size: .72rem;
    letter-spacing: .22em; text-transform: uppercase; color: var(--cyan);
    opacity: .7; animation: blink 1.6s steps(2) infinite;
}
@keyframes blink { 50% { opacity: .15; } }
.screen-bezel.has-signal .screen-empty { display: none; }
.screen-readout { font-family: var(--f-mono); font-size: .72rem; color: var(--ink-faint); letter-spacing: .1em; }

.transport { display: flex; align-items: center; gap: 12px; margin-top: 16px; }
.t-btn {
    flex: none; width: 40px; height: 40px; border-radius: 50%;
    border: 1px solid var(--line-strong); background: var(--panel-solid);
    color: var(--amber); font-size: .9rem; cursor: pointer; transition: .18s;
}
.t-btn:hover:not(:disabled) { border-color: var(--amber); box-shadow: 0 0 12px rgba(255,176,0,.3); }
.t-btn:disabled { opacity: .35; cursor: not-allowed; }
.transport input[type="range"] { flex: 1; }
.frame-count { font-size: .72rem; white-space: nowrap; }

.toggle-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.chip-toggle { font-family: var(--f-mono); font-size: .68rem; letter-spacing: .06em; cursor: pointer;
    display: inline-flex; align-items: center; gap: 6px; color: var(--ink-dim);
    border: 1px solid var(--line); border-radius: 999px; padding: 5px 10px; transition: .18s; }
.chip-toggle:hover { color: var(--ink); border-color: var(--line-strong); }
.chip-toggle input { accent-color: var(--cyan); }

/* ── Gauges + chips (fit analysis) ───────────────────────────────────────── */
.gauge { margin-bottom: calc(var(--sp) * 2); }
.gauge-head { display: flex; justify-content: space-between; font-family: var(--f-mono);
    font-size: .72rem; letter-spacing: .1em; text-transform: uppercase; color: var(--ink-dim); margin-bottom: 6px; }
.gauge-track { height: 8px; border-radius: 6px; background: var(--line-strong); overflow: hidden; }
.gauge-fill { height: 100%; width: 0%; border-radius: 6px;
    background: linear-gradient(90deg, var(--cyan), var(--amber));
    transition: width .5s cubic-bezier(.2,.8,.2,1); }
.gauge-fill.over { background: linear-gradient(90deg, var(--warn), var(--bad)); }
.gauge-sub { font-size: .68rem; color: var(--ink-faint); margin-top: 5px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: calc(var(--sp) * 1.5) 0; }
.chip { font-family: var(--f-mono); font-size: .66rem; letter-spacing: .1em;
    border: 1px solid var(--line-strong); border-radius: 999px; padding: 5px 10px; color: var(--ink-dim); }
.chip.good { color: var(--good); border-color: var(--good); }
.chip.warn { color: var(--warn); border-color: var(--warn); }
.chip.bad  { color: var(--bad);  border-color: var(--bad); }
.reco { font-size: .78rem; color: var(--ink-dim); line-height: 1.4; }
.reco span { display: block; padding-left: 14px; position: relative; margin-top: 4px; }
.reco span::before { content: "›"; position: absolute; left: 0; color: var(--amber); }

/* ── Convert button ──────────────────────────────────────────────────────── */
.convert-btn {
    position: relative; overflow: hidden; width: 100%;
    font-family: var(--f-display); font-weight: 800; font-size: 1.3rem; letter-spacing: -.01em;
    color: #0a0a0a; background: var(--amber); border: none; border-radius: var(--r-md);
    padding: 18px; cursor: pointer; transition: transform .12s, box-shadow .2s, filter .2s;
    box-shadow: 0 0 0 0 rgba(255,176,0,.5);
}
.convert-btn:hover:not(:disabled) { transform: translateY(-2px); box-shadow: 0 10px 30px -8px rgba(255,176,0,.6); filter: brightness(1.05); }
.convert-btn:active:not(:disabled) { transform: translateY(0); }
.convert-btn:disabled { opacity: .35; cursor: not-allowed; }
.convert-btn.busy { color: transparent; }
.convert-btn.busy .convert-spark {
    position: absolute; inset: 0; margin: auto; width: 22px; height: 22px;
    border: 3px solid rgba(0,0,0,.25); border-top-color: #0a0a0a; border-radius: 50%;
    animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.progress { margin-top: 14px; height: 4px; background: var(--line-strong); border-radius: 4px; overflow: hidden; }
.progress-bar { height: 100%; width: 0%; background: linear-gradient(90deg, var(--cyan), var(--amber));
    transition: width .2s; }

.stats { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 14px; }
.stat-item { font-family: var(--f-mono); font-size: .68rem; color: var(--ink-dim);
    border: 1px solid var(--line); border-radius: var(--r-sm); padding: 8px 10px; flex: 1; min-width: 80px; }
.stat-item .v { display: block; color: var(--amber); font-size: .98rem; margin-top: 3px; }

/* ── Output ──────────────────────────────────────────────────────────────── */
.output { padding: 0 clamp(16px, 4vw, 56px) clamp(40px, 6vw, 90px); max-width: 1500px; animation: rise .6s both; }
.output-head { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.output-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.tabs { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: -1px; }
.tab { font-family: var(--f-mono); font-size: .72rem; padding: 9px 14px; cursor: pointer;
    color: var(--ink-dim); background: var(--panel); border: 1px solid var(--line);
    border-bottom: none; border-radius: var(--r-sm) var(--r-sm) 0 0; }
.tab.active { color: var(--amber); background: var(--panel-solid); border-color: var(--line-strong); }
.code-view {
    background: var(--panel-solid); border: 1px solid var(--line-strong); border-radius: 0 var(--r-md) var(--r-md) var(--r-md);
    padding: 18px; max-height: 460px; overflow: auto;
}
.code-view code { font-family: var(--f-mono); font-size: .78rem; color: var(--ink); white-space: pre; line-height: 1.55; }

/* ── Footer ──────────────────────────────────────────────────────────────── */
.foot {
    display: flex; flex-wrap: wrap; gap: 14px; align-items: center; justify-content: space-between;
    padding: calc(var(--sp) * 3) clamp(16px, 4vw, 56px); border-top: 1px solid var(--line);
    font-family: var(--f-mono); font-size: .72rem; letter-spacing: .14em; color: var(--ink-faint);
}
.foot span:first-child { color: var(--amber); }
.foot a { color: var(--ink-dim); text-decoration: none; }
.foot a:hover { color: var(--amber); }

/* ── Toasts ──────────────────────────────────────────────────────────────── */
.toast-stack { position: fixed; bottom: 20px; right: 20px; z-index: 50; display: flex; flex-direction: column; gap: 8px; }
.toast {
    font-family: var(--f-mono); font-size: .76rem; color: var(--ink);
    background: var(--panel-solid); border: 1px solid var(--line-strong); border-left: 3px solid var(--amber);
    border-radius: var(--r-sm); padding: 12px 16px; max-width: 340px; box-shadow: var(--shadow);
    animation: toastIn .26s cubic-bezier(.2,.8,.2,1);
}
.toast.error { border-left-color: var(--bad); }
.toast.success { border-left-color: var(--good); }
.toast.fade { animation: toastOut .3s forwards; }
@keyframes toastIn { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: none; } }
@keyframes toastOut { to { opacity: 0; transform: translateX(20px); } }

/* ── Motion preferences ──────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; scroll-behavior: auto; }
}
