* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    /* Prevent double-tap zoom on iOS */
    -webkit-tap-highlight-color: transparent;
}

html {
    background-color: var(--bg-color, #764ba2);
    /* Primary theme color (user-customizable). Defaults match legacy blue. */
    --primary-color: #667eea;
    --primary-color-dark: #5568d3;
    --primary-rgb: 102, 126, 234;
    --select-arrow-svg: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23667eea' d='M6 9L1 4h10z'/%3E%3C/svg%3E");
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    min-height: 100vh;
    color: #333;
    margin: 0;
    padding: 0;
}

/* Home Screen */
.home-screen {
    background: var(--bg-color, #764ba2);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
}

.home-content {
    text-align: center;
    max-width: 500px;
    width: 100%;
}

.logo-container {
    margin-bottom: 15px;
    display: flex;
    justify-content: center;
}

.home-logo {
    width: 140px;
    height: auto;
    display: block;
}

.home-title {
    font-size: 3em;
    font-weight: 700;
    margin: 20px 0 10px 0;
    color: #fff;
    letter-spacing: 2px;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.home-title-daily {
    font-family: 'Segoe Script', 'Apple Chancery', 'Monotype Corsiva', 'French Script MT', 'Kunstler Script', 'Brush Script MT', cursive;
    font-weight: 400;
    font-style: normal;
    margin-left: 2px;
}

.home-tagline {
    font-size: 1.1em;
    color: #fff;
    margin-bottom: 30px;
    line-height: 1.5;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

.btn-play {
    background: #000;
    color: #fff;
    padding: 14px 40px;
    font-size: 1.1em;
    font-weight: 600;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
    margin-bottom: 30px;
}

/* Only real hover devices get “lift” — avoids sticky :hover after tap on touch */
@media (hover: hover) and (pointer: fine) {
    .btn-play:hover {
        background: #333;
        transform: translateY(-2px);
        box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
    }
}

.home-date {
    font-size: 0.95em;
    color: #fff;
    font-weight: 500;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

.home-game-info {
    margin: 20px 0;
    color: #fff;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

.home-game-number {
    font-size: 1.3em;
    font-weight: 700;
    margin-bottom: 5px;
}

.home-game-date {
    font-size: 1em;
    font-weight: 500;
}

.home-welcome {
    font-size: 1em;
    font-weight: 500;
    color: #fff;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
    text-align: center;
    margin: 8px 0 0 0;
}

.home-date-links {
    font-size: 0.9em;
    margin-top: 4px;
}

.home-date-links .home-link {
    margin-top: 0;
}

.home-date-sep {
    opacity: 0.8;
    margin: 0 2px;
}

.home-date-testing {
    font-size: 0.85em;
    opacity: 0.85;
    margin-top: 2px;
}

.home-stats {
    display: flex;
    justify-content: space-around;
    margin: 25px 0;
    padding: 15px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    backdrop-filter: blur(10px);
}

.home-stat-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
}

.home-stat-value {
    font-size: 1.8em;
    font-weight: 700;
    color: #fff;
    line-height: 1;
}

.home-stat-label {
    font-size: 0.8em;
    color: rgba(255, 255, 255, 0.9);
    font-weight: 500;
}

.difficulty-selection {
    display: flex;
    gap: 12px;
    justify-content: center;
    align-items: center;
    margin: 30px 0;
    flex-wrap: wrap;
    padding: 0 10px;
}

.admire-puzzle-area {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 12px;
    margin: 30px 0;
    padding: 0 10px;
    width: 100%;
    max-width: 280px;
    margin-left: auto;
    margin-right: auto;
}

.admire-puzzle-area .admire-area-btn {
    width: 100%;
    min-width: 200px;
    padding: 14px 28px;
    font-size: 1.05em;
    font-weight: 600;
    border-radius: 999px;
    box-shadow: none;
    transition: transform 0.2s ease, opacity 0.2s ease;
}

.admire-puzzle-area .admire-area-btn:hover {
    box-shadow: none;
}

.difficulty-label {
    font-size: 1em;
    font-weight: 600;
    color: #fff;
    white-space: nowrap;
}

.difficulty-dropdown {
    padding: 12px 16px;
    font-size: 1em;
    font-weight: 600;
    color: #333;
    background: #fff;
    border: 3px solid var(--primary-color);
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.3s ease;
    min-width: 120px;
    appearance: none;
    background-image: var(--select-arrow-svg);
    background-repeat: no-repeat;
    background-position: right 12px center;
    background-size: 12px;
    padding-right: 40px;
}

.difficulty-dropdown:hover {
    border-color: var(--primary-color-dark);
    box-shadow: 0 2px 8px rgba(var(--primary-rgb), 0.3);
}

.difficulty-dropdown:focus {
    outline: none;
    border-color: var(--primary-color-dark);
    box-shadow: 0 0 0 3px rgba(var(--primary-rgb), 0.2);
}

#start-game-btn {
    padding: 14px 32px;
    font-size: 1.05em;
    font-weight: 600;
    min-width: 120px;
    border-radius: 999px;
    box-shadow: none;
    transition: transform 0.2s ease, opacity 0.2s ease;
}

#start-game-btn:hover:not(:disabled) {
    box-shadow: none;
}

#start-game-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: none;
}

.home-completion-status {
    margin: 20px 0;
    padding: 15px;
    background: rgba(255, 255, 255, 0.15);
    border-radius: 8px;
    color: #fff;
    font-weight: 500;
}

.home-link {
    display: inline-block;
    color: #fff;
    text-decoration: none;
    font-size: 0.95em;
    margin-top: 20px;
    opacity: 0.9;
    transition: opacity 0.2s ease;
}

.home-link:hover {
    opacity: 1;
    text-decoration: underline;
}

.home-user-email {
    color: #fff;
    font-size: 0.95em;
    opacity: 0.9;
    cursor: default;
}

/* Footer: row 1 = How to Play · Stats, row 2 = Login or email (always on its own line) */
.home-footer-links {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    margin-top: 24px;
}

.home-footer-row {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
    gap: 0 10px;
}

.home-footer-links .home-link {
    margin-top: 0;
}

.home-footer-sep {
    color: rgba(255, 255, 255, 0.7);
    font-weight: 300;
    user-select: none;
    padding: 0 10px 0 4px;
}

.home-footer-with-sep {
    display: inline-flex;
    align-items: center;
}

.reset-link {
    color: rgba(255, 255, 255, 0.7);
    font-size: 0.85em;
    margin-top: 10px;
    margin-left: 15px;
}

.reset-link:hover {
    color: rgba(255, 255, 255, 0.9);
}

/* Game Screen */
body.game-active {
    background: var(--bg-color, #764ba2);
    padding: 0;
    margin: 0;
    min-height: 100vh;
}

.game-screen-wrapper {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    background: var(--bg-color, #764ba2);
    padding: 0 5px;
    box-sizing: border-box;
}

.game-toolbar {
    background: transparent;
    padding: 5px 0;
    margin-bottom: 5px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    flex-wrap: nowrap;
}

.game-toolbar-left {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.game-title-toolbar {
    flex-shrink: 0;
    font-weight: 700;
    font-size: 1.1em;
    color: var(--primary-color);
    letter-spacing: 0.5px;
    white-space: nowrap;
}

.toolbar-icons,
.toolbar-links {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 8px;
    flex: 1;
    flex-wrap: nowrap;
    min-width: 0;
}

.toolbar-icon-btn {
    width: 36px;
    height: 36px;
    padding: 0;
    border: none;
    border-radius: 8px;
    background: #fff;
    color: var(--primary-color);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.2s ease;
}

.toolbar-icon-btn:hover {
    opacity: 0.8;
}

.toolbar-icon-svg {
    width: 20px;
    height: 20px;
}

.toolbar-link {
    white-space: nowrap;
    color: #333;
    text-decoration: none;
    font-size: 0.95em;
    cursor: pointer;
    background: none;
    border: none;
    padding: 0;
    font-family: inherit;
    transition: color 0.2s ease;
}

.toolbar-link:hover {
    color: var(--primary-color);
}

.game-day-info {
    flex-shrink: 0;
    font-size: 0.85em;
    color: var(--primary-color);
    font-weight: 600;
    letter-spacing: 0.5px;
    white-space: nowrap;
}

.container {
    background: white;
    border-radius: 20px;
    padding: 30px;
    max-width: 800px;
    width: 100%;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    margin: 0 auto;
    box-sizing: border-box;
}

body.game-active .container {
    flex: 1;
    display: block;
    max-width: 450px;
    width: calc(100% - 10px);
    margin: 5px auto;
    padding: 10px;
    box-sizing: border-box;
}

header {
    text-align: center;
    margin-bottom: 30px;
}

header h1 {
    font-size: 2.5em;
    color: var(--primary-color);
    margin-bottom: 10px;
    font-weight: 700;
}

.subtitle {
    color: #666;
    font-size: 1.1em;
}

.game-info {
    display: flex;
    justify-content: space-around;
    margin-bottom: 8px;
    margin-top: 0;
    padding: 6px 12px;
    background: #f8f9fa;
    border-radius: 10px;
}

/* Compact header for DD mode and post-win (~5px whitespace) */
#game-container.compact-header .game-toolbar {
    padding: 5px 0;
    margin-bottom: 5px;
}

#game-container.compact-header .game-info {
    padding: 5px 12px;
    margin-bottom: 5px;
}

/* Play-again container: extra space between last row of tiles and first buttons (post-game) */
.play-again-container {
    margin-top: 24px;
    margin-bottom: 12px;
}

/* Center post-win / post-game button rows */
.play-again-buttons-centered,
.what-did-i-learn-buttons-centered {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    width: 100%;
    box-sizing: border-box;
}

/* Buttons in 2x2 grids fill their cell (equal width with others) */
.results-two-by-two #what-did-i-learn-results-btn,
.results-two-by-two #see-answers-btn,
.more-two-by-two #learn-see-results-btn {
    width: 100%;
    margin-left: 0;
    margin-right: 0;
}

/* Ensure button row is full width and its content is centered */
.play-again-button-row {
    display: flex;
    gap: 10px;
    justify-content: center;
    flex-wrap: wrap;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
}

.results-two-by-two,
.more-two-by-two {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
}

/* First cell holds More and See Answers (one visible at a time); both fill the cell */
.results-first-cell {
    min-width: 0;
    display: flex;
    align-items: stretch;
}
.results-first-cell .results-btn-equal {
    flex: 1;
    width: 100%;
}

.results-btn-equal,
.more-btn-equal {
    min-width: 0;
    width: 100%;
    box-sizing: border-box;
}

.replay-win-three-buttons {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 10px;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
}

.replay-win-btn-equal {
    min-width: 0;
    width: 100%;
    box-sizing: border-box;
}

/* Scoped centering for game screen button blocks - use full-width wrapper so flex center works */
#game-container .play-again-buttons-centered,
#game-container .what-did-i-learn-buttons-centered {
    width: 100%;
    max-width: 100%;
}

/* Category name on What Did I Just Learn screen – prominent heading */
.what-did-i-learn-category {
    font-size: 1.5em;
    font-weight: 700;
    letter-spacing: 0.02em;
    line-height: 1.3;
    padding: 12px 0 16px;
    min-height: 0;
    box-sizing: border-box;
}

/* Win modal: center primary button and Share/Home/Close row */
.win-modal-primary-btn {
    display: block;
    margin-left: auto;
    margin-right: auto;
}

.win-modal-button-row.win-modal-buttons-centered {
    display: flex;
    gap: 10px;
    justify-content: center;
    flex-wrap: wrap;
    width: 100%;
    box-sizing: border-box;
}

/* Tighter spacing in post-game view so gap between message and buttons matches tile grid (8px) */
#game-container.compact-header #message {
    margin-bottom: 4px;
    min-height: 0;
}

