/**
 * ==============================================
 * THƯ PHÁP AI - MODERN PREMIUM STYLESHEET
 * ==============================================
 * Vietnamese Calligraphy Application
 * Modern glassmorphism design with warm tones
 */

/* ===== Google Fonts Import ===== */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=Playfair+Display:wght@400;500;600;700&display=swap');

/* ===== CSS Variables (Design Tokens) ===== */
:root {
    /* Modern Color Palette - Light on Dark (Screenshot Match) */
    --color-primary: #ffffff;
    /* White container bg */
    --color-primary-light: #f8fafc;
    /* Slightly darker white for inputs */
    --color-accent: #fbbf24;
    /* Gold/Yellow borders */
    --color-accent-glow: rgba(251, 191, 36, 0.4);
    --color-accent-dark: #d97706;
    /* Darker gold for active states */
    --color-red-active: #b91c1c;
    /* Deep Red for active buttons */

    /* Background Colors */
    --bg-gradient-start: #000000;
    --bg-gradient-mid: #0a0a0a;
    --bg-gradient-end: #000000;

    /* Surface Colors */
    --surface-glass: rgba(255, 255, 255, 0.95);
    /* Opaque white container */
    --surface-glass-hover: rgba(255, 255, 255, 1);
    --surface-card: #ffffff;
    --surface-input: #ffffff;

    /* Text Colors */
    --text-primary: #1a1a1a;
    /* Dark text */
    --text-secondary: #4b5563;
    /* Grey text */
    --text-muted: #6b7280;

    /* Border Colors */
    --border-subtle: #fbbf24;
    /* Gold borders everywhere */
    --border-accent: #f59e0b;

    /* Typography */
    --font-primary: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    --font-display: 'Playfair Display', Georgia, serif;

    /* Spacing */
    --space-xs: 0.25rem;
    --space-sm: 0.5rem;
    --space-md: 1rem;
    --space-lg: 1.5rem;
    --space-xl: 2rem;
    --space-2xl: 3rem;
    --space-3xl: 4rem;

    /* Border Radius */
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 24px;
    --radius-2xl: 32px;

    /* Shadows */
    --shadow-glow: 0 0 40px rgba(245, 158, 11, 0.15);
    --shadow-card: 0 8px 32px rgba(0, 0, 0, 0.3);
    --shadow-elevated: 0 20px 40px rgba(0, 0, 0, 0.4);

    /* Transitions */
    --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-base: 300ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-slow: 500ms cubic-bezier(0.4, 0, 0.2, 1);
}

/* ===== Reset & Base ===== */
*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* ===== Local Fonts ===== */
@font-face {
    font-family: 'Thư Pháp Thành Công';
    src: url('Fonts/Thu_Phap_Thanh_Cong_Unicode.otf') format('opentype');
    font-display: swap;
}

@font-face {
    font-family: 'SVN Hottroof';
    src: url('Fonts/SVN-Hottroof-Semhesta.otf') format('opentype');
    font-display: swap;
}

@font-face {
    font-family: 'FC Opulent';
    src: url('Fonts/FC-Opulent-Brush.otf') format('opentype');
    font-display: swap;
}

@font-face {
    font-family: 'VN Lovelista';
    src: url('Fonts/VN-Lovelista-Regular.ttf') format('truetype');
    font-display: swap;
}

@font-face {
    font-family: 'Thuphap Congthuy';
    src: url('Fonts/ThuphapCongthuy.ttf') format('truetype');
    font-display: swap;
}

@font-face {
    font-family: 'Fz DucThuy';
    src: url('Fonts/Fz DucThuyThuPhap.ttf') format('truetype');
    font-display: swap;
}

@font-face {
    font-family: 'Fz Đại Tự';
    src: url('Fonts/Fz Thư pháp Đại tự Fontzin.ttf') format('truetype');
    font-display: swap;
}

@font-face {
    font-family: 'Fz Fashion Signature';
    src: url('Fonts/FzFashionSignature.ttf') format('truetype');
    font-display: swap;
}

@font-face {
    font-family: 'Fz Tiểu Tự';
    src: url('Fonts/fzthuphaptieutu-full.ttf') format('truetype');
    font-display: swap;
}


