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

:root {
    --bg: #0a0a0a;
    --surface: #141414;
    --surface-2: #1e1e1e;
    --border: #2a2a2a;
    --text: #e8e8e8;
    --text-dim: #888;
    --primary: #7c5cfc;
    --primary-hover: #6a48e8;
    --danger: #e54545;
    --danger-hover: #c93030;
    --success: #34c759;
    --radius: 12px;
    --radius-sm: 8px;
}

html, body {
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    -webkit-font-smoothing: antialiased;
    overflow-x: hidden;
    padding-bottom: env(safe-area-inset-bottom);
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
}

a {
    color: var(--primary);
}

.hidden {
    display: none !important;
}

/* Splash Screen */
.splash {
    position: fixed;
    inset: 0;
    background: var(--bg);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 999;
}

.splash-inner {
    width: 100%;
    max-width: 340px;
    padding: 20px;
    text-align: center;
}

.splash-title {
    font-size: 2rem;
    font-weight: 800;
    background: linear-gradient(135deg, var(--primary), #c084fc);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 8px;
}

.splash-subtitle {
    color: var(--text-dim);
    font-size: 0.9rem;
    margin-bottom: 32px;
}

/* Header */
header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    padding-top: calc(env(safe-area-inset-top, 0px) + 16px);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    background: var(--bg);
    z-index: 100;
}

header h1 {
    font-size: 1.25rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--primary), #c084fc);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 24px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

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

.btn-primary {
    background: var(--primary);
    color: #fff;
}

.btn-primary:hover:not(:disabled) {
    background: var(--primary-hover);
}

.btn-secondary {
    background: var(--surface-2);
    color: var(--text);
    border: 1px solid var(--border);
}

.btn-secondary:hover {
    background: var(--border);
}

.btn-danger {
    background: transparent;
    color: var(--danger);
    border: 1px solid var(--danger);
}

.btn-danger:hover {
    background: var(--danger);
    color: #fff;
}

.btn-sm {
    padding: 6px 14px;
    font-size: 0.8rem;
}

.icon-btn {
    background: none;
    border: none;
    color: var(--text-dim);
    cursor: pointer;
    padding: 8px;
    border-radius: var(--radius-sm);
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.icon-btn:hover {
    color: var(--text);
    background: var(--surface-2);
}

.icon-btn.small {
    padding: 4px;
}

/* Panels */
.panel {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(8px);
    z-index: 200;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    animation: fadeIn 0.2s ease;
    padding-bottom: env(safe-area-inset-bottom);
}

.panel.hidden {
    display: none;
}

.panel-content {
    background: var(--surface);
    border-radius: var(--radius) var(--radius) 0 0;
    padding: 24px 20px 40px;
    width: 100%;
    max-width: 480px;
    max-height: 80vh;
    overflow-y: auto;
    animation: slideUp 0.3s ease;
}

.panel-content h2 {
    font-size: 1.1rem;
    margin-bottom: 20px;
}

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

.form-group label {
    display: block;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-dim);
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.input-row {
    display: flex;
    gap: 8px;
}

input[type="text"],
input[type="password"],
textarea,
select {
    width: 100%;
    padding: 12px 14px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: 0.95rem;
    font-family: inherit;
    outline: none;
    transition: border-color 0.2s;
}

input:focus,
textarea:focus,
select:focus {
    border-color: var(--primary);
}

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

textarea.prompt-secondary {
    min-height: 50px;
    font-size: 0.85rem;
    color: var(--text-dim);
    border-style: dashed;
}

/* Toggle */
.toggle-row {
    margin-bottom: 8px;
}

.toggle-label {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-size: 0.85rem;
    color: var(--text-dim);
    user-select: none;
}

.toggle-label input[type="checkbox"] {
    display: none;
}

.toggle-switch {
    position: relative;
    width: 36px;
    height: 20px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 10px;
    transition: all 0.2s;
    flex-shrink: 0;
}

.toggle-switch::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 14px;
    height: 14px;
    background: var(--text-dim);
    border-radius: 50%;
    transition: all 0.2s;
}

.toggle-label input:checked + .toggle-switch {
    background: var(--primary);
    border-color: var(--primary);
}

.toggle-label input:checked + .toggle-switch::after {
    left: 18px;
    background: #fff;
}

