@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&display=swap');

/* Theme Variables */
:root {
    --bg-gradient: radial-gradient(circle at top right, rgba(107, 216, 203, 0.15) 0%, #0b1326 60%);
    --card-bg: rgba(23, 31, 51, 0.65);
    --card-bg-solid: #171f33;
    --text-primary: #dae2fd;
    --text-secondary: #bcc9c6;
    --text-muted: #879391;
    --border-color: rgba(255, 255, 255, 0.1);
    --input-bg: rgba(6, 14, 32, 0.8);
    --accent: #6bd8cb;
    --accent-dark: #29a195;
    --highlight-bg: rgba(107, 216, 203, 0.15);
    --focus-bg: rgba(107, 216, 203, 0.25);
    --correct-bg: rgba(107, 216, 203, 0.15);
    --correct-text: #89f5e7;
    --incorrect-bg: rgba(255, 180, 171, 0.15);
    --incorrect-text: #ffb4ab;
    --shadow-sm: 0 2px 8px rgba(0,0,0,0.4);
    --shadow-md: 0 4px 15px rgba(0,0,0,0.5);
    --shadow-lg: 0 10px 32px rgba(0,0,0,0.6);
    --shadow-xl: 0 20px 40px rgba(0,0,0,0.7);
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 24px;
    --transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--bg-gradient);
    background-attachment: fixed;
    color: var(--text-primary);
    min-height: 100vh;
    line-height: 1.6;
    transition: background var(--transition), color var(--transition);
}

/* Animations */
@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}
@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}
@keyframes confetti-fall {
    0% { transform: translateY(-100vh) rotate(0deg); opacity: 1; }
    100% { transform: translateY(100vh) rotate(720deg); opacity: 0; }
}
@keyframes float {
    0%, 100% { transform: translateY(0) scale(1); }
    50% { transform: translateY(-20px) scale(1.05); }
}

/* Ambient Background Blobs */
.ambient-blobs {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    z-index: -1;
    overflow: hidden;
    pointer-events: none;
}
.blob {
    position: absolute;
    filter: blur(80px);
    opacity: 0.5;
    animation: float 10s ease-in-out infinite;
}
.blob-1 {
    top: -10%; left: -10%;
    width: 50vw; height: 50vw;
    background: radial-gradient(circle, rgba(107, 216, 203, 0.4), transparent 70%);
    animation-delay: 0s;
}
.blob-2 {
    bottom: -20%; right: -10%;
    width: 60vw; height: 60vw;
    background: radial-gradient(circle, rgba(41, 161, 149, 0.3), transparent 70%);
    animation-delay: -5s;
}

/* ============================================= */
/* HOMEPAGE STYLES */
/* ============================================= */
#homepage {
    min-height: 100vh;
}

/* Top Navigation */
.top-nav {
    position: sticky;
    top: 0;
    z-index: 1000;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 2rem;
    background: rgba(11, 19, 38, 0.8);
    backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--border-color);
}
.nav-brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-primary);
}
.nav-brand .brand-icon {
    color: var(--accent);
}
.nav-actions {
    display: flex;
    gap: 1rem;
}
.btn-outline {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background: transparent;
    color: var(--text-primary);
    text-decoration: none;
    font-weight: 500;
    transition: var(--transition);
}
.btn-outline:hover {
    background: rgba(255, 255, 255, 0.05);
    border-color: rgba(255, 255, 255, 0.2);
}

/* Hero Section */
.hero-section {
    padding: 6rem 2rem;
    text-align: center;
    animation: fadeInUp 0.8s ease;
    position: relative;
    overflow: hidden;
}
.hero-section::before {
    content: '';
    position: absolute;
    inset: 0;
    z-index: -1;
    opacity: 0.35;
    mix-blend-mode: overlay;
    background: url('https://lh3.googleusercontent.com/aida-public/AB6AXuDVAgunlx1dWHwPmbUHdZDEVt8p-SSzL4RlydzPk-56-uEgTZkW7ysjWH9yeCAxqimqfBolFL9cv7J6gbd2lGazt4A7N0FEgGdGoAEuMpHLgm7FAyVIjjSN7TJY4ShEvUoOfMA2Y8WNOuxgcydU3Zv0M3MTh8b6lPB_70fyZ-FBDRVoEg2kKKVoPnqJu0kIwTZny07A6ks0SM7QEpujw2T0rvNqizZS87EzjUQqS_lb0M3MMY4Ziq0n5HBjjhLSSNVWm0f-KfHa4vLz') center/cover no-repeat;
    pointer-events: none;
}
.hero-badge {
    display: inline-block;
    padding: 0.25rem 0.75rem;
    background: rgba(107, 216, 203, 0.1);
    color: var(--accent);
    border: 1px solid rgba(107, 216, 203, 0.2);
    border-radius: 20px;
    font-size: 0.875rem;
    font-weight: 600;
    margin-bottom: 1.5rem;
    letter-spacing: 0.05em;
    text-transform: uppercase;
}
.hero-title {
    font-size: 4rem;
    color: var(--text-primary);
    margin-bottom: 1rem;
    font-weight: 800;
    letter-spacing: -0.03em;
    line-height: 1.1;
}
.text-gradient {
    background: linear-gradient(135deg, #89f5e7, #29a195);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}
.hero-subtitle {
    font-size: 1.25rem;
    color: var(--text-muted);
    font-weight: 400;
    max-width: 600px;
    margin: 0 auto;
}

/* Container */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 2rem;
}

/* Section Styles */
section {
    background: var(--card-bg);
    backdrop-filter: blur(16px);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-xl);
    padding: 2rem;
    margin-bottom: 2rem;
    box-shadow: var(--shadow-lg);
    animation: fadeInUp 0.6s ease both;
}
section:nth-child(2) { animation-delay: 0.1s; }
section:nth-child(3) { animation-delay: 0.2s; }

section h2 {
    color: var(--text-primary);
    margin-bottom: 1.5rem;
    text-align: center;
    font-size: 2rem;
    font-weight: 700;
}

/* Category Grid */
.category-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1.5rem;
}

.category-card {
    background: var(--accent);
    background: linear-gradient(135deg, var(--accent), var(--accent-dark));
    color: white;
    padding: 2rem 1.5rem;
    border-radius: 15px;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
    border: 0;
    font: inherit;
}

.category-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255,255,255,0.1);
    opacity: 0;
    transition: opacity 0.3s ease;
}

.category-card:hover::before {
    opacity: 1;
}

.category-card:hover {
    transform: translateY(-5px) scale(1.02);
    box-shadow: 0 15px 30px rgba(0,0,0,0.2), inset 0 1px 1px rgba(255,255,255,0.2);
}

.category-icon {
    font-size: 3rem;
    margin-bottom: 1rem;
}

.category-card h3 {
    font-size: 1.5rem;
    margin-bottom: 0.5rem;
}

.category-card p {
    opacity: 0.9;
    margin-bottom: 1rem;
    font-size: 0.9rem;
}

.puzzle-count {
    background: rgba(255,255,255,0.2);
    padding: 0.3rem 0.8rem;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 600;
}

/* Difficulty Grid */
.difficulty-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1.5rem;
}

.difficulty-card {
    background: var(--card-bg-solid);
    border: 2px solid var(--border-color);
    padding: 1.5rem;
    border-radius: var(--radius-lg);
    text-align: center;
    cursor: pointer;
    transition: all 0.3s ease;
    font: inherit;
}

.difficulty-card:hover {
    border-color: var(--accent);
    transform: translateY(-3px);
    box-shadow: 0 10px 25px rgba(0,0,0,0.1);
}

.difficulty-card h3 {
    color: var(--text-primary);
    margin-bottom: 0.5rem;
}

.difficulty-card p {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-bottom: 1rem;
}

.difficulty-stars {
    font-size: 1.5rem;
    color: #ffd700;
}

/* Puzzles Section */
.puzzles-filter {
    display: flex;
    gap: 1rem;
    margin-bottom: 2rem;
    justify-content: center;
    flex-wrap: wrap;
}

.puzzles-filter select {
    padding: 0.8rem 1.5rem;
    border: 2px solid var(--border-color);
    border-radius: var(--radius-md);
    background: var(--card-bg-solid);
    color: var(--text-primary);
    font-size: 1rem;
    cursor: pointer;
    transition: border-color 0.3s ease;
}

.puzzles-filter select:focus {
    outline: none;
    border-color: var(--accent);
}

.puzzles-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 1.5rem;
}

.puzzle-card {
    background: rgba(23, 31, 51, 0.7);
    border: 1px solid rgba(61, 73, 71, 0.3);
    border-radius: var(--radius-xl);
    padding: 1.5rem;
    cursor: pointer;
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    animation: fadeInUp 0.5s ease both;
    backdrop-filter: blur(20px);
    overflow: hidden;
}

.puzzle-card:hover {
    border-color: var(--accent);
    transform: translateY(-5px) scale(1.02);
    box-shadow: 0 15px 30px rgba(0,0,0,0.2), inset 0 1px 1px rgba(255,255,255,0.15);
}

.puzzle-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 1rem;
}

.puzzle-title {
    font-size: 1.2rem;
    color: var(--text-primary);
    margin-bottom: 0.5rem;
    flex: 1;
}

.puzzle-difficulty {
    background: var(--accent);
    color: white;
    padding: 0.3rem 0.8rem;
    border-radius: 15px;
    font-size: 0.8rem;
    font-weight: 600;
}

.puzzle-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    font-size: 0.9rem;
    color: #7f8c8d;
}

.puzzle-category {
    background: #f8f9fa;
    padding: 0.2rem 0.6rem;
    border-radius: 10px;
    font-weight: 600;
}

.puzzle-stats {
    display: flex;
    gap: 1rem;
}

.puzzle-description {
    color: var(--text-secondary);
    line-height: 1.5;
    margin-bottom: 1rem;
}

.puzzle-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.start-button {
    background: var(--accent);
    background: linear-gradient(135deg, var(--accent), var(--accent-dark));
    color: white;
    border: none;
    padding: 0.8rem 1.5rem;
    border-radius: 10px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
}

.start-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(102, 126, 234, 0.4);
}

.puzzle-size {
    font-size: 0.85rem;
    color: #7f8c8d;
}

/* Active States */
.category-card.active,
.difficulty-card.active {
    border: 3px solid var(--accent);
    background: var(--accent);
    background: linear-gradient(135deg, var(--accent), var(--accent-dark));
    color: white;
}

.difficulty-card.active h3,
.difficulty-card.active p {
    color: white;
}

/* ============================================= */
/* PUZZLE PAGE STYLES */
/* ============================================= */
#app-container {
    display: flex;
    gap: 40px;
    max-width: 1400px;
    margin: 0 auto;
    padding: 20px;
    align-items: flex-start;
}

#puzzle-container {
    flex: 1;
    min-width: 0;       /* Prevents flex item from overflowing */
    overflow-x: auto;   /* Scroll fallback if a very large grid still can't fit */
}

#puzzle-header {
    background: var(--card-bg);
    backdrop-filter: blur(16px);
    border: 1px solid var(--border-color);
    padding: 1.5rem;
    border-radius: var(--radius-lg);
    margin-bottom: 20px;
    box-shadow: var(--shadow-md);
    text-align: left;
}

#back-button {
    background: #6c757d;
    color: white;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: 5px;
    cursor: pointer;
    margin-bottom: 1rem;
    font-size: 14px;
    transition: background-color 0.2s;
}

#back-button:hover {
    background: #5a6268;
}

#puzzle-title {
    color: var(--text-primary);
    margin-bottom: 0.5rem;
    font-size: 2rem;
    font-weight: 700;
}

#puzzle-info {
    display: flex;
    gap: 1rem;
    font-size: 0.9rem;
    color: #6c757d;
}

#puzzle-info span {
    background: var(--input-bg);
    padding: 0.3rem 0.8rem;
    border-radius: var(--radius-lg);
    font-weight: 600;
    color: var(--text-secondary);
}

/* Crossword Grid Styles */
#crossword-grid {
    display: grid;
    border: 2px solid var(--border-color);
    margin-bottom: 20px;
    width: fit-content;
    height: fit-content;
    margin-left: auto;
    margin-right: auto;
    background: var(--card-bg-solid);
    box-shadow: var(--shadow-md);
    border-radius: var(--radius-sm);
    overflow: hidden;
}

.grid-cell, .black-cell {
    width: var(--cell-size, 40px);
    height: var(--cell-size, 40px);
    border: 1px solid #ccc;
    box-sizing: border-box;
    position: relative;
    /* ✅ Add these three lines */
    display: flex;
    align-items: center;
    justify-content: center;
}

