:root {
    --ink: #111820;
    --navy: #17222c;
    --surface: #22303c;
    --surface-2: #2c3a46;
    --line: #d8dde2;
    --muted: #6d7782;
    --gold: #cbad69;
    --gold-2: #b99a54;
    --paper: #f6f7f8;
    --white: #ffffff;
    --danger: #b42318;
    --ok: #147a55;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    color: var(--ink);
    background: var(--paper);
    font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select {
    font: inherit;
}

button {
    border: 0;
    cursor: pointer;
}

.hidden {
    display: none !important;
}

.app-shell {
    min-height: 100vh;
    display: grid;
    grid-template-rows: auto 1fr;
}

.topbar {
    min-height: 76px;
    padding: 18px 28px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    color: var(--white);
    background: var(--navy);
    border-bottom: 4px solid var(--gold);
}

.brand {
    display: flex;
    align-items: center;
    gap: 14px;
}

.brand-mark {
    width: 42px;
    height: 42px;
    display: grid;
    place-items: center;
    color: var(--navy);
    background: var(--gold);
    border-radius: 8px;
    font-size: 13px;
    font-weight: 900;
}

.brand strong {
    display: block;
    font-size: 18px;
    font-weight: 800;
}

.brand span,
.section-heading span,
.panel-header span,
.field-label,
label {
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0;
    text-transform: uppercase;
}

.brand span {
    color: #bac3ca;
    font-size: 12px;
    text-transform: none;
}

.session-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

.status-pill,
.language-chip {
    display: inline-flex;
    align-items: center;
    min-height: 30px;
    padding: 6px 11px;
    color: var(--navy);
    background: var(--gold);
    border-radius: 999px;
    font-size: 12px;
    font-weight: 800;
}

.topbar-ghost-button {
    min-height: 38px;
    padding: 0 14px;
    color: var(--white);
    background: transparent;
    border: 1px solid rgba(255, 255, 255, 0.28);
    border-radius: 8px;
}

main {
    width: 100%;
    padding: 30px;
}

.auth-panel {
    width: min(460px, 100%);
    margin: 8vh auto 0;
    padding: 28px;
    background: var(--white);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: 0 22px 70px rgba(17, 24, 32, 0.10);
}

.section-heading {
    margin-bottom: 26px;
}

.section-heading h1 {
    margin: 6px 0 0;
    color: var(--ink);
    font-size: clamp(28px, 4vw, 42px);
    line-height: 1.05;
    font-weight: 800;
}

.section-heading.compact h1 {
    font-size: 28px;
}

.login-form,
.control-rail {
    display: grid;
    gap: 18px;
}

label {
    display: grid;
    gap: 8px;
}

input,
select {
    width: 100%;
    min-height: 46px;
    padding: 0 12px;
    color: var(--ink);
    background: var(--white);
    border: 1px solid var(--line);
    border-radius: 8px;
    outline: none;
}

input:focus,
select:focus {
    border-color: var(--gold);
    box-shadow: 0 0 0 3px rgba(203, 173, 105, 0.26);
}

.primary-button,
.start-button,
.stop-button {
    min-height: 48px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    color: var(--navy);
    background: var(--gold);
    border-radius: 8px;
    font-weight: 800;
}

.primary-button:hover,
.start-button:hover {
    background: var(--gold-2);
}

.stop-button {
    color: var(--white);
    background: var(--danger);
}

.workspace {
    display: grid;
    grid-template-columns: minmax(280px, 390px) minmax(0, 1fr);
    gap: 24px;
    align-items: start;
}

.control-rail,
.transcript-panel {
    padding: 24px;
    background: var(--white);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: 0 14px 42px rgba(17, 24, 32, 0.08);
}

.input-source-segmented {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-top: 8px;
    padding: 5px;
    background: #edf0f2;
    border: 1px solid var(--line);
    border-radius: 8px;
}

.input-source-button {
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    color: var(--surface);
    background: transparent;
    border-radius: 6px;
    font-weight: 800;
}

.input-source-button.selected {
    color: var(--white);
    background: var(--navy);
}

.input-source-button svg,
.start-button svg,
.stop-button svg {
    width: 18px;
    height: 18px;
}

.setting-toggle-row {
    grid-template-columns: 18px 1fr;
    align-items: center;
    color: var(--ink);
    text-transform: none;
    font-weight: 600;
}

.setting-toggle-row input {
    width: 18px;
    min-height: 18px;
    accent-color: var(--gold);
}

.translation-transport-controls {
    display: grid;
    grid-template-columns: 1fr;
}

.audio-meter-card {
    padding: 14px;
    background: #f0f2f4;
    border-radius: 8px;
}

.audio-meter-row {
    display: flex;
    justify-content: space-between;
    margin-bottom: 10px;
    color: var(--muted);
    font-size: 13px;
    font-weight: 800;
}

.audio-level-meter {
    height: 10px;
    overflow: hidden;
    background: #dfe4e8;
    border-radius: 999px;
}

.audio-level-meter span {
    display: block;
    width: 0;
    height: 100%;
    background: linear-gradient(90deg, var(--gold), var(--ok));
    transition: width 120ms ease;
}

.app-status-message,
.form-message {
    min-height: 20px;
    margin: 0;
    color: var(--muted);
    font-size: 14px;
    line-height: 1.45;
}

.app-status-message.error,
.form-message.error {
    color: var(--danger);
}

.app-status-message.ok,
.form-message.ok {
    color: var(--ok);
}

.transcript-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 24px;
    min-height: calc(100vh - 136px);
}