.toggle-text {
    font-weight: 500;
}

.toggle-label input:checked ~ .toggle-text {
    color: var(--primary);
}

.label-hint {
    font-weight: 400;
    text-transform: none;
    letter-spacing: 0;
    opacity: 0.6;
    font-size: 0.7rem;
}

select {
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23888' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 32px;
}

.key-actions {
    display: flex;
    gap: 8px;
    margin-top: 10px;
}

.hint {
    font-size: 0.75rem;
    color: var(--text-dim);
    margin-top: 8px;
}

/* Header Right */
.header-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

.version-badge {
    font-size: 0.65rem;
    color: var(--text-dim);
    background: var(--surface-2);
    padding: 2px 8px;
    border-radius: 10px;
}

/* Tab Navigation */
.tab-nav {
    display: flex;
    gap: 4px;
    padding: 10px 20px;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: calc(env(safe-area-inset-top, 0px) + 53px);
    z-index: 99;
}

.tab-btn {
    flex: 1;
    padding: 10px 16px;
    background: var(--surface-2);
    color: var(--text-dim);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.tab-btn.active {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}

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

.tab-content.hidden {
    display: none !important;
}

/* Cost Estimate in Button */
.cost-estimate {
    font-weight: 400;
    opacity: 0.8;
    font-size: 0.85em;
}

/* Range Slider */
.range-slider {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 6px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 3px;
    outline: none;
    cursor: pointer;
}

.range-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 22px;
    height: 22px;
    background: var(--primary);
    border-radius: 50%;
    cursor: pointer;
    border: 2px solid #fff;
    box-shadow: 0 1px 4px rgba(0,0,0,0.3);
}

.range-slider::-moz-range-thumb {
    width: 22px;
    height: 22px;
    background: var(--primary);
    border-radius: 50%;
    cursor: pointer;
    border: 2px solid #fff;
    box-shadow: 0 1px 4px rgba(0,0,0,0.3);
}

/* Controls Row */
.controls-row {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
    margin-bottom: 16px;
}

.controls-row-3 {
    grid-template-columns: repeat(3, 1fr);
}

.controls-row-4 {
    grid-template-columns: repeat(4, 1fr);
}

.form-group.compact {
    margin-bottom: 0;
}

.form-group.compact select {
    padding: 10px 8px;
    font-size: 0.85rem;
    padding-right: 28px;
    background-position: right 6px center;
}

/* Upload */
.upload-section {
    padding: 20px 20px 0;
}

.drop-zone {
    position: relative;
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    cursor: pointer;
    transition: border-color 0.2s;
    min-height: 200px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.drop-zone:hover,
.drop-zone.dragover {
    border-color: var(--primary);
}

.drop-zone input[type="file"] {
    position: absolute;
    inset: 0;
    opacity: 0;
    cursor: pointer;
    z-index: 2;
}

.drop-zone-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    color: var(--text-dim);
    padding: 40px 20px;
    text-align: center;
}

.drop-zone-placeholder p {
    font-size: 0.9rem;
}

.image-preview {
    width: 100%;
    max-height: 400px;
    object-fit: contain;
    display: block;
}

.image-preview.hidden {
    display: none;
}

.clear-image-btn {
    position: absolute;
    top: 10px;
    right: 10px;
    z-index: 3;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.7);
    color: #fff;
    border: none;
    font-size: 1.2rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.clear-image-btn.hidden {
    display: none;
}

/* Controls */
.controls-section {
    padding: 20px;
}

.btn-generate {
    width: 100%;
    padding: 16px;
    font-size: 1.05rem;
    border-radius: var(--radius);
}

.btn-cancel {
    width: 100%;
    margin-top: 8px;
    padding: 12px;
    border-radius: var(--radius);
}

.btn-cancel.hidden {
    display: none;
}

.btn-loading {
    display: inline-flex;
    align-items: center;
    gap: 10px;
}

.btn-loading.hidden {
    display: none;
}

.btn-text.hidden {
    display: none;
}

.spinner {
    width: 18px;
    height: 18px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

/* History */
.history-section {
    padding: 0 20px 40px;
}

.history-section.hidden {
    display: none;
}

.history-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}

.history-header h2 {
    font-size: 1rem;
    font-weight: 600;
}

.history-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 16px;
}