#game-container.compact-header .action-buttons {
    margin-bottom: 0;
}

#game-container.compact-header .play-again-container {
    margin-top: 16px;
    margin-bottom: 12px;
}

/* Same spacing for WDIJL button block (See My Results, Share, Replay, Home) */
#what-did-i-learn-container {
    margin-top: 24px;
    margin-bottom: 12px;
}

#game-container.compact-header #what-did-i-learn-container {
    margin-top: 16px;
}

.info-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
}

.info-item .label {
    font-size: 0.85em;
    color: #666;
    font-weight: 500;
}

.info-item span:last-child {
    font-size: 1.3em;
    font-weight: 700;
    color: var(--primary-color);
}

.game-controls {
    display: flex;
    gap: 10px;
    justify-content: center;
    margin-bottom: 30px;
}

.btn {
    padding: 14px 28px;
    border: none;
    border-radius: 999px;
    font-size: 1em;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.btn:active {
    transform: scale(0.98);
}

.btn:focus {
    outline: none;
}

.btn-primary {
    background: var(--primary-color);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-secondary {
    background: var(--primary-color);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
}

@media (hover: hover) and (pointer: fine) {
    .btn-primary:hover:not(:disabled) {
        background: var(--primary-color-dark);
        transform: translateY(-2px);
        box-shadow: 0 5px 15px rgba(var(--primary-rgb), 0.4);
    }

    .btn-secondary:hover:not(:disabled) {
        background: var(--primary-color-dark);
        transform: translateY(-2px);
        box-shadow: 0 5px 15px rgba(var(--primary-rgb), 0.4);
    }
}

.btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    filter: grayscale(0.3);
}

.game-board {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    row-gap: 8px;
    margin-bottom: 8px;
    perspective: 800px;
    /* min-height removed - will be set dynamically based on difficulty */
}

.tile {
    aspect-ratio: 1;
    background: #e9ecef;
    border: 3px solid #dee2e6;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
    color: #333;
    user-select: none;
    padding: 2px 6px;
    text-align: center;
    word-wrap: break-word;
    line-height: 1.15;
    box-sizing: border-box;
}

.tile-has-image {
    padding: 0;
}

.tile-image {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center;
    border-radius: 12px;
    display: block;
}

.tile.viewing-phase {
    cursor: default;
    pointer-events: none;
}

/* No play-style hover on evaluated tiles (post-round / post-win board) */
.tile:hover:not(.flipped):not(.revealed):not(.viewing-phase):not(.correct):not(.incorrect):not(.answers-view-missed) {
    transform: scale(1.05);
    border-color: var(--primary-color);
    box-shadow: 0 5px 15px rgba(var(--primary-rgb), 0.3);
}

.tile.flipped {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color-dark);
}

