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

:root {
    --bg: #0d0d0d;
    --text: #e8e4dc;
    --text-muted: #8a8680;
    --accent: #e8a849;
    --surface: #1a1918;
    --border: #2a2826;
    --error: #dc4a4a;
    --success: #4adc7a;
    --radius: 8px;
    --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --mono: 'JetBrains Mono', 'Fira Code', monospace;
}

body {
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    font-size: 15px;
    line-height: 1.5;
    min-height: 100vh;
}

.container {
    max-width: 800px;
    margin: 0 auto;
    padding: 20px 16px 60px;
}

/* Header */
header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border);
}

.logo {
    font-size: 20px;
    font-weight: 700;
    letter-spacing: -0.5px;
}

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

.tabs {
    display: flex;
    gap: 4px;
}

.tab {
    background: none;
    border: 1px solid transparent;
    color: var(--text-muted);
    padding: 6px 14px;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 14px;
    font-family: var(--font);
    transition: all 0.15s;
}

.tab:hover { color: var(--text); }
.tab.active {
    color: var(--text);
    background: var(--surface);
    border-color: var(--border);
}

/* Views */
.view { display: none; }
.view.active { display: block; }

/* Cards */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 16px;
}

/* Presets */
.presets-row {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding-bottom: 8px;
    margin-bottom: 16px;
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
}

.preset-btn {
    flex-shrink: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 8px 16px;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 13px;
    font-family: var(--font);
    white-space: nowrap;
    transition: all 0.15s;
}

.preset-btn:hover { border-color: var(--accent); color: var(--accent); }
.preset-btn.active { border-color: var(--accent); background: rgba(232,168,73,0.1); color: var(--accent); }

/* Form */
.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: 6px;
    font-weight: 500;
}

.form-group textarea,
.form-group input[type="text"],
.form-group select {
    width: 100%;
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 10px 12px;
    border-radius: var(--radius);
    font-family: var(--font);
    font-size: 14px;
    outline: none;
    transition: border-color 0.15s;
}

.form-group textarea:focus,
.form-group input:focus,
.form-group select:focus {
    border-color: var(--accent);
}

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

.form-group.half { flex: 1; }

/* Pills */
.pill-group {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.pill {
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--text-muted);
    padding: 6px 14px;
    border-radius: 20px;
    cursor: pointer;
    font-size: 13px;
    font-family: var(--font);
    transition: all 0.15s;
}

.pill:hover { color: var(--text); border-color: var(--text-muted); }
.pill.active {
    background: rgba(232,168,73,0.15);
    border-color: var(--accent);
    color: var(--accent);
}

/* Toggles */
.toggles-row {
    display: flex;
    gap: 20px;
}

.toggle-label {
    display: flex !important;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-size: 14px;
    color: var(--text);
}

.toggle-label input[type="checkbox"] {
    accent-color: var(--accent);
    width: 16px;
    height: 16px;
}

/* Cost Card */
.cost-card {
    padding: 14px 20px;
}

.cost-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.cost-header span:first-child {
    font-size: 13px;
    color: var(--text-muted);
}

.cost-total {
    font-size: 20px;
    font-weight: 700;
    font-family: var(--mono);
    color: var(--accent);
}

.cost-breakdown {
    margin-top: 8px;
    font-size: 12px;
    color: var(--text-muted);
    font-family: var(--mono);
}

/* Buttons */
.btn-primary {
    display: block;
    width: 100%;
    background: var(--accent);
    color: #0d0d0d;
    border: none;
    padding: 14px;
    border-radius: var(--radius);
    font-size: 16px;
    font-weight: 600;
    font-family: var(--font);
    cursor: pointer;
    text-align: center;
    text-decoration: none;
    transition: opacity 0.15s;
}

.btn-primary:hover { opacity: 0.9; }
.btn-primary:disabled { opacity: 0.4; cursor: not-allowed; }

.btn-secondary {
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 10px 20px;
    border-radius: var(--radius);
    font-size: 14px;
    font-family: var(--font);
    cursor: pointer;
    transition: all 0.15s;
}

.btn-secondary:hover { border-color: var(--text-muted); }

.btn-text {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 13px;
    cursor: pointer;
    padding: 8px;
    font-family: var(--font);
    display: block;
    margin: 8px auto 0;
}

.btn-text:hover { color: var(--text); }

/* Progress */
.progress-title {
    font-size: 18px;
    margin-bottom: 4px;
}

.progress-timer {
    font-family: var(--mono);
    font-size: 14px;
    color: var(--text-muted);
    margin-bottom: 12px;
}

.progress-bar-container {
    width: 100%;
    height: 6px;
    background: var(--bg);
    border-radius: 3px;
    overflow: hidden;
    margin-bottom: 6px;
}

.progress-bar {
    height: 100%;
    background: var(--accent);
    border-radius: 3px;
    transition: width 0.3s ease;
}

.progress-pct {
    font-family: var(--mono);
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: 16px;
}

.stages-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 12px;
}

.stage-item {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: var(--text-muted);
}

.stage-item.done { color: var(--success); }
.stage-item.running { color: var(--accent); }
.stage-item.failed { color: var(--error); }

