/**
 * Thumbnail Studio - Redesigned Styles
 * Clean, Modern, Functional UI
 * 
 * @author Thumbnail Studio
 * @version 3.0.0
 */

/* ===== CSS RESET & VARIABLES ===== */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    /* Colors - Modern Dark Theme */
    --bg-primary: #0a0a0f;
    --bg-secondary: #12121a;
    --bg-card: #1a1a24;
    --bg-elevated: #22222e;
    
    --border-subtle: rgba(255, 255, 255, 0.06);
    --border-default: rgba(255, 255, 255, 0.1);
    --border-strong: rgba(255, 255, 255, 0.15);
    
    --text-primary: #ffffff;
    --text-secondary: #a0a0b0;
    --text-muted: #666680;
    
    --accent-primary: #7c3aed;
    --accent-secondary: #06b6d4;
    --accent-success: #10b981;
    --accent-warning: #f59e0b;
    --accent-danger: #ef4444;
    
    --gradient-primary: linear-gradient(135deg, #7c3aed 0%, #06b6d4 100%);
    --gradient-card: linear-gradient(180deg, rgba(255,255,255,0.03) 0%, transparent 100%);
    
    /* Spacing */
    --space-xs: 4px;
    --space-sm: 8px;
    --space-md: 16px;
    --space-lg: 24px;
    --space-xl: 32px;
    --space-2xl: 48px;
    
    /* Radius */
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    --radius-xl: 24px;
    --radius-full: 9999px;
    
    /* Shadows */
    --shadow-sm: 0 2px 8px rgba(0,0,0,0.3);
    --shadow-md: 0 8px 24px rgba(0,0,0,0.4);
    --shadow-lg: 0 16px 48px rgba(0,0,0,0.5);
    --shadow-glow: 0 0 30px rgba(124, 58, 237, 0.3);
    
    /* Typography */
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    --font-mono: 'JetBrains Mono', 'Fira Code', monospace;
    
    /* Transitions */
    --transition-fast: 150ms ease;
    --transition-normal: 250ms ease;
    --transition-slow: 400ms ease;
}

/* ===== BASE STYLES ===== */
html {
    scroll-behavior: smooth;
}

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

/* ===== LAYOUT ===== */
.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: var(--space-lg);
}

/* ===== HEADER ===== */
.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-lg) 0;
    border-bottom: 1px solid var(--border-subtle);
    margin-bottom: var(--space-xl);
    flex-wrap: wrap;
    gap: var(--space-md);
}

.header-brand {
    display: flex;
    align-items: center;
    gap: var(--space-md);
}

.site-logo {
    height: 42px;
    width: auto;
    filter: drop-shadow(0 0 12px rgba(124, 58, 237, 0.5));
}

h1 {
    font-size: 1.5rem;
    font-weight: 700;
    background: var(--gradient-primary);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    letter-spacing: -0.02em;
}

.version-badge {
    background: var(--accent-warning);
    color: #000;
    font-size: 0.65rem;
    font-weight: 700;
    padding: 4px 10px;
    border-radius: var(--radius-full);
    letter-spacing: 0.05em;
}

.header-controls {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    flex-wrap: nowrap; /* Prevent wrapping causing layout shift */
}

/* Adjust button padding for better fit */
.btn {
    padding: 8px 14px;
}

/* ===== BUTTONS ===== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-sm);
    padding: 10px 18px;
    border-radius: var(--radius-md);
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-fast);
    border: 1px solid transparent;
    background: var(--bg-elevated);
    color: var(--text-secondary);
}

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

.btn-icon {
    width: 20px;
    height: 20px;
}

.btn-primary {
    background: var(--gradient-primary);
    color: white;
    border: none;
    box-shadow: var(--shadow-glow);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 0 40px rgba(124, 58, 237, 0.5);
}

.btn-danger:hover {
    background: rgba(239, 68, 68, 0.15);
    color: var(--accent-danger);
    border-color: var(--accent-danger);
}

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

.btn-ghost:hover {
    background: var(--bg-elevated);
    border-color: var(--border-strong);
}

/* ===== SWITCH GROUPS ===== */
.switch-group {
    display: flex;
    flex-wrap: wrap; /* Allow wrapping if needed */
    background: var(--bg-secondary);
    border-radius: var(--radius-md);
    padding: 4px;
    border: 1px solid var(--border-subtle);
    max-width: 100%; /* Ensure it doesn't overflow parent */
}

