:root {
    color-scheme: dark;
    --bg: #0a0d12;
    --panel: #12171f;
    --panel-2: #171e28;
    --line: #273140;
    --text: #f4f7fb;
    --muted: #8f9aac;
    --accent: #4ade80;
    --accent-dark: #163d2a;
    --warning: #fbbf24;
    --danger: #fb7185;
    --blue: #60a5fa;
    --radius: 14px;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html { min-width: 320px; background: var(--bg); }

body {
    margin: 0;
    min-height: 100vh;
    color: var(--text);
    background:
        radial-gradient(circle at 15% -10%, rgba(74, 222, 128, .08), transparent 28rem),
        var(--bg);
}

button, input, select, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }

.app-shell {
    width: min(1500px, calc(100% - 40px));
    margin: 0 auto;
    padding: 28px 0 34px;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
    padding-bottom: 24px;
}

h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: clamp(1.35rem, 2vw, 2rem); letter-spacing: .055em; }
h2 { margin-bottom: 0; font-size: 1.08rem; font-weight: 650; }

.eyebrow {
    margin-bottom: 6px;
    color: var(--accent);
    font-size: .68rem;
    font-weight: 750;
    letter-spacing: .16em;
    text-transform: uppercase;
}

.topbar-actions, .control-row { display: flex; align-items: center; gap: 9px; flex-wrap: wrap; }
.inline-form { display: inline-flex; margin: 0; }
.user-badge {
    display: inline-flex;
    min-height: 34px;
    align-items: center;
    padding: 0 11px;
    border: 1px solid #314053;
    border-radius: 999px;
    color: #c7d0dc;
    background: #111822;
    font-size: .69rem;
    font-weight: 700;
    letter-spacing: .04em;
}

.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 40px;
    padding: 0 15px;
    border: 1px solid var(--line);
    border-radius: 9px;
    color: var(--text);
    background: #171d26;
    font-size: .74rem;
    font-weight: 750;
    letter-spacing: .045em;
    text-decoration: none;
    cursor: pointer;
    transition: border-color .15s ease, background .15s ease, opacity .15s ease;
}

