/* ====================================================== */
/* ===                STAKTYL STYLES                  === */
/* ====================================================== */

:root {
    --color-black: #000000;
    --color-red: #D12026;
    --color-green: #007C3F;
    --color-blue: #0046AD;
    --tile-ivory: #F7F3E3;
    --board-slate: #505A5B;
    --board-grid: #6a7374;
    --font-math: 'Stix Two Math', serif;
}

/* --- Default Desktop Layout Styles --- */
body {
    font-family: sans-serif;
    background-color: #333;
    color: #FFF;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    min-height: 100vh;
    margin: 0;
    padding: 0 0px;
}

.body-container {
    display: flex;
    flex-direction: row;
    align-items: flex-start;
    gap: 20px;
}

#chat-container {
    width: 250px;
    height: 720px;
    display: flex;
    flex-direction: column;
    background: rgba(68, 68, 68, 0.7);
    backdrop-filter: blur(15px);
    -webkit-backdrop-filter: blur(15px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.3);
    padding: 15px;
    box-sizing: border-box;
    margin-top: 2.5rem;
}

.game-container {
    display: flex;
    flex-direction: column;
}

header {
    width: 100%;
    max-width: 600px;
}
  
header h1 {
    text-align: left;
    font-size: 2.5rem;
    font-weight: bold;
    margin-bottom: 0.5rem;
}

.logo-red {
    color: var(--color-red);
}

.game-area {
    display: flex;
    gap: 5px;
}

.board-and-info-container {
    display: contents; /* On desktop, this container has no layout effect */
}

#game-board {
    width: 600px;
    height: 600px;
    background-color: var(--board-slate);
    display: grid;
    grid-template-columns: repeat(var(--grid-size), 1fr);
    grid-template-rows: repeat(var(--grid-size), 1fr);
    border: 2px solid #222;
    box-shadow: inset 0 0 10px rgba(0,0,0,0.5);
}

.info-panel {
    width: 200px;
    padding: 10px;
    background: rgba(68, 68, 68, 0.7);
    backdrop-filter: blur(15px);
    -webkit-backdrop-filter: blur(15px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.3);
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
}

footer {
    margin-top: 20px;
}

#player-rack {
    display: flex;
    justify-content: center;
    background-color: #5a3a22;
    padding: 10px;
    border-radius: 8px;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
}

.rack-slot {
    width: 50px;
    height: 50px;
    margin: 0 4px;
    background-color: #4a2a12;
    border-radius: 4px;
    display: flex;
    justify-content: center;
    align-items: center;
}

.tile {
    width: 45px;
    height: 45px;
    background-color: var(--tile-ivory);
    color: var(--color-black);
    font-family: var(--font-math);
    font-size: 24px;
    font-weight: bold;
    display: flex;
    justify-content: center;
    align-items: center;
    border-radius: 4px;
    box-shadow: 2px 2px 4px rgba(0,0,0,0.5);
    user-select: none;
    cursor: grab;
    transition: transform 0.1s ease-in-out, outline 0.1s ease-in-out;
}

