/* ===== CSS Variables & Design Tokens ===== */
:root {
    --bg-primary: #0a0a0f;
    --bg-secondary: #12121a;
    --bg-card: rgba(18, 18, 30, 0.7);
    --bg-card-hover: rgba(24, 24, 40, 0.8);
    --bg-input: rgba(255, 255, 255, 0.04);
    --bg-input-focus: rgba(255, 255, 255, 0.07);

    --text-primary: #f0f0f5;
    --text-secondary: #8888a0;
    --text-muted: #55556a;

    --accent-primary: #6c5ce7;
    --accent-secondary: #a29bfe;
    --accent-glow: rgba(108, 92, 231, 0.3);
    --accent-gradient: linear-gradient(135deg, #6c5ce7 0%, #a29bfe 50%, #74b9ff 100%);
    --accent-gradient-hover: linear-gradient(135deg, #7c6cf7 0%, #b2abfe 50%, #84c9ff 100%);

    --success: #00cec9;
    --success-bg: rgba(0, 206, 201, 0.1);
    --error: #ff6b6b;
    --error-bg: rgba(255, 107, 107, 0.1);
    --warning: #fdcb6e;

    --border-color: rgba(255, 255, 255, 0.06);
    --border-active: rgba(108, 92, 231, 0.4);

    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;

    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.2);
    --shadow-md: 0 4px 20px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 8px 40px rgba(0, 0, 0, 0.4);
    --shadow-glow: 0 0 30px var(--accent-glow);

    --font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --transition-fast: 0.15s ease;
    --transition-normal: 0.3s ease;
    --transition-slow: 0.5s ease;
}

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

html {
    font-size: 16px;
    scroll-behavior: smooth;
}

body {
    font-family: var(--font-family);
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

a {
    color: var(--accent-secondary);
    text-decoration: none;
    transition: color var(--transition-fast);
}

a:hover {
    color: #74b9ff;
}

/* ===== Animated Background ===== */
.bg-particles {
    position: fixed;
    inset: 0;
    z-index: 0;
    pointer-events: none;
    overflow: hidden;
}

.bg-particles::before {
    content: '';
    position: absolute;
    width: 600px;
    height: 600px;
    background: radial-gradient(circle, rgba(108, 92, 231, 0.08) 0%, transparent 70%);
    top: -200px;
    right: -200px;
    animation: float-slow 20s ease-in-out infinite;
}

.bg-particles::after {
    content: '';
    position: absolute;
    width: 500px;
    height: 500px;
    background: radial-gradient(circle, rgba(116, 185, 255, 0.06) 0%, transparent 70%);
    bottom: -150px;
    left: -150px;
    animation: float-slow 25s ease-in-out infinite reverse;
}

.particle {
    position: absolute;
    width: 3px;
    height: 3px;
    border-radius: 50%;
    background: var(--accent-secondary);
    opacity: 0;
    animation: particle-float 8s ease-in-out infinite;
}

@keyframes float-slow {
    0%, 100% { transform: translate(0, 0) scale(1); }
    25% { transform: translate(30px, -50px) scale(1.1); }
    50% { transform: translate(-20px, -30px) scale(0.95); }
    75% { transform: translate(40px, 20px) scale(1.05); }
}

@keyframes particle-float {
    0% { opacity: 0; transform: translateY(100vh) scale(0); }
    10% { opacity: 0.6; }
    90% { opacity: 0.6; }
    100% { opacity: 0; transform: translateY(-10vh) scale(1); }
}

/* ===== App Container ===== */
.app-container {
    position: relative;
    z-index: 1;
    max-width: 720px;
    margin: 0 auto;
    padding: 24px 20px 40px;
}

/* ===== Header ===== */
.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 32px;
    padding: 20px 24px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-xl);
    backdrop-filter: blur(20px);
    animation: slideDown 0.6s ease-out;
}

@keyframes slideDown {
    from { opacity: 0; transform: translateY(-20px); }
    to { opacity: 1; transform: translateY(0); }
}

.logo-section {
    display: flex;
    align-items: center;
    gap: 14px;
}

.logo-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 48px;
    height: 48px;
    background: var(--accent-gradient);
    border-radius: var(--radius-md);
    color: white;
    flex-shrink: 0;
    box-shadow: var(--shadow-glow);
}

.logo-text {
    font-size: 1.2rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.logo-subtitle {
    font-size: 0.8rem;
    color: var(--text-secondary);
    font-weight: 400;
    margin-top: 1px;
}

.header-badge {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 14px;
    background: var(--success-bg);
    border: 1px solid rgba(0, 206, 201, 0.2);
    border-radius: 100px;
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--success);
    white-space: nowrap;
}

.badge-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--success);
    animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.5; transform: scale(0.8); }
}

