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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Arial, sans-serif;
    background: #2d4a3e; /* Dark olive */
    touch-action: manipulation;
    -webkit-font-smoothing: antialiased;
    line-height: 1.4;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    overflow-x: hidden; /* Prevent horizontal scrollbar under racks */
}

/* Prevent zoom on input focus */
input, button {
    font-size: 16px !important;
}

.screen {
    max-width: 100vw;
    width: 100%;
    padding: 12px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    flex: 1;
}

/* ==== START SCREEN ==== */
.input-group, .button-group {
    width: 100%;
    max-width: 360px;
    margin: 6px 0;
}

.input-group label {
    display: block;
    font-weight: bold;
    font-size: 14px;
    margin-bottom: 4px;
    color: #333;
}

.input-group input {
    width: 100%;
    padding: 10px;
    font-size: 16px;
    border: 2px solid #ccc;
    border-radius: 8px;
    background: white;
}

.button-group {
    display: flex;
    gap: 10px;
}

.button-group button {
    flex: 1;
    padding: 12px;
    font-size: 15px;
    font-weight: bold;
    border: none;
    border-radius: 10px;
    background: #007bff;
    color: white;
    cursor: pointer;
    min-height: 48px;
    transition: all 0.2s;
}

.button-group button:active {
    transform: scale(0.96);
    background: #0056b3;
}

/* ==== MAIN GAME ==== */
h1, h2 {
    font-size: 20px;
    margin: 0 0 8px;
    text-align: center;
    color: #222;
    font-weight: bold;
}

#main-screen h2 {
    color: #ff3333; /* Pure red */
}

/* Copyright notice styling */
#main-screen > div:last-child {
    color: #ff3333 !important; /* Pure red */
}

.info-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px 12px;
    width: 100%;
    max-width: 360px;
    font-size: 13px;
    background: #f0f5f2; /* Pale sage */
    padding: 8px;
    border-radius: 10px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.info-grid div {
    display: flex;
    justify-content: space-between;
    padding: 2px 0;
}

.info-grid strong {
    font-weight: bold;
    color: #333;
}

/* Player and P-WORD block highlighting */
#main-screen .info-grid:first-of-type {
    background: #f8ca6b; /* Soft pink/coral - Player block */
}

#main-screen .info-grid:last-of-type {
    background: #f8ca6b; /* Soft pink/coral - P-WORD block */

}

/* Make P-WORD block values black for better readability */
#main-screen .info-grid:last-of-type span {
    color: #000 !important;
}

/* ==== RACKS ==== */
.rack {
    display: flex;
    justify-content: center;
    gap: 2px; /* ← CHANGED FROM 4px */
    margin: 0;
    padding: 1px;
    flex-wrap: nowrap;
}
.letter-square {
    width: 11vmin;
    height: 11vmin;
    max-width: 46px;
    max-height: 49px;
    min-width: 40px;
    min-height: 43px;
    font-size: 7vmin;
    font-weight: bold;
    line-height: 1;
    text-align: center;
    padding-top: 1px; /* Move letters to 1px below top */
    border: 2px solid #000;
    border-radius: 8px;
    display: flex;
    justify-content: center;
    align-items: flex-start; /* Changed from flex-end to flex-start */
    margin: 0;
    cursor: pointer;
    user-select: none;
    transition: all 0.15s ease;
    text-transform: uppercase;
    /* 3D effect: Multiple shadows for depth */
    box-shadow: 
        0 4px 8px rgba(0,0,0,0.3),
        0 2px 4px rgba(0,0,0,0.2),
        inset 0 1px 0 rgba(255,255,255,0.3),
        inset 0 -1px 0 rgba(0,0,0,0.2);
    position: relative;
}

.letter-square sup {
    font-size: 0.35em;
    line-height: 1;
    opacity: 1;
    font-weight: bold;
    position: absolute;
    bottom: 0;
    right: 2px; /* Moved 2px to the left */
    pointer-events: none;
    color: #000; /* Black text */
}

#main-screen {
    background: #2d4a3e; /* Dark olive */
}