.black-cell {
    background-color: #2c3e50;
}

.grid-cell input {
    width: 100%;
    height: 100%;
    border: none;
    text-align: center;
    font-size: var(--cell-font-size, 20px);
    font-weight: bold;
    text-transform: uppercase;
    padding: 0; /* ✅ Ensures no extra spacing */
    background-color: transparent;
    box-sizing: border-box;
    font-family: inherit;
}

.grid-cell input:focus {
    outline: none;
    background-color: var(--focus-bg);
}

/* Highlighting styles */
.grid-cell.highlighted {
    background-color: var(--highlight-bg);
}

.grid-cell.focused {
    background-color: var(--focus-bg);
}

/* Validation styles */
.grid-cell.correct input {
    background-color: var(--correct-bg);
    color: var(--correct-text);
}
.grid-cell.incorrect input {
    background-color: var(--incorrect-bg);
    color: var(--incorrect-text);
}

/* Puzzle Controls Styling */
#puzzle-controls {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 15px;
    margin-bottom: 20px;
    flex-wrap: wrap;
    background: var(--card-bg);
    padding: 1.5rem;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
}

#check-button, #reveal-button, #apply-action {
    padding: 10px 20px;
    font-size: 16px;
    cursor: pointer;
    border: none;
    border-radius: 5px;
    transition: all 0.2s;
    font-weight: bold;
}

#check-button {
    background-color: #007bff;
    color: white;
}

#check-button:hover {
    background-color: #0056b3;
    transform: translateY(-2px);
}

#reveal-button {
    background-color: #dc3545;
    color: white;
}

#reveal-button:hover {
    background-color: #c82333;
    transform: translateY(-2px);
}

#reveal-button:disabled {
    background-color: #6c757d;
    cursor: not-allowed;
    transform: none;
}

#apply-action {
    background-color: #28a745;
    color: white;
}

#apply-action:hover {
    background-color: #218838;
    transform: translateY(-2px);
}

/* Action Menu Styles */
#action-menu-container {
    display: flex;
    gap: 8px;
    align-items: center;
}

#action-select {
    padding: 10px 15px;
    font-size: 14px;
    border: 1px solid #ced4da;
    border-radius: 5px;
    background-color: white;
    min-width: 180px;
    cursor: pointer;
}

#action-select:focus {
    outline: none;
    border-color: #007bff;
    box-shadow: 0 0 0 2px rgba(0, 123, 255, 0.25);
}

#timer {
    font-size: 18px;
    font-weight: bold;
    color: #2c3e50;
    padding: 8px 16px;
    background-color: #f8f9fa;
    border-radius: 5px;
    border: 1px solid #dee2e6;
    min-width: 100px;
    text-align: center;
}

/* ============================================= */
/* SIDE-BY-SIDE CLUES LAYOUT */
/* ============================================= */
#clues-container {
    width: 340px;        /* Narrower so the grid gets more room */
    flex-shrink: 0;      /* Never squeeze clues — grid shrinks to fit instead */
    background: var(--card-bg);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    display: flex;
    flex-direction: column;
    max-height: 80vh;
}

.clues-header {
    padding: 1.5rem 1.5rem 0.5rem;
    border-bottom: 2px solid #007bff;
}

.clues-header h2 {
    color: var(--text-primary);
    margin: 0;
    font-size: 1.5rem;
}

.clues-content {
    display: flex;
    flex: 1;
    overflow: hidden;
}

.clue-column {
    flex: 1;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    min-height: 0; /* Important for flex scrolling */
}

.clue-column:first-child {
    border-right: 1px solid #e9ecef;
}

.clue-column-title {
    color: var(--text-primary);
    margin-bottom: 1rem;
    font-size: 1.2rem;
    text-align: center;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid #dee2e6;
}

.clues-list {
    list-style: none;
    padding: 0;
    margin: 0;
    overflow-y: auto;
    flex: 1;
}

.clues-list li {
    margin-bottom: 12px;
    line-height: 1.5;
    padding: 10px;
    border-radius: 8px;
    transition: all 0.2s;
    cursor: pointer;
    border: 1px solid transparent;
}

.clues-list li:hover {
    background-color: #e9ecef;
    transform: translateX(2px);
}

.clue-active {
    background-color: #fff3cd !important;
    border-color: #ffc107;
    font-weight: bold;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.clue-number {
    position: absolute; /* Lifts the number out of the layout */
    top: 1px;           /* Pushes it to the top */
    left: 2px;          /* Pushes it to the left */
    font-size: 10px;
    color: #6c757d;     /* A softer grey color */
    font-weight: bold;
    user-select: none;
}

/* Revealed letter styling */
.grid-cell.revealed {
    background-color: #e7f3ff;
}

.grid-cell.revealed input {
    color: #0056b3;
    font-weight: bold;
}

/* No puzzles message */
.no-puzzles {
    grid-column: 1 / -1;
    text-align: center;
    padding: 2rem;
    background: white;
    border-radius: 15px;
}

/* ============================================= */
/* RESPONSIVE DESIGN */
/* ============================================= */
@media (max-width: 979px) {
    #app-container {
        flex-direction: column;
        gap: 20px;
        max-width: 800px;
        align-items: stretch; /* children fill full width in column mode */
    }

    #puzzle-container {
        width: 100%;
    }

    #clues-container {
        width: 100%;
        max-height: none;
    }
    
    .clues-content {
        max-height: 300px;
    }
}

@media (max-width: 768px) {
    .container {
        padding: 1rem;
    }
    
    .main-header h1 {
        font-size: 2rem;
    }
    
    .category-grid {
        grid-template-columns: 1fr;
    }
    
    .difficulty-grid {
        grid-template-columns: 1fr;
    }
    
    .puzzles-grid {
        grid-template-columns: 1fr;
    }
    
    .puzzles-filter {
        flex-direction: column;
    }
    
    .puzzles-filter select {
        width: 100%;
    }
    
    /* Puzzle page responsive */
    #app-container {
        padding: 10px;
        gap: 15px;
    }
    
    #puzzle-controls {
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
    }
    
    #action-menu-container {
        justify-content: center;
    }
    
    .clues-content {
        flex-direction: column;
        max-height: 400px;
    }
    
    .clue-column:first-child {
        border-right: none;
        border-bottom: 1px solid #e9ecef;
    }
    
    .clue-column {
        min-height: 200px;
    }
}

@media (max-width: 480px) {
    #puzzle-title {
        font-size: 1.5rem;
    }
    
    .clues-header h2 {
        font-size: 1.3rem;
    }
    
    .clue-column-title {
        font-size: 1.1rem;
    }
}

/* ============================================= */
/* CONGRATULATIONS MODAL */
/* ============================================= */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(8px);
    z-index: 2000;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.3s ease;
}
.modal-overlay.active { display: flex; }

.modal-content {
    background: var(--card-bg-solid);
    border-radius: var(--radius-xl);
    padding: 3rem;
    text-align: center;
    max-width: 480px;
    width: 90%;
    box-shadow: var(--shadow-xl);
    animation: fadeInUp 0.4s ease;
    position: relative;
    overflow: hidden;
}
.modal-content::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 4px;
    background: linear-gradient(90deg, var(--accent), var(--accent-dark), #f093fb);
}
.modal-emoji { font-size: 4rem; margin-bottom: 1rem; }
.modal-title { font-size: 1.8rem; font-weight: 800; color: var(--text-primary); margin-bottom: 0.5rem; }
.modal-subtitle { color: var(--text-muted); font-size: 1rem; margin-bottom: 1.5rem; }
.modal-time { font-size: 2.5rem; font-weight: 800; color: var(--accent); margin-bottom: 0.5rem; }
.modal-time-label { color: var(--text-muted); font-size: 0.85rem; margin-bottom: 2rem; }
.modal-actions { display: flex; gap: 1rem; justify-content: center; flex-wrap: wrap; }
.modal-btn {
    padding: 0.8rem 1.8rem;
    border: none;
    border-radius: var(--radius-md);
    font-weight: 600;
    font-size: 1rem;
    cursor: pointer;
    transition: all var(--transition);
    font-family: inherit;
}
.modal-btn-primary {
    background: linear-gradient(135deg, var(--accent), var(--accent-dark));
    color: white;
}
.modal-btn-primary:hover { transform: translateY(-2px); box-shadow: 0 5px 20px rgba(102,126,234,0.4); }
.modal-btn-secondary {
    background: var(--input-bg);
    color: var(--text-primary);
    border: 2px solid var(--border-color);
}
.modal-btn-secondary:hover { border-color: var(--accent); }

/* Confetti pieces */
.confetti-piece {
    position: fixed;
    width: 10px;
    height: 10px;
    top: -10px;
    z-index: 2001;
    animation: confetti-fall 3s linear forwards;
    border-radius: 2px;
}

/* ============================================= */
/* PROGRESS BAR */
/* ============================================= */
.progress-bar-container {
    background: var(--card-bg);
    border-radius: var(--radius-lg);
    padding: 1rem 1.5rem;
    margin-bottom: 20px;
    box-shadow: var(--shadow-md);
    display: flex;
    align-items: center;
    gap: 1rem;
}
.progress-bar-track {
    flex: 1;
    height: 8px;
    background: var(--input-bg);
    border-radius: 4px;
    overflow: hidden;
}
.progress-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--accent), var(--accent-dark));
    border-radius: 4px;
    transition: width 0.4s ease;
    width: 0%;
}
.progress-bar-text {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary);
    min-width: 45px;
    text-align: right;
}

/* ============================================= */
/* STATS DASHBOARD */
/* ============================================= */
.stats-bar {
    display: flex;
    gap: 1.5rem;
    justify-content: center;
    flex-wrap: wrap;
    padding: 1.5rem;
    animation: fadeInUp 0.5s ease both;
}
.stat-item {
    text-align: center;
    min-width: 100px;
}
.stat-value {
    font-size: 2rem;
    font-weight: 800;
    color: var(--accent);
}
.stat-label {
    font-size: 0.8rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 600;
}

/* ============================================= */
/* SEARCH BAR */
/* ============================================= */
.search-container {
    display: flex;
    justify-content: center;
    margin-bottom: 1.5rem;
}
.search-input {
    width: 100%;
    max-width: 500px;
    padding: 0.8rem 1.5rem;
    border: 2px solid var(--border-color);
    border-radius: var(--radius-md);
    background: var(--card-bg-solid);
    color: var(--text-primary);
    font-size: 1rem;
    font-family: inherit;
    transition: border-color var(--transition);
}
.search-input:focus {
    outline: none;
    border-color: var(--accent);
}
.search-input::placeholder { color: var(--text-muted); }

/* ============================================= */
/* COMPLETION BADGE */
/* ============================================= */
.completion-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 0.2rem 0.6rem;
    border-radius: var(--radius-sm);
    font-size: 0.75rem;
    font-weight: 600;
}
.completion-badge.completed {
    background: var(--correct-bg);
    color: var(--correct-text);
}
.completion-badge.in-progress {
    background: #fff3cd;
    color: #856404;
}

/* ============================================= */
/* LOADING SPINNER */
/* ============================================= */
.loading-spinner {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 4rem;
    gap: 1rem;
}
.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid var(--border-color);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}
@keyframes spin {
    to { transform: rotate(360deg); }
}
.loading-text {
    color: var(--text-muted);
    font-weight: 500;
}

/* Hint counter */
.hint-counter {
    font-size: 0.85rem;
    color: var(--text-muted);
    font-weight: 600;
}

/* ============================================================
   Pencil mode
   ============================================================ */
.pencil-button {
    padding: 10px 20px;
    font-size: 16px;
    cursor: pointer;
    border: 2px solid var(--border-color);
    border-radius: 5px;
    font-weight: bold;
    background: var(--input-bg);
    color: var(--text-primary);
    transition: all 0.2s;
}
.pencil-button.active {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent-dark);
}
.grid-cell.pencil input {
    color: var(--text-muted);
    font-style: italic;
    opacity: 0.75;
}

/* Auto-check toggle — matches pencil-button styling */
.autocheck-button {
    padding: 10px 20px;
    font-size: 16px;
    cursor: pointer;
    border: 2px solid var(--border-color);
    border-radius: 5px;
    font-weight: bold;
    background: var(--input-bg);
    color: var(--text-primary);
    transition: all 0.2s;
}
.autocheck-button.active {
    background: #28a745;
    color: #fff;
    border-color: #1e7e34;
}

/* ============================================================
   Active clue banner (sticky above grid; key on mobile)
   ============================================================ */
