:root {
    --primary-color: #dc2626;
    --hover-color: #b91c1c;
    /* Action Red */
    --selection-blue: #3b82f6;
    --success-green: #16a34a;

    /* Theme Colors (Light) */
    --bg-color: #fdf8f3;
    --border-color: #000000;
    --letter-bg: #ffffff;
    --text-color: #111111;
    --clue-bg: #f8fafc;
    --clue-text: #1e293b;
    --active-cell: #cedefd;
    /* Solid color to prevent black bleed-through */
    --active-word: #e1e9fe;
    --checked-correct-bg: transparent;
    --checked-wrong-bg: transparent;
    --modal-overlay: rgba(0, 0, 0, 0.4);
    --modal-bg: #ffffff;
    --panel-bg: rgba(255, 255, 255, 0.95);
    --panel-border: rgba(0, 0, 0, 0.1);
    --shadow-color: rgba(0, 0, 0, 0.1);

    /* Responsive Cell Size */
    --cell-size: clamp(18px, 4.8vw, 50px);
    --grid-gap: 1px;
    /* Keep cell-size as it's used later */
    --btn-tool: #0f172a;
    /* Keep button styles as they are used later */
    --btn-tool-hover: #334155;
    --btn-primary: var(--primary-color);
    --btn-primary-hover: var(--hover-color);
    --btn-reveal: var(--primary-color);
    --btn-reveal-hover: var(--hover-color);
}

[data-theme="dark"] {
    --primary-color: #3b82f6;
    --hover-color: #2563eb;
    --bg-color: #0f172a;
    --border-color: #334155;
    --letter-bg: #1e293b;
    --text-color: #f1f5f9;
    --clue-bg: #1e293b;
    --clue-text: #94a3b8;
    --active-cell: rgba(59, 130, 246, 0.4);
    --active-word: rgba(59, 130, 246, 0.15);
    --shadow-color: rgba(0, 0, 0, 0.3);
    --bg-gradient: linear-gradient(135deg, #1e1e1e 0%, #121212 100%);
    /* Keep original dark gradient */
    --btn-tool: #334155;
    /* Keep button styles as they are used later */
    --btn-tool-hover: #475569;
    --btn-primary: #3b82f6;
    --btn-primary-hover: var(--hover-color);
    --btn-reveal: #3b82f6;
    --btn-reveal-hover: var(--hover-color);
    --panel-bg: rgba(30, 41, 59, 0.95);
    --panel-border: rgba(255, 255, 255, 0.15);
}

body {
    font-family: 'Outfit', sans-serif;
    background: var(--bg-color);
    background-attachment: fixed;
    color: var(--text-color);
    margin: 0;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    overflow-x: hidden;
    overflow-y: auto;
}

body.no-scroll {
    overflow: hidden !important;
    height: 100vh;
}

/* Skärmar och Layout */
.start-screen {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100vh;
    text-align: center;
}

.start-screen h1 {
    margin-bottom: 5px;
    font-size: clamp(1.8rem, 6vw, 2.5rem);
}

.start-screen p {
    margin-bottom: 30px;
    opacity: 0.8;
}

.branding {
    position: fixed;
    top: 0;
    left: 0;
    height: clamp(60px, 8vh, 80px);
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    background: var(--bg-color);
    z-index: 1600;
    border-bottom: 1px solid var(--panel-border);
    backdrop-filter: blur(10px);
}

.nav-container {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    width: calc(20 * var(--cell-size));
    max-width: 95vw;
    padding: 0;
    box-sizing: border-box;
}

.nav-left {
    display: flex;
    justify-content: flex-start;
}

.nav-center {
    display: flex;
    justify-content: center;
}

.nav-right {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 12px;
}

.nav-link {
    color: var(--text-color);
    text-decoration: none;
    font-weight: 600;
    font-size: 14px;
    opacity: 0.8;
    position: relative;
}

.nav-link::after {
    content: '';
    position: absolute;
    width: 100%;
    height: 1px;
    bottom: -2px;
    left: 0;
    background-color: var(--text-color);
    opacity: 0.3;
}

.nav-link:hover {
    opacity: 1;
}

.logo {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
}

.logo-icon {
    width: clamp(24px, 4vw, 32px);
    height: clamp(24px, 4vw, 32px);
    color: var(--primary-color);
}

.logo-text {
    font-size: clamp(20px, 3vw, 28px);
    font-weight: 800;
    letter-spacing: -0.02em;
    color: var(--text-color);
}

.copyright-footer {
    position: fixed;
    bottom: 20px;
    right: 20px;
    font-size: 12px;
    color: #94a3b8;
    opacity: 0.7;
    z-index: 10;
    pointer-events: none;
}

[data-theme="dark"] .copyright-footer {
    color: #64748b;
}

.hidden {
    display: none !important;
}

.main-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    /* Center between header and island */
    padding-top: 100px;
    padding-bottom: 250px;
    /* Provides space for scrolls but centers when small */
    width: 100%;
    box-sizing: border-box;
    min-height: 100vh;
}

