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

:root {
    --bg: #1a1a2e; --bg-card: #16213e; --bg-input: #0f3460;
    --accent: #00d4aa; --accent-hover: #00f0c0;
    --text: #e8e8e8; --text-muted: #8899aa;
    --border: #2a3a5e; --radius: 8px;
    --checkerboard: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20'%3E%3Crect width='10' height='10' fill='%23ccc'/%3E%3Crect x='10' y='10' width='10' height='10' fill='%23ccc'/%3E%3Crect x='10' width='10' height='10' fill='%23fff'/%3E%3Crect y='10' width='10' height='10' fill='%23fff'/%3E%3C/svg%3E");
}

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

/* Header */
header { background: var(--bg-card); border-bottom: 1px solid var(--border); padding: 14px 32px; display: flex; align-items: center; justify-content: space-between; }
header h1 { font-size: 22px; font-weight: 700; color: var(--accent); }
header .subtitle { font-weight: 400; color: var(--text-muted); font-size: 15px; margin-left: 8px; }
.badge { font-size: 12px; padding: 4px 12px; border-radius: 12px; font-weight: 600; }
.badge.ffmpeg { background: rgba(0, 212, 170, 0.15); color: var(--accent); border: 1px solid var(--accent); }
.badge.python { background: rgba(255, 193, 7, 0.15); color: #ffc107; border: 1px solid #ffc107; }

/* Tabs */
.tabs { display: flex; gap: 2px; background: var(--bg-card); border-radius: var(--radius); padding: 4px; margin: 24px auto 20px; max-width: 1200px; }
.tab { flex: 1; background: none; border: none; color: var(--text-muted); padding: 10px 20px; border-radius: 6px; cursor: pointer; font-size: 14px; font-weight: 500; transition: all 0.2s; }
.tab.active { background: var(--accent); color: #000; font-weight: 600; }
.tab:hover:not(.active) { color: var(--text); }
.tab-content { display: none; max-width: 1200px; margin: 0 auto; padding: 0 24px 24px; }
.tab-content.active { display: block; }

/* Controls */
.controls { display: flex; gap: 20px; flex-wrap: wrap; background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; margin-bottom: 20px; }
.control-group { flex: 1; min-width: 160px; }
.control-group.full-width { flex: 100%; min-width: 100%; }
.control-group label { display: block; font-size: 13px; color: var(--text-muted); margin-bottom: 6px; font-weight: 500; }
.control-group label span { color: var(--accent); font-weight: 600; }
.color-input-row { display: flex; gap: 6px; align-items: center; }
input[type="color"] { width: 38px; height: 34px; border: 1px solid var(--border); border-radius: 4px; cursor: pointer; background: none; padding: 2px; }
input[type="text"], input[type="password"], textarea, select { width: 100%; background: var(--bg-input); border: 1px solid var(--border); border-radius: 4px; color: var(--text); padding: 8px 12px; font-size: 14px; }
input[type="text"] { font-family: monospace; }
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--accent); }
textarea { resize: vertical; font-family: inherit; }
select { cursor: pointer; }
input[type="range"] { width: 100%; accent-color: var(--accent); }
input[type="checkbox"] { accent-color: var(--accent); margin-right: 6px; }
.help-text { font-size: 12px; color: var(--text-muted); margin-top: 4px; }
.help-text a { color: var(--accent); }

