/* =============================================
   ELITE WORD SEARCH — Design System
   Aesthetic: Editorial Warmth
   Fonts: Bricolage Grotesque + Figtree
   ============================================= */

/* ── Design Tokens ── */
:root {
    --font-display: 'Bricolage Grotesque', Georgia, serif;
    --font-body: 'Figtree', -apple-system, BlinkMacSystemFont, sans-serif;

    --bg-page: #faf8f5;
    --bg-card: #ffffff;
    --bg-subtle: #f3efe9;
    --bg-input: #ffffff;
    --text-primary: #1c1917;
    --text-secondary: #57534e;
    --text-muted: #a8a29e;
    --accent: #ea580c;
    --accent-hover: #c2410c;
    --accent-light: #fff7ed;
    --accent-subtle: #ffedd5;
    --accent-border: #fdba74;
    --border: #e7e5e4;
    --border-strong: #d6d3d1;

    --shadow-sm: 0 1px 2px rgba(28, 25, 23, 0.04);
    --shadow-md: 0 2px 8px rgba(28, 25, 23, 0.06), 0 1px 2px rgba(28, 25, 23, 0.04);
    --shadow-lg: 0 4px 20px rgba(28, 25, 23, 0.08), 0 2px 4px rgba(28, 25, 23, 0.03);
    --shadow-xl: 0 8px 32px rgba(28, 25, 23, 0.10), 0 4px 8px rgba(28, 25, 23, 0.04);

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

body.dark {
    --bg-page: #1c1917;
    --bg-card: #292524;
    --bg-subtle: #1c1917;
    --bg-input: #1c1917;
    --text-primary: #fafaf9;
    --text-secondary: #a8a29e;
    --text-muted: #78716c;
    --accent: #fb923c;
    --accent-hover: #f97316;
    --accent-light: #431407;
    --accent-subtle: #7c2d12;
    --accent-border: #c2410c;
    --border: #44403c;
    --border-strong: #57534e;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.2);
    --shadow-md: 0 2px 8px rgba(0, 0, 0, 0.25);
    --shadow-lg: 0 4px 20px rgba(0, 0, 0, 0.3);
    --shadow-xl: 0 8px 32px rgba(0, 0, 0, 0.4);
}

/* ── Animations ── */
@keyframes fadeUp {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

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

body {
    font-family: var(--font-body);
    background: var(--bg-page);
    min-height: 100vh;
    color: var(--text-primary);
    transition: background-color 0.4s ease, color 0.4s ease;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body.dark {
    background: var(--bg-page);
    color: var(--text-primary);
}

/* ── Layout ── */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 24px;
}

/* ── Theme Switcher (fixed bottom-right) ── */
.theme-switcher {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 1000;
    display: flex;
    gap: 10px;
    align-items: center;
    flex-direction: row;
}

.theme-toggle {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-full);
    border: 2px solid var(--border);
    background: var(--bg-card);
    color: var(--text-secondary);
    font-size: 1.1rem;
    cursor: pointer;
    transition: all 0.25s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-md);
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}

.theme-toggle:hover {
    background: var(--bg-subtle);
    border-color: var(--border-strong);
    transform: translateY(-1px);
    box-shadow: var(--shadow-lg);
}

body.dark .theme-toggle {
    background: var(--bg-card);
    border-color: var(--border);
    color: var(--text-secondary);
}

body.dark .theme-toggle:hover {
    background: var(--bg-subtle);
}

/* ── Themes Menu Toggle (hamburger FAB) ── */
.themes-menu-toggle {
    width: 56px;
    height: 56px;
    border-radius: var(--radius-full);
    border: none;
    background: linear-gradient(135deg, var(--accent) 0%, var(--accent-hover) 100%);
    color: #ffffff;
    cursor: pointer;
    font-size: 24px;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.25s ease;
    box-shadow: 0 4px 16px rgba(234, 88, 12, 0.35);
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}

.themes-menu-toggle:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 24px rgba(234, 88, 12, 0.45);
}

body.dark .themes-menu-toggle {
    background: linear-gradient(135deg, var(--accent) 0%, var(--accent-hover) 100%);
    box-shadow: 0 4px 16px rgba(251, 146, 60, 0.3);
}

body.dark .themes-menu-toggle:hover {
    box-shadow: 0 6px 24px rgba(251, 146, 60, 0.4);
}

.themes-menu-toggle.active {
    background: var(--accent-hover);
    transform: rotate(90deg);
    box-shadow: 0 6px 20px rgba(234, 88, 12, 0.4);
}

.themes-menu-toggle.active:hover {
    background: var(--accent);
}

body.dark .themes-menu-toggle.active {
    background: var(--accent-hover);
    box-shadow: 0 6px 20px rgba(251, 146, 60, 0.35);
}

body.dark .themes-menu-toggle.active:hover {
    background: var(--accent);
}

/* Hamburger Lines */
.hamburger {
    width: 20px;
    height: 16px;
    position: relative;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

.hamburger .line {
    width: 100%;
    height: 2px;
    background-color: currentColor;
    border-radius: 1px;
    transition: all 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55);
    transform-origin: center;
}

.themes-menu-toggle.active .hamburger .line:nth-child(1) {
    transform: translateY(7px) rotate(45deg);
}

.themes-menu-toggle.active .hamburger .line:nth-child(2) {
    opacity: 0;
    transform: scaleX(0);
}

.themes-menu-toggle.active .hamburger .line:nth-child(3) {
    transform: translateY(-7px) rotate(-45deg);
}

/* ── Themes Menu Overlay ── */
.themes-menu-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(28, 25, 23, 0.4);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 1100;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}

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

