/* Modern Minimalist Variables */
:root {
    --primary-color: #D71921;
    /* NOTHING Red */
    --bg-color: #FFFFFF;
    --text-color: #000000;
    --border-color: #000000;
    --grid-bg: #F0F0F0;
    --cell-active: #E5E5E5;
    --cell-selected: #000000;
    --cell-word-selected: #F0F0F0;
    --font-stack: "Inter", -apple-system, BlinkMacSystemFont, sans-serif;
    --border-width: 1.5px;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: var(--font-stack);
    -webkit-font-smoothing: antialiased;
}

body {
    background-color: var(--bg-color);
    color: var(--text-color);
    line-height: 1.5;
    height: 100vh;
    height: 100dvh;
    /* Mobile viewport fix */
    display: flex;
    flex-direction: column;
    /* Allow scrolling by default for safer mobile behavior, fix specific pages if needed */
    overflow-y: auto;
}

#bg-canvas {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -1;
    pointer-events: none;
}

/* Landing Page (Index) Styles */
/* Landing Page (Index) Styles */
.topic-selection-container {
    padding: 2rem;
    padding-top: 4rem;
    max-width: 700px;
    margin: 0 auto;
    /* height: 100vh;  Removed constraints to allow scrolling */
    min-height: 100vh;
    /* Ensure full height but allow growth */
    overflow-y: visible;
    /* Allow content to overflow/scroll */
}

.topic-selection-content {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    text-align: center;
}

h1 {
    font-size: 3.5rem;
    font-weight: 700;
    letter-spacing: -0.05em;
    line-height: 0.85;
    margin-bottom: 0rem;
    color: #333;
    min-height: auto;
}

.subtitle {
    font-size: 1.0rem;
    line-height: 1.4;
    color: #515151;
    margin-top: 0rem;
    margin-bottom: 0rem;
    font-family: 'Inter', sans-serif;
    font-weight: 300;
    /* Respect newlines in HTML */
}

/* Typing Cursor */
.cursor-blink {
    font-weight: 700;
    color: #D71921;
    animation: blink 1s step-end infinite;
}

@keyframes blink {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0;
    }
}

/* Custom Textarea styling to match the "Input Card" */
textarea {
    display: block;
    width: 100%;
    padding: 1rem;
    border: 1px solid #DDD;
    border-radius: 4px;
    /* Slight rounding like the image input box seems to have */
    font-size: 0.9rem;
    line-height: 1.4;
    margin-bottom: 0rem;
    resize: none;
    outline: none;
    min-height: 150px;
    color: #999;
    font-family: var(--font-stack);
}

textarea::placeholder {
    color: #999;
}

textarea:focus {
    border-color: #000;
    box-shadow: 0 0 0 1px #000;
}

/* Main CTA Button */
button#custom-topic-btn {
    width: 100%;
    display: block;
    background: #000;
    /* Matches the red in the image */
    color: #fff;
    border: 1px solid #DDD;
    padding: 1.2rem;
    font-size: 1rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: -0.02em;
    cursor: pointer;
    transition: background 0.2s;
    border-radius: 3px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}

button#custom-topic-btn:hover {
    background: #AAA;
}

button#custom-topic-btn:active {
    transform: scale(0.99);
}

button:disabled {
    opacity: 0.7;
    cursor: not-allowed;
    background: #ccc !important;
    color: #666 !important;
}

/* Warning/Footnote */
.popup-warning {
    font-size: 0.75rem;
    color: #444;
    margin-top: 1.5rem;
}

.bmc-link {
    display: inline-block;
    margin-top: 1rem;
    color: #000;
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 600;
    opacity: 0.7;
    transition: opacity 0.2s;
}

.bmc-link:hover {
    opacity: 1;
    text-decoration: underline;
}


/* --- PLAY PAGE STYLES --- */

.container {
    height: 100%;
    display: flex;
    flex-direction: column;
    max-width: 1200px;
    margin: 0 auto;
    width: 100%;
}

/* Header */
.game-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1rem;
    border-bottom: none;
}

.level-title {
    font-size: 2.5rem;
    font-weight: 700;
    letter-spacing: -0.05em;
    line-height: 0.9;
    margin: 0;
    color: #000;
}

.change-goal-btn {
    background: #fff;
    border: 1px solid #DDD;
    color: #707070;
    padding: 0.8rem 1.5rem;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    cursor: pointer;
    border-radius: 4px;
}

.change-goal-btn:hover {
    color: #CCC;
    border: 1px solid #EEE;
}

/* Game Content (Grid Area) */
.game-content-wrapper {
    flex: 1;
    display: flex;
    position: relative;
    overflow: hidden;
    background: #000;
    /* Black background per image */
}

.crossword-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    /* content centered if smaller than screen, scrollable if larger */
    /* align-items: center; REMOVED to prevent clipping on left side when overflowing */
    justify-content: flex-start;
    padding: 2rem;
    position: relative;
    background: #000;
    overflow: auto;
    /* Ensure grid can scroll in both directions */
    -webkit-overflow-scrolling: touch;
    /* iOS smooth scrolling */
}

