/* ==========================================================================
   VERBLE — NYTimes-Elegant Editorial Design
   Semantic Color System (WCAG AA)
   ========================================================================== */

:root {
    /* Background & surface */
    --color-background:   #F5F4F1;
    --color-surface:      #FAF9F6;
    --color-surface-elevated: #FCFBF9;

    /* Text hierarchy */
    --color-primary:     #111827;
    --color-secondary:   #374151;
    --color-muted:       #6B7280;

    /* Borders */
    --color-border:      #D1D5DB;
    --color-border-surface: #B8BDC4;
    --color-border-button: #A8AEBA;
    --color-border-focus: #6B9BEA;

    /* Semantic states */
    --color-success:     #6AAA64;
    --color-eliminated:  #9CA3AF;
    --color-disabled:    #F3F4F6;

    /* Legacy aliases (mapped to new tokens) */
    --paper:             var(--color-background);
    --ink-primary:       var(--color-primary);
    --ink-secondary:     var(--color-secondary);
    --ink-tertiary:      var(--color-muted);
    --surface-neutral:   var(--color-surface);
    --border-light:      var(--color-border);
    --border-mid:        #B8BDC4;
    --border-strong:     var(--color-muted);
    --border-structural: var(--color-border);
    --border-interactive:var(--color-secondary);
    --letter-matched:    var(--color-success);
    --letter-unmatched:  var(--color-eliminated);

    /* Consistent buffer between major sections */
    --section-buffer: 24px;

    /* Theme-dependent (overlay, subtle borders) */
    --color-overlay:       rgba(37, 29, 41, 0.5);
    --color-border-subtle: rgba(209, 213, 219, 0.5);
}

/* ==========================================================================
   Dark theme — Wordle/NYT-style (same tokens, dark palette)
   ========================================================================== */

html[data-theme="dark"] {
    /* Background & surface */
    --color-background:       #121213;
    --color-surface:         #1a1a1b;
    --color-surface-elevated: #242426;

    /* Text hierarchy */
    --color-primary:         #e5e5e5;
    --color-secondary:       #a1a1a1;
    --color-muted:           #6e6e73;

    /* Borders */
    --color-border:          #3a3a3c;
    --color-border-surface:  #48484a;
    --color-border-button:   #545456;
    --color-border-focus:    #5e9ff0;

    /* Semantic states */
    --color-success:         #6aaa64;
    --color-eliminated:      #5c5c5e;
    --color-disabled:        #2c2c2e;

    --color-overlay:         rgba(0, 0, 0, 0.65);
    --color-border-subtle:   rgba(255, 255, 255, 0.08);
}

/* Dark theme: header/footer icons and submit icon — white, lighter default + clear hover */
html[data-theme="dark"] .icon-btn .icon-btn-img {
    filter: brightness(0) invert(1) opacity(0.72);
    transition: filter 0.15s ease;
}
html[data-theme="dark"] .icon-btn:hover .icon-btn-img,
html[data-theme="dark"] .icon-btn:focus-visible .icon-btn-img {
    filter: brightness(0) invert(1) opacity(1);
}
html[data-theme="dark"] #submitBtn .submit-icon {
    filter: brightness(0) invert(1) opacity(0.72);
    transition: filter 0.15s ease;
}
html[data-theme="dark"] #submitBtn:hover:not(:disabled) .submit-icon,
html[data-theme="dark"] #submitBtn:focus-visible .submit-icon {
    filter: brightness(0) invert(1) opacity(1);
}
html[data-theme="dark"] #submitBtn:disabled .submit-icon {
    filter: brightness(0) invert(1) opacity(0.45);
}

/* ==========================================================================
   Reset & Base
   ========================================================================== */

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

html {
    overflow-x: hidden;
    overflow-y: hidden;
    height: 100dvh;
    max-width: 100%;
}

body {
    font-family: 'Outfit', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: var(--color-background);
    height: 100dvh;
    max-height: 100dvh;
    max-width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    padding: calc(20px + env(safe-area-inset-top, 0px)) calc(20px + env(safe-area-inset-right, 0px)) calc(20px + env(safe-area-inset-bottom, 0px)) calc(20px + env(safe-area-inset-left, 0px));
    color: var(--ink-primary);
    overflow-x: hidden;
    overflow-y: hidden;
    overscroll-behavior: none;
    overscroll-behavior-x: none;
    position: relative;
    width: 100%;
    min-width: 0;
}

/* ==========================================================================
   Container — No decorative borders, no radius, no shadow
   ========================================================================== */

.container {
    background: var(--color-background);
    padding: 40px;
    max-width: 600px;
    width: 100%;
    min-width: 0;
    flex: 1;
    min-height: 0;
    max-height: calc(100dvh - 40px);
    display: flex;
    flex-direction: column;
    border-radius: 0;
    overflow-x: hidden;
    overflow-y: hidden;
}

.content-wrapper {
    max-width: 460px;
    width: 100%;
    min-width: 0;
    margin: 0 auto;
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

/* Middle area: always scrollable; header and footer stay fixed */
.main-scroll-area {
    flex: 1;
    min-height: 0;
    min-width: 0;
    overflow-x: hidden;
    overflow-y: hidden;
    display: flex;
    flex-direction: column;
}

/* ==========================================================================
   Puzzle Column — Single centered column for core game area
   ========================================================================== */

.puzzle-column {
    width: 100%;
    min-width: 0;
    max-width: 100%;
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
}

/* ==========================================================================
   Game Container — Flex wrapper for viewport fitting
   ========================================================================== */

#gameContainer {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    width: 100%;
}

/* ==========================================================================
   Header — NYT-style game bar
   ========================================================================== */

#gameHeader.game-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-bottom: 10px;
    margin-bottom: calc(var(--section-buffer) * 2);
    border-bottom: 1px solid var(--color-border);
    flex-shrink: 0;
    gap: 12px;
    min-width: 0;
    max-width: 100%;
}

.game-header-left {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0;
    min-width: 0;
}

h1 {
    font-family: 'Outfit', sans-serif;
    font-size: clamp(1.2em, 4vw, 1.6em);
    color: var(--ink-primary);
    margin-bottom: 0;
    font-weight: 700;
    letter-spacing: -0.02em;
    text-transform: lowercase;
    line-height: 1;
}

