@import url('https://fonts.googleapis.com/css2?family=Josefin+Sans:wght@300;400;600&family=Playfair+Display:wght@700&display=swap');

:root {
    --gold: #D4AF37;
    --dark-gold: #AA8C2C;
    --black: #111111;
    --panel-bg: #1a1a1a;
    --text-color: #f0f0f0;

    /* Continent Colors - to be set dynamically or helpers */
    --europe: #4da6ff;
    --asia: #ff6666;
    --na: #ffcc00;
    --sa: #66ff66;
    --africa: #cc99ff;
    --oceania: #ff99cc;
}

body {
    background-color: var(--black);
    color: var(--text-color);
    font-family: 'Josefin Sans', sans-serif;
    margin: 0;
    padding: 0;
    overflow: hidden;
    /* Prevent scroll if possible, full app feel */
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
}

.app-container {
    display: flex;
    width: 95vw;
    height: 90vh;
    border: 4px solid var(--gold);
    background-color: var(--black);
    box-shadow: 0 0 20px rgba(212, 175, 55, 0.2);
    position: relative;
    padding: 20px;
    gap: 20px;
}

/* Corner decorations */
.app-container::before {
    content: '';
    position: absolute;
    top: 5px;
    left: 5px;
    right: 5px;
    bottom: 5px;
    border: 1px solid var(--gold);
    pointer-events: none;
}

.sidebar {
    width: 350px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    border-right: 2px solid var(--gold);
    padding-right: 20px;
    overflow-y: auto;
}

.back-button-floating {
    position: absolute;
    top: 15px;
    right: 15px;
    text-decoration: none;
    color: var(--gold);
    border: 1px solid var(--gold);
    padding: 8px 15px;
    font-size: 0.8em;
    font-weight: bold;
    background: rgba(26, 26, 26, 0.9);
    z-index: 200;
    text-transform: uppercase;
    transition: all 0.3s;
}

.back-button-floating:hover {
    background: var(--gold);
    color: var(--black);
}

.title {
    font-family: 'Playfair Display', serif;
    font-size: 3em;
    color: var(--gold);
    text-align: center;
    text-transform: uppercase;
    letter-spacing: 2px;
    border-bottom: 2px double var(--gold);
    padding-bottom: 10px;
    margin-bottom: 0;
}

.subtitle {
    text-align: center;
    color: var(--dark-gold);
    font-size: 0.9em;
    text-transform: uppercase;
    letter-spacing: 3px;
    margin-top: 5px;
}

.legend {
    display: none;
    /* Hidden by default */
    flex-wrap: wrap;
    gap: 10px;
    padding: 10px;
    border: 1px solid var(--gold);
    background-color: var(--black);
    position: absolute;
    /* Floating on the field? or just sidebar? User said 'appear on the field' */
    bottom: 20px;
    left: 20px;
    z-index: 100;
}

.legend.visible {
    display: flex;
}


.legend-item {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 0.8em;
    width: 45%;
}

.color-box {
    width: 15px;
    height: 15px;
    border: 1px solid white;
}

.clue-panel {
    flex-grow: 1;
    overflow-y: auto;
    border-top: 2px solid var(--gold);
    padding-top: 10px;
}

.clue-header {
    font-family: 'Playfair Display', serif;
    color: var(--gold);
    margin-bottom: 10px;
    font-size: 1.2em;
}

.clue-list {
    list-style: none;
    padding: 0;
}

.clue-item {
    margin-bottom: 15px;
    cursor: pointer;
    padding: 5px;
    border-left: 3px solid transparent;
    transition: all 0.3s;
}

.clue-item:hover,
.clue-item.active {
    background-color: rgba(212, 175, 55, 0.1);
    border-left-color: var(--gold);
}

.clue-number {
    font-weight: bold;
    color: var(--gold);
    margin-right: 5px;
}

.clue-category {
    font-size: 0.7em;
    text-transform: uppercase;
    color: #999;
    display: block;
    margin-bottom: 2px;
}

.game-area {
    flex-grow: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    overflow: auto;
}

.crossword-grid {
    display: grid;
    /* Gap handled by cell borders for cleaner 'floating' look */
    /* background-color: var(--gold); Remove solid background to avoid gold voids */
    border: none;
    /* No outer border for the whole grid area, just cells */
    padding: 2px;
}

