:root {
    --bg: #141618;
    --surface: #1c1f24;
    --surface-2: #262a31;
    --border: rgba(255,255,255,0.1);
    --text: #eceff4;
    --text-dim: #9aa3b2;
    --accent: #c9a227;
    --accent-hover: #dbb42e;
    --accent-soft: rgba(201,162,39,0.18);
    --danger: #c53030;
    --success: #3d8f5f;
    --font: 'DM Sans', system-ui, sans-serif;
    --mono: 'JetBrains Mono', monospace;
    --radius: 10px;
    --side-width: clamp(240px, 22vw, 300px);
}

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

html, body {
    height: 100%;
    overflow: hidden;
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    -webkit-font-smoothing: antialiased;
}

.app {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    background: var(--bg);
}

.app-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
}

/* ── Topbar ── */
.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: clamp(0.45rem, 1.2vmin, 0.65rem) clamp(0.75rem, 2vw, 1.25rem);
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.topbar-left { display: flex; align-items: center; gap: 0.75rem; min-width: 0; }

.brand {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--text);
    text-decoration: none;
    font-weight: 700;
    font-size: clamp(0.95rem, 1.8vw, 1.05rem);
    white-space: nowrap;
}
.brand:hover { color: var(--accent); }

.badge-live {
    font-size: 0.62rem;
    font-weight: 700;
    letter-spacing: 0.1em;
    padding: 0.2rem 0.45rem;
    border-radius: 3px;
    background: var(--danger);
    color: #fff;
    flex-shrink: 0;
}

.ntp-clock {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    font-family: var(--mono);
    font-size: 0.95rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    flex-shrink: 0;
}
.ntp-time { min-width: 5.5ch; }
.ntp-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #6b7280;
}
.ntp-dot.synced { background: #22c55e; }

.status-chip {
    font-family: var(--mono);
    font-size: 0.68rem;
    font-weight: 600;
    color: var(--accent);
    background: var(--accent-soft);
    border: 1px solid rgba(201,162,39,0.35);
    border-radius: 999px;
    padding: 0.22rem 0.55rem;
    white-space: nowrap;
}

.topbar-controls {
    display: flex;
    align-items: center;
    gap: clamp(0.4rem, 1.2vw, 0.75rem);
    flex-shrink: 0;
}

/* ── Buttons ── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    padding: 0.5rem 1rem;
    border: none;
    border-radius: 8px;
    font-family: var(--font);
    font-size: clamp(0.78rem, 1.4vw, 0.85rem);
    font-weight: 600;
    cursor: pointer;
    transition: background 0.12s, border-color 0.12s, transform 0.08s;
    touch-action: manipulation;
    color: var(--text);
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--accent); color: #1a1a1a; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary.active {
    box-shadow: 0 0 0 2px rgba(201,162,39,0.45);
}
.btn-secondary { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: #323842; }
.btn-danger {
    background: var(--danger);
    color: #fff;
    font-weight: 700;
    letter-spacing: 0.04em;
    padding: 0.5rem 1.1rem;
}
.btn-danger:hover { background: #a82828; }
.btn-ghost {
    background: var(--surface-2);
    color: var(--text-dim);
    border: 1px solid var(--border);
    padding: 0.45rem 0.55rem;
    min-width: 2.5rem;
    min-height: 2.5rem;
}
.btn-ghost:hover { color: var(--text); border-color: rgba(255,255,255,0.22); background: #323842; }
.btn-ghost[aria-pressed="true"] { color: var(--accent); border-color: var(--accent); }
.btn-ghost .icon-fs-exit[hidden] { display: none; }
.btn-ghost[aria-pressed="true"] .icon-fs-enter { display: none; }
.btn-ghost[aria-pressed="true"] .icon-fs-exit { display: block; }
.btn-toggle {
    min-width: 3.4rem;
    padding-inline: 0.55rem;
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.06em;
}
.btn-toggle.active,
.btn-toggle[aria-pressed="true"] {
    background: rgba(201, 162, 39, 0.2);
    border-color: var(--accent);
    color: var(--accent);
}
.btn-icon {
    background: none;
    border: none;
    color: var(--text-dim);
    font-size: 1.5rem;
    cursor: pointer;
    line-height: 1;
    padding: 0.25rem;
}
.btn-icon:hover { color: var(--text); }
.btn-row {
    display: flex;
    gap: 0.45rem;
    margin-top: 0.35rem;
}
.btn-row .btn { flex: 1; padding: 0.45rem 0.5rem; }
.custom-res-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.4rem;
}
.custom-res-row .field { margin-bottom: 0.35rem; }
.btn-row .btn.recording {
    background: var(--danger);
    color: #fff;
    border-color: var(--danger);
    animation: rec-pulse 1s ease infinite;
}
@keyframes rec-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.65; }
}

/* ── Body ── */
.app-body {
    flex: 1;
    display: flex;
    flex-direction: row;
    min-height: 0;
    min-width: 0;
}

.side-panel {
    width: var(--side-width);
    flex-shrink: 0;
    overflow-y: auto;
    background: var(--surface);
    border-right: 1px solid var(--border);
    padding: 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 0.65rem;
}

.panel-block {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.7rem 0.75rem;
}

.panel-title {
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--accent);
    margin-bottom: 0.55rem;
}