.game-header-meta {
    display: flex;
    align-items: baseline;
    gap: 4px;
    color: var(--color-secondary);
    font-size: 0.75em;
    font-weight: 500;
    white-space: nowrap;
    min-width: 0;
    line-height: 1.1;
}

.puzzle-number {
    letter-spacing: 0.16em;
}

.puzzle-separator {
    opacity: 0.6;
}

.dish-name {
    color: var(--color-secondary);
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
}

.game-header-right {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}

.header-icons-desktop {
    display: flex;
    align-items: center;
    gap: 6px;
}

.header-menu-mobile {
    display: none;
    position: relative;
}

.menu-mobile-dropdown {
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 4px;
    min-width: 140px;
    background: var(--color-surface-elevated);
    border: 1px solid var(--color-border);
    border-radius: 4px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    padding: 6px 0;
    z-index: 100;
    display: flex;
    flex-direction: column;
}

.menu-mobile-dropdown button {
    display: block;
    width: 100%;
    padding: 10px 16px;
    text-align: left;
    font-family: inherit;
    font-size: 0.75em;
    font-weight: 600;
    letter-spacing: 0.05em;
    color: var(--color-primary);
    background: none;
    border: none;
    cursor: pointer;
    transition: background 0.15s;
}

.menu-mobile-dropdown button:hover,
.menu-mobile-dropdown button:focus-visible {
    background: var(--color-border);
}

.menu-mobile-dropdown button:focus-visible {
    outline: 2px solid var(--color-border-focus);
    outline-offset: -2px;
}

/* ==========================================================================
   No Puzzle State
   ========================================================================== */

.no-puzzle {
    text-align: center;
    padding: 50px 20px;
    color: var(--color-secondary);
    font-size: 1.1em;
    flex: 1;
}

.no-puzzle p {
    margin-bottom: 25px;
}

.reset-btn {
    padding: 12px 24px;
    font-size: 1em;
    background: var(--color-surface);
    color: var(--color-primary);
    border: 1px solid var(--color-primary);
    border-radius: 6px;
    cursor: pointer;
    font-weight: 600;
    transition: border-color 0.2s, background 0.2s;
}

.reset-btn:hover {
    border-color: var(--color-secondary);
}

.reset-btn:focus-visible {
    outline: 2px solid var(--color-border-focus);
    outline-offset: 2px;
}

.reset-btn:active {
    background: var(--color-border);
}

/* ==========================================================================
   Puzzle Section — Vertical stack with per-row stars
   ========================================================================== */

.puzzle-section {
    margin-bottom: 25px;
    flex-shrink: 0;
}

.puzzle-label-wrap {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-bottom: 10px;
}

.puzzle-label-wrap .puzzle-label {
    margin-bottom: 0;
}

.countdown-in-label {
    color: var(--color-secondary);
    font-size: 0.7em;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.12em;
}

.countdown-in-label #countdownTimer {
    font-weight: 700;
    color: var(--color-primary);
}

.puzzle-label {
    text-align: left;
    color: var(--color-secondary);
    font-size: 0.7em;
    margin-bottom: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.12em;
}

.puzzle-display {
    background: var(--color-surface-elevated);
    padding: 20px 18px;
    border-radius: 4px;
    border: 1px solid var(--color-border-surface);
}

/* Puzzle display — two lines: adjectives, then noun, both centered */
.puzzle-stack {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
}

.puzzle-line {
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    justify-content: center;
    gap: 2px 6px;
    font-size: clamp(1.15em, 4.2vw, 1.75em);
    font-family: 'Outfit', sans-serif;
    font-weight: 700;
    line-height: 1.4;
    color: var(--color-primary);
}

/* Fixed cell size so letters and green boxes occupy same space (no layout shift) */
.puzzle-letter {
    width: 0.95em;
    height: 0.95em;
    min-width: 20px;
    min-height: 20px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    border-radius: 4px;
    border: 1px solid var(--color-border);
    transition: opacity 0.15s ease;
}

@media (prefers-reduced-motion: reduce) {
    .puzzle-letter {
        transition: none;
    }
}

.puzzle-letter-active {
    opacity: 1;
}

/* Matched letter — blank green box (same cell size as letters) */
.puzzle-letter-matched.puzzle-matched-box {
    background: var(--color-success);
    border-color: var(--color-success);
}

/* Wordle-style flip tile — puzzle (dish); 3D flip with perspective in transform to avoid ancestor overflow flattening */
.puzzle-flip-tile,
.letter-box-flip-tile {
    position: relative;
}

.puzzle-flip-tile {
    width: 0.95em;
    height: 0.95em;
    min-width: 20px;
    min-height: 20px;
    display: inline-block;
    flex-shrink: 0;
    vertical-align: middle;
}

.letter-box-flip-tile {
    width: 30px;
    height: 30px;
    display: inline-block;
    flex-shrink: 0;
    font-size: 0.85em;
    font-weight: 600;
    font-family: 'Outfit', sans-serif;
}

/* Inner fills the tile and rotates; perspective() in transform keeps 3D visible with overflow ancestors.
   Wordle-style top-to-bottom card flip (rotateX). */
.puzzle-flip-inner,
.letter-flip-inner {
    position: absolute;
    inset: 0;
    transform-style: preserve-3d;
    -webkit-transform-style: preserve-3d;
    transition: transform 0.55s cubic-bezier(0.32, 0.72, 0, 1);
    -webkit-transition: transform 0.55s cubic-bezier(0.32, 0.72, 0, 1);
    transform: perspective(800px) rotateX(0deg);
    -webkit-transform: perspective(800px) rotateX(0deg);
}

.puzzle-flip-tile.flipped .puzzle-flip-inner,
.letter-box-flip-tile.flipped .letter-flip-inner {
    transform: perspective(800px) rotateX(180deg);
    -webkit-transform: perspective(800px) rotateX(180deg);
}

.puzzle-flip-front,
.puzzle-flip-back,
.letter-flip-front,
.letter-flip-back {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    border-radius: 4px;
    border: 1px solid var(--color-border);
}