.stage-icon { width: 16px; text-align: center; font-size: 12px; }

/* Error Box */
.error-box {
    background: rgba(220,74,74,0.1);
    border: 1px solid var(--error);
    border-radius: var(--radius);
    padding: 14px;
    margin-top: 12px;
}

.error-box p {
    color: var(--error);
    font-size: 14px;
    margin-bottom: 10px;
}

/* Result */
#result-video {
    width: 100%;
    max-height: 70vh;
    border-radius: var(--radius);
    background: #000;
    margin-bottom: 12px;
}

.result-stats {
    font-size: 13px;
    color: var(--text-muted);
    font-family: var(--mono);
    margin-bottom: 16px;
}

.result-actions {
    display: flex;
    gap: 12px;
    margin-bottom: 16px;
}

.result-actions .btn-primary { flex: 2; }
.result-actions .btn-secondary { flex: 1; }

.result-details {
    margin-top: 8px;
}

.result-details summary {
    cursor: pointer;
    color: var(--text-muted);
    font-size: 13px;
}

.result-details pre {
    background: var(--bg);
    padding: 12px;
    border-radius: var(--radius);
    font-size: 12px;
    font-family: var(--mono);
    overflow-x: auto;
    margin-top: 8px;
    color: var(--text-muted);
    white-space: pre-wrap;
}

/* History */
.history-stats {
    font-size: 13px;
    color: var(--text-muted);
    font-family: var(--mono);
    margin-bottom: 16px;
}

.history-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 12px;
}

.history-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    cursor: pointer;
    transition: border-color 0.15s;
}

.history-card:hover { border-color: var(--accent); }

.history-thumb {
    width: 100%;
    aspect-ratio: 9/16;
    object-fit: cover;
    background: #111;
    display: block;
}

.history-thumb.landscape { aspect-ratio: 16/9; }
.history-thumb.square { aspect-ratio: 1/1; }

.history-card-info {
    padding: 10px;
}

.history-card-info h4 {
    font-size: 13px;
    font-weight: 500;
    margin-bottom: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.history-card-meta {
    font-size: 11px;
    color: var(--text-muted);
    font-family: var(--mono);
}

.history-card.error-card { border-color: var(--error); opacity: 0.7; }

.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-muted);
}

.empty-state p { margin-bottom: 16px; }

/* Settings */
.api-status {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.status-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 14px;
}

.status-dot {
    font-size: 13px;
    font-family: var(--mono);
}

.status-dot.ok { color: var(--success); }
.status-dot.err { color: var(--error); }
.status-dot.warn { color: var(--accent); }

.muted { color: var(--text-muted); font-size: 13px; margin-bottom: 12px; }

/* Modal */
.modal {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-backdrop {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.8);
}

.modal-content {
    position: relative;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    max-width: 600px;
    width: 90%;
    max-height: 90vh;
    overflow-y: auto;
}

.modal-close {
    position: absolute;
    top: 8px; right: 12px;
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 24px;
    cursor: pointer;
}

#modal-video {
    width: 100%;
    max-height: 60vh;
    border-radius: var(--radius);
    background: #000;
    margin-bottom: 12px;
}

.modal-info {
    font-size: 13px;
    color: var(--text-muted);
    font-family: var(--mono);
    margin-bottom: 12px;
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* Login */
.login-screen {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 20px;
    background: var(--bg);
}
.login-card {
    background: #1a1918;
    border: 1px solid #2a2826;
    border-radius: 12px;
    padding: 48px 40px;
    max-width: 400px;
    width: 100%;
}
.login-card h1 {
    font-family: 'Georgia', serif;
    font-style: italic;
    color: var(--accent);
    margin-bottom: 8px;
    font-size: 28px;
}
.login-subtitle {
    color: var(--text-muted);
    font-size: 14px;
    margin-bottom: 28px;
}
.login-card input {
    width: 100%;
    padding: 12px 16px;
    background: var(--bg);
    border: 1px solid #2a2826;
    border-radius: 8px;
    color: var(--text);
    font-size: 15px;
    margin-bottom: 16px;
    box-sizing: border-box;
}
.login-card input:focus {
    outline: none;
    border-color: var(--accent);
}
.login-card button[type="submit"] {
    width: 100%;
    padding: 14px;
    background: var(--accent);
    color: var(--bg);
    border: none;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
}
.login-card button[type="submit"]:hover {
    opacity: 0.9;
}
.login-card button[type="submit"]:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}
.login-error {
    color: #dc4a4a;
    font-size: 14px;
    margin-top: 12px;
    text-align: center;
}

/* Sign out */
.tab-signout {
    margin-left: auto;
    color: var(--text-muted) !important;
    font-size: 13px;
}
.tab-signout:hover {
    color: var(--text) !important;
}

/* Responsive */
@media (max-width: 600px) {
    header { flex-direction: column; gap: 12px; }
    .form-row { flex-direction: column; gap: 0; }
    .history-grid { grid-template-columns: repeat(2, 1fr); }
    .result-actions { flex-direction: column; }
}