.active-clue-banner {
    display: flex;
    align-items: baseline;
    gap: 0.6rem;
    position: sticky;
    top: 0;
    z-index: 20;
    margin: 0 0 0.75rem;
    padding: 0.7rem 1rem;
    background: var(--accent);
    color: #fff;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    line-height: 1.35;
}
.active-clue-banner[hidden] { display: none; }
.active-clue-dir {
    flex: none;
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 0.15rem 0.45rem;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.22);
}
.active-clue-text {
    font-size: 0.98rem;
    font-weight: 600;
}

/* ============================================================
   Stats link (floating, next to theme toggle)
   ============================================================ */
.stats-link {
    position: fixed;
    top: 20px;
    right: 76px;
    z-index: 100;
    background: var(--card-bg);
    color: var(--text-primary);
    text-decoration: none;
    padding: 10px 16px;
    border-radius: var(--radius-md);
    font-size: 0.85rem;
    font-weight: 700;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color);
    transition: transform var(--transition);
}
.stats-link:hover { transform: translateY(-2px); }

/* ============================================================
   Daily puzzle card
   ============================================================ */
.daily-section { margin-bottom: 2rem; }
.daily-card {
    display: flex;
    align-items: center;
    gap: 1.25rem;
    padding: 1.5rem 1.75rem;
    border-radius: var(--radius-xl);
    color: #fff;
    box-shadow: var(--shadow-lg);
    position: relative;
    flex-wrap: wrap;
}
.daily-badge {
    position: absolute;
    top: 14px;
    left: 18px;
    font-size: 0.72rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    background: rgba(255,255,255,0.25);
    padding: 4px 10px;
    border-radius: 999px;
}
.daily-icon { font-size: 3rem; line-height: 1; margin-top: 1rem; }
.daily-info { flex: 1; min-width: 200px; margin-top: 1rem; }
.daily-info h3 { font-size: 1.4rem; margin: 0 0 0.25rem; }
.daily-info p { margin: 0; opacity: 0.9; font-size: 0.9rem; }
.daily-start {
    margin-top: 1rem;
    background: #fff;
    color: var(--accent-dark);
    border: none;
    padding: 12px 24px;
    border-radius: var(--radius-md);
    font-weight: 800;
    font-size: 1rem;
    cursor: pointer;
    transition: transform var(--transition);
}
.daily-start:hover { transform: scale(1.05); }
.daily-card.done { filter: saturate(0.85); }

/* ============================================================
   Custom notes puzzle creator
   ============================================================ */
.notes-create-section { margin-bottom: 1.5rem; }
.notes-create-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-left: 5px solid #1abc9c;
    border-radius: var(--radius-lg);
    padding: 1.1rem 1.25rem;
    box-shadow: var(--shadow-sm);
}
.notes-kicker {
    color: #168f78;
    font-size: 0.72rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}
.notes-create-card h2 { margin: 0.15rem 0; color: var(--text-primary); font-size: 1.25rem; }
.notes-create-card p { margin: 0; color: var(--text-secondary); font-size: 0.9rem; }
.notes-create-btn {
    border: none;
    background: #1b1b1b;
    color: #fff;
    border-radius: var(--radius-md);
    padding: 11px 18px;
    font-weight: 800;
    cursor: pointer;
    white-space: nowrap;
}
.notes-create-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.notes-modal {
    position: fixed;
    inset: 0;
    z-index: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0,0,0,0.45);
    padding: 1rem;
}
.notes-modal-content {
    width: min(720px, 96vw);
    background: var(--card-bg-solid);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-lg);
    padding: 1rem;
}
.notes-modal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 0.75rem; }
.notes-modal-header h3 { margin: 0; color: var(--text-primary); }
#notes-close {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    border: 1px solid var(--border-color);
    background: var(--input-bg);
    color: var(--text-primary);
    cursor: pointer;
}
.creator-tabs {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 0.8rem;
}
.creator-tab {
    border: 1px solid var(--border-color);
    background: var(--input-bg);
    color: var(--text-primary);
    border-radius: var(--radius-md);
    padding: 0.55rem 0.9rem;
    font-weight: 800;
    cursor: pointer;
}
.creator-tab.active {
    background: #1b1b1b;
    border-color: #1b1b1b;
    color: #fff;
}
.api-panel {
    display: grid;
    gap: 0.55rem;
}
.creator-label {
    color: var(--text-primary);
    font-size: 0.82rem;
    font-weight: 800;
}
.creator-select,
.creator-input {
    width: 100%;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background: var(--input-bg);
    color: var(--text-primary);
    padding: 0.72rem 0.8rem;
    font: inherit;
    box-sizing: border-box;
}
.creator-help {
    margin: 0.25rem 0 0;
    color: var(--text-secondary);
    font-size: 0.82rem;
    line-height: 1.4;
}

/* Controls Bar and Wrappers */
.controls-bar {
    display: flex;
    gap: 1rem;
    margin-bottom: 2rem;
    align-items: center;
    flex-wrap: wrap;
}

.search-wrapper {
    position: relative;
    flex: 1;
    min-width: 300px;
}
.search-wrapper .search-icon {
    position: absolute;
    left: 1rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    width: 20px;
    height: 20px;
}

.select-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}
.select-wrapper .select-icon {
    position: absolute;
    right: 1rem;
    color: var(--text-muted);
    pointer-events: none;
    width: 16px;
    height: 16px;
}

.search-input {
    width: 100%;
    padding: 1rem 1rem 1rem 3rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    font-size: 1rem;
    background: var(--input-bg);
    color: var(--text-primary);
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.1);
    transition: var(--transition);
}
.notes-input {
    width: 100%;
    min-height: 240px;
    resize: vertical;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background: var(--input-bg);
    color: var(--text-primary);
    padding: 0.9rem;
    font: inherit;
    line-height: 1.45;
    box-sizing: border-box;
}
.notes-status { color: var(--text-secondary); font-size: 0.86rem; margin: 0.75rem 0; }
.notes-actions { display: flex; justify-content: flex-end; }

/* Notes file upload */
.notes-upload-row {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    flex-wrap: wrap;
    margin-bottom: 0.6rem;
}
.notes-upload-btn {
    border: 1px solid var(--border-color);
    background: var(--input-bg);
    color: var(--text-primary);
    border-radius: var(--radius-md);
    padding: 0.5rem 0.85rem;
    font: inherit;
    font-weight: 800;
    font-size: 0.86rem;
    cursor: pointer;
}
.notes-upload-btn:hover { border-color: var(--text-primary); }
.notes-upload-hint { color: var(--text-muted); font-size: 0.8rem; }
.notes-file-list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.45rem;
}
.notes-file-list:not(:empty) { margin-bottom: 0.6rem; }
.notes-file-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    max-width: 100%;
    border: 1px solid var(--border-color);
    background: var(--input-bg);
    color: var(--text-primary);
    border-radius: 999px;
    padding: 0.3rem 0.45rem 0.3rem 0.75rem;
    font-size: 0.8rem;
    font-weight: 700;
}
.notes-file-name {
    max-width: 220px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.notes-file-remove {
    border: none;
    background: transparent;
    color: var(--text-muted);
    font: inherit;
    font-weight: 800;
    line-height: 1;
    padding: 0.1rem 0.3rem;
    cursor: pointer;
}
.notes-file-remove:hover { color: var(--text-primary); }
#creator-notes-panel.drag-over .notes-input {
    border-color: var(--text-primary);
    border-style: dashed;
}

/* ============================================================
   Achievements preview (homepage)
   ============================================================ */
.achievements-preview { margin-bottom: 2.5rem; }
.ach-preview-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
}
.ach-preview-header h2 { color: var(--text-primary); margin: 0; font-size: 1.5rem; }
.ach-count {
    font-size: 0.85rem;
    background: var(--accent);
    color: #fff;
    padding: 2px 10px;
    border-radius: 999px;
    margin-left: 0.5rem;
    vertical-align: middle;
}
.ach-viewall { color: var(--accent); text-decoration: none; font-weight: 700; font-size: 0.9rem; }
.ach-viewall:hover { text-decoration: underline; }
.ach-preview-row {
    display: flex;
    gap: 0.75rem;
    overflow-x: auto;
    padding-bottom: 0.5rem;
}
.ach-chip {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex: 0 0 auto;
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 999px;
    padding: 8px 14px;
    box-shadow: var(--shadow-sm);
}
.ach-chip.locked { opacity: 0.55; }
.ach-chip-icon { font-size: 1.1rem; }
.ach-chip-name { font-size: 0.8rem; font-weight: 700; color: var(--text-primary); white-space: nowrap; }

/* ============================================================
   Congrats modal extras
   ============================================================ */
.modal-stats {
    display: flex;
    justify-content: center;
    gap: 1.5rem;
    margin: 1rem 0;
}
.modal-stat-value { font-size: 1.6rem; font-weight: 800; color: var(--accent); }
.modal-stat-label { font-size: 0.75rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; }
.modal-achievements { margin: 0.5rem 0 1rem; }
.modal-ach-title { font-weight: 800; color: var(--text-primary); margin-bottom: 0.5rem; }
.modal-ach-item {
    background: var(--highlight-bg);
    border-radius: var(--radius-sm);
    padding: 8px 12px;
    margin-bottom: 6px;
    font-size: 0.85rem;
    color: var(--text-primary);
    text-align: left;
}
.modal-ach-item .ach-icon { font-size: 1.1rem; }

/* ============================================================
   Stats page
   ============================================================ */
.stats-back {
    background: var(--card-bg);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    padding: 8px 16px;
    border-radius: var(--radius-md);
    cursor: pointer;
    font-weight: 700;
    margin-bottom: 1rem;
}
.stats-block {
    background: var(--card-bg);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    margin-bottom: 1.75rem;
    box-shadow: var(--shadow-md);
}
.stats-block h2 { margin-top: 0; color: var(--text-primary); }
.stats-overview {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 1rem;
    margin-bottom: 1.75rem;
}
.ov-card {
    background: var(--card-bg);
    border-radius: var(--radius-md);
    padding: 1.25rem 1rem;
    text-align: center;
    box-shadow: var(--shadow-sm);
}
.ov-value { font-size: 1.6rem; font-weight: 800; color: var(--accent); }
.ov-label { font-size: 0.78rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.03em; margin-top: 4px; }

.ach-gallery {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 1rem;
}
.ach-tile {
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 1.25rem 1rem;
    text-align: center;
    background: var(--input-bg);
}
.ach-tile.locked { opacity: 0.5; }
.ach-tile.unlocked { border-color: var(--accent); box-shadow: var(--shadow-sm); }
.ach-tile-icon { font-size: 2rem; }
.ach-tile-name { font-weight: 800; color: var(--text-primary); margin: 0.4rem 0 0.25rem; }
.ach-tile-desc { font-size: 0.8rem; color: var(--text-secondary); }
.ach-tile-date { font-size: 0.7rem; color: var(--text-muted); margin-top: 0.4rem; }

.specialty-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 1rem;
}
.spec-card {
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 1rem;
    background: var(--input-bg);
}
.spec-card.complete { border-color: var(--correct-text); }
.spec-top { display: flex; align-items: center; gap: 0.5rem; margin-bottom: 0.6rem; }
.spec-icon { font-size: 1.3rem; }
.spec-name { font-weight: 700; color: var(--text-primary); }
.spec-bar-track { height: 8px; background: var(--border-color); border-radius: 999px; overflow: hidden; }
.spec-bar-fill { height: 100%; background: var(--bg-gradient); border-radius: 999px; transition: width var(--transition); }
.spec-meta { display: flex; justify-content: space-between; font-size: 0.78rem; color: var(--text-muted); margin-top: 0.5rem; }

.weak-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
    gap: 1rem;
}
.weak-card {
    background: var(--input-bg);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 1rem;
}
.weak-type {
    color: var(--text-muted);
    font-size: 0.68rem;
    font-weight: 800;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}
.weak-title { color: var(--text-primary); font-size: 1.1rem; font-weight: 800; margin: 0.2rem 0; }
.weak-meta { color: var(--text-secondary); font-size: 0.8rem; line-height: 1.45; }
.weak-action {
    margin-top: 0.7rem;
    color: var(--accent);
    font-weight: 800;
    font-size: 0.82rem;
}

.daily-calendar-strip {
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
    gap: 0.5rem;
}
.daily-day {
    min-height: 54px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--input-bg);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    font-size: 0.72rem;
}
.daily-day.done {
    background: var(--correct-bg);
    color: var(--correct-text);
    border-color: var(--correct-text);
}
.daily-day.today { outline: 2px solid var(--accent); outline-offset: 2px; }
.daily-day strong { color: inherit; font-size: 0.9rem; }
.daily-calendar-note { margin-top: 0.8rem; color: var(--text-secondary); font-size: 0.84rem; }

