/* ── Reset & base ──────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg:          #0a0a0f;
    --surface:     #111118;
    --border:      rgba(140, 80, 255, 0.2);
    --border-glow: rgba(140, 80, 255, 0.5);
    --purple:      #7c3aed;
    --pink:        #ec4899;
    --cyan:        #06b6d4;
    --text:        #e2e0f0;
    --text-muted:  #9990bb;
    --radius:      12px;
    --glass-bg:    rgba(255,255,255,0.03);
    --glass-blur:  blur(12px);
}

html { font-size: 16px; }

body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background:  var(--bg);
    color:       var(--text);
    min-height:  100vh;
    line-height: 1.5;
}

/* ── Layout ─────────────────────────────────────────────────────────────────── */
.app-wrapper {
    max-width: 1200px;
    margin:    0 auto;
    padding:   0 1.5rem 4rem;
}

/* ── Header ─────────────────────────────────────────────────────────────────── */
header {
    padding:    2.5rem 0 2rem;
    text-align: center;
}

header h1 {
    font-size:   2.6rem;
    font-weight: 900;
    letter-spacing: -0.5px;
    background:  linear-gradient(135deg, var(--purple), var(--pink), var(--cyan));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

header p {
    color:      var(--text-muted);
    margin-top: 0.5rem;
    font-size:  1.05rem;
}

/* ── Main grid ──────────────────────────────────────────────────────────────── */
.main-grid {
    display:               grid;
    grid-template-columns: 1fr 1fr;
    gap:                   1.5rem;
    align-items:           start;
}

@media (max-width: 860px) {
    .main-grid { grid-template-columns: 1fr; }
}

/* ── Glass panel ─────────────────────────────────────────────────────────────── */
.panel {
    background:    var(--glass-bg);
    backdrop-filter: var(--glass-blur);
    border:        1px solid var(--border);
    border-radius: var(--radius);
    padding:       1.5rem;
    transition:    border-color 0.3s;
}

.panel:hover { border-color: var(--border-glow); }

.panel h2 {
    font-size:     1rem;
    font-weight:   700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color:          var(--text-muted);
    margin-bottom:  1rem;
    display:        flex;
    align-items:    center;
    gap:            0.4rem;
}

.panel h2 .step-badge {
    display:         inline-flex;
    align-items:     center;
    justify-content: center;
    width:  1.6rem;
    height: 1.6rem;
    border-radius: 50%;
    background: var(--purple);
    color:       #fff;
    font-size:   0.75rem;
    font-weight: 800;
}

/* ── Form elements ──────────────────────────────────────────────────────────── */
.form-row {
    display:   flex;
    gap:       0.75rem;
    flex-wrap: wrap;
}

.form-group {
    display:       flex;
    flex-direction: column;
    gap:           0.4rem;
    margin-bottom: 1rem;
    flex:          1 1 200px;
}

.form-group:last-child { margin-bottom: 0; }

label {
    font-size:   0.8rem;
    font-weight: 600;
    color:       var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

input[type="text"],
input[type="password"],
select,
textarea {
    background:    rgba(255,255,255,0.05);
    border:        1px solid var(--border);
    border-radius: 8px;
    color:         var(--text);
    font-size:     0.95rem;
    padding:       0.55rem 0.8rem;
    width:         100%;
    transition:    border-color 0.2s, box-shadow 0.2s;
    font-family:   inherit;
}

input:focus, select:focus, textarea:focus {
    outline:      none;
    border-color: var(--purple);
    box-shadow:   0 0 0 3px rgba(124,58,237,0.2);
}

select option { background: #1a1a2e; }

textarea {
    resize:     vertical;
    min-height: 80px;
}

/* ── API key row ──────────────────────────────────────────────────────────────  */
.key-row {
    display: flex;
    gap:     0.5rem;
}

.key-row input { flex: 1; }

/* ── Buttons ─────────────────────────────────────────────────────────────────── */
.btn {
    border:        none;
    border-radius: 8px;
    cursor:        pointer;
    font-family:   inherit;
    font-weight:   700;
    font-size:     0.9rem;
    padding:       0.6rem 1.2rem;
    transition:    all 0.2s;
    white-space:   nowrap;
}

.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.btn-primary {
    background: linear-gradient(135deg, var(--purple), var(--pink));
    color:      #fff;
    box-shadow: 0 0 20px rgba(124,58,237,0.35);
}

.btn-primary:hover:not(:disabled) {
    transform:  translateY(-1px);
    box-shadow: 0 0 30px rgba(124,58,237,0.55);
}

.btn-secondary {
    background: rgba(255,255,255,0.06);
    border:     1px solid var(--border);
    color:      var(--text);
}

.btn-secondary:hover:not(:disabled) {
    background:   rgba(255,255,255,0.1);
    border-color: var(--border-glow);
}

.btn-generate {
    width:     100%;
    padding:   0.85rem;
    font-size: 1.05rem;
    margin-top: 0.5rem;
    background: linear-gradient(135deg, var(--purple) 0%, var(--pink) 60%, var(--cyan) 100%);
    color:      #fff;
    box-shadow: 0 0 24px rgba(124,58,237,0.4);
}

.btn-generate:hover:not(:disabled) {
    box-shadow: 0 0 36px rgba(124,58,237,0.65);
    transform:  translateY(-1px);
}

/* ── Audio drop zone ─────────────────────────────────────────────────────────── */
.audio-drop {
    display:         flex;
    flex-direction:  column;
    align-items:     center;
    justify-content: center;
    gap:             0.5rem;
    border:          2px dashed var(--border);
    border-radius:   var(--radius);
    padding:         1.5rem;
    cursor:          pointer;
    text-align:      center;
    transition:      border-color 0.2s, background 0.2s;
}

.audio-drop:hover, .audio-drop.drag-over {
    border-color: var(--purple);
    background:   rgba(124,58,237,0.06);
}

.audio-drop .icon {
    font-size: 2rem;
    line-height: 1;
}

.audio-drop .drop-hint {
    font-size: 0.8rem;
    color:     var(--text-muted);
}

#audio-file { display: none; }
#audio-file-name {
    font-size:  0.85rem;
    color:      var(--cyan);
    font-weight: 600;
    margin-top:  0.25rem;
}

/* ── Status messages ──────────────────────────────────────────────────────────  */
.status-msg {
    display:       none;
    font-size:     0.82rem;
    font-weight:   600;
    padding:       0.4rem 0.7rem;
    border-radius: 6px;
    margin-top:    0.4rem;
}

.status-msg.success { background: rgba(6,182,212,0.12); color: var(--cyan); }
.status-msg.error   { background: rgba(236,72,153,0.12); color: var(--pink); }

/* ── Slider ──────────────────────────────────────────────────────────────────── */
.slider-row {
    display:     flex;
    align-items: center;
    gap:         0.75rem;
}

input[type="range"] {
    -webkit-appearance: none;
    flex:       1;
    height:     4px;
    background: linear-gradient(to right, var(--purple), var(--pink));
    border:     none;
    border-radius: 2px;
    cursor:     pointer;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width:         16px;
    height:        16px;
    border-radius: 50%;
    background:    var(--purple);
    box-shadow:    0 0 8px rgba(124,58,237,0.7);
    cursor:        pointer;
}

.slider-label-row {
    display:         flex;
    justify-content: space-between;
    font-size:       0.75rem;
    color:           var(--text-muted);
    margin-top:      0.2rem;
}

.energy-val {
    font-weight: 800;
    color:       var(--cyan);
    min-width:   1.5rem;
    text-align:  right;
}

/* ── Preview section ─────────────────────────────────────────────────────────── */
#preview-section {
    margin-top:    2rem;
    display:       flex;
    gap:           1.5rem;
    align-items:   start;
    flex-wrap:     wrap;
}

#preview-section.hidden { display: none; }

/* Canvas wrapper — letter-boxes the 9:16 canvas */
.canvas-wrapper {
    position:    relative;
    flex:        0 0 auto;
    width:       min(320px, 100%);
    aspect-ratio: 9/16;
    border:      1px solid var(--border-glow);
    border-radius: var(--radius);
    overflow:    hidden;
    box-shadow:  0 0 40px rgba(124,58,237,0.3);
}

.canvas-wrapper canvas {
    width:    100%;
    height:   100%;
    display:  block;
}

/* Controls beside canvas */
.preview-controls {
    flex:      1 1 260px;
    display:   flex;
    flex-direction: column;
    gap:       1rem;
}

.playback-row {
    display: flex;
    gap:     0.5rem;
}

/* Progress bar */
.rec-progress-wrap {
    margin-top: 0.5rem;
}

.rec-progress-wrap.hidden { display: none; }

.progress-track {
    background:    rgba(255,255,255,0.08);
    border-radius: 4px;
    height:        6px;
    overflow:      hidden;
    margin-bottom: 0.4rem;
}

.progress-fill {
    background:    linear-gradient(90deg, var(--purple), var(--cyan));
    height:        100%;
    width:         0%;
    border-radius: 4px;
    transition:    width 0.4s;
}

/* Shimmer pulse while FFmpeg converts server-side (duration unknown) */
@keyframes shimmer {
    0%   { background-position: -200% center; }
    100% { background-position:  200% center; }
}

.progress-fill.indeterminate {
    width:               82% !important;
    background:          linear-gradient(90deg, var(--purple) 25%, var(--cyan) 50%, var(--pink) 75%, var(--purple) 100%);
    background-size:     200% auto;
    animation:           shimmer 1.4s linear infinite;
    transition:          none;
}

.progress-text {
    font-size: 0.8rem;
    color:     var(--text-muted);
}

/* Theme description */
.theme-display {
    background:    rgba(6,182,212,0.06);
    border:        1px solid rgba(6,182,212,0.2);
    border-radius: 8px;
    padding:       0.75rem 1rem;
    font-size:     0.88rem;
    color:         var(--cyan);
    font-style:    italic;
    min-height:    2.5rem;
}

.theme-display::before {
    content: '"';
    font-size: 1.3rem;
    line-height: 0;
    vertical-align: -0.3rem;
    margin-right: 0.2rem;
    opacity: 0.5;
}

/* ── Controls sub-heading ────────────────────────────────────────────────────── */
.ctrl-heading {
    font-size:      0.75rem;
    font-weight:    700;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    color:          var(--text-muted);
    margin-bottom:  0.6rem;
}

/* ── Checkbox toggle rows ────────────────────────────────────────────────────── */
.toggle-group {
    display:        flex;
    flex-direction: column;
    gap:            0.5rem;
}

.toggle-row {
    display:     flex;
    align-items: center;
    gap:         0.55rem;
    cursor:      pointer;
    font-size:   0.9rem;
    color:       var(--text);
    user-select: none;
}

.toggle-row input[type="checkbox"] {
    width:         17px;
    height:        17px;
    accent-color:  var(--purple);
    cursor:        pointer;
    flex-shrink:   0;
}

/* ── Mode toggle ─────────────────────────────────────────────────────────────── */
.mode-toggle {
    display:       flex;
    gap:           0.5rem;
}

.mode-btn {
    flex:          1;
    border:        1px solid var(--border);
    border-radius: 8px;
    background:    rgba(255,255,255,0.04);
    color:         var(--text-muted);
    font-family:   inherit;
    font-size:     0.88rem;
    font-weight:   600;
    padding:       0.55rem 0.5rem;
    cursor:        pointer;
    transition:    all 0.2s;
}

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

.mode-btn.active {
    background:   linear-gradient(135deg, rgba(124,58,237,0.25), rgba(236,72,153,0.15));
    border-color: var(--purple);
    color:        #fff;
    box-shadow:   0 0 12px rgba(124,58,237,0.3);
}

/* ── AI Customise panel ──────────────────────────────────────────────────────── */
.ai-customise-panel select {
    padding: 0.45rem 0.7rem;
}

.color-grid {
    display:        flex;
    flex-direction: column;
    gap:            0.55rem;
    margin-bottom:  0.25rem;
}

.color-swatch-row {
    display:     flex;
    align-items: center;
    gap:         0.6rem;
}

.color-swatch-label {
    font-size:      0.8rem;
    font-weight:    600;
    color:          var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    width:          80px;
    flex-shrink:    0;
}

input[type="color"].color-swatch {
    -webkit-appearance: none;
    width:         42px;
    height:        30px;
    border:        1px solid var(--border);
    border-radius: 6px;
    background:    none;
    cursor:        pointer;
    padding:       2px;
    flex-shrink:   0;
}

input[type="color"].color-swatch::-webkit-color-swatch-wrapper { padding: 0; border-radius: 4px; }
input[type="color"].color-swatch::-webkit-color-swatch         { border: none; border-radius: 4px; }

/* ── Utility ──────────────────────────────────────────────────────────────────── */
.hidden { display: none !important; }

.divider {
    border:     none;
    border-top: 1px solid var(--border);
    margin:     1rem 0;
}

/* ── Geometry editor ──────────────────────────────────────────────────────────── */
.geometry-panel #shape-list {
    display:        flex;
    flex-direction: column;
    gap:            0.6rem;
    margin-bottom:  0.75rem;
    max-height:     340px;
    overflow-y:     auto;
    padding-right:  2px;
}

