/* Base styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: var(--font-sans, 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif);
    background: var(--bg);
    color: var(--fg);
    min-height: 100vh;
    padding: 0;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

.main-container { padding: 0 clamp(16px, 4vw, 32px) 32px; }

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

:focus-visible {
    outline: 2px solid var(--focus, var(--accent));
    outline-offset: 3px;
    border-radius: 4px;
}

/* ===== Topbar — base styles in chrome.css, Cornerstone overrides only ===== */
.topbar {
    max-width: 1600px;
    margin: 0 auto 8px;
    padding: 18px clamp(16px, 4vw, 32px);
}
.brand { font-size: 17px; }

/* ===== Arcade footer ===== */
.footer {
    padding: 24px clamp(16px, 4vw, 32px) 32px;
    color: var(--fg-subtle);
    font-size: 0.9rem;
    text-align: center;
    border-top: 1px solid var(--border);
    margin-top: 32px;
}
.footer p { margin: 0; }
.footer a { color: var(--fg-muted); }
.footer a:hover { color: var(--accent); }

/* Layout */
.main-container {
    max-width: 1600px;
    margin: 0 auto;
    display: grid;
    grid-template-columns: 1fr minmax(320px, 400px) minmax(280px, 360px);
    gap: 24px;
    align-items: start;
}

.game-container {
    background: var(--bg-elev);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 30px;
    box-shadow: var(--shadow-md, 0 20px 40px rgba(0,0,0,0.1));
    flex: 1;
    max-width: 700px;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.cornerstone-panel,
.found-panel {
    background: var(--bg-elev);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 30px;
    box-shadow: var(--shadow-md, 0 20px 40px rgba(0,0,0,0.1));
    max-height: 90vh;
    overflow-y: auto;
    position: relative; /* For X button positioning */
}

.cornerstone-panel {
    width: 420px;
}

.found-panel {
    width: 100%;
}

/* Header */
.header {
    text-align: center;
    margin-bottom: 20px;
    position: relative;
}

.title {
    font-size: 2.5em;
    color: var(--fg);
    margin-bottom: 10px;
    font-weight: 700;
}

.subtitle {
    color: var(--fg-muted);
    font-size: 1.1em;
}

/* Game grid - enlarged and more prominent */
.game-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    max-width: 400px;
    margin: 0 auto 20px auto;
    padding: 24px;
    background: var(--bg);
    border-radius: 16px;
    box-shadow: inset 0 2px 8px rgba(0,0,0,0.08);
}

.cell {
    width: 80px;
    height: 80px;
    border: 3px solid var(--border);
    border-radius: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2.2em;
    font-weight: bold;
    color: var(--fg);
    cursor: pointer;
    transition: all 0.2s ease;
    user-select: none;
    background: var(--bg-elev);
    position: relative;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}

.cell:hover {
    border-color: var(--accent);
    transform: scale(1.05);
}

.cell.empty {
    visibility: hidden;
    pointer-events: none;
}

.cell.selected {
    background: var(--accent);
    color: var(--bg-elev);
    border-color: var(--accent);
    transform: scale(1.1);
}

.cell.in-path {
    background: var(--tone-amber-bg);
    border-color: var(--accent);
}


/* Stats container */
.stats-container {
    display: flex;
    gap: 12px;
    margin-bottom: 25px;
    flex-wrap: wrap;
    justify-content: center;
    max-width: 400px;
    width: 100%;
}

.stat-chip {
    flex: 1;
    min-width: 100px;
    background: var(--cs-background);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 16px 12px;
    text-align: center;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
    transition: all 0.2s ease;
}

.stat-chip:hover {
    border-color: var(--cs-primary);
    box-shadow: var(--shadow-sm, 0 4px 12px rgba(0, 0, 0, 0.1));
    transform: translateY(-1px);
}

.stat-value {
    font-size: var(--font-size-24);
    font-weight: 600;
    color: var(--cs-neutral-dark);
    line-height: 1.2;
    margin-bottom: 4px;
    transition: all 0.3s ease;
}

