/* Voxel Game UI 样式。
   视觉方向：羊皮纸底色、柔和卡片、钴蓝强调色、温暖的地中海光感。
   Logo 使用独立 SVG，其余界面形状仍主要由 CSS 绘制。 */

:root {
    --cream: #f4ede0;
    --cream-2: #ede4d2;
    --paper: #fbf6ec;
    --ink: #2b2a26;
    --ink-soft: #51504a;
    --muted: #8a8678;
    --line: #d9d0bd;
    --shadow: 0 8px 24px rgba(60, 50, 30, 0.10), 0 2px 6px rgba(60, 50, 30, 0.06);
    --shadow-lg: 0 18px 48px rgba(60, 50, 30, 0.16), 0 4px 12px rgba(60, 50, 30, 0.08);
    --cobalt: #1b5ba8;
    --cobalt-2: #2e6fbc;
    --cobalt-light: #d6e6f6;
    --terracotta: #c4622e;
    --leaf: #3d7355;
    --bougainvillea: #d85b8e;
    --sand: #e8d4a8;
    --water: #6ec8e0;
    --radius: 14px;
    --radius-sm: 10px;
    --radius-lg: 22px;
    --edge-gap: 16px;
    --left-rail-width: 72px;
    /* Title card height (roughly): 12px padding + 44px logo + 12px padding ≈ 68px.
       Toolbar anchors directly under this with a single edge-gap so the title
       and toolbar read as one connected left rail rather than two floating cards. */
    --title-card-height: 68px;
}

* { box-sizing: border-box; }

html {
    margin: 0;
    padding: 0;
    min-height: 100%;
    width: 100%;
    scroll-behavior: smooth;
}

body {
    margin: 0;
    padding: 0;
    min-height: 100%;
    width: 100%;
    overflow-x: hidden;
    font-family: 'Inter', 'SF Pro Text', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
    color: var(--ink);
    background: linear-gradient(180deg, #f6efe1 0%, #ebe1cc 100%);
    -webkit-tap-highlight-color: transparent;
}

body.game-page {
    overscroll-behavior-y: contain;
}

#game-shell {
    position: relative;
    height: 100vh;
    height: 100dvh;
    min-height: 620px;
    overflow: hidden;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}

#app {
    position: absolute;
    inset: 0;
    overflow: hidden;
}
#app.hidden { display: none; }

#game-canvas {
    position: absolute;
    inset: 0;
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    display: block;
    background:
        radial-gradient(ellipse at 50% 30%, #fbf6ec 0%, #f0e7d2 60%, #e3d6ba 100%);
    cursor: crosshair;
    /* Stop the browser from interpreting touch gestures (scroll, pinch
       zoom, double-tap zoom, swipe-back nav). The InputManager handles
       all of them in JS now. */
    touch-action: none;
}

/* The touch-controls cheatsheet variant is a no-op on mouse devices —
   a media query below swaps it in on coarse-pointer devices. */
.ins-grid--touch { display: none; }

/* ── Loading screen ─────────────────────────────────────────────── */

#loading-screen {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    background: linear-gradient(180deg, #f6efe1, #e8dcc1);
    z-index: 999;
}
#loading-screen.hidden { display: none; }

.loading-card {
    background: var(--paper);
    border-radius: var(--radius-lg);
    padding: 36px 48px;
    box-shadow: var(--shadow-lg);
    text-align: center;
    width: 360px;
}
.loading-logo {
    width: 72px;
    height: 72px;
    margin: 0 auto 12px;
    background: url('/assets/logo.svg') center / contain no-repeat;
    border-radius: 18px;
    filter: drop-shadow(0 8px 14px rgba(60, 50, 30, 0.14));
}
.loading-logo::after {
    content: none;
}
.loading-title { font-size: 22px; font-weight: 700; letter-spacing: -0.01em; }
.loading-sub   { color: var(--muted); margin-top: 4px; font-size: 13px; }

.loading-bar {
    margin-top: 20px;
    height: 6px;
    width: 100%;
    background: var(--cream-2);
    border-radius: 999px;
    overflow: hidden;
}
.loading-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--cobalt), var(--cobalt-2));
    transition: width 0.18s ease;
}
.loading-status {
    margin-top: 10px;
    font-size: 12px;
    color: var(--muted);
    font-style: italic;
}

/* ── Title card ────────────────────────────────────────────────── */