/* ===== Body ===== */
body {
    font-family: var(--font-primary);
    background: linear-gradient(135deg, var(--bg-gradient-start) 0%, var(--bg-gradient-mid) 50%, var(--bg-gradient-end) 100%);
    background-attachment: fixed;
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    padding: var(--space-xl);
    overflow-x: hidden;
}

/* Animated background pattern */
body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-image:
        radial-gradient(circle at 20% 80%, rgba(245, 158, 11, 0.08) 0%, transparent 50%),
        radial-gradient(circle at 80% 20%, rgba(245, 158, 11, 0.05) 0%, transparent 50%),
        radial-gradient(circle at 40% 40%, rgba(255, 255, 255, 0.02) 0%, transparent 30%);
    pointer-events: none;
    z-index: 0;
}

/* ===== Container ===== */
.container {
    position: relative;
    z-index: 1;
    max-width: 1100px;
    margin: 0 auto;
    background: var(--surface-card);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-2xl);
    box-shadow: var(--shadow-card);
    padding: var(--space-2xl);
    animation: fadeSlideUp 0.6s ease-out;
}

@keyframes fadeSlideUp {
    from {
        opacity: 0;
        transform: translateY(30px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ===== Header ===== */
.header {
    text-align: center;
    margin-bottom: var(--space-2xl);
    padding-bottom: var(--space-xl);
    border-bottom: 1px solid var(--border-subtle);
    position: relative;
}

.header::after {
    content: '';
    position: absolute;
    bottom: -1px;
    left: 50%;
    transform: translateX(-50%);
    width: 100px;
    height: 3px;
    background: linear-gradient(90deg, transparent, var(--color-accent), transparent);
    border-radius: 2px;
}

.logo {
    font-family: var(--font-display);
    font-size: 2.75rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: var(--space-sm);
    letter-spacing: -0.02em;
    text-shadow: 0 2px 20px rgba(0, 0, 0, 0.3);
}

.logo-image {
    height: 100px;
    width: auto;
    display: block;
    margin: 0 auto;
    /* Layered shadow for 3D effect: Crisp offset + Soft blurry shadow */
    filter: drop-shadow(1px 4px 6px rgba(0, 0, 0, 0.2)) drop-shadow(0 8px 15px rgba(0, 0, 0, 0.1));
    transition: filter 0.3s ease;
}

.logo-image:hover {
    filter: drop-shadow(1px 4px 8px rgba(0, 0, 0, 0.25)) drop-shadow(0 12px 20px rgba(0, 0, 0, 0.15));
    transform: translateY(-2px);
}

.logo-accent {
    color: var(--color-accent);
    position: relative;
}

.logo-accent::after {
    content: '';
    position: absolute;
    bottom: 2px;
    left: 0;
    right: 0;
    height: 3px;
    background: var(--color-accent);
    border-radius: 2px;
    box-shadow: 0 0 15px var(--color-accent-glow);
}

.tagline {
    font-size: 1rem;
    color: var(--text-secondary);
    font-weight: 400;
    letter-spacing: 0.02em;
}

/* ===== Main Layout ===== */
.main-content {
    display: block;
}

.generator-section {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-2xl);
    align-items: stretch;
    /* Stretch columns to equal height */
}

/* Left Column - Controls */
.controls-column {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
}

/* Right Column - Preview (Sticky) */
.preview-column {
    position: sticky;
    top: var(--space-xl);
    /* Don't force 100vh, instead match parent grid height but cap at viewport for sticky */
    height: auto;
    max-height: calc(100vh - var(--space-xl) * 2);
    display: flex;
    flex-direction: column;
}

.preview-wrapper {
    background: var(--surface-glass);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    padding: var(--space-lg);
    display: flex;
    flex-direction: column;
    height: 100%;
    /* Fill the column */
}

.preview-title {
    position: absolute;
    top: var(--space-sm);
    left: 50%;
    transform: translateX(-50%);
    font-size: 0.85rem;
    font-weight: 500;
    color: rgba(255, 255, 255, 0.9);
    background: rgba(0, 0, 0, 0.5);
    padding: 6px 16px;
    border-radius: 20px;
    z-index: 10;
    pointer-events: none;
    white-space: nowrap;
    backdrop-filter: blur(4px);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.preview-description {
    font-size: 0.9rem;
    color: var(--text-muted);
    text-align: center;
    margin-bottom: var(--space-md);
    font-style: italic;
    line-height: 1.5;
    max-width: 90%;
    margin-left: auto;
    margin-right: auto;
}

.preview-box {
    flex: 1;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--surface-2);
    border-radius: var(--radius-md);
    /* overflow: hidden;  <-- Removed to allow share menu to popup */
    min-height: 500px;
    /* Ensure enough height for vertical couplets */
}

#calligraphyCanvas,
#resultImage {
    /* Critical for aspect ratio: allow scaling down but NEVER stretch */
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
    object-fit: contain;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
}

.result-controls {
    position: absolute;
    bottom: var(--space-lg);
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: var(--space-md);
    z-index: 20;
    width: 90%;
    justify-content: center;
}

.result-controls .btn {
    backdrop-filter: blur(8px);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
}

.preview-overlay {
    position: absolute;
    top: var(--space-md);
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.6);
    color: white;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 0.8rem;
    pointer-events: none;
    opacity: 0.8;
}