.stat-label {
    font-size: var(--font-size-12);
    color: var(--cs-neutral-medium);
    text-transform: uppercase;
    letter-spacing: 0.025em;
    font-weight: 500;
}

.stat-chip.cornerstone .stat-value {
    color: var(--cs-success);
}

.stat-chip.hints .stat-value {
    color: var(--cs-primary);
}

/* Legacy support - hide old stats container */
.stats {
    display: none;
}

/* Current word display */
.current-word {
    text-align: center;
    margin-bottom: 15px;
    min-height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg);
    border-radius: 12px;
    padding: 0 20px;
    max-width: 400px;
    width: 100%;
}

.word-display {
    font-size: 1.8em;
    font-weight: bold;
    color: var(--fg);
    letter-spacing: 2px;
}

/* Messages */
.message {
    text-align: center;
    margin-bottom: 20px;
    min-height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    max-width: 400px;
    width: 100%;
    font-size: 1.1em;
}

.message.success {
    color: #4299e1;
    font-weight: bold;
}

.message.error {
    color: #ef4444;
    font-weight: bold;
}

.message.cornerstone {
    color: #22c55e;
    font-weight: bold;
    font-size: 1.1em;
}

.word-display.success {
    color: #4299e1;
    font-weight: bold;
}

.word-display.error {
    color: #ef4444;
    font-weight: bold;
}

.word-display.cornerstone {
    color: #22c55e;
    font-weight: bold;
    font-size: 1.1em;
}

/* Found words panel */
.found-words-section h3 {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    color: var(--cs-neutral-dark);
    font-size: var(--font-size-24);
    font-weight: 700;
}

.found-count {
    font-size: var(--font-size-16);
    font-weight: normal;
    color: var(--cs-neutral);
}

.word-categories {
    display: flex;
    flex-direction: column;
    gap: 30px;
}

.word-category {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 20px;
}

.category-title {
    margin-bottom: 15px;
    font-size: var(--font-size-18);
    font-weight: 600;
}

.category-title.cornerstone {
    color: var(--cs-success);
}

.category-title.regular {
    color: var(--cs-accent);
}

.word-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

/* Scrollable found words panel */
.found-panel {
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: var(--cs-neutral-light) #f1f1f1;
}

.found-panel::-webkit-scrollbar {
    width: 8px;
}

.found-panel::-webkit-scrollbar-track {
    background: #f1f1f1;
}

.found-panel::-webkit-scrollbar-thumb {
    background: var(--cs-neutral-light);
    border-radius: 4px;
}

.found-panel::-webkit-scrollbar-thumb:hover {
    background: var(--cs-neutral);
}

.found-word {
    color: white;
    padding: 4px 8px;
    border-radius: 6px;
    font-size: 0.9em;
    cursor: pointer;
    transition: all 0.2s ease;
}

.found-word.cornerstone {
    background: var(--cs-success);
}

.found-word.regular {
    background: var(--cs-accent); /* Darker blue for better contrast */
}

.found-word.cornerstone:hover {
    background: #0f9f67; /* Darker green for hover */
    transform: scale(1.05);
}

.found-word.regular:hover {
    background: #1e40af; /* Darker blue for hover */
    transform: scale(1.05);
}

/* Cornerstone section */
.cornerstone-section {
    margin-bottom: 20px;
    display: flex;
    flex-direction: column;
    height: 100%;
}

.cornerstone-section h3 {
    color: var(--cs-neutral-dark);
    margin-bottom: 15px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: var(--font-size-18);
    font-weight: 600;
}

.cornerstone-count {
    font-size: var(--font-size-16);
    color: var(--cs-neutral-medium);
    font-weight: 500;
}

.cornerstone-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: 400px;
    overflow-y: auto;
    padding-right: 8px;
}

/* Custom Scrollbar for Better UX */
.cornerstone-list::-webkit-scrollbar {
    width: 6px;
}