#title-card {
    position: absolute;
    top: 16px;
    left: 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 18px 12px 12px;
    background: var(--paper);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    z-index: 10;
    user-select: none;
}
.title-logo {
    width: 44px;
    height: 44px;
    flex: 0 0 auto;
    border-radius: 12px;
    background: url('/assets/logo.svg') center / contain no-repeat;
    filter: drop-shadow(0 4px 8px rgba(60, 50, 30, 0.12));
}
.title-logo::before {
    content: none;
}
.title-logo::after {
    content: none;
}
.title-text h1 {
    margin: 0;
    font-size: 20px;
    font-weight: 700;
    letter-spacing: -0.01em;
    color: var(--cobalt);
}
.title-text p {
    margin: 2px 0 0;
    font-size: 12px;
    color: var(--muted);
}

/* ── First-screen guide navigation ────────────────────────────── */

.game-guide-nav {
    position: absolute;
    top: 16px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 25;
    display: flex;
    align-items: center;
    gap: 4px;
    max-width: min(620px, calc(100vw - 440px));
    padding: 6px;
    overflow-x: auto;
    scrollbar-width: none;
    background: rgba(251, 246, 236, 0.94);
    border: 1px solid rgba(43, 42, 38, 0.10);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow);
    backdrop-filter: blur(8px);
}
.game-guide-nav::-webkit-scrollbar { display: none; }
.game-guide-nav a {
    flex: 0 0 auto;
    padding: 8px 10px;
    border-radius: 6px;
    color: var(--ink-soft);
    font-size: 12px;
    font-weight: 800;
    line-height: 1;
    text-decoration: none;
    white-space: nowrap;
}
.game-guide-nav a:hover {
    color: var(--cobalt);
    background: rgba(214, 230, 246, 0.65);
}

/* ── Toolbar ───────────────────────────────────────────────────── */

#toolbar {
    position: absolute;
    /* Anchored under the title card to form a single left rail.
       Vertically centering this used to leave it floating in the dead
       middle of the canvas, disconnected from the title above and the
       help below. Top-anchoring fixes the imbalance. */
    top: calc(var(--edge-gap) + var(--title-card-height) + 12px);
    left: var(--edge-gap);
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 10px 8px;
    background: var(--paper);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    z-index: 10;
    max-height: calc(100vh - var(--edge-gap) - var(--title-card-height) - 24px);
    overflow-y: auto;
    scrollbar-width: none;
}
#toolbar::-webkit-scrollbar { display: none; }
.tool {
    width: 60px;
    padding: 10px 6px 8px;
    border: 0;
    background: transparent;
    border-radius: var(--radius-sm);
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    color: var(--ink-soft);
    transition: background 0.15s ease, color 0.15s ease, transform 0.05s ease;
    font: inherit;
}
.tool:hover { background: var(--cream-2); }
.tool:active { transform: scale(0.97); }
.tool.active {
    background: var(--cobalt-light);
    color: var(--cobalt);
}
.tool .ti {
    /* Icons are drawn on a 44×44 logical canvas. We display them at 36px
       (was 22px) so the glyph reads at a glance, sized to roughly fill
       the toolbar button without crowding the label below. */
    width: 36px;
    height: 36px;
    display: block;
}
.tool span.label {
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.01em;
}

/* ── Palette ──────────────────────────────────────────────────── */

#palette {
    position: absolute;
    right: 12px;
    top: 12px;
    bottom: 92px;
    width: 168px;
    background: var(--paper);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow);
    z-index: 10;
    padding: 6px 6px 6px;
    display: flex;
    flex-direction: column;
    min-height: 200px;
}

#palette-tabs {
    display: flex;
    gap: 2px;
    padding: 0 2px 4px;
    border-bottom: 1px solid var(--line);
    margin-bottom: 6px;
    overflow-x: auto;
    scrollbar-width: none;
    flex-shrink: 0;
}
#palette-tabs::-webkit-scrollbar { display: none; }
.tab {
    border: 0;
    background: transparent;
    padding: 4px 6px;
    border-radius: 6px 6px 0 0;
    font: inherit;
    font-size: 9.5px;
    font-weight: 700;
    letter-spacing: 0.04em;
    color: #5d584d;
    cursor: pointer;
    text-transform: uppercase;
    white-space: nowrap;
    flex-shrink: 0;
}
.tab:hover { color: var(--ink); background: var(--cream-2); }
.tab:focus-visible {
    outline: 2px solid var(--cobalt);
    outline-offset: 2px;
}
.tab[aria-busy="true"] { color: #435f7c; }
.tab.active {
    color: var(--cobalt);
    border-bottom: 2px solid var(--cobalt);
    margin-bottom: -1px;
}

#palette-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4px;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 2px 2px 4px;
    scroll-behavior: smooth;
    scrollbar-width: thin;
    flex: 1 1 auto;
    align-content: start;
}
#palette-grid::-webkit-scrollbar { width: 4px; }
#palette-grid::-webkit-scrollbar-thumb { background: var(--line); border-radius: 2px; }

