/* style.css */

/* ===============================
   1. DESIGN TOKENS
================================ */
:root {
    --bg-body: #eef1ea;
    --bg-section: #fffdf8;
    --bg-elevated: rgba(255, 253, 248, 0.78);
    --bg-hero: radial-gradient(circle at top left, #f4cf7b 0%, #d97f46 32%, #1d4c58 100%);

    --text-main: #263036;
    --text-header: #101819;
    --text-muted: #627175;

    --border-color: #d7d2c7;

    --grid-bg: #444;
    --cell-bg: #ffffff;
    --cell-text: #000;
    --cell-block: #222;
    --cell-number: #777;

    --highlight-active: #ffe082;
    --highlight-word: #fff8c6;
    --cell-updating: #e3f2fd;
    --cell-correct-bg: #cfead2;
    --cell-correct-text: #15381b;
    --cell-incorrect-bg: #f8d9d8;
    --cell-incorrect-line: #8b2220;

    --primary: #a34319;
    --primary-hover: #873512;

    --secondary: #1f6670;
    --secondary-hover: #184f57;

    --success: #3f7d45;
    --danger: #b7413e;
    --accent: #db8a4a;
    --play: #3f5f8d;

    --status-bg: #f8f4ec;
    --status-text: #222;

    --dropdown-bg: #fffdf8;
    --dropdown-hover: #f0ebe0;

    --cell-size: 36px;
    --nav-height: 60px;
    --home-shadow: 0 20px 40px rgba(16, 24, 25, 0.12);
}

/* ===============================
   DARK MODE
================================ */
body.dark-mode {
    --bg-body: #121212;
    --bg-section: #1e1e1e;
    --bg-elevated: rgba(30, 30, 30, 0.82);
    --bg-hero: radial-gradient(circle at top left, #8b4d12 0%, #4d2a3c 32%, #101f3f 100%);

    --text-main: #e0e0e0;
    --text-header: #ffffff;
    --text-muted: #aaaaaa;

    --border-color: #444;

    --grid-bg: #000;
    --cell-bg: #2c2c2c;
    --cell-text: #fff;
    --cell-block: #000;
    --cell-number: #aaa;

    --highlight-active: #5c4d00;
    --highlight-word: #3d3b20;
    --cell-updating: #1a237e;
    --cell-correct-bg: #244a2c;
    --cell-correct-text: #f4fff4;
    --cell-incorrect-bg: #4f2322;
    --cell-incorrect-line: #ff8a80;

    --status-bg: #000;
    --status-text: #9efc9e;

    --dropdown-bg: #252525;
    --dropdown-hover: #333;
}

/* ===============================
   2. RESET & BASE LAYOUT
================================ */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html, body {
    height: 100%;
}

body {
    font-family: Georgia, 'Times New Roman', serif;
    background: var(--bg-body);
    color: var(--text-main);
    line-height: 1.6;
    transition: background 0.25s ease, color 0.25s ease;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* App Layout (Sticky Footer System) */
.app-container {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

#app-main {
    flex: 1;
}

/* ===============================
   3. NAVBAR
================================ */
.navbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--bg-section);
    padding: 0 2rem;
    height: var(--nav-height);
    border-bottom: 2px solid var(--border-color);
    position: sticky;
    top: 0;
    z-index: 1000;
}

.nav-logo {
    font-size: 1.5rem;
    font-weight: 800;
    letter-spacing: -0.04em;
    color: var(--primary);
    cursor: pointer;
}

.nav-logo:hover {
    opacity: 0.8;
}

.nav-logo:focus-visible,
.nav-btn:focus-visible,
.btn:focus-visible,
.word-list-item:focus-visible,
.search-result-item:focus-visible,
.grid-cell:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
    outline: 3px solid var(--accent);
    outline-offset: 2px;
}

.nav-center {
    display: flex;
    gap: 10px;
}

.nav-btn {
    background: transparent;
    border: none;
    padding: 8px 16px;
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-muted);
    cursor: pointer;
    border-radius: 6px;
    transition: all 0.2s ease;
}

.nav-btn:hover {
    color: var(--text-main);
    background: var(--dropdown-hover);
}

.nav-btn.active {
    color: var(--primary);
    background: rgba(0, 105, 217, 0.1);
}

