/*
 * style.css — structural CSS only.
 *
 * All color, font, and surface tokens are CSS variables defined by the
 * active theme in assets/theme/theme.css (always loaded after this file).
 * Theme defaults live in resources/themes/default/theme.css. Other themes
 * override only the variables they care about.
 */

* {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    padding: 0;
    height: 100%;
}

body {
    font-family: var(--font-base);
    background: var(--color-bg);
    color: var(--color-text);
    -webkit-font-smoothing: antialiased;
    line-height: 1.4;
}

button,
input,
select,
textarea {
    font-family: inherit;
    font-size: 100%;
    color: inherit;
}

.hidden {
    display: none !important;
}

.app {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* ---- Header ---- */

.app-header {
    background: var(--color-surface);
    padding: var(--space-4) var(--space-6);
    display: flex;
    align-items: center;
    gap: var(--space-4);
    border-bottom: 1px solid var(--color-border);
    box-shadow: 0 1px 3px var(--color-shadow);
    flex-wrap: wrap;
}

.app-header > .app-title {
    flex: 1;
    min-width: 0;
}

.app-header > .app-controls {
    flex: 0 0 auto;
    justify-content: flex-end;
}

.app-title {
    margin: 0;
    font-family: var(--font-display);
    font-size: 2rem;
    font-weight: 700;
    color: var(--color-text);
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.app-controls {
    display: flex;
    align-items: center;
    gap: var(--space-3);
}

.mode-toggle {
    display: inline-flex;
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 3px;
}

.mode-btn {
    background: transparent;
    border: none;
    padding: var(--space-2) var(--space-4);
    border-radius: calc(var(--radius) - 2px);
    cursor: pointer;
    font-weight: 500;
    color: var(--color-text-muted);
    font-size: 0.95rem;
    white-space: nowrap;
}

.mode-btn.active {
    background: var(--color-primary);
    color: white;
}

.reset-btn {
    background: transparent;
    color: var(--color-text-muted);
    border: 1px solid var(--color-border);
    padding: var(--space-2) var(--space-4);
    border-radius: var(--radius);
    cursor: pointer;
    font-weight: 500;
    font-size: 0.95rem;
}

.reset-btn:hover {
    background: var(--color-bg);
    color: var(--color-text);
}

.theme-picker {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    font-family: var(--font-base);
}

.theme-picker-label {
    color: var(--color-text-muted);
    font-size: 0.95rem;
    font-weight: 500;
}

.theme-trigger {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    background: transparent;
    border: 1px solid var(--color-border);
    color: var(--color-text-muted);
    font-family: inherit;
    font-size: 0.95rem;
    font-weight: 500;
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius);
    cursor: pointer;
    transition: color 0.15s ease, border-color 0.15s ease;
}

.theme-trigger:hover {
    color: var(--color-text);
    border-color: var(--color-text-muted);
}

.theme-trigger[aria-expanded="true"] {
    color: var(--color-text);
    border-color: var(--color-primary);
}

.theme-trigger-chevron {
    font-size: 0.7em;
    color: var(--color-text-muted);
    transition: transform 0.15s ease;
    display: inline-block;
}

.theme-trigger[aria-expanded="true"] .theme-trigger-chevron {
    transform: rotate(180deg);
}

.theme-menu {
    position: absolute;
    top: calc(100% + 4px);
    right: 0;
    min-width: 100%;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    box-shadow: 0 8px 24px var(--color-shadow);
    list-style: none;
    margin: 0;
    padding: var(--space-1);
    z-index: 50;
    max-height: 60vh;
    overflow-y: auto;
    font-family: var(--font-base);
}

.theme-menu[hidden] {
    display: none;
}

.theme-option {
    display: block;
    width: 100%;
    background: transparent;
    border: none;
    color: var(--color-text);
    font-family: inherit;
    font-size: 0.95rem;
    font-weight: 500;
    padding: var(--space-2) var(--space-5);
    text-align: left;
    border-radius: calc(var(--radius) - 2px);
    cursor: pointer;
    white-space: nowrap;
    transition: background-color 0.1s ease;
}

.theme-option:hover {
    background: var(--color-bg);
}

.theme-option.active {
    background: var(--color-primary);
    color: white;
}

.icon-btn,
.particles-toggle {
    width: 2.25rem;
    height: 2.25rem;
    background: transparent;
    color: var(--color-text-muted);
    border: 1px solid var(--color-border);
    border-radius: 50%;
    cursor: pointer;
    font-weight: 700;
    font-size: 1rem;
    line-height: 1;
    padding: 0;
    transition: color 0.15s ease, background-color 0.15s ease, border-color 0.15s ease;
}

.icon-btn:hover,
.particles-toggle:hover {
    background: var(--color-bg);
    color: var(--color-text);
}

.particles-toggle[aria-pressed="true"] {
    background: var(--color-primary);
    color: white;
    border-color: var(--color-primary);
}

.particles-toggle[aria-pressed="true"]:hover {
    background: var(--color-primary-hover);
    border-color: var(--color-primary-hover);
    color: white;
}

/* ---- Main layout ---- */

.app-main {
    flex: 1;
    display: grid;
    grid-template-columns: minmax(0, 1fr) 360px;
    gap: var(--space-6);
    padding: var(--space-6);
    min-height: 0;
}

/* ---- State cards ---- */

.state-card {
    background: var(--color-surface);
    border-radius: var(--radius-lg);
    padding: var(--space-8);
    box-shadow: 0 2px 12px var(--color-shadow);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    min-height: 70vh;
}

.complete-card h2 {
    margin: 0 0 var(--space-3) 0;
    font-family: var(--font-display);
    font-size: 2.25rem;
    font-weight: 700;
}

.complete-card p {
    margin: 0 0 var(--space-8) 0;
    color: var(--color-text-muted);
    font-size: 1.125rem;
}

/* ---- Welcome state: BINGO branding + main menu ---- */

.welcome-card {
    gap: var(--space-6);
    padding-top: var(--space-10);
    padding-bottom: var(--space-10);
}

.bingo-headline {
    display: flex;
    align-items: baseline;
    justify-content: center;
    font-family: var(--font-display);
    font-size: 8rem;
    font-weight: 900;
    line-height: 1;
    letter-spacing: 0.04em;
    margin: 0;
    text-shadow: 0 4px 0 rgba(0, 0, 0, 0.08);
}

.bingo-letter,
.bingo-letter-bang {
    display: inline-block;
}

.bingo-letter-b { color: #2563eb; }
.bingo-letter-i { color: #dc2626; }
.bingo-letter-n { color: #16a34a; }
.bingo-letter-g { color: #9333ea; }
.bingo-letter-o { color: #ea580c; }

.bingo-letter-bang {
    color: var(--color-text);
    margin-left: 0.05em;
}

.welcome-topic {
    font-family: var(--font-display);
    font-size: 2.5rem;
    font-weight: 700;
    color: var(--color-text);
    margin: 0;
    line-height: 1.2;
    max-width: 90%;
}

.welcome-actions {
    display: flex;
    gap: var(--space-4);
    justify-content: center;
    flex-wrap: wrap;
    margin-top: var(--space-4);
}

.cta-btn {
    background: var(--color-primary);
    color: white;
    border: none;
    padding: var(--space-5) var(--space-10);
    border-radius: var(--radius-lg);
    cursor: pointer;
    font-family: inherit;
    box-shadow: 0 4px 12px var(--color-shadow);
    min-width: 260px;
    transition: background-color 0.15s ease, transform 0.08s ease, box-shadow 0.15s ease, color 0.15s ease, border-color 0.15s ease;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-1);
}

.cta-btn:hover {
    background: var(--color-primary-hover);
    box-shadow: 0 6px 16px var(--color-shadow-strong);
}

.cta-btn:active {
    transform: translateY(1px);
}

.cta-btn-secondary {
    background: transparent;
    color: var(--color-primary);
    border: 2px solid var(--color-primary);
    box-shadow: none;
    padding: calc(var(--space-5) - 2px) calc(var(--space-10) - 2px);
}

.cta-btn-secondary:hover {
    background: var(--color-bg);
    color: var(--color-primary-hover);
    border-color: var(--color-primary-hover);
}

.cta-label {
    font-size: 1.375rem;
    font-weight: 700;
    line-height: 1;
}

.cta-sub {
    font-size: 0.85rem;
    font-weight: 500;
    opacity: 0.9;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.text-link-btn {
    background: transparent;
    border: none;
    color: var(--color-primary);
    font-family: inherit;
    font-size: 1.375rem;
    font-weight: 600;
    cursor: pointer;
    padding: var(--space-2) var(--space-4);
    margin-top: var(--space-10);
    text-decoration: underline;
    text-underline-offset: 0.3em;
}

.text-link-btn:hover {
    color: var(--color-primary-hover);
}

/* ---- Question state ---- */

.question-card {
    gap: 0;
    justify-content: space-between;
}

.question-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex-grow: 1;
    width: 100%;
    gap: 0;
}

.question-number-large {
    font-family: var(--font-display);
    font-size: 2rem;
    font-weight: 700;
    color: var(--color-primary);
    line-height: 1;
    margin-bottom: 0;
}

.question-prefix {
    color: var(--color-text-muted);
    font-size: 2.5rem;
    text-transform: uppercase;
    letter-spacing: 0.02em;
    font-weight: 600;
    line-height: 1.15;
    margin-bottom: var(--space-8);
}

.question-body {
    font-size: 5rem;
    margin: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1.1;
}

.answer-slot {
    width: 100%;
    min-height: 7rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-end;
    margin-bottom: var(--space-4);
}

.answer-slot .big-action-btn {
    margin-top: 0;
}

.question-body .katex,
.answer-body .katex {
    font-size: 1em;
}

.question-body .katex-display,
.answer-body .katex-display {
    margin: 0;
}

/* Prose + math questions (word problems): renderLatex() tags the question/answer
   .mixed-content when the field is prose with embedded math rather than a single
   expression. Size it for reading and let it flow as a paragraph, instead of the
   giant single-expression display size (which would overflow). The single-
   expression games are unaffected. */
.question-body.mixed-content {
    display: block;
    width: 100%;
    font-size: clamp(1.15rem, 2.1vw, 1.9rem);
    line-height: 1.6;
    text-align: left;
    overflow-wrap: anywhere;
}
.answer-body.mixed-content {
    display: block;
    width: 100%;
    font-size: clamp(1.05rem, 1.7vw, 1.5rem);
    line-height: 1.6;
    text-align: left;
    overflow-wrap: anywhere;
}
.question-body.mixed-content .katex,
.answer-body.mixed-content .katex { font-size: 1.05em; vertical-align: baseline; }
.question-body.mixed-content .katex-display,
.answer-body.mixed-content .katex-display { margin: 0.4em 0; }

.answer-body {
    font-size: 4rem;
    padding: var(--space-4) var(--space-10);
    background: var(--color-accent-soft);
    border-radius: var(--radius-lg);
    color: var(--color-accent);
    font-weight: 600;
    margin: 0;
}

.big-action-btn {
    background: var(--color-primary);
    color: white;
    border: none;
    padding: var(--space-3) var(--space-10);
    border-radius: var(--radius);
    font-size: 1.125rem;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.15s ease, transform 0.05s ease;
    box-shadow: 0 2px 6px var(--color-shadow);
    margin-top: var(--space-4);
}

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

.big-action-btn:active {
    transform: translateY(1px);
}

.question-nav {
    display: flex;
    gap: var(--space-3);
    margin-top: 0;
    flex-wrap: wrap;
    justify-content: center;
}

.grid-pane-logo-link {
    display: block;
    margin: auto auto 0 auto;
    line-height: 0;
    transition: opacity 0.15s ease, transform 0.08s ease;
}

.grid-pane-logo-link:hover {
    opacity: 1;
    transform: translateY(-1px);
}

.grid-pane-logo {
    display: block;
    height: 2.5rem;
    width: auto;
    opacity: 0.9;
}

.grid-pane-logo-link:hover .grid-pane-logo {
    opacity: 1;
}

.nav-btn {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    padding: var(--space-3) var(--space-6);
    border-radius: var(--radius);
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    color: var(--color-text);
    transition: background-color 0.15s ease, border-color 0.15s ease;
    min-width: 8rem;
}

.nav-btn:hover:not(:disabled) {
    background: var(--color-bg);
    border-color: var(--color-text-muted);
}

.nav-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.nav-btn-primary {
    background: var(--color-primary);
    color: white;
    border-color: var(--color-primary);
}

.nav-btn-primary:hover:not(:disabled) {
    background: var(--color-primary-hover);
    border-color: var(--color-primary-hover);
    color: white;
}

/* ---- Grid pane ---- */

.grid-pane {
    background: var(--color-surface);
    border-radius: var(--radius-lg);
    padding: var(--space-5);
    box-shadow: 0 2px 12px var(--color-shadow);
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
}

.grid-title {
    margin: 0;
    font-size: 1rem;
    color: var(--color-text-muted);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    display: flex;
    justify-content: space-between;
    align-items: baseline;
}

.grid-count {
    font-size: 0.875rem;
    color: var(--color-text);
    font-weight: 700;
    text-transform: none;
    letter-spacing: 0;
}

.number-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: var(--space-2);
}

.grid-cell {
    aspect-ratio: 1;
    background: var(--color-bg);
    border: 2px solid var(--color-border);
    border-radius: var(--radius);
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--color-text);
    cursor: pointer;
    transition: border-color 0.1s ease, background-color 0.1s ease, transform 0.05s ease;
    padding: 0;
}

.grid-cell:hover {
    border-color: var(--color-primary);
}

.grid-cell:active {
    transform: scale(0.96);
}

.grid-cell.called {
    background: var(--color-called);
    color: var(--color-called-text);
    border-color: var(--color-called);
}

.grid-cell.current {
    background: var(--color-current);
    color: white;
    border-color: var(--color-primary-hover);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.25);
}

.grid-legend {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-3) var(--space-4);
    font-size: 0.8125rem;
    color: var(--color-text-muted);
    padding-top: var(--space-2);
    border-top: 1px solid var(--color-border);
}

.grid-legend > span {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
}

.legend-swatch {
    display: inline-block;
    width: 14px;
    height: 14px;
    border-radius: 4px;
    border: 2px solid var(--color-border);
}

.legend-swatch.legend-uncalled {
    background: var(--color-bg);
}

.legend-swatch.legend-called {
    background: var(--color-called);
    border-color: var(--color-called);
}

.legend-swatch.legend-current {
    background: var(--color-current);
    border-color: var(--color-primary-hover);
}

/* ---- Tablet ---- */

@media (max-width: 1023px) {
    .app-main {
        grid-template-columns: 1fr;
    }

    .grid-pane {
        order: 2;
    }

    .number-grid {
        grid-template-columns: repeat(10, 1fr);
    }

    .bingo-headline {
        font-size: 6rem;
    }

    .welcome-topic {
        font-size: 1.75rem;
    }

    .cta-btn {
        min-width: 220px;
    }

    .app-title {
        font-size: 1.5rem;
    }

    .question-number-large {
        font-size: 1.5rem;
        margin-bottom: var(--space-6);
    }

    .question-prefix {
        font-size: 1.75rem;
    }

    .question-body {
        font-size: 3.5rem;
    }

    .answer-body {
        font-size: 2.75rem;
    }

    .answer-slot {
        min-height: 5rem;
    }

    .state-card {
        min-height: 50vh;
    }
}

/* ---- Phone / narrow portrait ---- */

@media (max-width: 640px) {
    .app-header {
        flex-direction: column;
        align-items: stretch;
    }

    .app-controls {
        justify-content: space-between;
    }

    .app-main {
        padding: var(--space-4);
        gap: var(--space-4);
    }

    .state-card {
        padding: var(--space-6) var(--space-4);
    }

    .bingo-headline {
        font-size: 4rem;
    }

    .welcome-topic {
        font-size: 1.25rem;
    }

    .cta-btn {
        min-width: 100%;
        padding: var(--space-4) var(--space-6);
    }

    .cta-label {
        font-size: 1.125rem;
    }

    .app-title {
        font-size: 1.25rem;
    }

    .question-number-large {
        font-size: 1.125rem;
        margin-bottom: var(--space-4);
    }

    .question-prefix {
        font-size: 1.25rem;
    }

    .question-body {
        font-size: 2.25rem;
    }

    .answer-body {
        font-size: 1.75rem;
        padding: var(--space-3) var(--space-4);
    }

    .answer-slot {
        min-height: 3.5rem;
    }

    .question-nav {
        flex-direction: column;
    }

    .nav-btn {
        width: 100%;
    }

    .number-grid {
        grid-template-columns: repeat(5, 1fr);
    }
}

/* ---- Footer ---- */

.app-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-6);
    background: var(--color-surface);
    border-top: 1px solid var(--color-border);
    font-size: 0.8125rem;
    color: var(--color-text-muted);
    flex-wrap: wrap;
}

