:root {
    --bg: #f4f7fb;
    --panel: #ffffff;
    --ink: #172033;
    --muted: #667085;
    --line: #d9e1ec;
    --accent: #e11d48;
    --accent-dark: #9f1239;
    --gold: #d99a1b;
    --green: #15803d;
    --board: #263244;
    --shadow: 0 16px 40px rgba(23, 32, 51, 0.12);
}

* {
    box-sizing: border-box;
}

html {
    min-width: 320px;
    background: var(--bg);
}

body {
    margin: 0;
    color: var(--ink);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", Arial, sans-serif;
    line-height: 1.6;
    letter-spacing: 0;
}

a {
    color: inherit;
}

button,
input {
    font: inherit;
}

.site-header {
    height: 60px;
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
    gap: 18px;
    padding: 0 28px;
    background: #172033;
    color: #fff;
    position: sticky;
    top: 0;
    z-index: 80;
}

.brand {
    font-size: 20px;
    font-weight: 900;
    text-decoration: none;
    white-space: nowrap;
}

.desktop-nav {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 6px;
}

.desktop-nav a {
    min-height: 36px;
    display: inline-flex;
    align-items: center;
    padding: 0 12px;
    border-radius: 6px;
    color: rgba(255, 255, 255, 0.84);
    text-decoration: none;
}

.desktop-nav a:hover,
.desktop-nav a:focus-visible {
    color: #fff;
    background: rgba(255, 255, 255, 0.1);
    outline: none;
}

.header-download,
.mobile-menu {
    display: none;
}

main {
    padding: 28px 18px 0;
}

.game-shell {
    width: min(1180px, 100%);
    margin: 0 auto;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
    overflow: hidden;
}

.game-top {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 18px;
    align-items: center;
    padding: 18px;
    background: #fbfcff;
    border-bottom: 1px solid var(--line);
}

.mode-group {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.mode-btn,
.control-bar button,
.result-card button {
    min-height: 40px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #fff;
    color: var(--ink);
    cursor: pointer;
    font-weight: 800;
    transition: border-color 0.18s, background 0.18s, color 0.18s, transform 0.18s;
}

.mode-btn {
    padding: 0 16px;
}

.mode-btn.active,
.control-bar button:first-child,
.result-card button:first-child {
    color: #fff;
    background: var(--accent);
    border-color: var(--accent);
}

.mode-btn:hover,
.mode-btn:focus-visible,
.control-bar button:hover,
.control-bar button:focus-visible,
.result-card button:hover,
.result-card button:focus-visible {
    border-color: var(--accent);
    outline: none;
}

.control-bar button:active,
.mode-btn:active {
    transform: translateY(1px);
}

.score-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(74px, 1fr));
    gap: 8px;
}

.score-grid div {
    min-height: 48px;
    display: grid;
    place-items: center;
    padding: 4px 8px;
    border-radius: 6px;
    background: #101828;
    color: #fff;
}

.score-grid span {
    color: rgba(255, 255, 255, 0.62);
    font-size: 12px;
}

.score-grid strong {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 20px;
    line-height: 1;
    color: #f6c453;
    white-space: nowrap;
}

.client-notice {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto auto;
    align-items: center;
    gap: 12px;
    padding: 12px 18px;
    background: #fff7e6;
    border-bottom: 1px solid #f1d39b;
    color: #68430d;
}

.client-notice.hidden {
    display: none;
}

.client-notice-icon {
    width: 34px;
    height: 34px;
    display: grid;
    place-items: center;
    border-radius: 6px;
    background: #f4d792;
    color: #6b4405;
    font-size: 18px;
    font-weight: 900;
}

.client-notice p {
    margin: 0;
    min-width: 0;
}

.client-notice a {
    min-height: 38px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0 16px;
    border-radius: 6px;
    background: var(--gold);
    color: #fff;
    font-weight: 800;
    text-decoration: none;
    white-space: nowrap;
}