.swatch {
    background: var(--cream);
    border-radius: 8px;
    padding: 4px 3px 3px;
    border: 2px solid transparent;
    cursor: pointer;
    text-align: center;
    user-select: none;
    transition: transform 0.05s ease, border-color 0.15s ease, background 0.15s ease;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
}
.swatch:hover { background: #f6ecd5; transform: translateY(-1px); }
.swatch:focus-visible {
    outline: 2px solid var(--cobalt);
    outline-offset: 2px;
}
.swatch:disabled {
    cursor: progress;
    opacity: 0.72;
    transform: none;
}
.swatch:disabled:hover {
    background: var(--cream);
    transform: none;
}
.swatch.selected {
    border-color: var(--cobalt);
    background: var(--cobalt-light);
}
.swatch canvas, .swatch img, .swatch-placeholder {
    width: 38px;
    height: 38px;
    pointer-events: none;
}
.swatch canvas, .swatch img {
    image-rendering: pixelated;
    object-fit: contain;
}
.swatch-placeholder {
    display: grid;
    place-items: center;
    border-radius: 6px;
    background: rgba(43, 42, 38, 0.08);
    color: #5d584d;
    font-size: 14px;
    font-weight: 800;
}
.swatch .name {
    font-size: 9px;
    font-weight: 600;
    color: var(--ink-soft);
    line-height: 1.1;
    height: 20px;
    display: flex;
    align-items: center;
    text-align: center;
    overflow: hidden;
}

/* ── HUD (right side) ─────────────────────────────────────────── */

#hud {
    position: absolute;
    right: 12px;
    bottom: 12px;
    width: 168px;
    display: flex;
    flex-direction: row;
    align-items: center;
    flex-wrap: wrap;
    gap: 6px 8px;
    background: var(--paper);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow);
    padding: 6px 8px;
    z-index: 10;
    font-size: 11px;
}
.hud-row { display: flex; align-items: center; gap: 5px; }
.hud-clock {
    display: flex;
    align-items: center;
    gap: 5px;
    font-weight: 700;
    font-size: 11px;
    color: var(--ink);
}
.timer-icon {
    width: 12px; height: 12px;
    border-radius: 50%;
    border: 2px solid var(--cobalt);
    position: relative;
}
.timer-icon::before {
    content: '';
    position: absolute;
    left: 50%;
    top: -5px;
    width: 6px;
    height: 3px;
    border-radius: 2px;
    background: var(--cobalt);
    transform: translateX(-50%);
}
.timer-icon::after {
    content: '';
    position: absolute;
    left: 5px;
    top: 2px;
    width: 2px;
    height: 5px;
    border-radius: 2px;
    background: var(--cobalt);
    transform-origin: 1px 4px;
    transform: rotate(-35deg);
}

.hud-toggles {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    gap: 4px 8px;
    width: 100%;
    margin-top: 4px;
    padding-top: 5px;
    border-top: 1px solid var(--line);
}
.toggle {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 10px;
    color: var(--ink-soft);
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
}
.toggle input { display: none; }
.toggle .switch {
    width: 22px;
    height: 12px;
    background: #d8d2c4;
    border-radius: 999px;
    position: relative;
    transition: background 0.15s ease;
    flex-shrink: 0;
}
.toggle .switch::after {
    content: '';
    position: absolute;
    width: 8px; height: 8px;
    border-radius: 50%;
    background: #fff;
    top: 2px; left: 2px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.2);
    transition: transform 0.15s ease;
}
.toggle input:checked + .switch { background: #6ec07a; }
.toggle input:checked + .switch::after { transform: translateX(10px); }

.hud-layers {
    display: none;
}

/* ── Instructions panel ────────────────────────────────────────── */

/* The controls help is a collapsible disclosure (native <details>):
   - Closed: a small "?" badge in the bottom-left, easy to ignore.
   - Open: the full keyboard cheatsheet expands above the badge.
   Defaulting to closed reclaims a big chunk of bottom-left canvas
   space and removes the visual competition with the right-side palette. */
#instructions {
    position: absolute;
    left: var(--edge-gap);
    bottom: var(--edge-gap);
    z-index: 30;
    background: rgba(251, 246, 236, 0.94);
    backdrop-filter: blur(8px);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow);
    color: var(--ink-soft);
    font-size: 11px;
    overflow: hidden;
    max-width: 280px;
    transition: box-shadow 0.18s ease;
}
#instructions[open] {
    box-shadow: var(--shadow-lg);
}

