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

:root {
    --bg: #14110f;
    --panel: #262019;
    --line: #4a3d2e;
    --text: #f5ece0;
    --muted: #b6a48d;
    --accent: #e8a13c;
    --blood: #d1483c;
    --life: #4fbf72;
    --tile: #453a2d;
    --tile-open: #201b16;
}

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(232, 161, 60, 0.14), transparent 55%),
        linear-gradient(180deg, #0c0a08, #1b1713);
    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); }

/* Health and experience, the two things a run is spent managing. */
.vitals { display: flex; gap: 6px; align-items: center; flex: 0 0 auto; margin: 5px 0 4px; }

.bar-wrap { flex: 1; }
.bar-line { display: flex; justify-content: space-between; font-size: 0.6rem; color: var(--muted); margin-bottom: 2px; }
.bar-line b { font-size: 0.7rem; color: var(--text); font-variant-numeric: tabular-nums; }

.bar {
    height: 9px; border-radius: 5px; overflow: hidden;
    background: rgba(255, 255, 255, 0.08);
}
.bar span { display: block; height: 100%; border-radius: 5px; transition: width 0.18s ease; }
.bar-hp span { background: linear-gradient(90deg, #e0574a, var(--life)); }
.bar-hp.is-low span { background: linear-gradient(90deg, #ff5a48, #ff9166); }
.bar-xp span { background: linear-gradient(90deg, #c98a2e, var(--accent)); }

.satchel {
    flex: 0 0 auto; display: flex; align-items: center; gap: 3px;
    min-width: 54px; height: 36px; padding: 0 9px;
    border: 1px solid var(--line); border-radius: 10px;
    background: var(--panel);
    font-size: 0.95rem; cursor: pointer;
}
.satchel b { font-size: 0.78rem; font-variant-numeric: tabular-nums; }
.satchel:disabled { opacity: 0.35; }
.satchel:not(:disabled) { border-color: var(--life); }

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

#board {
    display: block;
    border-radius: 10px;
    box-shadow: 0 14px 36px rgba(0, 0, 0, 0.55);
    touch-action: none;
}

/* What the dungeon holds and how much of it is left. Without this the numbers
   cannot be pinned down at all, so it is part of the puzzle, not decoration. */
.bestiary { display: flex; gap: 4px; flex: 0 0 auto; margin-top: 6px; }

.beast {
    flex: 1; display: flex; flex-direction: column; align-items: center; gap: 1px;
    padding: 4px 1px; border-radius: 9px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid transparent;
}
.beast.is-gone { opacity: 0.3; }
.beast.is-dragon { border-color: rgba(209, 72, 60, 0.6); }
.beast i { font-style: normal; font-size: 1.05rem; line-height: 1.1; }
.beast b { font-size: 0.7rem; font-variant-numeric: tabular-nums; }
.beast s { text-decoration: none; font-size: 0.54rem; color: var(--muted); }

.tools { display: flex; gap: 6px; flex: 0 0 auto; margin-top: 6px; }

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

.tool i { font-style: normal; font-size: 1.02rem; line-height: 1; }
.tool span { font-size: 0.6rem; color: var(--muted); }
.tool:active { transform: scale(0.96); }
.tool:disabled { opacity: 0.4; }
.tool.is-on { border-color: var(--accent); background: rgba(232, 161, 60, 0.18); }

.hint-text { margin-top: 5px; text-align: center; font-size: 0.66rem; color: var(--muted); min-height: 1.2em; }
.hint-text.is-warn { color: #ff9d86; font-weight: 700; }

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

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

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

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

.title {
    font-size: clamp(1.7rem, 8vw, 2.3rem); font-weight: 800; letter-spacing: 0.04em;
    background: linear-gradient(135deg, #ffd79a, var(--accent) 60%, #d1483c);
    -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent;
}

.panel-title { font-size: 1.5rem; font-weight: 800; letter-spacing: 0.06em; color: var(--accent); }
.subtitle { color: var(--muted); font-size: 0.85rem; line-height: 1.7; }

.modes { display: flex; flex-direction: column; gap: 8px; margin-top: 4px; }

.mode {
    display: flex; align-items: center; justify-content: space-between;
    padding: 13px 16px;
    border: 1px solid var(--line); border-radius: 13px;
    background: rgba(255, 255, 255, 0.05); color: var(--text);
    font-family: inherit; font-size: 0.95rem; font-weight: 700; cursor: pointer;
    transition: transform 0.12s ease, border-color 0.12s ease;
}

.mode small { font-size: 0.68rem; font-weight: 500; color: var(--muted); }
.mode:active { transform: scale(0.98); border-color: var(--accent); }

.legend { display: flex; flex-direction: column; gap: 5px; margin-top: 6px; text-align: left; }
.legend h3 { font-size: 0.7rem; letter-spacing: 0.1em; color: var(--muted); font-weight: 600; }
.legend-row { display: flex; align-items: baseline; gap: 8px; font-size: 0.72rem; color: var(--muted); }
.legend-row b {
    flex: 0 0 auto; width: 1.8em; text-align: center;
    font-size: 0.95rem; font-weight: 400;
}

.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, #ffd08a, #e8a13c); color: #2a1600; }

.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); }

@media (max-height: 720px) {
    .vitals { margin: 3px 0; }
    .tool { min-height: 42px; }
    .hint-text { display: none; }
    .beast i { font-size: 0.92rem; }
}

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