:root {
    --bg-color: #ffffff;
    --panel-bg: #fafafa;
    --border-color: #e5e7eb;
    --text-primary: #111111;
    --text-secondary: #6b7280;
    --accent: #111111;
    --accent-hover: #333333;
    --success: #10b981;
    --radius: 12px;
    --warning-bg: #fef3c7;
    --warning-text: #92400e;
    --warning-border: #fcd34d;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Pretendard', -apple-system, BlinkMacSystemFont, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-primary);
    min-height: 100vh;
    display: flex;
    justify-content: center;
}

.app-container {
    width: 100%;
    max-width: 960px;
    padding: 60px 24px;
    display: flex;
    flex-direction: column;
    align-items: center;
}

/* Header */
.header {
    text-align: center;
    margin-bottom: 48px;
}

.logo {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.5px;
}

.subtitle {
    color: var(--text-secondary);
    font-size: 0.95rem;
    margin-top: 8px;
    font-weight: 400;
}

/* Panels / Cards */
.glass-panel {
    background: var(--panel-bg);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 28px;
    width: 100%;
    max-width: 720px;
    transition: box-shadow 0.2s ease;
}

.glass-panel:hover {
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.04);
}

.mt-4 {
    margin-top: 20px;
}

.mt-6 {
    margin-top: 36px;
}

.section-title {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 16px;
}

.section-title h2 {
    font-size: 1.05rem;
    font-weight: 600;
    color: var(--text-primary);
}

.config-row {
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
}

.input-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
    flex: 1;
    min-width: 220px;
}

.input-group.full-width {
    flex-basis: 100%;
    min-width: 100%;
}

.input-group label {
    font-size: 0.85rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.text-input {
    background: #ffffff;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 10px 14px;
    color: var(--text-primary);
    font-size: 0.95rem;
    font-family: inherit;
    outline: none;
    transition: border-color 0.2s ease;
    width: 100%;
}

.text-input:focus {
    border-color: var(--accent);
}

.number-control {
    display: flex;
    align-items: center;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    overflow: hidden;
    width: fit-content;
    background: #ffffff;
}

.number-control button {
    background: transparent;
    border: none;
    color: var(--text-primary);
    padding: 10px 18px;
    cursor: pointer;
    font-size: 1.1rem;
    transition: background 0.2s;
}

.number-control button:hover {
    background: #f3f4f6;
}

.num-input {
    width: 50px;
    text-align: center;
    border: none;
    border-radius: 0;
    padding: 10px 0;
    background: transparent;
    -moz-appearance: textfield;
}

.num-input::-webkit-outer-spin-button,
.num-input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.page-count-hint {
    display: block;
    font-size: 0.72rem;
    color: var(--text-secondary);
    margin-top: 4px;
    font-weight: 500;
}

textarea {
    width: 100%;
    min-height: 100px;
    background: #ffffff;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 14px;
    color: var(--text-primary);
    font-size: 0.95rem;
    font-family: inherit;
    resize: vertical;
    outline: none;
    transition: border-color 0.2s ease;
}

textarea:focus {
    border-color: var(--accent);
}

/* ===== Aspect Ratio Selector ===== */
.ratio-selector {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.ratio-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 12px 14px;
    border: 2px solid var(--border-color);
    border-radius: 10px;
    background: #ffffff;
    cursor: pointer;
    transition: all 0.2s ease;
    min-width: 72px;
}

.ratio-btn:hover {
    border-color: #9ca3af;
}

.ratio-btn.active {
    border-color: var(--accent);
    background: #f9fafb;
    box-shadow: 0 0 0 1px var(--accent);
}

.ratio-preview {
    width: 36px;
    max-height: 48px;
    border: 2px solid var(--text-secondary);
    border-radius: 3px;
    background: #e5e7eb;
    transition: border-color 0.2s;
}

.ratio-btn.active .ratio-preview {
    border-color: var(--accent);
    background: #d1d5db;
}

.ratio-btn span {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-primary);
}

.ratio-btn small {
    font-size: 0.7rem;
    color: var(--text-secondary);
}

/* ===== Template Selector ===== */
.section-desc {
    font-size: 0.82rem;
    color: var(--text-secondary);
    margin-bottom: 14px;
    line-height: 1.5;
}

.template-selector {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.template-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
    padding: 10px 10px 8px;
    border: 2px solid var(--border-color);
    border-radius: 10px;
    background: #ffffff;
    cursor: pointer;
    transition: all 0.2s ease;
    min-width: 80px;
    flex: 1;
}