.ins-summary {
    list-style: none;
    cursor: pointer;
    user-select: none;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px 8px 8px;
    color: var(--cobalt);
    font-weight: 700;
    font-size: 12px;
    letter-spacing: 0.02em;
    transition: background 0.15s ease;
}
.ins-summary:hover { background: rgba(214, 230, 246, 0.45); }
.ins-summary::-webkit-details-marker { display: none; }
.ins-summary::marker { display: none; content: ''; }

.ins-badge {
    width: 22px;
    height: 22px;
    border-radius: 7px;
    background: var(--cobalt);
    color: var(--paper);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: 13px;
    line-height: 1;
    flex-shrink: 0;
    box-shadow: inset 0 -2px 0 rgba(0,0,0,0.10);
}
.ins-summary-label { color: var(--cobalt); }
.ins-summary-hint {
    margin-left: 4px;
    font-size: 10px;
    font-weight: 500;
    color: var(--muted);
    letter-spacing: 0;
    text-transform: none;
}
#instructions[open] .ins-summary-hint { display: none; }
#instructions[open] .ins-summary {
    border-bottom: 1px solid var(--line);
}

.ins-grid {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 4px 10px;
    align-items: center;
    line-height: 1.2;
    padding: 9px 12px 11px;
}
.key {
    min-width: 60px;
    padding: 2px 6px;
    border: 1px solid rgba(27, 91, 168, 0.18);
    border-radius: 5px;
    background: rgba(214, 230, 246, 0.65);
    color: var(--cobalt);
    font-weight: 800;
    font-size: 9.5px;
    text-align: center;
    white-space: nowrap;
}

/* ── Toast ────────────────────────────────────────────────────── */

#toast {
    position: absolute;
    left: 50%;
    top: 16px;
    transform: translate(-50%, -20px);
    padding: 8px 16px;
    background: var(--ink);
    color: var(--paper);
    border-radius: 999px;
    font-size: 13px;
    font-weight: 500;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease, transform 0.2s ease;
    z-index: 100;
}
#toast.show {
    opacity: 1;
    transform: translate(-50%, 0);
}

/* ── Share panel ──────────────────────────────────────────────── */

.share-panel {
    position: absolute;
    inset: 0;
    z-index: 90;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    background: rgba(23, 33, 38, 0.42);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.18s ease;
}
.share-panel.show {
    opacity: 1;
    pointer-events: auto;
}
.share-dialog {
    position: relative;
    width: min(560px, calc(100vw - 32px));
    background: var(--paper);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-lg);
    padding: 12px;
    color: var(--ink);
}
.share-close {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 32px;
    height: 32px;
    border: 0;
    border-radius: 50%;
    background: rgba(250, 250, 245, 0.86);
    color: var(--ink);
    cursor: pointer;
    font: inherit;
    font-weight: 800;
    line-height: 1;
}
.share-preview {
    width: 100%;
    aspect-ratio: 16 / 9;
    display: block;
    object-fit: cover;
    border-radius: 6px;
    background: var(--cream);
}
.share-title {
    margin: 12px 0 4px;
    font-size: 18px;
    line-height: 1.2;
}
.share-text {
    margin: 0;
    color: var(--ink-soft);
    font-size: 13px;
    line-height: 1.45;
}
.share-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    margin-top: 12px;
}
.share-action {
    min-height: 40px;
    border: 1px solid rgba(27, 91, 168, 0.18);
    border-radius: var(--radius-sm);
    background: var(--cream);
    color: var(--cobalt);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    text-decoration: none;
    font: inherit;
    font-size: 12px;
    font-weight: 800;
}
.share-action:hover { background: var(--cobalt-light); }

/* ── Responsive: tablet (≤900px) ──────────────────────────────── */

@media (max-width: 900px) {
    .game-guide-nav {
        left: 240px;
        right: 16px;
        transform: none;
        justify-content: flex-start;
        max-width: none;
    }
    #palette {
        width: calc(100vw - 32px);
        right: 16px;
        top: auto;
        bottom: calc(16px + env(safe-area-inset-bottom));
        height: 180px;
    }
    #palette-grid {
        grid-template-columns: repeat(auto-fill, minmax(58px, 1fr));
    }
    /* HUD is duplicate info on small screens — palette dominates the
       bottom edge already. The compact controls badge stays so the
       cheatsheet is still discoverable on touch / portrait layouts;
       it lifts up to clear the bottom palette. */
    #hud { display: none; }
    #instructions {
        bottom: calc(180px + 24px + env(safe-area-inset-bottom));
    }
    /* Open state on narrow screens: cap the height so the cheatsheet
       can scroll instead of pushing offscreen. */
    #instructions[open] .ins-grid {
        max-height: 50vh;
        overflow-y: auto;
    }
}