.footer-link {
    color: var(--color-primary);
    text-decoration: none;
    font-weight: 600;
}

.footer-link:hover {
    text-decoration: underline;
}

/* ---- Falling particles (themed: snow, bats, bees, hearts, etc.) ---- */

.particle-container {
    position: fixed;
    inset: 0;
    pointer-events: none;
    overflow: hidden;
    z-index: 9;
}

.particle {
    position: absolute;
    top: 0;
    user-select: none;
    will-change: transform;
    line-height: 1;
    animation-name: particle-fall;
    animation-timing-function: linear;
    animation-iteration-count: infinite;
}

.particle-snow {
    color: #ffffff;
    text-shadow:
        0 0 6px rgba(255, 255, 255, 0.95),
        0 0 2px rgba(125, 145, 200, 0.55);
}

.particle-bat {
    color: #0f0a14;
}

.particle svg {
    display: block;
    width: 100%;
    height: 100%;
    fill: currentColor;
}

@keyframes particle-fall {
    0% {
        transform: translate3d(0, -10vh, 0) rotate(0deg);
    }
    100% {
        transform: translate3d(0, 110vh, 0) rotate(360deg);
    }
}

@media (prefers-reduced-motion: reduce) {
    .particle-container {
        display: none;
    }
}

/* ---- Modal ---- */