/* Sliders Grid */
.sliders-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-md);
}

.sliders-grid .form-section {
    margin-bottom: 0;
}

/* ===== Form Elements ===== */
.form-section {
    margin-bottom: var(--space-lg);
}

.form-label {
    display: block;
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: var(--space-sm);
    font-size: 0.9rem;
    letter-spacing: 0.01em;
}

.form-label span {
    color: var(--color-accent);
    font-weight: 600;
}

.form-hint {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: var(--space-md);
}

/* Select Inputs */
.form-select {
    width: 100%;
    padding: var(--space-md) var(--space-lg);
    background: var(--surface-input);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    font-family: var(--font-primary);
    font-size: 0.95rem;
    color: var(--text-primary);
    cursor: pointer;
    transition: all var(--transition-base);
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='%2394A3B8' viewBox='0 0 16 16'%3E%3Cpath d='M8 11L3 6h10l-5 5z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 16px center;
}

.form-select:hover {
    border-color: var(--color-accent);
    background-color: var(--surface-glass-hover);
}

.form-select:focus {
    outline: none;
    border-color: var(--color-accent);
    box-shadow: 0 0 0 3px var(--color-accent-glow);
}

.form-select option {
    background: #ffffff;
    /* Force white background for options */
    color: #1a1a1a;
    /* Force dark text */
    padding: var(--space-md);
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-md);
}

/* ===== Range Slider ===== */
.range-wrapper {
    width: 100%;
    padding: var(--space-xs) 0;
}

.form-range {
    width: 100%;
    height: 6px;
    background: #e5e7eb;
    /* Light grey track */
    border-radius: 3px;
    outline: none;
    appearance: none;
    -webkit-appearance: none;
    cursor: pointer;
}

.form-range::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--color-accent) 0%, var(--color-accent-dark) 100%);
    cursor: pointer;
    border: 3px solid #ffffff;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
    transition: transform var(--transition-fast), box-shadow var(--transition-fast);
}

.form-range::-webkit-slider-thumb:hover {
    transform: scale(1.1);
    box-shadow: 0 0 0 4px var(--color-accent-glow);
}

.form-range::-moz-range-thumb {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--color-accent) 0%, var(--color-accent-dark) 100%);
    cursor: pointer;
    border: 3px solid #ffffff;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
}

/* ===== Checkbox ===== */
.checkbox-section {
    margin-bottom: var(--space-lg);
    background: #fffbeb;
    /* Very light cream/yellow tint */
    padding: var(--space-lg);
    border-radius: var(--radius-md);
    border: 2px solid var(--color-accent);
    transition: all var(--transition-base);
}

.checkbox-section:hover {
    border-color: var(--color-accent-dark);
    background: #fff;
}

.checkbox-label {
    display: flex;
    align-items: flex-start;
    gap: var(--space-md);
    cursor: pointer;
}

.checkbox-label input[type="checkbox"] {
    margin-top: 3px;
    width: 20px;
    height: 20px;
    cursor: pointer;
    accent-color: var(--color-red-active);
    border-radius: 4px;
}