.template-btn:hover {
    border-color: #9ca3af;
}

.template-btn.active {
    border-color: var(--accent);
    background: #f9fafb;
    box-shadow: 0 0 0 1px var(--accent);
}

.template-btn span {
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--text-primary);
}

.template-btn small {
    font-size: 0.65rem;
    color: var(--text-secondary);
    text-align: center;
}

/* Template mini previews */
.tmpl-preview {
    width: 52px;
    height: 52px;
    border: 1.5px solid #d1d5db;
    border-radius: 4px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: #f3f4f6;
    font-size: 8px;
    font-weight: 700;
    color: #6b7280;
}

.tp-block {
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Free */
.tmpl-free .tp-full {
    flex: 1;
    background: linear-gradient(135deg, #e0e7ff, #ddd6fe);
    font-size: 12px;
    color: #4f46e5;
}

/* Hero */
.tmpl-hero {
    flex-direction: column;
}

.tmpl-hero .tp-hero-img {
    flex: 3;
    background: #dbeafe;
}

.tmpl-hero .tp-hero-txt {
    flex: 1;
    background: #ffffff;
    border-top: 1px solid #d1d5db;
}

/* Center */
.tmpl-center {
    flex-direction: column;
}

.tmpl-center .tp-top-txt {
    flex: 1;
    background: #ffffff;
}

.tmpl-center .tp-center-img {
    flex: 2;
    background: #dbeafe;
    border-top: 1px solid #d1d5db;
    border-bottom: 1px solid #d1d5db;
}

.tmpl-center .tp-bot-txt {
    flex: 1;
    background: #ffffff;
}

/* Before-After */
.tmpl-ba {
    flex-direction: row;
}

.tmpl-ba .tp-ba-left {
    flex: 1;
    height: 100%;
    background: #e5e7eb;
    font-size: 9px;
}

.tmpl-ba .tp-ba-right {
    flex: 1;
    height: 100%;
    background: #d1fae5;
    border-left: 1px solid #d1d5db;
    font-size: 9px;
}

/* Ingredients */
.tmpl-ingr {
    flex-direction: row;
}

.tmpl-ingr .tp-ingr-img {
    flex: 1;
    height: 100%;
    background: #dbeafe;
}

.tmpl-ingr .tp-ingr-list {
    flex: 1;
    height: 100%;
    background: #ecfdf5;
    border-left: 1px solid #d1d5db;
}

/* Review */
.tmpl-review {
    flex-direction: column;
}

.tmpl-review .tp-rev-star {
    flex: 1;
    background: #fef3c7;
}

.tmpl-review .tp-rev-txt {
    flex: 1.5;
    background: #ffffff;
    border-top: 1px solid #d1d5db;
    border-bottom: 1px solid #d1d5db;
}

.tmpl-review .tp-rev-img {
    flex: 1;
    background: #dbeafe;
}

/* Motion/Dynamic */
.tmpl-motion {
    flex-direction: row;
}

.tmpl-motion .tp-motion-img {
    flex: 1;
    height: 100%;
    background: linear-gradient(135deg, #1e3a5f, #3b82f6);
    color: #fff;
}

.tmpl-motion .tp-motion-fx {
    flex: 1;
    height: 100%;
    background: linear-gradient(135deg, #7c3aed, #ec4899);
    border-left: 1px solid #d1d5db;
    color: #fff;
}

/* All-in-One */
.tmpl-allin {
    flex-direction: column;
}

.tmpl-allin .tp-al-hero {
    flex: 2;
    background: #dbeafe;
}

.tmpl-allin .tp-al-ingr {
    flex: 1;
    background: #ecfdf5;
    border-top: 1px solid #d1d5db;
}

.tmpl-allin .tp-al-ba {
    flex: 1;
    background: #e0e7ff;
    border-top: 1px solid #d1d5db;
    font-size: 6px;
}

.tmpl-allin .tp-al-rev {
    flex: 1;
    background: #fef3c7;
    border-top: 1px solid #d1d5db;
}

/* ===== Brand Info Grid ===== */
.brand-info-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 14px;
}

.brand-info-grid .input-group {
    flex: 1;
    min-width: 200px;
}

.brand-info-grid .input-group.full-width {
    flex-basis: 100%;
    min-width: 100%;
}

/* ===== Image Upload Grid (3 slots) ===== */
.image-upload-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 16px;
}

@media (min-width: 520px) {
    .image-upload-grid {
        grid-template-columns: 1fr 1fr 1fr;
    }
}

.image-slot {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.slot-label {
    font-size: 0.8rem;
    font-weight: 600;
    padding: 4px 0;
}

.core-label {
    color: var(--text-primary);
}

.concept-label {
    color: var(--text-secondary);
}

/* Upload Area */
.upload-area {
    border: 2px dashed var(--border-color);
    border-radius: 8px;
    padding: 24px 12px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s ease;
    background: #ffffff;
}

.slot-upload {
    min-height: 140px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.upload-area:hover,
.upload-area.dragover {
    border-color: var(--accent);
    background: #f9fafb;
}

.upload-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    color: var(--text-secondary);
}

.upload-content svg {
    stroke: var(--text-secondary);
}

.upload-content p {
    font-size: 0.85rem;
}

.sub-text {
    font-size: 0.75rem;
    color: #9ca3af;
}

.hidden {
    display: none !important;
}

/* Image Preview per slot */
.image-preview {
    width: 100%;
    border-radius: 8px;
    overflow: hidden;
    position: relative;
    border: 1px solid var(--border-color);
}

.image-preview img {
    width: 100%;
    height: 140px;
    object-fit: cover;
    background: #f9fafb;
    display: block;
}

.slot-change-btn {
    position: absolute;
    bottom: 8px;
    right: 8px;
    background: rgba(0, 0, 0, 0.65);
    color: #fff;
    border: none;
    border-radius: 6px;
    padding: 5px 12px;
    font-size: 0.75rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s;
    backdrop-filter: blur(4px);
}

.slot-change-btn:hover {
    background: rgba(0, 0, 0, 0.85);
}

/* Warning message */
.slot-warning {
    display: flex;
    align-items: flex-start;
    gap: 6px;
    background: var(--warning-bg);
    border: 1px solid var(--warning-border);
    border-radius: 6px;
    padding: 8px 10px;
    margin-top: 2px;
}

.slot-warning svg {
    stroke: var(--warning-text);
    flex-shrink: 0;
    margin-top: 1px;
}

.slot-warning span {
    font-size: 0.72rem;
    color: var(--warning-text);
    line-height: 1.4;
    font-weight: 500;
}

/* ===== Buttons ===== */
.primary-btn {
    background: var(--accent);
    color: #ffffff;
    border: none;
    padding: 14px 36px;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s ease, transform 0.15s ease;
    display: flex;
    justify-content: center;
    width: 100%;
    max-width: 360px;
    margin-left: auto;
    margin-right: auto;
}

.primary-btn:hover {
    background: var(--accent-hover);
    transform: translateY(-1px);
}

.primary-btn .glow {
    display: none;
}

.secondary-btn {
    background: #ffffff;
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    padding: 10px 20px;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

.secondary-btn:hover {
    background: #f3f4f6;
}

/* ===== Loading Overlay ===== */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.92);
    backdrop-filter: blur(6px);
    z-index: 100;
    display: flex;
    justify-content: center;
    align-items: center;
}

.agent-timeline {
    width: 100%;
    max-width: 480px;
    padding: 36px;
    background: #ffffff;
    border-radius: var(--radius);
    border: 1px solid var(--border-color);
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.08);
}

.loading-title {
    text-align: center;
    margin-bottom: 28px;
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--text-primary);
}