.tile.flipped::before {
    content: '?';
    font-size: var(--question-mark-size, clamp(32px, 8vw, 48px));
    color: white;
    font-weight: 600;
    line-height: 1;
}

/* 2x mode: taller tiles, primary on top and secondary below (overlapping) */
.tile-2x {
    position: relative;
    flex-direction: column;
    padding: 0;
    aspect-ratio: 1 / 1.25;
    min-height: 0;
}
.tile-2x .tile-primary,
.tile-2x .tile-secondary {
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    overflow-wrap: break-word;
    word-break: normal;
    overflow: hidden;
    padding: 3px 6px;
    min-width: 0;
}
.tile-2x .tile-primary {
    font-size: 1.05em;
    font-weight: 600;
    flex: 0 0 50%;
    min-height: 0;
}
.tile-2x .tile-secondary {
    font-size: 0.9em;
    color: #555;
    margin-top: 0;
    flex: 0 0 50%;
    min-height: 0;
}
/* When flipped: hide content so ? centers */
.tile-2x.flipped .tile-primary,
.tile-2x.flipped .tile-secondary {
    opacity: 0;
    position: absolute;
    left: 0;
    right: 0;
    pointer-events: none;
    min-height: 0;
}
.tile-2x.flipped .tile-primary { top: 0; height: 50%; }
.tile-2x.flipped .tile-secondary { bottom: 0; height: 50%; }
.tile-2x .tile-primary.correct { background: transparent; }
.tile-2x .tile-primary.incorrect { background: transparent; }
.tile-2x .tile-secondary.correct { background: transparent; }
.tile-2x .tile-secondary.incorrect { background: transparent; }
.tile-2x.partial { border-color: #fd7e14; background: rgba(253, 126, 20, 0.1); }
.tile-2x.correct { background: #d4edda; border-color: #d4edda; }
.tile-2x.incorrect {
    background: #f8d7da;
    border-color: #dc3545;
    color: #721c24;
}
.tile-2x.incorrect .tile-primary,
.tile-2x.incorrect .tile-secondary {
    color: #721c24;
}
.tile-2x.answers-view-missed { background: #e9ecef; border-color: #adb5bd; }

.tile.revealed {
    background: #fff;
    border-color: #28a745;
}

/* Subtle 3D flip when a tile is revealed (A: viewing phase, B: user click) */
@keyframes tile-flip-in {
    from {
        transform: rotateY(90deg);
        opacity: 0.6;
    }
    to {
        transform: rotateY(0);
        opacity: 1;
    }
}

/* Run flip when tile goes from flipped to revealed (covers both viewing phase and user clicks) */
.tile:not(.flipped) {
    animation: tile-flip-in 0.4s ease-out;
}

.tile.matched {
    background: #fff3cd;
    border-color: #ffc107;
    color: #333;
}

.tile.correct {
    background: #d4edda;
    border-color: #28a745;
    color: #155724;
}

.tile.incorrect {
    background: #f8d7da;
    border-color: #dc3545;
    color: #721c24;
    animation: shake 0.5s ease;
}

.tile.answers-view-missed {
    background: #e9ecef;
    border-color: #adb5bd;
    color: #495057;
}

.tile.hint-view {
    background: #e9ecef;
    border-color: #dee2e6;
    color: #333;
}

.tile-2x.hint-view {
    background: #e9ecef;
    border-color: #dee2e6;
}

.tile-2x.hint-view .tile-primary,
.tile-2x.hint-view .tile-secondary {
    background: transparent;
}


@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-10px); }
    75% { transform: translateX(10px); }
}

