/**
 * Wordotron - Tron-inspired styling
 */

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

html {
    /* Prevent iOS bounce/overscroll */
    overscroll-behavior: none;
    -webkit-overflow-scrolling: touch;
}

body {
    background: #000;
    color: #0f0;
    font-family: 'Courier New', monospace;
    /* Allow scrolling by default (for static pages) */
    overflow-y: auto;
    width: 100%;
    min-height: 100%;
    overscroll-behavior: none;
    -webkit-overflow-scrolling: touch;
    /* Prevent text selection and zoom on mobile */
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

/* Lock body when game screen is active (prevents scrolling during gameplay) */
body:has(#game:not([style*="display: none"])) {
    position: fixed;
    overflow: hidden;
    height: 100%;
    touch-action: none;
    -webkit-user-select: none;
    user-select: none;
}

.screen {
    width: 100vw;
    height: 100vh;
}

.container {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    height: 100%;
    text-align: center;
}

.title {
    font-size: 4em;
    margin: 0;
    text-shadow: 0 0 20px #0f0, 0 0 40px #0f0;
    letter-spacing: 8px;
    animation: glow 2s ease-in-out infinite alternate;
}

@keyframes glow {
    from { text-shadow: 0 0 20px #0f0, 0 0 40px #0f0; }
    to { text-shadow: 0 0 30px #0f0, 0 0 60px #0f0, 0 0 80px #0f0; }
}

.subtitle {
    font-size: 1.2em;
    margin: 20px 0 40px;
    opacity: 0.7;
}

/* PWA Install Banner */
#pwa-install-banner {
    max-width: 600px;
    margin: 0 auto 30px auto;
    padding: 20px;
    background: linear-gradient(135deg, rgba(0, 255, 0, 0.1), rgba(0, 255, 255, 0.1));
    border: 2px solid #0f0;
    border-radius: 8px;
    box-shadow: 0 0 20px rgba(0, 255, 0, 0.3);
    animation: pulse-border 2s ease-in-out infinite;
}

@keyframes pulse-border {
    0%, 100% {
        border-color: #0f0;
        box-shadow: 0 0 20px rgba(0, 255, 0, 0.3);
    }
    50% {
        border-color: #0ff;
        box-shadow: 0 0 30px rgba(0, 255, 255, 0.5);
    }
}

#pwa-dismiss:hover {
    background: rgba(0, 255, 0, 0.2);
    box-shadow: 0 0 10px rgba(0, 255, 0, 0.5);
}

#lobby-content {
    min-width: 400px;
}

input[type="text"] {
    background: #000;
    border: 2px solid #0f0;
    color: #0f0;
    font-family: 'Courier New', monospace;
    font-size: 1.2em;
    padding: 12px 20px;
    margin: 20px 0;
    width: 100%;
    outline: none;
    box-shadow: 0 0 10px rgba(0, 255, 0, 0.3);
}

input[type="text"]:focus {
    box-shadow: 0 0 20px rgba(0, 255, 0, 0.6);
}

.btn {
    background: #000;
    border: 2px solid #0f0;
    color: #0f0;
    font-family: 'Courier New', monospace;
    font-size: 1.2em;
    padding: 12px 30px;
    margin: 10px;
    cursor: pointer;
    transition: all 0.3s;
    box-shadow: 0 0 10px rgba(0, 255, 0, 0.3);
}

.btn:hover {
    background: #0f0;
    color: #000;
    box-shadow: 0 0 20px rgba(0, 255, 0, 0.8);
}

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

#lobby-status {
    margin: 20px 0;
    font-size: 1.1em;
    min-height: 30px;
}

#lobby-players {
    margin-top: 30px;
    padding: 20px;
    border: 2px solid #0f0;
    box-shadow: 0 0 15px rgba(0, 255, 0, 0.3);
}

#lobby-players h3 {
    margin-bottom: 15px;
}

#player-list {
    list-style: none;
    margin: 15px 0;
}

#player-list li {
    padding: 8px;
    margin: 5px 0;
    border-left: 3px solid #0f0;
    padding-left: 15px;
}

/* Game Screen */
#game-ui {
    display: flex;
    flex-direction: column;
    height: 100vh;
    padding: 20px;
    overflow: hidden;
    touch-action: manipulation;
    position: fixed;
    width: 100%;
    -webkit-user-select: none;
    user-select: none;
}