/* ── Responsive: phone portrait (≤640px) ──────────────────────── */

/* Below 640px we're almost certainly on a phone in portrait. The
   redesign here optimises for the realities of one-thumb operation
   on a small screen:
     • The title card collapses to logo + short name to reclaim space.
     • The toolbar shrinks to icon-only and tucks against the safe-area
       inset on the left.
     • The palette becomes a full-width bottom sheet with bigger swatches.
     • The controls badge uses a 44px touch target and floats above the
       palette out of thumb-reach so it isn't tapped accidentally. */

@media (max-width: 640px) {
    :root {
        --edge-gap: 10px;
        --title-card-height: 52px;
    }

    /* Compact title card: logo + just the headline, subtitle hidden
       (it's prose, not a tool). Anchor with safe-area inset so the
       iPhone notch doesn't sit on top of the title text. */
    #title-card {
        top: calc(10px + env(safe-area-inset-top));
        left: calc(10px + env(safe-area-inset-left));
        padding: 8px 12px 8px 8px;
        gap: 8px;
        border-radius: var(--radius-sm);
    }
    .title-logo {
        width: 36px;
        height: 36px;
        border-radius: 8px;
    }
    .title-text h1 { font-size: 15px; line-height: 1.1; }
    .title-text p  { display: none; }

    .game-guide-nav {
        top: calc(10px + env(safe-area-inset-top) + var(--title-card-height) + 8px);
        left: calc(68px + env(safe-area-inset-left));
        right: calc(8px + env(safe-area-inset-right));
        padding: 5px;
    }
    .game-guide-nav a {
        padding: 7px 8px;
        font-size: 11px;
    }

    /* Toolbar: drop the labels (icons are already self-evident at this
       size) and tighten everything so it doesn't crowd the canvas.
       Each tool is still ≥44×44 touch target — Apple/Material guideline
       minimum — and the icon now visually fills the button instead of
       hiding in the middle of it. */
    #toolbar {
        top: calc(10px + env(safe-area-inset-top) + var(--title-card-height) + 8px);
        left: calc(8px + env(safe-area-inset-left));
        padding: 6px 5px;
        gap: 4px;
        border-radius: var(--radius-sm);
        max-height: calc(100vh - var(--title-card-height) - 232px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
    }
    .tool {
        width: 50px;
        padding: 7px 4px;
        gap: 2px;
    }
    .tool .ti { width: 32px; height: 32px; }
    .tool span.label { display: none; }

    /* Palette: full-width bottom sheet, taller, larger swatches sized
       for fingertips. Sits above the iOS home indicator. */
    #palette {
        left: calc(8px + env(safe-area-inset-left));
        right: calc(8px + env(safe-area-inset-right));
        width: auto;
        bottom: calc(8px + env(safe-area-inset-bottom));
        height: 200px;
        padding: 4px 6px 6px;
    }
    #palette-tabs {
        gap: 4px;
        padding: 2px 2px 4px;
    }
    .tab {
        font-size: 11px;
        padding: 6px 10px;
        min-height: 32px;
    }
    #palette-grid {
        grid-template-columns: repeat(auto-fill, minmax(72px, 1fr));
        gap: 6px;
    }
    .swatch { padding: 6px 4px 4px; min-height: 78px; }
    .swatch canvas, .swatch img, .swatch-placeholder { width: 44px; height: 44px; }
    .swatch .name { font-size: 10px; height: 22px; }

    /* Controls badge: bigger target, lifted above the palette sheet,
       and with the open panel scrollable so a long cheatsheet doesn't
       spill off the top of the screen. */
    #instructions {
        left: calc(8px + env(safe-area-inset-left));
        bottom: calc(200px + 16px + env(safe-area-inset-bottom));
        max-width: calc(100vw - 16px - env(safe-area-inset-left) - env(safe-area-inset-right));
    }
    .ins-summary {
        padding: 10px 14px 10px 10px;
        min-height: 44px;
    }
    .ins-badge { width: 26px; height: 26px; font-size: 14px; }
    .ins-summary-hint { display: none; }
    #instructions[open] .ins-grid {
        max-height: 40vh;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* Toast clears the safe-area + title-card on phones. */
    #toast {
        top: calc(env(safe-area-inset-top) + 8px);
        font-size: 12px;
        padding: 7px 14px;
    }
    .share-panel {
        align-items: flex-end;
        padding: 8px;
        padding-bottom: calc(8px + env(safe-area-inset-bottom));
    }
    .share-dialog {
        width: 100%;
        max-height: calc(100vh - 24px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
        overflow-y: auto;
    }
    .share-actions { grid-template-columns: 1fr; }
}