/* ===== Segmented Control (Size Options) ===== */
.size-options {
    display: flex;
    background: transparent;
    border: none;
    padding: 0;
    gap: var(--space-sm);
}

.size-option {
    flex: 1;
    position: relative;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-primary);
    text-align: center;
    border-radius: var(--radius-sm);
    transition: all var(--transition-base);
}

.size-option input {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

.size-label {
    display: block;
    padding: var(--space-sm) var(--space-md);
    border-radius: var(--radius-md);
    border: 1px solid var(--border-subtle);
    background: #ffffff;
}

.size-option input:checked+.size-label {
    background: var(--color-red-active);
    color: #ffffff;
    border-color: var(--color-red-active);
    box-shadow: 0 4px 10px rgba(185, 28, 28, 0.3);
    font-weight: 600;
}

.size-option:hover .size-label {
    background: #fffbeb;
    border-color: var(--color-accent-dark);
}

.size-option input:checked:hover+.size-label {
    background: var(--color-red-active);
    color: #ffffff;
}

.checkbox-text {
    display: flex;
    flex-direction: column;
    gap: var(--space-xs);
}

.checkbox-text strong {
    color: var(--text-primary);
    font-size: 0.95rem;
    font-weight: 500;
}

.checkbox-hint {
    font-size: 0.85rem;
    color: var(--text-muted);
    line-height: 1.5;
}

/* ===== Advanced Controls Panel ===== */
.advanced-controls {
    background: var(--surface-glass);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    padding: var(--space-xl);
    margin-bottom: var(--space-lg);
}

.controls-title {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: var(--space-lg);
    padding-bottom: var(--space-sm);
    border-bottom: 2px solid var(--color-accent);
    display: inline-block;
}

/* ===== Background Carousel ===== */
.background-carousel {
    display: flex;
    align-items: center;
    gap: var(--space-xs);
    position: relative;
}

.background-grid-wrapper {
    flex: 1;
    overflow: hidden;
    margin: 0 var(--space-xs);
}

.background-grid {
    display: flex;
    gap: var(--space-sm);
    transition: transform 0.3s ease;
    scroll-behavior: smooth;
    /* Determine visible items: 4 items */
    width: 100%;
}

.bg-option {
    flex: 0 0 calc(25% - var(--space-sm) * 3 / 4);
    /* Show 4 items per row */
    min-width: 0;
}

.nav-arrow {
    background: var(--surface-card);
    border: 1px solid var(--border-subtle);
    color: var(--text-primary);
    width: 28px;
    height: 28px;
    border-radius: 50%;
    /* Circle */
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 0.8rem;
    transition: all var(--transition-base);
    z-index: 2;
    flex-shrink: 0;
}

.nav-arrow:hover {
    background: var(--color-accent);
    color: var(--color-primary);
    border-color: var(--color-accent);
    box-shadow: 0 0 8px var(--color-accent-glow);
}

.bg-option {
    aspect-ratio: 1;
    border: 2px solid var(--border-subtle);
    border-radius: var(--radius-md);
    cursor: pointer;
    overflow: hidden;
    transition: all var(--transition-base);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: var(--surface-input);
    position: relative;
}

.bg-option img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform var(--transition-base);
}

.bg-option:hover {
    border-color: var(--color-accent);
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.3);
}

.bg-option:hover img {
    transform: scale(1.05);
}

.bg-option.selected {
    border-color: var(--color-accent);
    box-shadow: 0 0 0 3px var(--color-accent-glow), 0 8px 20px rgba(0, 0, 0, 0.3);
}

.bg-option.selected::after {
    content: '✓';
    position: absolute;
    top: 4px;
    right: 4px;
    width: 20px;
    height: 20px;
    background: var(--color-accent);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    color: white;
    font-weight: bold;
}

/* ===== Preview Container ===== */
.preview-container {
    position: relative;
    width: 100%;
    background: var(--surface-input);
    border: 2px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 400px;
    transition: all var(--transition-base);
}

.preview-container:hover {
    border-color: var(--border-accent);
}

#livePreviewCanvas {
    max-width: 100%;
    max-height: 400px;
    width: auto;
    cursor: move;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-elevated);
    object-fit: contain;
}