#crossword-grid {
    display: grid;
    gap: 1px;
    background: #000;
    padding: 2px;
    margin: 0 auto;
    /* Center horizontally safely */
}

.cell {
    width: 36px;
    height: 36px;
    background: #fff;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
}

.cell.blocked {
    background: #000;
}

.cell input {
    width: 100%;
    height: 100%;
    background: transparent;
    border: none;
    text-align: center;
    font-size: 1.2rem;
    font-weight: 700;
    text-transform: uppercase;
    color: #000;
    padding: 0;
    outline: none;
}

.cell.correct {
    background: #e6ffe6;
}

.cell.incorrect {
    background: #FFD2D2;
    /* Soft red to indicate error */
}


.cell.selected {
    background: #fff1d2;
    /* Highlight color */
}

.cell-number {
    position: absolute;
    top: 2px;
    left: 3px;
    font-size: 0.55rem;
    color: #333;
    font-weight: 800;
    pointer-events: none;
}

/* Show Clues Tab (Vertical on right) */
.show-clues-tab {
    position: absolute;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    background: #D71921;
    color: white;
    border: none;
    padding: 1.5rem 0.6rem;
    font-weight: 800;
    font-size: 1rem;
    letter-spacing: 0.0em;
    cursor: pointer;
    writing-mode: vertical-rl;
    text-orientation: mixed;
    border-radius: 4px 0 0 4px;
    z-index: 10;
}

.show-clues-tab:hover {
    background: #B3161E;
}

/* Clues Drawer */
.clues-drawer {
    position: absolute;
    top: 0;
    right: 0;
    width: 300px;
    height: 100%;
    background: #fff;
    transform: translateX(100%);
    transition: transform 0.3s ease;
    z-index: 20;
    border-left: 2px solid #000;
    display: flex;
    flex-direction: column;
}

.clues-drawer.open {
    transform: translateX(0);
}

.drawer-header {
    padding: 1rem;
    border-bottom: 1px solid #AAA;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #FFF;
}

.close-btn {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: #000;
    padding: 0;
}

.close-btn:hover {
    color: #CCC;
}

.clues-column {
    margin-bottom: 2rem;
}

.clues-column h3 {
    font-size: 1.2rem;
    font-weight: 700;
    margin-bottom: 1rem;
    border-bottom: 1px solid #eee;
    padding-bottom: 0.5rem;
    color: #000;
}

.clue {
    padding: 0.5rem;
    cursor: pointer;
    border-radius: 4px;
    margin-bottom: 0.25rem;
    font-size: 0.9rem;
    line-height: 1.4;
    color: #333;
    font-weight: 200;
}

.clue:hover {
    background-color: #f5f5f5;
}

.clue.selected {
    background-color: #ffd2d2;
    /* Softer yellow than the grid cell */
    font-weight: 600;
    border-left: 3px solid #D71921;
    padding-left: 4px;
}

.clue-number {
    font-weight: 700;
    margin-right: 0.4rem;
}

.clues-content {
    flex: 1;
    padding: 1rem;
    overflow-y: auto;
}

.drawer-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 15;
}


/* Footer Area */
/* Floating Notification */
/* Floating Notification (Inside Grid Box) */
.hint-message {
    display: none;
    position: absolute;
    top: 10px;
    left: 10px;
    z-index: 100;
    padding: 0.5rem 1rem;
    text-align: left;
    font-weight: 700;
    color: #000;
    background: #f8d4d3;
    font-size: 0.8rem;
    border: 1px solid #e99e9b;
    /* #D71921 with 50% opacity */
    border-radius: 4px;
    min-width: unset;
    max-width: 90%;
    animation: fadeIn 0.3s ease-out;
    pointer-events: none;
    /* Let clicks pass through */
}

@keyframes slideInLeft {
    from {
        transform: translateX(-100%);
        opacity: 0;
    }

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

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

@keyframes fadeOut {
    from {
        opacity: 1;
    }

    to {
        opacity: 0;
    }
}

.action-footer {
    padding: 1.5rem 2rem;
    border-top: 1px solid #eee;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.btn-primary {
    width: 100%;
    background: #000;
    color: white;
    border: 0px solid #000;
    padding: 1rem;
    font-size: 1rem;
    font-weight: 800;
    text-transform: uppercase;
    border-radius: 3px;
    cursor: pointer;
}

.btn-primary:hover {
    background: #AAA;
}

.secondary-actions {
    display: flex;
    gap: 1rem;
}

.btn-secondary {
    flex: 1;
    background: #fff;
    color: #7b7b7b;
    border: 1px solid #DDD;
    padding: 1rem;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    border-radius: 4px;
    cursor: pointer;
}

.btn-secondary:hover {
    color: #CCC;
    border: 1px solid #EEE;
}

/* Modals */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 3000;
}

.modal-content {
    background: white;
    padding: 2.5rem;
    text-align: center;
    border: 2px solid #000;
    max-width: 90%;
}

/* Utilities */
.hidden {
    display: none !important;
}

.asterisk {
    color: #D71921;
}

.re-solution {
    font-weight: 700;
}

.timer {
    font-weight: 700;
}