/* History Item */
.history-item {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    animation: fadeIn 0.3s ease;
}

.history-item video,
.history-item img.history-img {
    width: 100%;
    display: block;
    background: #000;
}

.history-item img.history-img {
    object-fit: contain;
    max-height: 400px;
}

.history-item-info {
    padding: 12px;
}

.history-item-prompt {
    font-size: 0.85rem;
    color: var(--text-dim);
    margin-bottom: 10px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.history-item-actions {
    display: flex;
    gap: 8px;
}

/* Generating Item */
.history-item.generating {
    border-color: var(--primary);
}

.generating-placeholder {
    height: 200px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    background: var(--surface-2);
}

.generating-placeholder .spinner {
    width: 28px;
    height: 28px;
    border-color: rgba(124, 92, 252, 0.3);
    border-top-color: var(--primary);
}

.generating-placeholder p {
    font-size: 0.85rem;
    color: var(--text-dim);
}

/* Error state */
.history-item.error {
    border-color: var(--danger);
}

.error-placeholder {
    height: 120px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--surface-2);
    color: var(--danger);
    font-size: 0.85rem;
    padding: 20px;
    text-align: center;
}

/* Animations */
@keyframes spin {
    to { transform: rotate(360deg); }
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes slideUp {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
}

/* Modal */
.modal {
    position: fixed;
    inset: 0;
    z-index: 500;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.2s ease;
    padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.modal.hidden {
    display: none !important;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(4px);
}

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

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}

.error-code {
    display: inline-block;
    background: var(--danger);
    color: #fff;
    font-size: 0.75rem;
    font-weight: 700;
    padding: 4px 10px;
    border-radius: 20px;
}

.modal-close {
    background: none;
    border: none;
    color: var(--text-dim);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0 4px;
    line-height: 1;
}

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

.modal-title {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 8px;
}

.modal-explanation {
    font-size: 0.9rem;
    color: var(--text-dim);
    line-height: 1.5;
    margin-bottom: 12px;
}

.error-details {
    background: var(--surface-2);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    font-size: 0.8rem;
    color: var(--text-dim);
}

.error-details summary {
    cursor: pointer;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 4px;
}

.error-details pre {
    white-space: pre-wrap;
    word-break: break-all;
    margin-top: 8px;
    font-family: 'SF Mono', 'Fira Code', monospace;
    font-size: 0.75rem;
    max-height: 150px;
    overflow-y: auto;
}

/* Crop Button on Image Preview */
.crop-image-btn {
    position: absolute;
    bottom: 10px;
    left: 10px;
    z-index: 3;
    padding: 6px 16px;
    border-radius: 20px;
    background: rgba(0, 0, 0, 0.7);
    color: #fff;
    border: 1px solid rgba(255, 255, 255, 0.2);
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    backdrop-filter: blur(4px);
    transition: all 0.2s;
}

.crop-image-btn:hover {
    background: var(--primary);
    border-color: var(--primary);
}

.crop-image-btn.hidden {
    display: none;
}

/* Crop Modal */
.crop-modal-content {
    position: relative;
    background: var(--bg);
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
}

.crop-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.crop-header h3 {
    font-size: 1rem;
    font-weight: 600;
}

.crop-ratios {
    display: flex;
    gap: 6px;
    padding: 12px 16px;
    overflow-x: auto;
    flex-shrink: 0;
    -webkit-overflow-scrolling: touch;
}

.crop-ratio-btn {
    flex-shrink: 0;
    padding: 6px 14px;
    border-radius: 20px;
    background: var(--surface-2);
    color: var(--text-dim);
    border: 1px solid var(--border);
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.crop-ratio-btn.active {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}

.crop-container {
    flex: 1;
    position: relative;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    touch-action: none;
}

.crop-container canvas {
    max-width: 100%;
    max-height: 100%;
    display: block;
}

.crop-overlay {
    position: absolute;
    inset: 0;
    pointer-events: none;
}

.crop-box {
    position: absolute;
    border: 2px solid #fff;
    box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.55);
    pointer-events: auto;
    cursor: move;
    touch-action: none;
}

.crop-box::before {
    content: '';
    position: absolute;
    inset: 0;
    background: repeating-linear-gradient(
        0deg,
        transparent,
        transparent calc(33.33% - 0.5px),
        rgba(255, 255, 255, 0.25) calc(33.33% - 0.5px),
        rgba(255, 255, 255, 0.25) calc(33.33% + 0.5px),
        transparent calc(33.33% + 0.5px)
    ),
    repeating-linear-gradient(
        90deg,
        transparent,
        transparent calc(33.33% - 0.5px),
        rgba(255, 255, 255, 0.25) calc(33.33% - 0.5px),
        rgba(255, 255, 255, 0.25) calc(33.33% + 0.5px),
        transparent calc(33.33% + 0.5px)
    );
    pointer-events: none;
}

.crop-handle {
    position: absolute;
    width: 20px;
    height: 20px;
    pointer-events: auto;
    touch-action: none;
}

.crop-handle::after {
    content: '';
    position: absolute;
    width: 16px;
    height: 16px;
    background: #fff;
    border-radius: 50%;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
}

.crop-handle.nw { top: -10px; left: -10px; cursor: nw-resize; }
.crop-handle.ne { top: -10px; right: -10px; cursor: ne-resize; }
.crop-handle.sw { bottom: -10px; left: -10px; cursor: sw-resize; }
.crop-handle.se { bottom: -10px; right: -10px; cursor: se-resize; }

.crop-handle.nw::after { top: 2px; left: 2px; }
.crop-handle.ne::after { top: 2px; right: 2px; }
.crop-handle.sw::after { bottom: 2px; left: 2px; }
.crop-handle.se::after { bottom: 2px; right: 2px; }

/* Save Modal */
.save-modal-content {
    position: relative;
    background: var(--bg);
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
}

.save-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    flex-shrink: 0;
}