#top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px;
    border: 2px solid #0f0;
    box-shadow: 0 0 15px rgba(0, 255, 0, 0.3);
    margin-bottom: 20px;
}

#timer {
    font-size: 2em;
    font-weight: bold;
    text-shadow: 0 0 10px #0f0;
}

#board-indicator {
    font-size: 1.5em;
    text-shadow: 0 0 10px #0f0;
}

#scoreboard {
    display: flex;
    gap: 20px;
}

.player-score {
    padding: 5px 10px;
    border: 1px solid #0f0;
    box-shadow: 0 0 8px rgba(0, 255, 0, 0.3);
}

.player-score.dead {
    opacity: 0.4;
}

#game-container {
    display: flex;
    flex: 1;
    gap: 20px;
    align-items: center;
}

#game-canvas {
    border: 3px solid #0f0;
    box-shadow: 0 0 30px rgba(0, 255, 0, 0.5);
    background: #000;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
    touch-action: none;
}

#sidebar {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

#word-history-container {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 15px;
    border: 2px solid #0f0;
    box-shadow: 0 0 15px rgba(0, 255, 0, 0.3);
    height: fit-content;
    max-height: 250px;
    overflow-y: auto;
}

#word-history {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.word-entry {
    display: flex;
    justify-content: space-between;
    padding: 5px 10px;
    border-left: 2px solid #0f0;
    background: rgba(0, 255, 0, 0.05);
}

.word-entry .word {
    font-weight: bold;
}

.word-entry .points {
    color: #0f0;
    text-shadow: 0 0 5px #0f0;
}

#minimap-container {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 15px;
    border: 2px solid #0f0;
    box-shadow: 0 0 15px rgba(0, 255, 0, 0.3);
    height: fit-content;
    max-height: 100%;
    overflow-y: auto;
}

.sidebar-label {
    font-size: 1.2em;
    margin-bottom: 10px;
    text-align: center;
    text-shadow: 0 0 10px #0f0;
}

#minimaps {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
}

.minimap {
    border: 1px solid #0f0;
    box-shadow: 0 0 8px rgba(0, 255, 0, 0.3);
    background: #000;
    position: relative;
}

.minimap.current-board {
    border: 2px solid #f00;
    box-shadow: 0 0 12px rgba(255, 0, 0, 0.5);
}

.minimap-number {
    position: absolute;
    top: 2px;
    left: 2px;
    font-size: 0.7em;
    background: rgba(0, 0, 0, 0.7);
    padding: 2px 4px;
    border: 1px solid #0f0;
}

.minimap.current-board .minimap-number {
    border: 1px solid #f00;
    color: #f00;
}

#bottom-bar {
    margin-top: 20px;
    padding: 15px;
    border: 2px solid #0f0;
    box-shadow: 0 0 15px rgba(0, 255, 0, 0.3);
}

#word-buffer-container {
    display: flex;
    align-items: center;
    gap: 15px;
    font-size: 1.5em;
}

#word-buffer {
    font-size: 2em;
    font-weight: bold;
    min-width: 200px;
    text-align: left;
    text-shadow: 0 0 10px #0f0;
    letter-spacing: 3px;
}

.label {
    opacity: 0.7;
}

.hint {
    font-size: 0.7em;
    opacity: 0.5;
}

#feedback {
    margin-top: 10px;
    font-size: 1.2em;
    min-height: 30px;
    animation: fadeOut 2s ease-out;
}

@keyframes fadeOut {
    0% { opacity: 1; }
    70% { opacity: 1; }
    100% { opacity: 0; }
}

.feedback-valid {
    color: #0f0;
    text-shadow: 0 0 15px #0f0;
}

.feedback-invalid {
    color: #f00;
    text-shadow: 0 0 15px #f00;
}

/* Game Over Screen */
#final-scores {
    margin: 30px 0;
    padding: 30px;
    border: 2px solid #0f0;
    box-shadow: 0 0 20px rgba(0, 255, 0, 0.4);
    min-width: 500px;
}

.final-score-item {
    padding: 15px;
    margin: 10px 0;
    border-left: 4px solid #0f0;
    font-size: 1.3em;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.final-score-item.winner {
    background: rgba(0, 255, 0, 0.1);
    border-left-width: 6px;
    text-shadow: 0 0 10px #0f0;
}

.rank {
    font-size: 1.5em;
    margin-right: 15px;
    opacity: 0.7;
}

.player-name {
    flex: 1;
}

.player-stats {
    text-align: right;
    font-size: 0.9em;
    opacity: 0.8;
}

/* Scrollbar styling */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: #000;
    border: 1px solid #0f0;
}