/* --- Other General Styles --- */
.board-cell { border: 1px solid var(--board-grid); box-sizing: border-box; position: relative; transform-style: preserve-3d; }
#center-equals { background-color: var(--tile-ivory); box-shadow: inset 2px 2px 5px rgba(0, 0, 0, 0.4); display: flex; justify-content: center; align-items: center; font-family: var(--font-math); font-size: 32px; font-weight: bold; color: var(--board-slate); text-shadow: 1px 1px 1px rgba(255, 255, 255, 0.2); pointer-events: none; }
#center-equals::before { content: '='; }
.info-panel h2 { margin-top: 0; margin-bottom: 15px; text-align: center; }
.active-player { font-weight: bold; color: var(--color-red); }
#game-id-container { font-size: 0.9em; color: #ccc; text-align: center; padding-top: 15px; margin-top: auto; }
.action-buttons { display: flex; flex-direction: column; flex-grow: 1; }
.info-panel button { width: 100%; padding: 6px 10px; margin-top: 8px; font-size: 14px; font-weight: 600; color: #fff; background: rgba(255, 255, 255, 0.1); border: 1px solid rgba(255, 255, 255, 0.2); border-radius: 8px; cursor: pointer; transition: all 0.3s ease; }
.info-panel button:hover:not(:disabled) { background: rgba(255, 255, 255, 0.2); }
.info-panel button:disabled { opacity: 0.5; cursor: not-allowed; }
#btn-play { background: rgba(0, 124, 63, 0.7); border-color: rgba(0, 124, 63, 0.8); }
#btn-play:hover:not(:disabled) { background: rgba(0, 124, 63, 0.9); }
#btn-end { background: rgba(209, 32, 38, 0.7); border-color: rgba(209, 32, 38, 0.8); }
#btn-end:hover:not(:disabled) { background: rgba(209, 32, 38, 0.9); }
.join-section { border-top: 1px solid rgba(255,255,255,0.1); padding-top: 10px; }
input[type="text"] { width: 100%; padding: 8px 12px; margin-bottom: 10px; border: 1px solid rgba(255,255,255,0.2); border-radius: 4px; background: rgba(255,255,255,0.1); color: #fff; font-size: 12px; box-sizing: border-box; }
.tile.selected { outline: 3px solid var(--color-blue); box-shadow: 0px 0px 12px 2px rgba(0, 70, 173, 0.6); transform: scale(1.05); }
.tile.operator { color: var(--color-red); }
.tile.equals { color: var(--color-green); }
.tile.parenthesis { color: var(--color-blue); }
.tile.wildcard { color: var(--color-blue); font-style: italic; }
.board-cell.drag-over { background-color: #7a8485; border: 1px dashed var(--tile-ivory); }
.tile.dragging { opacity: 0.5; cursor: grabbing; }
.board-cell .tile { width: 100%; height: 100%; cursor: default; position: absolute; }
.tile.staged { cursor: grab; border: 1px solid var(--color-blue); }
.stack-level-1 { z-index: 1; transform: translate(0, 0); box-shadow: 1px 1px 3px rgba(0,0,0,0.4); }
.stack-level-2 { z-index: 2; transform: translate(-3px, -3px); box-shadow: 3px 3px 6px rgba(0,0,0,0.45); }
.stack-level-3 { z-index: 3; transform: translate(-6px, -6px); box-shadow: 5px 5px 9px rgba(0,0,0,0.5); }
.stack-level-4 { z-index: 4; transform: translate(-9px, -9px); box-shadow: 7px 7px 12px rgba(0,0,0,0.5); }
.tile.wildcard-played { color: var(--color-blue); font-style: italic; }
#notification-container { position: fixed; top: 20px; left: 50%; transform: translateX(-50%); z-index: 1000; display: flex; flex-direction: column; align-items: center; gap: 10px; }
.notification { padding: 12px 20px; background: rgba(40, 40, 40, 0.85); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); color: var(--tile-ivory); font-size: 1em; border-radius: 8px; border: 1px solid rgba(255, 255, 255, 0.15); box-shadow: 0 4px 12px rgba(0,0,0,0.4); opacity: 0; transform: translateY(-20px); transition: transform 0.4s ease, opacity 0.4s ease; }
.notification.show { opacity: 1; transform: translateY(0); }
#chat-messages { flex-grow: 1; overflow-y: auto; border: 1px solid rgba(255, 255, 255, 0.1); border-radius: 4px; padding: 10px; background: rgba(0,0,0,0.2); margin-bottom: 10px; }
.chat-message { margin-bottom: 8px; line-height: 1.4; }
.chat-message .player-name { font-weight: bold; }
#chat-input-area { display: flex; gap: 10px; }
#chat-input { flex-grow: 1; border: 1px solid rgba(255,255,255,0.2); border-radius: 4px; background: rgba(255,255,255,0.1); color: #fff; padding: 8px; }
#btn-send-chat { padding: 8px 12px; font-weight: 600; color: #fff; background: var(--color-blue); border: 1px solid rgba(255, 255, 255, 0.2); border-radius: 4px; cursor: pointer; transition: background-color 0.2s; }
#btn-send-chat:hover { background: #0056b3; }
.chat-message.chat-system { color: var(--tile-ivory); font-style: italic; }
.chat-message.chat-player-1 .player-name { color: var(--color-blue); }
.chat-message.chat-player-2 .player-name { color: var(--board-slate); }

/* ====================================================== */
/* ---             Mobile Layout Overrides            --- */
/* ====================================================== */

@media (max-width: 1099px) {
    body {
        padding: 0px;
    }

    .body-container,
    .game-container,
    .game-area {
        flex-direction: column;
        align-items: center;
        width: 100%;
        gap: 5px;
    }

    .board-and-info-container {
        display: grid;
        grid-template-columns: 1fr 140px;
        width: 100%;
        gap: 10px;
        align-items: stretch;
    }

    #game-board {
        width: 100%;
        height: auto;
        aspect-ratio: 1 / 1;
    }

    .info-panel {
        width: 100%;
        height: 100%;
        padding: 10px;
    }

    .info-panel h2 { font-size: 4vw; margin-bottom: 5px; margin-top: 0; }
    .info-panel .scoreboard { font-size: 3.5vw; }
    .info-panel .game-stats p { font-size: 3vw; margin: 5px 0; }

    .info-panel .action-buttons {
        flex-grow: 0;
    }

    /* This rule was already present, we're just adding a margin for spacing */
    .join-section { 
        border-top: 1px solid rgba(255,255,255,0.1); 
        padding-top: 10px; 
        margin-top: 10px; /* <--- THIS LINE WAS ADDED for clean spacing */
    }

    .info-panel button { padding: 5px; font-size: 3.2vw; margin-top: 4px; }
    .info-panel input[type="text"] { font-size: 3vw; padding: 5px; }
    #game-id-container { font-size: 2.8vw; padding-top: 5px; }


    #chat-container {
        order: 2;
        width: 100%;
        max-width: 600px;
        height: 150px;
        margin-top: 0;
    }

    footer {
        order: 3;
        width: 100%;
        max-width: 600px;
        margin-top: 15px;
     }

#player-rack {
    display: grid;
    grid-template-columns: repeat(14, 1fr);
    /* Use a small, fixed gap instead of a relative one */
    gap: 3px;
    padding: 5px;
    box-sizing: border-box;
}

    .rack-slot {
        width: 100%;
        aspect-ratio: 1 / 1;
        margin: 0;
    }

