:root {
    color-scheme: dark;
    --bg: #101214;
    --surface: #171b20;
    --surface-2: #20262d;
    --line: #303843;
    --text: #f6f7f9;
    --muted: #aab2bf;
    --accent: #2dd4bf;
    --accent-strong: #14b8a6;
    --danger: #ef4444;
    --danger-dark: #b91c1c;
    --warning: #f59e0b;
    --focus: #fde68a;
    --shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
}

* {
    box-sizing: border-box;
}

html,
body {
    min-height: 100%;
}

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

button,
input,
select,
textarea {
    font: inherit;
}

button {
    cursor: pointer;
}

button:disabled {
    cursor: not-allowed;
    opacity: 0.55;
}

:focus-visible {
    outline: 3px solid var(--focus);
    outline-offset: 3px;
}

[hidden] {
    display: none !important;
}

.auth-view {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
}

.auth-panel,
.modal-panel,
.timer-panel,
.quick-panel,
.markers-panel,
.videocast-item,
.empty-state {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
}

.auth-panel {
    width: min(460px, 100%);
    padding: 32px;
    box-shadow: var(--shadow);
}

.auth-panel h1,
.section-heading h1,
.studio-meta h1 {
    margin: 0;
    line-height: 1.05;
}

.stack {
    display: grid;
    gap: 14px;
    margin-top: 28px;
}

label,
.filter-label {
    color: var(--muted);
    font-size: 0.92rem;
    font-weight: 700;
}

input,
select,
textarea {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #0b0d0f;
    color: var(--text);
    padding: 12px 14px;
}

textarea {
    resize: vertical;
}

.form-message {
    min-height: 1.4em;
    margin: 0;
    color: var(--muted);
}

.form-message.error {
    color: #fecaca;
}

.app-shell {
    min-height: 100vh;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 30;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 14px clamp(16px, 3vw, 32px);
    background: rgba(16, 18, 20, 0.92);
    border-bottom: 1px solid var(--line);
    backdrop-filter: blur(12px);
}

.brand-button {
    border: 0;
    background: transparent;
    color: var(--text);
    padding: 8px 0;
    font-weight: 800;
    font-size: 1.02rem;
}

.topbar-actions,
.studio-actions,
.toolbar-actions,
.export-actions,
.timer-controls,
.modal-actions,
.settings-row-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.main-layout {
    width: min(1280px, 100%);
    margin: 0 auto;
    padding: 28px clamp(16px, 3vw, 32px) 48px;
}

.view {
    display: grid;
    gap: 22px;
}

.section-heading,
.studio-header,
.marker-toolbar {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 18px;
}

.section-heading.compact {
    align-items: center;
}

.eyebrow {
    margin: 0 0 8px;
    color: var(--accent);
    font-size: 0.78rem;
    font-weight: 800;
    letter-spacing: 0;
    text-transform: uppercase;
}

.muted {
    color: var(--muted);
}

.primary-button,
.ghost-button,
.danger-button,
.warning-button,
.icon-button {
    min-height: 44px;
    border-radius: 8px;
    border: 1px solid transparent;
    padding: 0 16px;
    color: var(--text);
    font-weight: 800;
}

.primary-button {
    background: var(--accent-strong);
    color: #031716;
}

.primary-button:hover {
    background: var(--accent);
}

.ghost-button {
    background: var(--surface-2);
    border-color: var(--line);
}

.ghost-button:hover {
    border-color: var(--accent);
}

.danger-button {
    background: var(--danger-dark);
}

.danger-button:hover {
    background: var(--danger);
}

.warning-button {
    background: #a16207;
}

.warning-button:hover {
    background: var(--warning);
    color: #140d03;
}

.ghost-button.small {
    min-height: 36px;
    padding: 0 12px;
}

.icon-button {
    width: 44px;
    padding: 0;
    background: var(--surface-2);
    border-color: var(--line);
    font-size: 1.4rem;
}

.videocast-list {
    display: grid;
    gap: 12px;
}

.videocast-item {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 18px;
    padding: 18px;
}

.videocast-title {
    margin: 0 0 8px;
    font-size: 1.22rem;
}

.videocast-details {
    display: flex;
    flex-wrap: wrap;
    gap: 10px 18px;
    margin: 0;
    color: var(--muted);
}

.videocast-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.empty-state {
    padding: 26px;
    color: var(--muted);
}

.studio-view {
    gap: 18px;
}

.studio-header {
    align-items: center;
}

.studio-meta {
    min-width: 0;
    flex: 1;
}

.studio-meta h1 {
    overflow-wrap: anywhere;
}

.timer-panel {
    display: grid;
    gap: 18px;
    padding: clamp(22px, 4vw, 34px);
}

.timer-display {
    font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
    font-size: clamp(3.1rem, 11vw, 9rem);
    line-height: 1;
    text-align: center;
    font-variant-numeric: tabular-nums;
}

.timer-controls {
    justify-content: center;
}

.timer-controls button {
    min-width: 120px;
    min-height: 54px;
}

.quick-panel,
.markers-panel {
    padding: 18px;
}

.category-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
    gap: 12px;
}

.category-button {
    min-height: 84px;
    border: 1px solid var(--line);
    border-left-width: 8px;
    border-radius: 8px;
    background: var(--surface-2);
    color: var(--text);
    padding: 14px;
    text-align: left;
    display: grid;
    gap: 6px;
}

.category-button:hover {
    transform: translateY(-1px);
    border-top-color: rgba(255, 255, 255, 0.2);
    border-right-color: rgba(255, 255, 255, 0.2);
    border-bottom-color: rgba(255, 255, 255, 0.2);
}