/* ===== Cards ===== */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-xl);
    padding: 28px;
    margin-bottom: 20px;
    backdrop-filter: blur(20px);
    transition: border-color var(--transition-normal), box-shadow var(--transition-normal);
    animation: fadeUp 0.6s ease-out backwards;
}

.card:hover {
    border-color: rgba(255, 255, 255, 0.1);
}

.api-card { animation-delay: 0.1s; }
.config-card { animation-delay: 0.2s; }

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

.card-header {
    display: flex;
    align-items: flex-start;
    gap: 14px;
    margin-bottom: 20px;
}

.card-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: var(--radius-md);
    flex-shrink: 0;
}

.key-icon {
    background: rgba(253, 203, 110, 0.12);
    color: var(--warning);
}

.config-icon {
    background: rgba(108, 92, 231, 0.12);
    color: var(--accent-secondary);
}

.card-title {
    font-size: 1.05rem;
    font-weight: 600;
    letter-spacing: -0.01em;
}

.card-description {
    font-size: 0.82rem;
    color: var(--text-secondary);
    margin-top: 2px;
}

/* ===== Input Fields ===== */
.input-field {
    width: 100%;
    padding: 12px 16px;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-family: var(--font-family);
    font-size: 0.9rem;
    transition: all var(--transition-fast);
    outline: none;
}

.input-field:focus {
    background: var(--bg-input-focus);
    border-color: var(--border-active);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.input-field::placeholder {
    color: var(--text-muted);
}

/* API Key Input */
.api-input-wrapper {
    position: relative;
    margin-bottom: 12px;
}

.api-input {
    padding-right: 48px;
    font-family: 'Courier New', monospace;
    letter-spacing: 0.5px;
}

.toggle-visibility {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 4px;
    transition: color var(--transition-fast);
}

.toggle-visibility:hover {
    color: var(--text-primary);
}

/* Save Key Checkbox */
.save-key-label {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.82rem;
    color: var(--text-secondary);
    cursor: pointer;
    user-select: none;
}

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

.checkmark {
    width: 18px;
    height: 18px;
    border: 1.5px solid var(--border-color);
    border-radius: 5px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-fast);
    flex-shrink: 0;
}

.save-key-label input:checked + .checkmark {
    background: var(--accent-primary);
    border-color: var(--accent-primary);
}

.save-key-label input:checked + .checkmark::after {
    content: '✓';
    color: white;
    font-size: 11px;
    font-weight: 700;
}

/* ===== Select Fields ===== */
.select-wrapper {
    position: relative;
}

.select-field {
    appearance: none;
    -webkit-appearance: none;
    padding-right: 40px;
    cursor: pointer;
}

.select-field option {
    background: var(--bg-secondary);
    color: var(--text-primary);
    padding: 8px 12px;
}

.select-field option:hover {
    background: var(--accent-primary);
    color: white;
}

.select-field option:checked {
    background: var(--accent-primary);
    color: white;
}

.select-arrow {
    position: absolute;
    right: 14px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-secondary);
    pointer-events: none;
}

/* ===== Form Elements ===== */
.config-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-bottom: 20px;
}

.form-group {
    margin-bottom: 18px;
}

.form-label {
    display: block;
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 8px;
    letter-spacing: 0.02em;
}

.textarea-field {
    resize: vertical;
    min-height: 120px;
    line-height: 1.7;
}

.char-counter {
    text-align: right;
    font-size: 0.72rem;
    color: var(--text-muted);
    margin-top: 6px;
}

/* ===== Version Selector ===== */
.version-selector {
    display: flex;
    gap: 10px;
}

.version-btn {
    flex: 1;
    padding: 10px 20px;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    font-family: var(--font-family);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.version-btn:hover {
    background: var(--bg-input-focus);
    border-color: rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
}

.version-btn.active {
    background: rgba(108, 92, 231, 0.15);
    border-color: var(--border-active);
    color: var(--accent-secondary);
    box-shadow: 0 0 0 2px var(--accent-glow);
}

/* ===== Generate Button ===== */
.generate-btn {
    width: 100%;
    padding: 16px 24px;
    background: var(--accent-gradient);
    border: none;
    border-radius: var(--radius-md);
    color: white;
    font-family: var(--font-family);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-normal);
    position: relative;
    overflow: hidden;
    margin-top: 8px;
}

.generate-btn::before {
    content: '';
    position: absolute;
    inset: 0;
    background: var(--accent-gradient-hover);
    opacity: 0;
    transition: opacity var(--transition-normal);
}

.generate-btn:hover::before {
    opacity: 1;
}

.generate-btn:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-glow), var(--shadow-md);
}

.generate-btn:active {
    transform: translateY(0);
}

.generate-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.generate-btn:disabled:hover::before {
    opacity: 0;
}