.review-header { display: flex; align-items: center; justify-content: space-between; }
.review-sub { color: var(--text-secondary); font-size: 0.85rem; margin: 0.25rem 0 1rem; }
.clear-review-btn {
    background: var(--incorrect-bg);
    color: var(--incorrect-text);
    border: none;
    padding: 6px 14px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-weight: 600;
    font-size: 0.8rem;
}
.review-list { display: flex; flex-direction: column; gap: 0.6rem; }
.review-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    background: var(--input-bg);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 0.85rem 1rem;
}
.review-term { font-weight: 800; color: var(--text-primary); letter-spacing: 0.04em; }
.review-clue { font-size: 0.85rem; color: var(--text-secondary); margin-top: 2px; }
.review-remove {
    background: var(--correct-bg);
    color: var(--correct-text);
    border: none;
    padding: 6px 12px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-weight: 700;
    font-size: 0.8rem;
    white-space: nowrap;
}
.review-empty { color: var(--text-muted); text-align: center; padding: 1.5rem; }

/* The hidden attribute must win over display:flex/grid utilities below. */
[hidden] { display: none !important; }

/* ============================================================
   Review nudge (homepage) + Study Now button + box badges
   ============================================================ */
.review-nudge-card {
    display: flex;
    align-items: center;
    gap: 1rem;
    text-decoration: none;
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-left: 5px solid var(--accent);
    border-radius: var(--radius-lg);
    padding: 1rem 1.25rem;
    margin-bottom: 1.5rem;
    box-shadow: var(--shadow-sm);
    transition: transform var(--transition);
}
.review-nudge-card:hover { transform: translateY(-2px); }
.review-nudge-icon { font-size: 1.8rem; }
.review-nudge-text { display: flex; flex-direction: column; flex: 1; }
.review-nudge-text strong { color: var(--text-primary); font-size: 1rem; }
.review-nudge-text span { color: var(--text-secondary); font-size: 0.82rem; }
.review-nudge-cta { color: var(--accent); font-weight: 800; white-space: nowrap; }

.review-actions { display: flex; gap: 0.6rem; align-items: center; }
.study-now-btn {
    background: var(--accent);
    color: #fff;
    text-decoration: none;
    padding: 6px 16px;
    border-radius: var(--radius-sm);
    font-weight: 700;
    font-size: 0.85rem;
    transition: transform var(--transition);
}
.study-now-btn:hover { transform: translateY(-1px); }
.study-now-btn.disabled { background: var(--border-color); color: var(--text-muted); pointer-events: none; }

.box-badge {
    font-size: 0.62rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    padding: 2px 7px;
    border-radius: 999px;
    margin-left: 6px;
    vertical-align: middle;
    color: #fff;
}
.box-1 { background: #e74c3c; }
.box-2 { background: #e67e22; }
.box-3 { background: #f1c40f; color: #333; }
.box-4 { background: #3498db; }
.box-5 { background: #27ae60; }
.due-badge {
    font-size: 0.62rem;
    font-weight: 800;
    text-transform: uppercase;
    padding: 2px 7px;
    border-radius: 999px;
    margin-left: 4px;
    background: var(--highlight-bg);
    color: var(--accent);
}

/* ============================================================
   Study (flashcard) mode
   ============================================================ */
.study-container { max-width: 640px; }
.study-mode-tabs {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 0.9rem;
}
.study-mode-tab {
    flex: 1;
    border: 1px solid rgba(255,255,255,0.35);
    background: rgba(255,255,255,0.16);
    color: #fff;
    border-radius: var(--radius-md);
    padding: 10px 14px;
    font-weight: 800;
    cursor: pointer;
}
.study-mode-tab.active { background: #fff; color: var(--accent-dark); }
.study-progress-bar {
    height: 8px;
    background: var(--card-bg);
    border-radius: 999px;
    overflow: hidden;
    margin-bottom: 0.75rem;
    box-shadow: var(--shadow-sm);
}
.study-progress-fill {
    height: 100%;
    width: 0;
    background: var(--bg-gradient);
    border-radius: 999px;
    transition: width var(--transition);
}
.study-meta { text-align: center; color: rgba(255,255,255,0.85); font-size: 0.85rem; font-weight: 600; margin-bottom: 1rem; }

.flashcard {
    background: var(--card-bg);
    border-radius: var(--radius-xl);
    padding: 2.5rem 2rem;
    min-height: 240px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-lg);
    cursor: pointer;
    transition: transform var(--transition);
}
.flashcard.flipped { transform: scale(1.01); }
.flashcard-inner { width: 100%; text-align: center; }
.flashcard-label {
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    font-weight: 800;
    margin-bottom: 1rem;
}
.flashcard-front { font-size: 1.4rem; color: var(--text-primary); line-height: 1.5; }
.flashcard-back { margin-top: 1.5rem; padding-top: 1.5rem; border-top: 2px dashed var(--border-color); }
.flashcard-answer {
    font-size: 2rem;
    font-weight: 800;
    color: var(--accent);
    letter-spacing: 0.06em;
}
.flashcard-category { color: var(--text-secondary); font-size: 0.85rem; margin-top: 0.4rem; }
.flashcard-ai {
    margin-top: 1rem;
    border: 1px solid var(--border-color);
    background: var(--input-bg);
    color: var(--text-primary);
    border-radius: var(--radius-sm);
    padding: 7px 12px;
    font-weight: 800;
    cursor: pointer;
}
.flashcard-ai-text {
    margin-top: 0.8rem;
    color: var(--text-secondary);
    font-size: 0.88rem;
    line-height: 1.55;
    text-align: left;
}

.study-controls { margin-top: 1.5rem; }
.study-btn {
    border: none;
    border-radius: var(--radius-md);
    padding: 14px 24px;
    font-size: 1rem;
    font-weight: 800;
    cursor: pointer;
    transition: transform var(--transition);
}
.study-btn:hover { transform: translateY(-2px); }
.study-btn-show {
    display: block;
    width: 100%;
    background: var(--accent);
    color: #fff;
}
.study-grade { display: flex; gap: 1rem; }
.study-grade .study-btn { flex: 1; }
.study-btn-got { background: #27ae60; color: #fff; }
.study-btn-missed { background: #e74c3c; color: #fff; }

.study-done { text-align: center; background: var(--card-bg); border-radius: var(--radius-xl); padding: 2.5rem 2rem; box-shadow: var(--shadow-lg); }
.study-done-emoji { font-size: 3rem; }
.study-done h2 { color: var(--text-primary); margin: 0.5rem 0; }
.study-done p { color: var(--text-secondary); }
.study-done-actions { display: flex; gap: 1rem; margin-top: 1.5rem; }
.study-done-actions .study-btn { flex: 1; }

@media (max-width: 600px) {
    .stats-link { right: 70px; top: 18px; padding: 8px 12px; font-size: 0.78rem; }
    .daily-card { flex-direction: column; text-align: center; }
    .modal-stats { gap: 1rem; }
    .flashcard-front { font-size: 1.2rem; }
    .flashcard-answer { font-size: 1.6rem; }
}

/* ============================================================
   PHASE 3: NYT-STYLE PUZZLE PAGE
   All rules scoped to body.puzzle-page so homepage is untouched.
   ============================================================ */

/* ── Page background ── */
body.puzzle-page {
    background: var(--bg-main);
    color: var(--text-main);
    background-attachment: fixed;
}

/* ── Full-width sticky toolbar ── */
body.puzzle-page #puzzle-header {
    position: sticky;
    top: 0;
    z-index: 200;
    display: flex;
    align-items: center;
    gap: 1rem;
    background: var(--bg-header);
    border: none;
    border-bottom: 1px solid var(--border);
    border-radius: 0;
    margin: 0;
    padding: 0.65rem 1.25rem;
    box-shadow: var(--shadow-card);
    backdrop-filter: none;
    /* Pull outside the #app-container width constraint */
    width: 100%;
    box-sizing: border-box;
}

body.puzzle-page #back-button {
    flex: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    background: var(--btn-secondary-bg);
    color: var(--text-main);
    border: 1px solid var(--btn-secondary-border);
    border-radius: 10px;
    padding: 0;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s, color 0.15s;
    margin: 0;
    white-space: nowrap;
}
body.puzzle-page #back-button:hover {
    border-color: var(--accent);
    color: var(--accent);
    background: var(--accent-soft);
}

/* Center block: title + category/difficulty pills */
.ph-center {
    flex: 1;
    min-width: 0;
    text-align: center;
}

body.puzzle-page #puzzle-title {
    font-size: 1.05rem;
    font-weight: 800;
    margin: 0 0 0.2rem;
    color: var(--text-main);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    letter-spacing: -0.2px;
}

body.puzzle-page #puzzle-info {
    display: flex;
    gap: 0.4rem;
    justify-content: center;
    font-size: 0.72rem;
}

body.puzzle-page #puzzle-info span {
    font-size: 0.7rem;
    padding: 0.14rem 0.6rem;
    border-radius: 999px;
    background: var(--tag-bg);
    color: var(--tag-text);
    font-weight: 700;
    letter-spacing: 0.02em;
}

/* Timer in header */
body.puzzle-page #timer {
    flex: none;
    font-size: 0.92rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    color: var(--text-main);
    background: var(--stat-badge-bg);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 0.42rem 0.8rem;
    min-width: 76px;
    text-align: center;
    white-space: nowrap;
    line-height: 1.3;
}

/* ── App container: padding accounts for sticky header ── */
body.puzzle-page #app-container {
    padding-top: 1.25rem;
    max-width: min(1500px, calc(100vw - 2rem));
    align-items: flex-start;
    gap: 1.25rem;
}

/* ── NYT grid ── */
body.puzzle-page #crossword-grid {
    border: 2px solid var(--grid-line);
    border-radius: 6px;
    background: var(--grid-line);  /* shows as hairline between cells */
    gap: 1px;
    box-shadow: var(--shadow-card);
    overflow: hidden;
}

body.puzzle-page .black-cell {
    background-color: var(--grid-line);
    border: none;
}

body.puzzle-page .grid-cell {
    background-color: var(--grid-cell-bg);
    border: none;          /* gap on the grid container acts as the line */
    border-radius: 0;
}
body.puzzle-page .grid-cell input {
    color: var(--grid-cell-text);
}

/* Word highlight: soft accent */
body.puzzle-page .grid-cell.highlighted {
    background-color: var(--grid-highlight);
}

/* Active / focused cell */
body.puzzle-page .grid-cell.focused {
    background-color: var(--grid-focus);
}

body.puzzle-page .grid-cell input:focus {
    background-color: var(--grid-focus);
    outline: none;
}

/* Correct / incorrect override keeps them visible on white */
body.puzzle-page .grid-cell.correct input {
    background-color: #d4edda;
    color: #155724;
}
body.puzzle-page .grid-cell.incorrect input {
    background-color: #f8d7da;
    color: #721c24;
}

/* Revealed cell */
body.puzzle-page .grid-cell.revealed {
    background-color: #e8f0fe;
}
body.puzzle-page .grid-cell.revealed input {
    color: #1a56db;
    font-weight: 800;
}

/* Clue number: crisp on the cell background */
body.puzzle-page .clue-number {
    color: var(--grid-cell-text);
    font-size: 9px;
    top: 1px;
    left: 2px;
}

/* ── Active clue banner: themed card, no harsh black ── */
body.puzzle-page .active-clue-banner {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-left: 4px solid var(--accent);
    border-radius: 10px;
    box-shadow: var(--shadow-card);
    margin: 0 0 0.75rem;
    padding: 0.45rem 0.5rem;
    gap: 0.5rem;
}
body.puzzle-page .active-clue-banner { color: var(--text-main); }
body.puzzle-page .active-clue-dir {
    background: var(--tag-bg);
    color: var(--tag-text);
    align-self: center;
}
body.puzzle-page .active-clue-text {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-main);
}
body.puzzle-page .active-clue-middle { align-items: center; padding: 0.15rem 0; }
body.puzzle-page .clue-nav-btn {
    background: var(--btn-secondary-bg);
    color: var(--text-muted);
    border: 1px solid var(--btn-secondary-border);
    border-radius: 8px;
    width: 34px;
}
body.puzzle-page .clue-nav-btn:hover {
    background: var(--accent-soft);
    color: var(--accent);
    border-color: var(--accent);
}