#message {
    text-align: center;
    padding: 12px 15px;
    border-radius: 8px;
    margin-bottom: 8px;
    font-weight: 600;
    font-size: 1.1em;
    min-height: 0;
    height: auto;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1.4;
    box-sizing: border-box;
}

.action-buttons {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    gap: 20px;
    margin-bottom: 12px;
}

.action-buttons-bottom {
    display: flex;
    flex-direction: row;
    align-items: stretch;
    gap: 12px;
}

.action-bottom-btn {
    min-height: 48px;
    flex: 0 0 auto;
}

.timer-container {
    display: flex;
    align-items: center;
    height: 48px;
}

.timer-display {
    font-size: 1.2em;
    font-weight: 600;
    color: var(--primary-color);
    background: rgba(255, 255, 255, 0.9);
    padding: 8px 16px;
    border-radius: 8px;
    width: 70px;
    text-align: center;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    box-sizing: border-box;
}

#next-btn {
    margin: 0;
}

/* "Next Round" button: match other buttons, no depressed look; yellow border for emphasis */
#next-btn.continue-next-round {
    border: 2px solid #e6b800;
    box-shadow: none;
    box-sizing: border-box;
}
#next-btn.continue-next-round:hover:not(:disabled) {
    border-color: #d4a800;
    box-shadow: 0 5px 15px rgba(var(--primary-rgb), 0.4);
}

#next-btn.highlight-shake {
    background-color: #ffc107;
    border-color: #ffc107;
    color: #000;
    animation: shake 0.5s ease;
    box-shadow: 0 0 15px rgba(255, 193, 7, 0.6);
}

.message.success {
    background: #d4edda;
    color: #155724;
    border: 2px solid #28a745;
}

.message.error {
    background: #f8d7da;
    color: #721c24;
    border: 2px solid #dc3545;
}

.message.info {
    background: #d1ecf1;
    color: #0c5460;
    border: 2px solid #17a2b8;
}

.instructions {
    background: #f8f9fa;
    padding: 20px;
    border-radius: 10px;
    margin-top: 20px;
}

.instructions h3 {
    color: var(--primary-color);
    margin-bottom: 15px;
    font-size: 1.3em;
}

.instructions ol {
    margin-left: 20px;
    line-height: 1.8;
    color: #555;
}

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

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

.guess-modal-content {
    background: white;
    padding: 30px;
    border-radius: 15px;
    max-width: 400px;
    width: 90%;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
}

.guess-modal-content h3 {
    color: var(--primary-color);
    margin-bottom: 10px;
    font-size: 1.5em;
}

.guess-modal-content p {
    color: #666;
    margin-bottom: 20px;
    font-size: 1.1em;
}