.switch-item {
    display: flex;
    align-items: center;
    justify-content: center; /* Center content */
    gap: 6px;
    padding: 6px 10px; /* Reduced padding */
    border-radius: var(--radius-sm);
    font-size: 0.75rem; /* Slightly smaller font */
    font-weight: 600;
    color: var(--text-muted);
    cursor: pointer;
    transition: all var(--transition-fast);
    flex: 1; /* Distribute space evenly */
    white-space: nowrap;
}

.switch-item:hover {
    color: var(--text-secondary);
}

.switch-item.active {
    background: var(--accent-primary);
    color: white;
    box-shadow: 0 2px 8px rgba(124, 58, 237, 0.4);
}

.switch-item svg {
    width: 16px;
    height: 16px;
}

/* ===== TOOLBAR ===== */
.toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-md);
    padding: var(--space-md);
    background: var(--bg-secondary);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-subtle);
    margin-bottom: var(--space-lg);
    flex-wrap: wrap;
}

.toolbar-section {
    display: flex;
    align-items: center;
    gap: var(--space-md);
}

.toolbar-label {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* ===== MAIN LAYOUT - 2 COLUMN ===== */
.main-layout {
    display: grid;
    grid-template-columns: 1fr 380px;
    gap: var(--space-xl);
    margin-bottom: var(--space-xl);
}

@media (max-width: 1100px) {
    .main-layout {
        grid-template-columns: 1fr;
    }
}

/* ===== INPUT SECTIONS ===== */
.input-panel {
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
}

.input-section {
    background: var(--bg-card);
    background-image: var(--gradient-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    padding: var(--space-lg);
    transition: all var(--transition-normal);
}

.input-section:hover {
    border-color: var(--border-default);
}

.input-section:focus-within {
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px rgba(124, 58, 237, 0.1);
}

.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--space-md);
}

.section-title {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-primary);
}

.section-title svg {
    width: 20px;
    height: 20px;
    color: var(--accent-secondary);
}

.section-count {
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--text-muted);
    background: var(--bg-elevated);
    padding: 2px 8px;
    border-radius: var(--radius-full);
}

/* ===== INPUT FIELD ===== */
.input-wrapper {
    position: relative;
    margin-bottom: var(--space-md);
}

.input-field {
    width: 100%;
    background: var(--bg-secondary);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    padding: 12px 16px;
    padding-left: 44px;
    color: var(--text-primary);
    font-size: 0.9rem;
    font-family: var(--font-sans);
    transition: all var(--transition-fast);
}

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

.input-field:focus {
    outline: none;
    border-color: var(--accent-primary);
    background: var(--bg-primary);
}

.input-icon {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    width: 20px;
    height: 20px;
    color: var(--text-muted);
    pointer-events: none;
}

/* ===== CHIPS ===== */
.chips-container {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    max-height: 120px;
    overflow-y: auto;
    padding-right: 4px;
}

.chips-container::-webkit-scrollbar {
    width: 4px;
}

.chips-container::-webkit-scrollbar-track {
    background: transparent;
}

.chips-container::-webkit-scrollbar-thumb {
    background: var(--border-default);
    border-radius: var(--radius-full);
}

.chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background: var(--bg-elevated);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-full);
    font-size: 0.8rem;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition-fast);
    white-space: nowrap;
}

.chip:hover {
    background: var(--bg-secondary);
    border-color: var(--accent-primary);
    color: var(--text-primary);
    transform: translateY(-1px);
}

.chip:active {
    transform: scale(0.97);
}

.chip-icon {
    font-size: 1rem;
}

/* ===== SIDEBAR / PREVIEW PANEL ===== */
.sidebar {
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
    position: sticky;
    top: var(--space-lg);
    height: fit-content;
}

.preview-card {
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    overflow: hidden;
}

.preview-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-md);
    border-bottom: 1px solid var(--border-subtle);
}

.preview-title {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
}