/* ── Controls bar ── */
body.puzzle-page #puzzle-controls {
    display: flex;
    align-items: stretch;
    justify-content: center;
    flex-wrap: wrap;
    gap: 8px;
    padding: 0.75rem 0.85rem;
    margin-top: 14px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: var(--shadow-card);
}

/* Base style for all control buttons */
body.puzzle-page #puzzle-controls button,
body.puzzle-page #apply-action {
    height: 38px;
    padding: 0 16px;
    font-size: 0.84rem;
    font-weight: 700;
    border-radius: 10px;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s, color 0.15s;
    border: 1px solid var(--btn-secondary-border);
    background: var(--btn-secondary-bg);
    color: var(--btn-secondary-text);
    font-family: inherit;
    line-height: 1.4;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
}
body.puzzle-page #puzzle-controls button:hover,
body.puzzle-page #apply-action:hover {
    background: var(--accent-soft);
    border-color: var(--accent);
    color: var(--accent-hover);
    transform: none;
    box-shadow: none;
}

/* Disabled buttons: clearly off, still readable */
body.puzzle-page #puzzle-controls button:disabled,
body.puzzle-page #apply-action:disabled {
    background: var(--disabled-bg) !important;
    color: var(--disabled-text) !important;
    border-color: var(--border) !important;
    cursor: not-allowed;
    opacity: 1;
}

/* Check — primary action: teal */
body.puzzle-page #check-button {
    background: var(--btn-primary-bg) !important;
    color: var(--btn-primary-text) !important;
    border-color: var(--btn-primary-bg) !important;
}
body.puzzle-page #check-button:hover {
    background: var(--accent-hover) !important;
    border-color: var(--accent-hover) !important;
    color: var(--btn-primary-text) !important;
}

/* Reveal — secondary, inherits the shared base */
body.puzzle-page #reveal-button {
    border-color: var(--btn-secondary-border) !important;
    background: var(--btn-secondary-bg) !important;
    color: var(--btn-secondary-text) !important;
}
body.puzzle-page #reveal-button:disabled {
    background: var(--disabled-bg) !important;
    color: var(--disabled-text) !important;
    border-color: var(--border) !important;
    cursor: not-allowed;
    opacity: 1;
}
body.puzzle-page #reveal-button:hover:not(:disabled) {
    border-color: var(--accent) !important;
    background: var(--accent-soft) !important;
    color: var(--accent-hover) !important;
}

/* Hint — secondary, inherits the shared base */
body.puzzle-page #hint-button {
    background: var(--btn-secondary-bg) !important;
    color: var(--btn-secondary-text) !important;
    border-color: var(--btn-secondary-border) !important;
}
body.puzzle-page #hint-button:hover {
    background: var(--accent-soft) !important;
    color: var(--accent-hover) !important;
    border-color: var(--accent) !important;
}
body.puzzle-page .hint-counter { color: var(--text-muted); }

/* Pencil / Auto-check toggles: teal when active */
body.puzzle-page .pencil-button.active,
body.puzzle-page .autocheck-button.active {
    background: var(--accent-soft) !important;
    color: var(--accent-hover) !important;
    border-color: var(--accent) !important;
    box-shadow: inset 0 0 0 1px var(--accent);
}

/* Action menu select + Apply */
body.puzzle-page #action-menu-container {
    display: flex;
    gap: 8px;
    align-items: stretch;
}
body.puzzle-page #action-select {
    height: 38px;
    background: var(--btn-secondary-bg);
    color: var(--btn-secondary-text);
    border: 1px solid var(--btn-secondary-border);
    border-radius: 10px;
    padding: 0 10px;
    font-size: 0.82rem;
    font-family: inherit;
    cursor: pointer;
    min-width: 140px;
}
body.puzzle-page #action-select:focus {
    outline: none;
    border-color: var(--accent);
}

/* ── Progress bar ── */
body.puzzle-page .progress-bar-container {
    border: 1px solid var(--border);
    background: var(--bg-card);
    box-shadow: var(--shadow-card);
    border-radius: var(--radius-md);
    padding: 0.55rem 1rem;
    margin-bottom: 10px;
}
body.puzzle-page .progress-bar-container span {
    color: var(--text-muted) !important;
}
body.puzzle-page .progress-bar-fill {
    background: var(--accent);
}

/* ── Clue panel ── */
body.puzzle-page #clues-container {
    width: clamp(430px, 34vw, 560px);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-card);
    background: var(--bg-panel);
    border-radius: 12px;
    max-height: calc(100vh - 98px);
    position: sticky;
    top: 76px;
    overflow: hidden;
}

body.puzzle-page .clues-header {
    border-bottom: 1px solid var(--divider);
    padding: 1rem 1.15rem 0.8rem;
    background: var(--bg-panel);
}

body.puzzle-page .clues-header h2 {
    font-size: 1rem;
    font-weight: 800;
    letter-spacing: 0;
    color: var(--text-main);
}

body.puzzle-page .clues-content {
    display: grid;
    grid-template-columns: 1fr;
    overflow-y: auto;
    min-height: 0;
    padding: 0.9rem 1rem;
    gap: 1.1rem;
    scrollbar-width: thin;
    scrollbar-color: var(--border-strong) transparent;
}

/* Subtle scrollbars that match the theme (grid overflow + clues panel) */
body.puzzle-page #puzzle-container {
    scrollbar-width: thin;
    scrollbar-color: var(--border-strong) transparent;
}
body.puzzle-page #puzzle-container::-webkit-scrollbar { height: 8px; }
body.puzzle-page #puzzle-container::-webkit-scrollbar-track { background: transparent; }
body.puzzle-page #puzzle-container::-webkit-scrollbar-thumb {
    background: var(--border-strong);
    border-radius: 999px;
}
body.puzzle-page .clues-content::-webkit-scrollbar { width: 8px; }
body.puzzle-page .clues-content::-webkit-scrollbar-track { background: transparent; }
body.puzzle-page .clues-content::-webkit-scrollbar-thumb {
    background: var(--border-strong);
    border-radius: 999px;
    border: 2px solid var(--bg-panel);
}
body.puzzle-page .clues-content::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

body.puzzle-page .clue-column {
    padding: 0;
    min-height: auto;
}

body.puzzle-page .clue-column:first-child {
    border-right: 0;
}

body.puzzle-page .clue-column-title {
    position: sticky;
    top: -0.9rem;
    z-index: 1;
    background: var(--bg-panel);
    font-size: 0.74rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-weight: 800;
    color: var(--text-muted);
    border-bottom: 1px solid var(--divider);
    padding: 0.3rem 0 0.55rem;
    margin: 0 0 0.5rem;
    text-align: left;
}

body.puzzle-page .clues-list {
    overflow: visible;
}

body.puzzle-page .clues-list li {
    display: grid;
    grid-template-columns: 2.1rem 1fr;
    column-gap: 0.55rem;
    align-items: start;
    font-size: 0.94rem;
    padding: 0.62rem 0.7rem;
    border-radius: 8px;
    border: 1px solid transparent;
    line-height: 1.48;
    margin-bottom: 0.35rem;
    color: var(--text-main);
    overflow-wrap: anywhere;
}

body.puzzle-page .clue-number-list {
    font-weight: 800;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

body.puzzle-page .clue-active .clue-number-list {
    color: var(--accent-hover);
}

body.puzzle-page .clues-list li:hover {
    background: var(--accent-soft);
    transform: none;
}

/* Active clue: soft teal accent */
body.puzzle-page .clue-active {
    background-color: var(--active-clue-bg) !important;
    border-color: var(--active-clue-border) !important;
    color: var(--text-main) !important;
    font-weight: 700 !important;
    box-shadow: inset 3px 0 0 var(--accent) !important;
}

@media (min-width: 980px) {
    body.puzzle-page #app-container {
        flex-direction: row;
        max-width: min(1500px, calc(100vw - 2rem));
        align-items: flex-start;
    }

    body.puzzle-page #puzzle-container {
        width: auto;
        flex: 1 1 auto;
    }

    body.puzzle-page #clues-container {
        width: clamp(420px, 36vw, 560px);
        position: sticky;
        top: 76px;
        max-height: calc(100vh - 98px);
    }

    body.puzzle-page .clues-content {
        max-height: none;
    }
}

@media (max-width: 1200px) {
    body.puzzle-page #app-container {
        max-width: 900px;
        align-items: stretch;
    }

    body.puzzle-page #clues-container {
        width: 100%;
        position: static;
        max-height: none;
    }

    body.puzzle-page .clues-content {
        max-height: 360px;
    }
}

@media (max-width: 720px) {
    body.puzzle-page .clues-content {
        padding: 0.65rem;
        gap: 0.75rem;
    }

    body.puzzle-page .clues-list li {
        grid-template-columns: 1.85rem 1fr;
        font-size: 0.9rem;
        padding: 0.55rem 0.6rem;
    }
}

/* ── Dark mode adjustments ──
   Theme variables drive nearly everything; only the cell-state
   pastels need dark-legible variants. */
html[data-theme="dark"] body.puzzle-page .grid-cell.correct input {
    background-color: rgba(34, 197, 94, 0.22);
    color: #86EFAC;
}
html[data-theme="dark"] body.puzzle-page .grid-cell.incorrect input {
    background-color: rgba(239, 68, 68, 0.22);
    color: #FCA5A5;
}
html[data-theme="dark"] body.puzzle-page .grid-cell.revealed {
    background-color: rgba(96, 165, 250, 0.18);
}
html[data-theme="dark"] body.puzzle-page .grid-cell.revealed input {
    color: #93C5FD;
}

/* Progress labels (one is inline-styled, hence !important) */
html[data-theme="dark"] body.puzzle-page .progress-bar-container span {
    color: var(--text-muted) !important;
}
html[data-theme="dark"] body.puzzle-page .progress-bar-track {
    background: var(--bg-card-secondary);
}

/* Modals follow the theme too */
html[data-theme="dark"] body.puzzle-page .modal-content {
    background: var(--bg-card);
    border: 1px solid var(--border);
    color: var(--text-main);
}
html[data-theme="dark"] body.puzzle-page .modal-title { color: var(--text-main); }
html[data-theme="dark"] body.puzzle-page .modal-subtitle,
html[data-theme="dark"] body.puzzle-page .modal-time-label,
html[data-theme="dark"] body.puzzle-page .modal-stat-label { color: var(--text-muted); }
html[data-theme="dark"] body.puzzle-page .modal-btn-secondary {
    background: var(--btn-secondary-bg);
    color: var(--btn-secondary-text);
    border-color: var(--btn-secondary-border);
}

/* ── AI Panel (slides up from bottom) ────────────────────────────────────── */
.ai-panel {
    position: fixed;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    width: min(540px, 96vw);
    background: var(--card-bg-solid);
    border: 1.5px solid var(--border-color);
    border-bottom: none;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    box-shadow: 0 -6px 28px rgba(0,0,0,0.16);
    z-index: 500;
    animation: aiSlideUp 0.22s ease;
}
@keyframes aiSlideUp {
    from { transform: translateX(-50%) translateY(100%); opacity: 0; }
    to   { transform: translateX(-50%) translateY(0);    opacity: 1; }
}

.ai-panel-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.6rem 0.9rem;
    border-bottom: 1px solid var(--border-color);
    background: #1b1b1b;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}
.ai-panel-icon { font-size: 1.05rem; }
.ai-panel-title {
    flex: 1;
    font-size: 0.86rem;
    font-weight: 800;
    color: #fff;
    letter-spacing: 0.02em;
}
.ai-panel-close {
    background: rgba(255,255,255,0.15);
    border: none;
    color: #fff;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 0.72rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s;
}
.ai-panel-close:hover { background: rgba(255,255,255,0.3); }

.ai-panel-body {
    padding: 0.9rem 1.1rem 1.1rem;
    max-height: 210px;
    overflow-y: auto;
}

.ai-clue-context {
    font-size: 0.76rem;
    color: var(--text-muted);
    margin-bottom: 0.55rem;
}
.ai-clue-context em { font-style: italic; color: var(--text-secondary); }

.ai-answer-text {
    font-size: 0.92rem;
    line-height: 1.65;
    color: var(--text-primary);
}

.ai-loading-indicator {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    color: var(--text-secondary);
    font-size: 0.88rem;
    font-weight: 600;
    padding: 0.3rem 0;
}
.ai-spinner {
    width: 17px;
    height: 17px;
    border: 2px solid var(--border-color);
    border-top-color: #1b1b1b;
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
    flex: none;
}

