:root {
    --bg-color: #f8f9fa;
    --grid-bg: rgba(255, 255, 255, 0.8);
    --cell-bg: rgba(255, 255, 255, 0.95);
    --wall-bg: rgba(0, 0, 0, 0.05);
    --text-color: #333333;
    --selected-bg: rgba(0, 0, 0, 0.1);
    --glow-color: rgba(0, 0, 0, 0.2);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: linear-gradient(135deg, #e0eafc 0%, #cfdef3 100%);
    color: var(--text-color);
    display: flex;
    flex-direction: column;
    align-items: center;
    margin: 0;
    padding: 20px;
    user-select: none;
    touch-action: manipulation;
    min-height: 100vh;
    box-sizing: border-box;
}

h1 {
    margin-top: 5px;
    margin-bottom: 10px;
    font-size: 22px;
    text-align: center;
    font-weight: 800;
    color: #333333;
    text-shadow: 0 1px 2px rgba(255, 255, 255, 0.8);
    letter-spacing: 2px;
    text-transform: uppercase;
}

#game-container {
    max-width: 400px;
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
}

#grid {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 6px;
    background-color: var(--grid-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    padding: 8px;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.5);
    margin-bottom: 20px;
    width: 100%;
    max-width: 320px;
    box-sizing: border-box;
    touch-action: none;
    box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.1);
    /* Prevents scrolling while dragging */
}

.cell {
    position: relative;
    aspect-ratio: 1;
    background-color: var(--cell-bg);
    border-radius: 8px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 24px;
    font-weight: 700;
    cursor: pointer;
    transition: transform 0.15s ease, background-color 0.2s ease, box-shadow 0.2s ease;
    color: #333333;
    border: 1px solid rgba(0, 0, 0, 0.1);
    text-shadow: none;
}

.cell span {
    position: relative;
    z-index: 10;
    display: block;
    pointer-events: none;
}

/* The connecting line */
.cell::before {
    content: '';
    position: absolute;
    opacity: 0;
    transition: opacity 0.15s ease;
    pointer-events: none;
    z-index: 2;
    background-color: inherit;
    filter: brightness(0.9);
    border-radius: 4px;
}

.cell.dir-right::before {
    opacity: 1;
    top: 50%;
    left: 50%;
    width: calc(100% + 6px);
    height: 12px;
    transform: translateY(-50%);
}
.cell.dir-left::before {
    opacity: 1;
    top: 50%;
    right: 50%;
    width: calc(100% + 6px);
    height: 12px;
    transform: translateY(-50%);
}
.cell.dir-down::before {
    opacity: 1;
    top: 50%;
    left: 50%;
    height: calc(100% + 6px);
    width: 12px;
    transform: translateX(-50%);
}
.cell.dir-up::before {
    opacity: 1;
    bottom: 50%;
    left: 50%;
    height: calc(100% + 6px);
    width: 12px;
    transform: translateX(-50%);
}

/* The directional chevron */
.cell::after {
    content: '';
    position: absolute;
    opacity: 0;
    transition: opacity 0.15s ease;
    pointer-events: none;
    z-index: 3;
    background-image: url('data:image/svg+xml;utf8,<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M9 18l6-6-6-6" fill="none" stroke="%23ffffff" stroke-width="4" stroke-linecap="round" stroke-linejoin="round"/></svg>');
    background-size: contain;
    background-repeat: no-repeat;
    width: 12px;
    height: 12px;
    filter: drop-shadow(0 1px 2px rgba(0,0,0,0.4));
}

.cell.dir-right::after {
    opacity: 1;
    right: -9px;
    top: 50%;
    transform: translateY(-50%);
}

.cell.dir-left::after {
    opacity: 1;
    left: -9px;
    top: 50%;
    transform: translateY(-50%) rotate(180deg);
}

.cell.dir-down::after {
    opacity: 1;
    bottom: -9px;
    left: 50%;
    transform: translateX(-50%) rotate(90deg);
}

