﻿* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

.hidden {
    display: none !important;
}

:root {
    --tile-size: 36px;
    --inv-tile-size: 40px; /* inventory independent size */
    --tile-gap: 0px; /* no gap between tiles */
    --key-size: 36px;
    --key-gap: 4px;
}

body {
    font-family: Arial, Helvetica, sans-serif;
    background: #f7f7f7;
    color: #222;
    overflow-x: hidden;
}

/* Prevent mobile browser pull-to-refresh / overscroll on the root */
html, body {
    overscroll-behavior: none; /* modern browsers (Chrome, Edge, Firefox) */
    -ms-scroll-chaining: none; /* IE/Edge legacy */
    /* touch-action'ı kısıtlama — alt elemanlara bırak */
    touch-action: manipulation;
}

header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 2px;
    background: #1e88e5;
    color: white;
}

.header-left {
    display: flex;
    flex-direction: column;
}

header h1 {
    font-size: 18px;
}

#currentGameName {
    font-size: 12px;
    color: #e3f2fd;
}

#menuBtn {
    background: transparent;
    border: none;
    color: white;
    font-size: 22px;
}

nav#sideMenu {
    /* start hidden; positioning applied when opened by JS */
    box-sizing: border-box;
    font-family: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial;
    position: fixed;
    left: 0;
    top: 52px;
    bottom: 0;
    width: 260px;
    background: #fff;
    border-right: 1px solid #ddd;
    padding: 12px;
    z-index: 20;
}

    nav#sideMenu.hidden {
        display: none;
    }

/* Overlay default hidden (kept in sync with .hidden class) */
#overlay {
    transition: background 220ms ease-out, opacity 220ms ease-out;
}

/* Menu inner content layout (moved from index.html) */
.menu-content {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.menu-section {
    padding: 6px 8px;
    color: #555;
}

    .menu-section label {
        font-weight: 600;
        display: block;
        margin-bottom: 6px;
    }

    .menu-section #sideGameType {
        font-size: 14px;
    }

/* Menu list (vertical) */
.menu-list {
    list-style: none;
    margin: 0;
    padding: 6px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

    .menu-list li {
        margin: 0;
    }

/* Each menu button styled like a scrabble tile + label */
.menu-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 10px;
    border-radius: 8px;
    border: none;
    background: rgba(255,255,255,0.02);
    cursor: pointer;
    width: 100%;
    box-sizing: border-box;
    transition: background 120ms, transform 120ms;
    text-align: left;
    -webkit-tap-highlight-color: transparent;
}

    .menu-item:active {
        transform: translateY(1px);
    }

    .menu-item:hover {
        background: rgba(0,0,0,0.04);
    }

/* The scrabble-like tile on the left */
.menu-tile {
    width: 44px;
    height: 44px;
    min-width: 44px;
    background: linear-gradient(180deg,#fff 0%, #f2eee7 100%);
    border-radius: 6px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 16px;
    color: #222;
    box-shadow: 0 2px 0 rgba(0,0,0,0.08) inset, 0 3px 8px rgba(0,0,0,0.08);
    border: 1px solid rgba(0,0,0,0.06);
}

/* label text */
.menu-label {
    font-size: 16px;
    color: #111;
}

.menu-sub {
    font-size: 12px;
    color: #666;
}

/* small icon inside tile (emoji fallback) */
.menu-tile .icon {
    font-size: 18px;
    line-height: 1;
}

/* Ensure modal content is scrollable on small screens */
nav#sideMenu .menu-list {
    max-height: calc(100vh - 160px);
    overflow: auto;
}

main {
    padding: 0;
    margin-top: 0;
}

#boardArea {
    display: flex;
    justify-content: center;
    margin-bottom: 2px;
    padding: 0; /* remove outer padding so board can extend to edges */
    overflow: hidden;
}

#boardContainer {
    background: #fff;
    padding: 0; /* no padding around board */
    border-radius: 0; /* remove rounded corners */
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    width: 100%;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
}

.board {
    display: grid;
    grid-gap: 0; /* no gap between tiles */
    margin: 0 auto; /* keep centering if narrower than container */
    padding: 0; /* remove internal padding */
}

.tile {
    width: var(--tile-size);
    height: var(--tile-size);
    background: #fafafa;
    border: 1px solid #ddd;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    position: relative;
    border-radius: 5px; /* square corners */
}

    /* tile with a letter placed on it */
    .tile.has-letter {
        background: #F9E69A;
        border-color: #A0510A;
        box-shadow: inset 0 2px 0 rgba(255,255,255,0.18), 0 2px 4px rgba(0,0,0,0.22);
    }

        .tile.has-letter .tile-letter {
            color: #A0510A;
            /* text-shadow: 0 1px 2px rgba(0,0,0,0.45); */
            font-size: calc(var(--tile-size) * 0.58);
        }

        .tile.has-letter.selected {
            box-shadow: inset 0 2px 0 rgba(255,255,255,0.18), 0 0 0 2px rgb(207,22,35) inset;
        }

    .tile .tile-letter {
        position: relative;
        z-index: 4;
        display: flex;
        align-items: center;
        justify-content: center;
        width: 100%;
        height: 100%;
        font-size: calc(var(--tile-size) * 0.55);
        line-height: 1;
    }

