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

html {
    height: 100%;
    height: 100dvh; /* Dynamic viewport height */
    overflow: hidden;
    position: fixed;
    width: 100%;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background-color: #1a1a1a;
    color: #ffffff;
    min-height: 100vh;
    min-height: 100dvh; /* Dynamic viewport height for mobile */
    display: flex;
    justify-content: center;
    align-items: center;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    overflow: hidden; /* Prevent body scroll */
}

.game-container {
    width: 100%;
    max-width: 480px;
    min-height: 100vh;
    min-height: 100dvh; /* Dynamic viewport height for mobile */
    height: 100vh;
    height: 100dvh;
    background-color: #1a1a1a;
    padding: 20px;
    display: flex;
    flex-direction: column;
    overflow: hidden; /* Prevent scrolling */
}

/* Header */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
    padding-bottom: 15px;
    border-bottom: 1px solid #333;
}

.header-buttons {
    display: flex;
    gap: 8px;
}

.header-btn {
    background: none;
    border: none;
    color: #aaa;
    font-size: 18px;
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    transition: all 0.2s ease;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.header-btn:hover {
    background-color: #333;
    color: #fff;
}

#homeButton {
    font-size: 28px;
    font-weight: normal;
}

.title {
    font-size: 28px;
    font-weight: 700;
    letter-spacing: 2px;
}

.timer {
    font-size: 24px;
    font-weight: 600;
    color: #4a9eff;
}

/* Game Grid */
.game-grid {
    display: flex;
    flex-direction: column;
    gap: 20px;
    margin-bottom: 20px;
    padding-bottom: 20px;
    border-bottom: 1px solid #333;
}

/* Main Game Area */
.game-area {
    display: flex;
    flex-direction: column;
    margin-top: 5px
}

/* Game Grid */
.game-grid {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.word-row {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 8px;
}

.cell {
    aspect-ratio: 1;
    border: 2px solid #333;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 32px;
    font-weight: 700;
    text-transform: uppercase;
    background-color: #2a2a2a;
    transition: all 0.2s ease;
    cursor: pointer;
    user-select: none;
}

.cell.active {
    border-color: #4a9eff !important;
    box-shadow: 0 0 15px rgba(74, 158, 255, 0.5);
    animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% {
        box-shadow: 0 0 15px rgba(74, 158, 255, 0.5);
    }
    50% {
        box-shadow: 0 0 25px rgba(74, 158, 255, 0.8);
    }
}

.cell.filled {
    border-color: #555;
    background-color: #333;
}

.cell.correct {
    background-color: #2d7a3e;
    border-color: #3ba855;
    color: #ffffff;
    animation: correctFlash 0.6s ease;
    cursor: default;
    pointer-events: none;
}

.cell.found-incomplete {
    background-color: rgba(45, 122, 62, 0.3);
    border-color: rgba(59, 168, 85, 0.5);
    color: rgba(255, 255, 255, 0.5);
}

.letter-btn.found {
    background-color: #1f3a2b;
    color: #ffffff;
    box-shadow: 0 4px 0 #132418, inset 0 0 0 1px rgba(74, 158, 100, 0.3);
}

@keyframes correctFlash {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.1);
    }
}

.cell.incorrect {
    background-color: #8b2e2e;
    border-color: #c93a3a;
    animation: shake 0.5s ease;
}

/* Outline-only states for word validation feedback */
.cell.valid-outline {
    border-color: #3ba855 !important;
    box-shadow: 0 0 15px rgba(59, 168, 85, 0.5);
    animation: validPulse 0.6s ease;
}

.cell.invalid-outline {
    border-color: #c93a3a !important;
    animation: shakeOutline 0.4s ease;
}

@keyframes validPulse {
    0%, 100% {
        box-shadow: 0 0 15px rgba(59, 168, 85, 0.5);
    }
    50% {
        box-shadow: 0 0 25px rgba(59, 168, 85, 0.8);
    }
}

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

@keyframes shakeOutline {
    0%, 100% { 
        transform: translateX(0);
        border-color: #c93a3a;
    }
    12.5% { 
        transform: translateX(-5px);
        border-color: #e04a4a;
    }
    25% { 
        transform: translateX(0);
        border-color: #c93a3a;
    }
    37.5% { 
        transform: translateX(5px);
        border-color: #e04a4a;
    }
    50% { 
        transform: translateX(0);
        border-color: #c93a3a;
    }
    62.5% { 
        transform: translateX(-5px);
        border-color: #e04a4a;
    }
    75% { 
        transform: translateX(0);
        border-color: #c93a3a;
    }
    87.5% { 
        transform: translateX(5px);
        border-color: #e04a4a;
    }
}

