/* ===== Переменные темы ===== */
:root {
    --accent: #a78bfa;
    --accent-2: #7c3aed;
    --on-accent: #14092b;

    --bg: #0f0b1a;
    --bg-2: #171127;
    --surface: #1d1630;
    --surface-2: #2a2044;
    --line: #362a55;
    --text: #ece8f8;
    --muted: #9b92b8;
    --good: #4ade80;
    --bad: #f87171;
    --glow: rgba(167, 139, 250, 0.2);
    color-scheme: dark;
}

/* Светлая тема: лавандовые тона под фиолетовый акцент, без чисто белого */
html[data-theme="light"] {
    --accent: #7c3aed;
    --accent-2: #6d28d9;
    --on-accent: #ffffff;

    --bg: #e8e2f6;
    --bg-2: #ddd4f1;
    --surface: #d8cdef;
    --surface-2: #c7b8e6;
    --line: #b4a2dc;
    --text: #1f1533;
    --muted: #5b4d7a;
    --good: #15803d;
    --bad: #b91c1c;
    --glow: rgba(124, 58, 237, 0.18);
    color-scheme: light;
}

/* ===== Базовые стили ===== */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html,
body {
    min-height: 100%;
}

body {
    min-height: 100vh;
    min-height: 100dvh;
    font-family: Arial, Helvetica, sans-serif;
    font-size: 16px;
    color: var(--text);
    background: radial-gradient(circle at 50% 0%, var(--bg-2), var(--bg) 60%) fixed;
}

button {
    font: inherit;
    color: inherit;
    background: none;
    border: 0;
    cursor: pointer;
}

a {
    color: inherit;
    text-decoration: none;
}

.hidden {
    display: none !important;
}

.muted {
    color: var(--muted);
}

/* ===== Кнопки ===== */
.btn {
    padding: 10px 20px;
    font-weight: bold;
    color: var(--on-accent);
    background: linear-gradient(90deg, var(--accent), var(--accent-2));
    border-radius: 50px;
    transition: opacity 0.2s;
}

.btn:hover {
    opacity: 0.9;
}

.btn-ghost {
    color: var(--text);
    background: transparent;
    border: 1px solid var(--line);
}

.btn-ghost:hover {
    border-color: var(--accent);
    opacity: 1;
}

.btn-ghost.active {
    color: var(--on-accent);
    background: linear-gradient(90deg, var(--accent), var(--accent-2));
    border-color: transparent;
}

/* ===== Шапка ===== */
.topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 12px clamp(16px, 4vw, 40px);
    background: color-mix(in srgb, var(--bg) 85%, transparent);
    border-bottom: 1px solid var(--line);
    backdrop-filter: blur(8px);
}

.back {
    width: 40px;
    height: 40px;
    flex: none;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--line);
    border-radius: 50%;
    transition: border-color 0.2s, background 0.2s;
}

.back svg {
    width: 26px;
    height: 26px;
    fill: var(--text);
}

.back:hover {
    border-color: var(--accent);
}

.brand {
    font-size: 22px;
    font-weight: bold;
    background: linear-gradient(90deg, var(--accent), var(--accent-2));
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.topbar-tools {
    margin-left: auto;
    display: flex;
    gap: 8px;
}

.tool-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 14px;
    font-size: 14px;
    border: 1px solid var(--line);
    border-radius: 50px;
    transition: border-color 0.2s;
}

.tool-btn:hover {
    border-color: var(--accent);
}

.tool-btn b {
    color: var(--accent);
}

.theme-toggle_icon {
    width: 16px;
    height: 16px;
    flex: none;
    border-radius: 50%;
    background: var(--text);
    box-shadow: inset -5px -3px 0 0 var(--bg);
}

html[data-theme="light"] .theme-toggle_icon {
    background: #f5a623;
    box-shadow: 0 0 0 3px #ffe2b8;
}

/* ===== Основная область ===== */
.main {
    width: min(1100px, 100%);
    margin: 0 auto;
    padding: 28px clamp(16px, 4vw, 40px) 60px;
}

/* ===== Хаб: выбор головоломки ===== */
.hub h1 {
    font-size: clamp(26px, 4vw, 36px);
    margin-bottom: 8px;
}

.lead {
    margin-bottom: 24px;
    color: var(--muted);
}

.hub-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 16px;
}