.inv-slot {
    width: var(--inv-tile-size);
    height: var(--inv-tile-size);
    border: 2px solid #D4960A;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #F5C322;
    border-radius: 8px;
    font-weight: 800;
    font-size: calc(var(--inv-tile-size) * 0.56);
    color: #5A2D00;
    /* box-shadow: inset 0 2px 0 rgba(255,255,255,0.35), 0 3px 6px rgba(0,0,0,0.15); */
    position: relative;
}

.tile.selected {
    box-shadow: 0 0 0 2px rgb(207, 22, 35) inset;
}

.inv-slot.selected {
    box-shadow: 0 0 0 2px rgb(207, 22, 35) inset;
}

.tile-letter.dir-right::after,
.tile-letter.dir-down::after {
    content: '>';
    position: absolute;
    /* base positioning removed so each direction can place the arrow precisely */
    font-size: calc(var(--tile-size) * 0.38);
    /* place the arrow in the bottom-right corner to avoid overlapping the main letter */
    /* make the arrow smaller so it does not compete with the tile letter */
    font-weight: 800;
    color: rgb(207, 22, 35);
    text-shadow: 0 0 3px rgba(0,0,0,0.35);
    pointer-events: none;
    z-index: 3;
    line-height: 1;
    transform-origin: center;
}

.tile-letter.dir-right::after {
    /* Right-direction: center vertically on the right edge and slightly overflow to the right */
    top: 50%;
    right: calc(var(--tile-size) * -0.12); /* negative value to make it protrude outside the tile */
    transform: translateY(-50%) rotate(0deg);
}

.tile-letter.dir-down::after {
    /* Down-direction: center horizontally on the bottom edge and slightly overflow downward */
    left: 50%;
    bottom: calc(var(--tile-size) * -0.12);
    transform: translateX(-50%) rotate(90deg);
}

.tile .tile-bonus {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: calc(var(--tile-size) * 0.5);
    font-weight: 700;
    color: rgba(0, 0, 0, 0.42);
    z-index: 1;
    pointer-events: none;
    user-select: none;
    line-height: 1;
}

/* Bonus square styles */
.tile.extra-K3 {
    background: #C1AB96;
}

.tile.extra-K2 {
    background: #A3C19B;
}

.tile.extra-H3 {
    background: #CDBACD;
}

.tile.extra-H2 {
    background: #9ABAC5;
}

.tile.extra-YILDIZ {
    background: #F4D28A;
}

.tile.has-letter.extra-K3,
.tile.has-letter.extra-K2,
.tile.has-letter.extra-H3,
.tile.has-letter.extra-H2,
.tile.has-letter.extra-YILDIZ {
    background: #F9E69A;
    border-color: #A0510A;
}

#rackArea {   
    background: transparent;
}

#inventorySlots {
    display: flex;
    gap: var(--tile-gap);
    justify-content: center;
    flex-wrap: nowrap;
}

.rack-controls {
    display: flex;
    gap: 8px;
    margin-top: 2px;
    justify-content: space-between;
}

    .rack-controls button {
        flex: 1;
        padding: 8px;
        border-radius: 6px;
        border: 1px solid #ddd;
        background: #fff;
    }

/* Score badges adjusted: smaller, nudged out to avoid letter overlap */
.tile .tile-score,
.inv-slot .slot-score,
.tile .preview-score {
    position: absolute;
    top: calc(var(--tile-size) * 0.05);
    right: calc(var(--tile-size) * 0.05);
    transform: translate(40%, -40%);
    min-width: calc(var(--tile-size) * 0.32);
    height: calc(var(--tile-size) * 0.32);
    padding: 0 calc(var(--tile-size) * 0.05);
    border-radius: 999px;
    background: rgba(255,255,255,0.92);
    /* border: 1px solid rgba(0,0,0,0.12); */
    color: #333;
    font-weight: 700;
    font-size: calc(var(--tile-size) * 0.3);
    line-height: calc(var(--tile-size) * 0.32);
    text-align: center;
    pointer-events: none;
    user-select: none;
    z-index: 6;
    /* box-shadow: 0 1px 0 rgba(0,0,0,0.06); */
}

.inv-slot .slot-score {
    font-size: calc(var(--key-size) * 0.3);
}

.tile .preview-letter {
    z-index: 7;
}

.tile .preview-score {
    z-index: 6;
}