.preview-title svg {
    width: 16px;
    height: 16px;
    color: var(--accent-secondary);
}

#preview-canvas {
    width: 100%;
    height: auto;
    display: block;
    cursor: grab;
}

#preview-canvas:active {
    cursor: grabbing;
}

.preview-legend {
    display: flex;
    justify-content: center;
    gap: var(--space-lg);
    padding: var(--space-md);
    border-top: 1px solid var(--border-subtle);
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.7rem;
    color: var(--text-muted);
}

.legend-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
}

/* ===== POSITION CONTROLS ===== */
.position-controls {
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    padding: var(--space-md);
}

.position-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-md);
    margin-bottom: var(--space-sm);
}

.position-row:last-child {
    margin-bottom: 0;
}

.position-label {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    min-width: 80px;
}

/* ===== GENERATE BUTTON ===== */
.generate-section {
    margin-bottom: var(--space-xl);
}

.btn-generate {
    width: 100%;
    padding: 18px 32px;
    font-size: 1.1rem;
    font-weight: 700;
    letter-spacing: 0.02em;
    background: var(--gradient-primary);
    color: white;
    border: none;
    border-radius: var(--radius-lg);
    cursor: pointer;
    transition: all var(--transition-normal);
    box-shadow: var(--shadow-glow);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-sm);
}

.btn-generate:hover {
    transform: translateY(-3px);
    box-shadow: 0 0 50px rgba(124, 58, 237, 0.5);
}

.btn-generate svg {
    width: 24px;
    height: 24px;
}

/* ===== OUTPUT SECTION ===== */
.output-section {
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    padding: var(--space-lg);
    margin-bottom: var(--space-xl);
}

.output-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--space-md);
}

.output-title {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-secondary);
}

.output-actions {
    display: flex;
    gap: var(--space-sm);
}

.output-textarea {
    width: 100%;
    min-height: 120px;
    background: var(--bg-primary);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    padding: var(--space-md);
    color: var(--accent-success);
    font-family: var(--font-mono);
    font-size: 0.85rem;
    line-height: 1.7;
    resize: vertical;
}

.output-textarea:focus {
    outline: none;
    border-color: var(--accent-success);
}

/* ===== PROMPT STATS ===== */
.prompt-stats {
    display: flex;
    gap: var(--space-lg);
    padding: var(--space-md);
    background: var(--bg-secondary);
    border-radius: var(--radius-md);
    margin-top: var(--space-md);
}

.stat-item {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.stat-value {
    font-family: var(--font-mono);
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--accent-secondary);
}

.stat-label {
    font-size: 0.65rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* ===== HISTORY SECTION ===== */
.history-section {
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    padding: var(--space-lg);
    margin-bottom: var(--space-xl);
}

.history-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--space-md);
}

.history-title {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-secondary);
}

.history-title svg {
    width: 18px;
    height: 18px;
}

.history-list {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
    max-height: 300px;
    overflow-y: auto;
}

.history-item {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--space-md);
    padding: var(--space-md);
    background: var(--bg-secondary);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    transition: all var(--transition-fast);
}

.history-item:hover {
    border-color: var(--border-default);
}

.hist-text {
    font-family: var(--font-mono);
    font-size: 0.75rem;
    color: var(--text-muted);
    line-height: 1.5;
    flex: 1;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
}

.hist-actions {
    display: flex;
    gap: 4px;
    flex-shrink: 0;
}

.h-btn {
    padding: 6px 10px;
    font-size: 0.7rem;
    font-weight: 600;
    background: var(--bg-elevated);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    cursor: pointer;
    transition: all var(--transition-fast);
}

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

.h-del:hover {
    background: rgba(239, 68, 68, 0.15);
    color: var(--accent-danger);
    border-color: var(--accent-danger);
}

/* ===== PRESETS ===== */
.presets-section {
    margin-bottom: var(--space-lg);
}

.position-presets-section {
    margin-bottom: var(--space-lg);
}

.presets-header {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    margin-bottom: var(--space-md);
}

.presets-title {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-muted);
}

.presets-title svg {
    width: 16px;
    height: 16px;
}

.presets-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
    gap: 8px;
}

.position-presets-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
    gap: 8px;
}

