:root {
    --bg: #0b0c0f;
    --panel: #16181d;
    --panel-soft: #20232a;
    --line: #30343c;
    --text: #f7f7f8;
    --muted: #a7adb7;
    --orange: #f97316;
    --orange-dark: #c2410c;
    --white: #ffffff;
    --danger: #ef4444;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    background: var(--bg);
    color: var(--text);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    letter-spacing: 0;
}

button,
.button-secondary,
input,
select {
    font: inherit;
}

button,
.button-secondary {
    border: 0;
    border-radius: 8px;
    background: var(--orange);
    color: #111;
    cursor: pointer;
    font-weight: 800;
    padding: 10px 14px;
    text-decoration: none;
}

button:hover,
.button-secondary:hover {
    background: #fb923c;
}

.button-secondary {
    background: var(--panel-soft);
    color: var(--text);
    border: 1px solid var(--line);
}

.danger {
    width: 100%;
    background: var(--danger);
    color: var(--white);
}

.subtle-danger {
    margin-bottom: 10px;
    background: #7f1d1d;
}

.topbar {
    height: 58px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 18px;
    border-bottom: 1px solid var(--line);
    background: #111318;
}

.topbar strong {
    color: var(--orange);
    margin-right: 12px;
}

.topbar span,
.topbar a {
    color: var(--muted);
    text-decoration: none;
}

.topbar-actions {
    display: flex;
    gap: 14px;
    align-items: center;
}

.status-pill {
    border-radius: 999px;
    padding: 6px 10px;
    background: #243224;
    color: #bdf8c1;
    font-size: 13px;
}

.workspace {
    height: calc(100vh - 58px);
    display: grid;
    grid-template-columns: 260px minmax(300px, 1fr) 300px;
    min-width: 0;
    overflow: hidden;
}

.sidebar {
    overflow: auto;
    border-right: 1px solid var(--line);
    background: var(--panel);
}

.right-panel {
    border-right: 0;
    border-left: 1px solid var(--line);
}

.sidebar section {
    padding: 18px;
    border-bottom: 1px solid var(--line);
}

h1,
h2,
p {
    margin-top: 0;
}

h2 {
    font-size: 13px;
    text-transform: uppercase;
    color: var(--muted);
    letter-spacing: 0.08em;
}

.section-title {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
}

.program-list,
.element-list {
    display: grid;
    gap: 8px;
}

.program-list a,
.element-item {
    display: block;
    width: 100%;
    color: var(--text);
    background: var(--panel-soft);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 10px;
    text-align: left;
    text-decoration: none;
}

.preset-button {
    width: 100%;
    margin-top: 8px;
    color: #1f1204;
    background: linear-gradient(135deg, #ffd84d, #ff7a18);
    box-shadow: 0 0 18px rgba(255, 122, 24, 0.28);
}

.mini-hint {
    margin: 10px 0 0;
    color: var(--muted);
    font-size: 12px;
    line-height: 1.35;
}

.program-list a.active,
.element-item.active {
    border-color: var(--orange);
    box-shadow: inset 4px 0 0 var(--orange);
}

.element-item small {
    display: block;
    color: var(--muted);
    margin-top: 4px;
}

.stage-panel {
    min-width: 0;
    display: grid;
    grid-template-rows: auto 1fr auto;
    background: #0f1116;
}

.stage-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    padding: 14px 16px;
    border-bottom: 1px solid var(--line);
}

.preview-shell {
    display: grid;
    place-items: center;
    overflow: hidden;
    padding: 20px;
}

.canvas-viewport {
    width: min(100%, calc((100vh - 190px) * 16 / 9));
    aspect-ratio: 16 / 9;
    position: relative;
    overflow: hidden;
    background:
        linear-gradient(rgba(255,255,255,0.05) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255,255,255,0.05) 1px, transparent 1px),
        #050609;
    background-size: 48px 48px;
    border: 1px solid #3a3f49;
}

.safe-area {
    position: absolute;
    inset: 5%;
    border: 1px dashed rgba(255,255,255,0.3);
    pointer-events: none;
    z-index: 1;
    display: none;
}

.canvas-element {
    position: absolute;
    z-index: 2;
    user-select: none;
}

.canvas-element.selected {
    z-index: 5;
}

.lower-third {
    position: absolute;
    padding: 20px 28px;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 8px;
    color: #fff;
    background: var(--orange);
    overflow: hidden;
    user-select: none;
}

.canvas-element.editable {
    cursor: grab;
    outline: 0;
}

.canvas-element {
    cursor: grab;
}

.canvas-element:active {
    cursor: grabbing;
}