.shape-row {
    background:    rgba(255,255,255,0.04);
    border:        1px solid var(--border);
    border-radius: 10px;
    padding:       0.55rem 0.7rem 0.6rem;
}

.shape-row-head {
    display:     flex;
    align-items: center;
    gap:         0.5rem;
    margin-bottom: 0.45rem;
}

.shape-num {
    font-size:   0.75rem;
    font-weight: 700;
    color:       var(--text-muted);
    width:       1.4rem;
    text-align:  right;
    flex-shrink: 0;
}

.shape-field {
    flex:          1;
    padding:       0.28rem 0.5rem;
    font-size:     0.82rem;
    background:    var(--surface);
    color:         var(--text);
    border:        1px solid var(--border);
    border-radius: 6px;
    cursor:        pointer;
    min-width:     0;
}

.shape-remove-btn {
    background:    transparent;
    border:        1px solid rgba(255,80,80,0.4);
    color:         rgba(255,100,100,0.8);
    border-radius: 6px;
    width:         26px;
    height:        26px;
    font-size:     1rem;
    line-height:   1;
    cursor:        pointer;
    flex-shrink:   0;
    transition:    background 0.15s, color 0.15s;
    padding:       0;
}
.shape-remove-btn:hover {
    background: rgba(255,80,80,0.2);
    color:      #ff6464;
}

.shape-row-controls {
    display:               grid;
    grid-template-columns: repeat(4, 1fr);
    gap:                   0.4rem;
}

.shape-slider-wrap {
    display:        flex;
    flex-direction: column;
    gap:            0.2rem;
    align-items:    center;
}

.shape-slider-wrap span {
    font-size:      0.68rem;
    font-weight:    600;
    color:          var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.shape-slider-wrap input[type="range"] {
    width:   100%;
    height:  3px;
    margin:  0;
    cursor:  pointer;
    accent-color: var(--cyan);
}

/* ── Footer ──────────────────────────────────────────────────────────────────── */
footer {
    text-align: center;
    color:      var(--text-muted);
    font-size:  0.8rem;
    padding:    2rem 0 1rem;
    opacity:    0.6;
}