.hub-card {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
    padding: 20px;
    text-align: left;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 18px;
    transition: transform 0.2s, border-color 0.2s, box-shadow 0.2s;
}

.hub-card:hover {
    border-color: var(--accent);
    box-shadow: 0 0 20px var(--glow);
    transform: translateY(-3px);
}

.hub-card_icon {
    font-size: 40px;
}

.hub-card_title {
    font-size: 20px;
    font-weight: bold;
}

.hub-card_desc {
    flex: 1;
    font-size: 14px;
    color: var(--muted);
}

.hub-card_meta {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding-top: 10px;
    font-size: 13px;
    color: var(--muted);
    border-top: 1px solid var(--line);
}

.hub-card_meta b {
    color: var(--text);
}

/* ===== Игровой экран ===== */
.game-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 14px;
    margin-bottom: 16px;
}

.game-bar h2 {
    font-size: 26px;
}

.game-stats {
    margin-left: auto;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.chip {
    padding: 6px 12px;
    font-size: 14px;
    color: var(--muted);
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 50px;
}

.chip b {
    margin-left: 4px;
    color: var(--text);
}

.game-controls {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
}

.game-actions {
    display: flex;
    gap: 8px;
}

.game-controls #restart {
    margin-left: auto;
}

.segmented {
    display: flex;
    padding: 4px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 50px;
}

.segmented-item {
    padding: 7px 16px;
    font-size: 14px;
    color: var(--muted);
    border-radius: 50px;
    transition: color 0.2s, background 0.2s;
}

.segmented-item:hover {
    color: var(--text);
}

.segmented-item.active {
    color: var(--on-accent);
    background: linear-gradient(90deg, var(--accent), var(--accent-2));
}

.game-hint {
    margin-bottom: 18px;
    font-size: 14px;
    color: var(--muted);
}

/* Доска: ширина ограничена, шрифт масштабируется по ширине доски (container queries) */
.board {
    width: min(var(--board-w, 520px), 100%);
    margin: 0 auto;
    container-type: inline-size;
    user-select: none;
    -webkit-user-select: none;
}

/* ===== Пятнашки ===== */
.board_fifteen {
    position: relative;
    aspect-ratio: 1;
    padding: 6px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 18px;
}

.board_fifteen .tile {
    position: absolute;
    top: 6px;
    left: 6px;
    width: calc((100% - 12px) / var(--n));
    height: calc((100% - 12px) / var(--n));
    font-size: calc(36cqw / var(--n));
    font-weight: bold;
    color: var(--text);
    background: var(--surface-2);
    background-clip: padding-box;
    border: 4px solid transparent;
    border-radius: 14px;
    transition: transform 0.15s ease, background 0.2s;
}

.board_fifteen .tile:hover {
    background: color-mix(in srgb, var(--surface-2) 70%, var(--accent));
    background-clip: padding-box;
}

.board_fifteen .tile.in-place {
    color: var(--on-accent);
    background: linear-gradient(135deg, var(--accent), var(--accent-2));
    background-clip: padding-box;
}

/* ===== Огоньки ===== */
.board_lights {
    display: grid;
    grid-template-columns: repeat(var(--n), 1fr);
    gap: 8px;
    aspect-ratio: 1;
    padding: 10px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 18px;
}

.light {
    background: var(--surface-2);
    border-radius: 12px;
    transition: background 0.2s, box-shadow 0.2s, transform 0.1s;
}

.light:active {
    transform: scale(0.95);
}