/* ── Themes Menu Sidebar ── */
.themes-menu {
    position: fixed;
    bottom: 90px;
    right: 20px;
    width: 320px;
    max-height: 70vh;
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-xl);
    z-index: 1101;
    transform: scale(0) translateY(20px);
    transform-origin: bottom right;
    transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    opacity: 0;
    overflow-y: auto;
}

.themes-menu.active {
    transform: scale(1) translateY(0);
    opacity: 1;
}

body.dark .themes-menu {
    background: var(--bg-card);
    border-color: var(--border);
    box-shadow: var(--shadow-xl);
}

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

body.dark .themes-menu-header {
    border-bottom-color: var(--border);
}

.themes-menu-header .menu-title {
    margin: 0;
    color: var(--text-primary);
    font-family: var(--font-display);
    font-size: 18px;
    font-weight: 700;
    display: block;
}

body.dark .themes-menu-header .menu-title {
    color: var(--text-primary);
}

.browse-all-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 20px;
    background: linear-gradient(135deg, var(--accent) 0%, var(--accent-hover) 100%);
    color: white;
    text-decoration: none;
    font-weight: 600;
    font-size: 15px;
    border-bottom: 1px solid var(--border);
    transition: all 0.2s ease;
}

.browse-all-link:hover {
    background: linear-gradient(135deg, var(--accent-hover) 0%, #9a3412 100%);
}

.browse-all-link svg {
    stroke: white;
    flex-shrink: 0;
}

body.dark .browse-all-link {
    border-bottom-color: var(--border);
}

body.dark .browse-all-link:hover {
    background: linear-gradient(135deg, var(--accent-hover) 0%, #9a3412 100%);
}

.theme-toggle-container {
    padding: 15px 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
    transition: background-color 0.2s ease, transform 0.2s ease;
    user-select: none;
}

body.dark .theme-toggle-container {
    border-bottom-color: var(--border);
}

.theme-toggle-label {
    color: var(--text-primary);
    font-weight: 500;
}

body.dark .theme-toggle-label {
    color: var(--text-primary);
}

.theme-toggle-container:hover {
    background: var(--bg-subtle);
    transform: translateX(4px);
}

body.dark .theme-toggle-container:hover {
    background: var(--bg-subtle);
}

@media (max-width: 768px) {
    .themes-menu {
        bottom: 90px;
        right: 15px;
        left: 15px;
        width: auto;
        max-height: 65vh;
    }

    .theme-switcher {
        bottom: 15px;
        right: 15px;
    }

    .themes-menu-toggle {
        width: 60px;
        height: 60px;
        border-radius: 30px;
        font-size: 26px;
    }

    .theme-toggle {
        width: 40px;
        height: 40px;
        border-radius: 20px;
        font-size: 18px;
    }
}

/* ── Header / Hero ── */
header, .hero {
    text-align: center;
    margin-bottom: 40px;
    color: var(--text-primary);
    animation: fadeUp 0.6s ease-out both;
    animation-delay: 0.05s;
}

body.dark header, body.dark .hero {
    color: var(--text-primary);
}

header h1, .hero h1 {
    font-family: var(--font-display);
    font-size: 3rem;
    font-weight: 800;
    margin-bottom: 10px;
    letter-spacing: -0.02em;
    line-height: 1.1;
}

body.dark header h1, body.dark .hero h1 {
    text-shadow: none;
}

header p, .hero p {
    font-size: 1.15rem;
    color: var(--text-secondary);
    font-weight: 400;
}

/* ── Generator Section ── */
.generator-section {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 32px;
    align-items: start;
    animation: fadeUp 0.6s ease-out both;
    animation-delay: 0.15s;
}

.input-panel,
.puzzle-panel {
    background: var(--bg-card);
    border-radius: var(--radius-xl);
    padding: 32px;
    border: 1px solid var(--border);
    box-shadow: var(--shadow-lg);
    transition: border-color 0.3s ease, box-shadow 0.3s ease;
}

body.dark .input-panel,
body.dark .puzzle-panel {
    background: var(--bg-card);
    border-color: var(--border);
    box-shadow: var(--shadow-lg);
}

.input-panel h2 {
    color: var(--text-primary);
    margin-bottom: 24px;
    font-family: var(--font-display);
    font-size: 1.5rem;
    font-weight: 700;
}

body.dark .input-panel h2 {
    color: var(--text-primary);
}

/* ── Form Elements ── */
.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    color: var(--text-primary);
    font-size: 0.9rem;
    letter-spacing: 0.01em;
}

body.dark .form-group label {
    color: var(--text-primary);
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 12px 16px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 1rem;
    font-family: var(--font-body);
    transition: border-color 0.25s ease, box-shadow 0.25s ease;
    background: var(--bg-input);
    color: var(--text-primary);
}

body.dark .form-group input,
body.dark .form-group select,
body.dark .form-group textarea {
    background: var(--bg-input);
    border-color: var(--border);
    color: var(--text-primary);
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(234, 88, 12, 0.1);
}

body.dark .form-group input:focus,
body.dark .form-group select:focus,
body.dark .form-group textarea:focus {
    box-shadow: 0 0 0 3px rgba(251, 146, 60, 0.15);
}

.form-group textarea {
    resize: vertical;
    font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
}

.form-group small {
    display: block;
    margin-top: 6px;
    color: var(--text-muted);
    font-size: 0.85rem;
}

body.dark .form-group small {
    color: var(--text-muted);
}

/* ── Footer ── */
footer {
    text-align: center;
    margin-top: 48px;
    padding: 24px;
    color: var(--text-muted);
}

body.dark footer {
    color: var(--text-muted);
}

/* ── Fieldset / Directions ── */
fieldset {
    border: none;
    padding: 0;
    margin: 0;
}

fieldset legend {
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 8px;
    font-size: 0.9rem;
    letter-spacing: 0.01em;
}

body.dark fieldset legend {
    color: var(--text-primary);
}

.checkbox-group {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-bottom: 8px;
}

.checkbox-item {
    display: flex;
    align-items: center;
    cursor: pointer;
    padding: 10px 12px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    transition: all 0.2s ease;
    background: var(--bg-card);
    font-size: 0.88rem;
    color: var(--text-primary);
}

body.dark .checkbox-item {
    background: var(--bg-input);
    border-color: var(--border);
    color: var(--text-primary);
}

.checkbox-item:hover {
    border-color: var(--border-strong);
    background: var(--bg-subtle);
}

body.dark .checkbox-item:hover {
    border-color: var(--border-strong);
    background: var(--bg-subtle);
}

.checkbox-item input[type="checkbox"] {
    margin: 0;
    margin-right: 8px;
    width: 16px;
    height: 16px;
    accent-color: var(--accent);
    cursor: pointer;
}

.checkbox-item:has(input:checked) {
    border-color: var(--accent);
    background: var(--accent-light);
}

body.dark .checkbox-item:has(input:checked) {
    border-color: var(--accent-border);
    background: var(--accent-light);
}

.checkmark {
    flex: 1;
}

/* ── Messages ── */
.error-message,
.warning-message {
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    margin: 15px 0;
    font-size: 0.9rem;
    line-height: 1.4;
}

.error-message {
    background: #fef2f2;
    border: 1.5px solid #fecaca;
    color: #dc2626;
}

body.dark .error-message {
    background: #450a0a;
    border-color: #7f1d1d;
    color: #f87171;
}

.warning-message {
    background: #fffbeb;
    border: 1.5px solid #fde68a;
    color: #d97706;
}

body.dark .warning-message {
    background: #451a03;
    border-color: #92400e;
    color: #fbbf24;
}

/* ── Primary Button (Generate) ── */
.generate-btn {
    width: 100%;
    padding: 16px;
    background: linear-gradient(135deg, #ea580c 0%, #c2410c 100%);
    color: white;
    border: none;
    border-radius: var(--radius-md);
    font-family: var(--font-body);
    font-size: 1.05rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.25s ease;
    letter-spacing: 0.01em;
}

.generate-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 24px rgba(234, 88, 12, 0.4);
}

.generate-btn:active {
    transform: translateY(0);
    box-shadow: 0 2px 8px rgba(234, 88, 12, 0.3);
}

/* ── Tabs ── */
.tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 16px;
    background: var(--bg-subtle);
    padding: 4px;
    border-radius: var(--radius-md);
}