.ai-notice { font-size: 0.88rem; color: var(--text-secondary); }
.ai-error  { font-size: 0.88rem; color: #c0392b; }
.ai-step-actions {
    display: flex;
    justify-content: flex-end;
    margin-top: 0.8rem;
}
.ai-step-btn {
    border: none;
    background: #1b1b1b;
    color: #fff;
    border-radius: 5px;
    padding: 7px 12px;
    font-weight: 800;
    cursor: pointer;
}

/* AI Explain / Tutor buttons in controls bar: accent-outlined secondaries */
body.puzzle-page .ai-explain-btn {
    background: var(--accent-soft) !important;
    color: var(--accent-hover) !important;
    border-color: var(--accent-subtle-border) !important;
}
body.puzzle-page .ai-explain-btn:hover {
    background: var(--accent-subtle) !important;
    border-color: var(--accent) !important;
    color: var(--accent-hover) !important;
}

/* Post-puzzle Learn panel inside congrats modal */
.modal-learn-panel {
    margin: 0.75rem 0 0.5rem;
    text-align: left;
    background: var(--input-bg);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 0.9rem 1rem;
    max-height: 220px;
    overflow-y: auto;
}
.modal-learn-title {
    font-size: 0.88rem;
    font-weight: 800;
    color: var(--text-primary);
    margin-bottom: 0.6rem;
}
.modal-learn-body {
    font-size: 0.84rem;
    line-height: 1.7;
    color: var(--text-secondary);
}

/* ── Puzzle-page responsive overrides ── */
@media (max-width: 768px) {
    body.puzzle-page #puzzle-title {
        font-size: 0.88rem;
    }
    body.puzzle-page #puzzle-info {
        display: none; /* hide pills on small screens */
    }
    body.puzzle-page #timer {
        font-size: 0.82rem;
        min-width: 76px;
        padding: 0.3rem 0.55rem;
    }
    body.puzzle-page #puzzle-controls {
        gap: 5px;
        padding: 0.5rem;
    }
    body.puzzle-page #puzzle-controls button,
    body.puzzle-page #apply-action {
        padding: 5px 10px;
        font-size: 0.78rem;
    }
}

/* ============================================================
   NYT-style additions: pause, start overlay, clue bar arrows
   ============================================================ */
.timer-wrap {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
#pause-button {
    border: 1px solid var(--btn-secondary-border);
    background: var(--btn-secondary-bg);
    color: var(--btn-secondary-text);
    border-radius: 10px;
    height: 38px;
    padding: 0 16px;
    font-size: 0.84rem;
    font-weight: 700;
    font-family: inherit;
    cursor: pointer;
    line-height: 1;
    white-space: nowrap;
    transition: background 0.15s, border-color 0.15s, color 0.15s;
}
#pause-button:hover {
    transform: none;
    background: var(--accent-soft);
    border-color: var(--accent);
    color: var(--accent-hover);
}
#pause-button[hidden] { display: none; }

#grid-wrap { position: relative; }
#pause-overlay {
    position: absolute;
    inset: 0;
    z-index: 30;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-main);
    border: 1px solid var(--border);
    border-radius: 6px;
    min-height: 320px;
}
#pause-overlay[hidden] { display: none; }
.pause-card {
    text-align: center;
    padding: 2.25rem 2.75rem;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 16px;
    box-shadow: var(--shadow);
    max-width: 340px;
}
.pause-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--accent-subtle);
    color: var(--accent);
    margin-bottom: 0.9rem;
}
.pause-title {
    font-size: 1.2rem;
    font-weight: 800;
    color: var(--text-main);
    margin-bottom: 0.35rem;
}
.pause-subtitle {
    font-size: 0.9rem;
    color: var(--text-muted);
    margin-bottom: 1.25rem;
    line-height: 1.5;
}
#resume-button {
    background: var(--btn-primary-bg);
    color: var(--btn-primary-text);
    border: none;
    border-radius: 10px;
    height: 42px;
    padding: 0 26px;
    font-size: 0.92rem;
    font-weight: 700;
    font-family: inherit;
    cursor: pointer;
    transition: background 0.15s;
}
#resume-button:hover { background: var(--accent-hover); }

.clue-nav-btn {
    flex: none;
    border: none;
    background: rgba(255, 255, 255, 0.22);
    color: #fff;
    border-radius: 6px;
    width: 32px;
    align-self: stretch;
    font-size: 1.3rem;
    font-weight: 700;
    cursor: pointer;
    line-height: 1;
    transition: background 0.15s;
}
.clue-nav-btn:hover { background: rgba(255, 255, 255, 0.38); }
.active-clue-banner { align-items: stretch; }
.active-clue-middle {
    flex: 1;
    display: flex;
    align-items: baseline;
    gap: 0.6rem;
    min-width: 0;
}

.start-modal-content .modal-emoji { font-size: 2.6rem; }
.keep-trying-content .modal-subtitle { max-width: 320px; margin-left: auto; margin-right: auto; }

/* No theme toggle on the puzzle page — answers stay hidden behind the
   opaque pause overlay (NYT hides the grid). */

/* Word Completion Pulse */
@keyframes wordPulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.1); z-index: 10; box-shadow: 0 0 10px var(--accent); }
    100% { transform: scale(1); }
}
.word-pulse {
    animation: wordPulse 0.4s ease-out;
}

/* Celebration Overlay */
#celebration-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    pointer-events: none;
    z-index: 9999;
}

/* ============================================================
   Professional visual polish layer
   ============================================================ */
:root {
    --bg-gradient: #f5f7fb;
    --card-bg: #ffffff;
    --card-bg-solid: #ffffff;
    --text-primary: #172033;
    --text-secondary: #475569;
    --text-muted: #718096;
    --border-color: #d9e2ec;
    --input-bg: #f8fafc;
    --accent: #167f7a;
    --accent-dark: #0f5f5b;
    --highlight-bg: #dceefe;
    --focus-bg: #fde68a;
    --correct-bg: #e7f7ef;
    --correct-text: #17613a;
    --incorrect-bg: #fde8e8;
    --incorrect-text: #9b1c1c;
    --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.06);
    --shadow-md: 0 8px 18px rgba(16, 24, 40, 0.08);
    --shadow-lg: 0 14px 28px rgba(16, 24, 40, 0.10);
    --shadow-xl: 0 24px 48px rgba(16, 24, 40, 0.12);
    --radius-sm: 6px;
    --radius-md: 8px;
    --radius-lg: 10px;
    --radius-xl: 12px;
    --transition: 160ms ease;
}

body {
    background: var(--bg-gradient);
    color: var(--text-primary);
}

.main-header {
    background: #ffffff;
    border: 0;
    border-bottom: 1px solid var(--border-color);
    box-shadow: none;
    padding: 2.25rem 1rem 1.5rem;
}

.main-header h1 {
    font-size: clamp(2rem, 5vw, 3.25rem);
    letter-spacing: -0.04em;
}

.main-header p {
    color: var(--text-secondary);
    font-weight: 400;
}

.container {
    max-width: 1320px;
}



.stats-link {
    top: 16px;
    right: 16px;
    background: #ffffff;
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    box-shadow: var(--shadow-sm);
    border-radius: 8px;
}

.stats-link:hover,
.category-card:hover,
.difficulty-card:hover,
.puzzle-card:hover,
.daily-start:hover,
.start-button:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.stats-bar {
    gap: 0.75rem;
    padding: 1rem 0 0;
}

.stat-item {
    min-width: 112px;
    padding: 0.75rem 1rem;
    border: 1px solid var(--border-color);
    border-radius: 10px;
    background: var(--input-bg);
}

.stat-value {
    font-size: 1.35rem;
    color: var(--text-primary);
}

.stat-label {
    color: var(--text-muted);
    letter-spacing: 0.04em;
}

.category-grid,
.difficulty-grid,
.puzzles-grid {
    gap: 1rem;
}

.category-card,
.difficulty-card,
.puzzle-card,
.notes-create-card,
.review-nudge-card,
.ach-chip,
.weak-card,
.flashcard,
.study-done {
    background: #ffffff;
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    box-shadow: none;
    backdrop-filter: none;
}

.category-card {
    text-align: left;
    padding: 1.15rem;
}

.category-card::before,
.category-icon,
.daily-icon,
.review-nudge-icon {
    display: none;
}

.category-card h3,
.difficulty-card h3,
.puzzle-title {
    color: var(--text-primary);
    font-size: 1rem;
    letter-spacing: -0.01em;
}

.category-card p,
.difficulty-card p,
.puzzle-description {
    color: var(--text-secondary);
}

.puzzle-count,
.puzzle-difficulty,
.completion-badge,
.ach-count {
    border-radius: 999px;
    background: #e7f3f2;
    color: var(--accent-dark);
}

.difficulty-stars {
    display: none;
}

.category-card.active,
.difficulty-card.active {
    background: #e7f3f2;
    color: var(--text-primary);
    border: 1px solid var(--accent);
    box-shadow: inset 3px 0 0 var(--accent);
}

.difficulty-card.active h3,
.difficulty-card.active p {
    color: var(--text-primary);
}

.search-input,
.puzzles-filter select,
.creator-input,
.creator-select,
.notes-input,
body.puzzle-page #action-select {
    border: 1px solid var(--border-color);
    background: var(--input-bg);
    color: var(--text-primary);
    border-radius: 8px;
}

.search-input:focus,
.puzzles-filter select:focus,
.creator-input:focus,
.creator-select:focus,
.notes-input:focus {
    outline: 2px solid rgba(22, 127, 122, 0.18);
    border-color: var(--accent);
}

.start-button,
.notes-create-btn,
.daily-start,
.modal-btn-primary,
body.puzzle-page #check-button,
body.puzzle-page #puzzle-controls button,
body.puzzle-page #apply-action {
    border-radius: 8px;
}

.start-button,
.notes-create-btn,
.modal-btn-primary,
body.puzzle-page #check-button {
    background: var(--accent) !important;
    border-color: var(--accent) !important;
    color: #ffffff !important;
    box-shadow: none;
}

.notes-create-card {
    background: transparent;
    border: 0;
    box-shadow: none;
    padding: 0.1rem 0;
}

.daily-section {
    background: transparent;
    border: 0;
    box-shadow: none;
    padding: 0;
}

.daily-card {
    border: 1px solid #0f2945;
}

/*
 * The custom creator and daily challenge are page-level modules, not nested
 * card stacks. Keep their outer structure quiet and let one surface carry the
 * content.
 */
.notes-create-card {
    border-left: 0;
}

.notes-kicker {
    color: var(--accent-dark);
}

.creator-tab.active {
    background: var(--accent);
    border-color: var(--accent);
}

.daily-card {
    background: #102a43 !important;
    border-radius: 12px;
    box-shadow: var(--shadow-sm);
}

.daily-badge {
    background: rgba(255,255,255,0.14);
}

.daily-start {
    color: var(--accent-dark);
}

.modal-emoji:empty,
.pause-emoji:empty,
.ach-chip-icon:empty,
.ai-panel-icon:empty,
.notes-status:empty {
    display: none;
}

footer {
    color: var(--text-muted) !important;
}

/* Stats and study pages: compact, professional product surfaces. */
#stats-page .main-header,
#study-page .main-header {
    padding-top: 3.25rem;
}

.stats-back {
    position: static;
    margin: 0 auto 1.25rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 40px;
    padding: 0 0.9rem;
    background: var(--card-bg) !important;
    color: var(--text-primary) !important;
    border: 1px solid var(--border-color) !important;
    border-radius: 8px;
    box-shadow: var(--shadow-sm);
}

.stats-back:hover {
    background: var(--highlight-bg);
    transform: translateY(-1px);
}

.stats-block {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    box-shadow: var(--shadow-md);
    padding: 1.25rem;
    margin-bottom: 1rem;
}

.stats-block h2 {
    font-size: 1.05rem;
    letter-spacing: 0;
    margin-bottom: 0.9rem;
}

.stats-overview {
    gap: 0.8rem;
    margin-bottom: 1rem;
}

.ov-card,
.ach-tile,
.spec-card,
.review-item,
.weak-card {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: var(--shadow-sm);
}

.weak-card-link {
    display: block;
    color: inherit;
    text-decoration: none;
    transition: border-color 160ms ease, transform 160ms ease;
}

.weak-card-link:hover {
    border-color: var(--accent);
    transform: translateY(-1px);
}

.weak-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 0.8rem;
}

.weak-actions a {
    display: inline-flex;
    min-height: 34px;
    align-items: center;
    justify-content: center;
    padding: 0 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-primary);
    background: var(--card-bg);
    font-size: 0.85rem;
    font-weight: 700;
    text-decoration: none;
}

.weak-actions a:first-child {
    color: #ffffff;
    background: var(--accent);
    border-color: var(--accent);
}