/* ===============================
   4. VIEW SECTIONS
================================ */
.view-section {
    max-width: 1200px;
    margin: 0 auto;
    padding: 24px;
    animation: fadeIn 0.3s ease-in-out;
}

.hidden {
    display: none !important;
}

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

/* ===============================
   5. HOME
================================ */
.home-hero {
    position: relative;
    overflow: hidden;
    display: grid;
    grid-template-columns: minmax(0, 1.4fr) minmax(280px, 0.9fr);
    gap: 24px;
    align-items: stretch;
    padding: 42px;
    margin-bottom: 24px;
    background: var(--bg-hero);
    color: #fff9ef;
    border-radius: 28px;
    box-shadow: var(--home-shadow);
}

.home-hero::after {
    content: '';
    position: absolute;
    inset: auto -10% -30% auto;
    width: 320px;
    height: 320px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.12);
    filter: blur(4px);
}

.hero-copy {
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.hero-kicker,
.card-eyebrow {
    font-family: 'Trebuchet MS', Helvetica, sans-serif;
    text-transform: uppercase;
    letter-spacing: 0.18em;
    font-size: 0.75rem;
    font-weight: 700;
}

.hero-kicker {
    color: rgba(255, 249, 239, 0.8);
}

.home-hero h1 {
    font-size: clamp(2.8rem, 6vw, 4.8rem);
    line-height: 0.96;
    letter-spacing: -0.05em;
    max-width: 10ch;
}

.hero-subcopy {
    max-width: 42rem;
    color: rgba(255, 249, 239, 0.86);
    font-size: 1.05rem;
}

.hero-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    margin-top: 6px;
}

.home-action-btn {
    min-width: 160px;
}

.hero-spotlight {
    position: relative;
    z-index: 1;
    display: grid;
    gap: 14px;
    align-content: end;
}

.spotlight-card {
    padding: 20px;
    border-radius: 20px;
    backdrop-filter: blur(10px);
    background: rgba(255, 249, 239, 0.12);
    border: 1px solid rgba(255, 249, 239, 0.18);
}

.spotlight-primary {
    transform: translateX(18px);
}

.spotlight-secondary {
    transform: translateX(-10px);
}

.spotlight-label {
    display: inline-block;
    margin-bottom: 8px;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.16em;
    color: rgba(255, 249, 239, 0.72);
}

.spotlight-card strong {
    display: block;
    font-size: 1.15rem;
    line-height: 1.35;
}

.home-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 14px;
    margin-bottom: 24px;
}

.stat-card {
    padding: 18px 20px;
    border-radius: 18px;
    background: var(--bg-elevated);
    border: 1px solid var(--border-color);
    box-shadow: 0 10px 22px rgba(16, 24, 25, 0.05);
}

.stat-value {
    display: block;
    font-family: 'Trebuchet MS', Helvetica, sans-serif;
    font-size: 2rem;
    font-weight: 800;
    color: var(--primary);
    line-height: 1;
}

.stat-label {
    display: block;
    margin-top: 8px;
    color: var(--text-muted);
}

.home-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 20px;
}

.home-grid-featured {
    margin-bottom: 24px;
}

.home-library {
    margin-bottom: 24px;
}

.home-onboarding {
    margin-bottom: 24px;
}

.home-onboarding-card {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.home-onboarding-card h3 {
    margin: 0;
}

.home-library-header {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    gap: 20px;
    margin-bottom: 18px;
}

.home-library-controls {
    align-items: flex-end;
    min-width: min(420px, 100%);
}

.home-library-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 16px;
}