.preset-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 12px 8px;
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.preset-btn:hover {
    border-color: var(--accent-primary);
    transform: translateY(-2px);
    box-shadow: var(--shadow-sm);
}

.preset-icon {
    font-size: 1.2rem;
}

.preset-label {
    font-size: 0.65rem;
    font-weight: 600;
    color: var(--text-muted);
    text-align: center;
}

/* ===== MODE DESCRIPTION ===== */
#mode-desc {
    text-align: center;
    padding: var(--space-sm) var(--space-md);
    background: var(--bg-secondary);
    border-radius: var(--radius-md);
    font-size: 0.8rem;
    color: var(--accent-secondary);
    margin-bottom: var(--space-lg);
}

/* ===== FAVORITES DROPDOWN ===== */
.favorites-wrapper {
    position: relative;
    display: flex; /* Ensure inline display */
    align-items: center;
    gap: var(--space-sm);
}

.favorites-dropdown {
    position: absolute;
    top: calc(100% + 12px);
    right: 0;
    width: 320px;
    max-height: 400px;
    overflow-y: auto;
    background: var(--bg-elevated);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    z-index: 1000;
    display: none;
    padding: var(--space-sm);
}

.favorites-dropdown.show {
    display: block;
    animation: slideDown 0.2s ease;
}

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

.favorites-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--space-sm) var(--space-md);
    border-bottom: 1px solid var(--border-subtle);
    margin-bottom: var(--space-sm);
}

.favorites-header h4 {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--accent-warning);
}

.fav-clear-btn {
    font-size: 0.65rem;
    color: var(--text-muted);
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: var(--radius-sm);
}

.fav-clear-btn:hover {
    background: rgba(239, 68, 68, 0.15);
    color: var(--accent-danger);
}

.fav-item {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-sm) var(--space-md);
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    margin-bottom: 6px;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.fav-item:hover {
    border-color: var(--accent-primary);
}

.fav-item-content {
    flex: 1;
    min-width: 0;
}

.fav-item-title {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.fav-item-meta {
    font-size: 0.65rem;
    color: var(--text-muted);
}

.fav-action-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px;
    border-radius: var(--radius-sm);
    transition: all var(--transition-fast);
}

.fav-action-btn:hover {
    background: var(--bg-elevated);
}

.fav-action-btn.delete:hover {
    color: var(--accent-danger);
}

.fav-empty {
    text-align: center;
    padding: var(--space-xl);
    color: var(--text-muted);
}

.fav-empty-icon {
    font-size: 2rem;
    margin-bottom: var(--space-sm);
    opacity: 0.5;
}

.fav-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    background: transparent;
    border: 1px solid var(--border-default);
    border-radius: var(--radius-full);
    color: var(--text-muted);
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.fav-btn:hover {
    border-color: var(--accent-warning);
    color: var(--accent-warning);
}

.fav-btn.saved {
    background: var(--accent-warning);
    color: #000;
    border-color: var(--accent-warning);
}

.fav-btn svg {
    width: 16px;
    height: 16px;
}

.fav-count {
    background: var(--accent-primary);
    color: white;
    font-size: 0.6rem;
    padding: 2px 6px;
    border-radius: var(--radius-full);
    margin-left: 2px;
}

/* ===== EXPORT/IMPORT ===== */
.export-import-section {
    display: flex;
    gap: var(--space-md);
    margin-bottom: var(--space-xl);
}

.exp-imp-btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-sm);
    padding: var(--space-md);
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    color: var(--text-muted);
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.exp-imp-btn:hover {
    background: var(--bg-elevated);
    color: var(--text-primary);
    border-color: var(--border-default);
}

.exp-imp-btn svg {
    width: 18px;
    height: 18px;
}

/* ===== KEYBOARD SHORTCUTS ===== */
.shortcuts-hint {
    position: fixed;
    bottom: var(--space-lg);
    right: var(--space-lg);
    display: flex;
    align-items: center;
    gap: var(--space-md);
    padding: 10px 16px;
    background: var(--bg-elevated);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    font-size: 0.75rem;
    color: var(--text-muted);
    z-index: 100;
}