a.tab {
    text-decoration: none;
}

.tab {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    padding: 8px 14px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 500;
    font-family: var(--font-body);
    transition: all 0.2s ease;
}

.tab.active {
    background: var(--bg-card);
    color: var(--text-primary);
    box-shadow: var(--shadow-sm);
    font-weight: 600;
}

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

.tab.active:hover {
    background: var(--bg-card);
}

body.dark .tab {
    background: transparent;
    color: var(--text-secondary);
}

body.dark .tab.active {
    background: var(--bg-card);
    color: var(--text-primary);
    box-shadow: var(--shadow-sm);
}

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

body.dark .tab.active:hover {
    background: var(--bg-card);
}

.tab-panel[hidden] {
    display: none;
}

/* ── Puzzle Placeholder ── */
.puzzle-placeholder {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-muted);
}

.placeholder-icon {
    font-size: 4rem;
    margin-bottom: 20px;
}

.placeholder-hint {
    font-size: 0.9rem;
    margin-top: 10px;
}

#puzzle-display {
    margin-bottom: 30px;
}

.puzzle-title {
    text-align: center;
    font-family: var(--font-display);
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 20px;
}

body.dark .puzzle-title {
    color: var(--text-primary);
}

/* ── Puzzle Layout (3-column on desktop) ── */
.puzzle-layout {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
}

@media (min-width: 1100px) {
    .puzzle-layout {
        flex-direction: row;
        align-items: flex-start;
        justify-content: center;
        gap: 24px;
    }

    .puzzle-container:has(.puzzle-layout) ~ .puzzle-actions,
    .puzzle-container:has(.puzzle-layout) ~ .theme-actions {
        display: none !important;
    }
}

.puzzle-grid-wrapper {
    text-align: center;
    flex-shrink: 0;
    order: 2;
}

.word-list-panel {
    background: var(--bg-subtle);
    border: 1.5px solid var(--border);
    border-radius: var(--radius-md);
    padding: 20px;
    min-width: 180px;
    max-width: 220px;
    order: 1;
}

.word-list-panel h3 {
    color: var(--text-primary);
    margin: 0 0 15px 0;
    font-family: var(--font-display);
    font-size: 1rem;
    font-weight: 700;
    text-align: center;
}

.word-list-panel .words-list-container {
    column-count: 1;
    line-height: 1.7;
    font-size: 0.9rem;
}

body.dark .word-list-panel {
    background: var(--bg-subtle);
    border-color: var(--border);
}

body.dark .word-list-panel h3 {
    color: var(--text-primary);
}

body.dark .word-list-panel .words-list-container {
    color: var(--text-primary);
}

/* Actions panel (right side on desktop) */
.puzzle-actions-panel {
    display: none;
    flex-direction: column;
    gap: 12px;
    min-width: 160px;
    max-width: 180px;
    order: 3;
}

@media (min-width: 1100px) {
    .puzzle-actions-panel {
        display: flex;
    }
}

.puzzle-actions-panel .size-selector-container {
    width: 100%;
    margin-bottom: 8px;
}