/* Spinner Animation */
@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.spinner {
    width: 50px;
    height: 50px;
    border: 4px solid rgba(220, 38, 38, 0.1);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 0 auto 20px;
}

.loader {
    border: 4px solid rgba(128, 128, 128, 0.2);
    border-left-color: var(--btn-primary);
    border-radius: 50%;
    width: 40px;
    height: 40px;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

.modal-buttons {
    display: flex;
    flex-direction: column;
    align-items: center;
    /* Center the single button */
    gap: 12px;
    margin-top: 24px;
}

.crossword-area {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
}

.clue-display-box {
    width: 100%;
    min-height: 54px;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    font-family: 'Outfit', sans-serif;
    font-size: clamp(18px, 5vw, 22px);
    font-weight: 700;
    color: var(--text-color);
    letter-spacing: 0.5px;
    background: var(--panel-bg);
    backdrop-filter: blur(10px);
    padding: 12px 28px;
    box-sizing: border-box;
    border-bottom: 1px solid var(--panel-border);
    z-index: 21;
}

.clue-logo {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    opacity: 0.8;
}

.logo-icon.small {
    width: 20px;
    height: 20px;
    color: var(--primary-color);
}

.logo-text.small {
    font-size: 18px;
    font-weight: 800;
    letter-spacing: -0.01em;
    color: var(--text-color);
}

[data-theme="dark"] .clue-display-box {
    background: rgba(15, 23, 42, 0.8);
}

.clue-display-box.hidden {
    display: none;
}

/* Grid & Celler */

/* Grid & Celler */
.grid {
    display: grid;
    gap: 1px;
    background-color: #000000;
    /* Back to black as requested */
    border: 1px solid #000000;
    width: fit-content;
    margin: 0 auto;
    position: relative;
    border-radius: 2px;
    /* Force pixel-perfect snapping */
    transform: translate3d(0, 0, 0);
    backface-visibility: hidden;
}

[data-theme="dark"] .grid {
    background-color: var(--border-color);
    border-color: var(--border-color);
}

.cell {
    width: var(--cell-size);
    height: var(--cell-size);
    background-color: var(--letter-bg);
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    padding: 0;
}

.cell:not(.empty):not(.image-overlay) {
    z-index: 2;
}

/* Tomma celler helt osynliga */
.cell.empty {
    visibility: hidden;
    pointer-events: none;
}

/* Spelbara Celler - Borders hanteras nu av JavaScript! */
.cell.clue-box {
    background-color: var(--clue-bg);
    color: var(--clue-text);
    flex-direction: column;
    cursor: default;
    z-index: 2;
    font-family: 'Outfit', sans-serif;
}

.clue-top,
.clue-bottom {
    width: 100%;
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
}

.clue-top {
    border-bottom: 1px solid var(--border-color);
}

.clue-single {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 4px;
    box-sizing: border-box;
}

.clue-text {
    font-size: calc(var(--cell-size) * 0.18);
    font-weight: 600;
    line-height: 1.1;
    text-align: center;
    word-break: normal;
    overflow-wrap: break-word;
    hyphens: auto;
    white-space: pre-line;
    pointer-events: none;
    padding: 2px;
}

.cell.letter {
    background-color: var(--letter-bg);
    z-index: 2;
}

.cell.letter input {
    width: 100%;
    height: 100%;
    border: none;
    text-align: center;
    font-size: calc(var(--cell-size) * 0.55);
    font-weight: bold;
    font-family: 'Kalam', cursive;
    background: transparent;
    color: var(--text-color);
    text-transform: uppercase;
    outline: none;
    cursor: default;
    padding: 0;
    margin: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    caret-color: transparent;
}

.cell.letter input.correct {
    color: #22c55e;
}

.cell.letter input.wrong {
    color: #ef4444;
}

.cell.active-word {
    background-color: var(--active-word);
}

.cell.active-cell {
    background-color: var(--active-cell);
}

.danger-btn {
    background-color: var(--primary-color) !important;
    color: white !important;
}

.danger-btn:hover {
    background-color: var(--hover-color) !important;
}

/* Markers */
.cell.checked-correct:not(.revealed)::after {
    content: '✔';
    position: absolute;
    top: 2px;
    right: 2px;
    font-size: 11px;
    font-weight: 900;
    color: #16a34a;
    pointer-events: none;
    z-index: 5;
}

.cell.checked-wrong::after {
    content: '✖';
    position: absolute;
    top: 2px;
    right: 2px;
    font-size: 11px;
    font-weight: 900;
    color: #dc2626;
    pointer-events: none;
    z-index: 5;
}

/* Revealed Marker (Lightbulb) takes precedence over checkmark */
.cell.revealed::after {
    content: '💡';
    position: absolute;
    top: 2px;
    right: 2px;
    font-size: 11px;
    opacity: 0.8;
    pointer-events: none;
    z-index: 6;
}

/* Bilder och Osynliga Border-overlays */
.image-box {
    background-size: cover;
    background-position: center;
    z-index: 50;
    /* Base layering for image */
    position: relative;
    outline: 1px solid var(--border-color);
    /* Matches other cells */
}

.cell.image-overlay {
    background: transparent;
    pointer-events: none;
    z-index: 101;
}

.image-arrow {
    position: absolute;
    background: var(--primary-color);
    color: white;
    font-weight: bold;
    font-size: 16px;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 2px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.5);
    z-index: 200;
    /* Always on top of everything */
}