.preview-overlay {
    position: absolute;
    bottom: var(--space-md);
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.7);
    color: var(--text-primary);
    padding: var(--space-xs) var(--space-md);
    border-radius: var(--radius-full);
    font-size: 0.85rem;
    pointer-events: none;
    opacity: 0;
    transition: opacity var(--transition-base);
}




/* ===== Primary Button ===== */
.btn-primary {
    width: 100%;
    padding: var(--space-lg) var(--space-xl);
    border: none;
    background: linear-gradient(135deg, var(--color-accent) 0%, var(--color-accent-dark) 100%);
    color: var(--color-primary);
    font-family: var(--font-primary);
    font-size: 1.05rem;
    font-weight: 600;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-base);
    box-shadow: 0 4px 20px var(--color-accent-glow);
    position: relative;
    overflow: hidden;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.btn-primary::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.3), transparent);
    transition: left 0.5s ease;
}

.btn-primary:hover::before {
    left: 100%;
}

.btn-primary:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 30px var(--color-accent-glow);
}

.btn-primary:active {
    transform: translateY(-1px);
}

.btn-primary:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

/* ===== Stamp Section ===== */
.stamp-section {
    background: var(--surface-glass);
    padding: var(--space-lg);
    border-radius: var(--radius-md);
    border: 1px solid var(--border-subtle);
}

.stamp-controls {
    margin-top: var(--space-md);
    padding-top: var(--space-md);
    border-top: 1px solid var(--border-subtle);
}

.stamp-section small {
    display: block;
    margin-top: var(--space-sm);
    color: var(--text-muted);
    font-size: 0.8rem;
}

/* ===== Results Section (in preview column) ===== */
.results-section {
    margin-top: var(--space-xl);
    padding-top: var(--space-lg);
    border-top: 1px solid var(--border-subtle);
    animation: fadeSlideUp 0.5s ease;
}

.results-title {
    font-family: var(--font-display);
    font-size: 1.75rem;
    color: var(--text-primary);
    margin-bottom: var(--space-xl);
    text-align: center;
    position: relative;
}

.results-title::after {
    content: '';
    position: absolute;
    bottom: -8px;
    left: 50%;
    transform: translateX(-50%);
    width: 60px;
    height: 3px;
    background: var(--color-accent);
    border-radius: 2px;
}

.results-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: var(--space-lg);
}

.result-card {
    background: var(--surface-glass);
    border-radius: var(--radius-lg);
    padding: var(--space-lg);
    box-shadow: var(--shadow-card);
    transition: all var(--transition-base);
    border: 1px solid var(--border-subtle);
}

.result-card:hover {
    transform: translateY(-8px);
    box-shadow: var(--shadow-elevated);
    border-color: var(--border-accent);
}

.result-card img {
    width: 100%;
    height: auto;
    border-radius: var(--radius-md);
    margin-bottom: var(--space-md);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
}

.result-text {
    font-size: 0.9rem;
    color: var(--text-secondary);
    line-height: 1.6;
    font-style: italic;
    margin-bottom: var(--space-sm);
}

.result-meta {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: var(--space-md);
}

.btn-download {
    width: 100%;
    padding: var(--space-md) var(--space-lg);
    border: 2px solid var(--color-accent);
    background: transparent;
    color: var(--color-accent);
    font-family: var(--font-primary);
    font-size: 0.9rem;
    font-weight: 600;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition-base);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-sm);
}

.btn-download:hover {
    background: var(--color-accent);
    color: var(--color-primary);
    transform: translateY(-2px);
    box-shadow: 0 4px 20px var(--color-accent-glow);
}

.btn-download svg {
    flex-shrink: 0;
}

/* ===== Glass Action Buttons (Edit/Share) ===== */
.btn-glass-action {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-xs);
    padding: var(--space-md) var(--space-lg);
    border-radius: 50px;
    /* Fully rounded */
    border: 1px solid rgba(255, 255, 255, 0.3);
    background: rgba(0, 128, 128, 0.4);
    /* Teal/Greenish glass */
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    color: white;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

.btn-glass-action:hover {
    background: rgba(0, 128, 128, 0.6);
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2);
}