.puzzle-actions-panel button,
.puzzle-actions-panel .create-own-btn {
    width: 100%;
    padding: 12px 16px;
    font-size: 0.9rem;
    border-radius: var(--radius-sm);
    cursor: pointer;
    text-align: center;
    text-decoration: none;
    display: block;
    box-sizing: border-box;
}

.puzzle-actions-panel .create-own-btn {
    background: linear-gradient(135deg, #ea580c 0%, #c2410c 100%);
    color: white;
    font-weight: 600;
    border: none;
}

.puzzle-actions-panel .create-own-btn:hover {
    background: linear-gradient(135deg, #c2410c 0%, #9a3412 100%);
    box-shadow: 0 4px 16px rgba(234, 88, 12, 0.25);
}

/* Mobile: stack vertically */
@media (max-width: 1099px) {
    .puzzle-layout {
        flex-direction: column;
    }

    .word-list-panel,
    .puzzle-grid-wrapper {
        order: unset;
    }

    .puzzle-grid-wrapper {
        order: 1;
    }

    .word-list-panel {
        order: 2;
        max-width: 100%;
        width: 100%;
    }

    .word-list-panel .words-list-container {
        column-count: 3;
    }
}

@media (max-width: 500px) {
    .word-list-panel .words-list-container {
        column-count: 2;
    }
}

/* ── Puzzle Grid ── */
.puzzle-grid {
    display: inline-block;
    border: 2px solid var(--text-primary);
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: 20px;
}

body.dark .puzzle-grid {
    border-color: var(--text-primary);
}

.grid-row {
    display: flex;
}

.grid-cell {
    width: 25px;
    height: 25px;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: var(--font-body);
    font-weight: 700;
    font-size: 18px;
    background: transparent;
    color: var(--text-primary);
}

/* ── Word List ── */
.word-list {
    text-align: center;
}

.word-list h3 {
    color: var(--text-primary);
    margin-bottom: 15px;
    font-family: var(--font-display);
    font-size: 1.2rem;
    font-weight: 700;
}

body.dark .word-list h3 {
    color: var(--text-primary);
}

.words-container {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 10px;
    max-width: 640px;
    margin: 0 auto;
}

.word-item {
    padding: 8px 14px;
    background: var(--bg-subtle);
    border: 1px solid var(--border);
    border-radius: var(--radius-full);
    font-weight: 600;
    font-size: 0.88rem;
    text-align: center;
    overflow-wrap: anywhere;
    word-break: break-word;
    color: var(--text-primary);
}

body.dark .word-item {
    background: var(--bg-subtle);
    border-color: var(--border);
    color: var(--text-primary);
}

.words-list-container {
    background: var(--bg-subtle);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 12px 16px;
    font-family: var(--font-body);
    font-size: 0.9rem;
    line-height: 1.4;
    color: var(--text-primary);
    white-space: normal;
    min-height: 100px;
    max-width: 400px;
    margin: 0 auto;
    cursor: default;
    user-select: text;
    -webkit-user-select: text;
    -moz-user-select: text;
}

body.dark .words-list-container {
    background: var(--bg-subtle);
    border-color: var(--border);
    color: var(--text-primary);
}

/* Word list chip layout */
.words-list-container {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
}

.words-list-container .word-item {
    display: inline-block;
    padding: 6px 14px;
    min-width: 60px;
    text-align: center;
    background: var(--accent-light);
    border: 1px solid var(--accent-border);
    border-radius: var(--radius-full);
    font-weight: 500;
    font-size: 0.85rem;
    color: var(--accent-hover);
}

body.dark .words-list-container .word-item {
    background: var(--accent-light);
    border-color: var(--accent-border);
    color: var(--accent);
}

.words-list-container.cols-2 {
    max-width: 500px;
}

.words-list-container.cols-3 {
    max-width: 600px;
}

.words-list-container.cols-4 {
    max-width: 700px;
}

#theme-words-preview {
    background: var(--bg-subtle);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 10px;
    font-family: var(--font-body);
    font-size: 0.9rem;
    line-height: 1.4;
    color: var(--text-primary);
    resize: vertical;
    min-height: 120px;
    cursor: default;
    user-select: text;
    -webkit-user-select: text;
    -moz-user-select: text;
}

body.dark #theme-words-preview {
    background: var(--bg-input);
    border-color: var(--border);
    color: var(--text-primary);
}

/* ── Puzzle Actions Bar ── */
.puzzle-actions {
    display: flex;
    gap: 12px;
    justify-content: center;
    align-items: center;
    flex-wrap: wrap;
    margin-top: 20px;
}

/* ── Size Selector ── */
.size-selector-container {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: var(--accent-light);
    border: 1px solid var(--accent-border);
    border-radius: var(--radius-sm);
}

.size-selector-container label {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--accent-hover);
    white-space: nowrap;
}

.size-selector-container select {
    padding: 6px 10px;
    border: 1px solid var(--accent-border);
    border-radius: 6px;
    background: var(--bg-card);
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--accent-hover);
    cursor: pointer;
    font-family: var(--font-body);
}

.size-selector-container select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(234, 88, 12, 0.15);
}

.dark .size-selector-container {
    background: var(--accent-light);
    border-color: var(--accent-border);
}

.dark .size-selector-container label {
    color: var(--accent);
}

.dark .size-selector-container select {
    background: var(--bg-input);
    border-color: var(--accent-border);
    color: var(--accent);
}

/* ── Action Buttons ── */
.download-btn,
.print-btn,
.secondary-btn {
    padding: 12px 20px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    font-weight: 600;
    font-family: var(--font-body);
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
}