.ov-card {
    min-height: 108px;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.ov-value {
    color: var(--text-primary);
    font-size: 1.65rem;
    letter-spacing: 0;
}

.ov-label,
.ach-tile-desc,
.ach-tile-date,
.spec-meta,
.review-clue,
.review-sub {
    color: var(--text-muted);
}

.ach-tile {
    text-align: left;
}

.ach-tile.locked {
    opacity: 0.6;
    background: var(--card-bg);
}

.ach-tile.unlocked,
.spec-card.complete {
    border-color: var(--accent);
}

.ach-tile-name,
.spec-name,
.review-term {
    color: var(--text-primary);
    letter-spacing: 0;
}

.spec-bar-track,
.study-progress-bar {
    background: #e5edf2;
}

.spec-bar-fill,
.study-progress-fill {
    background: var(--accent);
}

.review-header {
    gap: 1rem;
}

.review-actions {
    flex-wrap: wrap;
    justify-content: flex-end;
}

.study-now-btn,
.clear-review-btn,
.review-remove,
.flashcard-ai {
    border-radius: 8px;
}

.study-now-btn {
    background: var(--accent);
    color: #ffffff;
    box-shadow: none;
}

.clear-review-btn,
.review-remove,
.flashcard-ai {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
}

.stats-notice {
    margin-top: 0.85rem;
    padding: 0.8rem 0.9rem;
    color: var(--text-primary);
    background: var(--highlight-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-weight: 700;
}

.review-item {
    align-items: flex-start;
    gap: 1rem;
}

.review-remove {
    white-space: nowrap;
}

.box-badge,
.due-badge {
    border-radius: 999px;
}

.study-container {
    max-width: 720px;
}

.study-mode-tabs {
    background: #edf3f7;
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 0.25rem;
}

.study-mode-tab {
    color: var(--text-secondary);
    border-radius: 8px;
}

.study-mode-tab.active {
    background: var(--card-bg);
    color: var(--accent);
    box-shadow: var(--shadow-sm);
}

.study-meta {
    color: var(--text-secondary);
}

.flashcard {
    border-radius: 10px;
    min-height: 300px;
}

.flashcard-label {
    color: var(--accent-dark);
    letter-spacing: 0.08em;
}

.flashcard-front {
    font-size: 1.25rem;
}

.flashcard-answer {
    color: var(--text-primary);
    letter-spacing: 0;
}

.flashcard-ai-text {
    color: var(--text-secondary);
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
}

.study-btn {
    border-radius: 8px;
    box-shadow: none;
}

.study-btn-show {
    background: var(--accent);
    color: #ffffff;
}

.study-btn-got {
    background: #167f7a;
    color: #ffffff;
}

.study-btn-hard {
    background: #f8fafc;
    border: 1px solid #cbd5e1;
    color: #334155;
}

.study-btn-easy {
    background: #0f766e;
    color: #ffffff;
}

.study-btn-missed {
    background: #fff1f2;
    border: 1px solid #fecdd3;
    color: #9f1239;
}

.study-done {
    border-radius: 10px;
}

.app-toast-root {
    position: fixed;
    left: 50%;
    bottom: 1rem;
    z-index: 3000;
    display: flex;
    width: min(92vw, 420px);
    flex-direction: column;
    gap: 0.5rem;
    transform: translateX(-50%);
    pointer-events: none;
}

.app-toast {
    padding: 0.8rem 1rem;
    background: #122033;
    color: #ffffff;
    border-radius: 8px;
    box-shadow: var(--shadow-lg);
    font-weight: 700;
    font-size: 0.9rem;
    line-height: 1.4;
    opacity: 0;
    transform: translateY(8px);
    transition: opacity 180ms ease, transform 180ms ease;
}

.app-toast.visible {
    opacity: 1;
    transform: translateY(0);
}

.app-dialog-overlay {
    position: fixed;
    inset: 0;
    z-index: 2900;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    background: rgba(15, 23, 42, 0.42);
    opacity: 0;
    pointer-events: none;
    transition: opacity 160ms ease;
}

.app-dialog-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

.app-dialog {
    width: min(92vw, 430px);
    padding: 1.35rem;
    background: var(--card-bg);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    box-shadow: var(--shadow-lg);
    backdrop-filter: blur(20px);
}

.app-dialog h2 {
    margin: 0 0 0.5rem;
    font-size: 1.15rem;
    letter-spacing: 0;
}

.app-dialog p {
    margin: 0;
    color: var(--text-secondary);
    line-height: 1.5;
}

.app-dialog-text {
    width: 100%;
    min-height: 132px;
    margin-top: 1rem;
    resize: vertical;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 0.8rem;
    color: var(--text-primary);
    background: var(--input-bg);
    font: inherit;
    line-height: 1.45;
}

.app-dialog-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.65rem;
    margin-top: 1.15rem;
}

@media (max-width: 680px) {
    .review-header {
        align-items: flex-start;
        flex-direction: column;
    }

    .review-actions {
        width: 100%;
        justify-content: flex-start;
    }

    .study-grade,
    .study-done-actions {
        flex-direction: column;
    }
}

/* Homepage usability pass: make puzzle discovery visible immediately. */
.ambient-blobs {
    display: none;
}

.hero-section {
    padding: 2.4rem 2rem 1.25rem;
}

.hero-badge {
    margin-bottom: 0.8rem;
}

.hero-title {
    font-size: clamp(2.15rem, 5vw, 4rem);
    line-height: 1.05;
    margin-bottom: 0.8rem;
}

.hero-subtitle {
    margin: 0 auto 1rem;
    max-width: 660px;
}

.hero-actions {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    flex-wrap: wrap;
    margin-bottom: 1rem;
}

.btn {
    min-height: 42px;
    border-radius: 8px;
    font-weight: 700;
    text-decoration: none;
}

.btn-primary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.65rem 1rem;
    background: var(--accent);
    color: #ffffff;
    border: 1px solid var(--accent);
    box-shadow: none;
}

.btn-primary:hover {
    background: var(--accent-dark);
    border-color: var(--accent-dark);
}

.hero-section .stats-bar {
    padding-top: 0;
}

#homepage > .container {
    padding-top: 0.75rem;
}

#review-nudge {
    margin-bottom: 1rem;
}

.puzzles-section {
    scroll-margin-top: 5rem;
    margin-bottom: 1.75rem;
}

.puzzles-section h2 {
    margin-bottom: 0.8rem;
}

.controls-bar {
    margin-bottom: 1rem;
}

.category-section,
.difficulty-section,
.achievements-preview {
    margin-top: 1.5rem;
}

@media (max-width: 680px) {
    .hero-section {
        padding: 1rem 1rem 0.75rem;
    }

    .hero-badge {
        display: none;
    }

    .hero-title {
        font-size: 2rem;
        line-height: 1.08;
        margin-bottom: 0.55rem;
    }

    .hero-subtitle {
        font-size: 0.95rem;
        line-height: 1.45;
        margin-bottom: 0.75rem;
    }

    .hero-actions {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 0.5rem;
        margin-bottom: 0;
    }

    .hero-actions .btn,
    .hero-actions button {
        width: 100%;
        min-height: 40px;
        padding: 0.55rem 0.65rem;
        font-size: 0.86rem;
        white-space: nowrap;
    }

    .hero-section .stats-bar {
        display: none;
    }

    .puzzles-section h2 {
        margin-bottom: 0.55rem;
    }

    .controls-bar {
        gap: 0.65rem;
        margin-bottom: 0.75rem;
    }

    .puzzle-card {
        padding: 1rem;
    }
}

/* Keep the core app surface immediately readable. */
.top-nav {
    background: rgba(255, 255, 255, 0.94);
    border-bottom: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
}

.nav-brand,
.top-nav .btn-outline {
    color: var(--text-primary);
}

.top-nav .btn-outline {
    background: #ffffff;
}

.hero-section,
.puzzles-section,
.notes-create-section,
.daily-section,
.achievements-preview,
.category-section,
.difficulty-section,
.category-card,
.difficulty-card,
.puzzle-card {
    animation: none !important;
    opacity: 1 !important;
}

/* ============================================================
   Homepage dark-theme enforcement
   Overrides the light-theme rules so they only apply to
   puzzle.html / stats.html, NOT the dark navy homepage.
   ============================================================ */

body.homepage {
    background: #07111F !important;
    color: #F8FAFC !important;
}

/* Shared homepage layout guardrails.
   The navbar is fixed, so the main content must reserve that space in
   normal document flow before the hero renders. Theme rules below should
   only alter visual treatment. */
body.homepage {
    --homepage-header-height: 4rem;
    --homepage-top-gap: 2rem;
}

body.homepage #site-navbar {
    height: var(--homepage-header-height);
}

body.homepage #homepage {
    min-height: 100vh;
    padding-top: calc(var(--homepage-header-height) + var(--homepage-top-gap)) !important;
}

body.homepage #homepage > header {
    position: relative;
    top: auto !important;
    transform: none !important;
    min-height: 340px;
    height: auto;
    max-height: none;
    margin-top: 0 !important;
    overflow: hidden;
}

body.homepage #stats-bar {
    position: relative;
    top: auto !important;
    transform: none !important;
    height: auto;
    max-height: none;
    overflow: visible;
}

@media (max-width: 680px) {
    body.homepage {
        --homepage-top-gap: 1rem;
    }

    body.homepage #homepage {
        padding-top: calc(var(--homepage-header-height) + var(--homepage-top-gap)) !important;
    }
}

/* Kill the light-mode section wrapper style on homepage */
body.homepage section {
    background: transparent !important;
    border: none !important;
    box-shadow: none !important;
    padding: 0 !important;
}

/* Kill white card backgrounds on homepage */
body.homepage .category-card,
body.homepage .difficulty-card,
body.homepage .puzzle-card,
body.homepage .notes-create-card,
body.homepage .ach-chip,
body.homepage .daily-card {
    background: #111C2E !important;
    color: #F8FAFC !important;
    border-color: rgba(255,255,255,0.08) !important;
}

/* Search / filter inputs stay dark */
body.homepage .search-input,
body.homepage .puzzles-filter select {
    background: transparent !important;
    color: #F8FAFC !important;
    border-color: rgba(255,255,255,0.08) !important;
}

/* Un-jam the Tailwind start-button & notes-create-btn overrides */
body.homepage .start-button,
body.homepage .notes-create-btn,
body.homepage .daily-start {
    background: revert !important;
    border-color: revert !important;
    color: revert !important;
}

/* Section headings — high contrast on dark background */
body.homepage .puzzles-section h2,
body.homepage .category-section h2,
body.homepage .difficulty-section h2 {
    color: #F8FAFC !important;
}

/* Nav stays dark on homepage */
body.homepage .top-nav {
    background: rgba(17, 28, 46, 0.9) !important;
    border-bottom-color: rgba(255,255,255,0.08) !important;
}

/* ============================================================
   MEDCROSS THEME SYSTEM
   Dark / Light mode via [data-theme] on <html>
   ============================================================ */

/* ── Dark theme CSS variables (default) ─────────────────────── */
:root,
[data-theme="dark"] {
    --bg-main:              #07111F;
    --bg-header:            #0F1A2B;
    --bg-card:              #111C2E;
    --bg-card-secondary:    #1A2A44;
    --text-main:            #F8FAFC;
    --text-muted:           #94A3B8;
    --border:               rgba(255,255,255,0.08);
    --border-strong:        rgba(255,255,255,0.15);
    --accent:               #67E8DC;
    --accent-hover:         #4DDDD0;
    --accent-on:            #07111F;
    --accent-subtle:        rgba(103,232,220,0.10);
    --accent-subtle-border: rgba(103,232,220,0.30);
    --btn-primary-bg:       #67E8DC;
    --btn-primary-text:     #07111F;
    --btn-secondary-bg:     #1A2A44;
    --btn-secondary-text:   #F8FAFC;
    --btn-secondary-border: rgba(255,255,255,0.08);
    --input-bg:             #111C2E;
    --input-border:         rgba(255,255,255,0.08);
    --tag-bg:               rgba(103,232,220,0.10);
    --tag-text:             #67E8DC;
    --divider:              rgba(255,255,255,0.08);
    --shadow:               0 4px 24px rgba(0,0,0,0.4);
    --shadow-card:          0 2px 12px rgba(0,0,0,0.3);
    --stat-badge-bg:        rgba(17,28,46,0.5);
    /* Puzzle-page aliases */
    --bg-panel:             #111C2E;
    --accent-soft:          rgba(103,232,220,0.12);
    --active-clue-bg:       rgba(103,232,220,0.12);
    --active-clue-border:   rgba(103,232,220,0.45);
    --disabled-bg:          #16243B;
    --disabled-text:        #5B6B82;
    --grid-line:            #0A1322;
    --grid-cell-bg:         #1B2A45;
    --grid-cell-text:       #F8FAFC;
    --grid-highlight:       rgba(103,232,220,0.20);
    --grid-focus:           rgba(103,232,220,0.42);
}