#output-1 .letter-square { 
    background: linear-gradient(135deg, #00FF00 0%, #00CC00 100%);
    color: #000;
    /* Add highlight for 3D effect */
    box-shadow: 
        0 4px 8px rgba(0,0,0,0.3),
        0 2px 4px rgba(0,0,0,0.2),
        inset 0 1px 0 rgba(255,255,255,0.4),
        inset 0 -1px 0 rgba(0,100,0,0.3);
}
#output-2 .letter-square { 
    background: linear-gradient(135deg, #FFC107 0%, #FFA000 100%);
    color: #000;
    box-shadow: 
        0 4px 8px rgba(0,0,0,0.3),
        0 2px 4px rgba(0,0,0,0.2),
        inset 0 1px 0 rgba(255,255,255,0.4),
        inset 0 -1px 0 rgba(200,120,0,0.3);
}
#output-3 .letter-square { 
    background: linear-gradient(135deg, #4A90E2 0%, #357ABD 100%);
    color: #000;
    box-shadow: 
        0 4px 8px rgba(0,0,0,0.3),
        0 2px 4px rgba(0,0,0,0.2),
        inset 0 1px 0 rgba(255,255,255,0.4),
        inset 0 -1px 0 rgba(0,50,150,0.3);
}
#wild-card .letter-square { 
    background: linear-gradient(135deg, #E6E6FA 0%, #D8D8F0 100%);
    color: #000;
    box-shadow: 
        0 4px 8px rgba(0,0,0,0.3),
        0 2px 4px rgba(0,0,0,0.2),
        inset 0 1px 0 rgba(255,255,255,0.5),
        inset 0 -1px 0 rgba(150,150,180,0.3);
}

#wild-card .letter-square.used {
    background: #999 !important;
    color: #666 !important;
    opacity: 0.6;
}

.letter-square.selected {
    background: linear-gradient(135deg, #007bff 0%, #0056b3 100%) !important;
    color: white !important;
    transform: scale(1.08);
    /* Enhanced 3D shadow when selected */
    box-shadow: 
        0 6px 12px rgba(0,123,255,0.4),
        0 3px 6px rgba(0,0,0,0.3),
        inset 0 1px 0 rgba(255,255,255,0.3),
        inset 0 -1px 0 rgba(0,0,0,0.3) !important;
    animation: bounce 0.3s ease;
}

.letter-square:active {
    transform: scale(0.96);
    box-shadow: 
        0 2px 4px rgba(0,0,0,0.3),
        inset 0 2px 4px rgba(0,0,0,0.2);
}

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

.letter-square:empty {
    background: #eee !important;
    border: 2px dashed #ccc;
    cursor: default;
}

.letter-square.drop-target {
    border: 3px dashed #007bff;
    background: #bbdefb !important;
}

/* ==== INPUT ROW ==== */
.input-row {
    display: flex;
    flex-direction: column;
    width: 100%;
    max-width: 360px;
    gap: 8px;
}

.input-row input {
    padding: 12px;
    font-size: 18px;
    font-weight: bold;
    text-align: center;
    border: 2px solid #ccc;
    border-radius: 10px;
    background: #f8ca6b; /* Soft pink/coral */
    text-transform: uppercase;
    color: #000; /* Black text */
}

.input-row input::placeholder {
    color: #000; /* Black placeholder text */
}

.action-buttons {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 6px;
}

.action-buttons button {
    min-height: 48px;
    padding: 8px 4px;
    font-size: 12px;
    font-weight: bold;
    border: none;
    border-radius: 10px;
    background: #6c757d;
    color: white;
    cursor: pointer;
    transition: all 0.2s;
}

/* Make Help/Settings button with two lines */
#help-button {
    font-size: 14px !important;
    line-height: 1.1;
    padding: 4px 2px !important;
}

.action-buttons button:active {
    transform: scale(0.94);
    background: #5a6268;
}

.action-buttons button.updated,
.action-buttons button.submitted {
    background: #28a745;
    animation: pulse 0.4s;
}

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

/* ==== TOGGLE & SETTINGS ==== */
.toggle-row {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    margin: 8px 0;
    font-weight: bold;
}

/* Tutorial */
.tutorial-wrapper {
    width: 100%;
    max-width: 360px;
}