/* Download PDF — cool slate */
.download-btn {
    background: linear-gradient(135deg, #475569 0%, #334155 100%);
    color: #f8fafc;
}

.download-btn:hover {
    background: linear-gradient(135deg, #334155 0%, #1e293b 100%);
    transform: translateY(-1px);
    box-shadow: 0 4px 16px rgba(51, 65, 85, 0.3);
}

/* Print — warm amber */
.print-btn {
    background: linear-gradient(135deg, #d97706 0%, #b45309 100%);
    color: #ffffff;
}

.print-btn:hover {
    background: linear-gradient(135deg, #b45309 0%, #92400e 100%);
    transform: translateY(-1px);
    box-shadow: 0 4px 16px rgba(217, 119, 6, 0.3);
}

/* Secondary / Shuffle — warm stone */
.secondary-btn {
    background: linear-gradient(135deg, #78716c 0%, #57534e 100%);
    color: white;
    border: none;
}

.secondary-btn:hover {
    background: linear-gradient(135deg, #57534e 0%, #44403c 100%);
    transform: translateY(-1px);
    box-shadow: 0 4px 16px rgba(120, 113, 108, 0.3);
}

#shuffle-btn {
    background: linear-gradient(135deg, #78716c 0%, #57534e 100%);
    color: white;
    border: none;
    font-weight: 600;
}

#shuffle-btn:hover {
    background: linear-gradient(135deg, #57534e 0%, #44403c 100%);
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(120, 113, 108, 0.3);
}

#new-puzzle-btn {
    background: linear-gradient(135deg, #78716c 0%, #57534e 100%);
    color: white;
    border: none;
    font-weight: 600;
}

#new-puzzle-btn:hover {
    background: linear-gradient(135deg, #57534e 0%, #44403c 100%);
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(120, 113, 108, 0.3);
}

/* ── Theme Quick-Pick Row ── */
.theme-row {
    display: flex;
    gap: 8px;
    align-items: center;
}

.theme-browse-btn {
    white-space: nowrap;
}

/* ── Theme Assistant (chat-style) ── */
.assistant {
    margin-top: 14px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-md);
    overflow: hidden;
    background: var(--bg-card);
}

body.dark .assistant {
    background: var(--bg-card);
    border-color: var(--border);
}

.assistant-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    background: var(--bg-subtle);
    border-bottom: 1.5px solid var(--border);
}

body.dark .assistant-header {
    background: var(--bg-subtle);
    border-color: var(--border);
}

.assistant-title {
    font-weight: 700;
    font-family: var(--font-display);
    font-size: 0.95rem;
}

.assistant-close {
    background: transparent;
    border: none;
    color: inherit;
    cursor: pointer;
    font-size: 0.95rem;
}

.assistant-body {
    padding: 12px;
    display: grid;
    gap: 10px;
}

.assistant-bubble {
    padding: 10px 14px;
    border-radius: var(--radius-md);
    max-width: 100%;
    line-height: 1.4;
}

.assistant-bubble.assistant {
    background: var(--accent-light);
    border: 1.5px solid var(--accent-border);
}

body.dark .assistant-bubble.assistant {
    background: var(--accent-light);
    border-color: var(--accent-border);
}

.assistant-bubble.user {
    background: var(--bg-subtle);
    border: 1.5px solid var(--border-strong);
}

body.dark .assistant-bubble.user {
    background: var(--bg-subtle);
    border-color: var(--border-strong);
}

.assistant-actions {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 8px;
}

.assistant-actions .secondary-btn {
    width: 100%;
    padding: 15px;
    border-radius: var(--radius-md);
    font-size: 1.05rem;
    font-weight: 600;
}

.assistant-options {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.assistant-chip {
    border: 1.5px solid var(--border);
    background: var(--bg-card);
    padding: 8px 12px;
    border-radius: var(--radius-full);
    cursor: pointer;
    font-size: 0.88rem;
    font-family: var(--font-body);
    color: var(--text-primary);
    transition: all 0.2s ease;
}

body.dark .assistant-chip {
    background: var(--bg-card);
    border-color: var(--border);
    color: var(--text-primary);
}

.assistant-chip:hover {
    border-color: var(--accent);
    background: var(--accent-light);
    color: var(--accent-hover);
}

.theme-assistant-controls {
    margin-top: 8px;
    display: flex;
    justify-content: flex-end;
}

/* ── Responsive (768px) ── */
@media (max-width: 768px) {
    .generator-section {
        grid-template-columns: 1fr;
        gap: 20px;
    }

    header h1 {
        font-size: 2rem;
    }

    .input-panel,
    .puzzle-panel {
        padding: 24px;
    }

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

    .grid-cell {
        width: 20px;
        height: 20px;
        font-size: 16px;
    }

    .checkbox-group {
        grid-template-columns: 1fr;
    }
}

/* ── Print Styles ── */
@media print {
    body {
        background: white !important;
        color: black !important;
    }

    .container {
        max-width: none;
        margin: 0;
        padding: 20px;
    }

    .generator-section {
        display: block;
    }

    .input-panel {
        display: none !important;
    }

    .puzzle-panel {
        box-shadow: none;
        border-radius: 0;
        background: white;
        border: none;
        padding: 0;
    }

    .puzzle-actions {
        display: none !important;
    }

    header {
        display: none !important;
    }

    .puzzle-title {
        color: black !important;
        font-size: 1.8rem;
        margin-bottom: 30px;
    }

    .puzzle-grid {
        border: 3px solid black;
    }

    .grid-cell {
        border: none;
        width: 30px;
        height: 30px;
        font-size: 20px;
        background: white !important;
        font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif !important;
        color: #000000 !important;
    }

    .word-list {
        display: block !important;
        page-break-inside: avoid;
        margin-top: 30px;
    }

    .word-list h3 {
        color: black !important;
        font-size: 1.3rem;
        margin: 30px 0 20px 0;
    }

    .words-list-container {
        column-count: 4 !important;
        column-gap: 20px !important;
        text-align: left !important;
        max-width: 100% !important;
        padding: 15px !important;
        background: white !important;
        border: 1px solid #ccc !important;
        line-height: 1.8 !important;
    }

    .words-container {
        display: grid !important;
        grid-template-columns: repeat(4, 1fr);
        gap: 10px;
        max-width: 100%;
        margin: 0 auto;
    }

    .word-item {
        background: white !important;
        border: 1px solid #ccc;
        padding: 8px;
        font-size: 0.9rem;
        text-align: center;
        border-radius: 0;
    }

    .puzzle-placeholder {
        display: none !important;
    }
}

/* ── Themes Showcase Section ── */
.themes-showcase {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    padding: 32px;
    border: 1px solid var(--border);
    box-shadow: var(--shadow-lg);
    margin-bottom: 30px;
    text-align: center;
}

body.dark .themes-showcase {
    background: var(--bg-card);
    border-color: var(--border);
    box-shadow: var(--shadow-lg);
}

.themes-showcase h2 {
    font-family: var(--font-display);
    font-size: 2rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 12px;
}

body.dark .themes-showcase h2 {
    color: var(--text-primary);
}

.themes-showcase p {
    color: var(--text-secondary);
    font-size: 1.05rem;
    margin-bottom: 28px;
}

body.dark .themes-showcase p {
    color: var(--text-secondary);
}

/* ── Theme Cards ── */
.themes-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-top: 20px;
}

.theme-card {
    background: var(--bg-card);
    border: 1.5px solid var(--border);
    border-radius: var(--radius-md);
    padding: 20px;
    text-align: center;
    transition: all 0.25s ease;
    text-decoration: none;
    color: inherit;
}

body.dark .theme-card {
    background: var(--bg-card);
    border-color: var(--border);
}

.theme-card:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-lg);
    border-color: var(--accent);
}

body.dark .theme-card:hover {
    box-shadow: var(--shadow-lg);
    border-color: var(--accent);
}

.theme-card-icon {
    font-size: 2.5rem;
    margin-bottom: 10px;
    display: block;
}

.theme-card-name {
    font-family: var(--font-display);
    font-size: 1.05rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 4px;
}

body.dark .theme-card-name {
    color: var(--text-primary);
}

.theme-card-description {
    font-size: 0.88rem;
    color: var(--text-secondary);
}

body.dark .theme-card-description {
    color: var(--text-secondary);
}

/* ── Theme Page ── */
.back-link {
    margin-bottom: 20px;
}

.back-button {
    display: inline-flex;
    align-items: center;
    padding: 8px 16px;
    background: var(--accent);
    color: white;
    text-decoration: none;
    border-radius: var(--radius-sm);
    font-weight: 500;
    transition: all 0.25s ease;
    font-size: 14px;
}

.back-button:hover {
    background: var(--accent-hover);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(234, 88, 12, 0.25);
}

/* ── FAQ Section ── */
.faq-section {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    padding: 32px;
    border: 1px solid var(--border);
    box-shadow: var(--shadow-lg);
    margin-top: 32px;
    animation: fadeUp 0.6s ease-out both;
    animation-delay: 0.25s;
}

body.dark .faq-section {
    background: var(--bg-card);
    border-color: var(--border);
    box-shadow: var(--shadow-lg);
}

.faq-section h2 {
    font-family: var(--font-display);
    font-size: 2rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 8px;
}

body.dark .faq-section h2 {
    color: var(--text-primary);
}

.faq-section .intro {
    color: var(--text-secondary);
    font-size: 1rem;
    margin-bottom: 20px;
}

.faq-section .intro a {
    color: var(--accent);
    text-decoration: none;
}

.faq-section .intro a:hover {
    text-decoration: underline;
    color: var(--accent-hover);
}

body.dark .faq-section .intro {
    color: var(--text-secondary);
}

/* ── Trending Themes Grid ── */
.trending-themes-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 10px;
}

.trending-theme-link {
    display: block;
    padding: 12px 16px;
    background: var(--bg-card);
    border: 1.5px solid var(--border);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    text-decoration: none;
    font-weight: 500;
    font-size: 0.95rem;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.trending-theme-link:hover {
    border-color: var(--accent-border);
    box-shadow: var(--shadow-md);
}

body.dark .trending-theme-link {
    background: var(--bg-card);
    border-color: var(--border);
}

body.dark .trending-theme-link:hover {
    border-color: var(--accent-border);
}

.faq-list {
    display: grid;
    gap: 10px;
}

.faq-item {
    border: 1.5px solid var(--border);
    border-radius: var(--radius-md);
    overflow: hidden;
    background: var(--bg-card);
    transition: border-color 0.2s ease;
}

body.dark .faq-item {
    border-color: var(--border);
    background: var(--bg-card);
}

.faq-item[open] {
    border-color: var(--accent-border);
}

body.dark .faq-item[open] {
    border-color: var(--accent-border);
}

.faq-item summary {
    list-style: none;
    cursor: pointer;
    padding: 14px 16px;
    font-weight: 600;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    justify-content: space-between;
    transition: background 0.2s ease;
    font-size: 0.95rem;
}

body.dark .faq-item summary {
    color: var(--text-primary);
}

.faq-item summary h3 {
    font-size: inherit;
    font-weight: inherit;
    margin: 0;
    color: inherit;
}

.faq-item summary::-webkit-details-marker {
    display: none;
}

.faq-item .chevron {
    color: var(--text-muted);
    transition: transform 0.25s ease;
    font-size: 1.2rem;
}

.faq-item[open] .chevron {
    transform: rotate(180deg);
}

.faq-item summary:hover {
    background: var(--accent-light);
}

body.dark .faq-item summary:hover {
    background: var(--accent-light);
}

.faq-item .answer {
    padding: 0 16px 16px 16px;
    margin: 0;
    color: var(--text-secondary);
    line-height: 1.6;
}

body.dark .faq-item .answer {
    color: var(--text-secondary);
}

/* ── Grid Comparison Table ── */
.grid-comparison-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 8px;
    font-family: var(--font-body);
    font-size: 0.95rem;
}

.grid-comparison-table th,
.grid-comparison-table td {
    padding: 12px 16px;
    text-align: left;
    border-bottom: 1px solid var(--border);
    color: var(--text-primary);
}

.grid-comparison-table th {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
}

.grid-comparison-table tbody tr:hover {
    background: var(--accent-light);
}

body.dark .grid-comparison-table th {
    color: var(--text-muted);
}

body.dark .grid-comparison-table td {
    color: var(--text-primary);
    border-bottom-color: var(--border);
}

body.dark .grid-comparison-table tbody tr:hover {
    background: var(--accent-light);
}

/* ── Site Footer ── */
.site-footer {
    text-align: center;
    padding: 32px 16px;
    margin-top: 40px;
    border-top: 1px solid var(--border);
    color: var(--text-muted);
    font-size: 0.88rem;
    line-height: 1.6;
}

.site-footer a {
    color: var(--accent);
    text-decoration: none;
}

.site-footer a:hover {
    text-decoration: underline;
}

.site-footer p {
    margin: 4px 0;
}

body.dark .site-footer {
    border-top-color: var(--border);
    color: var(--text-muted);
}

body.dark .site-footer a {
    color: var(--accent);
}

/* ── Theme Description ── */
.theme-description {
    max-width: 800px;
    margin: 32px auto 0 auto;
    padding: 0 16px;
}

.theme-description p {
    color: var(--text-secondary);
    font-size: 0.95rem;
    line-height: 1.7;
    text-align: center;
}

.theme-description a {
    color: var(--accent);
    text-decoration: none;
}

.theme-description a:hover {
    text-decoration: underline;
}

body.dark .theme-description p {
    color: var(--text-secondary);
}

body.dark .theme-description a {
    color: var(--accent);
}

.theme-description h2,
.theme-description h3 {
    color: var(--text-primary);
    font-family: var(--font-display);
    text-align: left;
    margin-top: 24px;
    margin-bottom: 8px;
}

.theme-description h2 {
    font-size: 1.3rem;
    font-weight: 700;
}

.theme-description h3 {
    font-size: 1.05rem;
    font-weight: 600;
}

.theme-description p {
    text-align: left;
}

.word-list-display {
    font-weight: 500;
    color: var(--text-primary) !important;
    line-height: 1.8 !important;
}

/* ── Breadcrumb ── */
.breadcrumb {
    margin-bottom: 16px;
    font-size: 0.88rem;
}

.breadcrumb ol {
    list-style: none;
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    align-items: center;
}

.breadcrumb li {
    display: flex;
    align-items: center;
}

.breadcrumb li + li::before {
    content: "\203A";
    margin-right: 6px;
    color: var(--text-muted);
}

.breadcrumb a {
    color: var(--accent);
    text-decoration: none;
    transition: color 0.2s ease;
}

.breadcrumb a:hover {
    text-decoration: underline;
    color: var(--accent-hover);
}

.breadcrumb [aria-current="page"] {
    color: var(--text-muted);
}

body.dark .breadcrumb a {
    color: var(--accent);
}

body.dark .breadcrumb [aria-current="page"] {
    color: var(--text-muted);
}

body.dark .breadcrumb li + li::before {
    color: var(--text-muted);
}

/* ── SEO Intro ── */
.seo-intro {
    max-width: 800px;
    margin: 0 auto 24px;
    text-align: center;
    line-height: 1.7;
    color: var(--text-secondary);
    font-size: 0.95rem;
}

body.dark .seo-intro {
    color: var(--text-secondary);
}

.seo-intro h2 {
    font-family: var(--font-display);
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--accent);
    margin-bottom: 12px;
}