.home-library-card {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.home-library-card h3 {
    margin: 0;
}

.home-dashboard-grid {
    margin-bottom: 24px;
}

.home-dashboard-card {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.home-dashboard-card h2 {
    margin-bottom: 0;
}

.home-daily {
    display: grid;
    grid-template-columns: minmax(0, 1.4fr) auto;
    gap: 20px;
    align-items: center;
    margin-bottom: 24px;
    border: 1px solid rgba(219, 138, 74, 0.28);
    background: linear-gradient(135deg, rgba(255, 248, 238, 0.96), rgba(243, 236, 223, 0.9));
}

.daily-puzzle-copy h2 {
    margin-bottom: 10px;
    border-bottom: none;
    padding-bottom: 0;
}

.daily-puzzle-summary {
    max-width: 52rem;
    color: var(--text-muted);
}

.home-recent .daily-puzzle-summary + .daily-puzzle-summary {
    margin-top: 10px;
}

.daily-puzzle-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    justify-content: flex-end;
}

.info-card {
    background: var(--bg-section);
    padding: 25px;
    border-radius: 20px;
    box-shadow: 0 12px 28px rgba(16, 24, 25, 0.06);
    border: 1px solid rgba(215, 210, 199, 0.8);
}

.feature-card {
    min-height: 220px;
}

.feature-card h2,
.home-flow h2 {
    border-bottom: none;
    padding-bottom: 0;
    margin-bottom: 12px;
}

.home-flow {
    margin-bottom: 24px;
    background: linear-gradient(180deg, rgba(255, 253, 248, 0.88), rgba(244, 236, 221, 0.7));
}

.workflow-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 16px;
}

.workflow-step {
    padding: 18px;
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.68);
    border: 1px solid rgba(215, 210, 199, 0.9);
}

.workflow-number {
    display: inline-block;
    margin-bottom: 10px;
    color: var(--accent);
    font-family: 'Trebuchet MS', Helvetica, sans-serif;
    font-size: 0.9rem;
    font-weight: 800;
    letter-spacing: 0.14em;
}

.workflow-step h3 {
    margin-bottom: 8px;
    color: var(--text-header);
}

/* ===============================
   6. SECTIONS (EDITOR)
================================ */
.section {
    background: var(--bg-section);
    padding: 20px;
    margin-bottom: 20px;
    border-radius: 12px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.05);
}

h2 {
    font-size: 1.2rem;
    margin-bottom: 15px;
    color: var(--text-header);
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 6px;
}

.section-helper {
    margin: -4px 0 14px;
    color: var(--text-muted);
    max-width: 68ch;
}

.compact-helper {
    margin-top: 12px;
    margin-bottom: 0;
    font-size: 0.92rem;
}

.settings-controls,
.mode-controls,
.button-group {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
}

.input-group {
    display: flex;
    align-items: center;
    gap: 8px;
}

.metadata-controls {
    align-items: flex-start;
}

.metadata-field {
    flex-direction: column;
    align-items: stretch;
    min-width: min(240px, 100%);
    flex: 1 1 240px;
}

.metadata-field-wide {
    flex-basis: 100%;
}

.toggle-container {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--bg-body);
}

.solver-theme-group {
    margin-top: 14px;
}

.solver-theme-group input {
    min-width: min(420px, 100%);
}

.solver-metrics {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 12px;
    margin-top: 16px;
}

.solver-diagnostics,
.solver-blacklist-panel {
    margin-top: 16px;
    padding: 14px;
    border: 1px solid var(--border-color);
    border-radius: 10px;
    background: var(--bg-section);
}

.solver-diagnostics {
    font-size: 0.92rem;
    line-height: 1.5;
}

.solver-blacklist-panel h3 {
    margin-bottom: 10px;
}