.btn-glass-action.secondary {
    background: rgba(70, 130, 180, 0.4);
    /* Steel Blue for Edit */
}

.btn-glass-action.secondary:hover {
    background: rgba(70, 130, 180, 0.6);
}



/* ===== Footer ===== */
.footer {
    margin-top: var(--space-3xl);
    padding-top: var(--space-xl);
    border-top: 1px solid var(--border-subtle);
    text-align: center;
    color: var(--text-muted);
    font-size: 0.85rem;
}

/* ===== Responsive Design ===== */
@media (max-width: 1024px) {
    .generator-section {
        grid-template-columns: 1fr;
    }

    .preview-column {
        position: static;
        order: -1;
        margin-bottom: var(--space-xl);
    }

    .container {
        padding: var(--space-xl);
    }
}

/* ===== Mobile Tab Navigation System ===== */
/* Hide mobile elements on desktop */
.mobile-tabs,
.mobile-tab-content {
    display: none;
}

@media (max-width: 768px) {

    /* Reset body for mobile app layout */
    body {
        padding: 0;
        margin: 0;
        overflow-x: hidden;
        height: 100vh;
        height: 100dvh;
        /* Dynamic viewport height */
    }

    .container {
        padding: 0;
        border-radius: 0;
        min-height: 100vh;
        min-height: 100dvh;
        display: flex;
        flex-direction: column;
        background: var(--bg-gradient-mid);
    }

    /* Compact Header */
    .header {
        padding: var(--space-sm) var(--space-md);
        margin-bottom: 0;
        background: rgba(15, 23, 42, 0.98);
        border-bottom: 1px solid var(--border-subtle);
        position: sticky;
        top: 0;
        z-index: 100;
    }

    .header::after {
        display: none;
    }

    .logo {
        font-size: 1.4rem;
        margin-bottom: 0;
    }

    .tagline {
        display: none;
    }

    /* Hide desktop controls on mobile */
    .controls-column {
        display: none !important;
    }

    /* Main content fills remaining space */
    .main-content {
        flex: 1;
        display: flex;
        flex-direction: column;
        padding-bottom: 60px;
        /* Space for bottom tabs */
    }

    .generator-section {
        flex: 1;
        display: flex;
        flex-direction: column;
        gap: 0;
    }

    /* Preview takes full available space */
    .preview-column {
        flex: 1;
        order: 0;
        margin: 0;
        padding: var(--space-sm);
        max-height: none;
        position: relative;
        height: auto;
    }

    .preview-wrapper {
        height: 100%;
        padding: var(--space-sm);
        background: transparent;
        border: none;
    }

    .preview-description {
        display: none;
    }

    .preview-box {
        min-height: 0;
        height: 100%;
        flex: 1;
        border-radius: var(--radius-lg);
        overflow: hidden;
    }

    #calligraphyCanvas,
    #resultImage {
        max-height: calc(100vh - 220px);
        max-height: calc(100dvh - 220px);
        border-radius: var(--radius-md);
    }

    .preview-title {
        font-size: 0.75rem;
        padding: 4px 12px;
        top: auto;
        bottom: var(--space-sm);
    }

    /* Result controls */
    .result-controls {
        bottom: var(--space-md);
        gap: var(--space-sm);
    }

    .btn-glass-action {
        padding: var(--space-sm) var(--space-md);
        font-size: 0.85rem;
    }

    /* Hide footer on mobile */
    .footer {
        display: none;
    }

    /* ===== Mobile Tab Bar ===== */
    .mobile-tabs {
        display: flex;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        height: 60px;
        background: rgba(15, 23, 42, 0.98);
        backdrop-filter: blur(20px);
        -webkit-backdrop-filter: blur(20px);
        border-top: 1px solid var(--border-subtle);
        z-index: 1000;
        padding: var(--space-xs) 0;
        padding-bottom: env(safe-area-inset-bottom, var(--space-xs));
    }

    .tab-btn {
        flex: 1;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 2px;
        background: transparent;
        border: none;
        color: var(--text-muted);
        cursor: pointer;
        transition: all 0.2s ease;
        position: relative;
        padding: var(--space-xs);
    }

    .tab-btn::before {
        content: '';
        position: absolute;
        top: -1px;
        left: 50%;
        transform: translateX(-50%) scaleX(0);
        width: 30px;
        height: 3px;
        background: var(--color-accent);
        border-radius: 0 0 4px 4px;
        transition: transform 0.2s ease;
    }

    .tab-btn.active {
        color: var(--color-accent);
    }

    .tab-btn.active::before {
        transform: translateX(-50%) scaleX(1);
    }

    .tab-icon {
        font-size: 1.3rem;
        line-height: 1;
    }

    .tab-label {
        font-size: 0.65rem;
        font-weight: 500;
        letter-spacing: 0.02em;
    }

    /* Generate button special styling */
    .tab-btn.generate-tab {
        background: linear-gradient(135deg, var(--color-accent) 0%, var(--color-accent-dark) 100%);
        color: var(--color-primary);
        border-radius: var(--radius-md);
        margin: var(--space-xs);
        flex: 0.9;
    }

    .tab-btn.generate-tab::before {
        display: none;
    }

    .tab-btn.generate-tab .tab-icon {
        font-size: 1.4rem;
    }

    .tab-btn.generate-tab .tab-label {
        font-weight: 700;
    }

    /* ===== Mobile Tab Content Panels ===== */
    .mobile-tab-content {
        display: block;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 60px;
        bottom: calc(60px + env(safe-area-inset-bottom, 0px));
        background: transparent;
        pointer-events: none;
        /* Always allow pass-through on container */
        opacity: 0;
        visibility: hidden;
        /* Ensure it's truly gone when inactive */
        transition: opacity 0.3s ease, visibility 0.3s ease;
        z-index: 998;
    }

    .mobile-tab-content.active {
        opacity: 1;
        visibility: visible;
        /* pointer-events remains none on container to let clicks pass to canvas */
    }

    /* Tab Panels - Floating overlay controls */
    .tab-panel {
        display: none;
        position: absolute;
        bottom: 10px;
        left: 10px;
        right: 10px;
        background: rgba(15, 23, 42, 0.95);
        /* Darker opacity for better contrast */
        border-radius: var(--radius-lg);
        border: 1px solid var(--border-accent);
        box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
        max-height: 50vh;
        overflow-y: auto;
        pointer-events: auto;
        /* Re-enable clicks on the panel itself */
        color: #ffffff;
        /* Force White Text in Mobile Panels */
    }

    .tab-panel .form-label {
        color: #e2e8f0;
        /* Light grey for labels */
    }

    .tab-panel .checkbox-text strong {
        color: #ffffff;
    }

    .tab-panel .checkbox-section {
        background: rgba(255, 255, 255, 0.1);
        /* Light glass for checkbox on mobile */
        border-color: rgba(255, 255, 255, 0.2);
    }

    /* Ensure inputs in mobile panel clearly visible */
    .tab-panel .form-select,
    .tab-panel .size-label {
        background: rgba(255, 255, 255, 0.9);
        color: #0f172a;
        /* Dark text inside white inputs */
    }

    .tab-panel.active {
        display: flex;
        flex-direction: column;
    }

    .panel-header {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: var(--space-md);
        border-bottom: 1px solid rgba(255, 255, 255, 0.1);
        background: rgba(15, 23, 42, 0.5);
        position: sticky;
        top: 0;
        z-index: 10;
        border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    }

    .panel-title {
        font-weight: 600;
        font-size: 1rem;
        color: var(--text-primary);
    }

    .panel-close {
        width: 32px;
        height: 32px;
        border-radius: 50%;
        background: var(--surface-glass);
        border: 1px solid var(--border-subtle);
        color: var(--text-secondary);
        font-size: 1rem;
        cursor: pointer;
        display: flex;
        align-items: center;
        justify-content: center;
        transition: all 0.2s ease;
    }

    .panel-close:hover {
        background: var(--color-accent);
        color: var(--color-primary);
        border-color: var(--color-accent);
    }

    .panel-body {
        flex: 1;
        padding: var(--space-sm) 0;
        overflow-y: auto;
        overflow-x: hidden;
    }

    /* Panel form elements spacing */
    .panel-body .form-section {
        margin-bottom: var(--space-sm);
        padding: 0 var(--space-md);
    }

    .panel-body .form-label {
        font-size: 0.8rem;
        margin-bottom: 2px;
    }

    .panel-body .form-select {
        padding: var(--space-xs) var(--space-sm);
        font-size: 0.85rem;
    }

    .panel-body .sliders-grid {
        grid-template-columns: 1fr 1fr;
        gap: var(--space-xs) var(--space-sm);
    }

    /* Mobile Background Carousel with Arrows */
    .mobile-bg-carousel {
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 8px;
        padding: 8px 12px;
    }

    .mobile-nav-arrow {
        background: var(--surface-card);
        border: 1px solid var(--border-subtle);
        color: var(--text-primary);
        width: 32px;
        height: 32px;
        border-radius: 50%;
        display: flex;
        align-items: center;
        justify-content: center;
        cursor: pointer;
        font-size: 0.9rem;
        transition: all var(--transition-base);
        flex-shrink: 0;
    }

    .mobile-nav-arrow:hover:not(:disabled) {
        background: var(--color-accent);
        color: var(--color-primary);
        border-color: var(--color-accent);
    }

    .mobile-nav-arrow:disabled {
        opacity: 0.3;
        cursor: not-allowed;
    }

    .mobile-bg-grid-wrapper {
        flex: 1;
        overflow-x: auto;
        overflow-y: hidden;
        scroll-snap-type: x mandatory;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        -ms-overflow-style: none;
    }

    .mobile-bg-grid-wrapper::-webkit-scrollbar {
        display: none;
    }

    .mobile-bg-grid {
        display: flex;
        gap: 10px;
        padding: 4px 8px;
        min-width: max-content;
    }

    .mobile-bg-grid .bg-option {
        flex: 0 0 58px;
        width: 58px;
        height: 58px;
        border-radius: 8px;
        scroll-snap-align: start;
    }

    .mobile-bg-grid .bg-option.hidden {
        display: none !important;
    }

    /* Hide old carousel styles */
    .panel-body .background-carousel,
    .panel-body .background-grid-wrapper,
    .panel-body .background-grid {
        display: none;
    }

    .panel-body .nav-arrow {
        display: none;
    }

    /* Size options in panel */
    .panel-body .size-options {
        flex-wrap: wrap;
    }

    .panel-body .size-option {
        flex: 0 0 calc(50% - 2px);
    }
}