.tile {
    width: 90%;
    height: 90%;
    /* Use clamp() for a responsive font size with min/max guardrails */
    font-size: clamp(16px, 4vw, 20px);
}

}


@media (max-width: 1099px) and (max-height: 550px) and (orientation: landscape) {

    /* --- Make Info Panel more compact vertically --- */
    .info-panel h2 {
        font-size: 0.9rem;
        margin-bottom: 4px;
    }

    .info-panel .scoreboard,
    .info-panel .game-stats p {
        font-size: 0.75rem;
        margin: 2px 0;
    }

    .info-panel button {
        padding: 4px;
        font-size: 0.7rem;
        margin-top: 4px;
    }

    .info-panel input[type="text"],
    #game-id-container,
    label[for="solo-mode-checkbox"] {
        font-size: 0.7rem;
    }

    /* --- Make Player Rack tiles smaller to prevent overflow --- */
    #player-rack {
        gap: 2px; /* Further reduce the gap between tiles */
    }
    .rack-slot {
        min-width: 0;
    }
.rack-slot .tile {
    font-size: clamp(14px, 3vw, 16px);
}
}

/* --- Help/Rules Modal Styles --- */

/* Style for the new container around the "Game Info" title and help button */
.info-header {
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    margin-bottom: 15px;
}

#btn-help {
    position: absolute;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 28px;
    height: 28px;
    font-size: 16px;
    font-weight: bold;
    border-radius: 50%; /* Make it circular */
    padding: 0;
    margin: 0;
    line-height: 1;
    cursor: pointer;
    background: rgba(255, 255, 255, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: #fff;
}

#btn-help:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* The modal overlay, hidden by default */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
    z-index: 2000;
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

/* The class that makes the modal visible */
.modal-overlay.show-modal {
    opacity: 1;
    visibility: visible;
}

/* The content box of the modal */
.modal-content {
    background: #333;
    color: #fff;
    padding: 20px 30px;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    width: 90%;
    max-width: 800px;
    height: 80vh;
    overflow-y: auto; /* Make the rules scrollable */
    position: relative;
    box-shadow: 0 8px 32px rgba(0,0,0,0.3);
}

/* The 'X' close button */
.modal-close {
    position: absolute;
    top: 10px;
    right: 15px;
    background: none;
    border: none;
    color: #fff;
    font-size: 2.5rem;
    line-height: 1;
    cursor: pointer;
}

/* Basic styling for the injected rules content */
#rules-content h1, #rules-content h3 {
    color: var(--color-red);
}
#rules-content h1 {
    margin-top: 1.5em;
}
#rules-content ul, #rules-content ol {
    line-height: 1.6;
}