/* ── Light theme CSS variables ───────────────────────────────── */
[data-theme="light"] {
    --bg-main:              #F5F7FB;
    --bg-header:            #FFFFFF;
    --bg-card:              #FFFFFF;
    --bg-card-secondary:    #F1F5F9;
    --text-main:            #0F172A;
    --text-muted:           #64748B;
    --border:               #DCE3EC;
    --border-strong:        #CBD5E1;
    --accent:               #14B8A6;
    --accent-hover:         #0F9B8B;
    --accent-on:            #FFFFFF;
    --accent-subtle:        rgba(20,184,166,0.10);
    --accent-subtle-border: rgba(20,184,166,0.35);
    --btn-primary-bg:       #14B8A6;
    --btn-primary-text:     #FFFFFF;
    --btn-secondary-bg:     #FFFFFF;
    --btn-secondary-text:   #111827;
    --btn-secondary-border: #CBD5E1;
    --input-bg:             #FFFFFF;
    --input-border:         #CBD5E1;
    --tag-bg:               rgba(20,184,166,0.10);
    --tag-text:             #0F766E;
    --divider:              #E2E8F0;
    --shadow:               0 4px 24px rgba(0,0,0,0.07);
    --shadow-card:          0 2px 12px rgba(0,0,0,0.06);
    --stat-badge-bg:        #F8FAFC;
    /* Puzzle-page aliases */
    --bg-panel:             #FFFFFF;
    --accent-soft:          #E6FFFA;
    --active-clue-bg:       #E6FFFA;
    --active-clue-border:   #14B8A6;
    --disabled-bg:          #EEF2F7;
    --disabled-text:        #94A3B8;
    --grid-line:            #334155;
    --grid-cell-bg:         #FFFFFF;
    --grid-cell-text:       #0F172A;
    --grid-highlight:       #CCFBF1;
    --grid-focus:           #5EEAD4;
}

/* ============================================================
   LIGHT MODE: Homepage Tailwind class overrides
   Applied when [data-theme="light"] is set on <html>
   Uses !important to beat the dark body.homepage overrides above
   ============================================================ */

/* ── Page & layout ────────────────────────────────────────────── */
[data-theme="light"] body.homepage {
    background: var(--bg-main) !important;
    color: var(--text-main) !important;
}

[data-theme="light"] body.homepage nav {
    background: rgba(255,255,255,0.95) !important;
    border-bottom-color: var(--border) !important;
    box-shadow: 0 1px 0 var(--border) !important;
}

[data-theme="light"] body.homepage section {
    background: transparent !important;
    border: none !important;
    box-shadow: none !important;
}

/* ── Tailwind bg-* overrides ──────────────────────────────────── */
[data-theme="light"] body.homepage .bg-background      { background-color: var(--bg-main)  !important; }
[data-theme="light"] body.homepage .bg-surface         { background-color: var(--bg-card)  !important; }
[data-theme="light"] body.homepage .bg-surface-bright  { background-color: var(--bg-card-secondary) !important; }

/* Transparent overlays */
[data-theme="light"] body.homepage header.relative { box-shadow: 0 2px 20px rgba(0,0,0,0.06) !important; border-color: var(--border) !important; }
[data-theme="light"] body.homepage .bg-background\/60 { background-color: rgba(245,247,251,0.50) !important; }
[data-theme="light"] body.homepage .bg-surface\/50     { background-color: var(--stat-badge-bg) !important; }
[data-theme="light"] body.homepage .bg-surface\/80     { background-color: rgba(255,255,255,0.95) !important; }
[data-theme="light"] body.homepage .bg-primary\/5      { background-color: rgba(20,184,166,0.04) !important; }
[data-theme="light"] body.homepage .bg-primary\/10     { background-color: rgba(20,184,166,0.10) !important; }
[data-theme="light"] body.homepage .bg-primary\/20     { background-color: rgba(20,184,166,0.15) !important; }

/* Primary accent */
[data-theme="light"] body.homepage .bg-primary         { background-color: var(--btn-primary-bg) !important; }

/* ── Text colors ──────────────────────────────────────────────── */
[data-theme="light"] body.homepage .text-on-background { color: var(--text-main) !important; }
[data-theme="light"] body.homepage .text-on-surface     { color: var(--text-main) !important; }
[data-theme="light"] body.homepage .text-on-surface-variant { color: var(--text-muted) !important; }
[data-theme="light"] body.homepage .text-on-primary    { color: var(--btn-primary-text) !important; }
[data-theme="light"] body.homepage .text-primary       { color: var(--accent) !important; }

/* ── Border colors ────────────────────────────────────────────── */
[data-theme="light"] body.homepage .border-outline-variant { border-color: var(--border) !important; }
[data-theme="light"] body.homepage .border-primary        { border-color: var(--accent) !important; }
[data-theme="light"] body.homepage .border-primary\/20    { border-color: rgba(20,184,166,0.30) !important; }
[data-theme="light"] body.homepage .border-primary\/50    { border-color: rgba(20,184,166,0.50) !important; }
[data-theme="light"] body.homepage .divide-outline-variant > * + * { border-color: var(--border) !important; }

/* ── Section headings ─────────────────────────────────────────── */
[data-theme="light"] body.homepage .puzzles-section h2,
[data-theme="light"] body.homepage .category-section h2,
[data-theme="light"] body.homepage .difficulty-section h2 {
    color: var(--text-main) !important;
}

/* ── Navbar links & buttons ───────────────────────────────────── */
[data-theme="light"] body.homepage #stats-link {
    background: var(--bg-card-secondary) !important;
    border-color: var(--border) !important;
    color: var(--text-main) !important;
}
[data-theme="light"] body.homepage #stats-link:hover {
    background: var(--border) !important;
}

/* ── Theme toggle button ──────────────────────────────────────── */
[data-theme="light"] #theme-toggle {
    background: var(--bg-card-secondary) !important;
    border-color: var(--border) !important;
    color: var(--text-muted) !important;
}
[data-theme="light"] #theme-toggle:hover {
    background: var(--accent-subtle) !important;
    color: var(--accent) !important;
}

/* ── Hero section ─────────────────────────────────────────────── */
[data-theme="light"] body.homepage header .text-on-background,
[data-theme="light"] body.homepage header .text-on-surface,
[data-theme="light"] body.homepage header h1 {
    color: var(--text-main) !important;
}
/* Hero Create Topic Puzzle (secondary) button */
[data-theme="light"] body.homepage #hero-create-puzzle {
    background: var(--btn-secondary-bg) !important;
    color: var(--btn-secondary-text) !important;
    border-color: var(--btn-secondary-border) !important;
}
[data-theme="light"] body.homepage #hero-create-puzzle:hover {
    background: var(--bg-card-secondary) !important;
}

/* ── Stats bar items ──────────────────────────────────────────── */
[data-theme="light"] body.homepage #stats-bar > div {
    background: var(--stat-badge-bg) !important;
    border-color: var(--border) !important;
    box-shadow: var(--shadow-card) !important;
}
[data-theme="light"] body.homepage #stats-bar .border-t { border-color: var(--border) !important; }

/* ── Cards: Daily, Custom Practice, Achievements ─────────────── */
[data-theme="light"] body.homepage .category-card,
[data-theme="light"] body.homepage .difficulty-card,
[data-theme="light"] body.homepage .puzzle-card,
[data-theme="light"] body.homepage .notes-create-card,
[data-theme="light"] body.homepage .ach-chip,
[data-theme="light"] body.homepage .daily-card {
    background: var(--bg-card) !important;
    color: var(--text-main) !important;
    border-color: var(--border) !important;
    box-shadow: var(--shadow-card) !important;
}

/* ── Puzzle card border-t divider ─────────────────────────────── */
[data-theme="light"] body.homepage .puzzle-card .border-t { border-color: var(--border) !important; }

/* Puzzle card hover */
[data-theme="light"] body.homepage .puzzle-card:hover {
    border-color: var(--accent) !important;
    box-shadow: 0 10px 30px rgba(20,184,166,0.12) !important;
}

/* ── Play / action buttons inside cards ───────────────────────── */
/* Start button: now secondary style in light mode */
[data-theme="light"] body.homepage .start-button {
    background: var(--bg-card-secondary) !important;
    border-color: var(--border) !important;
    color: var(--text-main) !important;
}
[data-theme="light"] body.homepage .start-button:hover,
[data-theme="light"] body.homepage .hover\:bg-primary:hover {
    background: var(--btn-primary-bg) !important;
    color: var(--btn-primary-text) !important;
    border-color: var(--btn-primary-bg) !important;
}

/* Daily start button */
[data-theme="light"] body.homepage .daily-start {
    background: var(--btn-primary-bg) !important;
    color: var(--btn-primary-text) !important;
    border: none !important;
}
[data-theme="light"] body.homepage .daily-start:hover {
    background: var(--accent-hover) !important;
}

/* Notes create button */
[data-theme="light"] body.homepage .notes-create-btn,
[data-theme="light"] body.homepage #open-notes-creator {
    background: var(--bg-card-secondary) !important;
    border-color: var(--border) !important;
    color: var(--text-main) !important;
}
[data-theme="light"] body.homepage #open-notes-creator:hover {
    background: var(--btn-primary-bg) !important;
    color: var(--btn-primary-text) !important;
    border-color: var(--btn-primary-bg) !important;
}

/* ── Search / filter bar ──────────────────────────────────────── */
[data-theme="light"] body.homepage .search-input,
[data-theme="light"] body.homepage input[id="puzzle-search"] {
    color: var(--text-main) !important;
    background: transparent !important;
}
[data-theme="light"] body.homepage select {
    color: var(--text-muted) !important;
    background: transparent !important;
}
[data-theme="light"] body.homepage input::placeholder {
    color: var(--text-muted) !important;
}
/* Search bar container */
[data-theme="light"] body.homepage .mb-8 > div:first-child {
    box-shadow: var(--shadow-card) !important;
}

/* ── Tags / chips ─────────────────────────────────────────────── */
[data-theme="light"] body.homepage .bg-surface-bright.border-outline-variant\/50 {
    background-color: var(--bg-card-secondary) !important;
    border-color: var(--border) !important;
    color: var(--text-muted) !important;
}

/* ── Achievement chips ────────────────────────────────────────── */
/* Unlocked: keep accent */
[data-theme="light"] body.homepage .bg-primary\/10.border-primary\/50 {
    background: rgba(20,184,166,0.10) !important;
    border-color: rgba(20,184,166,0.40) !important;
    color: var(--text-main) !important;
}
/* Locked */
[data-theme="light"] body.homepage .bg-surface-bright.border-outline-variant\/30 {
    background: var(--bg-card-secondary) !important;
    border-color: var(--border) !important;
}

/* ── Border-t lines ───────────────────────────────────────────── */
[data-theme="light"] body.homepage .border-t { border-color: var(--border) !important; }

/* ── Footer ───────────────────────────────────────────────────── */
[data-theme="light"] body.homepage footer { color: var(--text-muted) !important; border-color: var(--border) !important; }


/* ── Ambient blobs: slightly reduce opacity in light mode (keep layout intact) ── */
[data-theme="light"] body.homepage .ambient-blobs { opacity: 0.15 !important; }


/* ============================================================
   Polish fixes — light mode targeted overrides
   ============================================================ */

/* Achievement chips: locked chips should look intentionally muted,
   not like disabled form buttons. bg-transparent in light mode. */
[data-theme="light"] body.homepage [class*="border-outline-variant"].bg-transparent {
    background: transparent !important;
    border-color: var(--border) !important;
}

/* Create Puzzle button: use primary teal in light mode for visibility */
[data-theme="light"] body.homepage #open-notes-creator {
    background: var(--btn-primary-bg) !important;
    color: var(--btn-primary-text) !important;
    border-color: var(--btn-primary-bg) !important;
    box-shadow: 0 0 12px rgba(20,184,166,0.15) !important;
}
[data-theme="light"] body.homepage #open-notes-creator:hover {
    background: var(--accent-hover) !important;
    border-color: var(--accent-hover) !important;
}


/* Dark mode hero overlay stays dark */
[data-theme="dark"] body.homepage .bg-background\/60 {
    background-color: rgba(7,17,31,0.60) !important;
}