.kbd {
    display: inline-block;
    padding: 2px 6px;
    background: var(--bg-primary);
    border: 1px solid var(--border-default);
    border-radius: 6px;
    font-family: var(--font-mono);
    font-size: 0.7rem;
    min-width: 20px;
    text-align: center;
    box-shadow: 0 2px 0 var(--border-default);
}

/* ===== TOAST ===== */
.toast {
    position: fixed;
    bottom: 24px;
    left: 24px; /* Move to left */
    transform: none; /* Remove center transform */
    padding: 12px 24px;
    background: var(--accent-primary);
    color: white;
    font-size: 0.875rem;
    font-weight: 600;
    border-radius: var(--radius-md); /* Less rounded */
    box-shadow: var(--shadow-lg);
    z-index: 1001;
    animation: toastIn 0.3s ease;
    border: 1px solid rgba(255,255,255,0.1);
}

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

/* ===== SKIP LINK ===== */
.skip-link {
    position: absolute;
    top: -100px;
    left: 0;
    background: var(--accent-primary);
    color: white;
    padding: 8px 16px;
    z-index: 9999;
    transition: top var(--transition-fast);
}

.skip-link:focus {
    top: 0;
}

/* ===== FOCUS STYLES ===== */
*:focus-visible {
    outline: 2px solid var(--accent-primary);
    outline-offset: 2px;
}

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
    .container {
        padding: var(--space-md);
    }
    
    .header {
        flex-direction: column;
        align-items: flex-start;
    }
    
    .header-controls {
        width: 100%;
        flex-wrap: wrap;
    }
    
    .toolbar {
        flex-direction: column;
        align-items: stretch;
    }
    
    .toolbar-section {
        flex-wrap: wrap;
    }
    
    .presets-grid {
        grid-template-columns: repeat(4, 1fr);
    }
    
    .export-import-section {
        flex-direction: column;
    }
    
    .shortcuts-hint {
        display: none;
    }
}

/* ===== SCROLLBAR ===== */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-primary);
}

::-webkit-scrollbar-thumb {
    background: var(--border-default);
    border-radius: var(--radius-full);
}

::-webkit-scrollbar-thumb:hover {
    background: var(--border-strong);
}

/* Legacy class mappings for JS compatibility */
.mode-wrapper { display: none; }
.hud-panel { display: none; }
.position-control-panel { display: flex; flex-direction: column; gap: var(--space-sm); }
.drag-hint { display: none; }


/* ===== MODAL ===== */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    opacity: 0;
    visibility: hidden;
    transition: all var(--transition-normal);
}

.modal-overlay.active {
    opacity: 1;
    visibility: visible;
}

.modal-content {
    background: var(--bg-elevated);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-2xl);
    padding: var(--space-xl);
    width: 90%;
    max-width: 400px;
    transform: translateY(20px);
    transition: all var(--transition-normal);
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
}

.modal-overlay.active .modal-content {
    transform: translateY(0);
}

.modal-content h3 {
    margin: 0;
    font-size: 1.25rem;
    color: var(--text-primary);
}

.modal-input-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.modal-input-group input {
    background: var(--bg-secondary);
    border: 1px solid var(--border-default);
    color: var(--text-primary);
    padding: 12px;
    border-radius: var(--radius-md);
    font-size: 1rem;
    outline: none;
    transition: all var(--transition-fast);
}

.modal-input-group input:focus {
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 2px rgba(139, 92, 246, 0.2);
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: var(--space-sm);
    margin-top: var(--space-sm);
}

.modal-actions .btn {
    min-width: 80px;
}

/* ===== FONT SELECTOR ===== */
.font-selector-section {
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    padding: var(--space-md);
}

.font-selector-header {
    margin-bottom: var(--space-md);
}

.font-selector-title {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.font-preview-box {
    background: linear-gradient(135deg, var(--bg-elevated), var(--bg-card));
    border: 2px solid var(--border-default);
    border-radius: var(--radius-md);
    padding: var(--space-lg);
    margin-bottom: var(--space-md);
    text-align: center;
    min-height: 80px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-fast);
}

.font-preview-box:hover {
    border-color: var(--accent-primary);
}

