:root {
    --cell-size-max: 44px;
    --cell-size-min: 36px;
    --cell-size: var(--cell-size-max);
    --clues-panel-offset: 0px;
    --controls-dock-height: 0px;
    --footer-height: 40px;
    --gap-size: 4px;
    --header-height: 56px;
    --border-radius: 10px;
    --wrap-offset: 48px;
    --pane-gap: 18px;
    --clue-stack-track-size: 1fr;
    --sidebar-collapsed-width: 32px;
    --sidebar-expanded-width: 25vw;
    --sidebar-toggle-width: 24px;
    --viewport-height: 100vh;
    --full-size: 100%;
    --wrap-max-width: calc(100vw - var(--wrap-offset));
    --narrow-screen-width: 800px;
    --phone-screen-width: 500px;

    /* Theme-aware colors (dark default) */
    --cw-bg-gradient-a: #1f2440;
    --cw-bg-gradient-b: #0f1222;
    --cw-bg-gradient-c: #0b0d18;
    --cw-text: #e9edff;
    --cw-text-muted: #aab4dd;
    --cw-wrap-bg: rgba(255, 255, 255, .06);
    --cw-wrap-border: rgba(255, 255, 255, .15);
    --cw-cell-bg: #0b1022;
    --cw-cell-border: #2a2f45;
    --cw-cell-input: #dce5ff;
    --cw-blk-bg: #0f142a;
    --cw-blk-border: #202743;
    --cw-select-bg: #0f142a;
    --cw-clue-bg: rgba(255, 255, 255, .05);
    --cw-clue-border: rgba(255, 255, 255, .12);
    --cw-btn-secondary: #334155;
    --cw-placeholder: #6b7899;
    --cw-tab-bg: rgba(255, 255, 255, .08);
    --cw-tab-border: rgba(255, 255, 255, .12);
    --cw-tab-hover: rgba(255, 255, 255, .12);
    --cw-modal-glow-a: rgba(59, 130, 246, .14);
    --cw-modal-glow-b: rgba(52, 211, 153, .08);
    --cw-modal-surface-from: rgba(15, 23, 42, .96);
    --cw-modal-surface-to: rgba(8, 20, 32, .98);
    --cw-modal-divider: rgba(255, 255, 255, .14);
    --cw-modal-card-border: rgba(148, 163, 184, .2);
    --cw-modal-card-bg: rgba(15, 23, 42, .76);
    --cw-prism-shell-from: rgba(11, 18, 37, .96);
    --cw-prism-shell-to: rgba(6, 10, 24, .98);
    --cw-prism-border: rgba(124, 144, 196, .34);
    --cw-prism-highlight: rgba(255, 255, 255, .08);
    --cw-prism-separator: rgba(148, 163, 184, .26);
    --cw-prism-tab-text: #e6edff;
    --cw-prism-tab-muted: rgba(214, 226, 255, .82);
    --cw-prism-tab-hover: rgba(96, 165, 250, .16);
}

/* Light theme overrides — mpr-ui sets data-mpr-theme on <html> */
[data-mpr-theme="light"],
:root[data-mpr-theme="light"] {
    --cw-bg-gradient-a: #e8ecf4;
    --cw-bg-gradient-b: #f0f2f8;
    --cw-bg-gradient-c: #f5f7fb;
    --cw-text: #1a1d2e;
    --cw-text-muted: #555a70;
    --cw-wrap-bg: rgba(255, 255, 255, .85);
    --cw-wrap-border: rgba(0, 0, 0, .12);
    --cw-cell-bg: #ffffff;
    --cw-cell-border: #c5cad8;
    --cw-cell-input: #1a1d2e;
    --cw-blk-bg: #e2e5ee;
    --cw-blk-border: #d0d4e0;
    --cw-select-bg: #ffffff;
    --cw-clue-bg: rgba(0, 0, 0, .03);
    --cw-clue-border: rgba(0, 0, 0, .1);
    --cw-btn-secondary: #94a3b8;
    --cw-placeholder: #9ca3af;
    --cw-tab-bg: rgba(0, 0, 0, .05);
    --cw-tab-border: rgba(0, 0, 0, .1);
    --cw-tab-hover: rgba(0, 0, 0, .08);
    --cw-modal-glow-a: rgba(59, 130, 246, .1);
    --cw-modal-glow-b: rgba(16, 185, 129, .06);
    --cw-modal-surface-from: rgba(255, 255, 255, .98);
    --cw-modal-surface-to: rgba(232, 239, 248, .98);
    --cw-modal-divider: rgba(15, 23, 42, .12);
    --cw-modal-card-border: rgba(15, 23, 42, .12);
    --cw-modal-card-bg: rgba(255, 255, 255, .88);
    --cw-prism-shell-from: rgba(255, 255, 255, .98);
    --cw-prism-shell-to: rgba(229, 236, 246, .98);
    --cw-prism-border: rgba(88, 104, 145, .22);
    --cw-prism-highlight: rgba(255, 255, 255, .74);
    --cw-prism-separator: rgba(88, 104, 145, .18);
    --cw-prism-tab-text: #16203e;
    --cw-prism-tab-muted: rgba(22, 32, 62, .72);
    --cw-prism-tab-hover: rgba(59, 130, 246, .12);
}