.panel-hint {
    font-size: 0.72rem;
    color: var(--text-dim);
    line-height: 1.4;
    margin-bottom: 0.5rem;
}

.field {
    display: flex;
    flex-direction: column;
    gap: 0.28rem;
    margin-bottom: 0.5rem;
    font-size: 0.75rem;
    color: var(--text-dim);
}
.field span em {
    font-style: normal;
    color: var(--accent);
    font-family: var(--mono);
    font-size: 0.7rem;
}

.select, .input {
    width: 100%;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 7px;
    color: var(--text);
    font-family: var(--font);
    font-size: 0.8rem;
    padding: 0.42rem 0.55rem;
    outline: none;
}
.select:focus, .input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-soft);
}

.checkbox-field {
    flex-direction: row;
    align-items: center;
    gap: 0.5rem;
}
.checkbox-field input { accent-color: var(--accent); width: 1rem; height: 1rem; }

.chip-row {
    display: flex;
    flex-wrap: wrap;
    gap: 0.3rem;
    margin-top: 0.15rem;
}
.chip {
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--text-dim);
    border-radius: 6px;
    padding: 0.28rem 0.45rem;
    font-family: var(--mono);
    font-size: 0.68rem;
    font-weight: 600;
    cursor: pointer;
}
.chip:hover { color: var(--text); border-color: rgba(255,255,255,0.22); }
.chip.active {
    background: var(--accent-soft);
    border-color: var(--accent);
    color: var(--accent);
}

.ctrl {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    font-size: 0.75rem;
    color: var(--text-dim);
    margin-top: 0.55rem;
}
.ctrl input[type="range"] {
    flex: 1;
    accent-color: var(--accent);
}
.ctrl em {
    font-style: normal;
    font-family: var(--mono);
    font-size: 0.7rem;
    min-width: 2.6rem;
    text-align: right;
    color: var(--text);
}

.field input[type="range"] {
    width: 100%;
    accent-color: var(--accent);
}

/* ── Stage ── */
.main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
    padding: clamp(0.5rem, 1.5vmin, 0.85rem);
    gap: 0.45rem;
}

.stage-wrap {
    flex: 1;
    min-height: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #0a0b0d;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    position: relative;
}

.stage-wrap:fullscreen,
.stage:fullscreen {
    background: #000;
    border: none;
    border-radius: 0;
    width: 100%;
    height: 100%;
}

.stage {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #000;
}

.stage canvas {
    display: block;
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
    background: #000;
    image-rendering: auto;
}

.stage canvas.is-under-philips-css {
    opacity: 0;
    pointer-events: none;
}

.philips-css-frame {
    display: none;
    position: absolute;
    border: 0;
    z-index: 2;
    background: #000;
    pointer-events: none;
}
.philips-css-frame.is-on {
    display: block;
}

.stage.stretch canvas {
    width: 100%;
    height: 100%;
    object-fit: fill;
}

.stage-flash {
    position: absolute;
    inset: 0;
    background: #fff;
    opacity: 0;
    pointer-events: none;
    z-index: 5;
}
.stage-flash.on {
    opacity: 1;
    animation: flash-pulse 120ms ease-out;
}
@keyframes flash-pulse {
    from { opacity: 1; }
    to { opacity: 0; }
}