#keyboardArea {
    margin-top: 2px;
    padding: 0 4px;
}

#keyboardContainer {
    display: flex;
    flex-direction: column;
    gap: var(--key-gap);    
    margin: 0 auto;
}

.key-row {
    display: flex;
    gap: var(--key-gap);
    justify-content: center;
}

.key {
    width: var(--key-size);
    height: var(--key-size);
    background: #eee;
    border-radius: 4px;
    border: 1px solid #ddd;
    cursor: pointer;
    text-align: center;
    font-weight: 600;
    font-size: calc(var(--key-size) * 0.42);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    padding: 0;
}
    /* force-remove any focus outline/box-shadow for key elements */
    .key:focus,
    .key:focus-visible,
    .menu-item:focus,
    .modal-btn:focus {
        outline: none !important;
        box-shadow: none !important;
    }

/* remove Firefox inner focus border on buttons */
button.key::-moz-focus-inner {
    border: 0;
    padding: 0;
}

/* remove mobile tap highlight */
.key, .menu-item {
    -webkit-tap-highlight-color: transparent;
}

#movesArea {
    background: #fff;
    padding: 8px;
    border-radius: 8px;
    max-height: 250px;
    overflow-y: auto;
    margin-top: 8px;
}

#movesList {
    list-style: none;
    margin: 0;
    padding: 0;
}

    #movesList li {
        padding: 8px;
        border-bottom: 1px solid #eee;
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 6px;
        cursor: pointer;
        user-select: none;
    }

        #movesList li.active-move {
            background: #fff3e0;
        }

        #movesList li .move-info {
            flex: 1;
            font-size: 13px;
        }

        #movesList li .move-play-btn {
            flex-shrink: 0;
            background: #43a047;
            color: #fff;
            border: none;
            border-radius: 50%;
            width: 28px;
            height: 28px;
            font-size: 14px;
            cursor: pointer;
            display: flex;
            align-items: center;
            justify-content: center;
            line-height: 1;
        }

#controls {
    display: flex;
    gap: 8px;
    margin-bottom: 8px;
}

    #controls button {
        flex: 1;
        padding: 10px;
        font-size: 16px;
    }

/* Modal backdrop: dark and blocks interaction with page while open */
.modal {
    position: fixed;
    left: 0;
    top: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.6); /* darker backdrop */
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1200; /* above other UI */
    -webkit-backdrop-filter: blur(2px);
    backdrop-filter: blur(2px);
    transition: opacity 160ms ease-in-out;
    opacity: 1;
    pointer-events: auto; /* ensure it captures clicks so underlying UI isn't clickable */
}

    .modal.hidden {
        display: none;
        opacity: 0;
        pointer-events: none;
    }

.modal-content {
    background: #fff;
    padding: 16px;
    border-radius: 8px;
    width: 90%;
    max-width: 720px;
    box-shadow: 0 12px 40px rgba(0,0,0,0.24);
    pointer-events: auto;
}

.modal-actions {
    display: flex;
    gap: 12px;
    margin-top: 12px;
    justify-content: flex-end;
}

.modal-content ul {
    max-height: 300px;
    overflow: auto;
    list-style: none;
    padding: 0;
}

.modal-content li {
    padding: 8px;
    border-bottom: 1px solid #eee;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.tile.move-preview {
    box-shadow: 0 0 0 2px #e53935 inset;
}

.tile .preview-letter {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: calc(var(--tile-size) * 0.56);
    color: #5A2D00;
    background: #F5C322;
    z-index: 7;
    pointer-events: none;
    border: 2px solid #D4960A;
    border-radius: 8px;
    line-height: 1;
}

/* Modal - improved controls */
.modal-content select#modalGameTypeSelect {
    width: 100%;
    padding: 12px 14px;
    font-size: 18px;
    border-radius: 8px;
    border: 1px solid #ddd;
    margin-top: 6px;
    background: linear-gradient(180deg,#fff,#fbfbfb);
}

.modal-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    border-radius: 8px;
    border: 1px solid #ccc;
    background: #fff;
    cursor: pointer;
    font-weight: 600;
}

    .modal-btn.primary {
        background: linear-gradient(180deg,#3b82f6,#1e40af);
        color: #fff;
        border-color: rgba(0,0,0,0.12);
    }

    .modal-btn.warn {
        background: linear-gradient(180deg,#f97316,#c2410c);
        color: #fff;
        border-color: rgba(0,0,0,0.08);
    }

    .modal-btn .modal-btn-icon {
        display: inline-flex;
        width: 22px;
        height: 22px;
        align-items: center;
        justify-content: center;
        font-size: 14px;
    }

    .modal-btn:active {
        transform: translateY(1px);
    }

    /* modal-btn small variant for list actions */
    .modal-btn.small {
        padding: 6px 10px;
        font-size: 14px;
        border-radius: 6px;
    }

.saved-games-list li .modal-btn {
    min-width: 84px;
}

/* Ensure the overlay element covers background and receives clicks while modal open */
#overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.45);
    z-index: 1100;
    display: none;
}

    #overlay.visible {
        display: block;
    }