.cornerstone-list::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 3px;
}

.cornerstone-list::-webkit-scrollbar-thumb {
    background: var(--cs-neutral-light);
    border-radius: 3px;
    transition: background 0.2s;
}

.cornerstone-list::-webkit-scrollbar-thumb:hover {
    background: var(--cs-primary);
}

/* Firefox scrollbar */
.cornerstone-list {
    scrollbar-width: thin;
    scrollbar-color: var(--cs-neutral-light) #f1f1f1;
}

/* Sticky Progress Indicator */
.progress-indicator {
    position: sticky;
    top: 0;
    background: var(--cs-background);
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
    margin-bottom: 8px;
    font-size: var(--font-size-12);
    color: var(--cs-neutral-medium);
    text-align: center;
    z-index: 2;
}

.progress-bar {
    width: 100%;
    height: 4px;
    background: var(--border);
    border-radius: 2px;
    margin-top: 4px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--cs-success), #10b981);
    border-radius: 2px;
    transition: width 0.3s ease;
    width: 0%;
}

.cornerstone-word {
    background: var(--bg);
    color: var(--fg);
    border: 1px solid var(--border);
    padding: 10px 15px;
    border-radius: 8px;
    transition: all 0.2s;
}

.cornerstone-word > div:first-child {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.cornerstone-word.found {
    background: #22c55e;
    color: white;
}

.cornerstone-word-text {
    font-weight: bold;
    font-size: 1.1em;
}

.cornerstone-word.hidden .cornerstone-word-text {
    font-family: monospace;
    letter-spacing: 0.3em;
}

.word-length {
    font-size: 0.9em;
    color: var(--fg-muted);
    margin-left: 10px;
}

.cornerstone-word.found .word-length {
    color: rgba(255, 255, 255, 0.8);
}

.word-definition {
    font-size: 0.85em;
    color: var(--fg-muted);
    margin-top: 8px;
    font-style: italic;
    line-height: 1.4;
    display: block;
}

.cornerstone-word.found .word-definition {
    color: rgba(255, 255, 255, 0.9);
}

.cornerstone-word.definition-selectable {
    cursor: pointer;
    background: var(--tone-amber-bg);
    border: 2px solid var(--accent);
}

.cornerstone-word.definition-selectable:hover {
    background: var(--tone-amber-bg);
    transform: translateX(5px);
}

/* Letter positions */
.letter-position {
    display: inline-block;
    width: 28px;
    height: 28px;
    text-align: center;
    line-height: 28px;
    margin: 0 2px;
    border-radius: 6px;
    font-family: var(--font-mono, 'Courier New', monospace);
    font-weight: bold;
    font-size: 14px;
    box-sizing: border-box;
    border: 2px solid transparent; /* Default transparent border to match revealed letters */
}

.clickable-letter {
    cursor: pointer;
    background: transparent;
    color: var(--fg);
    border: 2px solid transparent;
    transition: all 0.2s;
}

.clickable-letter:hover {
    background: var(--tone-amber-bg);
    transform: translateX(3px);
}

.clickable-letter:active {
    background: var(--tone-amber-bg);
    transform: translateX(1px);
}

.revealed-letter {
    color: var(--fg-muted);
    background: var(--bg);
    border: 2px solid var(--border);
    /* Removed font-weight: bold to prevent width inconsistency */
    /* .letter-position already has font-weight: bold */
}

/* Compact letter selection - maintains visual consistency */
.letter-selection-word {
    background: var(--tone-amber-bg);
    padding: 8px 12px;
    border-radius: 6px;
    border: 2px solid var(--accent);
}

/* Hint section */
.hint-section {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 15px;
    margin-top: 20px;
}

/* Sticky hint section that stays at bottom */
.hint-section-sticky {
    position: sticky;
    bottom: 0;
    background: var(--cs-background);
    border-top: 2px solid var(--border);
    padding: 15px 20px;
    margin-top: auto;
    z-index: 10;
    box-shadow: 0 -2px 10px rgba(0,0,0,0.1);
}

.hint-section-sticky .hint-header h4 {
    margin: 0;
    font-size: 1.1em;
}

.hint-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
}