body.dark .seo-intro h2 {
    color: var(--accent);
}

/* ── Related Themes ── */
.related-themes {
    margin-top: 30px;
    padding-top: 20px;
    border-top: 1px solid var(--border);
}

body.dark .related-themes {
    border-top-color: var(--border);
}

.related-themes h2 {
    font-family: var(--font-display);
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--accent);
    margin-bottom: 16px;
    text-align: center;
}

body.dark .related-themes h2 {
    color: var(--accent);
}

.related-themes-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 12px;
}

.related-theme-card {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px;
    background: var(--bg-subtle);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    text-decoration: none;
    color: inherit;
    transition: all 0.2s ease;
    font-size: 0.9rem;
}

.related-theme-card:hover {
    border-color: var(--accent);
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(234, 88, 12, 0.1);
}

body.dark .related-theme-card {
    background: var(--bg-subtle);
    border-color: var(--border);
}

body.dark .related-theme-card:hover {
    border-color: var(--accent);
}

.related-theme-icon {
    font-size: 1.4rem;
}

/* ── Theme Puzzle Section ── */
.theme-puzzle-section {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    padding: 32px;
    border: 1px solid var(--border);
    box-shadow: var(--shadow-lg);
    margin-bottom: 30px;
    animation: fadeUp 0.6s ease-out both;
    animation-delay: 0.1s;
}