.puzzle-flip-front,
.letter-flip-front {
    background: var(--color-surface);
    color: var(--color-primary);
    font-size: inherit;
    font-weight: 700;
    font-family: inherit;
}

.puzzle-flip-back,
.letter-flip-back {
    background: var(--color-success);
    border-color: var(--color-success);
    transform: rotateX(180deg);
}

.letter-flip-back.letter-flip-back-plain {
    background: var(--color-eliminated);
    border-color: var(--color-eliminated);
}

.puzzle-flip-tile .puzzle-flip-back,
.puzzle-flip-tile .puzzle-flip-front {
    font-size: inherit;
    line-height: 1.4;
}

@media (prefers-reduced-motion: reduce) {
    .puzzle-flip-inner,
    .letter-flip-inner {
        transition: none;
    }
    .puzzle-flip-tile.flipped .puzzle-flip-inner,
    .letter-box-flip-tile.flipped .letter-flip-inner {
        transform: perspective(800px) rotateX(180deg);
    }
}

/* ==========================================================================
   Input Section — Tool, not headline
   ========================================================================== */

.input-section {
    display: flex;
    flex-direction: column;
    margin-bottom: 25px;
    flex-shrink: 0;
    overflow: visible;
}

.input-wrapper {
    display: flex;
    gap: 10px;
    align-items: stretch;
    overflow: visible;
    margin: 0 8px; /* room for focus ring so it isn't clipped by overflow:hidden ancestors */
}

#ingredientInput {
    flex: 1;
    padding: 12px 16px;
    font-size: 1em;
    border: 1px solid var(--color-border-surface);
    border-radius: 4px;
    text-transform: uppercase;
    font-family: 'Outfit', sans-serif;
    background: var(--color-surface-elevated);
    color: var(--color-primary);
    transition: border-color 0.15s;
}

#ingredientInput::placeholder {
    color: var(--color-muted);
    text-transform: none;
    font-style: normal;
}

#ingredientInput:focus {
    outline: none;
}

#ingredientInput:focus-visible {
    outline: 2px solid var(--color-border-focus);
    outline-offset: 2px;
}

#ingredientInput:disabled {
    background: var(--color-disabled);
    border-color: var(--color-border);
    color: var(--color-muted);
    cursor: not-allowed;
    opacity: 1;
}

#submitBtn {
    padding: 10px 18px;
    font-size: 0.75em;
    background: var(--color-surface-elevated);
    color: var(--color-muted);
    border: 1px solid var(--color-border-button);
    cursor: pointer;
    font-weight: 600;
    transition: border-color 0.15s, background 0.15s, color 0.15s;
    border-radius: 4px;
    letter-spacing: 0.05em;
}

#submitBtn:hover:not(:disabled) {
    border-color: var(--color-border-button);
    color: var(--color-secondary);
}

#submitBtn:focus-visible {
    outline: 2px solid var(--color-border-focus);
    outline-offset: 2px;
}

#submitBtn:active:not(:disabled) {
    background: var(--color-border);
}

#submitBtn:disabled {
    background: var(--color-disabled);
    color: var(--color-eliminated);
    border-color: var(--color-border);
    cursor: not-allowed;
    opacity: 1;
}

.submit-icon {
    display: block;
    width: 24px;
    height: 24px;
    object-fit: contain;
}

#submitBtn .submit-icon {
    filter: brightness(0) opacity(0.8);
}

#submitBtn:hover:not(:disabled) .submit-icon,
#submitBtn:focus-visible .submit-icon {
    filter: brightness(0) opacity(1);
}

#submitBtn:disabled .submit-icon {
    filter: brightness(0) opacity(0.4);
}

/* ==========================================================================
   Recipe Section — Subordinate, aligned to column
   ========================================================================== */

.recipe-section {
    margin-bottom: 0;
    flex: 0 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

.recipe-section h2 {
    font-size: 0.7em;
    margin-bottom: 4px;
    color: var(--color-secondary);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.12em;
}

#recipeContainer {
    display: flex;
    flex-direction: column;
    gap: 0;
    flex: 0 1 auto;
    min-height: 0;
    overflow-y: auto;
    padding-bottom: calc(var(--section-buffer) / 2);
}

.recipe-slot {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 0;
    min-height: 44px;
    border-bottom: 1px solid var(--color-border-subtle);
}

.recipe-slot:last-child {
    border-bottom: none;
}

.recipe-number {
    font-size: 0.8em;
    font-weight: 600;
    color: var(--color-muted);
    min-width: 22px;
}

.recipe-item {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
    min-width: 0;
    justify-content: flex-start;
    align-items: center;
}

.recipe-row-star {
    margin-left: 6px;
    font-size: 1em;
    line-height: 1;
    flex-shrink: 0;
}

.recipe-placeholder {
    color: var(--color-muted);
    font-size: 0.85em;
    font-weight: 400;
    min-height: 30px;
    display: flex;
    align-items: center;
}

/* Screen reader only */
.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;
}

/* Inline validation message — one line reserved so layout doesn't shift; right under input */
.input-feedback {
    font-size: 0.8em;
    font-weight: 500;
    line-height: 1.35;
    margin: 4px 8px 0 8px;
    min-height: calc(1.35em - 4px);
    padding-top: 4px;
    padding-bottom: 0;
    text-align: left;
}

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

.input-feedback .input-feedback-review-link {
    color: var(--color-secondary);
    text-decoration: underline;
}
.input-feedback .input-feedback-review-link:hover {
    color: var(--color-primary);
}

/* Keep reserved height when empty so validation message doesn't shift layout */
.input-feedback:empty {
    min-height: calc(1.35em - 4px);
}

.input-feedback.error .input-feedback-text {
    color: var(--color-muted);
}

.input-feedback.highlight .input-feedback-text {
    color: var(--color-muted);
}

/* Header win state */
header.solved .dish-name {
    font-weight: 600;
}

/* ==========================================================================
   Letter Tiles — Semantic colors (unused vs eliminated vs disabled)
   ========================================================================== */