/* ===== Scrollbar Styling ===== */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-gradient-mid);
}

::-webkit-scrollbar-thumb {
    background: var(--color-accent);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--color-accent-dark);
}

/* ===== Selection ===== */
::selection {
    background: var(--color-accent);
    color: var(--color-primary);
}

/* ===== Small Mobile Adjustments ===== */
@media (max-width: 480px) {
    .mobile-tabs {
        height: 65px;
    }

    .tab-icon {
        font-size: 1.2rem;
    }

    .tab-label {
        font-size: 0.6rem;
    }

    .mobile-tab-content {
        max-height: 55vh;
        bottom: 65px;
        bottom: calc(65px + env(safe-area-inset-bottom, 0px));
    }

}

/* ===== FIREWORKS BACKGROUND ===== */
#fireworksCanvas {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 0;
}

/* Fireworks Toggle Button */
.fireworks-toggle {
    position: fixed;
    bottom: 80px;
    right: 20px;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    border: 1px solid rgba(255, 200, 50, 0.4);
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    font-size: 1.4rem;
    cursor: pointer;
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
}

.fireworks-toggle.active {
    box-shadow: 0 0 20px rgba(255, 200, 50, 0.4);
    animation: fwPulse 3s infinite;
}

.fireworks-toggle:hover {
    transform: scale(1.1);
    background: rgba(255, 200, 50, 0.2);
}

@keyframes fwPulse {

    0%,
    100% {
        transform: scale(1);
        box-shadow: 0 0 20px rgba(255, 200, 50, 0.4);
    }

    50% {
        transform: scale(1.05);
        box-shadow: 0 0 30px rgba(255, 200, 50, 0.6);
    }
}

@media (max-width: 768px) {
    .fireworks-toggle {
        bottom: 75px;
        right: 12px;
        width: 42px;
        height: 42px;
        font-size: 1.2rem;
    }
}