/* ── Responsive: very small phones (≤380px) ───────────────────── */

/* On a 360-class device the bottom palette + toolbar would otherwise
   eat the canvas. Tighten further: 5-tool grid that wraps, smaller
   palette swatches. */
@media (max-width: 380px) {
    .game-guide-nav {
        left: calc(62px + env(safe-area-inset-left));
    }
    .tool { width: 46px; padding: 6px 3px; }
    .tool .ti { width: 28px; height: 28px; }
    #palette { height: 184px; }
    #palette-grid { grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); }
    .swatch canvas, .swatch img, .swatch-placeholder { width: 38px; height: 38px; }
    #instructions { bottom: calc(184px + 14px + env(safe-area-inset-bottom)); }
}

/* ── Responsive: phone landscape ──────────────────────────────── */

/* Landscape on a phone (short height, wide layout): bring the palette
   back to the right side as a slim column instead of eating the bottom
   third of the screen, and shrink the title back even further. */
@media (max-height: 480px) and (orientation: landscape) {
    .game-guide-nav {
        top: calc(8px + env(safe-area-inset-top));
        left: calc(60px + env(safe-area-inset-left));
        right: calc(216px + env(safe-area-inset-right));
        transform: none;
        max-width: none;
    }
    #title-card {
        padding: 6px 10px 6px 6px;
    }
    .title-logo { width: 32px; height: 32px; }
    .title-text h1 { font-size: 14px; }
    .title-text p  { display: none; }

    #toolbar {
        top: calc(8px + env(safe-area-inset-top));
        left: calc(8px + env(safe-area-inset-left));
        padding: 5px 4px;
        gap: 3px;
        max-height: calc(100vh - 16px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
    }
    .tool { width: 44px; padding: 6px 3px; }
    .tool .ti { width: 26px; height: 26px; }
    .tool span.label { display: none; }

    #palette {
        top: calc(8px + env(safe-area-inset-top));
        right: calc(8px + env(safe-area-inset-right));
        bottom: calc(8px + env(safe-area-inset-bottom));
        left: auto;
        width: 200px;
        height: auto;
    }
    #palette-grid { grid-template-columns: repeat(2, 1fr); }
    #instructions {
        bottom: calc(8px + env(safe-area-inset-bottom));
        left: calc(8px + env(safe-area-inset-left));
    }
}

/* ── Coarse-pointer (touch device) cheatsheet swap ────────────── */

/* On any pointer-coarse device (phones, tablets, touch laptops in
   tablet mode) the keyboard shortcuts are useless — swap to the
   touch-gesture cheatsheet. Pure CSS, no JS detection needed. */
@media (pointer: coarse) {
    .ins-grid--mouse { display: none; }
    .ins-grid--touch { display: grid; }
    /* Touch devices often have a crosshair-incompatible cursor. */
    #game-canvas { cursor: default; }
}

/* ── 可爬取网站内容与静态页面 ─────────────────────────────────── */

a {
    color: var(--cobalt);
    text-decoration-thickness: 1px;
    text-underline-offset: 0.18em;
}
a:hover { color: var(--cobalt-2); }