.tutorial-hint {
    background: #e3f2fd;
    border: 2px solid #90caf9;
    padding: 12px;
    border-radius: 12px;
    font-size: 13px;
    text-align: center;
    margin-bottom: 8px;
    box-shadow: 0 2px 6px rgba(0,0,0,0.1);
}

.tutorial-hint button {
    margin: 6px 4px 0;
    padding: 6px 12px;
    font-size: 12px;
    border-radius: 8px;
    min-width: 60px;
}

/* Error Popup */
.error-popup {
    position: fixed;
    top: 16px;
    left: 50%;
    transform: translateX(-50%);
    padding: 12px 20px;
    border-radius: 12px;
    font-size: 14px;
    font-weight: bold;
    z-index: 10000;
    max-width: 90%;
    text-align: center;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
    opacity: 0;
    transition: all 0.4s ease;
    pointer-events: none;
}

.error-popup.show {
    opacity: 1;
    pointer-events: auto;
    animation: slideDown 0.4s ease;
}

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

.error-popup.success { 
    background: #28a745; 
    color: white; 
}
.error-popup.merge { 
    background: #d8b4fe; 
    color: #333; 
}

/* High Contrast Mode */
.high-contrast .letter-square { 
    border: 3px solid #000 !important; 
}
.high-contrast #output-1 .letter-square { background: #00CC00; }
.high-contrast #output-2 .letter-square { background: #FFB300; }
.high-contrast #wild-card .letter-square { background: #BA55D3; }
.high-contrast .letter-square.selected { background: #0055ff; }

/* ==== RESPONSIVE ==== */
@media (max-width: 480px) {
    .screen { padding: 10px; }
    h1 { font-size: 18px; }
    h2 { font-size: 17px; }
    .info-grid { font-size: 12px; padding: 6px; }
    .letter-square { 
        width: 10vmin; 
        height: 10vmin; 
        font-size: 6.5vmin; 
        border-radius: 6px;
    }
    .letter-square sup {
        font-size: 0.35em;
        bottom: 0;
        right: 2px; /* Moved 2px to the left */
        color: #000; /* Black text */
    }
    .action-buttons button { 
        font-size: 11px; 
        min-height: 44px; 
    }
    
    /* Mobile - two line Help/Settings */
    #help-button {
        font-size: 16px !important;
        line-height: 1.1;
    }
    .input-row input { 
        font-size: 16px; 
        padding: 10px; 
    }
}
/* === SCREEN VISIBILITY CONTROL === */
.screen {
    display: none !important;   /* Hide all screens by default */
}

.screen.active {
    display: flex !important;   /* Show only the active one */
}

@media (min-width: 768px) {
    .screen { max-width: 400px; margin: 0 auto; }
    .letter-square { 
        width: 44px; 
        height: 44px; 
        font-size: 28px; 
    }
    
    .letter-square sup {
        font-size: 0.35em;
        bottom: 0;
        right: 2px; /* Moved 2px to the left */
        color: #000; /* Black text */
    }
    
    /* Rack spacing for PC */
    .rack {
        margin: 0;
    }
    
    /* Allow scrolling on PC */
    body {
        overflow-y: auto;
    }
    
    #main-screen {
        overflow-y: visible;
        background: #2d4a3e; /* Dark olive */
    }
}


/* GAME OVER SCREEN STYLING */
#game-over-screen h1 {
    color: #d32f2f;
    animation: pulse 1.5s infinite;
}

#game-over-screen p {
    color: #fff8dc; /* Light cream for better visibility on dark olive background */
}

#game-over-screen .input-group label {
    color: #d4af37; /* Mustard color */
}

#game-over-screen .info-grid {
    background: #fff3cd;
    border: 2px solid #ffc107;
    padding: 12px;
    border-radius: 12px;
}

#game-over-screen .button-group button {
    background: #28a745;
    font-weight: bold;
}

#game-over-screen .button-group button:active {
    background: #1e7e34;
}
.screen {
    display: none !important;
}

.screen.active {
    display: flex !important;
}
/* START SCREEN CENTERING & FULL HIDE */
#start-screen {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    background: linear-gradient(135deg, #1a2a6c, #b21f1f, #fdbb2d);
    padding: 20px;
    box-sizing: border-box;
}