body.dark .theme-puzzle-section {
    background: var(--bg-card);
    border-color: var(--border);
    box-shadow: var(--shadow-lg);
}

.theme-info {
    text-align: center;
    margin-bottom: 30px;
}

.theme-icon {
    font-size: 3rem;
    margin-bottom: 15px;
}

.theme-info h2 {
    font-family: var(--font-display);
    font-size: 2rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 10px;
}

body.dark .theme-info h2 {
    color: var(--text-primary);
}

.theme-info p {
    color: var(--text-secondary);
    font-size: 1.05rem;
}

body.dark .theme-info p {
    color: var(--text-secondary);
}

.theme-actions {
    text-align: center;
    margin-top: 30px;
    padding-top: 20px;
    border-top: 1px solid var(--border);
}

body.dark .theme-actions {
    border-top-color: var(--border);
}

.main-site-link {
    display: inline-flex;
    align-items: center;
    padding: 12px 24px;
    background: linear-gradient(135deg, #ea580c 0%, #c2410c 100%);
    color: white;
    text-decoration: none;
    border-radius: var(--radius-md);
    font-weight: 600;
    transition: all 0.25s ease;
    font-size: 16px;
}

.main-site-link:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(234, 88, 12, 0.35);
}

/* ── Theme Info Section ── */
.theme-info-section {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    padding: 32px;
    border: 1px solid var(--border);
    box-shadow: var(--shadow-lg);
    margin-bottom: 30px;
}

