* {
    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: 30px;
    display: flex;
    justify-content: center;
}

.tiles-background {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    grid-template-rows: repeat(2, 1fr);
    gap: 12px;
    width: 120px;
    height: 120px;
}

.logo-tile {
    width: 100%;
    height: 100%;
    border: 3px solid #5568d3;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    background: #667eea;
}

.logo-tile::before {
    content: '?';
    font-size: 2em;
    color: white;
    font-weight: 600;
}

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

.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: 12px 24px;
    font-size: 1em;
    font-weight: 600;
    min-width: 100px;
}

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

.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-day-info {
    font-size: 0.85em;
    color: #667eea;
    font-weight: 600;
    margin-left: 12px;
    letter-spacing: 0.5px;
}

/* 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: 8px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.toolbar-left {
    display: flex;
    gap: 20px;
    align-items: center;
    margin-left: -10px;
}

.toolbar-right {
    display: flex;
    align-items: center;
    margin-right: -10px;
}

.toolbar-link {
    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-title-toolbar {
    font-weight: 700;
    font-size: 1.1em;
    color: #667eea;
    letter-spacing: 0.5px;
    margin-right: 8px;
}

.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: 15px;
    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: 12px;
    margin-top: 0;
    padding: 10px 15px;
    background: #f8f9fa;
    border-radius: 10px;
}

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

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

@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: 15px 15px;
    border-radius: 8px;
    margin-bottom: 8px;
    font-weight: 600;
    font-size: 1.1em;
    min-height: 90px;
    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;
}

.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 {
    display: block;
    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;
}

.modal-body {
    padding: 20px;
}

.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 {
    padding: 25px 20px 15px 20px;
}

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

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

/* 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 15px;
    }
    
    .toolbar-left {
        gap: 15px;
    }
    
    .toolbar-link {
        font-size: 0.9em;
    }
    
    .game-title-toolbar {
        font-size: 1em;
    }
    
    body.game-active .container {
        width: calc(100% - 10px);
        margin: 5px auto;
        padding: 15px;
    }
    
    .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;
}