.cell.dir-up::after {
    opacity: 1;
    top: -9px;
    left: 50%;
    transform: translateX(-50%) rotate(-90deg);
}

.cell.wall {
    background-color: var(--wall-bg);
    cursor: default;
    border: 1px solid rgba(0, 0, 0, 0.05);
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.05);
    color: transparent;
}

.cell.selected {
    background-color: var(--selected-bg);
    transform: scale(0.92);
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.2), inset 0 0 0 2px rgba(0, 0, 0, 0.1);
    color: #333;
    text-shadow: none;
    z-index: 10;
}

/* Distinct colors for solved words */
.color-0 {
    background-color: rgba(255, 183, 77, 0.8) !important;
    box-shadow: 0 0 15px rgba(255, 183, 77, 0.6), inset 0 0 0 1px rgba(255, 255, 255, 0.5) !important;
    color: white;
    border: none;
    text-shadow: 0 0 5px rgba(255, 255, 255, 0.8);
}

.color-1 {
    background-color: rgba(240, 98, 146, 0.8) !important;
    box-shadow: 0 0 15px rgba(240, 98, 146, 0.6), inset 0 0 0 1px rgba(255, 255, 255, 0.5) !important;
    color: white;
    border: none;
    text-shadow: 0 0 5px rgba(255, 255, 255, 0.8);
}

.color-2 {
    background-color: rgba(77, 208, 225, 0.8) !important;
    box-shadow: 0 0 15px rgba(77, 208, 225, 0.6), inset 0 0 0 1px rgba(255, 255, 255, 0.5) !important;
    color: white;
    border: none;
    text-shadow: 0 0 5px rgba(255, 255, 255, 0.8);
}

.color-3 {
    background-color: rgba(186, 104, 200, 0.8) !important;
    box-shadow: 0 0 15px rgba(186, 104, 200, 0.6), inset 0 0 0 1px rgba(255, 255, 255, 0.5) !important;
    color: white;
    border: none;
    text-shadow: 0 0 5px rgba(255, 255, 255, 0.8);
}

.color-4 {
    background-color: rgba(255, 138, 101, 0.8) !important;
    box-shadow: 0 0 15px rgba(255, 138, 101, 0.6), inset 0 0 0 1px rgba(255, 255, 255, 0.5) !important;
    color: white;
    border: none;
    text-shadow: 0 0 5px rgba(255, 255, 255, 0.8);
}

.color-5 {
    background-color: rgba(129, 199, 132, 0.8) !important;
    box-shadow: 0 0 15px rgba(129, 199, 132, 0.6), inset 0 0 0 1px rgba(255, 255, 255, 0.5) !important;
    color: white;
    border: none;
    text-shadow: 0 0 5px rgba(255, 255, 255, 0.8);
}

.color-6 {
    background-color: rgba(121, 134, 203, 0.8) !important;
    box-shadow: 0 0 15px rgba(121, 134, 203, 0.6), inset 0 0 0 1px rgba(255, 255, 255, 0.5) !important;
    color: white;
    border: none;
    text-shadow: 0 0 5px rgba(255, 255, 255, 0.8);
}

.color-7 {
    background-color: rgba(144, 202, 249, 0.8) !important;
    box-shadow: 0 0 15px rgba(144, 202, 249, 0.6), inset 0 0 0 1px rgba(255, 255, 255, 0.5) !important;
    color: white;
    border: none;
    text-shadow: 0 0 5px rgba(255, 255, 255, 0.8);
}

.color-8 {
    background-color: rgba(255, 213, 79, 0.8) !important;
    box-shadow: 0 0 15px rgba(255, 213, 79, 0.6), inset 0 0 0 1px rgba(255, 255, 255, 0.5) !important;
    color: white;
    border: none;
    text-shadow: 0 0 5px rgba(255, 255, 255, 0.8);
}