.solver-blacklist-list {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.blacklist-chip {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 6px 10px;
    border-radius: 999px;
    background: var(--dropdown-hover);
    border: 1px solid var(--border-color);
    font-size: 0.88rem;
}

.blacklist-chip strong {
    font-family: monospace;
    letter-spacing: 0.04em;
}

.blacklist-chip button {
    border: none;
    background: transparent;
    color: var(--danger);
    font-weight: 700;
    cursor: pointer;
}

/* ===============================
   7. BUTTON SYSTEM (FIXED)
================================ */
.btn {
    border: none;
    padding: 8px 14px;
    border-radius: 6px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    color: white;
    font-family: 'Trebuchet MS', Helvetica, sans-serif;
}

/* Primary */
.primary-btn {
    background: var(--primary);
}
.primary-btn:hover {
    background: var(--primary-hover);
}

/* Secondary */
.secondary-btn {
    background: var(--secondary);
}
.secondary-btn:hover {
    background: var(--secondary-hover);
}

/* Success */
.success-btn {
    background: var(--success);
}

/* Danger */
.danger-btn {
    background: var(--danger);
}

/* Accent */
.accent-btn {
    background: var(--accent);
}

/* Solve */
.solve-btn {
    background: var(--play);
}

/* Mode Buttons */
.mode-btn {
    background: var(--bg-body);
    color: var(--text-main);
    border: 1px solid var(--border-color);
}

.mode-btn:hover {
    background: var(--dropdown-hover);
}

/* Active editor mode */
.active-mode {
    outline: 2px solid var(--primary);
    background: var(--primary);
    color: white;
}

/* Symmetry states */
.symmetry-on {
    background: var(--success);
}

.symmetry-off {
    background: var(--secondary);
}

/* Disabled consistency */
button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* ===============================
   8. INPUTS
================================ */
input[type="number"],
input[type="text"],
select,
textarea {
    padding: 8px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background: var(--bg-body);
    color: var(--text-main);
}

textarea {
    resize: vertical;
    min-height: 88px;
}

.clue-composer,
.play-clue-panel {
    margin-bottom: 16px;
    padding: 14px;
    border: 1px solid var(--border-color);
    border-radius: 10px;
    background: color-mix(in srgb, var(--bg-body) 58%, transparent);
}

.clue-composer {
    display: grid;
    gap: 10px;
}

.composer-slot-label {
    font-family: 'Trebuchet MS', Helvetica, sans-serif;
    font-size: 0.8rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.composer-preview {
    font-family: monospace;
}

.play-clue-nav {
    display: flex;
    gap: 8px;
    margin-bottom: 10px;
}

/* ===============================
   9. PLAY TOOLBAR
================================ */
.nyt-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--bg-section);
    padding: 12px 20px;
    border-radius: 10px;
    margin-bottom: 20px;
    border: 1px solid var(--border-color);
}

.timer {
    font-size: 1.4rem;
    font-weight: 700;
    font-family: monospace;
}

.toolbar-right {
    display: flex;
    gap: 8px;
}

.toolbar-btn {
    background: var(--bg-body);
    border: 1px solid var(--border-color);
    padding: 6px 14px;
    border-radius: 20px;
    font-weight: 700;
    font-size: 0.75rem;
    cursor: pointer;
}

.toolbar-btn:hover {
    background: var(--dropdown-hover);
}

/* Dropdown */
.dropdown-wrapper {
    position: relative;
}

.toolbar-dropdown {
    position: absolute;
    top: 110%;
    right: 0;
    background: var(--bg-section);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: 0 8px 16px rgba(0,0,0,0.15);
    z-index: 100;
    display: flex;
    flex-direction: column;
}

.toolbar-dropdown button {
    padding: 10px 15px;
    border: none;
    background: none;
    cursor: pointer;
}

.toolbar-dropdown button:hover {
    background: var(--dropdown-hover);
}

/* ===============================
   10. MAIN GAME LAYOUT
================================ */
.main-content {
    display: grid;
    grid-template-columns: 260px 1fr 300px;
    gap: 20px;
    align-items: start;
}

.editor-workspace {
    grid-template-columns: minmax(220px, 250px) minmax(0, 1fr) minmax(250px, 300px);
}

.puzzle-summary {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 12px;
    margin-bottom: 18px;
}

.summary-item {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 12px 14px;
    border: 1px solid var(--border-color);
    border-radius: 10px;
    background: var(--bg-section);
}

.summary-item-wide {
    grid-column: 1 / -1;
}

.summary-value {
    font-size: 1.2rem;
    font-weight: 700;
}

.summary-label {
    font-size: 0.82rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.editor-workspace .grid-panel,
#game-container .grid-panel {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.editor-workspace .grid-panel h3,
#game-container .grid-panel h3 {
    width: 100%;
}

.status-panel,
.clues-panel,
.grid-panel {
    min-width: 0;
}

#status-display {
    width: 100%;
    min-height: 260px;
    height: 260px;
    padding: 12px;
    border: 1px solid var(--border-color);
    border-radius: 10px;
    background: var(--status-bg);
    color: var(--status-text);
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    resize: vertical;
}

/* ===============================
   11. GRID
================================ */
.grid-container {
    background: var(--grid-bg);
    padding: 15px;
    border-radius: 6px;
    display: flex;
    justify-content: center;
    width: fit-content;
    max-width: 100%;
    margin: 0 auto;
    transition: opacity 0.2s ease;
}