.client-notice-close {
    width: 34px;
    height: 34px;
    border: 0;
    border-radius: 6px;
    background: rgba(104, 67, 13, 0.1);
    color: #68430d;
    cursor: pointer;
    font-size: 20px;
    line-height: 1;
}

.play-area {
    display: grid;
    grid-template-columns: minmax(320px, 1fr) 260px;
    gap: 18px;
    align-items: start;
    padding: 18px;
    background:
        linear-gradient(90deg, rgba(225, 29, 72, 0.055) 1px, transparent 1px),
        linear-gradient(rgba(21, 128, 61, 0.055) 1px, transparent 1px),
        #f2f6f5;
    background-size: 18px 18px;
}

.board-panel,
.side-panel {
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 8px;
}

.board-panel {
    position: relative;
    display: grid;
    gap: 12px;
    justify-items: center;
    padding: 14px;
    overflow: hidden;
}

.board-status {
    width: min(560px, 100%);
    min-height: 44px;
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    align-items: center;
    gap: 10px;
}

.board-status span {
    min-height: 32px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0 10px;
    border-radius: 6px;
    background: #fce7f3;
    color: var(--accent-dark);
    font-size: 13px;
    font-weight: 900;
    white-space: nowrap;
}

.board-status strong {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--ink);
    font-size: 15px;
    white-space: nowrap;
}

.match-board {
    width: min(560px, 100%);
    aspect-ratio: 1;
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    grid-template-rows: repeat(8, 1fr);
    gap: 8px;
    padding: 10px;
    border-radius: 8px;
    background: var(--board);
    touch-action: none;
    user-select: none;
    cursor: grab;
}

.match-board.dragging {
    cursor: grabbing;
}

.gem {
    min-width: 0;
    min-height: 0;
    display: grid;
    place-items: center;
    border: 1px solid rgba(255, 255, 255, 0.34);
    border-radius: 8px;
    color: #fff;
    cursor: pointer;
    font-size: 28px;
    font-weight: 900;
    line-height: 1;
    text-shadow: 0 2px 3px rgba(0, 0, 0, 0.22);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.26), 0 5px 12px rgba(2, 6, 23, 0.2);
    transition: transform 0.12s, opacity 0.12s, box-shadow 0.12s;
}

.gem:hover,
.gem:focus-visible {
    outline: none;
    transform: translateY(-2px);
}

.gem-0 {
    background: #ef4444;
}

.gem-1 {
    background: #f59e0b;
}

.gem-2 {
    background: #16a34a;
}

.gem-3 {
    background: #2563eb;
}

.gem-4 {
    background: #7c3aed;
}

.gem-5 {
    background: #db2777;
}

.gem-6 {
    background: #0891b2;
}

.gem.selected {
    transform: translateY(-3px) scale(1.04);
    box-shadow: 0 0 0 3px #fde047, inset 0 1px 0 rgba(255, 255, 255, 0.28), 0 8px 18px rgba(2, 6, 23, 0.24);
    z-index: 3;
}

.gem.hint {
    animation: hintPulse 0.72s ease-in-out infinite alternate;
    box-shadow: 0 0 0 3px #facc15, inset 0 1px 0 rgba(255, 255, 255, 0.28), 0 8px 18px rgba(2, 6, 23, 0.24);
}

.gem.clearing {
    opacity: 0.18;
    transform: scale(0.55) rotate(7deg);
}

.side-panel {
    display: grid;
    gap: 12px;
    padding: 14px;
}

.control-bar {
    display: grid;
    grid-template-columns: 1fr;
    gap: 10px;
}

.control-bar button {
    width: 100%;
}

.status-card {
    min-height: 74px;
    display: grid;
    align-content: center;
    gap: 4px;
    padding: 12px;
    border-radius: 6px;
    background: #f8fafc;
    border: 1px solid var(--line);
}

.status-card span {
    color: var(--muted);
    font-size: 13px;
    font-weight: 700;
}

.status-card strong {
    overflow-wrap: anywhere;
    font-size: 18px;
    line-height: 1.25;
}

