:root {
    --abyss: #0a1620;
    --deep: #0f1f2e;
    --panel: #142636;
    --panel-2: #1a3045;
    --line: #25415c;
    --line-soft: #1d3349;
    --fg: #e6f0f5;
    --fg-dim: #9bb3c2;
    --fg-mute: #5d7889;
    --teal: #2dd4bf;
    --teal-bright: #5eead4;
    --signal: #00d4ff;
    --amber: #fbbf24;
    --alert: #f97316;
    --danger: #ef4444;
    --grid: rgba(45, 212, 191, 0.06);
}

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

html, body {
    height: 100%;
    background: var(--abyss);
    color: var(--fg);
    font-family: 'Space Grotesk', system-ui, sans-serif;
    font-size: 14px;
    line-height: 1.5;
    overflow: hidden;
}

body {
    background:
        radial-gradient(ellipse 80% 50% at 20% 0%, rgba(0, 212, 255, 0.06), transparent 60%),
        radial-gradient(ellipse 60% 40% at 100% 100%, rgba(45, 212, 191, 0.05), transparent 50%),
        linear-gradient(180deg, var(--abyss) 0%, #07111a 100%);
}

/* ===== App grid ===== */
.app {
    display: grid;
    grid-template-rows: auto 1fr auto;
    height: 100vh;
}

/* ===== Topbar ===== */
.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 24px;
    background: linear-gradient(180deg, rgba(20, 38, 54, 0.85), rgba(15, 31, 46, 0.85));
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--line);
    position: relative;
}
.topbar::after {
    content: '';
    position: absolute;
    bottom: -1px; left: 0; right: 0;
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--teal) 50%, transparent);
    opacity: 0.5;
}

.brand { display: flex; align-items: center; gap: 14px; }
.brand-mark {
    color: var(--teal);
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px; height: 44px;
    background: rgba(45, 212, 191, 0.08);
    border: 1px solid rgba(45, 212, 191, 0.3);
    border-radius: 6px;
}
.brand-text h1 {
    font-size: 18px;
    font-weight: 700;
    letter-spacing: 0.02em;
}
.subtitle {
    font-family: 'JetBrains Mono', monospace;
    font-size: 11px;
    color: var(--fg-mute);
    letter-spacing: 0.08em;
    text-transform: uppercase;
    margin-top: 2px;
}

.status-cluster { display: flex; gap: 10px; }
.status-pill {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    background: rgba(37, 65, 92, 0.4);
    border: 1px solid var(--line);
    border-radius: 999px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 11px;
    color: var(--fg-dim);
}
.status-pill .dot {
    width: 7px; height: 7px;
    border-radius: 50%;
    background: var(--fg-mute);
    box-shadow: 0 0 0 0 currentColor;
}
.status-pill[data-state="loading"] .dot { background: var(--amber); animation: pulse 1.2s infinite; }
.status-pill[data-state="ready"]   .dot { background: var(--teal); box-shadow: 0 0 8px var(--teal); }
.status-pill[data-state="error"]   .dot { background: var(--danger); }
.status-pill[data-state="loading"] .label { color: var(--amber); }
.status-pill[data-state="ready"]   .label { color: var(--teal-bright); }
.status-pill[data-state="error"]   .label { color: var(--danger); }

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

/* ===== Workspace ===== */
.workspace {
    display: grid;
    grid-template-columns: 340px 1fr;
    gap: 0;
    min-height: 0;
}