.category-shortcut {
    color: var(--muted);
    font-size: 0.82rem;
    font-weight: 900;
}

.category-name {
    font-size: 1.06rem;
    font-weight: 900;
}

.shortcut-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 14px;
    color: var(--muted);
}

.shortcut-chip,
.category-pill {
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: 6px 10px;
    background: #0b0d0f;
    font-size: 0.86rem;
    font-weight: 800;
}

.marker-toolbar {
    margin-bottom: 14px;
    align-items: center;
}

.toolbar-actions {
    justify-content: flex-end;
}

.toolbar-actions select {
    min-width: 210px;
}

.markers-list {
    display: grid;
    gap: 10px;
}

.marker-row {
    display: grid;
    grid-template-columns: 120px minmax(150px, 220px) minmax(0, 1fr) auto;
    gap: 12px;
    align-items: center;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #0d1013;
}

.marker-row:hover {
    border-color: var(--accent);
}

.marker-row.flash {
    animation: flashRow 1.4s ease-out;
}

@keyframes flashRow {
    0% {
        border-color: var(--focus);
        background: rgba(253, 230, 138, 0.14);
    }
    100% {
        border-color: var(--line);
        background: #0d1013;
    }
}

.time-button {
    min-height: 42px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface-2);
    color: var(--text);
    font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
    font-weight: 900;
}

.category-pill {
    display: inline-flex;
    align-items: center;
    width: fit-content;
    max-width: 100%;
    border-left: 8px solid currentColor;
    color: var(--text);
}

.marker-note {
    margin: 0;
    color: var(--text);
    overflow-wrap: anywhere;
}

.marker-note.empty {
    color: var(--muted);
    font-style: italic;
}

.marker-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
}

.modal {
    position: fixed;
    inset: 0;
    z-index: 60;
    display: grid;
    place-items: center;
    padding: 18px;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.72);
}

.modal-panel {
    position: relative;
    z-index: 1;
    width: min(560px, 100%);
    max-height: min(92vh, 900px);
    overflow: auto;
    padding: 22px;
    box-shadow: var(--shadow);
    display: grid;
    gap: 14px;
}

.modal-panel.wide {
    width: min(760px, 100%);
}

.modal-header,
.participants-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.modal-header h2 {
    margin: 0;
}

.modal-actions {
    justify-content: flex-end;
    margin-top: 4px;
}

.modal-actions.split {
    justify-content: space-between;
}

.participants-list,
.categories-editor {
    display: grid;
    gap: 10px;
}

.participant-row,
.category-editor-row {
    display: grid;
    gap: 8px;
    align-items: center;
}

.participant-row {
    grid-template-columns: minmax(0, 1fr) auto;
}

.category-editor-row {
    grid-template-columns: 56px minmax(0, 1fr) auto;
}

.category-editor-row input[type="color"] {
    height: 46px;
    padding: 3px;
}

.toast-container {
    position: fixed;
    right: 16px;
    bottom: 16px;
    z-index: 100;
    display: grid;
    gap: 10px;
    width: min(420px, calc(100vw - 32px));
}

.toast {
    border: 1px solid var(--line);
    border-left-width: 6px;
    border-radius: 8px;
    background: var(--surface-2);
    padding: 14px 16px;
    box-shadow: var(--shadow);
}

.toast.error {
    border-left-color: var(--danger);
}

.toast.success {
    border-left-color: var(--accent);
}

.clock-page {
    min-height: 100vh;
    background: #080a0c;
}

.clock-shell {
    min-height: 100vh;
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
    padding: clamp(18px, 3vw, 34px);
}

.clock-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 18px;
}

.clock-header h1 {
    margin: 0;
    font-size: clamp(1.6rem, 3vw, 3rem);
    overflow-wrap: anywhere;
}

.clock-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.clock-stage {
    display: grid;
    place-items: center;
    align-content: center;
    gap: 20px;
    min-height: 0;
}

.clock-display {
    font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
    font-size: clamp(5rem, 19vw, 18rem);
    line-height: 0.95;
    font-variant-numeric: tabular-nums;
    color: var(--text);
    text-align: center;
}

.clock-run-status {
    margin: 0;
    color: var(--accent);
    font-size: clamp(1.2rem, 3vw, 2.2rem);
    font-weight: 900;
}

.clock-connection-status {
    margin: 0;
    color: var(--muted);
    font-size: clamp(0.95rem, 2vw, 1.3rem);
    text-align: center;
}

@media (max-width: 860px) {
    .section-heading,
    .studio-header,
    .marker-toolbar,
    .videocast-item {
        align-items: stretch;
        flex-direction: column;
        grid-template-columns: 1fr;
    }

    .studio-header {
        display: grid;
        grid-template-columns: 1fr;
    }

    .videocast-actions,
    .studio-actions,
    .toolbar-actions {
        justify-content: flex-start;
    }

    .marker-row {
        grid-template-columns: 1fr;
    }

    .marker-actions {
        justify-content: flex-start;
    }

    .timer-controls button {
        flex: 1 1 130px;
    }
}

@media (max-width: 560px) {
    .topbar {
        align-items: stretch;
        flex-direction: column;
    }

    .topbar-actions {
        width: 100%;
    }

    .topbar-actions button,
    .export-actions button {
        flex: 1;
    }

    .auth-panel,
    .quick-panel,
    .markers-panel,
    .timer-panel,
    .modal-panel {
        padding: 18px;
    }

    .category-editor-row {
        grid-template-columns: 48px minmax(0, 1fr);
    }

    .category-editor-row button {
        grid-column: 1 / -1;
    }

    .clock-header {
        align-items: stretch;
        flex-direction: column;
    }

    .clock-actions button {
        flex: 1;
    }
}