* {
    box-sizing: border-box;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

body {
    margin: 0;
    padding: 0;
    font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
    background-image: radial-gradient(at 20% 10%, var(--cw-bg-gradient-a) 0%, var(--cw-bg-gradient-b) 55%, var(--cw-bg-gradient-c) 100%);
    background-repeat: no-repeat;
    background-attachment: fixed;
    background-size: cover;
    color: var(--cw-text);
    display: grid;
    place-items: start center;
    min-height: var(--viewport-height);
}

/* ========== Two-panel puzzle layout ========== */
.puzzle-layout {
    --sidebar-width: var(--sidebar-expanded-width);
    display: grid;
    grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
    width: 100vw;
    min-height: calc(var(--viewport-height) - var(--header-height) - var(--footer-height));
    height: calc(var(--viewport-height) - var(--header-height) - var(--footer-height));
    overflow: hidden;
    transition: grid-template-columns .22s ease;
}

.puzzle-layout[data-sidebar-collapsed="true"] {
    --sidebar-width: var(--sidebar-collapsed-width);
}

.puzzle-sidebar {
    position: relative;
    overflow: hidden;
    padding: 40px 12px 12px;
    border-right: 1px solid var(--cw-wrap-border);
    background: var(--cw-wrap-bg);
}

.puzzle-sidebar__content {
    height: 100%;
    min-width: 0;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 8px;
    transition: opacity .16s ease, transform .16s ease, visibility .16s ease;
}

.puzzle-sidebar__toggle {
    position: absolute;
    top: 8px;
    right: 8px;
    width: var(--sidebar-toggle-width);
    height: var(--sidebar-toggle-width);
    min-width: var(--sidebar-toggle-width);
    padding: 0;
    border: none;
    border-radius: 999px;
    background: transparent;
    color: var(--cw-text);
    display: grid;
    place-items: center;
    z-index: 1;
}

.puzzle-sidebar__toggle:hover {
    background: rgba(59, 130, 246, .16);
}

.puzzle-sidebar__toggle:focus-visible {
    outline: 2px solid #3b82f6;
    outline-offset: 1px;
}

.puzzle-sidebar__toggle-icon {
    font-size: 20px;
    font-weight: 700;
    line-height: 1;
    pointer-events: none;
}

.puzzle-layout[data-sidebar-collapsed="true"] .puzzle-sidebar {
    padding: 8px 0 0;
}

.puzzle-layout[data-sidebar-collapsed="true"] .puzzle-sidebar__toggle {
    right: auto;
    left: 50%;
    transform: translateX(-50%);
}

.puzzle-layout[data-sidebar-collapsed="true"] .puzzle-sidebar__content {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transform: translateX(-10px);
}

.puzzle-main {
    overflow-y: auto;
    width: 100%;
    padding: var(--pane-gap);
    padding-bottom: calc(var(--pane-gap) + var(--footer-height) + var(--controls-dock-height));
    display: flex;
    flex-direction: column;
    gap: var(--pane-gap);
    min-height: 0; /* prevent grid blowout */
    min-width: 0;
}

.puzzle-main > .pane {
    flex: 0 0 auto;
}

.puzzle-main > .controls {
    flex: 0 0 auto;
}

@media (max-height: 420px) {
    .puzzle-main > .pane {
        flex: 1 1 auto;
        min-height: 0;
    }

    .gridViewport,
    .clues {
        max-height: 100%;
    }
}

/* --- Puzzle cards --- */
.puzzle-card {
    padding: 10px;
    border-radius: 10px;
    border: 1px solid var(--cw-wrap-border);
    background: var(--cw-clue-bg);
    cursor: pointer;
    transition: border-color .15s, background .15s;
    display: flex;
    align-items: flex-start;
    gap: 10px;
    min-height: 72px;
    overflow: hidden;
}

.puzzle-card:hover {
    border-color: rgba(59, 130, 246, .4);
    background: rgba(59, 130, 246, .06);
}

.puzzle-card--active {
    border-color: #3b82f6;
    background: rgba(59, 130, 246, .1);
}

.puzzle-card--new {
    align-items: center;
    gap: 10px;
}

.puzzle-card__icon {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    background: #3b82f6;
    color: #fff;
    font-size: 22px;
    font-weight: 700;
    display: grid;
    place-items: center;
    flex-shrink: 0;
}

.puzzle-card__title {
    font-size: 13px;
    font-weight: 600;
    line-height: 1.3;
    flex: 1 1 auto;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

.puzzle-card__copy {
    min-width: 0;
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.puzzle-card__badge {
    align-self: flex-start;
    padding: 3px 8px;
    border-radius: 999px;
    background: rgba(59, 130, 246, .16);
    border: 1px solid rgba(59, 130, 246, .26);
    color: var(--cw-text-muted);
    font-size: 10px;
    font-weight: 800;
    letter-spacing: .08em;
    text-transform: uppercase;
}

.puzzle-card__description {
    font-size: 12px;
    line-height: 1.35;
    color: var(--cw-text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

.puzzle-card__thumb {
    flex-shrink: 0;
    align-self: center;
    order: 1;
    width: 36px;
    height: 36px;
    display: grid;
    place-items: center;
    overflow: hidden;
}

.puzzle-card-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.puzzle-sidebar__section {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.puzzle-sidebar__section-title {
    margin: 6px 2px 0;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: .08em;
    text-transform: uppercase;
    color: var(--cw-text-muted);
}

/* Mini grid thumbnail — cells sized dynamically by JS to fit thumb container */
.mini-grid {
    display: grid;
    gap: 1px;
    width: 36px;
    height: 36px;
    align-content: center;
    justify-content: center;
}

.mini-grid__cell {
    border-radius: 1px;
}

.mini-grid__cell--letter {
    background: rgba(99, 102, 241, .6);
}

.mini-grid__cell--blank {
    background: rgba(255, 255, 255, .04);
}

[data-mpr-theme="light"] .mini-grid__cell--letter {
    background: rgba(59, 130, 246, .5);
}

[data-mpr-theme="light"] .mini-grid__cell--blank {
    background: rgba(0, 0, 0, .04);
}

@media (max-width: 800px) {
    .puzzle-layout {
        grid-template-columns: minmax(0, 1fr);
        grid-template-rows: auto 1fr;
        height: auto;
    }

    .puzzle-layout[data-sidebar-collapsed="true"] {
        grid-template-columns: minmax(0, 1fr);
    }

    .puzzle-sidebar {
        overflow: visible;
        padding: 12px;
        border-right: none;
        border-bottom: 1px solid var(--cw-wrap-border);
    }

    .puzzle-layout[data-sidebar-collapsed="true"] .puzzle-sidebar {
        padding: 12px;
    }

    .puzzle-sidebar__content {
        overflow-x: auto;
        overflow-y: hidden;
        flex-direction: row;
        max-height: 120px;
        opacity: 1;
        visibility: visible;
        pointer-events: auto;
        transform: none;
    }

    .puzzle-sidebar__toggle {
        display: none;
    }

    .puzzle-sidebar .puzzle-card {
        flex-shrink: 0;
        width: 120px;
    }

    .puzzle-card-list {
        flex-direction: row;
    }
}

.wrap {
    width: 100%;
    padding: var(--pane-gap);
    display: grid;
    grid-template-rows: auto auto auto;
    gap: var(--pane-gap);
}

.hdr {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    align-items: flex-end;
    flex-wrap: wrap;
}

.hdr__copy {
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex: 1 1 20rem;
    min-width: 0;
    max-width: 72rem;
    position: relative;
}

.hdr__title-row {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
    flex-wrap: wrap;
}

h1 {
    margin: 0;
    font-size: 22px;
}

.puzzle-info-button {
    width: 32px;
    min-width: 32px;
    height: 32px;
    padding: 0;
    border: 1px solid var(--cw-tab-border);
    border-radius: 999px;
    background: var(--cw-tab-bg);
    color: var(--cw-text);
    font-size: 15px;
    font-weight: 700;
    line-height: 1;
}

.puzzle-info-button:hover {
    background: var(--cw-tab-hover);
}

.puzzle-info-button[hidden] {
    display: none !important;
}

.puzzle-popover {
    position: absolute;
    top: calc(100% + 12px);
    left: 0;
    z-index: 6;
    width: min(420px, calc(100vw - 48px));
    padding: 16px 18px;
    border: 1px solid var(--cw-modal-card-border);
    border-radius: 18px;
    background: linear-gradient(180deg, var(--cw-modal-surface-from) 0%, var(--cw-modal-surface-to) 100%);
    box-shadow: 0 20px 40px rgba(0, 0, 0, .28);
    backdrop-filter: blur(16px);
}

.puzzle-popover[hidden] {
    display: none !important;
}

.puzzle-popover__body {
    margin: 0;
    font-size: 14px;
    line-height: 1.6;
    color: var(--cw-text);
}

.sub {
    opacity: .8;
    font-size: 13px;
}

.clues__header[hidden],
.clues__description[hidden] {
    display: none !important;
}

.clues__header,
.reward-strip,
.share-hint {
    display: none !important;
}

.clues__header {
    padding: 0 2px 2px;
}

.clues__description {
    margin: 0;
    font-size: 14px;
    line-height: 1.55;
    color: var(--cw-text);
    opacity: .92;
}

.reward-strip {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    align-items: start;
    column-gap: 10px;
    row-gap: 2px;
    max-width: 44rem;
    padding: 8px 10px;
    border-radius: 12px;
    border: 1px solid rgba(59, 130, 246, .28);
    background: rgba(59, 130, 246, .1);
}

.reward-strip__label {
    font-size: 13px;
    font-weight: 700;
    line-height: 1.25;
}

.reward-strip__meta {
    font-size: 11px;
    line-height: 1.35;
    color: var(--cw-text-muted);
}

select {
    background: var(--cw-select-bg);
    color: var(--cw-text);
    border: 1px solid var(--cw-cell-border);
    border-radius: var(--border-radius);
    padding: 8px 10px;
}


.pane {
    display: grid;
    grid-template-columns: minmax(0, 2fr) minmax(0, 1fr);
    gap: var(--pane-gap);
    min-height: 0;
    align-items: start;
}

/* Grid viewport: fixed cell size, scrolls/pans when grid exceeds space */
.gridViewport {
    overflow: auto;
    background: transparent;
    border: 0;
    border-radius: 0;
    min-width: 0;
    max-height: 80vh;
}

.gridViewport.dragging {
    cursor: grabbing;
}

/* The grid itself should also be transparent & panel-less */
.grid {
    display: grid;
    gap: var(--gap-size);
    width: max-content;
    margin-inline: auto;
    justify-content: start;
    align-content: start;
    /* remove panel visuals */
    background: transparent;
    border: 0;
    border-radius: 0;
    padding: 0;
}

/* Individual cells */
.cell {
    width: var(--cell-size);
    height: var(--cell-size);
    min-width: 0;
    min-height: 0;
    position: relative;
    border-radius: 6px;
    border: 1px solid var(--cw-cell-border);
    background: var(--cw-cell-bg);
    display: grid;
    place-items: center;
}

.blk {
    background: var(--cw-blk-bg);
    border-color: var(--cw-blk-border);
}

/* (kept for safety) */

.cell input {
    width: 100%;
    height: 100%;
    border: 0;
    outline: 0;
    background: transparent;
    text-align: center;
    font: 700 18px/1.1 system-ui;
    color: var(--cw-cell-input);
    text-transform: uppercase;
}

.num {
    position: absolute;
    top: 2px;
    left: 4px;
    font-size: 10px;
    color: var(--cw-text-muted);
    opacity: .9;
    pointer-events: none;
}

.correct {
    box-shadow: inset 0 0 0 2px rgba(55, 211, 154, .28);
    border-color: #34d399;
}

.wrong {
    box-shadow: inset 0 0 0 2px rgba(255, 107, 107, .28);
    border-color: #ff6b6b;
}

.clues {
    display: grid;
    grid-template-columns: var(--clue-stack-track-size);
    gap: 12px 18px;
    overflow-y: auto;
    max-height: 80vh;
    align-self: start;
    transform: translateY(calc(-1 * var(--clues-panel-offset)));
    margin-bottom: calc(-1 * var(--clues-panel-offset));
}

.word-search-panel {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.word-search-panel[hidden] {
    display: none !important;
}

.word-search-panel__header {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
}

.word-search-panel__title {
    margin: 0;
    font-size: 16px;
}

.word-search-panel__progress {
    font-size: 12px;
    color: var(--cw-text-muted);
}

.word-search-panel__hint {
    padding: 10px 12px;
    border-radius: 12px;
    border: 1px solid rgba(245, 158, 11, .3);
    background: rgba(245, 158, 11, .08);
    font-size: 13px;
    line-height: 1.5;
}

.word-search-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: grid;
    gap: 8px;
}

.word-search-word {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: start;
    gap: 8px;
    padding: 10px 12px;
    border-radius: 12px;
    border: 1px solid var(--cw-clue-border);
    background: var(--cw-clue-bg);
    font-size: 12px;
    font-weight: 400;
    letter-spacing: 0;
    text-transform: uppercase;
}

.word-search-word .hintControls {
    float: none;
    margin-left: 0;
    justify-self: end;
}

.word-search-word .hintButton {
    width: auto;
}

.word-search-word__definition,
.word-search-word .hintText {
    grid-column: 1 / -1;
    color: var(--cw-text-muted);
    font-size: 12px;
    font-weight: 400;
    letter-spacing: 0;
    line-height: 1.45;
    text-transform: none;
}

.word-search-word__definition[hidden] {
    display: none;
}

.word-search-word--found {
    color: var(--cw-text-muted);
    border-color: rgba(52, 211, 153, .42);
    background: rgba(52, 211, 153, .09);
}

.word-search-word--found .word-search-word__label {
    text-decoration: line-through;
}

.word-search-grid {
    --gap-size: 6px;
    position: relative;
    gap: var(--gap-size);
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
}

.word-search-cell {
    width: var(--cell-size);
    height: var(--cell-size);
    border-radius: 8px;
    border: 1px solid var(--cw-cell-border);
    background: var(--cw-cell-bg);
    color: var(--cw-cell-input);
    font: 800 18px/1.1 system-ui;
    text-transform: uppercase;
    display: grid;
    place-items: center;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
    transition: transform .12s ease, border-color .12s ease, background .12s ease, box-shadow .12s ease;
}

.word-search-cell:hover {
    transform: translateY(-1px);
}

.word-search-cell--selected {
    border-color: rgba(96, 165, 250, .72);
    background: rgba(59, 130, 246, .12);
}

.word-search-cell--found,
.word-search-cell--revealed {
    border-color: rgba(52, 211, 153, .6);
    background: rgba(52, 211, 153, .16);
    box-shadow: inset 0 0 0 1px rgba(52, 211, 153, .36);
}

.word-search-cell--revealed {
    border-color: rgba(245, 158, 11, .65);
    background: rgba(245, 158, 11, .16);
}

.word-search-cell--hinted {
    animation: word-search-pulse 0.7s ease-in-out 2;
}

.word-search-found-boundary {
    position: absolute;
    z-index: 2;
    box-sizing: border-box;
    border: 1px solid rgba(209, 250, 229, .9);
    border-radius: 8px;
    box-shadow: 0 0 0 1px rgba(16, 185, 129, .28);
    pointer-events: none;
    transform-origin: center;
}

.word-search-drag-coach {
    position: fixed;
    z-index: 80;
    width: 112px;
    height: 34px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    pointer-events: none;
    border-radius: 999px;
    border: 1px solid rgba(96, 165, 250, .42);
    background: rgba(15, 20, 42, .94);
    box-shadow: 0 14px 30px rgba(0, 0, 0, .32);
    animation: word-search-drag-coach-enter .18s ease-out;
}

.word-search-drag-coach__dot {
    width: 10px;
    height: 10px;
    border-radius: 999px;
    background: #dbeafe;
    box-shadow: 0 0 0 4px rgba(96, 165, 250, .16);
}

.word-search-drag-coach__dot--end {
    animation: word-search-drag-coach-dot 1.2s ease-in-out infinite;
}

.word-search-drag-coach__trail {
    position: relative;
    width: 44px;
    height: 2px;
    border-radius: 999px;
    background: rgba(147, 197, 253, .72);
    overflow: hidden;
}

.word-search-drag-coach__trail::after {
    content: "";
    position: absolute;
    inset: 0;
    width: 18px;
    border-radius: inherit;
    background: #60a5fa;
    animation: word-search-drag-coach-trail 1.2s ease-in-out infinite;
}

@keyframes word-search-pulse {
    0% { transform: scale(1); box-shadow: 0 0 0 0 rgba(245, 158, 11, .3); }
    50% { transform: scale(1.04); box-shadow: 0 0 0 10px rgba(245, 158, 11, 0); }
    100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(245, 158, 11, 0); }
}

@keyframes word-search-drag-coach-enter {
    from { opacity: 0; transform: translateY(4px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes word-search-drag-coach-trail {
    0% { transform: translateX(-18px); opacity: 0; }
    22% { opacity: 1; }
    78% { opacity: 1; }
    100% { transform: translateX(44px); opacity: 0; }
}

@keyframes word-search-drag-coach-dot {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.25); }
}

@media (prefers-reduced-motion: reduce) {
    .word-search-drag-coach,
    .word-search-drag-coach__dot--end,
    .word-search-drag-coach__trail::after {
        animation: none;
    }
}

@media (max-width: 800px) {
    .reward-strip {
        grid-template-columns: 1fr;
    }

    .clues {
        transform: none;
        margin-bottom: 0;
    }

    .wrap {
        height: auto;
        overflow-y: auto;
        overflow-x: auto;
    }

    .pane {
        grid-template-columns: minmax(0, 1fr);
        overflow-y: auto;
        overflow-x: visible;
    }

    .gridViewport {
        flex: 0 0 auto;
        height: auto;
        overflow: auto;
    }

    .clues {
        flex: 0 0 auto;
        width: 100%;
        margin-left: 0;
        align-self: stretch;
    }
}

.cluegrp h3 {
    margin: 0 0 6px;
    font-size: 16px;
    text-align: left;
}

.cluegrp ol,
.cluegrp li {
    text-align: left;
}

ol {
    list-style: none;
    padding-left: 0;
    margin: 0;
    display: grid;
    gap: 6px;
}

li {
    padding: 8px 10px;
    background: var(--cw-clue-bg);
    border: 1px solid var(--cw-clue-border);
    border-radius: var(--border-radius);
}

.controls {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.controls__actions {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.clue-toolbar[hidden] {
    display: none !important;
}

.clue-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    min-width: 0;
    padding-bottom: 4px;
    border-bottom: 1px solid var(--cw-wrap-border);
}

.clue-toolbar__actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    min-width: 0;
}

.clue-toolbar__button,
.clue-toolbar__share {
    min-height: 42px;
    padding: 0 16px;
    border: 1px solid var(--cw-tab-border);
    border-radius: 14px;
    background: var(--cw-tab-bg);
    color: var(--cw-text);
    font-size: 14px;
    font-weight: 700;
    letter-spacing: .01em;
    line-height: 1;
    transition:
        transform .14s ease,
        background .14s ease,
        border-color .14s ease,
        box-shadow .14s ease,
        color .14s ease;
}

.clue-toolbar__button:hover:not(:disabled),
.clue-toolbar__share:hover:not(:disabled) {
    transform: translateY(-1px);
    background: var(--cw-tab-hover);
    border-color: var(--cw-prism-border);
    box-shadow: 0 10px 18px rgba(15, 23, 42, .2);
}

.clue-toolbar__button:focus-visible,
.clue-toolbar__share:focus-visible {
    outline: 2px solid rgba(96, 165, 250, .56);
    outline-offset: 2px;
}

.clue-toolbar__button--check {
    border-color: rgba(96, 165, 250, .52);
    background: linear-gradient(180deg, #4f8df9 0%, #2563eb 100%);
    box-shadow: 0 10px 20px rgba(37, 99, 235, .24);
}

.clue-toolbar__button--check:hover:not(:disabled) {
    background: linear-gradient(180deg, #69a4ff 0%, #326ef0 100%);
    border-color: rgba(147, 197, 253, .72);
}

.clue-toolbar__button--reveal {
    border-color: rgba(245, 158, 11, .34);
    background: rgba(245, 158, 11, .1);
}

.clue-toolbar__button--reveal:hover:not(:disabled) {
    background: rgba(245, 158, 11, .16);
    border-color: rgba(251, 191, 36, .52);
}

.clue-toolbar__share {
    width: 42px;
    min-width: 42px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-left: auto;
}

.clue-toolbar__share-icon {
    font-size: 18px;
    line-height: 1;
}

.clue-toolbar__button:disabled {
    opacity: .52;
    box-shadow: none;
    cursor: not-allowed;
}

.clue-toolbar__share:disabled {
    display: none;
}

.share-hint {
    font-size: 11px;
    line-height: 1.35;
    color: var(--cw-text-muted);
}

button {
    background: #3b82f6;
    color: #fff;
    border: 0;
    border-radius: var(--border-radius);
    padding: 10px 14px;
    font-weight: 700;
    cursor: pointer;
}

button.secondary {
    background: var(--cw-btn-secondary);
}

button:disabled {
    opacity: .56;
    cursor: not-allowed;
}

@keyframes copied-flash {
    0%   { opacity: 1; }
    100% { opacity: 1; }
}
.copied-flash {
    animation: copied-flash 2s forwards;
}

@media (max-width: 500px) {
    :root {
        --controls-dock-height: 0px;
        --wrap-offset: 24px;
        --pane-gap: 12px;
    }

    body {
        padding: 12px;
    }

    .hdr {
        align-items: stretch;
    }

    button {
        width: 100%;
    }

    .clue-toolbar {
        display: grid;
        grid-template-columns: minmax(0, 1fr);
        width: 100%;
    }

    .clue-toolbar__actions {
        width: 100%;
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .clue-toolbar__button,
    .clue-toolbar__share {
        width: 100%;
    }

    .clue-toolbar__share {
        margin-left: 0;
    }
}

.status {
    align-self: flex-start;
    font-size: 14px;
    opacity: .95;
}

.ok {
    color: #34d399;
    font-weight: 700;
}

.error {
    flex-basis: 100%;
    padding: 10px 12px;
    border-radius: var(--border-radius);
    background: rgba(255, 107, 107, .1);
    border: 1px solid rgba(255, 107, 107, .35);
    color: #ffd0d0;
    display: none;
}

/* Word/cell highlighting */
.cell.hl {
    box-shadow: inset 0 0 0 2px rgba(99, 102, 241, .45); /* subtle indigo glow */
    border-color: #6366f1;
}

.clueHL {
    background: rgba(99, 102, 241, .12);
    border-color: rgba(99, 102, 241, .5);
}

.clueSolved {
    background: rgba(52, 211, 153, .12);
    border-color: rgba(52, 211, 153, .5);
}

.hintControls {
    display: inline-block;
    float: right;
    margin-left: 4px;
    padding: 0;
}

.hintButton {
    padding: 0 4px;
    font-size: 12px;
    line-height: 1;
    min-width: 0;
    border-radius: 4px;
}

.hintText {
    margin-top: 4px;
    font-size: 13px;
    opacity: .9;
}

/* --- Mode tabs --- */
.mode-tabs {
    display: flex;
    gap: 4px;
    margin-left: auto;
}

.mode-tab {
    background: var(--cw-tab-bg);
    color: var(--cw-text-muted);
    border: 1px solid var(--cw-tab-border);
    border-radius: 8px;
    padding: 6px 14px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: background .15s, color .15s;
}

.mode-tab.active {
    background: #3b82f6;
    color: #fff;
    border-color: #3b82f6;
}

.mode-tab:hover:not(.active) {
    background: var(--cw-tab-hover);
}

/* --- Panel bar --- */
.panel-bar {
    padding: 0 2px;
}

/* --- Generate form --- */
.generate-form {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
}

.puzzle-type-switch {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px;
    border-radius: 14px;
    border: 1px solid var(--cw-wrap-border);
    background: rgba(255, 255, 255, .04);
}

.puzzle-type-switch__button {
    min-width: 128px;
    padding: 10px 14px;
    border-radius: 10px;
    background: transparent;
    color: var(--cw-text-muted);
    border: 1px solid transparent;
}

.puzzle-type-switch__button--active {
    background: rgba(59, 130, 246, .14);
    border-color: rgba(59, 130, 246, .28);
    color: var(--cw-text);
}

.generate-form input[type="text"] {
    flex: 1 1 200px;
    min-width: 180px;
    background: var(--cw-select-bg);
    color: var(--cw-text);
    border: 1px solid var(--cw-cell-border);
    border-radius: var(--border-radius);
    padding: 8px 12px;
    font-size: 14px;
    outline: none;
}

.generate-form input[type="text"]:focus {
    border-color: #3b82f6;
    box-shadow: 0 0 0 2px rgba(59, 130, 246, .25);
}

.generate-form input[type="text"]::placeholder {
    color: var(--cw-placeholder);
}

.word-count-label {
    display: flex;
    gap: 6px;
    align-items: center;
    font-size: 13px;
    opacity: .85;
}

#generateBtn {
    white-space: nowrap;
}

#generateBtn:disabled {
    opacity: .45;
    cursor: not-allowed;
}


/* ========== Settings modal ========== */
.settings-modal {
    width: min(64rem, calc(100vw - 2rem));
    max-width: calc(100vw - 2rem);
    max-height: calc(100vh - 2rem);
    margin: auto;
    padding: 0;
    border: none;
    background: transparent;
    color: var(--cw-text);
}

.settings-modal::backdrop {
    background: rgba(2, 6, 23, .72);
    backdrop-filter: blur(12px);
}

.settings-modal__surface {
    display: flex;
    flex-direction: column;
    min-height: min(32rem, calc(100vh - 2rem));
    max-height: calc(100vh - 2rem);
    overflow: hidden;
    border-radius: 22px;
    border: 1px solid var(--cw-wrap-border);
    background:
        radial-gradient(circle at top right, var(--cw-modal-glow-a), transparent 30%),
        radial-gradient(circle at left center, var(--cw-modal-glow-b), transparent 28%),
        linear-gradient(180deg, var(--cw-modal-surface-from), var(--cw-modal-surface-to));
    box-shadow: 0 32px 80px rgba(2, 6, 23, .58);
    backdrop-filter: blur(22px) saturate(140%);
}

.settings-modal__header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    padding: 20px 24px 14px;
    border-bottom: 1px solid var(--cw-modal-divider);
}

.settings-modal__title {
    margin: 0;
    font-size: 28px;
    line-height: 1.05;
}

.settings-modal__subtitle {
    margin: 6px 0 0;
    font-size: 13px;
    color: var(--cw-text-muted);
}

.settings-modal__close {
    padding: 8px 12px;
    border-radius: 999px;
    border: 1px solid var(--cw-tab-border);
    background: var(--cw-tab-bg);
    color: var(--cw-text);
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
}

.settings-modal__close:hover {
    background: var(--cw-tab-hover);
}

.settings-modal__body {
    display: flex;
    flex: 1 1 auto;
    flex-direction: column;
    gap: 14px;
    padding: 18px 24px 24px;
    overflow: hidden;
}

.completion-modal {
    width: min(34rem, calc(100vw - 2rem));
    max-width: calc(100vw - 2rem);
    margin: auto;
    padding: 0;
    border: none;
    background: transparent;
    color: var(--cw-text);
}

.completion-modal::backdrop {
    background: rgba(2, 6, 23, .72);
    backdrop-filter: blur(12px);
}

.completion-modal__surface {
    display: flex;
    flex-direction: column;
    gap: 18px;
    padding: 22px;
    border-radius: 22px;
    border: 1px solid var(--cw-wrap-border);
    background:
        radial-gradient(circle at top right, var(--cw-modal-glow-a), transparent 28%),
        linear-gradient(180deg, var(--cw-modal-surface-from), var(--cw-modal-surface-to));
    box-shadow: 0 32px 80px rgba(2, 6, 23, .58);
}

.completion-modal__header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
}

.completion-modal__title {
    margin: 0;
    font-size: 24px;
}

.completion-modal__summary {
    margin: 6px 0 0;
    font-size: 14px;
    color: var(--cw-text-muted);
}

.completion-modal__close {
    padding: 8px 12px;
    border-radius: 999px;
    border: 1px solid var(--cw-tab-border);
    background: var(--cw-tab-bg);
    color: var(--cw-text);
}

.completion-modal__body {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.completion-modal__breakdown {
    display: grid;
    gap: 8px;
}

.completion-modal__row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 12px;
    border-radius: 14px;
    border: 1px solid var(--cw-modal-card-border);
    background: var(--cw-modal-card-bg);
}

.completion-modal__row--total {
    border-color: rgba(52, 211, 153, .4);
}

.completion-modal__reason {
    font-size: 13px;
    line-height: 1.45;
    color: var(--cw-text-muted);
}

.completion-modal__actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    flex-wrap: wrap;
}

.settings-tabs {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
}

.settings-tabs__btn {
    padding: 8px 16px;
    font-size: 14px;
    font-weight: 700;
    border-radius: 12px;
    border: 1px solid var(--cw-modal-card-border);
    background: rgba(15, 23, 42, .68);
    color: var(--cw-text-muted);
    cursor: pointer;
    transition: background .15s, color .15s, border-color .15s, transform .15s;
}

.settings-tabs__btn:hover:not(.settings-tabs__btn--active) {
    background: rgba(59, 130, 246, .14);
    border-color: rgba(59, 130, 246, .28);
    color: var(--cw-text);
}

.settings-tabs__btn--active {
    background: #3b82f6;
    color: #fff;
    border-color: #3b82f6;
    box-shadow: 0 10px 24px rgba(59, 130, 246, .28);
}

.settings-section {
    min-height: 0;
    overflow: auto;
    padding-right: 2px;
}

/* --- Account card (inside modal) --- */
.settings-account-card {
    padding: 22px;
    border-radius: 18px;
    background: rgba(8, 20, 32, .88);
    border: 1px solid var(--cw-modal-card-border);
    display: flex;
    flex-direction: column;
    gap: 18px;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, .04);
}

.settings-account-card__row {
    display: flex;
    align-items: center;
    gap: 16px;
    min-width: 0;
}

.settings-account-card__avatar {
    width: 72px;
    height: 72px;
    border-radius: 50%;
    flex-shrink: 0;
    object-fit: cover;
    border: 3px solid rgba(59, 130, 246, .35);
    box-shadow: 0 12px 24px rgba(2, 6, 23, .32);
}

.settings-account-card__info {
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex: 1 1 auto;
}

.settings-account-card__name {
    font-size: clamp(24px, 3.8vw, 38px);
    font-weight: 800;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.settings-account-card__email {
    font-size: 16px;
    color: #c7d2fe;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.settings-account-card__details {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.settings-account-card__details-header {
    font-size: 13px;
    font-weight: 700;
    letter-spacing: .12em;
    text-transform: uppercase;
    color: #c7d2fe;
}

.settings-account-details {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 12px;
    margin: 0;
}

.settings-account-details__item {
    padding: 16px 18px;
    border-radius: 16px;
    border: 1px solid var(--cw-modal-card-border);
    background: var(--cw-modal-card-bg);
    min-width: 0;
    min-height: 96px;
}

.settings-account-details__term {
    margin: 0 0 8px;
    font-size: 13px;
    font-weight: 700;
    letter-spacing: .12em;
    text-transform: uppercase;
    color: #bec8ee;
}

.settings-account-details__value {
    margin: 0;
    font-size: 16px;
    line-height: 1.3;
    color: var(--cw-text);
    overflow-wrap: anywhere;
    word-break: break-word;
    font-weight: 600;
}

.settings-billing {
    display: flex;
    flex-direction: column;
    gap: 18px;
    margin-top: 18px;
    padding: 22px;
    border-radius: 18px;
    background: rgba(8, 20, 32, .88);
    border: 1px solid var(--cw-modal-card-border);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, .04);
}

.settings-billing__header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
}

.settings-billing__copy {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.settings-billing__balance {
    font-size: clamp(28px, 4vw, 40px);
    font-weight: 800;
    line-height: 1;
}

.settings-billing__meta {
    margin: 0;
    max-width: 36rem;
    font-size: 14px;
    line-height: 1.5;
    color: var(--cw-text-muted);
}

.settings-billing__manage {
    white-space: nowrap;
}

.settings-billing__section {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.billing-pack-list {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 12px;
}

.billing-pack,
.billing-pack-list__empty,
.billing-activity,
.billing-activity-list__empty {
    padding: 16px 18px;
    border-radius: 16px;
    border: 1px solid var(--cw-modal-card-border);
    background: var(--cw-modal-card-bg);
}

.billing-pack {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.billing-pack__label {
    font-size: 18px;
    font-weight: 700;
}

.billing-pack__credits {
    font-size: 30px;
    font-weight: 800;
    line-height: 1;
}

.billing-pack__meta {
    color: var(--cw-text-muted);
    font-size: 13px;
    line-height: 1.5;
}

.billing-pack__buy {
    margin-top: auto;
}

.billing-pack-list__empty,
.billing-activity-list__empty {
    color: var(--cw-text-muted);
    font-size: 13px;
}

.billing-activity-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.billing-activity {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.billing-activity__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
}

.billing-activity__summary {
    font-size: 14px;
    font-weight: 600;
}

.billing-activity__status {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .08em;
}

.billing-activity__status--completed {
    color: #34d399;
}

.billing-activity__status--pending {
    color: #f59e0b;
}

.billing-activity__meta {
    color: var(--cw-text-muted);
    font-size: 12px;
    line-height: 1.5;
}

/* ========== Admin sub-panel (inside settings Admin tab) ========== */

.admin-panel__body {
    flex: 1 1 auto;
    overflow-y: auto;
    display: grid;
    grid-template-columns: minmax(220px, 280px) minmax(0, 1fr);
    min-height: 0;
    border-radius: 20px;
    border: 1px solid var(--cw-modal-card-border);
    background: rgba(8, 20, 32, .84);
}

.admin-panel__users {
    border-right: 1px solid var(--cw-wrap-border);
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    overflow-y: auto;
}

.admin-panel__details {
    padding: 16px;
    overflow-y: auto;
    min-width: 0;
}

.admin-panel__section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
}

.admin-panel__section-title {
    margin: 0 0 8px;
    font-size: 13px;
    font-weight: 700;
    text-transform: uppercase;
    color: var(--cw-text-muted);
    letter-spacing: .5px;
}

.admin-panel__btn-sm {
    font-size: 11px;
    padding: 3px 8px;
    border-radius: 6px;
}

.admin-panel__search {
    width: 100%;
    background: var(--cw-select-bg);
    color: var(--cw-text);
    border: 1px solid var(--cw-cell-border);
    border-radius: 8px;
    padding: 6px 8px;
    font-size: 12px;
    outline: none;
}

.admin-panel__search:focus {
    border-color: #3b82f6;
    box-shadow: 0 0 0 2px rgba(59, 130, 246, .25);
}

.admin-panel__user-list {
    display: flex;
    flex-direction: column;
    gap: 2px;
    overflow-y: auto;
    max-height: 100%;
}

.admin-panel__user-item {
    display: flex;
    flex-direction: column;
    gap: 2px;
    width: 100%;
    text-align: left;
    padding: 6px 8px;
    font-size: 12px;
    border-radius: 6px;
    border: 1px solid transparent;
    background: transparent;
    color: var(--cw-text);
    cursor: pointer;
    min-width: 0;
}

.admin-panel__user-item:hover {
    background: rgba(59, 130, 246, .06);
    border-color: rgba(59, 130, 246, .2);
}

.admin-panel__user-item--active {
    background: rgba(59, 130, 246, .12);
    border-color: #3b82f6;
    font-weight: 600;
}

.admin-panel__user-empty {
    font-size: 12px;
    color: var(--cw-text-muted);
    padding: 8px 0;
}

.admin-panel__user-primary,
.admin-panel__user-secondary {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.admin-panel__user-primary {
    font-weight: 600;
}

.admin-panel__user-secondary {
    color: var(--cw-text-muted);
    font-size: 11px;
}

.admin-panel__placeholder {
    font-size: 13px;
    color: var(--cw-text-muted);
    padding: 24px 0;
    text-align: center;
}

.admin-panel__user-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
    gap: 12px;
}

.admin-panel__selected-user {
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.admin-panel__selected-label {
    font-size: 13px;
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.admin-panel__selected-meta {
    font-size: 12px;
    color: var(--cw-text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.admin-panel__balance-card {
    padding: 16px;
    border-radius: 14px;
    background: var(--cw-modal-card-bg);
    border: 1px solid var(--cw-modal-card-border);
    margin-bottom: 16px;
}

[data-mpr-theme="light"] .settings-tabs__btn {
    background: rgba(255, 255, 255, .92);
    color: var(--cw-text-muted);
}

[data-mpr-theme="light"] .settings-tabs__btn:hover:not(.settings-tabs__btn--active) {
    background: rgba(59, 130, 246, .1);
}

[data-mpr-theme="light"] .settings-account-card,
[data-mpr-theme="light"] .settings-billing,
[data-mpr-theme="light"] .admin-panel__body {
    background: rgba(255, 255, 255, .94);
}

[data-mpr-theme="light"] .settings-account-card__email,
[data-mpr-theme="light"] .settings-account-card__details-header,
[data-mpr-theme="light"] .settings-account-details__term {
    color: #42506f;
}

.admin-panel__balance-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 4px 0;
}

.admin-panel__balance-label {
    font-size: 12px;
    color: var(--cw-text-muted);
}

.admin-panel__balance-value {
    font-size: 14px;
    font-weight: 700;
}

.admin-panel__grant-form {
    display: grid;
    gap: 8px;
}

.admin-panel__label {
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 12px;
    color: var(--cw-text-muted);
    flex: 1 1 auto;
}

.admin-panel__input {
    background: var(--cw-select-bg);
    color: var(--cw-text);
    border: 1px solid var(--cw-cell-border);
    border-radius: 8px;
    padding: 8px 10px;
    font-size: 14px;
    outline: none;
    width: 100%;
}

.admin-panel__input:focus {
    border-color: #3b82f6;
    box-shadow: 0 0 0 2px rgba(59, 130, 246, .25);
}

.admin-panel__textarea {
    resize: vertical;
    min-height: 84px;
    font-family: inherit;
}

.admin-panel__hint {
    font-size: 12px;
    color: var(--cw-text-muted);
    margin-bottom: 6px;
}

.admin-panel__status {
    font-size: 12px;
    min-height: 18px;
    padding-top: 4px;
}

.admin-panel__status--error {
    color: #ff6b6b;
}

.admin-panel__status--success {
    color: #34d399;
}

.admin-panel__history-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.admin-panel__history-item,
.admin-panel__history-empty {
    padding: 12px 14px;
    border-radius: 14px;
    background: var(--cw-modal-card-bg);
    border: 1px solid var(--cw-modal-card-border);
}

.admin-panel__history-empty {
    color: var(--cw-text-muted);
    font-size: 12px;
}

.admin-panel__history-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    margin-bottom: 8px;
}

.admin-panel__history-amount {
    font-size: 14px;
    font-weight: 700;
}

.admin-panel__history-time,
.admin-panel__history-meta {
    font-size: 12px;
    color: var(--cw-text-muted);
}

.admin-panel__history-reason {
    font-size: 13px;
    line-height: 1.4;
    margin-bottom: 6px;
}

@media (max-width: 600px) {
    .settings-modal {
        width: calc(100vw - 1rem);
        max-width: calc(100vw - 1rem);
        max-height: calc(100vh - 1rem);
    }
    .settings-modal__surface {
        min-height: calc(100vh - 1rem);
        max-height: calc(100vh - 1rem);
        border-radius: 18px;
    }
    .settings-modal__header {
        padding: 18px 18px 14px;
    }
    .settings-modal__title {
        font-size: 24px;
    }
    .settings-modal__body {
        padding: 16px 18px 18px;
    }
    .settings-account-card__row {
        align-items: flex-start;
    }
    .settings-account-card {
        padding: 18px;
    }
    .settings-account-card__avatar {
        width: 64px;
        height: 64px;
    }
    .settings-account-details {
        grid-template-columns: 1fr;
    }
    .admin-panel__body {
        grid-template-columns: 1fr;
        grid-template-rows: auto 1fr;
    }
    .admin-panel__users {
        border-right: none;
        border-bottom: 1px solid var(--cw-wrap-border);
        max-height: 180px;
    }
}

/* --- Push header actions (sign-in, avatar) to the right --- */
#app-header .mpr-header__brand-link,
#app-header .mpr-header > a:first-of-type {
    display: inline-flex;
    align-items: center;
    gap: 10px;
}

#app-header .mpr-header__brand-link::before,
#app-header .mpr-header > a:first-of-type::before {
    content: "";
    display: block;
    width: 30px;
    height: 30px;
    flex: 0 0 auto;
    border-radius: 8px;
    overflow: hidden;
    background: #050816;
    background-image: url("/assets/img/hecate_favicon.png");
    background-position: center;
    background-size: cover;
    background-repeat: no-repeat;
    box-shadow: 0 6px 16px rgba(15, 23, 42, .24);
}

[data-mpr-theme="light"] #app-header .mpr-header__brand-link::before,
:root[data-mpr-theme="light"] #app-header .mpr-header__brand-link::before,
[data-mpr-theme="light"] #app-header .mpr-header > a:first-of-type::before,
:root[data-mpr-theme="light"] #app-header .mpr-header > a:first-of-type::before {
    background-color: #f8ecd1;
    background-image: url("/assets/img/hecate_header_icon_light.png");
}

.mpr-header .mpr-header__actions {
    margin-left: auto;
}

@media (max-width: 860px) and (min-width: 501px) {
    .mpr-header .mpr-header__inner {
        flex-wrap: wrap;
        row-gap: 10px;
    }

    .clue-toolbar {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        width: 100%;
    }

    .clue-toolbar__actions {
        display: flex;
    }

    .clue-toolbar__button {
        width: 100%;
        min-width: 0;
    }
}

/* --- Credit badge (in header) --- */
.header-credit-badge {
    appearance: none;
    border: 1px solid rgba(52, 211, 153, .28);
    font-size: 13px;
    font-weight: 600;
    padding: 4px 10px;
    border-radius: 12px;
    background: rgba(52, 211, 153, .15);
    color: #34d399;
    white-space: nowrap;
    margin-right: 8px;
    cursor: pointer;
    transition: transform .12s ease, border-color .12s ease, background .12s ease;
}

.header-credit-badge:hover {
    background: rgba(52, 211, 153, .22);
    border-color: rgba(52, 211, 153, .42);
    transform: translateY(-1px);
}

.header-credit-badge:focus-visible {
    outline: 2px solid rgba(52, 211, 153, .4);
    outline-offset: 2px;
}

.header-credit-badge--pulse {
    animation: credit-pulse .5s ease;
}

@keyframes credit-pulse {
    0% { transform: scale(1); }
    40% { transform: scale(1.08); }
    100% { transform: scale(1); }
}

.credit-popover {
    position: fixed;
    z-index: 20;
    width: min(360px, calc(100vw - 32px));
}

.credit-popover[hidden] {
    display: none !important;
}

.credit-popover__surface {
    padding: 18px;
    border: 1px solid var(--cw-modal-card-border);
    border-radius: 20px;
    background: linear-gradient(180deg, var(--cw-modal-surface-from) 0%, var(--cw-modal-surface-to) 100%);
    box-shadow: 0 22px 44px rgba(0, 0, 0, .28);
    backdrop-filter: blur(18px);
}

.credit-popover__eyebrow {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: .12em;
    text-transform: uppercase;
    color: var(--cw-text-muted);
}

.credit-popover__balance {
    margin-top: 8px;
    font-size: 28px;
    font-weight: 800;
    line-height: 1.1;
}

.credit-popover__sections {
    display: grid;
    gap: 10px;
    margin-top: 16px;
}

.credit-popover__section {
    padding: 12px 14px;
    border-radius: 14px;
    border: 1px solid var(--cw-modal-card-border);
    background: var(--cw-modal-card-bg);
}

.credit-popover__section-title {
    font-size: 13px;
    font-weight: 700;
}

.credit-popover__section-body {
    margin-top: 4px;
    font-size: 12px;
    line-height: 1.5;
    color: var(--cw-text-muted);
}

.credit-popover__billing {
    width: 100%;
    margin-top: 16px;
    border-radius: 14px;
}

/* --- Generate status --- */
.generate-status {
    flex: 1 1 220px;
    font-size: 13px;
    padding-top: 6px;
    min-height: 20px;
}

.generate-status-row {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    flex-wrap: wrap;
}

.generate-buy-credits {
    white-space: nowrap;
}

.generate-buy-credits[hidden] {
    display: none !important;
}

.generate-status.loading {
    color: #3b82f6;
}

.generate-status.loading::after {
    content: "";
    display: inline-block;
    width: 12px;
    height: 12px;
    margin-left: 8px;
    border: 2px solid rgba(59, 130, 246, .3);
    border-top-color: #3b82f6;
    border-radius: 50%;
    animation: spin .6s linear infinite;
    vertical-align: middle;
}

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

/* --- Adjust wrap for mpr-header/footer --- */
body {
    padding-top: 0;
}

.wrap {
    margin: 24px auto 48px; /* top spacing, center, space for sticky footer */
}

/* ========== Landing page ========== */
.landing {
    width: 100%;
    max-width: 960px;
    margin: 0 auto;
    padding: 48px 24px 80px;
    text-align: center;
}

.landing__hero {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-bottom: 32px;
}

.landing__title {
    font-size: clamp(28px, 5vw, 42px);
    font-weight: 800;
    margin: 0 0 16px;
    line-height: 1.2;
}

.landing__subtitle {
    font-size: 17px;
    max-width: 540px;
    margin: 0 auto 32px;
    color: var(--cw-text-muted);
    line-height: 1.6;
}

.landing__type-grid {
    width: min(720px, 100%);
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
    margin: 28px auto 0;
}

.landing__type-card {
    padding: 18px;
    text-align: left;
    border-radius: 18px;
    border: 1px solid var(--cw-wrap-border);
    background: var(--cw-wrap-bg);
    color: var(--cw-text);
    display: flex;
    flex-direction: column;
    gap: 8px;
    box-shadow: 0 14px 28px rgba(15, 23, 42, .12);
}

.landing__type-card:hover {
    transform: translateY(-2px);
}

.landing__type-card--selected {
    border-color: rgba(59, 130, 246, .55);
    background: linear-gradient(180deg, rgba(59, 130, 246, .16) 0%, rgba(59, 130, 246, .08) 100%);
}

.landing__type-label {
    font-size: 18px;
    font-weight: 800;
}

.landing__type-desc {
    font-size: 14px;
    line-height: 1.5;
    color: var(--cw-text-muted);
}

.landing__generate {
    margin-top: 24px;
    padding: 16px 20px;
    background: var(--cw-wrap-bg);
    border: 1px solid var(--cw-wrap-border);
    border-radius: 12px;
    max-width: 700px;
    margin-left: auto;
    margin-right: auto;
}

/* --- Sample puzzle on landing page --- */
.landing__sample {
    margin-top: 48px;
    padding: 24px;
    background: var(--cw-wrap-bg);
    border: 1px solid var(--cw-wrap-border);
    border-radius: 16px;
    backdrop-filter: blur(6px);
}

.landing__sample-body {
    display: block;
}

.landing__sample-header {
    position: relative;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    min-height: 38px;
    margin-bottom: 12px;
    padding: 0 180px;
}

.landing__sample-title {
    margin: 0;
    font-size: 20px;
    color: #3b82f6;
}

.landing__sample-controls-slot {
    position: absolute;
    top: 0;
    right: 0;
    display: flex;
    justify-content: flex-end;
}

.landing__sample-layout {
    display: flex;
    gap: var(--pane-gap);
}

.landing__sample-grid {
    flex: 0 0 auto;
}

.landing__sample-clues {
    flex: 1 1 auto;
    max-height: 300px;
}

.landing__sample-controls {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 0;
}

.landing__sample-controls button {
    width: auto;
    min-width: 78px;
    min-height: 34px;
    padding: 0 12px;
    white-space: nowrap;
}

@media (max-width: 800px) {
    .landing__sample-header {
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
        padding: 0;
    }

    .landing__sample-controls-slot {
        position: static;
        justify-content: flex-end;
    }

    .landing__sample-controls {
        width: 100%;
    }

    .landing__sample-controls button {
        flex: 1 1 0;
        min-width: 0;
    }

    .landing__sample-layout {
        flex-direction: column;
    }
    .landing__sample-clues {
        max-height: none;
    }
}

.landing__features {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 24px;
    text-align: left;
    margin: 0;
}

.landing__feature {
    padding: 24px;
    border-radius: 16px;
    background: var(--cw-wrap-bg);
    border: 1px solid var(--cw-wrap-border);
    backdrop-filter: blur(6px);
}

.landing__feature-icon {
    font-size: 28px;
    margin-bottom: 12px;
}

.landing__feature-title {
    margin: 0 0 8px;
    font-size: 17px;
    font-weight: 700;
}

.landing__feature-desc {
    margin: 0;
    font-size: 14px;
    color: var(--cw-text-muted);
    line-height: 1.5;
}

/* ========== Auth status banner ========== */
.auth-banner {
    text-align: center;
    padding: 8px 16px;
    font-size: 13px;
    color: var(--cw-text-muted);
}

.auth-banner__user {
    font-weight: 600;
    color: var(--cw-text);
}

@media (max-width: 800px) {
    .generate-form {
        flex-direction: column;
        align-items: stretch;
    }
    .generate-status-row {
        flex-direction: column;
        align-items: stretch;
    }
    .mode-tabs {
        margin-left: 0;
        margin-top: 8px;
    }
    .credit-badge {
        text-align: center;
    }
    .landing {
        padding: 32px 16px 64px;
    }
    .landing__features {
        grid-template-columns: 1fr;
    }

    .landing__type-grid {
        grid-template-columns: 1fr;
    }

    .puzzle-type-switch {
        width: 100%;
        justify-content: stretch;
    }

    .puzzle-type-switch__button {
        flex: 1 1 0;
        min-width: 0;
    }

    .settings-billing__header {
        flex-direction: column;
        align-items: stretch;
    }
}