.letter-box {
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.85em;
    font-weight: 600;
    font-family: 'Outfit', sans-serif;
    border-radius: 4px;
    background: var(--color-surface);
    color: var(--color-primary);
    border: 2px solid var(--color-border);
    transition: background 0.15s ease, color 0.15s ease, opacity 0.15s ease;
}

@media (prefers-reduced-motion: reduce) {
    .letter-box {
        transition: none;
    }
}

/* Matched (adj or noun) — success/active */
.letter-box.adj,
.letter-box.noun {
    background: var(--color-success);
    color: var(--color-surface);
    border-color: var(--color-success);
}

/* Eliminated (plain) — muted tone, lighter weight */
.letter-box.plain {
    background: var(--color-eliminated);
    color: var(--color-surface);
    border-color: var(--color-eliminated);
    font-weight: 500;
}

/* Recipe slot during flip animation — empty cells until letters appear at once */
.letter-box.recipe-letter-pending {
    opacity: 0.5;
}

/* Star ingredient display — hidden on main screen, kept for future use */
.star-ingredient {
    display: none;
    font-size: 0.7em;
    font-weight: 600;
    color: var(--color-secondary);
    text-transform: uppercase;
    letter-spacing: 0.12em;
    margin-top: 12px;
    margin-bottom: 4px;
    flex-shrink: 0;
}

/* Food waste display — hidden on main screen, kept for future use */
.food-waste {
    display: none;
    font-size: 0.7em;
    font-weight: 600;
    color: var(--color-secondary);
    text-transform: uppercase;
    letter-spacing: 0.12em;
    margin-top: 6px;
    margin-bottom: 0;
    flex-shrink: 0;
}

/* ==========================================================================
   Footer
   ========================================================================== */

footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-top: calc(var(--section-buffer) / 2);
    margin-top: calc(var(--section-buffer) / 2);
    border-top: 1px solid var(--color-border);
    gap: 12px;
    flex-shrink: 0;
    background: var(--color-background);
    position: relative;
    z-index: 1;
}

.footer-left {
    display: flex;
    gap: 6px;
    align-items: center;
    flex-shrink: 0;
}

#countdownTimer {
    font-weight: 700;
    color: var(--color-primary);
}

/* ==========================================================================
   Navigation Buttons — Editorial, not playful
   ========================================================================== */

.nav-btn {
    padding: 10px 18px;
    font-size: 0.75em;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--color-surface-elevated);
    color: var(--color-muted);
    border: 1px solid var(--color-border-button);
    cursor: pointer;
    font-weight: 600;
    letter-spacing: 0.05em;
    transition: border-color 0.15s, background 0.15s, color 0.15s;
    border-radius: 4px;
}

.nav-btn:hover:not(:disabled) {
    border-color: var(--color-border-button);
    color: var(--color-secondary);
}

.nav-btn:focus-visible {
    outline: 2px solid var(--color-border-focus);
    outline-offset: 2px;
}

.nav-btn:active:not(:disabled) {
    background: var(--color-border);
}

.nav-btn:disabled {
    background: var(--color-disabled);
    color: var(--color-eliminated);
    border-color: var(--color-border);
    cursor: not-allowed;
    opacity: 1;
}

/* Replay button: blue border when puzzle is complete (matches input focus) */
.game-footer .footer-replay-controls .nav-btn.replay-complete {
    outline: 2px solid var(--color-border-focus);
    outline-offset: 0;
}

/* ==========================================================================
   Archive — Scrollable list of past puzzles
   ========================================================================== */

#mainScrollArea .archive-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    width: 100%;
    overflow: hidden;
}

.archive-title {
    font-size: 1.1em;
    font-weight: 600;
    color: var(--color-primary);
    margin-bottom: 12px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    flex-shrink: 0;
}

.archive-controls {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 4px;
    align-items: center;
    margin-bottom: 24px;
    flex-shrink: 0;
}

.archive-controls #archivePrevMonthBtn {
    grid-column: 1;
    justify-self: center;
}

.archive-controls-center {
    grid-column: 2 / 7;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

.archive-controls #archiveNextMonthBtn {
    grid-column: 7;
    justify-self: center;
}

.archive-nav-btn {
    flex-shrink: 0;
}

.archive-select {
    font-family: inherit;
    font-size: 0.95em;
    font-weight: 500;
    color: var(--color-primary);
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 4px;
    padding: 6px 10px;
    cursor: pointer;
}

.archive-select:focus-visible {
    outline: 2px solid var(--color-border-focus);
    outline-offset: 2px;
}

.archive-days-header {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 4px;
    margin-bottom: 6px;
    font-size: 0.75em;
    font-weight: 600;
    color: var(--color-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    text-align: center;
}

.archive-days-header span {
    display: block;
}

.archive-calendar-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    column-gap: 4px;
    row-gap: 18px;
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    align-content: start;
}

.archive-cell-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    min-width: 0;
}

.archive-calendar-tile {
    aspect-ratio: 1;
    width: 100%;
    min-height: 44px;
    min-width: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    background: var(--color-surface);
    border: 2px solid var(--color-border);
    border-radius: 4px;
    font-size: 1.1em;
    padding: 4px;
    overflow: hidden;
}

.archive-tile-main {
    flex-shrink: 0;
    min-width: 0;
    font-weight: 600;
    font-size: 1.4em;
    line-height: 1.2;
}

.archive-tile-q {
    font-size: 1.2em;
    color: var(--color-muted);
}

.archive-tile-bottom {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    margin-top: auto;
    padding-top: 2px;
    font-size: 0.75em;
    min-width: 0;
    flex-shrink: 0;
}

.archive-tile-ll {
    flex-shrink: 0;
}

.archive-tile-lr {
    flex-shrink: 0;
    margin-left: auto;
}

.archive-calendar-tile-empty {
    background: var(--color-background);
    border-color: var(--color-border);
    opacity: 0.7;
}

.archive-calendar-tile-filled {
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s;
}

.archive-calendar-tile-filled:hover {
    border-color: var(--color-border-surface);
    background: var(--color-surface-elevated);
}

.archive-calendar-tile-filled:focus-visible {
    outline: 2px solid var(--color-border-focus);
    outline-offset: 2px;
}