body.home-page,
.home-content,
.site-page {
    background:
        linear-gradient(180deg, #fffaf1 0%, #f5ead4 44%, #edf6f8 100%);
    color: var(--ink);
}

body.home-page {
    min-height: 100vh;
    min-height: 100dvh;
}

.site-nav {
    width: min(1120px, calc(100% - 32px));
    margin: 0 auto;
    padding: 22px 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    border-bottom: 1px solid rgba(43, 42, 38, 0.12);
}

.site-logo {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    color: var(--cobalt);
    font-size: 20px;
    font-weight: 800;
    text-decoration: none;
    white-space: nowrap;
}
.site-logo::before {
    content: '';
    width: 34px;
    height: 34px;
    flex: 0 0 auto;
    background: url('/assets/logo.svg') center / contain no-repeat;
    filter: drop-shadow(0 3px 6px rgba(60, 50, 30, 0.10));
}

.site-nav-links {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    flex-wrap: wrap;
    gap: 12px 18px;
    font-size: 14px;
    font-weight: 700;
}
.site-nav-links a {
    color: var(--ink-soft);
    text-decoration: none;
}
.site-nav-links a:hover { color: var(--cobalt); }
.site-nav-links .site-nav-cta {
    padding: 8px 12px;
    border-radius: 8px;
    color: #fff;
    background: var(--cobalt);
    box-shadow: 0 6px 16px rgba(27, 91, 168, 0.16);
}
.site-nav-links .site-nav-cta:hover {
    color: #fff;
    background: var(--cobalt-2);
}

.home-grid,
.info-band,
.feature-list,
.faq-section,
.related-links,
.site-main,
.site-footer {
    width: min(1120px, calc(100% - 32px));
    margin-left: auto;
    margin-right: auto;
}

.home-grid {
    padding: clamp(42px, 7vw, 84px) 0 36px;
    display: grid;
    grid-template-columns: minmax(0, 1.1fr) minmax(280px, 0.9fr);
    gap: clamp(28px, 5vw, 72px);
    align-items: center;
}

.home-intro h1,
.home-intro h2,
.site-hero h1 {
    margin: 0;
    max-width: 780px;
    font-size: clamp(38px, 6vw, 76px);
    line-height: 0.96;
    font-weight: 850;
    color: var(--ink);
}

.home-intro p,
.site-hero p,
.article-body p,
.article-body li,
.info-band p,
.info-band li,
.feature-grid p,
.faq-section p {
    font-size: 17px;
    line-height: 1.72;
    color: var(--ink-soft);
}

.home-intro p {
    max-width: 700px;
    margin: 20px 0 0;
}

.home-hero {
    min-height: min(680px, calc(100vh - 90px));
}

.content-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    margin-top: 28px;
}

.button-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 44px;
    padding: 12px 18px;
    border-radius: 8px;
    background: var(--cobalt);
    color: #fff;
    font-weight: 800;
    text-decoration: none;
    box-shadow: 0 8px 20px rgba(27, 91, 168, 0.18);
}
.button-link:hover {
    color: #fff;
    background: var(--cobalt-2);
}
.button-link--secondary {
    color: var(--cobalt);
    background: rgba(110, 200, 224, 0.18);
    box-shadow: none;
}
.button-link--secondary:hover {
    color: var(--cobalt);
    background: rgba(110, 200, 224, 0.30);
}

.asset-showcase {
    display: grid;
    grid-template-columns: 1fr 0.82fr;
    gap: 12px;
    align-items: end;
}
.asset-showcase img {
    width: 100%;
    height: auto;
    display: block;
    border: 1px solid rgba(27, 91, 168, 0.12);
    border-radius: 8px;
    background:
        radial-gradient(circle at 50% 20%, rgba(110, 200, 224, 0.24), transparent 54%),
        rgba(255, 255, 255, 0.72);
    box-shadow: var(--shadow);
}
.asset-showcase img:first-child {
    grid-row: span 2;
}

.home-preview {
    align-self: center;
}

.home-preview img {
    transform: translateZ(0);
}

.info-band {
    padding: 36px 0;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 36px;
    border-top: 1px solid rgba(43, 42, 38, 0.12);
    border-bottom: 1px solid rgba(43, 42, 38, 0.12);
}

.info-band h2,
.feature-list h2,
.faq-section h2,
.related-links h2,
.article-body h2 {
    margin: 0 0 14px;
    font-size: clamp(26px, 3vw, 38px);
    line-height: 1.08;
}

.info-band ol,
.article-body ol,
.article-body ul {
    padding-left: 1.35rem;
}

.feature-list,
.faq-section,
.related-links {
    padding: 54px 0 0;
}

.feature-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 14px;
}
.feature-grid article {
    min-height: 210px;
    padding: 20px;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.68);
    border: 1px solid rgba(43, 42, 38, 0.10);
}
.feature-grid h3 {
    margin: 0 0 10px;
    color: var(--cobalt);
    font-size: 19px;
}

.faq-section {
    display: grid;
    gap: 10px;
}
.faq-section details {
    padding: 18px 20px;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.68);
    border: 1px solid rgba(43, 42, 38, 0.10);
}
.faq-section summary {
    cursor: pointer;
    color: var(--ink);
    font-weight: 800;
    font-size: 18px;
}

.related-links {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 12px;
}
.related-links h2 {
    grid-column: 1 / -1;
}
.related-links a {
    min-height: 72px;
    display: flex;
    align-items: center;
    padding: 16px;
    border-radius: 8px;
    background: rgba(27, 91, 168, 0.08);
    color: var(--cobalt);
    font-weight: 800;
    text-decoration: none;
}