.result-overlay {
    position: absolute;
    inset: 14px;
    display: grid;
    place-items: center;
    padding: 20px;
    border-radius: 8px;
    background: rgba(16, 24, 40, 0.62);
    z-index: 50;
}

.result-overlay[hidden] {
    display: none;
}

.result-card {
    width: min(320px, 100%);
    display: grid;
    gap: 10px;
    padding: 22px;
    border-radius: 8px;
    background: #fff;
    text-align: center;
    box-shadow: var(--shadow);
}

.result-card strong {
    font-size: 24px;
    line-height: 1.2;
}

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

.result-actions {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
}

.content-page {
    width: min(980px, 100%);
    margin: 28px auto 0;
    padding: 0 18px;
}

.content-page article {
    margin-bottom: 18px;
    padding: 28px;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 8px;
}

.content-page h1,
.content-page h2 {
    margin: 0 0 10px;
    line-height: 1.25;
}

.content-page h1 {
    font-size: 32px;
}

.content-page h2 {
    margin-top: 24px;
    font-size: 23px;
}

.content-page p,
.content-page li {
    color: var(--muted);
}

.content-page a {
    color: var(--accent-dark);
    font-weight: 800;
}

.game-card-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
    margin-top: 14px;
}

.game-card {
    min-height: 56px;
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    align-items: center;
    gap: 10px;
    padding: 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #f8fafc;
    color: var(--ink);
    text-decoration: none;
}

.game-card:hover,
.game-card:focus-visible {
    border-color: var(--accent);
    outline: none;
}

.game-card-icon {
    width: 34px;
    height: 34px;
    display: grid;
    place-items: center;
    border-radius: 7px;
    color: #fff;
    font-size: 14px;
    font-weight: 900;
}

.game-card strong {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--ink);
    font-size: 16px;
    line-height: 1.2;
    white-space: nowrap;
}

.game-card-icon.snake {
    background: #15803d;
}

.game-card-icon.mine {
    background: #0f8b8d;
}

.game-card-icon.block {
    background: #172033;
}

.game-card-icon.gomoku {
    background: #111827;
}

.game-card-icon.spider {
    background: #166534;
}

.game-card-icon.tile {
    background: #2563eb;
    font-size: 12px;
}

.game-card-icon.jump {
    background: #d93a2f;
}

.game-card-icon.sudoku {
    background: #2f6f9f;
}

.game-card-icon.box {
    background: #d99a1b;
}

.site-footer {
    margin-top: 34px;
    padding: 22px 18px;
    color: var(--muted);
    text-align: center;
    border-top: 1px solid var(--line);
}

.site-footer p {
    margin: 6px 0;
}

.site-footer a {
    color: var(--accent-dark);
    font-weight: 800;
    text-decoration: none;
}

@keyframes hintPulse {
    from {
        transform: translateY(-2px) scale(1);
    }
    to {
        transform: translateY(-4px) scale(1.06);
    }
}

