:root {
    --game-primary: #6d28d9;
    --game-secondary: #f5c518;
    --qn-ink: #1e1b4b;
    --qn-panel: #1e1b4b;
}

body.qn-page {
    margin: 0;
    min-height: 100vh;
    font-family: "Rockwell", "Rockwell Nova", "Roboto Slab", serif;
    color: #f8fafc;
    background:
        radial-gradient(circle at 12% 8%, rgba(109, 40, 217, 0.28), transparent 42%),
        radial-gradient(circle at 88% 18%, rgba(245, 197, 24, 0.16), transparent 48%),
        linear-gradient(180deg, #0f0a1f 0%, #1e1b4b 55%, #0b0818 100%);
}

body.qn-page.game-menu-active {
    overflow-y: auto;
    overflow-x: hidden;
}

body.qn-page.game-menu-active #game-header {
    display: none !important;
}

.qn-page .game-screen {
    display: none;
    min-height: 100vh;
}

.qn-page .game-screen.active {
    display: block;
}

body.qn-page.with-game-header .qn-shell {
    padding-top: 5.5rem;
}

.qn-shell {
    max-width: min(920px, 96vw);
    margin: 0 auto;
    padding: 1.1rem 0.75rem 2.5rem;
}

.qn-hud {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    max-width: 520px;
    margin: 0 auto 0.85rem;
    padding: 0.55rem 0.7rem;
    background: linear-gradient(180deg, #3b0764, #1e1b4b);
    border: 3px solid #0b0818;
    border-radius: 12px;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08), 0 10px 24px rgba(0, 0, 0, 0.35);
}

.qn-lcd {
    min-width: 4.6rem;
    padding: 0.2rem 0.45rem;
    background: #140414;
    color: #f5c518;
    font-family: "Courier New", ui-monospace, monospace;
    font-size: 1.55rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-align: center;
    border-radius: 6px;
    box-shadow: inset 0 0 0 2px #6d28d9, inset 0 8px 16px rgba(0, 0, 0, 0.45);
}

.qn-lcd span {
    display: block;
    font-size: 0.62rem;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: #c4b5fd;
}

.qn-toolbar {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.45rem;
    margin: 0 auto 0.85rem;
    max-width: 520px;
}

.qn-chip {
    padding: 0.45rem 0.7rem;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.08);
    color: #fde68a;
    font-weight: 700;
}

.qn-tool-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.5rem 0.75rem;
    border-radius: 999px;
    border: 1px solid rgba(245, 197, 24, 0.28);
    background: rgba(15, 10, 31, 0.7);
    color: #f8fafc;
    font-weight: 700;
    cursor: pointer;
}

.qn-tool-btn:hover {
    border-color: #f5c518;
    color: #f5c518;
}

.qn-tool-btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.qn-board-wrap {
    display: flex;
    justify-content: center;
    overflow: auto;
    padding: 0.25rem;
}

.qn-board {
    --qn-n: 6;
    --qn-cell: min(72px, calc((min(92vw, 640px) - 1rem) / var(--qn-n)));
    display: grid;
    grid-template-columns: repeat(var(--qn-n), var(--qn-cell));
    grid-template-rows: repeat(var(--qn-n), var(--qn-cell));
    width: calc(var(--qn-n) * var(--qn-cell));
    border: 4px solid #0b0818;
    border-radius: 10px;
    overflow: hidden;
    background: #0b0818;
    box-shadow: 0 18px 40px rgba(0, 0, 0, 0.4);
}

