:root {
    color-scheme: dark;
    --bg: #12161c;
    --bg-deep: #0c1015;
    --panel: rgba(20, 26, 34, 0.96);
    --panel-soft: rgba(30, 37, 47, 0.92);
    --ink: #eef3f8;
    --muted: #9da8b6;
    --line: rgba(238, 243, 248, 0.08);
    --line-strong: rgba(238, 243, 248, 0.14);
    --accent: #4aa2ff;
    --accent-strong: #2d73d6;
    --accent-soft: rgba(74, 162, 255, 0.14);
    --fb: #1877f2;
    --xink: #f6f7f9;
    --ok: #6ec7a3;
    --warn: #d8b06d;
    --danger: #d48176;
    --danger-soft: rgba(212, 129, 118, 0.12);
    --shadow-xl: 0 30px 70px rgba(0, 0, 0, 0.36);
    --shadow-lg: 0 18px 34px rgba(0, 0, 0, 0.26);
    --shadow-sm: 0 10px 18px rgba(0, 0, 0, 0.18);
    --radius-2xl: 34px;
    --radius-xl: 24px;
    --radius-lg: 18px;
    --radius-md: 14px;
    --ease-soft: cubic-bezier(.2, .8, .2, 1);
}

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

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

body {
    font-family: "Manrope", "Segoe UI", sans-serif;
    color: var(--ink);
    background:
        radial-gradient(circle at 12% 10%, rgba(74, 162, 255, 0.1), transparent 20%),
        radial-gradient(circle at 86% 12%, rgba(255, 255, 255, 0.04), transparent 18%),
        linear-gradient(180deg, #171d25 0%, var(--bg) 36%, var(--bg-deep) 100%);
}

body::before {
    content: "";
    position: fixed;
    inset: 0;
    pointer-events: none;
    background:
        linear-gradient(180deg, rgba(255, 255, 255, 0.04), transparent 28%),
        repeating-linear-gradient(0deg, rgba(255, 255, 255, 0.02) 0, rgba(255, 255, 255, 0.02) 1px, transparent 1px, transparent 92px);
    mask-image: linear-gradient(180deg, rgba(0, 0, 0, 0.46), transparent 82%);
}

body.app-ready .broadcast-cover,
body.app-ready .switchboard-grid,
body.app-ready .notice {
    animation: fadeUp 560ms var(--ease-soft) both;
}

body.app-ready .switchboard-grid {
    animation-delay: 90ms;
}

body.app-ready .notice {
    animation-delay: 130ms;
}

body.is-busy {
    cursor: progress;
}

body.is-modal-open {
    overflow: hidden;
}

.hidden {
    display: none !important;
}

.shell {
    width: min(1500px, calc(100% - 40px));
    margin: 28px auto 44px;
    position: relative;
    z-index: 1;
}

.shell > .notice {
    margin-bottom: 24px;
}

.broadcast-cover,
.rail-card,
.console-panel,
.state-card,
.panel,
.notice,
.modal-panel,
.result-card {
    border: 1px solid var(--line);
    background: var(--panel);
    box-shadow: var(--shadow-xl);
}

.eyebrow {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    margin: 0 0 10px;
    font-size: 0.75rem;
    font-weight: 800;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: rgba(157, 168, 182, 0.88);
}

.eyebrow::before {
    content: "";
    width: 18px;
    height: 1px;
    background: currentColor;
    opacity: 0.72;
}

.broadcast-cover {
    display: grid;
    gap: 18px;
    padding: 32px;
    border-radius: var(--radius-2xl);
    margin-bottom: 24px;
    background:
        linear-gradient(180deg, rgba(20, 26, 34, 0.98) 0%, rgba(16, 21, 28, 0.98) 100%);
}

.cover-copy h1,
.rail-card h2,
.panel-head h2,
.state-card strong,
.modal-head h2,
.result-head h3 {
    margin: 0;
    letter-spacing: -0.05em;
}

.cover-copy h1 {
    font-size: 30px;
    line-height: 1;
}

.lead,
.panel-copy,
.rail-card p,
.rail-list,
.form-note,
.state-card p,
.notice p,
.modal-head p,
.result-copy,
.bullet-list li {
    margin: 0;
    color: var(--muted);
    line-height: 1.72;
}

.lead {
    max-width: 70ch;
    font-size: 1.03rem;
}

.cover-pills {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.cover-pills span {
    padding: 10px 14px;
    border-radius: 999px;
    border: 1px solid rgba(74, 162, 255, 0.12);
    background: rgba(74, 162, 255, 0.08);
    color: #cde1ff;
    font-size: 0.88rem;
    font-weight: 800;
}

.switchboard-grid {
    display: grid;
    grid-template-columns: 280px minmax(0, 1fr) 340px;
    gap: 22px;
    align-items: start;
}

.source-rail,
.state-rail {
    display: grid;
    gap: 18px;
}

.state-rail {
    position: sticky;
    top: 24px;
}

.rail-card,
.console-panel,
.state-card,
.panel {
    padding: 24px;
    border-radius: var(--radius-xl);
}

.rail-card {
    background:
        linear-gradient(180deg, rgba(23, 30, 39, 0.98) 0%, rgba(17, 23, 31, 0.98) 100%);
}

.rail-card-dark {
    background:
        linear-gradient(180deg, rgba(31, 61, 107, 0.98) 0%, rgba(20, 39, 76, 0.98) 100%);
}

.rail-card h2 {
    font-size: 1.52rem;
    line-height: 1.08;
    margin-bottom: 12px;
}

.rail-list,
.bullet-list {
    display: grid;
    gap: 10px;
    padding-left: 18px;
}

.console-panel {
    background:
        linear-gradient(180deg, rgba(18, 24, 32, 0.98) 0%, rgba(14, 19, 26, 0.98) 100%);
}

.panel-head {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 18px;
    margin-bottom: 20px;
}

.panel-head.compact {
    margin-bottom: 16px;
}

.panel-head h2 {
    font-size: 1.64rem;
    line-height: 1.04;
}

.head-actions {
    display: flex;
    justify-content: flex-end;
}

.rewrite-form {
    display: grid;
    gap: 18px;
}

.field {
    display: grid;
    gap: 10px;
}

.field > span {
    font-size: 0.86rem;
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: rgba(238, 243, 248, 0.82);
}

.field-lg textarea {
    min-height: 260px;
}

.tuning-tray {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 14px;
    padding: 16px;
    border-radius: 20px;
    border: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.03);
}

.intent-row {
    display: grid;
    gap: 16px;
}

textarea,
input[type="text"],
select {
    width: 100%;
    min-height: 58px;
    padding: 16px 18px;
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-md);
    background: rgba(255, 255, 255, 0.04);
    color: var(--ink);
    font: inherit;
    transition: border-color 180ms var(--ease-soft), box-shadow 180ms var(--ease-soft), background 180ms var(--ease-soft), transform 180ms var(--ease-soft);
}