.stage-hud {
    position: absolute;
    top: 2.5%;
    left: 50%;
    transform: translateX(-50%);
    text-align: center;
    z-index: 4;
    pointer-events: none;
    text-shadow: 0 1px 3px rgba(0,0,0,0.9);
}
.stage-hud.hidden { display: none; }
.hud-tc {
    font-family: var(--mono);
    font-size: clamp(0.85rem, 2.2vmin, 1.35rem);
    font-weight: 700;
    color: #fff;
    letter-spacing: 0.06em;
}
.hud-meta {
    font-family: var(--mono);
    font-size: clamp(0.55rem, 1.3vmin, 0.75rem);
    color: rgba(255,255,255,0.85);
    margin-top: 0.15rem;
}

.stage-text {
    position: absolute;
    bottom: 8%;
    left: 50%;
    transform: translateX(-50%);
    text-align: center;
    z-index: 4;
    pointer-events: none;
    max-width: 80%;
    padding: 0.45rem 0.9rem;
    background: rgba(0,0,0,0.55);
    border: 1px solid rgba(255,255,255,0.25);
    border-radius: 4px;
}
.stage-text.hidden { display: none; }
.stage-text-l1 {
    font-weight: 800;
    font-size: clamp(0.95rem, 2.8vmin, 1.8rem);
    letter-spacing: 0.08em;
    color: #fff;
    text-transform: uppercase;
}
.stage-text-l2 {
    font-size: clamp(0.7rem, 1.8vmin, 1.05rem);
    color: #f5e6a8;
    margin-top: 0.15rem;
}

.stage-info {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.35rem;
    font-family: var(--mono);
    font-size: 0.68rem;
    color: var(--text-dim);
    flex-shrink: 0;
}
.stage-info .dot { opacity: 0.4; }

/* ── Bottom bar ── */
.bottombar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.45rem clamp(0.75rem, 2vw, 1.25rem);
    background: var(--surface);
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}

.now-playing {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    min-width: 0;
}
.np-info { display: flex; flex-direction: column; min-width: 0; }
.np-label {
    font-size: 0.58rem;
    font-weight: 700;
    letter-spacing: 0.12em;
    color: var(--accent);
}
.np-title {
    font-size: 0.82rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.bottom-actions {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    font-size: 0.7rem;
    color: var(--text-dim);
    flex-shrink: 0;
}
.bottom-actions kbd {
    font-family: var(--mono);
    font-size: 0.65rem;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 0.12rem 0.35rem;
    color: var(--text);
}

/* ── Modal ── */
.edit-modal {
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--surface);
    color: var(--text);
    padding: 0;
    width: min(420px, 92vw);
    box-shadow: 0 24px 80px rgba(0,0,0,0.55);
}
.edit-modal::backdrop { background: rgba(0,0,0,0.55); }
.edit-form { display: flex; flex-direction: column; }
.edit-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.85rem 1rem;
    border-bottom: 1px solid var(--border);
}
.edit-header h2 { font-size: 1rem; font-weight: 700; }
.edit-body { padding: 1rem; }
.prefs-body .field { margin-bottom: 0.75rem; }
.limits-box {
    margin-top: 0.75rem;
    padding: 0.65rem 0.75rem;
    background: rgba(197, 48, 48, 0.12);
    border: 1px solid rgba(197, 48, 48, 0.35);
    border-radius: 8px;
    font-size: 0.72rem;
    color: var(--text-dim);
    line-height: 1.4;
}
.limits-box strong {
    display: block;
    color: #fca5a5;
    margin-bottom: 0.35rem;
    font-size: 0.7rem;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}
.limits-box ul {
    margin: 0;
    padding-left: 1.1rem;
}
.limits-box li { margin: 0.15rem 0; }
select optgroup {
    color: var(--accent);
    font-weight: 700;
}
.edit-footer {
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    border-top: 1px solid var(--border);
}

@media (max-width: 900px) {
    .app-body { flex-direction: column; }
    .side-panel {
        width: 100%;
        max-height: 42vh;
        border-right: none;
        border-bottom: 1px solid var(--border);
    }
    .ntp-clock { display: none; }
    .bottom-actions { display: none; }
    .status-chip { display: none; }
}