.btn-content,
.btn-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    position: relative;
    z-index: 1;
}

.spinner {
    width: 20px;
    height: 20px;
    border: 2.5px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

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

/* ===== Results Section ===== */
.results-section {
    animation: fadeUp 0.5s ease-out;
}

.result-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-xl);
    padding: 28px;
    margin-bottom: 20px;
    backdrop-filter: blur(20px);
    animation: fadeUp 0.5s ease-out backwards;
    transition: border-color var(--transition-normal);
}

.result-card:hover {
    border-color: rgba(108, 92, 231, 0.2);
}

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

.result-title {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 1rem;
    font-weight: 600;
}

.result-badge {
    display: inline-flex;
    align-items: center;
    padding: 4px 10px;
    background: rgba(108, 92, 231, 0.12);
    border-radius: 100px;
    font-size: 0.72rem;
    font-weight: 500;
    color: var(--accent-secondary);
}

.result-content {
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 20px;
    white-space: pre-wrap;
    font-size: 0.88rem;
    line-height: 1.8;
    color: var(--text-primary);
    margin-bottom: 16px;
    max-height: 400px;
    overflow-y: auto;
}

.result-content::-webkit-scrollbar {
    width: 6px;
}

.result-content::-webkit-scrollbar-track {
    background: transparent;
}

.result-content::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}

.result-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.action-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 18px;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    font-family: var(--font-family);
    font-size: 0.82rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.action-btn:hover {
    background: var(--bg-input-focus);
    border-color: rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
}

.action-btn.copy-btn:hover {
    border-color: rgba(0, 206, 201, 0.3);
    color: var(--success);
}

.action-btn.download-btn:hover {
    border-color: var(--border-active);
    color: var(--accent-secondary);
}

.stats-badge {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-left: auto;
    padding: 8px 14px;
    background: rgba(108, 92, 231, 0.08);
    border-radius: var(--radius-sm);
    font-size: 0.78rem;
    color: var(--text-secondary);
}

.stats-badge span {
    color: var(--accent-secondary);
    font-weight: 600;
}

/* ===== Toast ===== */
.toast {
    position: fixed;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    padding: 12px 24px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: 0.85rem;
    font-weight: 500;
    backdrop-filter: blur(20px);
    box-shadow: var(--shadow-lg);
    z-index: 1000;
    opacity: 0;
    transition: all 0.4s cubic-bezier(0.16, 1, 0.3, 1);
    pointer-events: none;
}

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

.toast.toast-success {
    border-color: rgba(0, 206, 201, 0.3);
}

.toast.toast-error {
    border-color: rgba(255, 107, 107, 0.3);
}

/* ===== Footer ===== */
.app-footer {
    text-align: center;
    padding: 24px 0;
    font-size: 0.8rem;
    color: var(--text-muted);
    animation: fadeUp 0.6s ease-out 0.3s backwards;
}

.app-footer a {
    color: var(--text-secondary);
    font-weight: 500;
}

.app-footer a:hover {
    color: var(--accent-secondary);
}

/* ===== Responsive ===== */
@media (max-width: 640px) {
    .app-container {
        padding: 16px 14px 32px;
    }

    .app-header {
        flex-direction: column;
        gap: 14px;
        padding: 18px 20px;
        text-align: center;
    }

    .logo-section {
        flex-direction: column;
        text-align: center;
    }

    .header-badge {
        align-self: center;
    }

    .config-grid {
        grid-template-columns: 1fr;
        gap: 0;
    }

    .card {
        padding: 22px 18px;
    }

    .result-actions {
        flex-direction: column;
    }

    .stats-badge {
        margin-left: 0;
        justify-content: center;
    }
}

/* ===== Shimmer Loading Effect ===== */
.shimmer {
    background: linear-gradient(
        90deg,
        var(--bg-input) 0%,
        rgba(255, 255, 255, 0.06) 50%,
        var(--bg-input) 100%
    );
    background-size: 200% 100%;
    animation: shimmer 1.5s ease-in-out infinite;
    border-radius: var(--radius-md);
}

@keyframes shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

.loading-skeleton {
    padding: 28px;
}

.skeleton-line {
    height: 14px;
    margin-bottom: 12px;
    border-radius: 6px;
}

.skeleton-line:nth-child(1) { width: 90%; }
.skeleton-line:nth-child(2) { width: 75%; }
.skeleton-line:nth-child(3) { width: 85%; }
.skeleton-line:nth-child(4) { width: 60%; }
.skeleton-line:nth-child(5) { width: 70%; }

/* ===== Error State ===== */
.error-card {
    background: var(--error-bg);
    border-color: rgba(255, 107, 107, 0.2);
}

.error-card .result-header {
    color: var(--error);
}