.steps {
    display: flex;
    flex-direction: column;
    gap: 18px;
    margin-bottom: 28px;
}

.step {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    opacity: 0.35;
    transition: opacity 0.4s ease;
}

.step.active {
    opacity: 1;
}

.step.done .dot {
    background: var(--success);
}

.step.active .dot {
    background: var(--accent);
    animation: pulse 1.5s infinite;
}

.dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: #d1d5db;
    margin-top: 5px;
    flex-shrink: 0;
}

.step .content h3 {
    font-size: 0.95rem;
    font-weight: 600;
    margin-bottom: 3px;
    color: var(--text-primary);
}

.step .content p {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

@keyframes pulse {
    0% {
        transform: scale(0.9);
        opacity: 1;
    }

    50% {
        transform: scale(1.1);
        opacity: 0.7;
    }

    100% {
        transform: scale(0.9);
        opacity: 1;
    }
}

.progress-bar-container {
    width: 100%;
    height: 4px;
    background: #e5e7eb;
    border-radius: 2px;
    overflow: hidden;
}

.progress-bar {
    height: 100%;
    width: 0%;
    background: var(--accent);
    transition: width 0.3s ease;
}

/* ===== Result View ===== */
.result-view {
    width: 100%;
    max-width: 1100px;
    display: flex;
    flex-direction: column;
}

.result-header {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 28px;
    padding-bottom: 20px;
    border-bottom: 1px solid var(--border-color);
    flex-wrap: wrap;
    gap: 12px;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 8px;
}

.header-left h2 {
    font-size: 1.3rem;
    font-weight: 700;
}

.result-actions {
    display: flex;
    gap: 10px;
}

.primary-btn-pink {
    background: var(--accent);
    color: #ffffff;
    border: none;
    padding: 10px 22px;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s, transform 0.15s;
}

.primary-btn-pink:hover {
    background: var(--accent-hover);
    transform: translateY(-1px);
}

.compositions-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 20px;
    width: 100%;
}