.hint-count {
    font-size: 1.2em;
    font-weight: bold;
    color: var(--accent);
}

.hint-actions {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.hint-button {
    background: var(--accent);
    color: var(--bg-elev);
    border: none;
    padding: 10px 15px;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: all 0.2s;
}

.hint-button:hover:not(:disabled) {
    background: var(--accent-hover);
    transform: translateX(5px);
}

.hint-button:disabled {
    background: var(--border-strong);
    color: var(--fg-subtle);
    cursor: not-allowed;
    opacity: 0.6;
}

.hint-cost {
    background: rgba(255, 255, 255, 0.2);
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 0.9em;
}

/* Controls */
.controls {
    text-align: center;
    margin-top: 25px;
    max-width: 400px;
    width: 100%;
}

.control-button {
    background: var(--accent);
    color: var(--bg-elev);
    border: none;
    padding: 10px 20px;
    border-radius: 8px;
    font-size: 1em;
    cursor: pointer;
    margin: 0 5px;
    transition: background 0.2s ease;
}

.control-button:hover {
    background: var(--accent-hover);
    filter: brightness(0.95);
}

/* Popups */
.definition-popup {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: var(--bg-elev);
    color: var(--fg);
    border: 1px solid var(--border);
    border-radius: 15px;
    padding: 20px;
    max-width: 400px;
    width: 90%;
    box-shadow: var(--shadow-lg, 0 20px 40px rgba(0,0,0,0.3));
    z-index: 1000;
    display: none;
}

.definition-popup.show {
    display: block;
}

.popup-word {
    font-size: 1.5em;
    font-weight: bold;
    color: var(--accent);
    margin-bottom: 10px;
    text-transform: uppercase;
}

.popup-definition {
    color: var(--fg);
    line-height: 1.5;
    margin-bottom: 15px;
}

.popup-type {
    font-size: 0.9em;
    color: var(--fg-muted);
    margin-bottom: 10px;
}

.popup-type.cornerstone {
    color: var(--cs-success);
    font-weight: bold;
}

.close-btn {
    background: var(--accent);
    color: var(--bg-elev);
    border: none;
    padding: 8px 16px;
    border-radius: 6px;
    cursor: pointer;
    float: right;
    transition: background 0.2s ease;
}

.close-btn:hover {
    background: var(--accent-hover);
    filter: brightness(0.95);
}

.overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    z-index: 999;
    display: none;
}

.overlay.show {
    display: block;
}

/* Clickable hint styles */
.cornerstone-word.clickable-hint {
    cursor: pointer;
    transition: all 0.2s;
    border-left: 3px solid var(--cs-primary);
    padding-left: 12px;
}

.cornerstone-word.clickable-hint:hover {
    background: var(--cs-background-soft);
    transform: translateX(5px);
}

.clickable-letter-global {
    cursor: pointer;
    transition: all 0.2s;
    padding: 2px 4px;
    border-radius: 3px;
    display: inline-block;
    min-width: 1.2em;
    text-align: center;
    background: var(--tone-amber-bg);
    color: var(--tone-amber-fg);
    animation: pulse 2s ease-in-out infinite;
}

