body {
    font-family: 'Outfit', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    margin: 0;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    /* Use min-height */
    transition: background-color 0.3s ease;
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
    background: var(--widget-bg);
    backdrop-filter: blur(10px);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
    position: sticky;
    /* Sticky header */
    top: 0;
    z-index: 100;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 15px;
    /* Increased gap */
}

.header-controls {
    display: flex;
    align-items: center;
    gap: 8px;
}



/* Symbol Mode Filled State */
.grid-cell.symbol-mode-filled {
    display: flex;
    justify-content: flex-end;
    /* Push letter to bottom-right */
    align-items: flex-end;
    /* Push letter to bottom-right */
    position: relative;
    padding: 1px 3px 0 0;
    /* Slight padding */
    isolation: isolate;
}

.grid-cell.symbol-mode-filled>span:not(.symbol-corner) {
    z-index: 2;
    position: relative;
    font-size: 1rem;
    /* Smaller letter */
    line-height: 1.2;
}

.symbol-corner {
    position: absolute;
    top: 2px;
    left: 2px;
    font-size: 0.8rem;
    /* Slightly smaller */
    color: #4a90e2;
    pointer-events: none;
    font-weight: bold;
    z-index: 1;
    transform: none;
    /* Force text presentation for symbols (no emojis) */
    font-family: "Segoe UI Symbol", "Deja Vu Sans", Symbola, sans-serif;
    font-variant-emoji: text;
}

@media (max-width: 600px) {
    .symbol-corner {
        font-size: 0.75rem;
        /* Smaller on mobile */
    }

    .grid-cell.symbol-mode-filled>span:not(.symbol-corner) {
        font-size: 0.9rem;
        /* Smaller letter on mobile */
    }

    .grid-cell.filled {
        font-size: 1.3rem;
        /* Adjust filled font size for mobile */
        /* Ensure normal filled cells are sized correctly if needed */
    }
}

/* Clue Word Highlight */
@keyframes clue-pulse {
    0% {
        opacity: 0.6;
    }

    50% {
        opacity: 1;
    }

    100% {
        opacity: 0.6;
    }
}

.grid-cell.clue-highlight::after {
    content: '';
    position: absolute;
    inset: -2px;
    /* Slightly larger than cell */
    border: 3px solid #FFD700;
    /* Gold border */
    box-shadow: 0 0 5px rgba(0, 0, 0, 0.5);
    /* Shadow for contrast */
    z-index: 20;
    /* High z-index to sit on top of everything */
    pointer-events: none;
    animation: clue-pulse 1.5s infinite alternate;
    border-radius: 6px;
    display: block;
}



h1 {
    margin: 0;
    font-size: 1.2rem;
    font-weight: 600;
}

.game-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 1rem;
    /* overflow-y: auto; REMOVED to allow page scroll */
    gap: 1rem;
    width: 100%;
    box-sizing: border-box;
    padding-bottom: 2rem;
    /* Extra padding above footer */
}

.game-layout {
    display: flex;
    flex-direction: row;
    align-items: flex-start;
    justify-content: center;
    gap: 2rem;
    width: 100%;
    max-width: 1200px;
}

.puzzle-area {
    flex: 0 0 auto;
}

.legend-area {
    flex: 1;
    max-width: 300px;
    background: var(--legend-bg);
    padding: 1rem;
    border-radius: 12px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
    min-width: 200px;
    color: var(--text-color);
    transition: background-color 0.3s ease, color 0.3s ease;
}

.legend-area h3 {
    margin-top: 0;
    font-size: 1rem;
    margin-bottom: 0.5rem;
    text-align: center;
    color: var(--text-color);
}

.cipher-legend-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-content: flex-start;
}

.legend-item {
    display: flex;
    flex-direction: row;
    /* Row layout: Symbol - Letter */
    align-items: center;
    justify-content: space-between;
    border: 1px solid var(--grid-border);
    border-radius: 8px;
    padding: 5px 10px;
    cursor: pointer;
    background: var(--legend-item-bg);
    min-width: 60px;
    /* Wider */
    gap: 10px;
    transition: transform 0.1s, background-color 0.3s;
}

.legend-item.solved {
    background-color: rgba(0, 191, 165, 0.1);
    border-color: var(--secondary-color);
}

.legend-item .symbol-preview {
    font-size: 1.2rem;
    line-height: 1;
    width: 24px;
    text-align: center;
    color: #4a90e2;
    /* Match grid numbers */
    font-family: 'Comic Sans MS', 'Chalkboard SE', 'Comic Neue', sans-serif;
    font-weight: bold;
}

.legend-item .letter-preview {
    font-size: 1.3rem;
    font-weight: 800;
    color: #000000;
    /* Black as requested */
}

@media (max-width: 900px) {

    /* Increased breakpoint */
    /* Increased breakpoint */
    .game-layout {
        display: contents;
        /* Remove wrapper form layout flow */
    }

    .puzzle-area {
        order: 1;
        width: 100%;
        display: flex;
        justify-content: center;
    }

    .alphabet-line {
        order: 2;
    }

    .controls-area {
        order: 3;
        width: 100%;
    }

    .legend-area {
        order: 4;
        width: 100%;
        max-width: 600px;
        margin-top: 2rem;
    }

    .cipher-legend-grid {
        justify-content: center;
    }
}