::-webkit-scrollbar-thumb {
    background: #0f0;
    box-shadow: 0 0 5px rgba(0, 255, 0, 0.5);
}

::-webkit-scrollbar-thumb:hover {
    background: #0f0;
    box-shadow: 0 0 10px rgba(0, 255, 0, 0.8);
}

/* Footer */
#main-footer {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(0, 0, 0, 0.9);
    border-top: 1px solid #0f0;
    padding: 10px 20px;
    z-index: 1000;
}

.footer-content {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 30px;
    font-size: 0.9em;
}

.footer-content p {
    margin: 0;
}

.footer-content a {
    color: #0f0;
    text-decoration: none;
    transition: all 0.3s;
}

.footer-content a:hover {
    text-shadow: 0 0 10px #0f0;
    color: #0ff;
}

/* Touch Controls (Mobile Only) */
#touch-controls {
    display: none;
    position: fixed;
    bottom: 20px;
    left: 0;
    right: 0;
    justify-content: space-between;
    align-items: flex-end;
    padding: 0 20px;
    z-index: 1000;
    pointer-events: none;
}

#touch-controls > * {
    pointer-events: all;
}

#dpad-container {
    position: relative;
    width: 140px;
    height: 140px;
}

.dpad-btn {
    position: absolute;
    width: 50px;
    height: 50px;
    background: rgba(0, 255, 0, 0.3);
    border: 2px solid #0f0;
    box-shadow: 0 0 10px rgba(0, 255, 0, 0.5);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #0f0;
    font-size: 1.5em;
    user-select: none;
    -webkit-user-select: none;
    touch-action: none;
}

.dpad-btn:active {
    background: rgba(0, 255, 0, 0.6);
    box-shadow: 0 0 20px rgba(0, 255, 0, 0.9);
}

#dpad-up {
    top: 0;
    left: 50%;
    transform: translateX(-50%);
}

#dpad-down {
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
}

#dpad-left {
    left: 0;
    top: 50%;
    transform: translateY(-50%);
}

#dpad-right {
    right: 0;
    top: 50%;
    transform: translateY(-50%);
}

#touch-submit {
    width: 100px;
    height: 100px;
    background: rgba(0, 255, 0, 0.3);
    border: 3px solid #0f0;
    box-shadow: 0 0 15px rgba(0, 255, 0, 0.5);
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    color: #0f0;
    font-size: 0.9em;
    font-weight: bold;
    user-select: none;
    -webkit-user-select: none;
    touch-action: none;
}

#touch-submit:active {
    background: rgba(0, 255, 0, 0.6);
    box-shadow: 0 0 30px rgba(0, 255, 0, 0.9);
}

/* Minimap Modal (Mobile) */
#minimap-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.95);
    z-index: 2000;
    padding: 20px;
    overflow-y: auto;
}

#minimap-modal.active {
    display: flex;
    flex-direction: column;
}

#minimap-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 10px;
    border-bottom: 2px solid #0f0;
}

#minimap-modal-close {
    background: none;
    border: 2px solid #0f0;
    color: #0f0;
    font-size: 1.5em;
    padding: 5px 15px;
    cursor: pointer;
}

#minimap-toggle, #word-history-toggle {
    display: none;
    position: fixed;
    top: 10px;
    z-index: 1001;
    width: 40px;
    height: 40px;
    padding: 0;
    background: rgba(0, 0, 0, 0.8);
    border: 2px solid #0f0;
    color: #0f0;
    font-size: 1.2em;
    cursor: pointer;
    box-shadow: 0 0 10px rgba(0, 255, 0, 0.3);
    font-family: 'Courier New', monospace;
    transition: all 0.3s;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    border-radius: 8px;
}

#minimap-toggle:active,
#word-history-toggle:active {
    background: rgba(0, 255, 0, 0.3);
    box-shadow: 0 0 20px rgba(0, 255, 0, 0.6);
    transform: scale(0.95);
}

#minimap-toggle {
    left: 50%;
    transform: translateX(-50px);
}

#minimap-toggle:active {
    transform: translateX(-50px) scale(0.95);
}

