:root {
    --bg: #0b0e1a;
    --card: #141a2e;
    --border: #232c46;
    --text: #f2f5ff;
    --muted: #8b94b0;
    --accent: #6c5ce7;
    --accent2: #00d2ff;
    --danger: #ff5f6d;
    --ok: #2ecc71;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
    height: 100%;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    overflow: hidden;
    -webkit-user-select: none;
    user-select: none;
}

/* Screens */
.screen {
    display: none;
    width: 100%;
    height: 100%;
    position: absolute;
    inset: 0;
    flex-direction: column;
}
.screen.active { display: flex; }

/* ===== Editor ===== */
.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 16px;
    gap: 10px;
}
.topbar-right {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}
.topbar a {
    flex-shrink: 0;
}
.topbar-right .login-btn {
    white-space: nowrap;
    max-width: 110px;
    overflow: hidden;
    text-overflow: ellipsis;
}
.brand { font-size: 20px; font-weight: 800; }
.icon-btn {
    background: var(--card);
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: 10px;
    width: 42px; height: 42px;
    font-size: 20px;
    cursor: pointer;
}

/* Tier badge (Pro / Agency) in header */
.tier-badge {
    background: rgba(255,140,66,.15);
    border: 1px solid rgba(255,140,66,.5);
    border-radius: 16px;
    padding: 5px 12px;
    font-size: 12px;
    font-weight: 700;
    color: #ffb074;
    white-space: nowrap;
    max-width: 90px;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Login / Logout pill button — single line, professional */
.login-btn {
    background: linear-gradient(90deg, #6c5ce7, #00d2ff);
    color: #fff;
    border: none;
    padding: 10px 20px;
    border-radius: 22px;
    font-size: 14px;
    font-weight: 700;
    white-space: nowrap;
    cursor: pointer;
    line-height: 1;
    transition: transform .1s, opacity .2s;
}
.login-btn:active { transform: scale(0.95); }
.login-btn:hover { opacity: 0.88; }

.editor-body {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 18px;
    padding: 8px 20px 24px;
    overflow-y: auto;
    max-width: 640px;
    width: 100%;
    margin: 0 auto;
}

.field-label {
    font-size: 13px;
    color: var(--muted);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

#script {
    width: 100%;
    min-height: 200px;
    flex: 1;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 14px;
    color: var(--text);
    font-size: 17px;
    line-height: 1.6;
    padding: 16px;
    resize: none;
    outline: none;
}
#script:focus { border-color: var(--accent); }

.controls-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}
.control {
    display: flex;
    flex-direction: column;
    gap: 8px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 12px;
}
.control label { font-size: 12px; color: var(--muted); }
.control span {
    align-self: flex-end;
    font-size: 14px;
    font-weight: 700;
    color: var(--accent2);
}
input[type="range"] {
    width: 100%;
    accent-color: var(--accent);
}

.ratio-row { display: flex; flex-direction: column; gap: 8px; }
.ratio-row label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.5px; }
.ratio-group { display: flex; gap: 8px; }
.ratio-btn {
    flex: 1;
    background: var(--card);
    border: 1px solid var(--border);
    color: var(--muted);
    padding: 10px;
    border-radius: 10px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
}
.ratio-btn.active {
    background: linear-gradient(90deg, var(--accent), var(--accent2));
    color: #fff;
    border-color: transparent;
}