/* Row alignment - first row (3 cells) */
.word-row[data-row="0"] {
    grid-template-columns: repeat(5, 1fr);
}

.word-row[data-row="0"] .cell:nth-child(1) { grid-column: 1; }
.word-row[data-row="0"] .cell:nth-child(2) { grid-column: 2; }
.word-row[data-row="0"] .cell:nth-child(3) { grid-column: 3; }

/* Row 2 (4 cells) */
.word-row[data-row="1"] .cell:nth-child(1) { grid-column: 1; }
.word-row[data-row="1"] .cell:nth-child(2) { grid-column: 2; }
.word-row[data-row="1"] .cell:nth-child(3) { grid-column: 3; }
.word-row[data-row="1"] .cell:nth-child(4) { grid-column: 4; }

/* Row 3 (5 cells) - all columns */
.word-row[data-row="2"] .cell:nth-child(1) { grid-column: 1; }
.word-row[data-row="2"] .cell:nth-child(2) { grid-column: 2; }
.word-row[data-row="2"] .cell:nth-child(3) { grid-column: 3; }
.word-row[data-row="2"] .cell:nth-child(4) { grid-column: 4; }
.word-row[data-row="2"] .cell:nth-child(5) { grid-column: 5; }

/* Keyboard */
.keyboard-container {
    display: flex;
    gap: 12px;
    padding-bottom: 20px;
    margin-top: 5px;
}

.letter-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    flex: 1;
}

.letter-btn {
    aspect-ratio: 1;
    border: none;
    border-radius: 8px;
    background-color: #2a2a2a;
    color: #ffffff;
    font-size: 32px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.15s ease;
    user-select: none;
    text-transform: uppercase;
    box-shadow: 0 4px 0 #1a1a1a;
    position: relative;
}

.letter-btn.found {
    background-color: rgba(45, 122, 62, 0.3);
    color: #ffffff !important;
    box-shadow: 0 4px 0 #132418, inset 0 0 0 1px rgba(74, 158, 100, 0.3);
    position: relative;
}

.letter-btn.found::after {
    content: '';
    position: absolute;
    top: 4px;
    right: 4px;
    width: 0;
    height: 0;
}

/* Individual dots that will be added dynamically */

.letter-btn:active {
    transform: translateY(4px);
    box-shadow: 0 0 0 #1a1a1a;
}

.letter-btn.found:active {
    box-shadow: 0 0 0 #132418, inset 0 0 0 1px rgba(74, 158, 100, 0.3);
}

.letter-btn:hover {
    background-color: #3a3a3a;
}

.letter-btn.found:hover {
    background-color: #244a33;
}

.control-buttons {
    display: flex;
    flex-direction: column;
    gap: 10px;
    width: 70px;
}

.control-btn {
    flex: 1;
    border: none;
    border-radius: 8px;
    background-color: #2a2a2a;
    color: #ffffff;
    font-size: 24px;
    cursor: pointer;
    transition: all 0.15s ease;
    user-select: none;
    box-shadow: 0 4px 0 #1a1a1a;
}

.control-btn:active {
    transform: translateY(4px);
    box-shadow: 0 0 0 #1a1a1a;
}

.control-btn:hover {
    background-color: #3a3a3a;
}

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

.modal.hidden {
    display: none;
}

.modal-content {
    background-color: #2a2a2a;
    border-radius: 16px;
    padding: 40px 50px;
    max-width: 85%;
    width: 400px;
    text-align: center;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
    margin: 0 20px;
}

.modal-content h1 {
    font-size: 42px;
    letter-spacing: 4px;
    margin-bottom: 15px;
    color: #4a9eff;
}

.modal-content h2 {
    font-size: 32px;
    margin-bottom: 20px;
}

.modal-content p {
    font-size: 16px;
    color: #aaa;
    margin-bottom: 30px;
}

.start-btn, .share-btn, .close-btn {
    width: 100%;
    padding: 16px;
    border: none;
    border-radius: 8px;
    font-size: 18px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s ease;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.start-btn {
    background-color: #4a9eff;
    color: #ffffff;
    margin-bottom: 10px;
}

.start-btn:hover {
    background-color: #3a8eef;
}

/* Puzzle info styling */
.puzzle-info {
    margin-top: 20px;
    text-align: center;
}

#puzzleNumber {
    font-size: 20px;
    font-weight: 700;
    color: #4a9eff;
    margin-bottom: 16px;
}

#puzzleDate {
    font-size: 14px;
    color: #aaa;
    margin-bottom: 4px;
}