#word-history-toggle {
    left: 50%;
    transform: translateX(10px);
}

#word-history-toggle:active {
    transform: translateX(10px) scale(0.95);
}

/* Word History Modal (Mobile) */
#word-history-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.95);
    z-index: 2000;
    padding: 20px;
    overflow-y: auto;
}

#word-history-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 10px;
    border-bottom: 2px solid #0f0;
}

#word-history-modal-close {
    background: none;
    border: 2px solid #0f0;
    color: #0f0;
    font-size: 1.5em;
    padding: 5px 15px;
    cursor: pointer;
    font-family: 'Courier New', monospace;
}

#word-history-mobile {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

/* Controls Tutorial Modal */
#controls-tutorial {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.95);
    z-index: 3000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.tutorial-content {
    background: rgba(0, 20, 0, 0.9);
    border: 2px solid #0f0;
    box-shadow: 0 0 30px rgba(0, 255, 0, 0.5);
    padding: 30px;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
    border-radius: 10px;
}

.tutorial-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 15px;
    border-bottom: 2px solid rgba(0, 255, 0, 0.3);
}

.tutorial-header button {
    transition: all 0.3s;
}

.tutorial-header button:hover {
    background: rgba(0, 255, 0, 0.2);
    box-shadow: 0 0 10px rgba(0, 255, 0, 0.5);
}

.tutorial-item {
    display: flex;
    align-items: center;
    margin-bottom: 20px;
    padding: 15px;
    background: rgba(0, 255, 0, 0.05);
    border: 1px solid rgba(0, 255, 0, 0.2);
    border-radius: 5px;
}

.tutorial-icon {
    font-size: 2.5em;
    margin-right: 15px;
    min-width: 60px;
    text-align: center;
}

.tutorial-text {
    flex: 1;
    color: #0f0;
    line-height: 1.6;
}

.tutorial-text strong {
    color: #0ff;
    font-size: 1.1em;
    display: block;
    margin-bottom: 5px;
}

/* Settings Modal */
#settings-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.95);
    z-index: 3000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.settings-content {
    background: rgba(0, 20, 0, 0.9);
    border: 2px solid #0f0;
    box-shadow: 0 0 30px rgba(0, 255, 0, 0.5);
    padding: 30px;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch; /* Enable momentum scrolling on iOS */
    border-radius: 10px;
    width: 100%;
}

.settings-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 15px;
    border-bottom: 2px solid rgba(0, 255, 0, 0.3);
}

.modal-close-btn {
    background: none;
    border: 2px solid #0f0;
    color: #0f0;
    font-size: 1.5em;
    padding: 5px 15px;
    cursor: pointer;
    font-family: 'Courier New', monospace;
    transition: all 0.3s;
}

.modal-close-btn:hover {
    background: rgba(0, 255, 0, 0.2);
    box-shadow: 0 0 10px rgba(0, 255, 0, 0.5);
}

.settings-body {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.setting-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.setting-label {
    color: #0ff;
    font-size: 1.1em;
    font-weight: bold;
}

.setting-select {
    background: #000;
    border: 2px solid #0f0;
    color: #0f0;
    font-family: 'Courier New', monospace;
    font-size: 1em;
    padding: 10px;
    outline: none;
    box-shadow: 0 0 10px rgba(0, 255, 0, 0.3);
    cursor: pointer;
}

.setting-select:focus {
    box-shadow: 0 0 20px rgba(0, 255, 0, 0.6);
}

.setting-description {
    font-size: 0.9em;
    opacity: 0.7;
    margin: 0;
    color: #0f0;
}

.settings-footer {
    display: flex;
    gap: 10px;
    align-items: center;
    justify-content: space-between;
    margin-top: 20px;
    padding-top: 20px;
    border-top: 2px solid rgba(0, 255, 0, 0.3);
}

#settings-saved-indicator {
    font-size: 0.9em;
    margin-left: auto;
}

.btn-secondary {
    background: transparent;
    border: 2px solid #0f0;
    color: #0f0;
    font-family: 'Courier New', monospace;
    font-size: 1em;
    padding: 12px 20px;
    cursor: pointer;
    transition: all 0.3s;
    box-shadow: 0 0 10px rgba(0, 255, 0, 0.3);
    flex: 1;
}

.btn-secondary:hover {
    background: rgba(0, 255, 0, 0.1);
    box-shadow: 0 0 20px rgba(0, 255, 0, 0.5);
}