.modal {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-6);
}

.modal.hidden {
    display: none;
}

body.modal-open {
    overflow: hidden;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, 0.55);
    -webkit-backdrop-filter: blur(2px);
    backdrop-filter: blur(2px);
    cursor: pointer;
}

.modal-card {
    position: relative;
    z-index: 1;
    background: var(--color-surface);
    border-radius: var(--radius-lg);
    box-shadow: 0 25px 50px var(--color-shadow-strong);
    max-width: 640px;
    width: 100%;
    max-height: calc(100vh - 4rem);
    overflow-y: auto;
    animation: modal-pop 0.15s ease-out;
}

@keyframes modal-pop {
    from { opacity: 0; transform: scale(0.96); }
    to   { opacity: 1; transform: scale(1); }
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-4);
    padding: var(--space-5) var(--space-6);
    border-bottom: 1px solid var(--color-border);
}

.modal-title {
    margin: 0;
    font-family: var(--font-display);
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--color-text);
}

.modal-close {
    background: transparent;
    border: none;
    font-size: 1.75rem;
    line-height: 1;
    color: var(--color-text-muted);
    cursor: pointer;
    padding: var(--space-1) var(--space-2);
    border-radius: var(--radius);
}

.modal-close:hover {
    background: var(--color-bg);
    color: var(--color-text);
}