.arrow-across {
    bottom: 4px;
    right: -10px;
    z-index: 11;
}

.arrow-down {
    bottom: -10px;
    right: 4px;
    z-index: 11;
}

.arrow-rotated {
    display: inline-block;
    transform: rotate(90deg);
}

/* Flytande Kontrollpanel (Sleek Island) */
.controls-container {
    position: fixed;
    bottom: 25px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--panel-bg);
    backdrop-filter: blur(10px);
    border: 1px solid var(--panel-border);
    border-radius: 20px;
    padding: 0;
    /* No padding here so header can touch edges */
    box-shadow: 0 10px 40px var(--shadow-color);
    display: flex;
    flex-direction: column;
    align-items: center;
    z-index: 2000;
    overflow: hidden;
    /* Clips the clue header to radius */
    width: fit-content;
    max-width: 95vw;
}

.controls-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    width: 100%;
    padding: 16px 28px;
    box-sizing: border-box;
    flex-wrap: wrap;
    /* Allow grouping to wrap on small mobile */
}

.controls-row:first-of-type {
    padding-top: 16px;
}

.controls-row.bottom-bar {
    padding-bottom: 16px;
    padding-top: 0;
}

.btn-group {
    background: rgba(255, 255, 255, 0.4);
    border: 1px solid var(--panel-border);
    border-radius: 16px;
    padding: 10px 16px;
    display: flex;
    align-items: center;
    gap: 10px;
    position: relative;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.02);
}

[data-theme="dark"] .btn-group {
    background: rgba(30, 41, 59, 0.4);
}

.group-label {
    font-size: 11px;
    font-weight: 800;
    color: var(--clue-text);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-right: 4px;
    opacity: 0.6;
}

.bottom-bar {
    justify-content: space-between;
    padding: 8px 16px;
    margin-top: 12px;
    width: 100%;
    box-sizing: border-box;
}

.main-action-btn {
    border-radius: 12px;
    font-weight: 700 !important;
    padding: 10px 20px;
    font-size: 14px;
    white-space: nowrap;
}

.divider {
    width: 1px;
    height: 24px;
    background: var(--panel-border);
    margin: 0 5px;
}

button {
    padding: 8px 16px;
    font-size: 13px;
    font-family: inherit;
    cursor: pointer;
    border: none;
    border-radius: 8px;
    font-weight: bold;
    transition: all 0.2s;
}

.tool-btn {
    background: var(--btn-tool);
    color: white;
}

.tool-btn:hover {
    background: var(--btn-tool-hover);
}

.reveal-btn {
    background: var(--btn-reveal);
    color: white;
}

.reveal-btn:hover {
    background: var(--btn-reveal-hover);
}

.primary-btn {
    background: var(--btn-primary);
    color: white;
    padding: 12px 28px;
    font-size: 18px;
    border-radius: 12px;
}

.primary-btn:hover {
    background: var(--btn-primary-hover);
}

.icon-btn {
    background: transparent;
    font-size: 20px;
    padding: 4px 8px;
    border-radius: 50%;
}

.icon-btn:hover {
    background: rgba(128, 128, 128, 0.2);
}