.font-preview-text {
    font-size: 2.5rem;
    color: var(--text-primary);
    text-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
    letter-spacing: 0.02em;
}

.font-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: var(--space-sm);
}

.font-item {
    background: var(--bg-elevated);
    border: 2px solid var(--border-default);
    border-radius: var(--radius-md);
    padding: var(--space-sm);
    cursor: pointer;
    transition: all var(--transition-fast);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-xs);
    min-height: 70px;
}

.font-item:hover {
    background: var(--bg-card);
    border-color: var(--accent-secondary);
    transform: translateY(-2px);
}

.font-item.active {
    background: linear-gradient(135deg, rgba(139, 92, 246, 0.1), rgba(59, 130, 246, 0.1));
    border-color: var(--accent-primary);
    box-shadow: 0 0 20px rgba(139, 92, 246, 0.3);
}

.font-item-name {
    font-size: 0.75rem;
    color: var(--text-secondary);
    font-weight: 500;
    text-align: center;
}

.font-item-preview {
    font-size: 1.25rem;
    color: var(--text-primary);
    font-weight: bold;
}

/* Responsive adjustments */
@media (max-width: 768px) {
    .font-grid {
        grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
        gap: var(--space-xs);
    }

    .font-preview-text {
        font-size: 2rem;
    }
}

/* ===== POPULAR FONT BADGES ===== */
.font-item.popular {
    position: relative;
    background: linear-gradient(135deg, rgba(251, 146, 60, 0.1), rgba(209, 69, 0, 0.05));
    border-color: rgba(251, 146, 60, 0.3);
}

.font-item.popular:hover {
    border-color: #f97316;
    box-shadow: 0 0 20px rgba(251, 146, 60, 0.3);
}

.popular-badge {
    position: absolute;
    top: 4px;
    right: 4px;
    font-size: 0.7rem;
    background: rgba(251, 146, 60, 0.2);
    border-radius: 4px;
    padding: 2px 4px;
    backdrop-filter: blur(4px);
}

/* ===== IMPROVED FONT GRID ===== */
.font-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: var(--space-sm);
    max-height: 500px;
    overflow-y: auto;
    padding-right: var(--space-xs);
}

/* Custom scrollbar for font grid */
.font-grid::-webkit-scrollbar {
    width: 8px;
}

.font-grid::-webkit-scrollbar-track {
    background: var(--bg-elevated);
    border-radius: 4px;
}

.font-grid::-webkit-scrollbar-thumb {
    background: var(--accent-primary);
    border-radius: 4px;
}

.font-grid::-webkit-scrollbar-thumb:hover {
    background: var(--accent-secondary);
}

/* ===== CATEGORY SECTIONS ===== */
.font-category {
    grid-column: 1 / -1;
    padding: var(--space-sm) 0;
    border-bottom: 1px solid var(--border-subtle);
}

.font-category-title {
    font-size: 0.7rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.1em;
    font-weight: 600;
}

/* ===== FONT ITEM STYLES ===== */
.font-item {
    background: var(--bg-elevated);
    border: 2px solid var(--border-default);
    border-radius: var(--radius-md);
    padding: var(--space-sm);
    cursor: pointer;
    transition: all var(--transition-fast);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-xs);
    min-height: 80px;
    position: relative;
}

.font-item:hover {
    background: var(--bg-card);
    border-color: var(--accent-secondary);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(139, 92, 246, 0.2);
}

.font-item.active {
    background: linear-gradient(135deg, rgba(139, 92, 246, 0.15), rgba(59, 130, 246, 0.1));
    border-color: var(--accent-primary);
    box-shadow: 0 0 25px rgba(139, 92, 246, 0.4);
}

.font-item.active::before {
    content: '✓';
    position: absolute;
    top: 6px;
    left: 6px;
    background: var(--accent-primary);
    color: white;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.65rem;
    font-weight: bold;
}

.font-item-name {
    font-size: 0.7rem;
    color: var(--text-secondary);
    font-weight: 500;
    text-align: center;
    word-break: break-word;
}

.font-item-preview {
    font-size: 1.4rem;
    color: var(--text-primary);
    font-weight: bold;
    letter-spacing: 0.02em;
}