.transcript-panel {
    display: grid;
    grid-template-rows: auto 1fr;
    min-height: 520px;
}

.transcript-panel.output {
    background: var(--navy);
    color: var(--white);
    border-color: var(--navy);
}

.panel-header {
    display: flex;
    align-items: start;
    justify-content: space-between;
    gap: 14px;
    padding-bottom: 18px;
    border-bottom: 1px solid var(--line);
}

.output .panel-header {
    border-color: rgba(255, 255, 255, 0.14);
}

.panel-header h2 {
    margin: 5px 0 0;
    font-size: 22px;
    line-height: 1.15;
}

.transcript-placeholder {
    margin: 0;
    padding-top: 20px;
    color: #53606b;
    font-size: clamp(18px, 2.2vw, 26px);
    line-height: 1.45;
    white-space: pre-wrap;
}

.output .transcript-placeholder {
    color: #eef2f4;
}

@media (max-width: 1040px) {
    .workspace,
    .transcript-grid {
        grid-template-columns: 1fr;
    }

    .transcript-panel {
        min-height: 320px;
    }
}

.video-preview-container {
    display: grid;
    gap: 8px;
}

.video-preview-container video {
    width: 100%;
    max-height: 220px;
    border-radius: 8px;
    background: #000;
    object-fit: contain;
}

.theater-button {
    min-height: 42px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    color: var(--white);
    background: var(--navy);
    border-radius: 8px;
    font-weight: 800;
}

.theater-button:hover {
    background: var(--surface);
}

.theater-button svg {
    width: 18px;
    height: 18px;
}

.tab-volume-row {
    display: grid;
    gap: 8px;
}

.tab-volume-control {
    display: flex;
    align-items: center;
    gap: 12px;
}

.tab-volume-control input[type="range"] {
    flex: 1;
    width: auto;
    min-height: auto;
    padding: 0;
    border: 0;
    background: transparent;
    accent-color: var(--gold);
    cursor: pointer;
}

.tab-volume-control input[type="range"]:focus {
    box-shadow: none;
}

.tab-volume-control strong {
    min-width: 42px;
    text-align: right;
    color: var(--muted);
    font-size: 13px;
    font-weight: 800;
}

/* Flowing transcript: newest on top, older fading downward */
.transcript-flow {
    margin: 0;
    padding-top: 20px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    overflow: hidden;
    -webkit-mask-image: linear-gradient(to bottom, #000 0%, #000 55%, transparent 100%);
    mask-image: linear-gradient(to bottom, #000 0%, #000 55%, transparent 100%);
}

.flow-line {
    color: #53606b;
    font-size: clamp(18px, 2.2vw, 26px);
    line-height: 1.4;
    animation: flow-in 360ms ease;
}

.flow-line.latest {
    color: var(--ink);
    font-weight: 600;
}

.output .flow-line {
    color: #c6d0d6;
}

.output .flow-line.latest {
    color: var(--white);
    font-weight: 600;
}

@keyframes flow-in {
    from { opacity: 0; transform: translateY(-8px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Theater mode */
.theater-overlay {
    position: fixed;
    inset: 0;
    z-index: 1000;
    background: #000;
    display: grid;
    place-items: center;
    overflow: hidden;
}

.theater-video {
    width: 100%;
    height: 100%;
    object-fit: contain;
    background: #000;
}

.theater-exit-button {
    position: absolute;
    top: 22px;
    right: 22px;
    min-height: 44px;
    padding: 0 18px;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: var(--white);
    background: rgba(17, 24, 32, 0.55);
    border: 1px solid rgba(255, 255, 255, 0.25);
    border-radius: 999px;
    font-weight: 800;
    backdrop-filter: blur(8px);
    transition: background 160ms ease;
}

.theater-exit-button:hover {
    background: rgba(17, 24, 32, 0.85);
}

.theater-exit-button svg {
    width: 18px;
    height: 18px;
}

.theater-caption-stage {
    position: absolute;
    left: 50%;
    bottom: 7%;
    transform: translateX(-50%);
    width: min(1100px, 90vw);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    pointer-events: none;
}

.theater-caption {
    max-width: 100%;
    padding: 14px 26px;
    text-align: center;
    color: var(--white);
    background: rgba(10, 15, 20, 0.55);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 14px;
    font-size: clamp(22px, 3.2vw, 40px);
    font-weight: 700;
    line-height: 1.25;
    letter-spacing: 0.2px;
    backdrop-filter: blur(14px);
    box-shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
    text-shadow: 0 2px 14px rgba(0, 0, 0, 0.6);
    animation: caption-pop 280ms ease;
}

.theater-caption:empty {
    display: none;
}

.theater-caption.source {
    padding: 8px 18px;
    color: #cdd6dd;
    background: rgba(10, 15, 20, 0.4);
    font-size: clamp(15px, 1.7vw, 22px);
    font-weight: 600;
}

.theater-caption.source::before {
    content: attr(data-lang) "  ";
    color: var(--gold);
    font-weight: 800;
}

@keyframes caption-pop {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

@media (max-width: 640px) {
    .topbar,
    main {
        padding: 18px;
    }

    .topbar {
        align-items: flex-start;
        flex-direction: column;
        gap: 14px;
    }

    .brand-mark {
        width: 36px;
        height: 36px;
    }

    .auth-panel,
    .control-rail,
    .transcript-panel {
        padding: 18px;
    }
}