.qn-cell {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0;
    padding: 0;
    border: 1px solid rgba(15, 10, 31, 0.18);
    background: var(--qn-fill, #e2e8f0);
    cursor: pointer;
    color: #1e1b4b;
}

.qn-cell.region-0 { --qn-fill: #f5c2c7; }
.qn-cell.region-1 { --qn-fill: #fde68a; }
.qn-cell.region-2 { --qn-fill: #a5f3fc; }
.qn-cell.region-3 { --qn-fill: #bbf7d0; }
.qn-cell.region-4 { --qn-fill: #ddd6fe; }
.qn-cell.region-5 { --qn-fill: #fdba74; }
.qn-cell.region-6 { --qn-fill: #fecdd3; }
.qn-cell.region-7 { --qn-fill: #bfdbfe; }
.qn-cell.region-8 { --qn-fill: #d9f99d; }

.qn-cell.edge-n { border-top: 3px solid #0b0818; }
.qn-cell.edge-s { border-bottom: 3px solid #0b0818; }
.qn-cell.edge-w { border-left: 3px solid #0b0818; }
.qn-cell.edge-e { border-right: 3px solid #0b0818; }

.qn-cell .qn-x,
.qn-cell .qn-piece {
    pointer-events: none;
}

.qn-cell .qn-x {
    display: none;
    font-size: calc(var(--qn-cell) * 0.42);
    font-weight: 800;
    color: rgba(30, 27, 75, 0.42);
    line-height: 1;
}

.qn-cell .qn-piece {
    display: none;
    font-size: calc(var(--qn-cell) * 0.48);
    color: #2e1065;
    filter: drop-shadow(0 1px 0 rgba(255, 255, 255, 0.35));
}

.qn-cell.is-marked:not(.has-queen) .qn-x {
    display: block;
}

.qn-cell.has-queen .qn-piece,
.qn-cell.is-given .qn-piece {
    display: inline-block;
}

.qn-cell.is-given {
    cursor: default;
}

.qn-cell.is-given .qn-piece {
    color: #6d28d9;
}

.qn-cell.has-queen:not(.is-given) .qn-piece {
    color: #1e1b4b;
}

.qn-cell.is-error {
    animation: qn-shake 0.32s ease;
    box-shadow: inset 0 0 0 3px #c90c0f;
}

.qn-cell.is-hint {
    box-shadow: inset 0 0 0 3px #f5c518;
}

@keyframes qn-shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-3px); }
    75% { transform: translateX(3px); }
}

.qn-hint {
    text-align: center;
    color: #c4b5fd;
    font-size: 0.92rem;
    margin: 0.85rem 0 0;
}

.qn-settings-panel {
    margin: 0 0 1.1rem;
    padding: 1rem 1.1rem 1.15rem;
    border-radius: 16px;
    background: rgba(15, 10, 31, 0.72);
    border: 1px solid rgba(245, 197, 24, 0.28);
}

.qn-settings-panel__title {
    margin: 0 0 0.75rem;
    color: #f5c518;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    font-size: 0.92rem;
}

.qn-settings-panel__label {
    margin: 0 0 0.45rem;
    color: #e2e8f0;
    font-weight: 600;
}

.qn-settings-panel__buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 0.45rem;
    margin-bottom: 0.85rem;
}

.qn-settings-panel__buttons .difficulty-pill,
#settingsModal .difficulty-pill {
    border: 1px solid rgba(255, 255, 255, 0.14);
    border-radius: 999px;
    padding: 0.5rem 0.85rem;
    background: rgba(255, 255, 255, 0.05);
    color: #f8fafc;
    font-weight: 600;
    cursor: pointer;
}

.qn-settings-panel__buttons .difficulty-pill.is-selected,
#settingsModal .difficulty-pill.is-selected {
    background: #f5c518;
    color: #1e1b4b;
    border-color: #f5c518;
}

.qn-settings-toggle {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    color: #e2e8f0;
    font-weight: 600;
}

.qn-settings-panel__note,
#settingsModal .qn-settings-panel__note {
    margin: 0.75rem 0 0;
    color: #c4b5fd;
    font-size: 0.9rem;
}

.modal {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.72);
    z-index: 12000;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: #fff;
    color: #1a1a1a;
    border-radius: 1rem;
    max-width: 640px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
}

.modal-large {
    max-width: 760px;
}

.modal-header,
.modal-footer {
    padding: 1.1rem 1.4rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
}

.modal-header {
    border-bottom: 2px solid #eee;
}

.modal-header h2 {
    margin: 0;
    color: #6d28d9;
    font-size: 1.35rem;
}

.modal-close {
    background: #fff;
    border: 2px solid #6d28d9;
    color: #6d28d9;
    border-radius: 8px;
    cursor: pointer;
    padding: 0.35rem 0.55rem;
}

.modal-close:hover {
    background: #6d28d9;
    color: #fff;
}

.modal-body {
    padding: 1.2rem 1.4rem;
}

.modal-footer {
    border-top: 2px solid #eee;
    justify-content: flex-end;
}

.help-section {
    margin-bottom: 1.1rem;
}

.help-section h3 {
    color: #6d28d9;
    margin: 0 0 0.4rem;
}

.help-section ul {
    margin: 0.3rem 0 0;
    padding-left: 1.2rem;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.stat-card {
    background: #f8fafc;
    border-radius: 12px;
    padding: 0.85rem;
    text-align: center;
}

.stat-value {
    font-size: 1.6rem;
    color: #6d28d9;
    font-weight: 700;
}

.stat-label {
    color: #64748b;
    font-size: 0.85rem;
}

.difficulty-stats {
    display: grid;
    gap: 0.45rem;
}

.difficulty-stats div {
    display: flex;
    justify-content: space-between;
    padding: 0.45rem 0.55rem;
    background: #f8fafc;
    border-radius: 8px;
}

.result-message {
    font-size: 1.05rem;
    margin: 0 0 1rem;
}

.win-stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.6rem;
    text-align: center;
}

.win-stat strong {
    display: block;
    font-size: 1.35rem;
    color: #6d28d9;
}

.win-stat span {
    color: #64748b;
    font-size: 0.82rem;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    padding: 0.65rem 1.1rem;
    border-radius: 0.55rem;
    border: 2px solid transparent;
    font-weight: 700;
    cursor: pointer;
}

.btn-primary {
    background: #6d28d9;
    color: #fff;
}

.btn-secondary {
    background: #fff;
    color: #6d28d9;
    border-color: #6d28d9;
}

#settingsModal .qn-settings-panel__label,
#settingsModal .qn-settings-toggle {
    color: #1e1b4b;
}

#settingsModal .qn-settings-panel__note {
    color: #6b21a8;
}

#settingsModal .difficulty-pill {
    background: #f5f3ff;
    color: #1e1b4b;
    border-color: #ddd6fe;
}

#settingsModal .difficulty-pill.is-selected {
    background: #6d28d9;
    color: #fff;
    border-color: #6d28d9;
}

@media (max-width: 640px) {
    .qn-lcd {
        min-width: 3.8rem;
        font-size: 1.25rem;
    }

    .qn-tool-btn span {
        display: none;
    }
}