/* ===== Control panel ===== */
.control-panel {
    background: var(--deep);
    border-right: 1px solid var(--line);
    overflow-y: auto;
    padding: 18px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.panel {
    background: var(--panel);
    border: 1px solid var(--line-soft);
    border-radius: 4px;
    overflow: hidden;
}
.panel-title {
    font-family: 'JetBrains Mono', monospace;
    font-size: 11px;
    font-weight: 500;
    color: var(--fg-mute);
    letter-spacing: 0.12em;
    text-transform: uppercase;
    padding: 10px 14px;
    background: rgba(0, 0, 0, 0.18);
    border-bottom: 1px solid var(--line-soft);
}
.panel-body { padding: 14px; display: flex; flex-direction: column; gap: 14px; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field-label {
    font-size: 12px;
    color: var(--fg-dim);
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.value-readout {
    font-family: 'JetBrains Mono', monospace;
    color: var(--teal-bright);
    font-size: 12px;
}

.input {
    width: 100%;
    padding: 9px 11px;
    background: var(--abyss);
    border: 1px solid var(--line);
    border-radius: 3px;
    color: var(--fg);
    font-family: 'JetBrains Mono', monospace;
    font-size: 12px;
    transition: border-color 0.15s, box-shadow 0.15s;
}
.input:focus {
    outline: none;
    border-color: var(--teal);
    box-shadow: 0 0 0 2px rgba(45, 212, 191, 0.15);
}

select.input { font-family: 'Space Grotesk', sans-serif; cursor: pointer; }

.slider {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 4px;
    background: var(--line);
    border-radius: 2px;
    outline: none;
    cursor: pointer;
}
.slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 16px; height: 16px;
    background: var(--teal);
    border: 2px solid var(--deep);
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 0 6px rgba(45, 212, 191, 0.5);
}
.slider::-moz-range-thumb {
    width: 14px; height: 14px;
    background: var(--teal);
    border: 2px solid var(--deep);
    border-radius: 50%;
    cursor: pointer;
}

.btn-row { display: flex; gap: 8px; }
.btn {
    flex: 1;
    padding: 9px 12px;
    border: 1px solid var(--line);
    background: var(--panel-2);
    color: var(--fg);
    border-radius: 3px;
    font-family: 'Space Grotesk', sans-serif;
    font-size: 12px;
    font-weight: 500;
    letter-spacing: 0.02em;
    cursor: pointer;
    transition: all 0.15s;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}
.btn:hover:not(:disabled) {
    border-color: var(--teal);
    color: var(--teal-bright);
    background: rgba(45, 212, 191, 0.08);
}
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-primary {
    background: linear-gradient(180deg, rgba(45, 212, 191, 0.18), rgba(45, 212, 191, 0.08));
    border-color: var(--teal);
    color: var(--teal-bright);
}
.btn-primary:hover:not(:disabled) {
    background: linear-gradient(180deg, rgba(45, 212, 191, 0.28), rgba(45, 212, 191, 0.12));
    box-shadow: 0 0 12px rgba(45, 212, 191, 0.2);
}
.btn-ghost { background: transparent; }

.hint {
    font-size: 11px;
    color: var(--fg-mute);
    line-height: 1.4;
    margin-top: 2px;
}

/* ===== Dropzone ===== */
.dropzone {
    border: 1px dashed var(--line);
    border-radius: 4px;
    padding: 24px 12px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
    color: var(--fg-mute);
}

/* ===== Source tabs ===== */
.source-tabs {
    display: flex;
    gap: 0;
    border: 1px solid var(--line);
    border-radius: 3px;
    overflow: hidden;
}
.source-tabs .tab {
    flex: 1;
    padding: 8px 10px;
    border: none;
    background: var(--panel-2);
    color: var(--fg-dim);
    font-family: 'Space Grotesk', sans-serif;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
    border-right: 1px solid var(--line);
}
.source-tabs .tab:last-child { border-right: none; }
.source-tabs .tab:hover { color: var(--teal-bright); }
.source-tabs .tab.active {
    background: linear-gradient(180deg, rgba(45, 212, 191, 0.18), rgba(45, 212, 191, 0.08));
    color: var(--teal-bright);
    box-shadow: inset 0 -2px 0 var(--teal);
}

.source-pane { display: none; flex-direction: column; gap: 14px; }
.source-pane.active { display: flex; }

.dropzone:hover, .dropzone:focus, .dropzone.dragover {
    border-color: var(--teal);
    color: var(--teal-bright);
    background: rgba(45, 212, 191, 0.04);
}
.dropzone-inner { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.dz-title { font-size: 13px; font-weight: 500; }
.dz-sub { font-size: 11px; }

/* ===== Viewport ===== */
.viewport {
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
    background:
        linear-gradient(var(--grid) 1px, transparent 1px) 0 0 / 40px 40px,
        linear-gradient(90deg, var(--grid) 1px, transparent 1px) 0 0 / 40px 40px,
        var(--abyss);
}

.canvas-stage {
    flex: 1;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    min-height: 0;
    overflow: hidden;
}

#imageCanvas {
    max-width: 100%;
    max-height: 100%;
    border: 1px solid var(--line);
    border-radius: 4px;
    background: #000;
    display: block;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
}

.canvas-overlay {
    position: absolute;
    inset: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(7, 17, 26, 0.92);
    border-radius: 4px;
    transition: opacity 0.25s;
}
.canvas-overlay.hidden { opacity: 0; pointer-events: none; }
.overlay-message {
    text-align: center;
    color: var(--fg-dim);
}
.overlay-icon {
    font-size: 48px;
    color: var(--teal);
    opacity: 0.6;
    margin-bottom: 12px;
    font-family: 'JetBrains Mono', monospace;
}
.overlay-message p { font-size: 16px; font-weight: 500; color: var(--fg); }
.overlay-message span {
    font-size: 12px;
    color: var(--fg-mute);
    display: block;
    margin-top: 6px;
}

.canvas-hud {
    position: absolute;
    top: 32px;
    right: 32px;
    display: flex;
    gap: 8px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 11px;
}
.hud-item {
    padding: 4px 8px;
    background: rgba(7, 17, 26, 0.85);
    border: 1px solid var(--line);
    border-radius: 2px;
    color: var(--teal-bright);
    letter-spacing: 0.05em;
}

/* ===== Detection strip ===== */
.detection-strip {
    background: var(--deep);
    border-top: 1px solid var(--line);
    padding: 14px 24px;
    max-height: 200px;
    display: flex;
    flex-direction: column;
}
.strip-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}
.strip-head h3 {
    font-size: 13px;
    font-weight: 700;
    letter-spacing: 0.04em;
}
.strip-meta {
    font-family: 'JetBrains Mono', monospace;
    font-size: 11px;
    color: var(--fg-mute);
    display: flex;
    gap: 8px;
}
.strip-meta .sep { opacity: 0.5; }

.result-list {
    display: flex;
    gap: 10px;
    overflow-x: auto;
    overflow-y: hidden;
    padding-bottom: 4px;
}
.result-list::-webkit-scrollbar { height: 6px; }
.result-list::-webkit-scrollbar-track { background: var(--abyss); }
.result-list::-webkit-scrollbar-thumb { background: var(--line); border-radius: 3px; }

.empty-result {
    color: var(--fg-mute);
    font-size: 12px;
    font-style: italic;
    padding: 12px 0;
}

.result-card {
    flex: 0 0 160px;
    background: var(--panel);
    border: 1px solid var(--line-soft);
    border-left: 3px solid var(--teal);
    border-radius: 3px;
    padding: 10px 12px;
    font-family: 'JetBrains Mono', monospace;
}
.result-card .rc-class {
    font-size: 13px;
    font-weight: 700;
    color: var(--fg);
    margin-bottom: 4px;
}
.result-card .rc-conf {
    font-size: 11px;
    color: var(--teal-bright);
}
.result-card .rc-box {
    font-size: 10px;
    color: var(--fg-mute);
    margin-top: 4px;
}

/* ===== Footer ===== */
.footer {
    padding: 8px 24px;
    background: var(--deep);
    border-top: 1px solid var(--line);
    font-family: 'JetBrains Mono', monospace;
    font-size: 10px;
    color: var(--fg-mute);
    letter-spacing: 0.05em;
    text-align: center;
}

/* ===== Responsive ===== */
@media (max-width: 960px) {
    .workspace { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
    .control-panel { max-height: 40vh; border-right: none; border-bottom: 1px solid var(--line); }
    .status-cluster { display: none; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