#guess-input {
    width: 100%;
    padding: 12px;
    font-size: 1.1em;
    border: 2px solid #dee2e6;
    border-radius: 8px;
    margin-bottom: 20px;
    box-sizing: border-box;
}

#guess-input:focus {
    outline: none;
    border-color: var(--primary-color);
}

.guess-modal-buttons {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
}

/* Modal Styles */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.modal-content {
    background: white;
    border-radius: 12px;
    max-width: 500px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px;
    border-bottom: 1px solid #e0e0e0;
}

.modal-header h2 {
    margin: 0;
    font-size: 1.5em;
    color: #333;
}

.modal-close {
    background: none;
    border: none;
    font-size: 2em;
    color: #666;
    cursor: pointer;
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    transition: color 0.2s ease;
}

.modal-close:hover {
    color: #333;
}

.input-field {
    padding: 10px 12px;
    font-size: 1em;
    border: 1px solid #ccc;
    border-radius: 8px;
    box-sizing: border-box;
}

.input-field:focus {
    outline: none;
    border-color: #764ba2;
    box-shadow: 0 0 0 2px rgba(118, 75, 162, 0.2);
}

.modal-body {
    padding: 20px;
}

/* How to Play: single-spaced text and consistent spacing between paragraphs */
#how-to-play-modal .modal-body {
    line-height: 1.4;
}
#how-to-play-modal .modal-body p,
#how-to-play-modal .modal-body ol {
    margin: 0 0 0.85em 0;
}
#how-to-play-modal .modal-body ol {
    padding-left: 1.4em;
}
#how-to-play-modal .modal-body li {
    line-height: 1.4;
    margin-bottom: 0.2em;
}
#how-to-play-modal .modal-body li:last-child {
    margin-bottom: 0;
}
#how-to-play-modal .modal-body p:last-child {
    margin-bottom: 0;
}

/* Hint buffer screen (interstitial after viewing hint answers or after reveal) */
.hint-buffer-modal {
    background: var(--bg-color, #764ba2);
}
.hint-buffer-modal .hint-buffer-content {
    background: #fff;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
    width: 90%;
    max-width: 420px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    padding: 24px;
    border-radius: 16px;
}
.hint-buffer-title {
    margin: 0;
    font-weight: 600;
    font-size: 1.1em;
    color: #333;
    text-align: center;
}
.hint-buffer-image-wrap {
    width: 100%;
    border-radius: 12px;
    overflow: hidden;
    background: #f8f8f8;
    padding: 12px;
}
.hint-buffer-image {
    display: block;
    width: 100%;
    height: auto;
    max-height: 40vh;
    object-fit: contain;
}
.hint-buffer-copy-panel {
    min-height: 2.5em;
    text-align: center;
    font-size: 1.1em;
    color: #333;
    transition: opacity 1s ease;
}
.hint-buffer-return-wrap {
    position: relative;
    min-height: 52px;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
}
.hint-buffer-countdown {
    position: absolute;
    left: 0;
    right: 0;
    top: 0;
    bottom: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1em;
    font-weight: 600;
    color: var(--primary-color);
    font-variant-numeric: tabular-nums;
    transition: opacity 1s ease;
    pointer-events: none;
}
.hint-buffer-return-link {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    color: #fff;
    font-size: 1.1em;
    font-weight: 600;
    text-decoration: none;
    padding: 14px 28px;
    background: var(--primary-color);
    border-radius: 999px;
    transition: background 0.2s ease, opacity 1s ease;
    opacity: 0;
    pointer-events: none;
}
.hint-buffer-return-link:hover {
    background: var(--primary-color-dark);
}

.setting-item {
    margin-bottom: 20px;
}

.setting-label {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    font-weight: 500;
    color: #333;
}

.setting-checkbox {
    width: 18px;
    height: 18px;
    cursor: pointer;
}

.difficulty-select {
    width: 100%;
    padding: 10px;
    border: 2px solid #ddd;
    border-radius: 8px;
    font-size: 1em;
    background-color: white;
    cursor: pointer;
    transition: border-color 0.2s ease;
}

.difficulty-select:hover {
    border-color: var(--primary-color);
}

.difficulty-select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(var(--primary-rgb), 0.1);
}

.setting-description {
    margin: 8px 0 0 28px;
    font-size: 0.9em;
    color: #666;
    font-style: italic;
}

.color-options {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 10px;
}

.color-option {
    width: 40px;
    height: 40px;
    border-radius: 8px;
    border: 3px solid transparent;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 18px;
    font-weight: bold;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.color-option:hover {
    transform: scale(1.1);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
}

.color-option.selected {
    border-color: #333;
    box-shadow: 0 0 0 2px white, 0 0 0 4px #333;
}

.modal-body ol {
    margin: 0;
    padding-left: 20px;
    line-height: 1.8;
}

.modal-body li {
    margin-bottom: 12px;
    color: #555;
}

/* Win Modal Styles */
.win-modal-content {
    max-width: 500px;
    text-align: center;
}

.win-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 25px 20px 15px 20px;
}

#replay-win-modal .win-header,
#daily-double-modal .win-header {
    justify-content: center;
}

.win-header-with-close {
    justify-content: space-between;
}

.win-header-spacer {
    flex: 1;
    min-width: 0;
}