/* Buttons */
.btn-icon { background: var(--bg-input); border: 1px solid var(--border); border-radius: 4px; color: var(--text-muted); padding: 6px 8px; cursor: pointer; transition: all 0.2s; display: flex; align-items: center; }
.btn-icon:hover, .btn-icon.active { border-color: var(--accent); color: var(--accent); background: rgba(0,212,170,0.1); }
.btn-primary { background: var(--accent); color: #000; border: none; padding: 12px 32px; border-radius: var(--radius); font-size: 15px; font-weight: 600; cursor: pointer; transition: all 0.2s; }
.btn-primary:hover { background: var(--accent-hover); transform: translateY(-1px); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }
.btn-large { padding: 14px 48px; font-size: 16px; }
.btn-secondary { background: var(--bg-input); color: var(--text); border: 1px solid var(--border); padding: 12px 32px; border-radius: var(--radius); font-size: 15px; cursor: pointer; transition: all 0.2s; }
.btn-secondary:hover { border-color: var(--text-muted); }
.btn-download { background: var(--bg-input); border: 1px solid var(--border); color: var(--text); padding: 8px 16px; border-radius: 4px; font-size: 13px; cursor: pointer; text-decoration: none; transition: all 0.2s; display: inline-block; }
.btn-download:hover { border-color: var(--accent); color: var(--accent); }
.btn-toggle { background: none; border: none; color: var(--text-muted); padding: 6px 16px; border-radius: 4px; cursor: pointer; font-size: 13px; transition: all 0.2s; }
.btn-toggle.active { background: var(--accent); color: #000; font-weight: 600; }

/* Upload */
.upload-zone { border: 2px dashed var(--border); border-radius: var(--radius); padding: 50px 20px; text-align: center; cursor: pointer; transition: all 0.3s; background: var(--bg-card); }
.upload-zone:hover, .upload-zone.drag-over { border-color: var(--accent); background: rgba(0,212,170,0.05); }
.upload-content svg { color: var(--text-muted); margin-bottom: 12px; }
.upload-content p { font-size: 17px; margin-bottom: 6px; }
.upload-hint { font-size: 14px !important; color: var(--text-muted) !important; }

/* Preview */
.preview-section { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; margin-top: 20px; }
.preview-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.preview-header h2 { font-size: 17px; }
.preview-toggle { display: flex; gap: 4px; background: var(--bg); border-radius: 6px; padding: 3px; }
.preview-container { position: relative; background: var(--checkerboard); border-radius: 4px; overflow: hidden; display: flex; justify-content: center; min-height: 250px; max-height: 550px; }
.preview-container.eyedropper-mode { cursor: crosshair; }
#preview-canvas { max-width: 100%; max-height: 550px; object-fit: contain; transform-origin: center center; }
.preview-container.zoomed #preview-canvas { image-rendering: pixelated; }
.preview-actions { display: flex; gap: 12px; margin-top: 14px; justify-content: center; }

/* Results */
.results-section { margin-top: 20px; }
.results-section h2 { font-size: 17px; margin-bottom: 14px; }
.results-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; margin-bottom: 18px; }
.result-card { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.result-card .card-preview { background: var(--checkerboard); height: 180px; display: flex; align-items: center; justify-content: center; overflow: hidden; }
.result-card .card-preview img { max-width: 100%; max-height: 100%; object-fit: contain; }
.result-card .card-info { padding: 10px 12px; display: flex; flex-direction: column; gap: 6px; }
.result-card .card-top { display: flex; justify-content: space-between; align-items: center; }
.result-card .card-name { font-size: 13px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 130px; }
.result-card .card-actions { display: flex; gap: 6px; }
.result-card .card-settings { display: flex; flex-wrap: wrap; gap: 4px 6px; font-size: 10px; color: var(--text-muted); padding: 4px 0 0; border-top: 1px solid var(--border); }
.result-card .card-settings span { background: rgba(0,212,170,0.08); padding: 1px 5px; border-radius: 3px; white-space: nowrap; }
/* Queue badge */
.queue-badge { display: inline-block; background: #ff4444; color: #fff; font-size: 11px; font-weight: 700; min-width: 18px; height: 18px; line-height: 18px; border-radius: 9px; text-align: center; margin-left: 8px; padding: 0 5px; vertical-align: middle; }
.results-count { font-size: 13px; font-weight: 400; color: var(--text-muted); }

/* Pending cards */
.result-card.pending { border-color: var(--accent); border-style: dashed; }
.result-card.error { border-color: #ff4444; }
.card-pending-preview { flex-direction: column; gap: 10px; color: var(--text-muted); font-size: 13px; background: var(--bg) !important; }
.card-error-preview { flex-direction: column; gap: 8px; color: #ff6666; font-size: 12px; background: rgba(255,68,68,0.05) !important; }
.error-icon { display: inline-flex; align-items: center; justify-content: center; width: 32px; height: 32px; border-radius: 50%; background: rgba(255,68,68,0.15); color: #ff4444; font-size: 18px; font-weight: 700; }

/* Pending spinner */
.pending-spinner { width: 28px; height: 28px; border: 3px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.8s linear infinite; }

/* Inspected card */
.result-card.inspected { border-color: var(--accent); border-width: 2px; box-shadow: 0 0 12px rgba(0, 212, 170, 0.3); }
.result-card:not(.pending):not(.error):hover { border-color: var(--accent); opacity: 0.9; transition: all 0.15s; }

.results-actions { display: flex; gap: 12px; justify-content: center; margin-top: 18px; }

/* Generation */
.gen-controls { flex-direction: column; }
.gen-actions { text-align: center; margin-bottom: 20px; }
.gen-results { margin-top: 20px; }
.gen-compare { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 16px; }
.gen-card { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.gen-card h3 { font-size: 14px; padding: 10px 14px; color: var(--text-muted); border-bottom: 1px solid var(--border); }
.gen-preview { height: 350px; display: flex; align-items: center; justify-content: center; overflow: hidden; }
.gen-preview.checkerboard { background: var(--checkerboard); }
.gen-preview img { max-width: 100%; max-height: 100%; object-fit: contain; }
.gen-download { display: flex; gap: 10px; justify-content: center; }

/* Loader */
.loader-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(26,26,46,0.92); display: flex; flex-direction: column; align-items: center; justify-content: center; z-index: 1000; }
.loader-spinner { width: 44px; height: 44px; border: 3px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.loader-overlay p { margin-top: 14px; color: var(--text-muted); font-size: 15px; }

/* Preview Toolbar */
.preview-toolbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; gap: 12px; flex-wrap: wrap; }
.bg-swatches { display: flex; align-items: center; gap: 6px; }
.swatch-label { font-size: 12px; color: var(--text-muted); margin-right: 2px; }
.swatch { width: 26px; height: 26px; border-radius: 4px; border: 2px solid var(--border); cursor: pointer; padding: 0; transition: all 0.15s; position: relative; background: none; }
.swatch:hover { border-color: var(--text-muted); transform: scale(1.1); }
.swatch.active { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(0,212,170,0.3); }
.swatch-checker { display: block; width: 100%; height: 100%; border-radius: 2px; background: conic-gradient(#ccc 25%, #fff 25% 50%, #ccc 50% 75%, #fff 75%); background-size: 8px 8px; }
.swatch-custom { width: 26px; height: 26px; border: 2px solid var(--border); border-radius: 4px; cursor: pointer; padding: 1px; background: none; transition: all 0.15s; }
.swatch-custom:hover { border-color: var(--text-muted); transform: scale(1.1); }
.swatch-custom.swatch-active { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(0,212,170,0.3); }
.zoom-controls { display: flex; align-items: center; gap: 4px; }
.zoom-controls .btn-icon { width: 28px; height: 28px; display: flex; align-items: center; justify-content: center; font-size: 16px; font-weight: 700; }
.zoom-controls span { font-size: 12px; color: var(--text-muted); min-width: 42px; text-align: center; font-variant-numeric: tabular-nums; }
.preview-container.zoomed:not(.eyedropper-mode) { cursor: grab; }
.preview-container.panning { cursor: grabbing !important; }

/* Radio button groups */
.radio-group { display: flex; gap: 6px; flex-wrap: wrap; }
.radio-btn { display: inline-flex; align-items: center; gap: 4px; background: var(--bg-input); border: 1px solid var(--border); border-radius: 4px; padding: 5px 10px; font-size: 13px; color: var(--text); cursor: pointer; transition: all 0.15s; }
.radio-btn:hover { border-color: var(--accent); }
.radio-btn:has(input:checked) { border-color: var(--accent); background: rgba(0,212,170,0.12); color: var(--accent); font-weight: 600; }
.radio-btn input[type="radio"] { accent-color: var(--accent); margin: 0; }

/* Help tooltips */
.help-tip { display: inline-flex; align-items: center; justify-content: center; width: 16px; height: 16px; border-radius: 50%; background: rgba(0,212,170,0.15); color: var(--accent); font-size: 11px; font-weight: 700; cursor: pointer; position: relative; vertical-align: middle; margin-left: 4px; border: 1px solid rgba(0,212,170,0.3); transition: all 0.15s; user-select: none; }
.help-tip:hover { background: rgba(0,212,170,0.3); transform: scale(1.15); }
.help-tip-popup { background: var(--bg-card); border: 1px solid var(--accent); border-radius: 6px; padding: 10px 14px; font-size: 12px; font-weight: 400; color: var(--text); white-space: normal; width: 240px; box-shadow: 0 4px 20px rgba(0,0,0,0.5); pointer-events: none; line-height: 1.5; }

/* Favorite profile cards */
.fav-card { display: flex; flex-direction: column; background: var(--bg-input); border: 1px solid var(--border); border-radius: 8px; overflow: hidden; width: 200px; min-width: 200px; transition: all 0.15s; }
.fav-card.fav-card-wide { width: 260px; min-width: 260px; }
.fav-card:hover { border-color: var(--accent); transform: translateY(-2px); box-shadow: 0 4px 12px rgba(0,0,0,0.3); }
.fav-card.active { border-color: var(--accent); box-shadow: 0 0 12px rgba(0,212,170,0.35); }
.fav-preview-box { position: relative; width: 100%; height: 150px; background: var(--checkerboard); display: flex; align-items: center; justify-content: center; cursor: pointer; overflow: hidden; border-bottom: 1px solid var(--border); }
.fav-preview-img { width: 100%; height: 100%; object-fit: cover; }
.fav-preview-empty { width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; font-size: 32px; color: var(--text-muted); opacity: 0.4; }
.fav-preview-empty:hover { opacity: 0.7; }
.fav-img-overlay { position: absolute; inset: 0; background: rgba(0,0,0,0.5); display: flex; align-items: center; justify-content: center; opacity: 0; transition: opacity 0.2s; }
.fav-preview-box:hover .fav-img-overlay { opacity: 1; }
.fav-btn-change-img { background: rgba(255,255,255,0.15); border: 2px solid rgba(255,255,255,0.5); color: #fff; font-size: 22px; width: 44px; height: 44px; border-radius: 50%; cursor: pointer; transition: all 0.15s; display: flex; align-items: center; justify-content: center; }
.fav-btn-change-img:hover { background: rgba(255,255,255,0.3); transform: scale(1.1); }
.fav-card-body { padding: 8px 10px; }
.fav-card-header { display: flex; align-items: center; gap: 5px; margin-bottom: 6px; }
.fav-star { color: #f1c40f; font-size: 15px; flex-shrink: 0; }
.fav-card-name { font-size: 13px; font-weight: 600; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.fav-card-actions { display: flex; gap: 6px; }
.fav-btn-load { background: var(--accent); color: #000; border: none; padding: 4px 12px; border-radius: 4px; font-size: 12px; font-weight: 600; cursor: pointer; transition: all 0.15s; }
.fav-btn-load:hover { background: var(--accent-hover); }
.fav-btn-edit { background: none; border: 1px solid var(--border); color: var(--text-muted); padding: 4px 8px; border-radius: 4px; font-size: 13px; cursor: pointer; transition: all 0.15s; }
.fav-btn-edit:hover { border-color: var(--accent); color: var(--accent); }
.fav-btn-master { background: none; border: 1px solid var(--border); color: var(--text-muted); padding: 4px 8px; border-radius: 4px; font-size: 11px; cursor: pointer; transition: all 0.15s; }
.fav-btn-master:hover { border-color: #f1c40f; color: #f1c40f; }
.fav-card.master { border-color: #f1c40f; border-width: 2px; box-shadow: 0 0 12px rgba(241,196,15,0.2); }
.fav-card.master.active { border-color: var(--accent); box-shadow: 0 0 12px rgba(0,212,170,0.35); }
.fav-card.master .fav-btn-master { color: #f1c40f; border-color: #f1c40f; }
.fav-master-badge { font-size: 10px; background: rgba(241,196,15,0.15); color: #f1c40f; padding: 1px 6px; border-radius: 8px; font-weight: 600; white-space: nowrap; }
#pp-color-swatch:hover { border-color: var(--accent) !important; box-shadow: 0 0 0 2px rgba(0,212,170,0.3); }

/* Favorite zoom overlay */
.fav-zoom-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.85); display: flex; align-items: center; justify-content: center; z-index: 10000; cursor: zoom-out; }
.fav-zoom-content { text-align: center; }
.fav-zoom-content img { width: 600px; max-width: 90vw; max-height: 80vh; object-fit: contain; border-radius: 8px; border: 2px solid var(--border); image-rendering: auto; }
.fav-zoom-title { color: var(--text); font-size: 16px; margin-top: 12px; font-weight: 600; }

/* PRO settings disabled state */
#fa-pro-settings-section.pro-disabled > *:not(h3):not(:first-child) { opacity: 0.3; pointer-events: none; filter: grayscale(0.8); }
#fa-pro-settings-section.pro-disabled h3:not(:first-of-type) { opacity: 0.3; }

/* Retry button in error cards */
.btn-retry, .btn-retry-adjust { background: #e67e22; color: white; border: none; padding: 5px 12px; border-radius: 4px; font-size: 12px; cursor: pointer; transition: all 0.15s; }
.btn-retry:hover { background: #f39c12; }
.btn-retry-adjust { background: #2980b9; }
.btn-retry-adjust:hover { background: #3498db; }

/* Queue visual - current + upcoming */
.queue-item-current { display: flex; flex-direction: column; align-items: center; min-width: 140px; }
.queue-thumb-current { position: relative; width: 140px; height: 140px; border-radius: 8px; border: 2px solid var(--accent); background: var(--checkerboard); display: flex; align-items: center; justify-content: center; overflow: hidden; box-shadow: 0 0 16px rgba(0,212,170,0.25); }
.queue-thumb-current img { max-width: 100%; max-height: 100%; object-fit: contain; }
.queue-spinner-overlay { position: absolute; inset: 0; background: rgba(0,0,0,0.35); display: flex; align-items: center; justify-content: center; }
.queue-item-name { font-size: 11px; color: var(--text); margin-top: 6px; max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-align: center; }
.queue-item-badge { font-size: 10px; background: var(--accent); color: #000; padding: 2px 8px; border-radius: 10px; font-weight: 600; margin-top: 3px; }
.queue-upcoming-list { display: flex; gap: 10px; align-items: flex-start; overflow-x: auto; flex: 1; padding: 4px 0; }
.queue-upcoming-item { display: flex; flex-direction: column; align-items: center; min-width: 80px; opacity: 0.7; transition: opacity 0.2s; }
.queue-upcoming-item:hover { opacity: 1; }
.queue-upcoming-thumb { width: 80px; height: 80px; border-radius: 6px; border: 1px solid var(--border); background: var(--checkerboard); display: flex; align-items: center; justify-content: center; overflow: hidden; }
.queue-upcoming-thumb img { max-width: 100%; max-height: 100%; object-fit: contain; }
.queue-upcoming-item .queue-item-name { max-width: 80px; font-size: 10px; color: var(--text-muted); }
.queue-upcoming-item .queue-item-pos { font-size: 9px; color: var(--text-muted); opacity: 0.6; margin-top: 2px; }

/* Responsive */
@media (max-width: 768px) {
    .controls { flex-direction: column; }
    .results-grid { grid-template-columns: 1fr; }
    .gen-compare { grid-template-columns: 1fr; }
    header { padding: 12px 16px; }
    .tab-content { padding: 0 14px 14px; }
}