textarea {
    resize: vertical;
    min-height: 132px;
    line-height: 1.65;
}

textarea::placeholder,
input[type="text"]::placeholder {
    color: rgba(157, 168, 182, 0.62);
}

textarea:focus,
input[type="text"]:focus,
select:focus {
    outline: none;
    border-color: rgba(74, 162, 255, 0.36);
    background: rgba(255, 255, 255, 0.06);
    box-shadow: 0 0 0 4px rgba(74, 162, 255, 0.08);
    transform: translateY(-1px);
}

select {
    appearance: none;
    padding-right: 48px;
    background-image:
        linear-gradient(45deg, transparent 50%, rgba(238, 243, 248, 0.74) 50%),
        linear-gradient(135deg, rgba(238, 243, 248, 0.74) 50%, transparent 50%);
    background-position:
        calc(100% - 24px) calc(50% - 3px),
        calc(100% - 16px) calc(50% - 3px);
    background-size: 8px 8px, 8px 8px;
    background-repeat: no-repeat;
}

button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 52px;
    padding: 0 22px;
    border: 0;
    border-radius: 999px;
    font: inherit;
    font-weight: 800;
    letter-spacing: -0.02em;
    cursor: pointer;
    transition: transform 180ms var(--ease-soft), box-shadow 180ms var(--ease-soft), background 180ms var(--ease-soft), opacity 180ms var(--ease-soft);
}

button:hover:not(:disabled) {
    transform: translateY(-1px);
}

button:active:not(:disabled) {
    transform: translateY(0);
}

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

#rewrite-button,
.copy-button {
    color: #f5fbff;
    background: linear-gradient(180deg, var(--accent) 0%, var(--accent-strong) 100%);
    box-shadow: 0 14px 28px rgba(45, 115, 214, 0.2);
}

.ghost-button {
    color: var(--ink);
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--line);
}

.action-row {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
}

.console-actions {
    display: grid;
    gap: 14px;
}

.mode-note {
    margin-top: -4px;
}

.state-card {
    display: grid;
    gap: 10px;
    background:
        linear-gradient(180deg, rgba(19, 25, 33, 0.98) 0%, rgba(16, 21, 28, 0.98) 100%);
}

.state-card strong {
    font-size: 1.52rem;
    line-height: 1.08;
}

.state-card-muted {
    background:
        linear-gradient(180deg, rgba(24, 35, 49, 0.98) 0%, rgba(16, 21, 28, 0.98) 100%);
}

.notice {
    padding: 18px 20px;
}

