* {
    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);
}

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;
}

.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-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 #667eea;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.3s ease;
    min-width: 120px;
    appearance: none;
    background-image: 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");
    background-repeat: no-repeat;
    background-position: right 12px center;
    background-size: 12px;
    padding-right: 40px;
}

.difficulty-dropdown:hover {
    border-color: #5568d3;
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.3);
}

.difficulty-dropdown:focus {
    outline: none;
    border-color: #5568d3;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 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: #667eea;
    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: #667eea;
    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: #667eea;
}

.game-day-info {
    flex-shrink: 0;
    font-size: 0.85em;
    color: #667eea;
    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: 800px;
    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: #667eea;
    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;
}

/* Single primary button (What Did I Just Learn? / See My Results) - center with margin auto */
#what-did-i-learn-results-btn,
#learn-see-results-btn {
    display: block;
    margin-left: auto;
    margin-right: auto;
    text-align: center;
}

/* 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;
}

/* 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: #667eea;
}

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

.btn {
    padding: 12px 24px;
    border: none;
    border-radius: 8px;
    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: #667eea;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-primary:hover:not(:disabled) {
    background: #5568d3;
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(102, 126, 234, 0.4);
}

.btn-secondary {
    background: #6c757d;
    color: white;
}

.btn-secondary:hover:not(:disabled) {
    background: #5a6268;
    transform: translateY(-2px);
}

.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;
    /* 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: 6px 8px;
    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;
}

.tile:hover:not(.flipped):not(.revealed):not(.viewing-phase) {
    transform: scale(1.05);
    border-color: #667eea;
    box-shadow: 0 5px 15px rgba(102, 126, 234, 0.3);
}

.tile.flipped {
    background: #667eea;
    color: white;
    border-color: #5568d3;
}

.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: 6px 6px 10px;
    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: 0 4px;
}
.tile-2x .tile-primary {
    font-size: 1.05em;
    font-weight: 600;
    min-height: 1.8em;
    flex-shrink: 0;
}
.tile-2x .tile-secondary {
    font-size: 0.9em;
    color: #555;
    margin-top: 0;
    min-height: 2em;
    flex: 1 1 auto;
}
/* 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;
    animation: reveal 0.3s ease;
}

.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 reveal {
    0% {
        transform: scale(0.8);
        opacity: 0;
    }
    100% {
        transform: scale(1);
        opacity: 1;
    }
}

@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: #667eea;
    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-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: #667eea;
    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: #667eea;
    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: #667eea;
}

.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;
}

/* 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 {
    min-height: 52px;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
}
.hint-buffer-return-link {
    color: #fff;
    font-size: 1.1em;
    font-weight: 600;
    text-decoration: none;
    padding: 12px 32px;
    background: #667eea;
    border-radius: 8px;
    transition: background 0.2s ease, opacity 1s ease;
    opacity: 0;
    pointer-events: none;
}
.hint-buffer-return-link:hover {
    background: #5568d3;
}

.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: #667eea;
}

.difficulty-select:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 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;
}

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

.win-title {
    font-size: 2.2em;
    font-weight: 700;
    color: #667eea;
    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;
}

/* 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: #667eea;
    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: #667eea;
}

.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: #667eea;
    text-decoration: none;
    font-size: 0.95em;
    margin: 5px 0;
    transition: color 0.2s ease;
}

.improve-link:hover {
    color: #5568d3;
    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;
    }
    
    .tile {
        font-size: 0.9em;
    }
    
    .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;
}

