:root {
    --bg: #0b0d12;
    --bg-soft: #11141b;
    --bg-card: #161a23;
    --bg-elev: #1d2230;
    --border: #262c3b;
    --border-strong: #34394a;
    --text: #e8ecf3;
    --text-dim: #9aa3b5;
    --text-muted: #6c7488;
    --primary: #ffd34d;
    --primary-hover: #ffdf75;
    --primary-ink: #1a1300;
    --accent: #6ea8ff;
    --danger: #ff6b6b;
    --success: #66e0a3;
    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 8px 30px rgba(0, 0, 0, 0.35);
    --transition: 0.18s ease;
}

* { box-sizing: border-box; }
html, body {
    margin: 0;
    padding: 0;
    background: radial-gradient(circle at 20% -10%, #1a1d2c 0, var(--bg) 60%) no-repeat;
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Inter", Roboto, Oxygen, Ubuntu, sans-serif;
    min-height: 100vh;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0 0 0.5rem; font-weight: 600; letter-spacing: -0.01em; }
h1 { font-size: 1.15rem; }
h2 { font-size: 1.05rem; color: var(--text); }
h3 { font-size: 0.95rem; color: var(--text-dim); }
p { margin: 0.25rem 0; }
small { font-size: 0.8rem; }
.muted { color: var(--text-muted); font-size: 0.85rem; }

/* Topbar */
.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 1rem;
    padding: 1.2rem 1.5rem;
    border-bottom: 1px solid var(--border);
    background: rgba(11, 13, 18, 0.85);
    backdrop-filter: blur(8px);
    position: sticky;
    top: 0;
    z-index: 50;
}
.brand { display: flex; align-items: center; gap: 0.85rem; }
.brand .logo {
    width: 40px; height: 40px;
    border-radius: 10px;
    background: linear-gradient(135deg, var(--primary), #ffaa3d);
    color: var(--primary-ink);
    display: grid; place-items: center;
    font-weight: 800; font-size: 0.95rem;
    box-shadow: 0 4px 14px rgba(255, 211, 77, 0.25);
}
.brand p { color: var(--text-muted); font-size: 0.8rem; }

.tabs { display: flex; gap: 0.4rem; background: var(--bg-card); padding: 4px; border-radius: 999px; border: 1px solid var(--border); }
.tab {
    padding: 0.55rem 1rem;
    border: 0; background: transparent;
    color: var(--text-dim);
    border-radius: 999px;
    font-weight: 500; font-size: 0.9rem;
    cursor: pointer;
    transition: var(--transition);
}
.tab:hover { color: var(--text); }
.tab.active { background: var(--primary); color: var(--primary-ink); font-weight: 600; }

/* Layout */
.container { max-width: 1280px; margin: 0 auto; padding: 1.5rem; }
.tab-panel { display: none; animation: fade 0.18s ease; }
.tab-panel.active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1.25rem;
}
@media (min-width: 880px) {
    .grid { grid-template-columns: 1fr 1fr; }
}

.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    box-shadow: var(--shadow);
}

/* Form fields */
.field { display: flex; flex-direction: column; gap: 0.4rem; margin: 1rem 0; }
.field > span { font-size: 0.85rem; color: var(--text-dim); font-weight: 500; }

select, textarea, input[type="text"] {
    width: 100%;
    background: var(--bg-elev);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 0.65rem 0.8rem;
    font-family: inherit;
    font-size: 0.92rem;
    transition: var(--transition);
    resize: vertical;
}
select:focus, textarea:focus, input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(255, 211, 77, 0.18);
}

textarea { min-height: 100px; }

.checkbox {
    display: flex; align-items: center; gap: 0.55rem;
    margin: 0.75rem 0;
    color: var(--text-dim); font-size: 0.9rem;
    cursor: pointer;
}
.checkbox input { accent-color: var(--primary); width: 16px; height: 16px; }

.advanced {
    margin: 1rem 0;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 0 0.85rem;
    background: var(--bg-soft);
}
.advanced summary {
    cursor: pointer;
    padding: 0.7rem 0;
    color: var(--text-dim);
    font-size: 0.9rem;
    user-select: none;
}
.advanced[open] summary { color: var(--text); }
.ratio-helper {
    margin-top: 0.6rem;
    display: flex;
    flex-wrap: wrap;
    gap: 0.45rem;
}
.ratio-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    padding: 0.3rem 0.5rem;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: var(--bg-elev);
    color: var(--text-muted);
    font-size: 0.75rem;
}
.ratio-chip.active {
    border-color: rgba(255, 211, 77, 0.6);
    color: var(--text);
    background: rgba(255, 211, 77, 0.08);
}
.ratio-icon {
    display: inline-block;
    border: 1.5px solid var(--accent);
    border-radius: 2px;
    opacity: 0.95;
}
.ratio-auto {
    width: 15px;
    height: 11px;
    border-style: dashed;
}
.ratio-1-1 { width: 12px; height: 12px; }
.ratio-4-5 { width: 10px; height: 13px; }
.ratio-9-16 { width: 8px; height: 14px; }
.ratio-16-9 { width: 15px; height: 8px; }
.ratio-21-9 { width: 17px; height: 7px; }