#statusMessage {
    font-weight: bold;
    font-size: 15px;
    opacity: 0.9;
}

/* Modals */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    transition: opacity 0.3s ease;
}

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

.modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--modal-overlay);
    backdrop-filter: blur(4px);
}

.modal-content {
    position: relative;
    background: var(--modal-bg);
    padding: 40px;
    border-radius: 24px;
    box-shadow: 0 20px 50px var(--shadow-color);
    max-width: 450px;
    width: 90%;
    text-align: center;
    z-index: 2001;
    animation: modalSlideUp 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes modalSlideUp {
    from {
        transform: translateY(30px);
        opacity: 0;
    }

    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.close-x {
    position: absolute;
    top: 20px;
    right: 24px;
    font-size: 28px;
    color: var(--clue-text);
    cursor: pointer;
    transition: color 0.2s;
    line-height: 1;
}

.close-x:hover {
    color: var(--primary-color);
}

.modal h2 {
    margin-top: 0;
    font-size: 28px;
    color: var(--primary-color);
}

.modal p {
    font-size: 16px;
    margin-bottom: 30px;
    color: var(--clue-text);
}

.modal-buttons {
    display: flex;
    margin-top: 24px;
}

/* Toast Notifications */
.toast-notification {
    position: fixed;
    bottom: 140px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: rgba(0, 0, 0, 0.85);
    color: white;
    padding: 12px 24px;
    border-radius: 14px;
    font-size: 15px;
    font-weight: 600;
    z-index: 5000;
    pointer-events: none;
    opacity: 0;
    transition: all 0.3s cubic-bezier(0.18, 0.89, 0.32, 1.28);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.toast-notification.visible {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* Responsive Refinement: Docked Sticky Footer (Tiered) */
@media (max-width: 1400px) {
    .controls-container {
        position: fixed;
        bottom: 0;
        left: 0;
        transform: none;
        width: 100%;
        max-width: 100%;
        border-radius: 0;
        border-left: none;
        border-right: none;
        border-bottom: none;
        background: var(--panel-bg);
        backdrop-filter: blur(20px);
        box-shadow: 0 -5px 25px rgba(0, 0, 0, 0.15);
        padding: 0;
        z-index: 3000;
        display: block;
    }

    .controls-content {
        display: flex;
        flex-direction: column;
        /* Keep vertical stacking for laptop/tablet */
        align-items: center;
        padding: 0;
        min-height: auto;
    }

    .clue-header {
        width: 100%;
        height: auto;
        min-height: 48px;
        background: rgba(0, 0, 0, 0.03);
        border-bottom: 1px solid var(--panel-border);
        border-right: none;
        padding: 12px 20px;
        display: flex;
        align-items: center;
        justify-content: center;
        text-align: center;
    }

    [data-theme="dark"] .clue-header {
        background: rgba(255, 255, 255, 0.05);
    }

    .clue-header .clue-text {
        font-size: 15px;
        text-align: center;
        width: 100%;
    }

    .controls-row {
        width: 100%;
        display: flex;
        flex-direction: row;
        justify-content: center;
        padding: 14px 20px;
        gap: 12px;
        box-sizing: border-box;
    }

    .controls-row.bottom-bar {
        padding-top: 0;
        padding-bottom: 14px;
    }

    .btn-group {
        padding: 8px 16px;
        border-radius: 12px;
        gap: 12px;
        flex-direction: row;
        align-items: center;
    }

    .main-wrapper {
        padding-bottom: 180px;
        /* More space for two stacked rows */
    }
}

/* Small Mobile: Compact Horizontal Layout */
@media (max-width: 768px) {
    .controls-content {
        display: grid;
        grid-template-areas:
            "clue clue"
            "row1 row2";
        grid-template-columns: 1fr 1fr;
    }

    .clue-header {
        grid-area: clue;
    }

    .controls-row {
        grid-area: row1;
        flex-direction: column;
        padding: 10px;
        border-right: 1px solid var(--panel-border);
        gap: 6px;
    }

    .controls-row.bottom-bar {
        grid-area: row2;
        padding-top: 10px;
        border-right: none;
    }

    .btn-group {
        flex-direction: column;
        padding: 6px;
        width: 100%;
        gap: 4px;
    }

    .btn-group .btn-row {
        display: flex;
        gap: 4px;
        justify-content: center;
    }

    .btn-group .group-label {
        font-size: 9px;
        margin-bottom: 2px;
    }

    .tool-btn {
        padding: 6px 10px;
        font-size: 12px;
    }

    .main-wrapper {
        padding-bottom: 150px;
    }
}