.mirror-row {
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.switch {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
}
.switch input { display: none; }
.slider {
    width: 44px; height: 24px;
    background: var(--border);
    border-radius: 12px;
    position: relative;
    transition: background .2s;
    flex-shrink: 0;
}
.slider::after {
    content: "";
    position: absolute;
    width: 18px; height: 18px;
    background: #fff;
    border-radius: 50%;
    top: 3px; left: 3px;
    transition: transform .2s;
}
.switch input:checked + .slider {
    background: linear-gradient(90deg, var(--accent), var(--accent2));
}
.switch input:checked + .slider::after { transform: translateX(20px); }
.switch-label { font-size: 14px; }

.primary-btn {
    background: linear-gradient(90deg, var(--accent), var(--accent2));
    color: #fff;
    border: none;
    padding: 16px;
    border-radius: 14px;
    font-size: 17px;
    font-weight: 700;
    cursor: pointer;
    width: 100%;
}
/* Modern Start button */
.start-btn {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 18px;
    border-radius: 18px;
    font-size: 18px;
    background: linear-gradient(135deg, #6c5ce7 0%, #00d2ff 100%);
    box-shadow: 0 8px 30px rgba(108, 92, 231, 0.35), 0 2px 10px rgba(0, 210, 255, 0.2);
    transition: transform .15s ease, box-shadow .15s ease, filter .15s ease;
    overflow: hidden;
}
.start-btn::after {
    content: "";
    position: absolute;
    top: 0; left: -60%;
    width: 40%; height: 100%;
    background: linear-gradient(100deg, transparent, rgba(255,255,255,0.35), transparent);
    transform: skewX(-20deg);
    animation: btn-shine 3.2s ease-in-out infinite;
}
@keyframes btn-shine {
    0% { left: -60%; }
    55% { left: 130%; }
    100% { left: 130%; }
}
.start-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 12px 36px rgba(108, 92, 231, 0.5), 0 4px 14px rgba(0, 210, 255, 0.3);
    filter: brightness(1.06);
}
.start-btn:active {
    transform: translateY(0) scale(0.98);
    box-shadow: 0 4px 18px rgba(108, 92, 231, 0.4);
}
.secondary-btn {
    background: var(--card);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 16px;
    border-radius: 14px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    width: 100%;
}
.analyze-btn {
    background: linear-gradient(90deg, #ff8c42, #ff5f6d);
    color: #fff;
    border: none;
    padding: 16px;
    border-radius: 14px;
    font-size: 15px;
    font-weight: 700;
    cursor: pointer;
    width: 100%;
}
.mp4-btn {
    background: linear-gradient(90deg, #00b894, #00d2ff);
    color: #fff;
    border: none;
    padding: 16px;
    border-radius: 14px;
    font-size: 15px;
    font-weight: 700;
    cursor: pointer;
    width: 100%;
}
.mp4-btn:disabled { opacity: 0.6; cursor: wait; }
.hint { font-size: 12px; color: var(--muted); line-height: 1.5; text-align: center; }

/* ===== Login modal ===== */
.modal-overlay {
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.75);
    display: flex; align-items: center; justify-content: center;
    z-index: 100; padding: 24px;
}
.modal {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 18px;
    padding: 26px 22px;
    width: 100%; max-width: 380px;
    position: relative;
    box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}
.modal h3 { font-size: 20px; margin-bottom: 4px; }
.modal-close {
    position: absolute; top: 14px; right: 14px;
    background: transparent; border: none;
    color: var(--muted); font-size: 18px; cursor: pointer;
}
.modal-close:hover { color: var(--text); }

/* ===== Record screen ===== */
#screen-record { position: relative; }

/* WYSIWYG: the preview shows exactly the aspect-ratio crop that gets recorded.
   The wrapper is centered and sized to fit the selected ratio inside the screen
   (like object-fit:contain); the video covers it with the same cover-fit math
   the canvas uses for the output. Ratio is set via --ar-w/--ar-h from JS. */
#preview-wrap {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: min(100vw, calc(100vh * var(--ar-w, 9) / var(--ar-h, 16)));
    aspect-ratio: var(--ar-w, 9) / var(--ar-h, 16);
    overflow: hidden;
    background: #000;
}

#preview {
    width: 100%;
    height: 100%;
    object-fit: cover;
    background: #000;
}
#preview.mirrored { transform: scaleX(-1); }

