:root {
    --bg: #0d1117;
    --panel: #161b22;
    --border: #2a313c;
    --text: #e6edf3;
    --muted: #8b949e;
    --accent: #2f81f7;
    --ok: #3fb950;
    --warn: #d29922;
    --err: #f85149;
    color-scheme: dark;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    min-height: 100vh;
    background: var(--bg);
    color: var(--text);
    font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

h1 { margin: 0; font-size: 17px; font-weight: 600; letter-spacing: .01em; }
.muted { color: var(--muted); font-size: 13px; }

.brand { display: flex; align-items: center; gap: 10px; }
.brand-dot {
    width: 10px; height: 10px; border-radius: 50%;
    background: var(--err);
    box-shadow: 0 0 0 4px rgba(248, 81, 73, .18);
}

.btn, select {
    font: inherit; font-size: 13px;
    color: var(--text);
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 6px 12px;
    cursor: pointer;
}
.btn:hover, select:hover { border-color: var(--muted); }
.btn:focus-visible, select:focus-visible, input:focus-visible, .icon-btn:focus-visible {
    outline: 2px solid var(--accent); outline-offset: 1px;
}
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn-primary:hover { filter: brightness(1.1); border-color: var(--accent); }

/* ---------- Login ---------- */

.login-page { display: grid; place-items: center; padding: 16px; }
.login-card {
    width: 100%; max-width: 360px;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 28px;
}
.login-card .muted { margin: 6px 0 20px; }
.login-card label { display: block; font-size: 13px; color: var(--muted); margin: 14px 0 6px; }
.login-card input[type=text], .login-card input[type=password] {
    width: 100%;
    font: inherit;
    color: var(--text);
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 9px 11px;
}
.login-card .btn { width: 100%; margin-top: 22px; padding: 10px; font-size: 14px; }
.alert {
    border: 1px solid rgba(248, 81, 73, .5);
    background: rgba(248, 81, 73, .12);
    color: #ffb4ae;
    border-radius: 6px;
    padding: 9px 11px;
    font-size: 13px;
}

/* ---------- Viewer ---------- */

.topbar {
    position: sticky; top: 0; z-index: 5;
    display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between;
    gap: 10px 16px;
    padding: 10px 16px;
    background: rgba(13, 17, 23, .92);
    backdrop-filter: blur(6px);
    border-bottom: 1px solid var(--border);
}
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.toolbar form { margin: 0; }

main { padding: 16px; }

.notice {
    border: 1px solid rgba(210, 153, 34, .5);
    background: rgba(210, 153, 34, .1);
    color: #f0d48a;
    border-radius: 8px;
    padding: 10px 14px;
    margin-bottom: 16px;
    font-size: 13px;
}

.grid {
    display: grid;
    gap: 12px;
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 420px), 1fr));
}
.grid.fixed-cols { grid-template-columns: repeat(var(--cols), minmax(0, 1fr)); }
@media (max-width: 640px) {
    .grid.fixed-cols { grid-template-columns: 1fr; }
}

.tile {
    position: relative;
    aspect-ratio: 16 / 9;
    background: #000;
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
}
.tile video, .tile iframe {
    width: 100%; height: 100%;
    display: block; border: 0;
    object-fit: contain;
    background: #000;
}
.tile:fullscreen { border: 0; border-radius: 0; aspect-ratio: auto; }

.tile-bar {
    position: absolute; left: 0; right: 0; top: 0;
    display: flex; align-items: center; gap: 8px;
    padding: 8px 10px 18px;
    background: linear-gradient(rgba(0, 0, 0, .7), transparent);
    font-size: 13px;
    pointer-events: none;
}
.tile-label { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile-state { color: #c9d1d9; margin-right: auto; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.status { flex: none; width: 8px; height: 8px; border-radius: 50%; background: var(--warn); }
.status[data-state=live] { background: var(--ok); }
.status[data-state=embed] { background: var(--accent); }
.status[data-state=error] { background: var(--err); }
.status[data-state=wait] { animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .3; } }
@media (prefers-reduced-motion: reduce) { .status[data-state=wait] { animation: none; } }

.icon-btn {
    flex: none;
    pointer-events: auto;
    font: inherit; font-size: 12px;
    color: #fff;
    background: rgba(0, 0, 0, .45);
    border: 1px solid rgba(255, 255, 255, .25);
    border-radius: 5px;
    padding: 2px 8px;
    cursor: pointer;
    opacity: 0;
    transition: opacity .15s;
}
.tile:hover .icon-btn, .tile:focus-within .icon-btn { opacity: 1; }
@media (hover: none) { .icon-btn { opacity: 1; } }
.icon-btn:hover { background: rgba(0, 0, 0, .75); }