.warning {
    color: var(--warn);
    background: linear-gradient(180deg, rgba(52, 42, 28, 0.96) 0%, rgba(41, 32, 22, 0.96) 100%);
}

.success {
    color: var(--ok);
    background: linear-gradient(180deg, rgba(28, 52, 44, 0.96) 0%, rgba(22, 39, 33, 0.96) 100%);
}

.error {
    color: var(--danger);
    background: var(--danger-soft);
}

.ad-shell {
    background:
        linear-gradient(180deg, rgba(19, 25, 33, 0.98) 0%, rgba(16, 21, 28, 0.98) 100%);
}

.ad-slot,
.ad-placeholder {
    border: 1px solid var(--line);
    border-radius: 22px;
    min-height: 360px;
    background: rgba(255, 255, 255, 0.03);
    overflow: hidden;
}

.ad-placeholder {
    padding: 16px;
}

.ad-mockup {
    position: relative;
    min-height: 324px;
    height: 100%;
    border-radius: 20px;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.04), rgba(255, 255, 255, 0.02));
}

.ad-mockup::before {
    content: "";
    position: absolute;
    inset: 16px;
    border-radius: 18px;
    border: 1px solid rgba(74, 162, 255, 0.12);
}

.ad-mockup-top,
.ad-mockup-feed,
.ad-mockup-badge {
    position: absolute;
}

.ad-mockup-top {
    top: 30px;
    left: 28px;
    width: 120px;
    height: 18px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.12);
}

.ad-mockup-feed {
    inset: 82px 28px 40px;
    display: grid;
    gap: 14px;
}

.ad-mockup-feed span {
    display: block;
    height: 62px;
    border-radius: 18px;
    background: linear-gradient(90deg, rgba(74, 162, 255, 0.16), rgba(255, 255, 255, 0.05));
}

.ad-mockup-badge {
    right: 28px;
    bottom: 26px;
    width: 120px;
    height: 120px;
    border-radius: 999px;
    display: grid;
    place-content: center;
    justify-items: center;
    gap: 2px;
    color: #eaf5ff;
    background: linear-gradient(180deg, rgba(74, 162, 255, 0.98) 0%, rgba(45, 115, 214, 0.94) 100%);
    font-size: 1.4rem;
    font-weight: 900;
    letter-spacing: 0.08em;
}

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

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(8, 12, 16, 0.64);
    backdrop-filter: blur(10px);
}

.modal-panel {
    position: relative;
    width: min(1100px, 100%);
    max-height: min(88vh, 960px);
    overflow: auto;
    padding: 28px;
    border-radius: 28px;
    background: linear-gradient(180deg, rgba(21, 28, 37, 0.99) 0%, rgba(15, 20, 27, 0.99) 100%);
}

.modal-head {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 18px;
    margin-bottom: 20px;
}

.modal-head h2 {
    font-size: 1.82rem;
    line-height: 1.04;
}

.result-stack {
    display: grid;
    gap: 16px;
}

.result-card {
    padding: 22px;
    border-radius: 22px;
    background: rgba(255, 255, 255, 0.03);
    box-shadow: var(--shadow-sm);
}

.result-card-primary {
    background: linear-gradient(180deg, rgba(74, 162, 255, 0.08) 0%, rgba(255, 255, 255, 0.03) 100%);
}

.result-head {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 14px;
    margin-bottom: 14px;
}

.result-head h3 {
    font-size: 1.24rem;
}

.result-copy {
    margin: 0;
    white-space: pre-wrap;
    word-break: break-word;
    font-family: "SFMono-Regular", Consolas, monospace;
    font-size: 0.95rem;
    line-height: 1.7;
}

.copy-button.is-copied {
    background: linear-gradient(180deg, #5db894 0%, #3f8d6f 100%);
}

.notice.is-visible,
.result-stack.is-entering {
    animation: fadeUp 360ms var(--ease-soft) both;
}

@keyframes fadeUp {
    from {
        opacity: 0;
        transform: translateY(14px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@media (max-width: 1260px) {
    .switchboard-grid,
    .tuning-tray {
        grid-template-columns: 1fr;
    }

    .state-rail {
        position: static;
    }
}

@media (max-width: 760px) {
    .shell {
        width: min(100% - 20px, 100%);
        margin: 18px auto 28px;
    }

    .broadcast-cover,
    .rail-card,
    .console-panel,
    .state-card,
    .panel,
    .modal-panel,
    .result-card {
        padding: 20px;
    }

    .panel-head,
    .modal-head,
    .head-actions,
    .action-row,
    .result-head {
        flex-direction: column;
        align-items: stretch;
    }

    button,
    .ghost-button,
    #rewrite-button,
    .copy-button {
        width: 100%;
    }
}