/* ===== IMPROVED PREVIEW BOX ===== */
.font-preview-box {
    background: linear-gradient(135deg, var(--bg-elevated), var(--bg-card));
    border: 2px solid var(--border-default);
    border-radius: var(--radius-md);
    padding: var(--space-lg);
    margin-bottom: var(--space-md);
    text-align: center;
    min-height: 100px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-fast);
    position: relative;
    overflow: hidden;
}

.font-preview-box::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: radial-gradient(circle at 50% 50%, rgba(139, 92, 246, 0.1), transparent 70%);
    opacity: 0;
    transition: opacity var(--transition-fast);
}

.font-preview-box:hover::before {
    opacity: 1;
}

.font-preview-box:hover {
    border-color: var(--accent-primary);
    transform: scale(1.02);
}

.font-preview-text {
    font-size: 3rem;
    color: var(--text-primary);
    text-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
    letter-spacing: 0.05em;
    z-index: 1;
    font-weight: 900;
}

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
    .font-grid {
        grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
        gap: var(--space-xs);
        max-height: 400px;
    }

    .font-preview-text {
        font-size: 2.2rem;
    }

    .popular-badge {
        font-size: 0.6rem;
    }
}

/* ===== FONT SELECTOR HEADER ===== */
.font-selector-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--space-md);
    flex-wrap: wrap;
    gap: var(--space-sm);
}

.font-selector-hint {
    font-size: 0.7rem;
    color: var(--text-muted);
    font-weight: 500;
    background: var(--bg-elevated);
    padding: 4px 10px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-subtle);
}

/* ===== LOADING STATE ===== */
.font-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    font-size: 0.9rem;
}

.font-loading::after {
    content: '...';
    animation: dots 1.5s steps(4, end) infinite;
}

@keyframes dots {
    0%, 20% { content: '.'; }
    40% { content: '..'; }
    60%, 100% { content: '...'; }
}

/* ===== FONT TOAST ===== */
.font-toast {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--accent-primary);
    color: white;
    padding: 10px 20px;
    border-radius: var(--radius-md);
    font-size: 0.9rem;
    font-weight: 600;
    box-shadow: 0 4px 20px rgba(139, 92, 246, 0.4);
    z-index: 10000;
    animation: toastSlideUp 0.3s ease-out;
}

@keyframes toastSlideUp {
    from {
        opacity: 0;
        transform: translateX(-50%) translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
}

/* ===== FONT ITEM - ENSURE LOCAL RENDERING ===== */
.font-item {
    background: var(--bg-elevated);
    border: 2px solid var(--border-default);
    border-radius: var(--radius-md);
    padding: var(--space-sm);
    cursor: pointer;
    transition: all var(--transition-fast);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-xs);
    min-height: 85px;
    position: relative;
    /* Force browser to use the specified font */
    font-display: swap !important;
}

.font-item:hover {
    background: var(--bg-card);
    border-color: var(--accent-secondary);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(139, 92, 246, 0.2);
}

.font-item.active {
    background: linear-gradient(135deg, rgba(139, 92, 246, 0.15), rgba(59, 130, 246, 0.1));
    border-color: var(--accent-primary);
    box-shadow: 0 0 25px rgba(139, 92, 246, 0.4);
}

.font-item.active::before {
    content: '✓';
    position: absolute;
    top: 6px;
    left: 6px;
    background: var(--accent-primary);
    color: white;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.65rem;
    font-weight: bold;
    z-index: 1;
}

.font-item-name {
    font-size: 0.7rem;
    color: var(--text-secondary);
    font-weight: 500;
    text-align: center;
    word-break: break-word;
}

.font-item-preview {
    font-size: 1.4rem;
    color: var(--text-primary);
    font-weight: bold;
    letter-spacing: 0.02em;
}

/* ===== POPULAR BADGES ===== */
.font-item.popular {
    position: relative;
    background: linear-gradient(135deg, rgba(251, 146, 60, 0.1), rgba(209, 69, 0, 0.05));
    border-color: rgba(251, 146, 60, 0.3);
}

.font-item.popular:hover {
    border-color: #f97316;
    box-shadow: 0 0 20px rgba(251, 146, 60, 0.3);
}