.grid-container {
    display: grid;
    gap: 1px;
    /* Thinner lines */
    background: var(--grid-border);
    padding: 1px;
    /* Thinner border around */
    border-radius: 4px;
    margin: 0 auto;
}

.grid-cell {
    width: var(--cell-size);
    height: var(--cell-size);
    background: var(--grid-bg);
    display: flex;
    justify-content: center;
    align-items: center;
    font-weight: bold;
    cursor: pointer;
    user-select: none;
    position: relative;
    font-size: 1.1rem;
    color: var(--text-color);
}

/* Distinct style for Cipher Numbers (vs User Input Letters) */
.grid-cell:not(.filled):not(.black):not(.image-cell-wrapper) {
    font-family: 'Comic Sans MS', 'Chalkboard SE', 'Comic Neue', sans-serif;
    font-size: 0.9em;
    color: #4a90e2;
    /* Bright readable blue */
    font-weight: bold;
    /* Restored to bold */
}

/* User Input Letters */
.grid-cell.filled {
    font-size: 1.5rem;
    font-weight: 800;
    /* Extra bold */
    color: var(--text-color);
}

.grid-cell.black {
    background-color: #000;
    cursor: default;
}





.grid-cell.active {
    outline: 2px solid var(--primary-color);
    z-index: 10;
}

.grid-cell.word-highlight {
    /* background-color: rgba(255, 255, 255, 0.5) !important; REMOVED to preserve colors */
    box-shadow: inset 0 0 0 3px rgba(255, 193, 7, 0.6) !important;
    /* Thick slightly transparent yellow border */
    z-index: 5;
}

.image-cell {
    width: 100% !important;
    height: 100% !important;
    border: none !important;
    background: transparent !important;
    padding: 0 !important;
    overflow: hidden;
    position: relative;
    border-radius: 4px;
    display: flex !important;
    justify-content: center;
    align-items: center;
    box-shadow: none !important;
    background: #fff !important;
    /* Force white background */
}

.image-cell img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.virtual-keyboard {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 6px;
    max-width: 700px;
    margin: 1rem auto 2rem auto;
    /* Centered with margin */
    padding: 10px;
    background: rgba(0, 0, 0, 0.03);
    border-radius: 12px;
}

.virtual-keyboard button.key {
    width: 40px;
    height: 48px;
    border: none;
    border-radius: 8px;
    background: var(--key-bg);
    color: var(--key-text);
    box-shadow: 0 4px 0 var(--key-shadow);
    font-family: inherit;
    font-weight: 600;
    font-size: 1.1rem;
    cursor: pointer;
    transition: all 0.1s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.virtual-keyboard button.key:active {
    transform: translateY(4px);
    box-shadow: 0 0 0 var(--key-shadow);
}

.virtual-keyboard button.key:hover {
    background-color: var(--bg-color);
    filter: brightness(0.95);
}

/* Header Widgets */
.header-widgets {
    display: flex;
    gap: 15px;
    font-size: 0.9rem;
    align-items: center;
    /* Vertically center all widgets */
}

.widget {
    display: flex;
    align-items: center;
    gap: 5px;
}

.hidden {
    display: none !important;
}

@media (max-width: 600px) {
    :root {
        --cell-size: 22px;
        /* Smaller cells on mobile (was 28px) */
    }

    .header-widgets {
        display: none;
    }

    /* Compact Keyboard */
    .virtual-keyboard {
        gap: 3px;
        padding: 5px;
        margin-top: 0.5rem;
        margin-bottom: 1rem;
    }

    .virtual-keyboard button.key {
        width: 32px;
        height: 38px;
        font-size: 0.9rem;
        border-radius: 6px;
    }

    /* Compact Controls */
    .action-buttons {
        transform: scale(0.9);
        /* Slightly smaller buttons */
        margin-bottom: 0;
        gap: 5px;
    }

    .game-container {
        padding: 0.5rem;
        /* Less padding around edge */
        gap: 0.5rem;
    }
}

/* Error State */
.grid-cell.error {
    background-color: #ffcdd2 !important;
    color: #b71c1c !important;
    animation: shake 0.3s;
}

@keyframes shake {
    0% {
        transform: translateX(0);
    }

    25% {
        transform: translateX(-2px);
    }

    50% {
        transform: translateX(2px);
    }

    75% {
        transform: translateX(-2px);
    }

    100% {
        transform: translateX(0);
    }
}

/* Isolated Image Cell Styles (Merged from fixes.css) */
.image-cell-wrapper {
    background: #ffffff !important;
    padding: 0 !important;
    border: none !important;
    display: flex !important;
    justify-content: center;
    align-items: center;
    overflow: hidden !important;
    position: relative !important;
    /* z-index set in JS to 2000 */
    cursor: zoom-in;
    /* Grid placement is handled by JS grid-area, but ensure defaults don't conflict */
    grid-column: span 4;
    grid-row: span 4;
}

.image-cell-wrapper img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    background: #ffffff;
    /* Ensure image itself has bg just in case */
}