/* Prompter overlay */
.prompter {
    position: absolute;
    inset: 0;
    overflow: hidden;
    padding: 12vh 22px 10vh;
    pointer-events: none;
}
#prompter-text {
    position: absolute;
    left: 50%;
    top: 100%;
    transform: translateX(-50%);
    width: 90%;
    text-align: center;
    color: #fff;
    text-shadow: 0 0 10px rgba(0,0,0,0.9), 0 0 2px rgba(0,0,0,1);
    line-height: 1.5;
    white-space: pre-wrap;
    font-weight: 600;
    transition: none;
}

.countdown {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 120px;
    font-weight: 800;
    color: #fff;
    text-shadow: 0 0 20px rgba(0,0,0,0.8);
    background: rgba(0,0,0,0.35);
    z-index: 5;
}
.countdown.hidden { display: none; }

.rec-time {
    position: absolute;
    top: 14px;
    right: 16px;
    background: rgba(0,0,0,0.6);
    color: var(--danger);
    font-weight: 700;
    font-size: 15px;
    padding: 6px 12px;
    border-radius: 20px;
    z-index: 4;
}

.record-controls {
    position: absolute;
    bottom: 24px;
    left: 0; right: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 16px;
    z-index: 4;
}

/* Manual timestamp marker button */
.marker-btn {
    width: 56px; height: 56px;
    border-radius: 50%;
    background: rgba(255,255,255,0.15);
    border: 2px solid rgba(255,255,255,0.5);
    color: #fff;
    font-size: 22px;
    cursor: pointer;
    transition: transform .15s;
}
.marker-btn:active { transform: scale(0.9); }

/* Scroll-pause button — pauses ONLY the script, recording continues */
.scrollpause-btn {
    width: 56px; height: 56px;
    border-radius: 50%;
    background: rgba(0,210,255,0.2);
    border: 2px solid rgba(0,210,255,0.7);
    color: #fff;
    font-size: 22px;
    cursor: pointer;
    transition: transform .15s, background .2s;
}
.scrollpause-btn:active { transform: scale(0.9); }
.scrollpause-btn.sp-paused {
    background: rgba(255,165,0,0.35);
    border-color: #ffa500;
}

/* Pause / Resume button */
.pause-btn {
    width: 56px; height: 56px;
    border-radius: 50%;
    background: rgba(255,255,255,0.15);
    border: 2px solid rgba(255,255,255,0.5);
    color: #fff;
    font-size: 22px;
    cursor: pointer;
    transition: transform .15s, background .2s;
}
.pause-btn:active { transform: scale(0.9); }
.pause-btn.paused {
    background: rgba(46, 204, 113, 0.35);
    border-color: rgba(46, 204, 113, 0.8);
}

/* Live speed control during recording */
.speed-ctl {
    position: absolute;
    top: 14px;
    left: 16px;
    display: flex;
    align-items: center;
    gap: 10px;
    background: rgba(0,0,0,0.6);
    border-radius: 24px;
    padding: 6px 12px;
    z-index: 4;
}
.speed-btn {
    width: 34px; height: 34px;
    border-radius: 50%;
    background: rgba(255,255,255,0.15);
    border: 1px solid rgba(255,255,255,0.4);
    color: #fff;
    font-size: 20px;
    font-weight: 700;
    cursor: pointer;
    line-height: 1;
}
.speed-ctl span {
    color: #fff;
    font-weight: 700;
    font-size: 16px;
    min-width: 30px;
    text-align: center;
}
.stop-btn {
    width: 72px; height: 72px;
    border-radius: 50%;
    background: var(--danger);
    border: 4px solid rgba(255,255,255,0.8);
    color: #fff;
    font-size: 26px;
    cursor: pointer;
    box-shadow: 0 4px 20px rgba(255,95,109,0.4);
}

/* ===== Result screen ===== */
#screen-result { align-items: center; justify-content: center; gap: 20px; padding: 20px; }
#result-video {
    max-width: 100%;
    max-height: 60vh;
    border-radius: 14px;
    background: #000;
    border: 1px solid var(--border);
}
.result-actions { display: flex; flex-direction: column; gap: 10px; width: 100%; max-width: 360px; }