.win-header-close-wrap {
    display: flex;
    justify-content: flex-end;
    align-items: flex-start;
    flex-shrink: 0;
}

/* Win modal ×: lighter and positioned up/right so it doesn't press against the title */
#win-modal #close-win-modal-x {
    font-size: 1.35em;
    font-weight: 400;
    margin-top: -6px;
    margin-right: -4px;
}

.win-modal-two-buttons {
    display: flex;
    gap: 10px;
    justify-content: center;
    width: 100%;
    flex-wrap: wrap;
}

.win-modal-two-buttons .win-modal-btn-equal {
    flex: 1;
    min-width: 0;
    max-width: none;
}

/* Win modal buttons: avoid wrapping (keeps equal heights on small screens) */
#win-modal .win-modal-two-buttons .win-modal-btn-equal {
    white-space: nowrap;
}

@media (max-width: 420px) {
    #win-modal .win-modal-two-buttons .win-modal-btn-equal {
        font-size: 0.95em;
        padding: 13px 18px;
    }
}

.win-title {
    font-size: 2.2em;
    font-weight: 700;
    color: var(--primary-color);
    margin: 0 0 10px 0;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.win-body {
    padding: 15px 20px 20px 20px;
    display: flex;
    flex-direction: column;
    gap: 15px;
    align-items: center;
}

.alternate-win-content {
    width: 100%;
    text-align: left;
    line-height: 1.5;
}

/* Statistics Section */
.stats-section {
    width: 100%;
}

.stats-title {
    font-size: 0.85em;
    font-weight: 700;
    color: #666;
    text-transform: uppercase;
    letter-spacing: 1px;
    margin: 0 0 10px 0;
    text-align: left;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 15px;
    margin-bottom: 15px;
}

.stat-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
}

.stat-value {
    font-size: 2em;
    font-weight: 700;
    color: #333;
    line-height: 1;
}

.stat-label {
    font-size: 0.75em;
    color: #666;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Daily Double wins: two trophy emojis either side of number */
.daily-double-wins-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.35em;
}

.daily-double-wins-stat .daily-double-wins-row .stat-value {
    margin: 0 0.15em;
}

.daily-double-trophy-emoji {
    font-size: 2.2em;
    line-height: 1;
}

#daily-double-stats-section {
    margin-bottom: 15px;
}

.daily-double-wins-stat {
    gap: 4px;
}

.time-stats-row {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 15px;
    margin-bottom: 10px;
}

.time-stat-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
}

.time-stat-value {
    font-size: 1.3em;
    font-weight: 600;
    color: var(--primary-color);
    line-height: 1;
}

.time-stat-label {
    font-size: 0.75em;
    color: #666;
    text-align: center;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Replay Win Modal - center title, smaller fonts, even horizontal spread */
#replay-win-modal .win-header {
    justify-content: center;
    text-align: center;
}

#replay-win-modal .replay-stat-value {
    font-size: 1.3em;
    font-weight: 600;
    color: var(--primary-color);
}

.replay-stats-grid {
    width: 100%;
    display: grid;
    gap: 15px;
    margin-bottom: 15px;
}

.replay-scores-grid {
    grid-template-columns: 1fr 1fr;
}

.replay-time-grid {
    grid-template-columns: 1fr 1fr 1fr;
    margin-bottom: 10px;
}

.replay-lifetime-grid {
    grid-template-columns: 1fr 1fr 1fr;
}

/* Difficulty Distribution */
.difficulty-distribution-section {
    width: 100%;
    margin-top: 15px;
}

.difficulty-bar-container {
    display: flex;
    width: 100%;
    height: 20px;
    border-radius: 4px;
    overflow: hidden;
    background: #eee;
}

.difficulty-bar-segment {
    transition: width 0.3s ease;
}

.difficulty-bar-segment.easy {
    background: #2ecc71;
}

.difficulty-bar-segment.medium {
    background: #3498db;
}

.difficulty-bar-segment.hard {
    background: #e74c3c;
}

.difficulty-bar-segment.twox {
    background: #b22222;
}

.difficulty-legend {
    display: flex;
    justify-content: center;
    gap: 16px;
    margin-top: 6px;
    font-size: 0.8em;
    color: #666;
}

.difficulty-legend span {
    display: flex;
    align-items: center;
    gap: 4px;
}

.difficulty-legend .swatch {
    width: 10px;
    height: 10px;
    border-radius: 2px;
}