.composition-card {
    background: #ffffff;
    border-radius: var(--radius);
    border: 1px solid var(--border-color);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    transition: transform 0.2s ease, box-shadow 0.2s;
}

.composition-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.06);
}

.card-image-wrapper {
    width: 100%;
    aspect-ratio: 9/16;
    background: #f3f4f6;
    position: relative;
    overflow: hidden;
}

.card-image-wrapper img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.card-footer {
    padding: 14px 18px;
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    background: #ffffff;
    border-top: 1px solid var(--border-color);
}

.card-meta {
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.card-meta .label {
    font-size: 10px;
    font-weight: 700;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.card-meta .title {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-primary);
}

.card-actions {
    display: flex;
    gap: 6px;
    align-items: center;
}

.edit-icon,
.download-icon {
    color: #9ca3af;
    background: transparent;
    border: none;
    cursor: pointer;
    transition: color 0.2s;
    padding: 4px;
    display: flex;
    align-items: center;
}

.edit-icon:hover,
.download-icon:hover {
    color: var(--text-primary);
}

/* ===== Edit Panel ===== */
.edit-panel {
    border-top: 1px solid var(--border-color);
    padding: 14px 18px;
    background: #f9fafb;
}

.edit-prompt-area {
    display: flex;
    gap: 8px;
}

.edit-prompt-input {
    flex: 1;
    font-size: 0.85rem !important;
    padding: 8px 12px !important;
}

.edit-submit-btn {
    background: var(--accent);
    color: #ffffff;
    border: none;
    padding: 8px 16px;
    border-radius: 8px;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.2s, opacity 0.2s;
}

.edit-submit-btn:hover {
    background: var(--accent-hover);
}

.edit-submit-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.edit-loading {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 10px;
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.mini-spinner {
    width: 16px;
    height: 16px;
    border: 2px solid #e5e7eb;
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* ===== Fallback HTML overlay ===== */
.fallback-html-content {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    padding: 24px;
    display: flex;
    flex-direction: column;
    color: white;
    z-index: 5;
}

.fallback-html-content .f-badge {
    color: #fbbf24;
    font-size: 12px;
    font-weight: bold;
    margin-bottom: 8px;
}

.fallback-html-content .f-title {
    font-size: 20px;
    font-weight: 800;
    line-height: 1.3;
    margin-bottom: 12px;
    text-shadow: 0 2px 8px rgba(0, 0, 0, 0.7);
}

.fallback-html-content .f-desc {
    font-size: 13px;
    line-height: 1.5;
    opacity: 0.9;
    text-shadow: 0 1px 5px rgba(0, 0, 0, 0.7);
}

/* ===== Mobile responsiveness ===== */
@media (max-width: 600px) {
    .app-container {
        padding: 32px 16px;
    }

    .glass-panel {
        padding: 20px;
    }

    .config-row {
        flex-direction: column;
    }

    .result-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .result-actions {
        width: 100%;
    }

    .result-actions button {
        flex: 1;
    }

    .compositions-grid {
        grid-template-columns: 1fr;
    }

    .ratio-selector {
        gap: 6px;
    }

    .ratio-btn {
        padding: 8px 10px;
        min-width: 58px;
    }

    .edit-prompt-area {
        flex-direction: column;
    }

    .template-selector {
        gap: 6px;
    }

    .template-btn {
        padding: 8px 6px;
        min-width: 65px;
    }

    .image-upload-grid {
        grid-template-columns: 1fr;
    }
}