.clickable-letter-global:hover {
    background: var(--accent);
    color: var(--bg-elev);
    transform: scale(1.1);
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

.revealed-letter-global {
    background: var(--bg);
    color: var(--fg-muted);
}

/* Topbar action cluster (help + theme toggle) */
.topbar-actions {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

/* Win banner — persistent celebration that stays until the player moves on. */
.win-banner {
    width: 100%;
    max-width: 400px;
    margin: 4px 0 16px;
    padding: 16px 20px;
    background: linear-gradient(135deg, var(--cs-success, #22c55e), #10b981);
    color: white;
    border-radius: 14px;
    text-align: center;
    box-shadow: var(--shadow-md, 0 10px 24px rgba(16, 185, 129, 0.25));
    animation: winBannerPop 0.45s ease-out;
}

.win-banner[hidden] { display: none; }

.win-banner-title {
    font-size: 1.35em;
    font-weight: 700;
    margin-bottom: 4px;
}

.win-banner-sub {
    font-size: 0.95em;
    opacity: 0.95;
    margin-bottom: 12px;
}

.win-banner-cta {
    background: white !important;
    color: #047857 !important;
    font-weight: 600;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.win-banner-cta:hover {
    background: #f0fdf4 !important;
    color: #065f46 !important;
}

@keyframes winBannerPop {
    0%   { transform: translateY(8px) scale(0.96); opacity: 0; }
    100% { transform: translateY(0)   scale(1);    opacity: 1; }
}

/* Side-panel intro line (under each panel heading) */
.panel-intro {
    margin: -6px 0 14px;
    color: var(--fg-muted);
    font-size: 0.9em;
    line-height: 1.45;
}

.hint-help {
    margin: -4px 0 12px;
    color: var(--fg-muted);
    font-size: 0.85em;
    line-height: 1.4;
}

.category-sub {
    color: var(--fg-muted);
    font-weight: 400;
    font-size: 0.85em;
}

/* Help-dialog typography for inline tokens */
.instructions-popup kbd {
    display: inline-block;
    padding: 1px 6px;
    font-family: var(--font-mono, 'Courier New', monospace);
    font-size: 0.85em;
    background: var(--bg);
    border: 1px solid var(--border);
    border-bottom-width: 2px;
    border-radius: 4px;
    color: var(--fg);
}

.instructions-popup code {
    font-family: var(--font-mono, 'Courier New', monospace);
    font-size: 0.9em;
    background: var(--bg);
    padding: 1px 5px;
    border-radius: 4px;
    color: var(--fg-muted);
    letter-spacing: 0.1em;
}

/* Mobile-only content */
.mobile-only {
    display: none;
}

/* Instructions popup */
.instructions-popup {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: var(--bg-elev);
    color: var(--fg);
    border: 1px solid var(--border);
    padding: 30px;
    padding-top: 40px;
    border-radius: 10px;
    box-shadow: var(--shadow-lg, 0 5px 15px rgba(0,0,0,0.3));
    max-width: 500px;
    width: 90%;
    max-height: 90vh;
    overflow-y: auto;
    z-index: 1000;
    display: none;
}

/* Unified modal close button — used by definition, instructions, and the
 * mobile cornerstone / found-words panels. Visible by default; on desktop
 * the side panels override to display: none (see desktop rules below). */
.modal-close-x {
    position: absolute;
    top: 10px;
    right: 10px;
    width: 30px;
    height: 30px;
    background: var(--accent);
    color: var(--bg-elev);
    border: none;
    border-radius: 50%;
    font-size: 20px;
    font-weight: bold;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s ease;
    z-index: 10;
    line-height: 1;
    padding: 0;
}
.modal-close-x:hover {
    background: var(--accent-hover);
    filter: brightness(0.95);
}

/* Side panels are inline on desktop, so their close X stays hidden until
 * the panel is promoted to a mobile popup. */
.cornerstone-panel > .modal-close-x,
.found-panel > .modal-close-x {
    display: none;
}

.instructions-popup.show {
    display: block;
}

.instructions-popup h2 {
    color: var(--accent);
    margin-bottom: 20px;
    text-align: center;
}

.instructions-popup .section {
    margin-bottom: 20px;
}

.instructions-popup .section h3 {
    color: var(--fg);
    margin-bottom: 10px;
    font-size: 1.1em;
}

.instructions-popup ul {
    margin-left: 20px;
    color: var(--fg-muted);
}

.instructions-popup li {
    margin-bottom: 8px;
}

.close-instructions {
    background: var(--accent);
    color: var(--bg-elev);
    border: none;
    padding: 10px 20px;
    border-radius: 6px;
    cursor: pointer;
    display: block;
    margin: 20px auto 0;
    font-size: 16px;
    transition: background 0.2s ease;
}

.close-instructions:hover {
    background: var(--accent-hover);
    filter: brightness(0.95);
}

/* Mobile popup styles */
@media (max-width: 960px) {
    /* Make stat chips clickable on mobile */
    .stat-chip {
        cursor: pointer;
        user-select: none;
    }
    
    .stat-chip:active {
        transform: scale(0.95);
        box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
    }
    
    /* Style panels as popups on mobile */
    .cornerstone-panel.mobile-popup,
    .found-panel.mobile-popup {
        position: fixed;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
        width: 90%;
        max-width: 500px;
        max-height: 85vh;
        z-index: 1001;
        display: block;
        box-shadow: 0 20px 40px rgba(0,0,0,0.3);
        border-radius: 20px;
        animation: popupSlide 0.3s ease-out;
    }
    
    @keyframes popupSlide {
        from {
            transform: translate(-50%, -40%);
            opacity: 0;
        }
        to {
            transform: translate(-50%, -50%);
            opacity: 1;
        }
    }
    
    /* Mobile backdrop */
    .mobile-backdrop {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: rgba(0,0,0,0.5);
        z-index: 1000;
        display: none;
        backdrop-filter: blur(2px);
    }
    
    .mobile-backdrop.show {
        display: block;
    }
    
    /* Show close buttons on mobile popups */
    .cornerstone-panel.mobile-popup > .modal-close-x,
    .found-panel.mobile-popup > .modal-close-x {
        display: flex;
    }
}

/* Modern Responsive Breakpoint with CSS Grid */
@media (max-width: 1200px) {
    .main-container {
        grid-template-columns: 1fr minmax(320px, 380px);
    }
    
    .found-panel {
        display: none;
    }
}

@media (max-width: 960px) {
    .mobile-only {
        display: block;
    }
    
    .main-container {
        grid-template-columns: 1fr;
        gap: 16px;
    }
    
    .cornerstone-panel,
    .found-panel {
        display: none;
    }
    
    .game-container {
        order: 1;
        max-width: 100%;
        width: 100%;
    }
    
    .title {
        font-size: var(--font-size-32);
    }
    
    .stats-container {
        flex-direction: column;
        gap: 8px;
    }
    
    .stat-chip {
        min-width: auto;
    }
}

/* Mobile optimizations — pull the play surface (the grid) above the
   fold by hiding the subtitle, compacting the header, and reducing
   container padding. Topbar + header + grid should fit inside the
   first ~500px on a phone. */
@media (max-width: 480px) {
    .main-container {
        padding: 0 12px 24px;
    }

    .game-container {
        padding: 12px 14px 20px;
    }

    .header {
        margin-bottom: 10px;
    }

    .title {
        font-size: 1.5em;
        margin-bottom: 0;
    }

    .subtitle {
        display: none;
    }

    .game-grid {
        max-width: 360px;
        gap: 14px;
        padding: 20px;
        margin-bottom: 12px;
    }

    .cell {
        width: 75px;
        height: 75px;
        font-size: 2em;
    }
    
    .stats-container {
        gap: 6px;
    }
    
    .stat-chip {
        padding: 12px 8px;
    }
    
    .instructions-popup {
        padding: 20px;
        padding-top: 35px;
        width: 95%;
        max-height: 90vh;
        max-width: 90vw;
        top: 50%;
        overflow-y: auto;
    }
    
    .instructions-popup .modal-close-x {
        top: 5px;
        right: 5px;
    }

    .close-instructions {
        padding: 12px 24px;
    }
}

/* Support for modern viewport units */
@supports (height: 100dvh) {
    .instructions-popup {
        max-height: 90dvh;
    }
}

/* Honour OS-level reduce-motion preference (matches the arcade launcher) */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.001ms !important;
        transition-duration: 0.001ms !important;
    }
}