/* ==================== CSS Variables ==================== */
:root {
    --primary: #6C5CE7;
    --primary-light: #a29bfe;
    --primary-dark: #5849c7;
    --bg-dark: #0f0f1a;
    --bg-card: rgba(255, 255, 255, 0.05);
    --border-color: rgba(255, 255, 255, 0.1);
    --text-primary: #ffffff;
    --text-secondary: #a0a0b0;
    --text-muted: #6b6b7b;
    --success: #00d26a;
    --error: #ff4757;
}

/* ==================== Reset & Base ==================== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Pretendard', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-dark);
    color: var(--text-primary);
    min-height: 100vh;
    line-height: 1.6;
}

/* ==================== App Container ==================== */
.app-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 1.5rem;
}

/* ==================== Header ==================== */
.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.25rem 0;
    border-bottom: 1px solid var(--border-color);
}

.header-left {
    display: flex;
    flex-direction: column;
}

.logo {
    font-size: 1.5rem;
    font-weight: 800;
    color: var(--text-primary);
}

.logo span {
    color: var(--primary);
}

.logo-sub {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 0.125rem;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.api-status {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--error);
}

.status-dot.active {
    background: var(--success);
}

.status-text {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.icon-btn {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s ease;
}

.icon-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
}

/* ==================== Main Content ==================== */
.main-content {
    padding: 3rem 0;
}

/* ==================== Steps ==================== */
.step {
    display: none;
    animation: fadeIn 0.3s ease;
}