.archive-tile-num {
    font-size: 0.7em;
    font-weight: 600;
    color: var(--color-secondary);
    min-width: 0;
    min-height: 1.2em;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Placeholder reserves space so every row has same height (tile + ID line) */
.archive-tile-num-placeholder {
    visibility: hidden;
}

.archive-list {
    overflow-y: auto;
    overflow-x: hidden;
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.archive-item {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 4px;
    padding: 10px 12px;
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s;
}

.archive-item:hover {
    border-color: var(--color-border-surface);
    background: var(--color-surface-elevated);
}

.archive-item:focus-visible {
    outline: 2px solid var(--color-border-focus);
    outline-offset: 2px;
}

.archive-item-row1 {
    font-size: 0.95em;
    font-weight: 500;
    color: var(--color-primary);
    margin-bottom: 4px;
}

.archive-item-row2 {
    font-size: 0.85em;
    color: var(--color-secondary);
}

.footer-right {
    display: flex;
    gap: 8px;
    flex: 0 0 auto;
    justify-content: flex-end;
}

.footer-replay-controls {
    gap: 6px;
    align-items: center;
}

/* Replay + arrows: same height in footer (nav-btn matches icon-btn) */
.game-footer .footer-replay-controls .nav-btn {
    height: 38px;
    padding-top: 0;
    padding-bottom: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ==========================================================================
   Icon Buttons — No colored backgrounds, editorial
   ========================================================================== */

.icon-btn {
    width: 38px;
    height: 38px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--color-surface-elevated);
    color: var(--color-muted);
    border: 1px solid var(--color-border-button);
    cursor: pointer;
    font-size: 0.75em;
    font-weight: 600;
    letter-spacing: 0.05em;
    transition: border-color 0.15s, background 0.15s, color 0.15s;
    border-radius: 4px;
}

.icon-btn:hover {
    border-color: var(--color-border-button);
    color: var(--color-secondary);
}

.icon-btn:focus-visible {
    outline: 2px solid var(--color-border-focus);
    outline-offset: 2px;
}

.icon-btn:active {
    background: var(--color-border);
}

.icon-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* ==========================================================================
   Modal — Restrained, no decorative borders
   ========================================================================== */

.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--color-overlay);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 4px;
    width: 90%;
    max-width: 600px;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.modal-header {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 24px;
    border-bottom: 1px solid var(--color-border);
}

.modal-header h3 {
    font-size: 1.1em;
    font-weight: 600;
    color: var(--color-primary);
    text-transform: uppercase;
}

.modal-close {
    background: none;
    border: none;
    color: var(--color-secondary);
    font-size: 1.6em;
    cursor: pointer;
    padding: 0;
    line-height: 1;
    transition: color 0.2s;
}

.modal-close:hover {
    color: var(--color-primary);
}

.modal-close:focus-visible {
    outline: 2px solid var(--color-border-focus);
    outline-offset: 2px;
}

.modal-content {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 24px;
    color: var(--color-primary);
}

.modal-content button:focus-visible {
    outline: 2px solid var(--color-border-focus);
    outline-offset: 2px;
}

/* Copy-success modal — compact, no header, centered message */
.modal--copy-success .modal-header {
    display: none;
}
.modal--copy-success .modal {
    max-width: 340px;
}
.modal--copy-success .modal-content {
    text-align: center;
    padding: 28px 24px;
}
.copy-success-message {
    margin: 0;
    font-size: 1em;
    font-weight: 600;
    letter-spacing: 0.02em;
    color: var(--color-primary);
}

/* About modal — paragraph spacing */
.about-content p {
    margin-bottom: 12px;
}
.about-content > p:last-child {
    margin-bottom: 0;
}
.about-content-link {
    color: var(--color-secondary);
    text-decoration: underline;
}
.about-content-link:hover {
    color: var(--color-primary);
}

/* About modal — contact form (matches site inputs/buttons) */
.about-contact-form {
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--color-border);
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-width: 100%;
}
.about-form-label {
    font-size: 0.8em;
    font-weight: 500;
    color: var(--color-secondary);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.about-form-input,
.about-form-textarea {
    font-family: inherit;
    font-size: 0.95em;
    padding: 8px 12px;
    border: 1px solid var(--color-border);
    border-radius: 4px;
    background: var(--color-surface);
    color: var(--color-primary);
}
.about-form-input:focus,
.about-form-textarea:focus {
    outline: none;
}
.about-form-input:focus-visible,
.about-form-textarea:focus-visible {
    outline: 2px solid var(--color-border-focus);
    outline-offset: 2px;
}
.about-form-textarea {
    resize: vertical;
    min-height: 80px;
}
.about-form-submit {
    margin-top: 4px;
    padding: 10px 18px;
    font-size: 0.75em;
    font-weight: 600;
    letter-spacing: 0.05em;
    background: var(--color-surface-elevated);
    color: var(--color-muted);
    border: 1px solid var(--color-border-button);
    border-radius: 4px;
    cursor: pointer;
    align-self: flex-start;
}
.about-form-submit:hover:not(:disabled) {
    border-color: var(--color-border-button);
    color: var(--color-secondary);
}
.about-form-submit:focus-visible {
    outline: 2px solid var(--color-border-focus);
    outline-offset: 2px;
}
.about-form-submit:disabled {
    opacity: 0.7;
    cursor: not-allowed;
}
.about-contact-status {
    margin-top: 8px;
    font-size: 0.9em;
    color: var(--color-secondary);
}
.about-contact-status--error {
    color: var(--color-primary);
}

/* Stats modal */
.stats-content {
    font-size: 0.95em;
}
.stats-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 20px 16px;
    margin-bottom: 28px;
}
.stats-cell {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 6px;
}
.stats-label {
    color: var(--color-secondary);
    font-weight: 500;
    font-size: 0.8em;
    line-height: 1.3;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.stats-value {
    font-weight: 700;
    font-size: 1.75em;
    color: var(--color-primary);
    line-height: 1.2;
}
.stats-reset {
    border-top: 1px solid var(--color-border);
    padding-top: 16px;
    margin-top: 4px;
}
.settings-dark-mode {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding-bottom: 16px;
    margin-bottom: 16px;
    border-bottom: 1px solid var(--color-border);
}
.settings-dark-mode-label {
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.settings-dark-mode-title {
    font-size: 0.9em;
    font-weight: 600;
    color: var(--color-primary);
}
.settings-dark-mode-hint {
    font-size: 0.75em;
    color: var(--color-muted);
}
.settings-toggle {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 24px;
    flex-shrink: 0;
    cursor: pointer;
}
.settings-toggle input {
    opacity: 0;
    width: 0;
    height: 0;
}
.settings-toggle-track {
    position: absolute;
    inset: 0;
    background: var(--color-border);
    border-radius: 12px;
    transition: background 0.2s;
}
.settings-toggle input:checked + .settings-toggle-track {
    background: var(--color-success);
}
.settings-toggle-track::after {
    content: '';
    position: absolute;
    width: 18px;
    height: 18px;
    left: 3px;
    top: 3px;
    background: var(--color-surface-elevated);
    border-radius: 50%;
    transition: transform 0.2s;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}
.settings-toggle input:checked + .settings-toggle-track::after {
    transform: translateX(20px);
}
.settings-toggle input:focus-visible + .settings-toggle-track {
    outline: 2px solid var(--color-border-focus);
    outline-offset: 2px;
}
.settings-content .stats-reset {
    border-top: none;
    margin-top: 0;
    padding-top: 0;
}
.stats-reset-hint {
    margin-bottom: 8px;
    color: var(--color-muted);
    font-size: 0.75em;
    line-height: 1.4;
}
.stats-reset-underline {
    text-decoration: underline;
}
.stats-reset-row {
    display: flex;
    gap: 8px;
    align-items: center;
}
.stats-reset-row input {
    flex: 1;
    max-width: 120px;
    padding: 6px 10px;
    font-size: 0.85em;
    border: 1px solid var(--color-border);
    border-radius: 4px;
    font-family: inherit;
    background: var(--color-surface);
    color: var(--color-primary);
}
.stats-reset-row input::placeholder {
    color: var(--color-muted);
}
.stats-reset-row input:focus {
    outline: none;
}

.stats-reset-row input:focus-visible {
    outline: 2px solid var(--color-border-focus);
    outline-offset: 2px;
}
.stats-reset-btn {
    padding: 6px 12px;
    font-size: 0.75em;
    font-weight: 600;
    letter-spacing: 0.05em;
    background: var(--color-surface);
    color: var(--color-muted);
    border: 1px solid var(--color-border);
    border-radius: 4px;
    cursor: pointer;
}
.stats-reset-btn:hover {
    color: var(--color-secondary);
    border-color: var(--color-border-surface);
}
.icon-btn .icon-btn-img {
    display: block;
    width: 24px;
    height: 24px;
    object-fit: contain;
    pointer-events: none;
}

.icon-btn {
    padding: 0;
}

.icon-btn .icon-btn-img {
    filter: brightness(0) opacity(0.75);
}

.icon-btn:hover .icon-btn-img,
.icon-btn:focus-visible .icon-btn-img {
    filter: brightness(0) opacity(1);
}

/* Help modal — Wordle-style layout */
.help-content {
    font-size: 0.95em;
    line-height: 1.5;
}

.help-title {
    font-size: 1em;
    font-weight: 600;
    color: var(--color-primary);
    margin-bottom: 12px;
}

.help-content p {
    margin-bottom: 12px;
    color: var(--color-primary);
}

/* Remove bottom margin from last child to avoid unnecessary scrollbar */
.help-content > *:last-child {
    margin-bottom: 0;
}

.help-label {
    font-weight: 600;
    margin-top: 16px;
}

.help-content ul {
    margin: 8px 0 12px 1.2em;
    padding-left: 0;
}

.help-example {
    text-align: center;
    margin: 12px 0;
}

.help-image {
    display: block;
    max-width: 100%;
    height: auto;
    border: 1px solid var(--color-border);
    border-radius: 4px;
}

/* Victory modal — message, grid, top ingredient, waste */
.victory-message {
    text-align: center;
    margin-bottom: 16px;
    line-height: 1.4;
}

.victory-grid {
    list-style: decimal;
    list-style-position: outside;
    padding-left: 1.75em;
    margin: 0 0 16px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.victory-grid-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.victory-row-num {
    flex-shrink: 0;
    font-weight: 600;
    color: var(--color-secondary);
    min-width: 1.5em;
}

.victory-row-cells {
    display: flex;
    gap: 4px;
    flex-wrap: nowrap;
    justify-content: flex-start;
}

.victory-row-star {
    margin-left: 4px;
    flex-shrink: 0;
}

.victory-cell {
    width: 20px;
    height: 20px;
    border-radius: 3px;
    border: 2px solid var(--color-border);
}

.victory-cell-unused {
    background: var(--color-surface);
    border-color: var(--color-border);
}

.victory-cell-matched {
    background: var(--color-success);
    border-color: var(--color-success);
}

.victory-cell-unmatched {
    background: var(--color-eliminated);
    border-color: var(--color-eliminated);
}

.victory-star,
.victory-waste {
    text-align: center;
    font-size: 0.85em;
    font-weight: 600;
    color: var(--color-secondary);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    margin-bottom: 6px;
}

.victory-waste {
    margin-bottom: 20px;
}

.victory-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    justify-content: center;
}

.victory-share-btn {
    padding: 10px 18px;
    font-size: 0.75em;
    background: var(--color-surface-elevated);
    color: var(--color-muted);
    border: 1px solid var(--color-border-button);
    cursor: pointer;
    font-weight: 600;
    letter-spacing: 0.05em;
    transition: border-color 0.15s, background 0.15s, color 0.15s;
    border-radius: 4px;
}

.victory-share-btn:hover {
    border-color: var(--color-border-button);
    color: var(--color-secondary);
}

.victory-share-btn:focus-visible {
    outline: 2px solid var(--color-border-focus);
    outline-offset: 2px;
}

.victory-share-btn:active {
    background: var(--color-border);
}

/* ==========================================================================
   Mobile — pull-to-refresh, keyboard handling
   ========================================================================== */

@media (max-width: 768px) {
    /* Allow pull-to-refresh: body scroll root; no horizontal scroll or swipe */
    html {
        overflow-x: hidden;
        overflow-y: scroll;
        -webkit-overflow-scrolling: touch;
        max-width: 100%;
    }

    body {
        overflow-x: hidden;
        overflow-y: scroll;
        overscroll-behavior-y: auto;
        overscroll-behavior-x: none;
        min-height: 100dvh;
        max-height: none;
        max-width: 100%;
        justify-content: flex-start;
        -webkit-overflow-scrolling: touch;
        touch-action: pan-y pinch-zoom;
    }

    /* 1px overflow enables pull-to-refresh when content fits viewport */
    .container {
        margin-bottom: 1px;
    }

    /* When keyboard open: footer hidden, body scrollable so input stays visible */
    html.keyboard-open body {
        overflow-y: auto;
    }

    /* When keyboard closed: no inner scroll so only body is scroll root (PTR); JS prevents scroll */
    #gameContainer {
        overflow-y: hidden;
    }
    /* When keyboard open: middle can scroll so input can stay visible */
    html.keyboard-open #gameContainer {
        overflow-y: auto;
        overscroll-behavior-y: auto;
        -webkit-overflow-scrolling: touch;
    }
    .archive-calendar-grid {
        overscroll-behavior-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* Compact layout for phones so whole game fits without scrolling */
    /* Spacing scaled ~0.45× from desktop to maintain proportional rhythm */
    .container {
        max-height: 100dvh;
        max-width: 100%;
    }
    .content-wrapper {
        max-width: 100%;
    }
    .main-scroll-area,
    #gameContainer,
    .archive-container {
        max-width: 100%;
    }

    :root {
        --section-buffer: 14px;
    }

    /* Extra space between header and game content */
    #gameHeader.game-header {
        margin-bottom: calc(var(--section-buffer) * 1.5);
        padding-bottom: 8px;
    }

    /* Mobile: one hamburger menu instead of four icons */
    .header-icons-desktop {
        display: none;
    }
    .header-menu-mobile {
        display: block;
    }
    .menu-mobile-dropdown[hidden] {
        display: none !important;
    }

    /* Footer: replay arrow buttons same size as ARCHIVE/TODAY on mobile */
    .game-footer .footer-left .nav-btn {
        min-height: 36px;
    }
    .game-footer .footer-replay-controls .icon-btn {
        width: 36px;
        height: 36px;
        min-width: 36px;
        min-height: 36px;
    }
    .game-footer .footer-replay-controls .nav-btn {
        height: 36px;
        padding-top: 0;
        padding-bottom: 0;
    }

    .puzzle-section {
        margin-bottom: 12px;
    }

    .puzzle-display {
        padding: 14px 12px;
    }

    .input-section {
        margin-bottom: 12px;
    }

    .recipe-section h2 {
        margin-bottom: 4px;
    }

    #recipeContainer {
        gap: 2px;
    }

    .recipe-slot {
        min-height: 32px;
        padding: 6px 0;
    }

    .star-ingredient,
    .food-waste {
        margin-top: 6px;
        margin-bottom: 2px;
    }

    /* Stats and Settings modals: no horizontal scroll; reset input stays above keyboard via JS */
    .stats-content,
    .settings-content {
        overflow-x: hidden;
        min-width: 0;
    }
    .modal-content {
        overflow-x: hidden;
    }

    /* Stats icon: show without filter so it doesn’t render as black box */
    .icon-btn .icon-btn-img {
        filter: none;
        opacity: 0.75;
    }
    .icon-btn:hover .icon-btn-img {
        filter: none;
        opacity: 1;
    }
    /* Dark mode: keep icons white on small viewports too */
    html[data-theme="dark"] .icon-btn .icon-btn-img {
        filter: brightness(0) invert(1) opacity(0.72);
        transition: filter 0.15s ease;
    }
    html[data-theme="dark"] .icon-btn:hover .icon-btn-img,
    html[data-theme="dark"] .icon-btn:focus-visible .icon-btn-img {
        filter: brightness(0) invert(1) opacity(1);
    }

    /* Archive tiles: keep content inside borders on small viewports */
    .archive-calendar-tile {
        padding: 2px;
        min-height: 36px;
    }
    .archive-tile-main {
        font-size: 1.1em;
    }
    .archive-tile-bottom {
        font-size: 0.65em;
    }
    .archive-tile-num {
        font-size: 0.6em;
    }
}