.light.on {
    background: radial-gradient(circle, #fff6c8, #ffd54f 45%, #ffb300);
    box-shadow: 0 0 18px rgba(255, 196, 0, 0.6);
}

/* ===== Мемори ===== */
.board_memory {
    --board-w: 620px;
    display: grid;
    grid-template-columns: repeat(var(--cols), 1fr);
    gap: 10px;
}

.card {
    aspect-ratio: 3 / 4;
    perspective: 600px;
}

.card-inner {
    position: relative;
    display: block;
    width: 100%;
    height: 100%;
    transition: transform 0.35s;
    transform-style: preserve-3d;
}

.card.open .card-inner {
    transform: rotateY(180deg);
}

.card-back,
.card-front {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 12px;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
}

.card-back {
    background:
        repeating-linear-gradient(45deg, transparent 0 8px, rgba(255, 255, 255, 0.08) 8px 16px),
        linear-gradient(135deg, var(--accent), var(--accent-2));
}

.card-front {
    font-size: calc(48cqw / var(--cols));
    background: var(--surface-2);
    border: 2px solid var(--line);
    transform: rotateY(180deg);
}

.card.done .card-front {
    border-color: var(--good);
    box-shadow: 0 0 12px color-mix(in srgb, var(--good) 40%, transparent);
}

/* ===== Сапёр ===== */
.board_mines {
    --board-w: 640px;
    display: grid;
    grid-template-columns: repeat(var(--cols), 1fr);
    gap: 2px;
    padding: 6px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 14px;
}

.mine-cell {
    aspect-ratio: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: calc(55cqw / var(--cols));
    font-weight: bold;
    background: var(--surface-2);
    border-radius: 4px;
    transition: background 0.15s;
}

.mine-cell:hover {
    background: color-mix(in srgb, var(--surface-2) 75%, var(--accent));
}

.mine-cell.open {
    background: var(--bg);
    cursor: default;
}

.mine-cell.boom {
    background: var(--bad);
}

.mine-cell.wrong-flag {
    background: color-mix(in srgb, var(--bad) 40%, var(--surface-2));
}

/* Цвета цифр как в классическом сапёре */
.mine-cell[data-n="1"] { color: #60a5fa; }
.mine-cell[data-n="2"] { color: #4ade80; }
.mine-cell[data-n="3"] { color: #f87171; }
.mine-cell[data-n="4"] { color: #c084fc; }
.mine-cell[data-n="5"] { color: #fb923c; }
.mine-cell[data-n="6"] { color: #2dd4bf; }
.mine-cell[data-n="7"] { color: var(--text); }
.mine-cell[data-n="8"] { color: var(--muted); }

html[data-theme="light"] .mine-cell[data-n="1"] { color: #1d4ed8; }
html[data-theme="light"] .mine-cell[data-n="2"] { color: #15803d; }
html[data-theme="light"] .mine-cell[data-n="3"] { color: #b91c1c; }
html[data-theme="light"] .mine-cell[data-n="4"] { color: #6d28d9; }
html[data-theme="light"] .mine-cell[data-n="5"] { color: #c2410c; }
html[data-theme="light"] .mine-cell[data-n="6"] { color: #0f766e; }

/* ===== Судоку ===== */
.board_sudoku {
    --board-w: 500px;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.sudoku-grid {
    display: grid;
    grid-template-columns: repeat(9, 1fr);
    overflow: hidden;
    background: var(--surface);
    border: 2px solid var(--accent);
    border-radius: 12px;
}

.sudoku-cell {
    aspect-ratio: 1;
    font-size: 5.5cqw;
    color: var(--accent);
    border-right: 1px solid var(--line);
    border-bottom: 1px solid var(--line);
    transition: background 0.1s;
}

.sudoku-cell:nth-child(9n) {
    border-right: 0;
}

.sudoku-cell:nth-child(n + 73) {
    border-bottom: 0;
}

.sudoku-cell.edge-right {
    border-right: 2px solid var(--accent);
}

.sudoku-cell.edge-bottom {
    border-bottom: 2px solid var(--accent);
}

.sudoku-cell.given {
    font-weight: bold;
    color: var(--text);
}

.sudoku-cell.peer {
    background: color-mix(in srgb, var(--surface) 80%, var(--accent));
}

.sudoku-cell.same {
    background: color-mix(in srgb, var(--surface) 60%, var(--accent));
}

.sudoku-cell.selected {
    background: color-mix(in srgb, var(--surface) 40%, var(--accent));
}

.sudoku-cell.wrong {
    color: var(--bad);
}

.sudoku-pad {
    display: grid;
    grid-template-columns: repeat(10, 1fr);
    gap: 6px;
}

.pad-btn {
    aspect-ratio: 1;
    font-size: 5cqw;
    font-weight: bold;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 10px;
    transition: border-color 0.2s, opacity 0.2s;
}

.pad-btn:hover:not(:disabled) {
    border-color: var(--accent);
}

.pad-btn:disabled {
    opacity: 0.3;
    cursor: default;
}

.pad-btn_erase {
    color: var(--muted);
}

/* ===== Окна ===== */
.modal {
    position: fixed;
    inset: 0;
    z-index: 40;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    background: color-mix(in srgb, var(--bg) 70%, transparent);
    backdrop-filter: blur(4px);
}

.modal-box {
    width: min(380px, 100%);
    max-height: calc(100dvh - 32px);
    overflow-y: auto;
    padding: 28px;
    text-align: center;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 20px;
    box-shadow: 0 0 30px var(--glow);
    animation: pop 0.25s ease-out;
}

.modal-box_wide {
    width: min(760px, 100%);
    text-align: left;
}

@keyframes pop {
    from {
        opacity: 0;
        transform: scale(0.95);
    }
    to {
        opacity: 1;
        transform: none;
    }
}

.modal-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 16px;
}

.icon-btn {
    width: 36px;
    height: 36px;
    flex: none;
    font-size: 24px;
    line-height: 1;
    color: var(--muted);
    border: 1px solid var(--line);
    border-radius: 50%;
}

.icon-btn:hover {
    color: var(--text);
    border-color: var(--accent);
}

.modal-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 10px;
    margin-top: 20px;
}

.result-icon {
    font-size: 54px;
}

.result-badge {
    display: inline-block;
    margin-top: 8px;
    padding: 4px 12px;
    font-size: 13px;
    font-weight: bold;
    color: var(--on-accent);
    background: linear-gradient(90deg, var(--accent), var(--accent-2));
    border-radius: 50px;
}

.result-stats {
    display: grid;
    gap: 8px;
    margin-top: 16px;
}

.result-stats div {
    display: flex;
    justify-content: space-between;
    padding: 8px 12px;
    background: var(--surface-2);
    border-radius: 10px;
}

.result-stats span {
    color: var(--muted);
}

/* ===== Достижения ===== */
.ach-list {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
}

.ach-card {
    display: flex;
    gap: 12px;
    padding: 12px;
    background: var(--surface-2);
    border: 1px solid transparent;
    border-radius: 14px;
    opacity: 0.75;
}

.ach-card.unlocked {
    opacity: 1;
    border-color: var(--accent);
    box-shadow: 0 0 12px var(--glow);
}

.ach-icon {
    flex: none;
    font-size: 28px;
    filter: grayscale(1);
}

.ach-card.unlocked .ach-icon {
    filter: none;
}

.ach-info {
    flex: 1;
    min-width: 0;
}

.ach-title {
    font-weight: bold;
}

.ach-desc {
    margin: 2px 0 6px;
    font-size: 13px;
    color: var(--muted);
}

.ach-done {
    font-size: 12px;
    font-weight: bold;
    color: var(--good);
}

.ach-progress {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    color: var(--muted);
}

.ach-bar {
    flex: 1;
    height: 6px;
    overflow: hidden;
    background: var(--bg);
    border-radius: 4px;
}

.ach-bar i {
    display: block;
    height: 100%;
    background: linear-gradient(90deg, var(--accent), var(--accent-2));
}

/* ===== Уведомления ===== */
.toasts {
    position: fixed;
    top: 76px;
    left: 50%;
    z-index: 60;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    transform: translateX(-50%);
    pointer-events: none;
}

.toast {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 18px;
    background: var(--surface);
    border: 1px solid var(--accent);
    border-radius: 14px;
    box-shadow: 0 0 18px var(--glow);
    animation: toast-in 0.35s ease-out;
    transition: opacity 0.5s, transform 0.5s;
}

.toast.out {
    opacity: 0;
    transform: translateY(-10px);
}

.toast-icon {
    font-size: 28px;
}

.toast-text b {
    display: block;
    font-size: 11px;
    letter-spacing: 1px;
    text-transform: uppercase;
    color: var(--accent);
}

.toast-text span {
    font-size: 16px;
    font-weight: bold;
}

@keyframes toast-in {
    from {
        opacity: 0;
        transform: translateY(-14px);
    }
    to {
        opacity: 1;
        transform: none;
    }
}

/* ===== Адаптивность ===== */
@media (max-width: 720px) {
    .tool-btn_text {
        display: none;
    }

    .brand {
        font-size: 19px;
    }

    .game-stats {
        width: 100%;
        margin-left: 0;
    }

    .game-controls #restart {
        margin-left: 0;
    }

    .ach-list {
        grid-template-columns: 1fr;
    }

    .board_mines {
        gap: 1px;
        padding: 4px;
    }
}

@media (max-width: 420px) {
    .segmented-item {
        padding: 6px 10px;
        font-size: 13px;
    }

    .board_lights {
        gap: 5px;
        padding: 6px;
    }

    .board_memory {
        gap: 6px;
    }
}