.start-container {
    background: rgba(255, 255, 255, 0.95);
    padding: 30px;
    border-radius: 20px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
    text-align: center;
    max-width: 400px;
    width: 100%;
    backdrop-filter: blur(10px);
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.start-container h1 {
    margin: 0 0 20px;
    font-size: 2.5rem;
    color: #1a2a6c;
    text-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.input-group {
    margin-bottom: 15px;
    text-align: left;
}

.input-group label {
    display: block;
    margin-bottom: 5px;
    font-weight: bold;
    color: #333;
}

.input-group input {
    width: 100%;
    padding: 12px;
    border: 2px solid #ddd;
    border-radius: 10px;
    font-size: 1rem;
    transition: border 0.3s;
}

.input-group input:focus {
    outline: none;
    border-color: #1a2a6c;
}

.button-group {
    display: flex;
    gap: 10px;
    margin: 20px 0;
    justify-content: center;
}

#facebook-login,
#start-game {
    flex: 1;
    padding: 14px;
    font-size: 1.1rem;
    font-weight: bold;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.3s;
}

#facebook-login {
    background: #1877f2;
    color: white;
}

#facebook-login:hover {
    background: #166fe5;
}

#start-game {
    background: #28a745;
    color: white;
}

#start-game:hover {
    background: #218838;
}

#start-error {
    color: #dc3545;
    font-weight: bold;
    min-height: 20px;
    margin-top: 10px;
}

/* HIDE ALL SCREENS BY DEFAULT */
.screen {
    display: none !important;
}

.screen.active {
    display: flex !important;
}
#display-score.penalty {
    color: #dc3545;
    transform: scale(1.1);
    transition: all 0.2s;
}
#display-score.penalty {
    color: #dc3545 !important;
    transform: scale(1.15);
    transition: all 0.2s ease;
}

/* =========================================== */
/* INTERSTITIAL AD STYLING */
/* =========================================== */
.interstitial-ad-container {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.95);
    z-index: 10000;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(5px);
}

.interstitial-ad-container.show {
    display: flex;
}

.interstitial-ad-content {
    position: relative;
    background: white;
    border-radius: 12px;
    padding: 20px;
    max-width: 95%;
    max-height: 95%;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
}

.close-ad-button {
    position: absolute;
    top: 10px;
    right: 10px;
    background: #dc3545;
    color: white;
    border: none;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    font-size: 20px;
    font-weight: bold;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10001;
    transition: all 0.2s;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.close-ad-button:hover {
    background: #c82333;
    transform: scale(1.1);
}

.close-ad-button:active {
    transform: scale(0.95);
}

#interstitial-ad-slot {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 250px;
}

/* Mobile adjustments */
@media (max-width: 480px) {
    .interstitial-ad-content {
        padding: 10px;
        border-radius: 8px;
    }
    
    .close-ad-button {
        width: 32px;
        height: 32px;
        font-size: 18px;
        top: 5px;
        right: 5px;
    }
    
    #interstitial-ad-slot {
        min-height: 200px;
    }
}

/* TUTORIAL MODAL STYLING */
/* =========================================== */
.tutorial-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    z-index: 10000;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(5px);
    overflow-y: auto;
    padding: 20px;
}

.tutorial-modal.show {
    display: flex;
}

.tutorial-modal-content {
    position: relative;
    background: #2d4a3e; /* Dark olive - same as main screen */
    border-radius: 12px;
    padding: 20px;
    max-width: 360px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
    margin: auto;
}

.close-tutorial-button {
    position: absolute;
    top: 10px;
    right: 10px;
    background: #dc3545;
    color: white;
    border: none;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    font-size: 24px;
    font-weight: bold;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10001;
    transition: all 0.2s;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.close-tutorial-button:hover {
    background: #c82333;
    transform: scale(1.1);
}

.close-tutorial-button:active {
    transform: scale(0.95);
}

.tutorial-container {
    color: white;
}

.tutorial-container h2 {
    margin-bottom: 16px;
    color: #fff;
    text-align: center;
}

.tutorial-section {
    margin-bottom: 16px;
    padding: 12px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 8px;
}

.tutorial-section strong {
    display: block;
    margin-bottom: 8px;
    color: #90caf9;
}

.tutorial-section p {
    margin: 0;
    line-height: 1.5;
}