.grid-container.paused-grid {
    opacity: 0.45;
}

.crossword-table {
    border-collapse: separate;
    border-spacing: 2px;
    border: 2px solid var(--grid-bg);
}

.grid-cell {
    width: var(--cell-size);
    height: var(--cell-size);
    background: var(--cell-bg);
    border: 1px solid #aaa;
    position: relative;
    cursor: pointer;
    touch-action: manipulation;
}

.grid-cell[tabindex="0"] {
    box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--accent) 72%, transparent);
}

.grid-cell.block {
    background: var(--cell-block);
}

.cell-number {
    position: absolute;
    top: 2px;
    left: 3px;
    font-size: 9px;
    color: var(--cell-number);
}

.cell-letter {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100%;
    font-size: 20px;
    font-weight: 600;
}

/* ===============================
   12. CLUES
================================ */
.word-list-display {
    border: 1px solid var(--border-color);
    border-radius: 8px;
    height: 320px;
    overflow-y: auto;
}

.list-empty-state {
    margin: 0;
    padding: 12px;
}

.word-list-item {
    width: 100%;
    border: none;
    background: transparent;
    color: var(--text-main);
    text-align: left;
    padding: 8px 12px;
    border-bottom: 1px solid var(--bg-body);
    cursor: pointer;
}

.word-list-item:hover {
    background: var(--dropdown-hover);
}

.word-list-item.selected-clue {
    background: var(--highlight-word);
    border-left: 4px solid var(--play);
    color: var(--text-header);
}

.search-result-item {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 2px;
    padding: 10px 12px;
    border: none;
    border-bottom: 1px solid var(--bg-body);
    background: transparent;
    text-align: left;
    color: var(--text-main);
    cursor: pointer;
}

.search-result-item:hover {
    background: var(--dropdown-hover);
}

.search-result-title {
    font-weight: 700;
    letter-spacing: 0.04em;
}

.search-result-subtitle {
    font-size: 0.86rem;
    color: var(--text-muted);
}

/* ===============================
   13. STATES
================================ */
.grid-cell.active-cell {
    background: var(--highlight-active);
    color: var(--text-header);
}

.grid-cell.active-word {
    background: var(--highlight-word);
    color: var(--text-header);
}

.grid-cell.correct {
    background: var(--cell-correct-bg);
    color: var(--cell-correct-text);
}

.grid-cell.incorrect::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(to top right, transparent 45%, var(--cell-incorrect-line) 50%, transparent 55%);
}

.grid-cell.incorrect {
    background: var(--cell-incorrect-bg);
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }

    .view-section {
        animation: none;
    }
}

/* Better loading state */
.muted-text {
    color: var(--text-muted);
    font-style: italic;
}

/* Builder mode word preview */
.builder-word {
    letter-spacing: 2px;
    font-family: monospace;
}

/* Clue source badge */
.clue-source {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 0.75rem;
    color: var(--bg-section);
    background: var(--secondary);
    margin-top: 6px;
    padding: 2px 8px;
    border-radius: 999px;
}

.clue-source[data-source-kind="authored"] {
    background: var(--primary);
}

.clue-source[data-source-kind="local"] {
    background: var(--success);
}

.clue-source[data-source-kind="web"] {
    background: var(--play);
}

.clue-origin-detail {
    margin-top: 8px;
    font-size: 0.9rem;
}

.play-paused-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.65);
    color: #fff;
    font-size: 1.2rem;
    font-weight: 700;
    border-radius: 12px;
    z-index: 2;
}

#game-container {
    position: relative;
    grid-template-columns: minmax(0, 1fr) minmax(280px, 330px);
    grid-template-areas:
        "grid clues"
        "grid status";
    align-items: start;
}

#game-container .grid-panel {
    grid-area: grid;
}

#game-container .clues-panel {
    grid-area: clues;
}

#game-container .status-panel {
    grid-area: status;
}

#game-container .clues-panel,
#game-container .status-panel {
    margin-top: 0;
}

/* ===============================
   14. FOOTER (STICKY)
================================ */
.footer {
    text-align: center;
    padding: 12px;
    background: var(--bg-section);
    border-top: 1px solid var(--border-color);
    font-size: 0.9rem;
}