/* ==========================================================================
   Responsive
   ========================================================================== */

@media (max-width: 600px) {
    .container {
        padding: 22px 18px;
    }

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

    h1 {
        font-size: 1.8em;
    }

    .puzzle-line {
        font-size: 1.4em;
    }

    /* Mobile: arrow button inline with input to save vertical space */

    .input-wrapper {
        flex-direction: row;
    }

    #submitBtn {
        width: auto;
        min-width: 48px;
        padding: 0 14px;
        flex-shrink: 0;
    }

    .letter-box {
        width: 26px;
        height: 26px;
        font-size: 0.75em;
    }

    .victory-cell {
        width: 18px;
        height: 18px;
    }

    #recipeContainer {
        gap: 4px;
    }

    .recipe-slot {
        padding: 5px 0;
        min-height: 32px;
    }

    footer {
        flex-wrap: nowrap;
        gap: 8px;
    }

    .footer-left {
        flex: 0 1 auto;
        min-width: 0;
    }
}

/* ==========================================================================
   Small Phones — Aggressive scaling for short/narrow screens
   ========================================================================== */

@media (max-width: 480px), (max-height: 700px) {
    body {
        padding: calc(10px + env(safe-area-inset-top, 0px)) calc(10px + env(safe-area-inset-right, 0px)) calc(10px + env(safe-area-inset-bottom, 0px)) calc(10px + env(safe-area-inset-left, 0px));
    }

    .container {
        padding: 16px 14px;
        max-height: calc(100dvh - 20px);
    }

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

    :root {
        --section-buffer: 12px;
    }

    #gameHeader.game-header {
        margin-bottom: calc(var(--section-buffer) * 1.25);
        padding-bottom: 6px;
    }

    h1 {
        font-size: 1.5em;
        margin-bottom: 4px;
    }

    .date-line {
        font-size: 0.8em;
    }

    .puzzle-section {
        margin-bottom: 9px;
    }

    .input-section {
        margin-bottom: 9px;
    }

    .puzzle-label {
        font-size: 0.75em;
        margin-bottom: 5px;
    }

    .puzzle-display {
        padding: 12px 10px;
    }

    .puzzle-line {
        font-size: 1.2em;
    }

    .input-section {
        gap: 8px;
    }

    #ingredientInput {
        padding: 10px 12px;
        font-size: 16px; /* Must be 16px+ to prevent iOS auto-zoom on focus */
    }

    #submitBtn {
        padding: 0 14px;
        min-width: 48px;
        font-size: 1em;
    }

    .recipe-section {
        margin-bottom: 4px;
    }

    .recipe-section h2 {
        font-size: 0.75em;
        margin-bottom: 4px;
    }

    #recipeContainer {
        gap: 2px;
    }

    .recipe-slot {
        padding: 4px 0;
        gap: 8px;
        min-height: 28px;
    }

    .recipe-number {
        font-size: 0.8em;
        min-width: 20px;
    }

    .recipe-item {
        gap: 2px;
    }

    .letter-box {
        width: 22px;
        height: 22px;
        font-size: 0.7em;
        border-radius: 3px;
    }

    .victory-cell {
        width: 16px;
        height: 16px;
    }

    .recipe-placeholder {
        font-size: 0.8em;
    }

    footer {
        gap: 10px;
    }

    .footer-left {
        font-size: 0.75em;
    }

    .icon-btn {
        width: 32px;
        height: 32px;
        font-size: 0.9em;
    }

    .footer-left .nav-btn {
        padding: 8px 14px;
        font-size: 0.75em;
        min-height: 32px;
    }
    .game-footer .footer-replay-controls .icon-btn {
        width: 32px;
        height: 32px;
        min-width: 32px;
        min-height: 32px;
    }
    .game-footer .footer-replay-controls .nav-btn {
        height: 32px;
        padding-top: 0;
        padding-bottom: 0;
    }

    /* Archive tiles: extra compact */
    .archive-calendar-tile {
        min-height: 32px;
        padding: 2px;
    }
    .archive-tile-main {
        font-size: 1em;
    }
    .archive-tile-bottom {
        font-size: 0.6em;
    }
    .archive-tile-num {
        font-size: 0.55em;
    }
}