.difficulty-legend .swatch.easy { background: #2ecc71; }
.difficulty-legend .swatch.medium { background: #3498db; }
.difficulty-legend .swatch.hard { background: #e74c3c; }
.difficulty-legend .swatch.twox { background: #b22222; }

/* Solve Distribution */
.solve-distribution-section {
    width: 100%;
    margin-top: 5px;
}

.distribution-chart {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-top: 10px;
}

.distribution-bar-container {
    display: flex;
    align-items: center;
    gap: 10px;
}

.distribution-round-label {
    font-size: 0.9em;
    font-weight: 600;
    color: #333;
    width: 20px;
    text-align: center;
}

.distribution-bar-wrapper {
    flex: 1;
    display: flex;
    align-items: center;
    position: relative;
    height: 20px;
    background: #f0f0f0;
    border-radius: 4px;
    overflow: hidden;
}

.distribution-bar {
    height: 100%;
    background: #6aaa64;
    transition: width 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding-right: 8px;
    min-width: 0;
    position: relative;
}

.distribution-bar-current {
    background: #6aaa64;
    box-shadow: 0 0 0 2px #6aaa64;
}

.distribution-count-label {
    position: absolute;
    right: 8px;
    font-size: 0.85em;
    font-weight: 600;
    color: #333;
    z-index: 1;
    white-space: nowrap;
}

.improve-link {
    color: var(--primary-color);
    text-decoration: none;
    font-size: 0.95em;
    margin: 5px 0;
    transition: color 0.2s ease;
}

.improve-link:hover {
    color: var(--primary-color-dark);
    text-decoration: underline;
}

.share-btn {
    width: 100%;
    max-width: 250px;
    /* Prevent zoom on iOS when tapping */
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

/* Prevent zoom on all buttons on iOS */
.btn {
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

@media (max-width: 600px) {
    .game-board {
        grid-template-columns: repeat(4, 1fr);
        gap: 6px;
    }
    
    /* Don't scale tile label fonts down on small screens — adjustTileFontSize sets px on .tile,
       but 0.9em here was shrinking the cascade and made labels smaller than the pre-refactor look. */
    .tile {
        font-size: 1em;
    }
    
    .game-toolbar {
        padding: 10px 0;
        gap: 24px;
    }
    
    .game-title-toolbar {
        margin-right: 12px;
        font-size: 1em;
    }
    
    .toolbar-links {
        gap: 20px;
    }
    
    .toolbar-link {
        font-size: 0.9em;
    }
    
    body.game-active .container {
        width: calc(100% - 10px);
        margin: 5px auto;
        padding: 10px;
    }
    
    .game-screen-wrapper {
        padding: 0 5px;
    }
    
    .difficulty-selection {
        gap: 8px;
        padding: 0 5px;
    }
    
    .btn-difficulty {
        padding: 12px 8px;
        font-size: 0.85em;
        letter-spacing: 0.3px;
    }
    
    .stats-grid {
        gap: 10px;
    }
    
    .stat-value {
        font-size: 1.6em;
    }
    
    .stat-label {
        font-size: 0.7em;
    }
    
    .time-stats-row {
        gap: 10px;
    }
    
    .time-stat-value {
        font-size: 1.1em;
    }
    
    .time-stat-label {
        font-size: 0.7em;
        text-transform: uppercase;
        letter-spacing: 0.5px;
    }
    
    .win-modal-content {
        max-width: 95%;
    }
}

/* Error Toast Modal */
.error-toast-modal {
    position: fixed;
    top: 80px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 2000;
}

.error-toast-modal.showing {
    animation: slideDown 0.3s ease-out;
}

.error-toast-modal.hiding {
    animation: fadeOut 0.3s ease-out forwards;
}

.error-toast-content {
    background: #333;
    color: white;
    padding: 16px 24px;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    min-width: 280px;
    text-align: center;
}

.error-toast-content p {
    margin: 0;
    font-size: 1em;
    font-weight: 500;
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateX(-50%) translateY(-20px);
    }
    to {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
}

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

.share-success-message {
    display: none;
    background-color: #28a745;
    color: white;
    padding: 12px 20px;
    border-radius: 8px;
    font-size: 16px;
    font-weight: bold;
    text-align: center;
    margin: 15px auto;
    width: calc(100% - 40px);
    max-width: 300px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
}

/* --- Standard mode: horizontal answer strip (v2 drag-and-drop) --- */
.answer-strip-wrap {
    margin: 0 0 8px; /* match tile row gap above/below */
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    gap: 0; /* rely on message panel for instructions */
    position: relative;
    border-radius: 12px;
    overflow: hidden; /* clip fade overlays to rounded corners */
}

.answer-strip-hint {
    font-size: 0.85rem;
    color: rgba(255, 255, 255, 0.88);
    text-align: center;
    margin: 0;
    line-height: 1.35;
    padding: 0 6px;
    display: none;
}

.answer-strip-wrap.answer-strip-drag-target {
    outline: 2px dashed rgba(255, 255, 255, 0.65);
    outline-offset: 4px;
    border-radius: 10px;
}

.answer-strip-row {
    position: relative;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
}

.answer-strip-submit-btn {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    z-index: 6;
    pointer-events: auto;
    white-space: nowrap;
    margin: 0;
    /* Match .answer-strip-chip tiles; stronger focus ring + slightly larger type */
    background: #fff3cd;
    color: #333;
    border: 2px solid rgba(255, 193, 7, 0.55);
    border-radius: 12px;
    font-weight: 600;
    font-size: clamp(14px, 3.2vw, 17px);
    padding: 8px 14px;
    min-height: 56px;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
    outline: 3px solid rgba(255, 255, 255, 0.9);
    outline-offset: 2px;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    transition: background 0.12s ease, box-shadow 0.12s ease, border-color 0.12s ease;
}

.answer-strip-submit-btn:hover:not(:disabled) {
    background: #ffe69c;
    color: #333;
    border-color: rgba(255, 193, 7, 0.85);
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.22);
    transform: translate(-50%, -50%);
}

.answer-strip-submit-btn:active:not(:disabled) {
    transform: translate(-50%, -50%) scale(0.98);
}

.answer-strip-scroll {
    display: flex;
    flex-direction: row;
    flex-wrap: nowrap;
    gap: 10px;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scroll-snap-type: x mandatory;
    padding: 8px 12px;
    margin: 0;
    scrollbar-width: none; /* Firefox: hide scroll indicator */
    touch-action: pan-x;
    background: var(--primary-color); /* match button color (btn-primary) */
    border-radius: 12px;
    min-height: 72px;
    align-items: center;
    border: 1px solid rgba(255, 255, 255, 0.22);
    touch-action: pan-x;
    order: 1;
}

/* Edge fade that affects only tiles (via overlay), not the background.
   Put overlays on the non-scroll wrapper so they don't move with scroll. */
.answer-strip-wrap::before,
.answer-strip-wrap::after {
    content: '';
    position: absolute;
    top: 0;
    bottom: 0;
    width: 28px;
    pointer-events: none;
    z-index: 2;
}

.answer-strip-wrap::before {
    left: 0;
    background: linear-gradient(to right, var(--primary-color) 0%, rgba(var(--primary-rgb), 0) 100%);
}

.answer-strip-wrap::after {
    right: 0;
    background: linear-gradient(to left, var(--primary-color) 0%, rgba(var(--primary-rgb), 0) 100%);
}

.answer-strip-scroll::-webkit-scrollbar {
    height: 0; /* WebKit: hide scroll indicator */
}

.answer-strip-scroll::-webkit-scrollbar-thumb {
    background: transparent;
}

.answer-strip-chip {
    flex: 0 0 auto;
    scroll-snap-align: center;
    min-width: 76px;
    max-width: 140px;
    min-height: 56px;
    padding: 8px 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    border-radius: 12px;
    background: #fff3cd;
    border: 2px solid rgba(255, 193, 7, 0.55);
    color: #333;
    font-size: clamp(12px, 2.8vw, 15px);
    font-weight: 600;
    cursor: grab;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
    user-select: none;
    -webkit-user-drag: element;
    transition: transform 0.12s ease, box-shadow 0.12s ease;
    touch-action: auto;
}

.answer-strip-chip.answer-strip-chip-active {
    outline: 3px solid rgba(255, 255, 255, 0.85);
    outline-offset: 2px;
    transform: none; /* no vertical shift when highlighted */
}

@keyframes tile-flip-out {
    from {
        transform: rotateY(0);
        opacity: 1;
    }
    to {
        transform: rotateY(90deg);
        opacity: 0.15;
    }
}

.tile.tile-unplace-anim {
    animation: tile-flip-out 0.22s ease-in forwards;
}

/* SortableJS touch dragging: avoid transition-induced jank on mobile */
.sortable-fallback,
.sortable-ghost,
.sortable-chosen,
.sortable-drag {
    transition: none !important;
}

/* When a chip is placed into a tile, it should look like the tile content (not a nested tile). */
.tile .answer-strip-chip {
    width: 100%;
    height: 100%;
    max-width: none;
    min-width: 0;
    min-height: 0;
    padding: 0 6px;
    background: transparent;
    border: none;
    box-shadow: none;
    border-radius: 0;
    cursor: grab;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    touch-action: none;
}

.tile .answer-strip-chip:hover {
    transform: none;
    box-shadow: none;
}

.answer-strip-chip:active {
    cursor: grabbing;
}

@media (hover: hover) and (pointer: fine) {
    .answer-strip-chip:hover {
        transform: translateY(-2px);
        box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
    }
}

/* When a chip is inside a tile, disable scroll gestures so horizontal drags start reliably */
.tile .answer-strip-chip {
    touch-action: none;
}

/* Prevent page scrolling while actively dragging */
body.sortable-dragging,
body.sortable-dragging * {
    overscroll-behavior: none;
}
body.sortable-dragging {
    touch-action: none;
}

.answer-strip-chip.answer-strip-chip-dragging {
    opacity: 0.55;
    transform: scale(0.97);
}

.answer-strip-ghost {
    position: fixed;
    left: 0;
    top: 0;
    transform: translate3d(-9999px, -9999px, 0);
    z-index: 9999;
    pointer-events: none;
    opacity: 0.95;
    filter: drop-shadow(0 10px 18px rgba(0,0,0,0.35));
}

.answer-strip-ghost .answer-strip-chip {
    cursor: grabbing;
    transform: none;
}

/* Prevent text selection while dragging */
body.answer-strip-dragging-body {
    user-select: none;
    -webkit-user-select: none;
}

.answer-strip-chip-image {
    min-width: 64px;
    min-height: 56px;
    padding: 4px;
}

.answer-strip-chip .tile-image {
    max-width: 56px;
    max-height: 48px;
    width: auto;
    height: auto;
    object-fit: cover;
    border-radius: 6px;
    display: block;
}

.game-board .tile[draggable="true"] {
    cursor: grab;
}

.game-board .tile.tile-drag-source {
    opacity: 0.75;
    outline: 2px dashed rgba(255, 255, 255, 0.85);
    outline-offset: 2px;
}

.game-board .tile.drag-over {
    outline: 3px solid rgba(241, 196, 15, 0.95);
    outline-offset: 3px;
    box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.15) inset;
}