/* ===============================
   15. POPUP / MODAL
================================ */
.popup-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    z-index: 9998;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    backdrop-filter: blur(2px);
}

.popup-modal {
    width: min(560px, 100%);
    max-height: 80vh;
    overflow-y: auto;
    background: var(--bg-section);
    color: var(--text-main);
    border-radius: 12px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.25);
    padding: 24px;
    border: 1px solid var(--border-color);
}

.popup-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border-color);
}

.popup-title {
    margin: 0;
    color: var(--text-header);
}

.popup-close-btn {
    border: none;
    background: var(--primary);
    color: white;
    padding: 8px 14px;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 600;
}

.popup-close-btn:hover {
    background: var(--primary-hover);
}

.popup-body {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.popup-entry {
    padding-bottom: 10px;
}

.popup-entry-bordered {
    border-bottom: 1px solid var(--border-color);
}

.popup-clue {
    margin: 0 0 6px 0;
    font-size: 1.05rem;
    line-height: 1.45;
}

.popup-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.popup-source {
    font-size: 0.75rem;
    color: var(--primary);
    font-weight: 700;
    text-transform: uppercase;
}

.popup-date {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.popup-empty {
    color: var(--text-muted);
    font-style: italic;
}

.popup-footer {
    margin-top: 20px;
    padding-top: 14px;
    border-top: 1px solid var(--border-color);
}

.popup-footer-source {
    color: var(--text-muted);
}

@media (max-width: 960px) {
    .home-hero {
        grid-template-columns: 1fr;
        padding: 28px;
    }

    .hero-spotlight {
        grid-template-columns: 1fr 1fr;
        align-content: initial;
    }

    .spotlight-primary,
    .spotlight-secondary {
        transform: none;
    }

    .home-stats,
    .workflow-grid,
    .home-daily {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .editor-workspace {
        grid-template-columns: minmax(0, 1fr);
    }

    #game-container {
        grid-template-columns: 1fr;
        grid-template-areas:
            "grid"
            "clues"
            "status";
    }

    .nyt-toolbar {
        align-items: flex-start;
        gap: 12px;
    }

    .toolbar-right {
        flex-wrap: wrap;
    }

    .toolbar-btn {
        min-height: 42px;
    }
}

@media (max-width: 640px) {
    .navbar {
        padding: 0 1rem;
    }

    .view-section {
        padding: 16px;
    }

    .home-hero {
        padding: 22px;
        border-radius: 22px;
    }

    .home-hero h1 {
        max-width: none;
        font-size: 2.6rem;
    }

    .hero-actions,
    .hero-spotlight,
    .home-stats,
    .workflow-grid,
    .home-daily,
    .daily-puzzle-actions {
        grid-template-columns: 1fr;
    }

    .home-action-btn {
        width: 100%;
    }

    #game-container {
        grid-template-columns: 1fr;
        grid-template-areas:
            "grid"
            "clues"
            "status";
    }

    .nyt-toolbar {
        flex-direction: column;
        align-items: stretch;
    }

    .toolbar-right {
        width: 100%;
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .dropdown-wrapper,
    .toolbar-btn,
    .toolbar-right > button {
        width: 100%;
    }

    .word-list-display {
        height: 240px;
    }

    .grid-container {
        overflow: auto;
        -webkit-overflow-scrolling: touch;
    }
}

@media print {
    body {
        background: #fff;
        color: #000;
    }

    .navbar,
    .home-hero,
    .home-stats,
    .home-daily,
    .home-library,
    .home-dashboard-grid,
    .mode-section,
    .search-panel,
    .status-panel,
    .solver-diagnostics,
    .solver-blacklist-panel,
    .solver-theme-group,
    .nyt-toolbar,
    .play-paused-overlay,
    .popup-overlay,
    #theme-toggle-button {
        display: none !important;
    }

    .view-section.hidden {
        display: none !important;
    }

    .view-section {
        max-width: none;
        padding: 0;
        animation: none;
    }

    .editor-workspace,
    #game-container {
        display: block;
    }

    .grid-panel,
    .word-list-panel,
    .section {
        box-shadow: none;
        border: none;
        background: #fff;
    }

    .grid-container {
        background: #000;
        padding: 8px;
        overflow: visible;
    }

    .word-list-display {
        height: auto;
        overflow: visible;
        border: none;
    }
}
