*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

:root {
    --bg: #14110a;
    --panel: #241f14;
    --line: #4d4227;
    --text: #fff6e2;
    --muted-real: #b8ac8c;
    --accent: #ffc861;
    --floor: #2a2418;
    --wall: #4a4029;
    --goal: #6b5a2a;
    --box: #c98a3c;
    --box-done: #6fbf73;
    --player: #7fd0ff;
}

html, body { height: 100%; overscroll-behavior: none; }

body {
    position: fixed;
    inset: 0;
    overflow: hidden;
    color: var(--text);
    font-family: 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', 'Segoe UI', sans-serif;
    background:
        radial-gradient(circle at 50% 0%, rgba(255, 200, 97, 0.12), transparent 55%),
        linear-gradient(180deg, #0d0b06, #191509);
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
    touch-action: none;
}

.shell {
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 100dvh;
    max-width: 520px;
    margin: 0 auto;
    padding:
        max(6px, env(safe-area-inset-top))
        max(8px, env(safe-area-inset-right))
        max(8px, env(safe-area-inset-bottom))
        max(8px, env(safe-area-inset-left));
}

.toolbar { display: flex; align-items: center; gap: 6px; flex: 0 0 auto; height: 38px; }
.toolbar-spacer { flex: 1; }

.icon-btn {
    display: inline-flex; align-items: center; justify-content: center;
    min-width: 34px; height: 31px; padding: 0 10px;
    border: 1px solid var(--line); border-radius: 9px;
    background: var(--panel); color: var(--text);
    font-family: inherit; font-size: 0.88rem; line-height: 1;
    text-decoration: none; cursor: pointer;
    transition: transform 0.12s ease, border-color 0.12s ease;
}

.icon-btn-text { font-size: 0.76rem; font-weight: 600; }
.icon-btn:active { transform: scale(0.94); border-color: var(--accent); }

.hud { display: flex; gap: 6px; flex: 0 0 auto; margin: 5px 0; }

.hud span {
    flex: 1; display: flex; flex-direction: column; align-items: center;
    padding: 4px 2px; border-radius: 9px; background: rgba(255, 255, 255, 0.05);
}

.hud b { font-size: 0.9rem; font-variant-numeric: tabular-nums; }
.hud i { font-style: normal; font-size: 0.58rem; letter-spacing: 0.08em; color: var(--muted-real); }

/* ===== Board ===== */
.board-area { flex: 1 1 auto; min-height: 0; display: flex; align-items: center; justify-content: center; }

.board {
    position: relative;
    border-radius: 8px;
    overflow: hidden;
    background: #0f0d07;
    touch-action: none;
}

.tile { position: absolute; }
.tile-wall { background: linear-gradient(180deg, #574a2f, var(--wall)); border-radius: 3px; }
.tile-floor { background: var(--floor); }

.tile-goal {
    background: var(--floor);
    box-shadow: inset 0 0 0 2px var(--goal);
    border-radius: 4px;
}

.tile-goal::after {
    content: '';
    position: absolute;
    inset: 34%;
    border-radius: 50%;
    background: var(--goal);
}

.mover {
    position: absolute;
    transition: transform 0.11s linear;
    will-change: transform;
}

.box-body {
    position: absolute;
    inset: 9%;
    border-radius: 5px;
    background: linear-gradient(180deg, #e0a355, var(--box));
    box-shadow: inset 0 0 0 2px rgba(0, 0, 0, 0.22);
}

.mover.is-done .box-body { background: linear-gradient(180deg, #8fe094, var(--box-done)); }

.player-body {
    position: absolute;
    inset: 14%;
    border-radius: 50%;
    background: radial-gradient(circle at 35% 30%, #c7ecff, var(--player));
    box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.22);
}

/* ===== Pad ===== */
.pad { display: flex; flex-direction: column; align-items: center; gap: 5px; flex: 0 0 auto; margin-top: 6px; }
.dir-row { display: flex; gap: 5px; }

.dir {
    width: 58px; height: 46px;
    border: 1px solid var(--line); border-radius: 11px;
    background: var(--panel); color: var(--text);
    font-family: inherit; font-size: 0.95rem; cursor: pointer;
    transition: transform 0.1s ease, border-color 0.1s ease;
}

.dir:active { transform: scale(0.93); border-color: var(--accent); }

/* ===== Tools ===== */
.tools { display: flex; gap: 5px; flex: 0 0 auto; margin-top: 6px; }

.tool {
    flex: 1; min-height: 46px;
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
    border: 1px solid var(--line); border-radius: 11px;
    background: var(--panel); color: var(--text);
    font-family: inherit; cursor: pointer;
    transition: transform 0.1s ease;
}

.tool i { font-style: normal; font-size: 1rem; line-height: 1; }
.tool span { font-size: 0.58rem; color: var(--muted-real); }
.tool:active { transform: scale(0.95); }
.tool:disabled { opacity: 0.4; }

.hint { margin-top: 5px; text-align: center; font-size: 0.64rem; color: var(--muted-real); }

/* ===== Overlays ===== */
.overlay {
    position: absolute; inset: 0; display: none;
    align-items: center; justify-content: center; padding: 18px;
    background: rgba(8, 6, 3, 0.9);
    backdrop-filter: blur(5px); -webkit-backdrop-filter: blur(5px);
    z-index: 50;
}

.overlay.is-open { display: flex; }

.panel {
    width: 100%; max-width: 330px; max-height: 100%; overflow-y: auto;
    display: flex; flex-direction: column; gap: 10px;
    padding: 20px 16px;
    border: 1px solid var(--line); border-radius: 20px;
    background: linear-gradient(180deg, #2e2717, #1a1509);
    text-align: center;
    animation: pop 0.22s ease;
}

.panel-wide { max-width: 380px; }

@keyframes pop { from { opacity: 0; transform: translateY(12px) scale(0.97); } to { opacity: 1; transform: none; } }

.panel-title { font-size: 1.45rem; font-weight: 800; letter-spacing: 0.08em; color: var(--accent); }

.tiers { display: flex; gap: 5px; }

.tier {
    flex: 1; padding: 8px 4px;
    border: 1px solid var(--line); border-radius: 10px;
    background: rgba(255, 255, 255, 0.05); color: var(--text);
    font-family: inherit; font-size: 0.74rem; font-weight: 700; cursor: pointer;
}

.tier.is-current { border-color: var(--accent); background: rgba(255, 200, 97, 0.16); }

.grid-levels { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }

.level-cell {
    aspect-ratio: 1;
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
    border: 1px solid var(--line); border-radius: 10px;
    background: rgba(255, 255, 255, 0.05); color: var(--text);
    font-family: inherit; font-size: 0.9rem; font-weight: 700; cursor: pointer;
}

.level-cell small { font-size: 0.5rem; color: var(--accent); letter-spacing: -0.02em; }
.level-cell.is-done { border-color: var(--box-done); background: rgba(111, 191, 115, 0.14); }
.level-cell.is-current { border-color: var(--accent); }

.stars { font-size: 1.7rem; letter-spacing: 0.12em; }

.btn {
    min-height: 46px; padding: 12px 20px;
    border: 1px solid var(--line); border-radius: 13px;
    background: rgba(255, 255, 255, 0.05); color: var(--text);
    font-family: inherit; font-size: 0.92rem; font-weight: 700;
    text-decoration: none; display: flex; align-items: center; justify-content: center;
    cursor: pointer;
}

.btn:active { transform: scale(0.97); }
.btn-primary { border-color: transparent; background: linear-gradient(135deg, #ffd98a, #f0a828); color: #2a1c00; }

.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; }
.stat { padding: 9px 6px; border-radius: 11px; background: rgba(255, 255, 255, 0.06); }
.stat b { display: block; font-size: 1.1rem; font-variant-numeric: tabular-nums; }
.stat span { font-size: 0.62rem; color: var(--muted-real); }

@media (max-height: 680px) {
    .hud { margin: 3px 0; }
    .dir { height: 40px; width: 52px; }
    .tool { min-height: 40px; }
    .hint { display: none; }
}

@media (prefers-reduced-motion: reduce) { .panel { animation: none; } .mover { transition: none; } }