.site-footer {
    margin-top: 64px;
    padding: 18px 0 40px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 10px 22px;
    border-top: 1px solid rgba(43, 42, 38, 0.12);
}
.site-footer p {
    margin: 0;
    color: var(--muted);
    font-size: 13px;
    line-height: 1.5;
}
.site-footer-link-groups {
    margin-left: auto;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    flex-wrap: wrap;
    gap: 10px clamp(24px, 4vw, 52px);
}
.site-footer nav {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: flex-end;
    gap: 8px 14px;
    font-size: 14px;
    font-weight: 700;
}
.site-footer-friendly {
    margin-left: auto;
}
.site-footer a {
    color: var(--ink-soft);
    text-decoration: none;
}
.site-footer a:hover {
    color: var(--cobalt);
    text-decoration: underline;
}
.site-footer-friendly-label {
    color: var(--muted);
    font-weight: 800;
    white-space: nowrap;
}

.site-page {
    min-height: 100vh;
    min-height: 100dvh;
    --site-footer-reserve: 84px;
}
body.site-page > .site-nav {
    position: sticky;
    top: 0;
    z-index: 80;
    background: rgba(255, 250, 241, 0.94);
    backdrop-filter: blur(8px);
}
body.site-page > .site-main {
    padding: clamp(44px, 7vw, 86px) 0 0;
    padding-bottom: calc(clamp(44px, 6vw, 76px) + var(--site-footer-reserve));
}
body.site-page > .site-footer {
    position: fixed;
    left: 50%;
    bottom: 0;
    z-index: 80;
    transform: translateX(-50%);
    margin-top: 0;
    padding: 12px 0 calc(12px + env(safe-area-inset-bottom));
    background: rgba(237, 246, 248, 0.94);
    backdrop-filter: blur(8px);
}
.site-hero {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 250px;
    gap: 44px;
    align-items: center;
}
.site-hero p {
    max-width: 760px;
    margin: 22px 0 0;
}
.site-hero img {
    width: min(100%, 250px);
    height: auto;
    justify-self: center;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.64);
    border: 1px solid rgba(43, 42, 38, 0.10);
    box-shadow: var(--shadow);
}

.article-body {
    max-width: 840px;
    padding-top: 44px;
}
.article-meta {
    margin: 0 0 18px;
    color: var(--muted);
    font-size: 14px;
    font-weight: 700;
}
.article-body h2 {
    margin-top: 42px;
}
.article-body h3 {
    margin: 28px 0 8px;
    color: var(--cobalt);
    font-size: 22px;
}
.article-body p,
.article-body li {
    color: var(--ink-soft);
}

.callout {
    margin: 32px 0;
    padding: 22px;
    border-left: 5px solid var(--terracotta);
    border-radius: 8px;
    background: rgba(196, 98, 46, 0.10);
}
.callout p {
    margin: 0;
}

.article-cta {
    margin-top: 42px;
    padding: 28px;
    border-radius: 8px;
    background: rgba(27, 91, 168, 0.08);
    border: 1px solid rgba(27, 91, 168, 0.12);
}
.article-cta h2 {
    margin-top: 0;
}
.article-cta p {
    margin-bottom: 22px;
}

@media (max-width: 900px) {
    #game-shell { min-height: 560px; }
    .site-page {
        --site-footer-reserve: 150px;
    }
    .home-grid,
    .info-band,
    .site-hero {
        grid-template-columns: 1fr;
    }
    .feature-grid,
    .related-links {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
    .site-footer {
        flex-direction: column;
        align-items: flex-start;
    }
    .site-footer-link-groups {
        margin-left: 0;
        flex-direction: column;
        align-items: flex-start;
        justify-content: flex-start;
        gap: 10px;
    }
    .site-footer-friendly {
        margin-left: 0;
    }
    .site-footer nav {
        justify-content: flex-start;
    }
}

@media (max-width: 640px) {
    #game-shell { min-height: 560px; }
    .site-nav {
        align-items: flex-start;
        flex-direction: column;
    }
    .site-nav-links {
        justify-content: flex-start;
    }
    .home-grid {
        padding-top: 36px;
    }
    .asset-showcase {
        grid-template-columns: repeat(3, 1fr);
    }
    .asset-showcase img:first-child {
        grid-row: auto;
    }
    .home-intro h1,
    .home-intro h2,
    .site-hero h1 {
        font-size: clamp(34px, 12vw, 52px);
        line-height: 1.02;
    }
    .feature-grid,
    .related-links {
        grid-template-columns: 1fr;
    }
}