/* ==========================================================================
   Very Small Screens — Extra compact for tiny phones
   ========================================================================== */

@media (max-height: 600px) {
    body {
        padding: calc(6px + env(safe-area-inset-top, 0px)) calc(6px + env(safe-area-inset-right, 0px)) calc(6px + env(safe-area-inset-bottom, 0px)) calc(6px + env(safe-area-inset-left, 0px));
    }

    .container {
        padding: 12px;
        max-height: calc(100dvh - 10px);
    }

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

    :root {
        --section-buffer: 10px;
    }

    h1 {
        font-size: 1.3em;
        margin-bottom: 2px;
    }

    .puzzle-section {
        margin-bottom: 7px;
    }

    .puzzle-display {
        padding: 10px 8px;
    }

    .puzzle-line {
        font-size: 1.05em;
    }

    #ingredientInput,
    #submitBtn {
        padding: 8px 10px;
    }

    .recipe-section h2 {
        margin-bottom: 4px;
    }

    #recipeContainer {
        gap: 2px;
    }

    .recipe-slot {
        padding: 3px 0;
        min-height: 26px;
    }

    .letter-box {
        width: 20px;
        height: 20px;
        font-size: 0.65em;
    }

    .victory-cell {
        width: 14px;
        height: 14px;
    }

    .icon-btn {
        width: 28px;
        height: 28px;
        font-size: 0.8em;
    }

    .footer-left .nav-btn {
        padding: 6px 12px;
        font-size: 0.75em;
        min-height: 28px;
    }
    .game-footer .footer-replay-controls .icon-btn {
        width: 28px;
        height: 28px;
        min-width: 28px;
        min-height: 28px;
    }
    .game-footer .footer-replay-controls .nav-btn {
        height: 28px;
        padding-top: 0;
        padding-bottom: 0;
    }
}