.color-9 {
    background-color: rgba(161, 136, 127, 0.8) !important;
    box-shadow: 0 0 15px rgba(161, 136, 127, 0.6), inset 0 0 0 1px rgba(255, 255, 255, 0.5) !important;
    color: white;
    border: none;
    text-shadow: 0 0 5px rgba(255, 255, 255, 0.8);
}

#word-slots {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 30px;
    width: 100%;
}

.slot-row {
    display: flex;
    justify-content: center;
}

.slots-wrapper {
    display: flex;
    gap: 6px;
    position: relative;
}

.debug-word {
    position: absolute;
    left: 100%;
    top: 50%;
    transform: translateY(-50%);
    margin-left: 15px;
    font-size: 14px;
    color: #dc3545;
    font-weight: bold;
    white-space: nowrap;
    letter-spacing: 2px;
}

.slot-cell {
    width: 32px;
    height: 32px;
    background-color: rgba(255, 255, 255, 0.6);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    border: 1px solid rgba(0, 0, 0, 0.1);
    border-radius: 6px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-weight: bold;
    font-size: 16px;
    text-transform: uppercase;
    color: rgba(0, 0, 0, 0.3);
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.05);
}

.slot-row.solved .slot-cell {
    color: white;
    background-color: rgba(0, 0, 0, 0.05);
    border-color: rgba(0, 0, 0, 0.2);
    text-shadow: 0 0 2px rgba(0, 0, 0, 0.2);
}

.slot-row.solved.interactive {
    cursor: pointer;
    transition: transform 0.1s;
}

.slot-row.solved.interactive:hover {
    transform: scale(0.98);
}

button {
    padding: 10px 24px;
    font-size: 14px;
    font-weight: bold;
    color: #333;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.8), rgba(255, 255, 255, 0.5));
    border: 1px solid rgba(0, 0, 0, 0.1);
    border-radius: 20px;
    cursor: pointer;
    transition: all 0.2s ease;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
    letter-spacing: 1px;
    text-transform: uppercase;
}

button:hover {
    background: linear-gradient(135deg, rgba(255, 255, 255, 1), rgba(255, 255, 255, 0.8));
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.15);
    border-color: rgba(0, 0, 0, 0.2);
}

button:active {
    transform: translateY(1px);
}

#current-word {
    height: 32px;
    font-size: 24px;
    font-weight: bold;
    color: #333333;
    text-shadow: none;
    letter-spacing: 4px;
    text-transform: uppercase;
    margin-bottom: 10px;
    text-align: center;
    width: 100%;
}

#message {
    font-weight: bold;
    color: #333;
    text-shadow: none;
    letter-spacing: 1px;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 24px;
}

.spinner {
    width: 20px;
    height: 20px;
    border: 3px solid rgba(0, 0, 0, 0.1);
    border-radius: 50%;
    border-top-color: #333;
    animation: spin 1s ease-in-out infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.grid-victory-pulse {
    animation: grid-victory-pulse 1.5s ease-in-out infinite alternate;
}

@keyframes grid-victory-pulse {
    0% {
        transform: scale(1);
        box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.1);
    }

    100% {
        transform: scale(1.03);
        box-shadow: 0 8px 32px 0 rgba(0, 229, 255, 0.4), 0 0 20px rgba(0, 229, 255, 0.3);
    }
}

#top-area {
    min-height: 55px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    width: 100%;
    margin-bottom: 15px;
}

.controls {
    display: flex;
    align-items: flex-end;
    justify-content: center;
    gap: 15px;
    flex-wrap: wrap;
}

.control-group {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
}

.controls label {
    color: #555;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 700;
}

.select-wrapper {
    position: relative;
}

.select-wrapper::after {
    content: '▼';
    font-size: 9px;
    color: #666;
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    pointer-events: none;
}