.created-by {
    font-size: 12px;
    color: #666;
    font-style: italic;
}

.share-btn {
    background-color: #4a9eff;
    color: #ffffff;
    margin-bottom: 10px;
}

.share-btn:hover {
    background-color: #3a8eef;
}


.close-btn {
    background-color: #555;
    color: #ffffff;
}

.close-btn:hover {
    background-color: #666;
}

.final-time {
    font-size: 48px;
    font-weight: 700;
    color: #4a9eff;
    margin-bottom: 30px;
}

.stats {
    background-color: #1a1a1a;
    border-radius: 12px;
    padding: 20px;
    margin-bottom: 20px;
}

.stats h3 {
    font-size: 20px;
    margin-bottom: 15px;
    color: #aaa;
}

.stat-row {
    display: flex;
    justify-content: space-between;
    padding: 10px 0;
    border-bottom: 1px solid #333;
}

.stat-row:last-child {
    border-bottom: none;
}

.stat-label {
    color: #aaa;
    font-size: 16px;
}

.stat-value {
    font-size: 18px;
    font-weight: 700;
    color: #4a9eff;
}

/* Responsive adjustments */
@media (max-width: 480px) {
    .game-container {
        padding: 15px;
        padding-top: max(15px, env(safe-area-inset-top));
        padding-bottom: max(15px, env(safe-area-inset-bottom));
    }

    .header {
        margin-bottom: 20px;
        padding-bottom: 10px;
    }

    .title {
        font-size: 24px;
    }

    .timer {
        font-size: 20px;
    }

    .game-grid {
        gap: 10px;
        margin-bottom: 15px;
        padding-bottom: 15px;
    }

    .word-row {
        gap: 6px;
    }

    .cell {
        font-size: 28px;
        border-radius: 6px;
    }

    .letter-btn {
        font-size: 28px;
        border-radius: 6px;
    }

    .letter-grid {
        gap: 8px;
    }

    .control-buttons {
        gap: 8px;
    }

    .keyboard-container {
        padding-bottom: 10px;
    }
}

/* Prevent text selection and zooming on mobile */
input, button, textarea {
    -webkit-user-select: none;
    user-select: none;
}

/* Force minimal UI on mobile browsers */
@media (max-height: 700px) {
    .header {
        margin-bottom: 15px;
        padding-bottom: 8px;
    }

    .game-grid {
        gap: 8px;
        margin-bottom: 12px;
        padding-bottom: 12px;
    }

    .word-row {
        gap: 5px;
    }

    .cell {
        font-size: 24px;
        border-width: 2px;
    }

    .letter-btn {
        font-size: 24px;
    }

    .control-btn {
        font-size: 20px;
    }

    .letter-grid {
        gap: 6px;
    }

    .control-buttons {
        gap: 6px;
        width: 60px;
    }

    .keyboard-container {
        gap: 8px;
    }
}

/* Rules modal specific styles */
.modal-header {
    display: flex;
    justify-content: flex-end;
    align-items: flex-start;
    margin-bottom: 10px;
}

.modal-header h2 {
    font-size: 25px;
    margin: 0;
    margin-top: 30px;
    margin-bottom: 2px;
    text-align: left;
    width: 100%;
}

.close-x {
    background: none;
    border: none;
    color: #aaa;
    font-size: 28px;
    font-weight: normal;
    cursor: pointer;
    padding: 0;
    width: 35px;
    height: 35px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.2s ease;
    margin-top: -10px;
    margin-right: -10px;
}

.close-x:hover {
    background-color: #333;
    color: #fff;
}

.modal-content .subtitle {
    font-size: 18px !important;
    color: #dddddd;
    margin-bottom: 20px;
    font-weight: 600;
    text-align: left;
}

.rules-list {
    text-align: left;
    margin: 0 0 20px 0;
    padding-left: 20px;
}

.rules-list li {
    margin-bottom: 8px;
    color: #dddddd;
    line-height: 1.4;
}

.rules-list li:first-child {
    word-break: keep-all;
    hyphens: none;
}

.daily-note {
    font-size: 15px;
    color: #ffffff !important;
    font-style: italic;
    margin-top: 20px;
    text-align: left;
}

.rules-btn {
    background-color: #333;
    color: #fff;
    border: 2px solid #555;
    padding: 8px 16px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    margin-top: 8px;
    width: auto;
    text-transform: none;
    display: inline-block;
}

.rules-btn::before {
    content: "ⓘ";
    margin-right: 8px;
    font-size: 16px;
    font-weight: bold;
}

.rules-btn:hover {
    background-color: #555;
    border-color: #777;
}