.btn-secondary:active {
    transform: scale(0.95);
}

/* Hide settings buttons on desktop */
#mobile-settings-container,
#game-over-settings-container {
    display: none;
}

/* Mobile-specific adjustments */
@media (max-width: 768px) {
    /* Show settings buttons on mobile */
    #mobile-settings-container,
    #game-over-settings-container {
        display: block;
    }

    body {
        overflow-y: auto;
        position: static;
        height: auto;
        touch-action: pan-y;
    }

    /* Lock body when game is active */
    .screen {
        width: 100%;
        height: auto;
        min-height: 100vh;
    }

    .container {
        padding: 20px;
        height: auto;
        min-height: 100vh;
    }

    .title {
        font-size: 2.5em;
        letter-spacing: 4px;
    }

    .subtitle {
        font-size: 1em;
    }

    /* PWA Install Banner Mobile */
    #pwa-install-banner {
        margin: 0 10px 20px 10px;
        padding: 15px;
        font-size: 0.9em;
    }

    #pwa-install-banner > div {
        flex-direction: column;
        gap: 12px;
    }

    #pwa-dismiss {
        width: 100%;
        padding: 10px;
    }

    #lobby-content {
        min-width: 0;
        width: 100%;
        max-width: 400px;
    }

    input[type="text"] {
        font-size: 1em;
        padding: 10px 15px;
    }

    .btn {
        font-size: 1em;
        padding: 10px 20px;
        margin: 5px;
        width: 100%;
        max-width: 300px;
    }

    /* Game UI Mobile Layout */
    #game-ui {
        padding: 10px;
        height: auto;
        min-height: 100vh;
    }

    #top-bar {
        flex-wrap: wrap;
        padding: 10px;
        margin-bottom: 10px;
    }

    #timer {
        font-size: 1.5em;
    }

    #board-indicator {
        font-size: 1.2em;
    }

    #scoreboard {
        width: 100%;
        flex-wrap: wrap;
        justify-content: center;
        gap: 10px;
        margin-top: 10px;
    }

    .player-score {
        font-size: 0.9em;
        padding: 4px 8px;
    }

    /* Stack game container vertically */
    #game-container {
        flex-direction: column;
        gap: 10px;
        align-items: stretch;
    }

    #game-canvas {
        width: 100%;
        height: auto;
        max-width: 500px;
        margin: 0 auto;
        border-width: 2px;
    }

    /* Hide desktop sidebar on mobile */
    #sidebar {
        display: none;
    }

    /* Show touch controls on mobile */
    #touch-controls {
        display: flex;
    }

    /* Show minimap and word history toggle buttons */
    #minimap-toggle, #word-history-toggle {
        display: block;
    }

    #bottom-bar {
        margin-top: 10px;
        padding: 10px;
        margin-bottom: 180px;
    }

    #word-buffer-container {
        flex-direction: column;
        gap: 5px;
        font-size: 1em;
        align-items: flex-start;
    }

    #word-buffer {
        font-size: 1.5em;
        min-width: 0;
    }

    .hint {
        display: none;
    }

    #feedback {
        font-size: 1em;
    }

    /* Game Over Screen */
    #final-scores {
        min-width: 0;
        width: 100%;
        padding: 20px;
    }

    .final-score-item {
        font-size: 1em;
        flex-direction: column;
        align-items: flex-start;
        gap: 5px;
    }

    .rank {
        font-size: 1.2em;
    }

    .player-stats {
        text-align: left;
        font-size: 0.85em;
    }

    /* Footer */
    #main-footer {
        position: relative;
        padding: 15px 10px;
    }

    .footer-content {
        flex-direction: column;
        gap: 10px;
        font-size: 0.8em;
        text-align: center;
    }

    /* Modal minimap on mobile */
    #minimap-modal #minimaps {
        max-width: 500px;
        margin: 0 auto;
    }

    #minimap-modal .minimap {
        width: 100%;
        height: auto;
    }
}