.countdown-card {
    overflow: visible;
    color: #211104;
    border: 2px solid rgba(255,255,255,0.9);
    background: linear-gradient(135deg, #fff7dc, #ffd84d 42%, #ff7a18);
    font-family: Poppins, Inter, system-ui, sans-serif;
    font-weight: 900;
}

.countdown-kicker-preview {
    display: inline-block;
    padding: 0.45em 0.8em;
    margin-bottom: 0.55em;
    border-radius: 0.55em;
    background: rgba(20, 11, 4, 0.88);
    color: #fff7dc;
    line-height: 1;
}

.countdown-logo-preview {
    position: absolute;
    z-index: 6;
    cursor: move;
    object-fit: contain;
    padding: 4px;
    border: 1px dashed rgba(255, 255, 255, 0.7);
    border-radius: 8px;
    filter:
        drop-shadow(0 0 10px rgba(255, 255, 255, 0.8))
        drop-shadow(0 0 18px rgba(255, 216, 77, 0.72));
}

.countdown-title-preview {
    max-width: 78%;
    line-height: 1.05;
    text-transform: uppercase;
}

.countdown-time-preview {
    position: absolute;
    right: 0.45em;
    bottom: 0.25em;
    color: #fff7dc;
    line-height: 1;
    text-shadow: 0 4px 0 rgba(0,0,0,0.6);
}

.lower-third .category {
    display: inline-block;
    align-self: flex-start;
    max-width: 100%;
    box-sizing: border-box;
    background: #111;
    color: #fff;
    font-size: 18px;
    line-height: 1;
    font-weight: 900;
    padding: 6px 10px;
    overflow-wrap: anywhere;
    white-space: normal;
}

.lower-third .title {
    font-size: 46px;
    line-height: 0.96;
    font-weight: 950;
    max-width: 100%;
    overflow-wrap: anywhere;
    white-space: normal;
}

.lower-third .subtitle {
    font-size: 25px;
    line-height: 1.06;
    font-weight: 700;
    opacity: 0.92;
    max-width: 100%;
    overflow-wrap: anywhere;
    white-space: normal;
}

.operator-strip {
    display: flex;
    flex-wrap: wrap;
    gap: 18px;
    padding: 11px 16px;
    color: var(--muted);
    border-top: 1px solid var(--line);
    font-size: 13px;
    min-width: 0;
}

.obs-link {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: min(100%, 680px);
    flex: 1 1 520px;
    font-weight: 800;
}

.obs-link input {
    width: 100%;
    min-width: 260px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #080a0e;
    color: var(--text);
    padding: 7px 10px;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
    font-size: 13px;
}

.copy-link {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel-soft);
    color: var(--text);
    padding: 5px 10px;
    font-weight: 800;
    cursor: pointer;
}

.copy-link:hover {
    border-color: var(--orange);
}

.property-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.property-grid label {
    display: grid;
    gap: 6px;
    color: var(--muted);
    font-size: 13px;
}

.property-grid label:nth-child(-n + 3),
.property-grid label:nth-child(12),
.checkbox-row {
    grid-column: 1 / -1;
}

.countdown-controls {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: 1fr;
    gap: 12px;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: rgba(255, 122, 24, 0.06);
}

.countdown-controls[hidden] {
    display: none;
}

input,
select {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #0e1015;
    color: var(--text);
    padding: 9px 10px;
}

input[type="color"] {
    height: 40px;
    padding: 4px;
}

.checkbox-row {
    display: flex !important;
    grid-template-columns: auto 1fr;
    align-items: center;
}

.checkbox-row input {
    width: auto;
}

.hint {
    color: var(--muted);
    line-height: 1.5;
}

.login-screen {
    display: grid;
    place-items: center;
    background: #090a0d;
}

.login-panel {
    width: min(420px, calc(100vw - 32px));
    padding: 32px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
}

.brand-mark {
    color: var(--orange);
    font-weight: 950;
    margin-bottom: 18px;
}

.login-form {
    display: grid;
    gap: 14px;
}

.login-form label {
    display: grid;
    gap: 6px;
    color: var(--muted);
}

.alert {
    margin: 16px 0;
    padding: 10px;
    border-radius: 8px;
    background: #3d1515;
    color: #fecaca;
}

@media (max-width: 1180px) {
    .workspace {
        grid-template-columns: 220px minmax(300px, 1fr) 260px;
    }

    .topbar {
        padding: 0 12px;
    }

    .topbar-actions {
        gap: 10px;
    }

    .sidebar section {
        padding: 14px;
    }

    .stage-toolbar {
        gap: 8px;
        padding: 10px;
    }

    button,
    .button-secondary {
        padding: 9px 11px;
    }

    .preview-shell {
        padding: 12px;
    }

    .property-grid {
        gap: 10px;
    }
}

@media (max-width: 980px) {
    body {
        overflow: hidden;
    }

    .topbar {
        height: 52px;
    }

    .topbar strong {
        margin-right: 8px;
    }

    .topbar .status-pill {
        display: none;
    }

    .workspace {
        height: calc(100vh - 52px);
        grid-template-columns: 190px minmax(280px, 1fr) 220px;
    }

    .program-list a,
    .element-item {
        padding: 9px;
        font-size: 14px;
    }

    h2 {
        font-size: 12px;
    }

    .section-title {
        align-items: flex-start;
        flex-direction: column;
    }

    .section-title button {
        width: 100%;
    }

    .stage-panel {
        grid-template-rows: auto minmax(240px, 1fr) auto;
    }

    .stage-toolbar {
        position: sticky;
        top: 0;
        z-index: 2;
        background: #0f1116;
    }

    .stage-toolbar button,
    .stage-toolbar .button-secondary {
        flex: 1 1 calc(50% - 8px);
        min-width: 0;
        text-align: center;
        white-space: nowrap;
    }

    .canvas-viewport {
        width: 100%;
    }

    .right-panel {
        min-width: 0;
    }

    .property-grid {
        grid-template-columns: 1fr;
    }

    .property-grid label {
        grid-column: 1 / -1;
        font-size: 12px;
    }

    input,
    select {
        padding: 8px;
    }

    .hint {
        font-size: 13px;
    }

    .operator-strip {
        gap: 10px;
        padding: 8px 10px;
    }
}

@media (max-width: 820px) {
    .workspace {
        grid-template-columns: 150px minmax(260px, 1fr) 190px;
    }

    .sidebar section {
        padding: 10px;
    }

    .topbar {
        font-size: 14px;
    }

    .topbar-actions {
        font-size: 13px;
    }

    .stage-toolbar button,
    .stage-toolbar .button-secondary {
        flex-basis: 100%;
    }

    .obs-link {
        flex-basis: 100%;
    }
}