.step.active {
    display: block;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ==================== Step 1: Input ==================== */
.input-card {
    max-width: 600px;
    margin: 0 auto;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    padding: 2.5rem;
    backdrop-filter: blur(10px);
}

.input-header {
    text-align: center;
    margin-bottom: 2rem;
}

.input-header h2 {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
}

.input-header p {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.topic-textarea {
    width: 100%;
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 1.25rem;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 1rem;
    resize: none;
    transition: border-color 0.2s ease;
}

.topic-textarea:focus {
    outline: none;
    border-color: var(--primary);
}

.topic-textarea::placeholder {
    color: var(--text-muted);
}

.primary-btn {
    width: 100%;
    margin-top: 1.5rem;
    padding: 1rem 2rem;
    background: linear-gradient(135deg, var(--primary), var(--primary-light));
    border: none;
    border-radius: 12px;
    color: white;
    font-family: inherit;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.primary-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 30px rgba(108, 92, 231, 0.3);
}

.primary-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

/* ==================== Step 2: Loading ==================== */
.loading-card {
    max-width: 400px;
    margin: 0 auto;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    padding: 3rem;
    text-align: center;
    backdrop-filter: blur(10px);
}

.loading-spinner {
    width: 60px;
    height: 60px;
    border: 4px solid var(--border-color);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 1.5rem;
}

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

.loading-text {
    font-size: 1.125rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
}

.loading-sub {
    color: var(--text-muted);
    font-size: 0.875rem;
}

/* ==================== Step 3: Result ==================== */
.result-layout {
    display: flex;
    gap: 2rem;
    justify-content: center;
}

.viewer-section {
    display: flex;
    flex-direction: column;
    align-items: center;
}

/* Card Viewer */
.card-viewer {
    width: 360px;
    aspect-ratio: 4 / 5;
    position: relative;
    border-radius: 16px;
    overflow: hidden;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
}

.card-bg {
    position: absolute;
    inset: 0;
    z-index: 1;
}

.card-asset {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 2;
    filter: drop-shadow(0 20px 30px rgba(0, 0, 0, 0.15));
}

.card-asset img {
    max-width: 200px;
    max-height: 200px;
    object-fit: contain;
}

.card-content {
    position: absolute;
    top: 2rem;
    left: 0;
    right: 0;
    z-index: 3;
    padding: 0 1.5rem;
    text-align: center;
}

.card-title {
    font-size: 2rem;
    font-weight: 800;
    color: white;
    text-shadow: 2px 2px 8px rgba(0, 0, 0, 0.5);
    word-break: keep-all;
    line-height: 1.3;
}

.card-title:focus {
    outline: 2px dashed var(--primary);
    outline-offset: 4px;
}

.card-body {
    font-size: 1rem;
    color: rgba(255, 255, 255, 0.9);
    text-shadow: 1px 1px 4px rgba(0, 0, 0, 0.5);
    margin-top: 0.75rem;
    word-break: keep-all;
}

.card-body:focus {
    outline: 2px dashed var(--primary);
    outline-offset: 4px;
}

.card-page {
    position: absolute;
    bottom: 1rem;
    right: 1rem;
    z-index: 3;
    background: rgba(0, 0, 0, 0.3);
    padding: 0.25rem 0.75rem;
    border-radius: 20px;
    font-size: 0.75rem;
    color: rgba(255, 255, 255, 0.8);
}

/* Highlight Effect */
.card-title .hl,
.card-body .hl {
    background: linear-gradient(180deg, transparent 60%, rgba(108, 92, 231, 0.5) 60%);
    padding: 0 4px;
}

/* Thumbnails */
.thumbnails {
    display: flex;
    gap: 0.75rem;
    margin-top: 1.5rem;
}

.thumb {
    width: 56px;
    aspect-ratio: 4 / 5;
    border-radius: 8px;
    overflow: hidden;
    cursor: pointer;
    border: 2px solid transparent;
    transition: all 0.2s ease;
    opacity: 0.6;
}

.thumb:hover {
    opacity: 0.8;
}

.thumb.active {
    border-color: var(--primary);
    opacity: 1;
}

.thumb-inner {
    width: 100%;
    height: 100%;
}

/* Control Panel */
.control-panel {
    width: 220px;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.panel-section {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 1rem;
}

.panel-section h4 {
    font-size: 0.875rem;
    font-weight: 600;
    margin-bottom: 0.75rem;
    color: var(--text-secondary);
}

.panel-btn {
    width: 100%;
    padding: 0.75rem;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.875rem;
    cursor: pointer;
    transition: all 0.2s ease;
    margin-bottom: 0.5rem;
}

.panel-btn:last-child {
    margin-bottom: 0;
}

.panel-btn:hover {
    background: rgba(255, 255, 255, 0.1);
}

.panel-btn.primary {
    background: var(--primary);
    border-color: var(--primary);
}

.panel-btn.primary:hover {
    background: var(--primary-dark);
}

.panel-hint {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 0.5rem;
    line-height: 1.4;
}

.back-btn {
    padding: 0.875rem;
    background: transparent;
    border: 1px solid var(--border-color);
    border-radius: 10px;
    color: var(--text-secondary);
    font-family: inherit;
    font-size: 0.875rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.back-btn:hover {
    background: var(--bg-card);
    color: var(--text-primary);
}

/* ==================== Modal ==================== */
.modal {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal.hidden {
    display: none;
}

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

.modal-content {
    position: relative;
    width: 100%;
    max-width: 400px;
    margin: 1rem;
    background: #1a1a2e;
    border: 1px solid var(--border-color);
    border-radius: 16px;
    overflow: hidden;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
}

.modal-header h3 {
    font-size: 1.125rem;
    font-weight: 600;
}

.close-btn {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 1.5rem;
    cursor: pointer;
    transition: color 0.2s ease;
}

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

.modal-body {
    padding: 1.5rem;
}

.form-group {
    margin-bottom: 1rem;
}

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

.form-group label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    margin-bottom: 0.5rem;
    color: var(--text-secondary);
}

.form-group input {
    width: 100%;
    padding: 0.875rem 1rem;
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.9375rem;
    transition: border-color 0.2s ease;
}

.form-group input:focus {
    outline: none;
    border-color: var(--primary);
}

.form-hint {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 0.5rem;
    line-height: 1.5;
}

.form-hint a {
    color: var(--primary-light);
    text-decoration: none;
}

.form-hint a:hover {
    text-decoration: underline;
}

.modal-footer {
    display: flex;
    gap: 0.75rem;
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--border-color);
}

.modal-footer .primary-btn,
.modal-footer .secondary-btn {
    flex: 1;
    margin: 0;
    padding: 0.75rem;
}

.secondary-btn {
    background: transparent;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-secondary);
    font-family: inherit;
    font-size: 0.9375rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.secondary-btn:hover {
    background: var(--bg-card);
    color: var(--text-primary);
}

/* ==================== Toast ==================== */
.toast {
    position: fixed;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: #2d2d44;
    color: var(--text-primary);
    padding: 1rem 1.5rem;
    border-radius: 10px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
    z-index: 200;
    opacity: 0;
    transition: all 0.3s ease;
}

.toast.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

.toast.hidden {
    display: none;
}

/* ==================== Responsive ==================== */
@media (max-width: 900px) {
    .result-layout {
        flex-direction: column;
        align-items: center;
    }

    .control-panel {
        width: 100%;
        max-width: 360px;
        flex-direction: row;
        flex-wrap: wrap;
    }

    .panel-section {
        flex: 1;
        min-width: 150px;
    }

    .back-btn {
        width: 100%;
    }
}

@media (max-width: 480px) {
    .app-container {
        padding: 0 1rem;
    }

    .input-card {
        padding: 1.5rem;
    }

    .card-viewer {
        width: 100%;
        max-width: 320px;
    }

    .card-title {
        font-size: 1.5rem;
    }
}