body.dark .theme-info-section {
    background: var(--bg-card);
    border-color: var(--border);
    box-shadow: var(--shadow-lg);
}

.theme-details h3 {
    font-family: var(--font-display);
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 15px;
}

body.dark .theme-details h3 {
    color: var(--text-primary);
}

.theme-details p {
    color: var(--text-secondary);
    line-height: 1.6;
    margin-bottom: 20px;
}

body.dark .theme-details p {
    color: var(--text-secondary);
}

.theme-features h4 {
    font-family: var(--font-display);
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 15px;
}

body.dark .theme-features h4 {
    color: var(--text-primary);
}

.theme-features ul {
    list-style: none;
    padding: 0;
}

.theme-features li {
    color: var(--text-secondary);
    margin-bottom: 8px;
    padding-left: 0;
}

body.dark .theme-features li {
    color: var(--text-secondary);
}

/* ── Mobile Theme/Showcase ── */
@media (max-width: 768px) {
    .themes-showcase {
        padding: 24px;
    }

    .themes-showcase h2 {
        font-size: 1.5rem;
    }

    .themes-grid {
        grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
        gap: 12px;
    }

    .theme-card {
        padding: 16px;
    }

    .theme-card-icon {
        font-size: 2rem;
    }

    .theme-card-name {
        font-size: 0.95rem;
    }

    .theme-card-description {
        font-size: 0.8rem;
    }

    .theme-puzzle-section,
    .theme-info-section {
        padding: 24px;
    }

    .theme-icon {
        font-size: 2.5rem;
    }

    .theme-info h2 {
        font-size: 1.5rem;
    }

    .back-button,
    .main-site-link {
        width: 100%;
        justify-content: center;
    }
}

/* ── Mobile: Puzzle Grid Scaling ── */
/* Ensure the puzzle grid never overflows the screen */
.puzzle-container {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

@media (max-width: 768px) {
    .puzzle-grid-wrapper {
        width: 100%;
        display: flex;
        justify-content: center;
    }

    .puzzle-grid {
        max-width: 100%;
    }
}

/* Scale grid cells to fit on small screens */
@media (max-width: 520px) {
    .grid-cell {
        width: 16px;
        height: 16px;
        font-size: 13px;
    }
}

@media (max-width: 400px) {
    .grid-cell {
        width: 14px;
        height: 14px;
        font-size: 11px;
    }
}

/* ── Mobile: Small Screen Refinements (< 480px) ── */
@media (max-width: 480px) {
    .container {
        padding: 16px;
    }

    header h1, .hero h1 {
        font-size: 1.6rem;
    }

    header p, .hero p {
        font-size: 1rem;
    }

    .input-panel,
    .puzzle-panel {
        padding: 16px;
    }

    .theme-puzzle-section,
    .theme-info-section {
        padding: 16px;
    }

    .faq-section {
        padding: 20px;
    }

    .faq-section h2 {
        font-size: 1.4rem;
    }

    .themes-showcase {
        padding: 16px;
    }

    .themes-showcase h2 {
        font-size: 1.3rem;
    }

    .theme-description {
        padding: 0 8px;
    }

    .puzzle-actions {
        gap: 8px;
    }

    .download-btn,
    .print-btn,
    .secondary-btn {
        padding: 12px 16px;
        font-size: 0.88rem;
        width: 100%;
    }

    .generate-btn {
        padding: 14px;
        font-size: 1rem;
    }

    .trending-themes-grid {
        grid-template-columns: 1fr;
        gap: 8px;
    }

    .related-themes-grid {
        grid-template-columns: 1fr 1fr;
        gap: 8px;
    }

    .themes-grid {
        grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
        gap: 10px;
    }
}

/* ── Mobile: Footer Link Wrapping ── */
@media (max-width: 600px) {
    .site-footer p:first-child {
        display: flex;
        flex-wrap: wrap;
        justify-content: center;
        gap: 4px 0;
        line-height: 2;
    }
}

/* ── Touch Target Minimum Sizes ── */
@media (hover: none) and (pointer: coarse) {
    .tab {
        padding: 10px 16px;
        min-height: 44px;
        display: inline-flex;
        align-items: center;
    }

    .trending-theme-link {
        min-height: 48px;
        display: flex;
        align-items: center;
    }

    .related-theme-card {
        min-height: 48px;
    }

    .breadcrumb a {
        padding: 4px 0;
        min-height: 44px;
        display: inline-flex;
        align-items: center;
    }

    .faq-item summary {
        min-height: 48px;
    }

    .size-selector-container select {
        min-height: 44px;
        padding: 8px 12px;
    }
}