/* ==========================================================================
   Very Short Phones — Fit game without scrolling (iPhone SE, etc.)
   ========================================================================== */

@media (max-height: 568px) {
    body {
        padding: calc(6px + env(safe-area-inset-top, 0px)) calc(6px + env(safe-area-inset-right, 0px)) calc(6px + env(safe-area-inset-bottom, 0px)) calc(6px + env(safe-area-inset-left, 0px));
    }

    .container {
        padding: 10px;
        max-height: calc(100dvh - 16px);
    }

    :root {
        --section-buffer: 8px;
    }

    h1 {
        font-size: 1.2em;
        margin-bottom: 2px;
    }

    .puzzle-section {
        margin-bottom: 6px;
    }

    .puzzle-display {
        padding: 8px 6px;
    }

    .puzzle-line {
        font-size: 0.95em;
    }

    .recipe-section {
        margin-bottom: 0;
    }

    .recipe-section h2 {
        margin-bottom: 3px;
    }

    .recipe-slot {
        padding: 2px 0;
        min-height: 24px;
    }

    .letter-box {
        width: 18px;
        height: 18px;
        font-size: 0.6em;
    }

    .victory-cell {
        width: 12px;
        height: 12px;
    }

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

    .footer-left .nav-btn {
        padding: 6px 12px;
        font-size: 0.75em;
        min-height: 28px;
    }
    .game-footer .footer-replay-controls .icon-btn {
        width: 28px;
        height: 28px;
        min-width: 28px;
        min-height: 28px;
    }
    .game-footer .footer-replay-controls .nav-btn {
        height: 28px;
        padding-top: 0;
        padding-bottom: 0;
    }
}

/* Very narrow screens — footer wraps when needed */
@media (max-width: 380px) {
    footer {
        flex-wrap: wrap;
    }

    .footer-left {
        flex-basis: 100%;
        order: 2;
        margin-top: 8px;
        justify-content: center;
    }

    .footer-right {
        order: 1;
    }
}