.save-hint {
    font-size: 0.9rem;
    color: var(--primary);
    font-weight: 600;
    animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.save-modal-body {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 10px 40px;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
}

.save-modal-media {
    max-width: 100%;
    max-height: 100%;
    border-radius: var(--radius);
    -webkit-touch-callout: default !important;
    -webkit-user-select: auto !important;
    user-select: auto !important;
}

/* Error card clickable */
.history-item.error .error-placeholder {
    cursor: pointer;
}

.history-item.error .error-placeholder:hover {
    background: var(--surface);
}

/* Provider badges */
.provider-badge {
    display: inline-block;
    font-size: 0.6rem;
    font-weight: 700;
    padding: 2px 6px;
    border-radius: 4px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    margin-right: 6px;
    vertical-align: middle;
}

.provider-grok { background: #1a3a5c; color: #6db3f2; }
.provider-wavespeed { background: #3a1a5c; color: #c28af2; }
.provider-replicate { background: #5c3a1a; color: #f2b86d; }

/* Provider notice */
.provider-notice {
    padding: 14px 20px;
    background: rgba(124, 92, 252, 0.08);
    border-left: 3px solid var(--primary);
    color: var(--text-dim);
    font-size: 0.85rem;
    margin: 0 20px;
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

.provider-notice.hidden {
    display: none;
}

/* Session cost button */
.session-cost {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--success);
    background: rgba(52, 199, 89, 0.1);
    padding: 4px 12px;
    border-radius: 20px;
    white-space: nowrap;
    border: none;
    cursor: pointer;
    transition: all 0.2s;
}

.session-cost:hover {
    background: rgba(52, 199, 89, 0.2);
}

/* Cost Log Panel */
.cost-log-section {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 20px;
}

.cost-log-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 12px;
    background: var(--surface-2);
    border-radius: var(--radius-sm);
}

.cost-log-row-total {
    background: rgba(52, 199, 89, 0.1);
    border: 1px solid rgba(52, 199, 89, 0.2);
}

.cost-log-label {
    font-size: 0.85rem;
    color: var(--text-dim);
    font-weight: 500;
}

.cost-log-value {
    font-size: 1rem;
    font-weight: 700;
    color: var(--text);
}

.cost-log-row-total .cost-log-value {
    color: var(--success);
}

.cost-log-subheader {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 8px;
}

.cost-log-daily {
    max-height: 200px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.cost-log-day {
    display: flex;
    justify-content: space-between;
    padding: 8px 12px;
    background: var(--surface-2);
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
}

.cost-log-day-date {
    color: var(--text-dim);
}

.cost-log-day-amount {
    color: var(--text);
    font-weight: 600;
}

.cost-log-empty {
    text-align: center;
    color: var(--text-dim);
    font-size: 0.8rem;
    padding: 12px;
}

/* Lock toggles */
.label-with-lock {
    display: flex;
    align-items: center;
    gap: 6px;
    width: 100%;
}

.lock-btn {
    background: none;
    border: none;
    font-size: 0.75rem;
    cursor: pointer;
    padding: 2px 4px;
    border-radius: 4px;
    margin-left: auto;
    opacity: 0.7;
    transition: opacity 0.2s;
}

.lock-btn:hover {
    opacity: 1;
}

.lock-btn.locked {
    opacity: 1;
}

/* Provider hints */
.provider-hint {
    font-size: 0.75rem;
    color: var(--text-dim);
    margin-bottom: 8px;
    font-style: italic;
}

/* AI Prompt Generator */
.ai-prompt-group {
    background: rgba(124, 92, 252, 0.06);
    border: 1px solid rgba(124, 92, 252, 0.2);
    border-radius: var(--radius);
    padding: 12px;
    margin-bottom: 16px;
}

.ai-input-row {
    display: flex;
    gap: 8px;
}

.ai-input {
    flex: 1;
    padding: 10px 14px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: 0.95rem;
    outline: none;
    min-height: 80px;
    resize: vertical;
    font-family: inherit;
    line-height: 1.4;
}

.ai-input:focus {
    border-color: var(--primary);
}

.ai-btn {
    flex-shrink: 0;
    padding: 10px 14px;
}

.spicy-scale {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 8px;
}

.spicy-scale label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-dim);
    white-space: nowrap;
    min-width: 70px;
    text-transform: none;
    letter-spacing: 0;
    margin-bottom: 0;
}

.spicy-slider {
    flex: 1;
}

.ai-status {
    font-size: 0.8rem;
    margin-top: 8px;
    padding: 6px 10px;
    border-radius: var(--radius-sm);
    background: var(--surface-2);
}

.ai-status.hidden {
    display: none;
}

.ai-status.loading {
    color: var(--primary);
}

.ai-status.error {
    color: var(--danger);
}

.ai-status.success {
    color: var(--success);
}

/* Controls row 2-col */
.controls-row-2 {
    grid-template-columns: repeat(2, 1fr);
}

/* History item actions — right-aligned for one-handed use */
.history-item-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
}

/* Fullscreen Gallery */
.gallery {
    position: fixed;
    inset: 0;
    background: #000;
    z-index: 600;
    display: flex;
    flex-direction: column;
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
}

.gallery.hidden {
    display: none !important;
}

.gallery-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    flex-shrink: 0;
    z-index: 2;
}