/* Buttons */
.btn-primary, .btn-secondary {
    border: 0;
    border-radius: var(--radius-sm);
    padding: 0.7rem 1.1rem;
    font-weight: 600;
    font-size: 0.92rem;
    cursor: pointer;
    transition: var(--transition);
    font-family: inherit;
    text-decoration: none;
    display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem;
}
.btn-primary {
    background: var(--primary);
    color: var(--primary-ink);
    width: 100%;
    margin-top: 0.5rem;
    box-shadow: 0 4px 14px rgba(255, 211, 77, 0.25);
}
.btn-primary:hover { background: var(--primary-hover); transform: translateY(-1px); }
.btn-primary:disabled { opacity: 0.6; cursor: not-allowed; transform: none; }

.btn-secondary {
    background: var(--bg-elev);
    color: var(--text);
    border: 1px solid var(--border-strong);
}
.btn-secondary:hover { background: var(--border); }

/* Dropzone */
.dropzone {
    display: block;
    border: 2px dashed var(--border-strong);
    border-radius: var(--radius);
    background: var(--bg-soft);
    padding: 1.25rem;
    text-align: center;
    cursor: pointer;
    transition: var(--transition);
    min-height: 180px;
    position: relative;
    overflow: hidden;
}
.dropzone.small { min-height: 120px; }
.dropzone.tall { min-height: 220px; }
.dropzone:hover, .dropzone.dragover {
    border-color: var(--primary);
    background: rgba(255, 211, 77, 0.06);
}
.dz-empty {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 0.5rem;
    color: var(--text-muted);
    font-size: 0.9rem;
    height: 100%;
    min-height: 150px;
}
.dz-icon {
    width: 38px; height: 38px;
    border-radius: 50%;
    background: var(--bg-elev);
    display: grid; place-items: center;
    font-size: 1.4rem; color: var(--primary);
}
.dz-preview {
    display: block;
    max-width: 100%;
    max-height: 280px;
    margin: 0 auto;
    border-radius: var(--radius-sm);
}

/* Thumb grid */
.thumb-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 0.6rem;
    margin-top: 0.85rem;
}
.thumb {
    position: relative;
    aspect-ratio: 1 / 1;
    background: var(--bg-elev);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    overflow: hidden;
}
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb .badge {
    position: absolute; top: 4px; left: 4px;
    background: rgba(0, 0, 0, 0.65);
    color: #fff;
    padding: 2px 6px;
    font-size: 0.7rem;
    border-radius: 4px;
}
.thumb .remove {
    position: absolute; top: 4px; right: 4px;
    width: 22px; height: 22px;
    border: 0; border-radius: 50%;
    background: rgba(0, 0, 0, 0.7);
    color: #fff;
    cursor: pointer;
    font-size: 0.85rem;
    display: grid; place-items: center;
}
.thumb .remove:hover { background: var(--danger); }

.thumb-grid.result {
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
}
.thumb-grid.result .thumb { aspect-ratio: auto; }
.thumb-grid.result .slide-card {
    background: var(--bg-elev);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 0.6rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}
.thumb-grid.result .slide-card img {
    width: 100%; border-radius: 6px; display: block;
}
.thumb-grid.result .slide-card .slide-actions {
    display: flex; gap: 0.4rem; flex-wrap: wrap;
}
.thumb-grid.result .slide-card .slide-actions .btn-secondary {
    flex: 1;
    padding: 0.45rem 0.6rem;
    font-size: 0.8rem;
}
.thumb-grid.result .slide-card .slide-prompt {
    font-size: 0.75rem;
    color: var(--text-muted);
    background: var(--bg-soft);
    padding: 0.5rem;
    border-radius: 4px;
    max-height: 80px;
    overflow: auto;
}
.slide-error {
    color: var(--danger);
    font-size: 0.8rem;
    background: rgba(255, 107, 107, 0.08);
    padding: 0.5rem;
    border-radius: 4px;
}

/* Result card */
.result-card { margin-top: 1.25rem; }
.result-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1.25rem;
}
@media (min-width: 880px) {
    .result-grid { grid-template-columns: 1.2fr 1fr; }
}
.result-img-wrap {
    background: var(--bg-elev);
    border-radius: var(--radius-sm);
    padding: 0.5rem;
    display: grid; place-items: center;
}
.result-img-wrap img { max-width: 100%; max-height: 600px; display: block; border-radius: 6px; }
.result-meta { display: flex; flex-direction: column; gap: 0.6rem; }
.prompt-box {
    background: var(--bg-soft);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 0.7rem;
    font-size: 0.78rem;
    color: var(--text-dim);
    white-space: pre-wrap;
    word-break: break-word;
    max-height: 280px;
    overflow: auto;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.result-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 0.5rem; }

/* Loading overlay */
.loading {
    position: fixed; inset: 0;
    background: rgba(11, 13, 18, 0.85);
    backdrop-filter: blur(4px);
    display: grid; place-items: center;
    z-index: 100;
    flex-direction: column;
    gap: 1rem;
}
.loading[hidden] { display: none; }
.loading p { font-size: 1rem; color: var(--text); margin-top: 1rem; }
.loading small { color: var(--text-muted); }
.spinner {
    width: 48px; height: 48px;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Toast */
.toast {
    position: fixed;
    bottom: 1.5rem; left: 50%;
    transform: translateX(-50%);
    background: var(--bg-elev);
    border: 1px solid var(--border-strong);
    color: var(--text);
    padding: 0.8rem 1.2rem;
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow);
    z-index: 200;
    font-size: 0.9rem;
    max-width: 90%;
}
.toast[hidden] { display: none; }
.toast.error { border-color: var(--danger); color: #ffd0d0; }
.toast.success { border-color: var(--success); color: #d0ffe6; }