.cell {
    width: 35px;
    height: 35px;
    background-color: var(--black);
    border: 1px solid var(--gold);
    /* Individual cell borders */
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    font-family: 'Josefin Sans', sans-serif;
    font-weight: bold;
    font-size: 1.2em;
    text-transform: uppercase;
    cursor: pointer;
    transition: background-color 0.3s;
    user-select: none;
    margin: -1px 0 0 -1px;
    /* Collapse borders */
}

.cell.empty {
    background-color: transparent;
    border: none;
    pointer-events: none;
}

.cell.block {
    background-color: var(--black);
    /* Or a pattern */
}

/* Number in the cell */
.cell-number {
    position: absolute;
    top: 2px;
    left: 2px;
    font-size: 0.5em;
    color: var(--gold);
    pointer-events: none;
}

.cell.active {
    background-color: rgba(212, 175, 55, 0.3);
}

.cell.focused {
    background-color: rgba(212, 175, 55, 0.6);
    color: #fff;
    outline: 2px solid #fff;
    /* Distinct outline */
    z-index: 10;
    /* Bring to front */
}

.cell input {
    width: 100%;
    height: 100%;
    background: transparent;
    border: none;
    color: inherit;
    text-align: center;
    font-family: inherit;
    font-size: inherit;
    font-weight: inherit;
    text-transform: uppercase;
    outline: none;
    caret-color: transparent;
    /* Hide caret to mimic standard crossword feel */
    cursor: pointer;
}

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

::-webkit-scrollbar-track {
    background: var(--black);
}

::-webkit-scrollbar-thumb {
    background: var(--gold);
}

/* Mobile Responsive Adjustments */
@media (max-width: 768px) {
    body {
        /* Allow body scroll if needed, but we try to contain it */
        position: fixed;
        width: 100%;
        height: 100%;
    }

    .app-container {
        width: 100%;
        height: 100%;
        border: none;
        flex-direction: column;
        padding: 0;
        gap: 0;
        box-shadow: none;
        background-color: var(--black);
    }

    .app-container::before {
        display: none;
    }

    /* Move Back Button to Top-Left on Mobile to avoid overlapping with top-right site UI */
    .back-button-floating {
        top: 10px;
        left: 10px;
        right: auto;
        padding: 5px 10px;
        font-size: 0.7em;
        background: var(--black);
        /* Ensure visibility */
        border-color: var(--gold);
    }

    .sidebar {
        width: 100%;
        height: 40vh;
        /* Give enough space for clues */
        border-right: none;
        border-bottom: 2px solid var(--gold);
        padding: 40px 10px 10px 10px;
        /* Top padding for the back button */
        box-sizing: border-box;
        display: flex;
        flex-direction: column;
        background-color: var(--black);
        z-index: 10;
        flex-shrink: 0;
    }

    .title {
        font-size: 1.5em;
        margin: 0 0 5px 0;
        padding-bottom: 5px;
        line-height: 1;
    }

    .subtitle {
        display: none;
    }

    .controls {
        display: flex;
        justify-content: center;
        gap: 10px;
        margin-bottom: 5px;
        flex-shrink: 0;
    }

    .controls button {
        padding: 5px 10px !important;
        font-size: 0.75em;
    }

    .clue-panel {
        display: flex;
        gap: 10px;
        flex: 1;
        min-height: 0;
        /* Crucial for flex nested scrolling */
        border-top: 1px solid var(--gold);
        padding-top: 5px;
    }

    #clues-across,
    #clues-down {
        flex: 1;
        overflow-y: auto;
        height: 100%;
        padding-right: 2px;
    }

    .game-area {
        width: 100%;
        height: 60vh;
        flex-grow: 1;
        padding: 20px;
        position: relative;
        overflow: auto;
        /* Enable scrolling for the grid */
        background-color: var(--panel-bg);
        -webkit-overflow-scrolling: touch;
        /* Smooth scroll on iOS */
        display: block;
        /* Ensure standard block scrolling behavior */
    }

    #grid-container {
        /* Ensure the container is large enough to hold the grid */
        display: inline-block;
        min-width: 100%;
        min-height: 100%;
        padding-bottom: 50px;
        /* Extra space at bottom */
    }

    /* Prevent iOS zoom on inputs */
    .cell input {
        font-size: 16px;
    }

    /* Make cells slightly smaller if needed, or keep them touch-friendly */
    .cell {
        width: 32px;
        height: 32px;
        font-size: 1em;
    }

    .crossword-grid {
        /* Let the grid expand naturally */
        margin: 0 auto;
    }
}