/* iPad Portrait - Better layout for larger tablets */
@media (min-width: 768px) and (max-width: 834px) and (orientation: portrait) {
    /* Show settings buttons on tablet portrait */
    #mobile-settings-container,
    #game-over-settings-container {
        display: block;
    }

    /* Compact lobby layout for iPad - reduce spacing */
    .container {
        max-width: 600px;
        padding: 15px 20px;
    }

    .title {
        margin: 0 0 10px 0;
        font-size: 3em;
        letter-spacing: 6px;
    }

    .subtitle {
        margin: 5px 0 20px;
        font-size: 1em;
    }

    input[type="text"] {
        padding: 10px 18px;
        margin: 15px 0;
    }

    .btn {
        padding: 10px 24px;
        margin: 8px;
    }

    #lobby-players {
        margin-top: 20px;
        padding: 15px;
    }

    #lobby-players h3 {
        margin-bottom: 10px;
    }

    #player-list {
        margin: 10px 0;
    }

    #player-list li {
        padding: 6px;
        margin: 4px 0;
    }

    #pwa-install-banner {
        margin: 0 auto 15px auto;
        padding: 15px;
    }

    /* Override mobile styles for iPad portrait */
    #sidebar {
        display: flex !important;
        max-width: 250px;
    }

    #game-container {
        flex-direction: row !important;
        gap: 15px;
    }

    #game-canvas {
        width: auto !important;
        height: auto !important;
        max-width: 450px;
        max-height: 600px;
    }

    #touch-controls {
        display: flex;
        bottom: 10px;
    }

    #dpad-container {
        width: 120px;
        height: 120px;
    }

    .dpad-btn {
        width: 45px;
        height: 45px;
        font-size: 1.2em;
    }

    #touch-submit {
        width: 120px;
        height: 120px;
        font-size: 1.2em;
    }

    #minimap-toggle, #word-history-toggle {
        display: none !important;
    }
}

/* iPad Landscape & Tablet optimization */
@media (min-width: 769px) and (max-width: 1024px) and (orientation: landscape) {
    /* Show settings buttons on tablet landscape */
    #mobile-settings-container,
    #game-over-settings-container {
        display: block;
    }

    /* Compact lobby layout for iPad landscape */
    .container {
        padding: 20px;
    }

    .title {
        margin: 0 0 15px 0;
        font-size: 3.5em;
    }

    .subtitle {
        margin: 10px 0 25px;
    }

    input[type="text"], .btn {
        margin: 10px;
    }

    #game-container {
        flex-direction: row;
    }

    #game-canvas {
        width: auto;
        height: auto;
        max-width: 380px;
        max-height: 380px;
    }

    #sidebar {
        display: flex;
        max-width: 250px;
    }

    /* Keep touch controls on iPad landscape - smaller to fit */
    #touch-controls {
        display: flex;
        bottom: 5px;
        padding: 0 15px;
    }

    #dpad-container {
        width: 100px;
        height: 100px;
    }

    .dpad-btn {
        width: 38px;
        height: 38px;
        font-size: 1em;
    }

    #touch-submit {
        width: 100px;
        height: 100px;
        font-size: 1em;
    }

    #minimap-toggle, #word-history-toggle {
        display: none;
    }
}

/* Desktop - hide touch controls */
@media (min-width: 1025px) {
    #touch-controls {
        display: none;
    }

    #minimap-toggle, #word-history-toggle {
        display: none;
    }
}

/* Small mobile devices */
@media (max-width: 480px) {
    .title {
        font-size: 2em;
        letter-spacing: 2px;
    }

    #dpad-container {
        width: 120px;
        height: 120px;
    }

    .dpad-btn {
        width: 45px;
        height: 45px;
        font-size: 1.3em;
    }

    #touch-submit {
        width: 85px;
        height: 85px;
        font-size: 0.8em;
    }

    #touch-controls {
        bottom: 10px;
        padding: 0 10px;
    }

    #minimap-toggle, #word-history-toggle {
        width: 35px;
        height: 35px;
        font-size: 1em;
        top: 8px;
    }

    #minimap-toggle {
        transform: translateX(-43px);
    }

    #minimap-toggle:active {
        transform: translateX(-43px) scale(0.95);
    }

    #word-history-toggle {
        transform: translateX(8px);
    }

    #word-history-toggle:active {
        transform: translateX(8px) scale(0.95);
    }
}

/* Prevent text selection on touch controls */
#touch-controls * {
    -webkit-touch-callout: none;
    -webkit-tap-highlight-color: transparent;
}

/* Ensure canvas scales properly */
@media (max-width: 768px) {
    canvas {
        max-width: 100%;
        height: auto !important;
        width: 100% !important;
    }
}