/* Slightly rounder modal on small screens and larger padding */
.modal-content {
    padding: 20px;
    border-radius: 12px;
    max-width: 520px;
}

/* Make sure modal itself sits above overlay */
.modal {
    z-index: 1200;
}

/* Accessibility: focus states */
.modal-btn:focus, .menu-item:focus, .key:focus, .menu-item:focus {
    outline: 3px solid rgba(100,149,237,0.3);
    outline-offset: 2px;
}

/* Larger select on smaller screens */
@media (min-width: 700px) {
    .modal-content {
        max-width: 520px;
    }
}

/* modal input styling */
.modal-content .modal-input, .modal-content input#saveNameInput {
    width: 100%;
    padding: 12px 14px;
    font-size: 17px;
    border-radius: 8px;
    border: 1px solid #ddd;
    margin-top: 6px;
}

/* For save modal center actions on small screens */
#saveNameModal .modal-actions {
    justify-content: center;
}

    #saveNameModal .modal-actions .modal-btn {
        min-width: 120px;
    }

    /* Unsaved modal action layout */
.modal-actions.unsaved-actions {
    justify-content: space-between;
}

    .modal-actions.unsaved-actions .modal-btn {
        flex: 1;
        min-width: 0;
    }

        .modal-actions.unsaved-actions .modal-btn + .modal-btn {
            margin-left: 10px;
        }

    /* Make unsaved modal buttons more compact and allow multi-line labels on small screens.
       Stack icon above text to improve fit when there isn't enough horizontal space. */
.modal-actions.unsaved-actions {
    justify-content: space-between;
    gap: 8px;
}

    .modal-actions.unsaved-actions .modal-btn {
        flex: 1;
        min-width: 0;
        padding: 8px 10px;
        font-size: 14px;
        gap: 6px;
        align-items: center;
        justify-content: center;
        white-space: normal;
        /* stack icon and text vertically on narrow widths */
        flex-direction: column;
    }

        /* smaller icon for stacked layout */
        .modal-actions.unsaved-actions .modal-btn .modal-btn-icon {
            width: 18px;
            height: 18px;
            font-size: 12px;
            display: inline-flex;
            align-items: center;
            justify-content: center;
        }

        /* center label and allow wrapping */
        .modal-actions.unsaved-actions .modal-btn .modal-btn-text {
            display: block;
            text-align: center;
            line-height: 1.1;
        }

        /* maintain spacing between buttons when stacked */
        .modal-actions.unsaved-actions .modal-btn + .modal-btn {
            margin-left: 0;
        }

    /* On wider screens restore row layout and slightly larger sizes */
    @media (min-width: 480px) {
        .modal-actions.unsaved-actions .modal-btn {
            flex-direction: row;
            font-size: 15px;
            padding: 10px 14px;
        }

            .modal-actions.unsaved-actions .modal-btn .modal-btn-icon {
                width: 22px;
                height: 22px;
                font-size: 14px;
            }
    }

/* ── Zoom Button ─────────────────────────────────────────────────────── */
#zoomBtn {
    background: transparent;
    border: none;
    color: white;
    font-size: 20px;
    cursor: pointer;
    padding: 2px 4px;
    line-height: 1;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}

    #zoomBtn:focus {
        outline: none;
    }

    #zoomBtn.zoomed {
        opacity: 0.75;
        filter: brightness(1.4);
    }

/* ── Zoom Scroll Container ───────────────────────────────────────────── */
/* boardContainer gets overflow-x:auto normally; when zoom active we
   change the wrapper to clip and allow panning via a scroll container  */
#boardScrollOuter {
    width: 100%;
    /* Her iki eksende scroll izin ver — yükseklik JS tarafından ayarlanır */
    overflow-x: auto;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    /* prevent the scroll container itself from pulling to refresh */
    overscroll-behavior: contain;
    /* touch-action: tahtanın içini tüm yönlerde kaydırılabilir yap;
       sayfa scroll'una olayın taşmasını önle */
    touch-action: pan-x pan-y;
    /* max-height: ekranın görebildiği kısım kadar; JS height ile birlikte çalışır */
    max-height: 65vh;
}

/* When zoomed, the board inner content is scaled up */
#boardContainer.zoom-active {
    overflow: visible;          /* let scaled content overflow into scroll outer */
    width: max-content !important;
    margin-left: 0 !important;
    margin-right: 0 !important;
}

    #boardContainer.zoom-active .board-wrapper {
        transform-origin: top left;
        /* scale set via JS as inline style */
    }
/* ───────────────────────────────────────────────────────────────────── */