@media (max-width: 900px) {
    .game-top,
    .play-area {
        grid-template-columns: 1fr;
    }

    .score-grid {
        grid-template-columns: repeat(4, 1fr);
    }

    .side-panel {
        grid-template-columns: minmax(0, 1.2fr) repeat(2, minmax(0, 1fr));
        align-items: stretch;
    }

    .control-bar {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (max-width: 700px) {
    .site-header {
        height: 48px;
        grid-template-columns: minmax(0, 1fr) auto 40px;
        gap: 6px;
        padding: 0 8px;
    }

    .brand {
        font-size: 17px;
    }

    .desktop-nav {
        display: none;
    }

    .header-download {
        min-height: 34px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        padding: 0 10px;
        border-radius: 6px;
        background: #fff7e6;
        color: #68430d;
        border: 1px solid #e5c16b;
        font-size: 13px;
        font-weight: 800;
        line-height: 1;
        text-decoration: none;
        white-space: nowrap;
    }

    .mobile-menu {
        display: block;
        position: relative;
    }

    .mobile-menu summary {
        width: 40px;
        height: 40px;
        display: grid;
        place-items: center;
        gap: 4px;
        padding: 10px;
        border-radius: 6px;
        background: rgba(255, 255, 255, 0.1);
        cursor: pointer;
        list-style: none;
    }

    .mobile-menu summary::-webkit-details-marker {
        display: none;
    }

    .mobile-menu span {
        width: 18px;
        height: 2px;
        display: block;
        border-radius: 2px;
        background: #fff;
    }

    .mobile-menu nav {
        position: fixed;
        top: 48px;
        right: 8px;
        z-index: 90;
        width: min(220px, calc(100vw - 16px));
        display: grid;
        gap: 4px;
        padding: 10px;
        border-radius: 8px;
        background: #172033;
        box-shadow: var(--shadow);
    }

    .mobile-menu:not([open]) nav {
        display: none;
    }

    .mobile-menu nav a {
        min-height: 42px;
        display: flex;
        align-items: center;
        padding: 0 12px;
        border-radius: 6px;
        color: #fff;
        text-decoration: none;
    }

    main {
        padding: 8px 8px 0;
    }

    .game-shell {
        overflow: visible;
    }

    .game-top {
        grid-template-columns: minmax(132px, 0.92fr) minmax(0, 1.08fr);
        align-items: stretch;
        gap: 8px;
        padding: 8px;
    }

    .mode-group {
        display: grid;
        grid-template-columns: repeat(3, 1fr);
        gap: 5px;
    }

    .mode-btn {
        min-height: 36px;
        padding: 0 4px;
        font-size: 13px;
    }

    .score-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 5px;
    }

    .score-grid div {
        min-height: 35px;
        padding: 2px 4px;
    }

    .score-grid span {
        font-size: 10px;
    }

    .score-grid strong {
        font-size: 15px;
    }

    .client-notice {
        display: none;
    }

    .play-area {
        gap: 8px;
        padding: 8px;
    }

    .board-panel {
        gap: 8px;
        padding: 8px;
    }

    .board-status {
        min-height: 34px;
        gap: 6px;
    }

    .board-status span {
        min-height: 28px;
        padding: 0 8px;
        font-size: 12px;
    }

    .board-status strong {
        font-size: 13px;
    }

    .match-board {
        gap: 5px;
        padding: 6px;
    }

    .gem {
        border-radius: 6px;
        font-size: 20px;
    }

    .side-panel {
        position: sticky;
        bottom: 0;
        z-index: 45;
        grid-template-columns: 1fr;
        gap: 6px;
        padding: 6px;
        padding-bottom: calc(6px + env(safe-area-inset-bottom));
        border-color: rgba(255, 255, 255, 0.18);
        background: #263244;
        box-shadow: 0 -8px 20px rgba(2, 6, 23, 0.18);
    }

    .control-bar {
        grid-template-columns: repeat(3, 1fr);
        gap: 6px;
    }

    .control-bar button {
        min-height: 40px;
        font-size: 13px;
    }

    .status-card {
        display: none;
    }

    .result-overlay {
        position: fixed;
        inset: 0;
        padding: 16px;
        border-radius: 0;
        z-index: 100;
    }

    .result-card {
        padding: 18px;
    }

    .content-page {
        margin-top: 14px;
        padding: 0 10px;
    }

    .content-page article {
        padding: 20px;
    }

    .content-page h1 {
        font-size: 26px;
    }

    .game-card-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 8px;
    }

    .game-card {
        min-height: 54px;
        padding: 8px;
    }

    .game-card-icon {
        width: 32px;
        height: 32px;
        font-size: 13px;
    }

    .game-card strong {
        font-size: 15px;
    }

    .site-footer {
        margin-top: 20px;
        padding: 18px 12px;
        font-size: 13px;
    }
}

@media (max-width: 380px) {
    .game-top {
        grid-template-columns: minmax(120px, 0.9fr) minmax(0, 1.1fr);
    }

    .mode-btn {
        min-height: 34px;
        font-size: 12px;
    }

    .score-grid strong {
        font-size: 14px;
    }

    .match-board {
        gap: 4px;
        padding: 5px;
    }

    .gem {
        font-size: 18px;
    }
}
