:root {
    color-scheme: dark;
    --bg: #191d21;
    --panel: #252b31;
    --stage: #f2f4f5;
    --topbar: #363f47;
    --text: #f1f1f1;
    --muted: #aab4be;
    --line: rgba(255, 255, 255, 0.14);
    --button: #f4f4f4;
    --button-text: #20262c;
    --accent: #49c6d8;
    --danger: #e16b5f;
}

* {
    box-sizing: border-box;
}

html,
body {
    width: 100%;
    height: 100%;
    margin: 0;
    overflow: hidden;
    background: var(--bg);
    font-family: Arial, Helvetica, sans-serif;
}

button {
    font: inherit;
}

.app {
    position: relative;
    display: grid;
    grid-template-columns: minmax(0, 1fr) 300px;
    width: 100vw;
    height: 100vh;
    background:
        linear-gradient(135deg, rgba(73, 198, 216, 0.08), transparent 34%),
        linear-gradient(315deg, rgba(242, 184, 75, 0.06), transparent 28%),
        var(--bg);
    overflow: hidden;
}

.ambient-grid {
    position: absolute;
    inset: 0;
    z-index: 0;
    opacity: 0.16;
    background-image:
        linear-gradient(rgba(255, 255, 255, 0.08) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255, 255, 255, 0.08) 1px, transparent 1px);
    background-size: 42px 42px;
    pointer-events: none;
}

.app.connected {
    grid-template-columns: minmax(0, 1fr) 0;
}

.app.connected .side-panel {
    display: none;
}

.app.connected .workspace {
    padding: 0;
}

.app.connected .stage {
    border: 0;
    border-radius: 0;
}

.workspace {
    position: relative;
    z-index: 1;
    min-width: 0;
    min-height: 0;
    padding: 18px;
}

.stage {
    position: relative;
    width: 100%;
    height: 100%;
    min-width: 0;
    min-height: 0;
    overflow: hidden;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 8px;
    background:
        linear-gradient(0deg, rgba(0, 0, 0, 0.04), transparent),
        var(--stage);
    box-shadow: 0 18px 44px rgba(0, 0, 0, 0.24);
}

#frameImage {
    width: 100%;
    height: 100%;
    object-fit: contain;
    background: #fff;
}

.detection-svg {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.detection-debug {
    position: absolute;
    left: 18px;
    bottom: 18px;
    z-index: 2;
    display: none;
    max-width: min(560px, calc(100% - 220px));
    padding: 10px 12px;
    border: 1px solid rgba(255, 255, 255, 0.25);
    background: rgba(0, 0, 0, 0.62);
    color: #fff;
    font-size: 14px;
    line-height: 1.35;
    white-space: pre-wrap;
    pointer-events: none;
}

.detection-debug:empty {
    display: none;
}

.empty-frame {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    color: #6d7780;
    font-size: 26px;
    font-weight: 700;
    pointer-events: none;
}

.stage.has-frame .empty-frame,
.app.connected .empty-frame {
    display: none;
}

.disconnect-button {
    position: absolute;
    right: 32px;
    bottom: 32px;
    display: none;
    width: 150px;
    height: 52px;
    border: 1px solid #d0d0d0;
    border-radius: 2px;
    background: var(--danger);
    color: #fff;
    font-size: 20px;
    font-weight: 700;
    cursor: pointer;
    transition: background-color 120ms ease, color 120ms ease, transform 120ms ease;
}

.app.connected .disconnect-button {
    display: block;
}

.side-panel {
    position: relative;
    z-index: 1;
    display: grid;
    grid-template-rows: minmax(0, 1fr) auto;
    gap: 22px;
    margin: 18px 18px 18px 0;
    padding: 22px 16px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: rgba(37, 43, 49, 0.92);
    color: var(--text);
    box-shadow: 0 18px 44px rgba(0, 0, 0, 0.22);
}

.panel-section {
    display: grid;
    gap: 10px;
}

.streams {
    align-self: end;
}

.section-title {
    color: var(--text);
    font-size: 20px;
    font-weight: 700;
}

.status {
    margin-top: 6px;
    color: var(--muted);
    font-size: 13px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

button,
.stream-item button {
    height: 42px;
    border: 0;
    border-radius: 2px;
    background: var(--button);
    color: var(--button-text);
    cursor: pointer;
    font-weight: 700;
    transition: background-color 120ms ease, color 120ms ease, transform 120ms ease;
}

button:hover,
.stream-item button:hover {
    background: #ffffff;
    color: #222;
}

button:active,
.stream-item button:active {
    transform: translateY(1px);
}

.stream-list-wrapper {
    position: absolute;
    top: 18px;
    left: 18px;
    right: 18px;
    z-index: 4;
    display: none;
}

.stream-list-wrapper.visible {
    display: block;
}

.stream-list {
    display: grid;
    align-content: start;
    gap: 12px;
}

.stream-item {
    display: grid;
    grid-template-columns: minmax(190px, 1fr) auto 160px;
    align-items: center;
    gap: 32px;
    min-height: 92px;
    padding: 18px 32px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 8px;
    background: rgba(54, 63, 71, 0.94);
    cursor: pointer;
    box-shadow: 0 14px 34px rgba(0, 0, 0, 0.2);
    transition: background-color 120ms ease, border-color 120ms ease, outline-color 120ms ease;
}

.stream-item:hover {
    border-color: rgba(73, 198, 216, 0.5);
    background: #43505a;
}

.stream-item.selected {
    outline: 2px solid var(--accent);
    outline-offset: -2px;
}

.stream-title,
.stream-meta {
    color: #fff;
    font-size: 25px;
    font-weight: 700;
    white-space: nowrap;
}

.stream-meta {
    color: var(--muted);
    font-size: 20px;
}

.box {
    fill: none;
    stroke: #28d7ff;
    stroke-width: 4;
}

.box-label {
    fill: #28d7ff;
    font-size: 18px;
    font-weight: 700;
    paint-order: stroke;
    stroke: rgba(0, 0, 0, 0.8);
    stroke-width: 4;
}