.modal-body {
    padding: var(--space-6);
}

.instructions-list {
    margin: 0;
    padding-left: var(--space-6);
    color: var(--color-text);
}

.instructions-list li {
    margin-bottom: var(--space-3);
    line-height: 1.5;
}

.patterns-heading {
    margin: var(--space-8) 0 var(--space-4) 0;
    font-family: var(--font-display);
    font-size: 1.125rem;
    font-weight: 700;
    color: var(--color-text);
}

.patterns-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: var(--space-4) var(--space-3);
}

.pattern {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-2);
}

.pattern-diagram {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 2px;
    width: 100px;
    height: 100px;
    background: var(--color-border);
    padding: 2px;
    border-radius: 4px;
}

.pattern-diagram > span {
    background: var(--color-surface);
    border-radius: 2px;
}

.pattern-diagram > span.on {
    background: var(--color-primary);
}

.pattern-label {
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--color-text-muted);
    text-align: center;
}

/* ---- Large screens / projector ---- */

@media (min-width: 1600px) {
    .bingo-headline {
        font-size: 10rem;
    }

    .welcome-topic {
        font-size: 3rem;
    }

    .cta-label {
        font-size: 1.625rem;
    }

    .app-title {
        font-size: 2.5rem;
    }

    .question-number-large {
        font-size: 2.25rem;
        margin-bottom: var(--space-10);
    }

    .question-prefix {
        font-size: 3rem;
    }

    .question-body {
        font-size: 6.5rem;
    }

    .answer-body {
        font-size: 5rem;
    }

    .answer-slot {
        min-height: 8.5rem;
    }
}