.controls select {
    padding: 10px 32px 10px 14px;
    background: rgba(255, 255, 255, 0.85);
    color: #333;
    border: 1px solid rgba(0, 0, 0, 0.1);
    border-radius: 12px;
    outline: none;
    cursor: pointer;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    font-weight: 700;
    font-size: 14px;
    appearance: none;
    -webkit-appearance: none;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.05);
    transition: all 0.2s ease;
}

.controls select:hover {
    background: rgba(255, 255, 255, 1);
    box-shadow: 0 6px 15px rgba(0, 0, 0, 0.1);
    transform: translateY(-1px);
}

.controls select:active {
    transform: translateY(0);
}

.controls select option {
    background: #ffffff;
    color: #333;
    font-weight: bold;
}

/* Modal Styling */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.7);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
    backdrop-filter: blur(5px);
    transition: opacity 0.3s ease;
}

.modal.hidden {
    opacity: 0;
    pointer-events: none;
}

.modal-content {
    background: linear-gradient(135deg, #ffffff 0%, #f4f6f9 100%);
    padding: 30px;
    border-radius: 12px;
    border: 1px solid rgba(0, 0, 0, 0.1);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
    max-width: 90%;
    width: 350px;
    position: relative;
    color: var(--text-color);
}

.close-modal {
    position: absolute;
    top: 10px;
    right: 15px;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
    color: rgba(0, 0, 0, 0.4);
    transition: color 0.2s;
}

.close-modal:hover {
    color: #000;
}

#modal-word-title {
    margin-top: 0;
    font-size: 24px;
    text-transform: uppercase;
    letter-spacing: 2px;
    color: #0099aa;
    text-shadow: none;
    border-bottom: 1px solid rgba(0, 0, 0, 0.1);
    padding-bottom: 10px;
    margin-bottom: 15px;
}

#modal-word-definition {
    font-size: 16px;
    line-height: 1.5;
    max-height: 50vh;
    overflow-y: auto;
}

.def-part-of-speech {
    font-style: italic;
    color: rgba(0, 0, 0, 0.6);
    margin-top: 10px;
    margin-bottom: 5px;
    font-weight: bold;
}

.def-meaning {
    margin-left: 15px;
    margin-bottom: 8px;
    position: relative;
    color: rgba(0, 0, 0, 0.8);
}

.def-meaning::before {
    content: "•";
    position: absolute;
    left: -15px;
    color: #0099aa;
}

/* Responsive adjustments for smaller screens */
@media (max-width: 420px),
(max-height: 800px) {
    body {
        padding: 10px;
    }

    #game-container {
        max-width: 350px;
    }

    h1 {
        font-size: 24px;
        margin-top: 5px;
        margin-bottom: 10px;
    }

    #grid {
        gap: 4px;
        padding: 6px;
        margin-bottom: 15px;
        border-radius: 8px;
    }

    .cell {
        font-size: 20px;
        border-radius: 6px;
    }

    .slot-cell {
        width: 28px;
        height: 28px;
        font-size: 14px;
        border-radius: 4px;
    }

    .slots-wrapper {
        gap: 4px;
    }

    #word-slots {
        gap: 6px;
        margin-bottom: 15px;
    }

    #current-word {
        height: 28px;
        font-size: 20px;
        margin-bottom: 5px;
    }

    #message {
        margin-bottom: 5px;
        min-height: 20px;
    }

    .controls {
        margin-top: 10px;
        gap: 15px;
    }

    button {
        padding: 10px 20px;
        font-size: 14px;
    }
}

@media (max-height: 700px) {
    #game-container {
        max-width: 300px;
    }

    .cell {
        font-size: 18px;
    }

    .slot-cell {
        width: 24px;
        height: 24px;
        font-size: 12px;
    }

    h1 {
        font-size: 20px;
        margin-bottom: 5px;
    }
}

.easter-egg-color {
    background-color: white !important;
    color: black !important;
    border: 1px solid rgba(0, 0, 0, 0.2) !important;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1) !important;
    text-shadow: none !important;
}