.gallery-counter {
    font-size: 0.9rem;
    color: var(--text-dim);
    font-weight: 600;
}

.gallery-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

.gallery-close {
    background: none;
    border: none;
    color: var(--text);
    font-size: 2rem;
    cursor: pointer;
    padding: 0 4px;
    line-height: 1;
}

.gallery-track {
    flex: 1;
    display: flex;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}

.gallery-track::-webkit-scrollbar {
    display: none;
}

.gallery-slide {
    flex: 0 0 100%;
    scroll-snap-align: center;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 10px;
}

.gallery-slide img,
.gallery-slide video {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    border-radius: var(--radius);
    -webkit-touch-callout: default !important;
}

/* Prompt Library */
.panel-header-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}

.panel-header-row h2 {
    margin-bottom: 0;
}

.library-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-height: 50vh;
    overflow-y: auto;
}

.library-item {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 12px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.library-item-name {
    font-size: 0.9rem;
    font-weight: 600;
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.library-item-actions {
    display: flex;
    gap: 6px;
    flex-shrink: 0;
}

.library-empty {
    text-align: center;
    color: var(--text-dim);
    font-size: 0.85rem;
    padding: 20px 0;
}

/* Tappable history media — opens gallery */
.history-item video,
.history-item img.history-img {
    cursor: pointer;
}

/* Responsive */
@media (min-width: 600px) {
    main {
        max-width: 560px;
        margin: 0 auto;
    }

    .history-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .panel-content {
        border-radius: var(--radius);
        margin-bottom: 20px;
    }

    .panel {
        align-items: center;
    }
}

@media (min-width: 900px) {
    main {
        max-width: 720px;
    }
}