.button:hover:not(:disabled) { border-color: #445268; background: #1b2430; }
.button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, summary:focus-visible {
    outline: 2px solid var(--blue);
    outline-offset: 2px;
}
.button:disabled { cursor: not-allowed; opacity: .38; }
.button-primary { color: #07130c; border-color: var(--accent); background: var(--accent); }
.button-primary:hover:not(:disabled) { border-color: #86efac; background: #86efac; }
.button-secondary { border-color: #3b506d; background: #172235; }
.button-danger { color: #fecdd3; border-color: #57303a; background: #28171c; }
.button-quiet { background: transparent; }

.status-strip {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: rgba(18, 23, 31, .9);
    overflow: hidden;
}

.status-item { min-width: 0; padding: 15px 18px; border-right: 1px solid var(--line); }
.status-item:last-child { border-right: 0; }
.status-item > span { display: block; margin-bottom: 5px; color: var(--muted); font-size: .68rem; letter-spacing: .06em; text-transform: uppercase; }
.status { display: flex; align-items: center; gap: 8px; font-size: .82rem; font-weight: 650; }
.status i { width: 8px; height: 8px; border-radius: 50%; background: #64748b; box-shadow: 0 0 0 3px rgba(100, 116, 139, .13); }
.status[data-state="ok"] i { background: var(--accent); box-shadow: 0 0 0 3px rgba(74, 222, 128, .13); }
.status[data-state="busy"] i { background: var(--warning); box-shadow: 0 0 0 3px rgba(251, 191, 36, .13); }
.status[data-state="error"] i { background: var(--danger); box-shadow: 0 0 0 3px rgba(251, 113, 133, .13); }

.notice {
    margin-top: 14px;
    padding: 12px 15px;
    border: 1px solid #3d4e65;
    border-radius: 10px;
    color: #dbeafe;
    background: #101c2d;
    font-size: .84rem;
}
.notice-warning { color: #fef3c7; border-color: #634f20; background: #261f0f; }
.notice-success { color: #d1fae5; border-color: #26563d; background: #10251a; }
.notice-error { color: #ffe4e6; border-color: #6a303d; background: #2b141a; }

.control-card, .panel, .transcript-card {
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: rgba(18, 23, 31, .94);
}
.control-card { margin-top: 14px; padding: 15px; }
.primary-controls { justify-content: flex-start; }
.display-hint { margin: 10px 0 0; color: var(--muted); font-size: .77rem; }

.dashboard-grid {
    display: grid;
    grid-template-columns: 1fr 1.35fr 1fr;
    gap: 14px;
    margin-top: 14px;
}
.panel { min-width: 0; padding: 18px; }
.audio-panel { grid-row: span 2; }
.context-panel { grid-column: span 2; }
.audience-panel { grid-column: 1 / -1; }
.panel-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 17px; }
.text-button { padding: 0; border: 0; color: var(--blue); background: none; font-size: .75rem; cursor: pointer; }
.info-badge { padding: 4px 7px; border: 1px solid #38475a; border-radius: 999px; color: var(--muted); font-size: .61rem; font-weight: 750; letter-spacing: .08em; }

.field { display: flex; min-width: 0; flex-direction: column; gap: 7px; color: var(--muted); font-size: .72rem; font-weight: 620; }
.field input, .field select, .field textarea {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 8px;
    color: var(--text);
    background: #0c1118;
    padding: 10px 11px;
    font-weight: 450;
}
.field select { height: 40px; }
.field textarea { resize: vertical; line-height: 1.45; }
.field input::placeholder, .field textarea::placeholder { color: #596577; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 13px; }
.field-wide { grid-column: 1 / -1; }
.settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.meter-block { margin-top: 20px; }
.meter-label { display: flex; justify-content: space-between; margin-bottom: 8px; color: var(--muted); font-size: .65rem; font-weight: 750; letter-spacing: .08em; }
.meter-label strong { color: #a8b2c2; }
.meter {
    position: relative;
    height: 15px;
    border: 1px solid #293444;
    border-radius: 99px;
    background: repeating-linear-gradient(90deg, #1b2430 0 8px, #0c1118 8px 11px);
    overflow: hidden;
}
.meter-fill {
    width: 0;
    height: 100%;
    background: linear-gradient(90deg, #22c55e 0 74%, #fbbf24 87%, #ef4444 100%);
    transition: width .06s linear;
}
.meter-clip { position: absolute; inset: 0 7px 0 auto; width: 2px; background: rgba(255,255,255,.45); }

.advanced { margin-top: 20px; padding-top: 15px; border-top: 1px solid var(--line); }
.advanced summary { color: #bec7d4; font-size: .77rem; cursor: pointer; }
.advanced-grid { display: grid; gap: 12px; margin-top: 15px; }
.check-field { display: flex; align-items: center; gap: 9px; color: #c4cbd6; font-size: .78rem; }
.check-field input { accent-color: var(--accent); }

.toggle-field { display: flex; align-items: center; gap: 10px; color: #d5dbe4; font-size: .79rem; cursor: pointer; }
.toggle-field input { position: absolute; opacity: 0; pointer-events: none; }
.toggle { position: relative; width: 38px; height: 21px; flex: 0 0 auto; border-radius: 99px; background: #354052; transition: background .15s; }
.toggle::after { content: ""; position: absolute; top: 3px; left: 3px; width: 15px; height: 15px; border-radius: 50%; background: white; transition: transform .15s; }
.toggle-field input:checked + .toggle { background: #229651; }
.toggle-field input:checked + .toggle::after { transform: translateX(17px); }
.toggle-field input:focus-visible + .toggle { outline: 2px solid var(--blue); outline-offset: 2px; }
.muted { margin: 10px 0 14px; color: var(--muted); font-size: .74rem; line-height: 1.45; }

.audience-layout { display: grid; grid-template-columns: minmax(280px, .8fr) minmax(380px, 1.2fr); gap: 22px; align-items: start; }
.audience-link-area { min-width: 0; }
.audience-link-area[hidden] { display: none; }
.audience-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.audience-network-hint { margin: 0; color: #f8c970; font-size: .72rem; line-height: 1.45; }
.viewer-broadcast-status {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 5px 9px;
    border: 1px solid #38475a;
    border-radius: 999px;
    color: #8d99aa;
    font-size: .65rem;
    font-weight: 760;
    letter-spacing: .07em;
}
.viewer-broadcast-status i { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.viewer-broadcast-status[data-state="live"] { color: #5ee38c; border-color: #285b3d; }
.viewer-broadcast-status[data-state="busy"] { color: #f8c970; border-color: #655226; }
.viewer-broadcast-status[data-state="error"] { color: #ff8e9d; border-color: #6a303d; }

.transcript-grid { display: grid; grid-template-columns: .86fr 1.14fr; gap: 14px; margin-top: 14px; }
.transcript-card { min-width: 0; padding: 18px; }
.transcript-card header { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 14px; }
.transcript-card header > span { color: var(--muted); font-size: .65rem; text-transform: uppercase; }
.transcript-text { height: 210px; overflow-y: auto; padding: 17px; border: 1px solid #273141; border-radius: 10px; background: #0b0f15; font-size: clamp(1rem, 1.45vw, 1.32rem); line-height: 1.55; white-space: pre-wrap; }
.translation-card .transcript-text { border-color: #294336; font-size: clamp(1.1rem, 1.7vw, 1.48rem); }
.transcript-text.empty { color: #667287; }

.footer-note { display: flex; justify-content: center; gap: 22px; padding: 18px 0 0; color: #616d7d; font-size: .65rem; letter-spacing: .04em; }

.glossary-shell { width: min(1120px, calc(100% - 40px)); }
.glossary-add { margin-top: 14px; }
.glossary-form { display: grid; grid-template-columns: 1fr 1fr auto; align-items: end; gap: 12px; }
.term-list { display: grid; gap: 8px; }
.term-row { display: grid; grid-template-columns: 1fr 1fr auto auto; align-items: center; gap: 8px; padding-bottom: 8px; border-bottom: 1px solid #202936; }
.term-row:last-child { padding-bottom: 0; border-bottom: 0; }
.glossary-list { margin-top: 14px; }
.sr-only { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

.login-body {
    display: grid;
    min-height: 100vh;
    place-items: center;
    padding: 24px;
}
.login-shell { width: min(430px, 100%); }
.login-card {
    padding: clamp(25px, 6vw, 38px);
    border: 1px solid var(--line);
    border-radius: 18px;
    background: rgba(18, 23, 31, .96);
    box-shadow: 0 24px 80px rgba(0, 0, 0, .35);
}
.login-heading { margin-bottom: 24px; }
.login-heading h1 { font-size: clamp(1.25rem, 5vw, 1.65rem); }
.login-heading > p:last-child { margin: 11px 0 0; color: var(--muted); font-size: .84rem; line-height: 1.5; }
.login-card .notice { margin: 0 0 17px; }
.login-form { display: grid; gap: 15px; }
.login-form .field { font-size: .78rem; }
.login-form .field input { min-height: 44px; }
.login-submit { width: 100%; min-height: 45px; margin-top: 3px; }
.login-security-note { margin: 20px 0 0; color: #697688; font-size: .69rem; line-height: 1.5; text-align: center; }

@media (max-width: 1050px) {
    .dashboard-grid { grid-template-columns: 1fr 1fr; }
    .audio-panel { grid-row: auto; }
    .context-panel { grid-column: 1 / -1; }
}

@media (max-width: 760px) {
    .app-shell, .glossary-shell { width: min(100% - 22px, 1500px); padding-top: 18px; }
    .topbar { align-items: flex-start; flex-direction: column; }
    .status-strip { grid-template-columns: 1fr 1fr; }
    .status-item:nth-child(2) { border-right: 0; }
    .status-item:nth-child(-n+2) { border-bottom: 1px solid var(--line); }
    .dashboard-grid, .transcript-grid { grid-template-columns: 1fr; }
    .context-panel { grid-column: auto; }
    .form-grid, .settings-grid, .audience-layout { grid-template-columns: 1fr; }
    .field-wide { grid-column: auto; }
    .glossary-form, .term-row { grid-template-columns: 1fr; }
    .footer-note { align-items: center; flex-direction: column; gap: 5px; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { transition: none !important; }
}