.popular-badge {
    position: absolute;
    top: 4px;
    right: 4px;
    font-size: 0.7rem;
    background: rgba(251, 146, 60, 0.2);
    border-radius: 4px;
    padding: 2px 4px;
    backdrop-filter: blur(4px);
    z-index: 1;
}

/* ===== FONT GRID ===== */
.font-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: var(--space-sm);
    max-height: 500px;
    overflow-y: auto;
    padding-right: var(--space-xs);
}

/* Custom scrollbar for font grid */
.font-grid::-webkit-scrollbar {
    width: 8px;
}

.font-grid::-webkit-scrollbar-track {
    background: var(--bg-elevated);
    border-radius: 4px;
}

.font-grid::-webkit-scrollbar-thumb {
    background: var(--accent-primary);
    border-radius: 4px;
}

.font-grid::-webkit-scrollbar-thumb:hover {
    background: var(--accent-secondary);
}

/* ===== IMPROVED PREVIEW BOX ===== */
.font-preview-box {
    background: linear-gradient(135deg, var(--bg-elevated), var(--bg-card));
    border: 2px solid var(--border-default);
    border-radius: var(--radius-md);
    padding: var(--space-lg);
    margin-bottom: var(--space-md);
    text-align: center;
    min-height: 100px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-fast);
    position: relative;
    overflow: hidden;
}

.font-preview-box::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: radial-gradient(circle at 50% 50%, rgba(139, 92, 246, 0.1), transparent 70%);
    opacity: 0;
    transition: opacity var(--transition-fast);
}

.font-preview-box:hover::before {
    opacity: 1;
}

.font-preview-box:hover {
    border-color: var(--accent-primary);
    transform: scale(1.01);
}

.font-preview-text {
    font-size: 3rem;
    color: var(--text-primary);
    text-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
    letter-spacing: 0.05em;
    z-index: 1;
    font-weight: 900;
    /* Force font loading */
    font-display: swap !important;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
    .font-grid {
        grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
        gap: var(--space-xs);
        max-height: 400px;
    }

    .font-preview-text {
        font-size: 2.2rem;
    }

    .popular-badge {
        font-size: 0.6rem;
    }

    .font-selector-hint {
        font-size: 0.65rem;
    }
}

/* ===== FOOTER ===== */
.app-footer {
    margin-top: var(--space-xl);
    padding: var(--space-lg);
    border-top: 1px solid var(--border-subtle);
    background: linear-gradient(180deg, transparent 0%, rgba(139, 92, 246, 0.03) 100%);
}

.footer-content {
    max-width: 1400px;
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--space-md);
}

.footer-left {
    display: flex;
    align-items: center;
    gap: var(--space-md);
}

.footer-brand {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-primary);
}

.footer-logo {
    width: 20px;
    height: 20px;
    color: var(--accent-primary);
}

.footer-version {
    padding: 4px 10px;
    background: rgba(139, 92, 246, 0.1);
    border: 1px solid rgba(139, 92, 246, 0.2);
    border-radius: 20px;
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--accent-primary);
}

.footer-right {
    display: flex;
    gap: var(--space-sm);
}

.footer-link {
    display: flex;
    align-items: center;
    gap: var(--space-xs);
    padding: 8px 16px;
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.85rem;
    font-weight: 500;
    transition: all 0.2s ease;
}

.footer-link svg {
    width: 18px;
    height: 18px;
}

.footer-link:hover {
    background: rgba(139, 92, 246, 0.1);
    border-color: var(--accent-primary);
    color: var(--accent-primary);
    transform: translateY(-2px);
    box-shadow: var(--shadow-sm);
}

.footer-link:active {
    transform: translateY(0);
}

.footer-bottom {
    text-align: center;
    padding-top: var(--space-md);
    border-top: 1px solid var(--border-subtle);
}

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

/* Responsive */
@media (max-width: 768px) {
    .footer-content {
        flex-direction: column;
        gap: var(--space-md);
        text-align: center;
    }

    .footer-brand {
        justify-content: center;
    }

    .footer-link span {
        display: none;
    }

    .footer-link {
        padding: 10px;
    }

    .footer-link svg {
        width: 20px;
        height: 20px;
    }
}
