:root {
    --ink: #e9f3df;
    --muted: #9fb59a;
    --poison: #9bff4f;
    --amber: #ffc857;
    --danger: #ff5a4f;
    --panel: rgba(8, 14, 12, 0.55);
    font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
}

html, body {
    margin: 0;
    height: 100%;
    overflow: hidden;
    background: #05080a;
    color: var(--ink);
    user-select: none;
    -webkit-user-select: none;
}

#game {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    display: block;
    touch-action: none;
}

.hidden { display: none !important; }

#hud {
    position: fixed;
    inset: 0;
    pointer-events: none;
}

.hud-left {
    position: absolute;
    top: 18px;
    left: 20px;
    width: min(320px, 42vw);
}

.portrait {
    font-weight: 800;
    letter-spacing: 0.18em;
    font-size: 12px;
    color: var(--amber);
    text-shadow: 0 1px 6px #000;
    margin-bottom: 6px;
}

.bar {
    position: relative;
    height: 16px;
    border-radius: 9px;
    background: var(--panel);
    border: 1px solid rgba(255, 255, 255, 0.18);
    overflow: hidden;
    backdrop-filter: blur(3px);
    margin-bottom: 6px;
}

.bar > div {
    position: absolute;
    inset: 0 auto 0 0;
    width: 100%;
    transition: width 120ms linear;
}

.bar.health > div { background: linear-gradient(90deg, #c9302c, #ff7a45 70%, #ffd166); }
.bar.mana { height: 8px; }
.bar.mana > div { background: linear-gradient(90deg, #2d8cff, #8be9ff); }

.bar span {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    font-size: 11px;
    font-weight: 700;
    text-shadow: 0 1px 3px #000;
}

.hud-right {
    position: absolute;
    top: 14px;
    right: 22px;
    text-align: right;
    text-shadow: 0 2px 8px #000;
}

.score-label { font-size: 11px; letter-spacing: 0.25em; color: var(--muted); }
#score { font-size: 38px; font-weight: 800; line-height: 1; font-variant-numeric: tabular-nums; color: #fff; }
.sub { font-size: 12px; color: var(--muted); margin-top: 4px; }

.chapter {
    position: absolute;
    top: 22%;
    left: 50%;
    transform: translateX(-50%);
    text-align: center;
    opacity: 0;
    transition: opacity 600ms ease;
    text-shadow: 0 2px 18px #000, 0 0 40px rgba(0, 0, 0, 0.8);
    width: min(720px, 90vw);
}

.chapter.show { opacity: 1; }
.chapter-num { letter-spacing: 0.5em; font-size: 12px; color: var(--poison); }
.chapter-name { font-size: clamp(28px, 5vw, 56px); font-weight: 800; letter-spacing: 0.04em; }
.chapter-story { font-style: italic; color: var(--muted); font-size: clamp(14px, 2vw, 20px); margin-top: 4px; }

.controls-hint {
    position: absolute;
    bottom: 12px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 12px;
    color: var(--muted);
    background: var(--panel);
    padding: 6px 14px;
    border-radius: 14px;
    white-space: nowrap;
    max-width: 96vw;
    overflow: hidden;
    text-overflow: ellipsis;
}

.controls-hint b { color: var(--ink); }

.overlay {
    position: fixed;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    background: radial-gradient(ellipse at center, rgba(5, 12, 10, 0.55), rgba(2, 4, 4, 0.92));
    text-align: center;
    z-index: 10;
}

.overlay .title {
    font-size: clamp(30px, 6vw, 72px);
    font-weight: 900;
    letter-spacing: 0.12em;
    color: var(--amber);
    text-shadow: 0 0 30px rgba(155, 255, 79, 0.35), 0 4px 0 #3a2a05;
}

.overlay .title.bad { color: var(--danger); text-shadow: 0 0 30px rgba(255, 90, 79, 0.4); }
.overlay .tagline { font-style: italic; color: var(--muted); font-size: clamp(14px, 2vw, 22px); }
.loading-text { margin-top: 18px; font-size: 13px; letter-spacing: 0.2em; color: var(--poison); animation: pulse 1.4s ease-in-out infinite; }

@keyframes pulse { 50% { opacity: 0.35; } }

#retry {
    margin-top: 18px;
    pointer-events: auto;
    background: linear-gradient(#ffd166, #e09f1f);
    color: #261a00;
    border: 0;
    padding: 12px 26px;
    font-size: 16px;
    font-weight: 800;
    border-radius: 24px;
    cursor: pointer;
    box-shadow: 0 6px 24px rgba(255, 200, 87, 0.35);
}

#blazor-error-ui {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: #6b1010;
    padding: 10px 16px;
    z-index: 50;
}

#blazor-error-ui a { color: #fff; }

/* ---------- touch controls ---------- */
body.is-touch .controls-hint { display: none; }

#touch {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 6;
    touch-action: none;
    -webkit-touch-callout: none;
}

#touch button {
    pointer-events: auto;
    position: absolute;
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, 0.35);
    background: rgba(10, 18, 14, 0.45);
    color: rgba(255, 255, 255, 0.92);
    font-weight: 800;
    font-size: 15px;
    letter-spacing: 0.08em;
    backdrop-filter: blur(3px);
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
    display: grid;
    place-items: center;
    padding: 0;
}

#touch button.down { background: rgba(155, 255, 79, 0.45); border-color: #d6ff6a; transform: scale(0.94); }

.tc-left button { width: 92px; height: 92px; font-size: 34px; bottom: calc(26px + env(safe-area-inset-bottom)); }
.tc-left button:first-child { left: calc(22px + env(safe-area-inset-left)); }
.tc-left button:last-child { left: calc(126px + env(safe-area-inset-left)); }

.tc-right .tc-fire { width: 112px; height: 112px; right: calc(26px + env(safe-area-inset-right)); bottom: calc(26px + env(safe-area-inset-bottom)); background: rgba(255, 160, 40, 0.4); border-color: #ffc069; font-size: 18px; }
.tc-right .tc-bomb { width: 78px; height: 78px; right: calc(150px + env(safe-area-inset-right)); bottom: calc(34px + env(safe-area-inset-bottom)); }
.tc-right .tc-jump { width: 86px; height: 86px; right: calc(60px + env(safe-area-inset-right)); bottom: calc(150px + env(safe-area-inset-bottom)); }

#touch .tc-top button { position: static; width: 44px; height: 44px; font-size: 15px; margin-left: 8px; }
.tc-top { position: absolute; top: calc(70px + env(safe-area-inset-top)); left: calc(20px + env(safe-area-inset-left)); display: flex; pointer-events: none; }
.tc-top button:first-child { margin-left: 0; }

.tc-tip {
    position: absolute;
    left: 50%;
    bottom: calc(8px + env(safe-area-inset-bottom));
    transform: translateX(-50%);
    font-size: 11px;
    color: var(--muted);
    background: var(--panel);
    padding: 3px 10px;
    border-radius: 10px;
    white-space: nowrap;
    animation: tip-fade 1s ease 8s forwards;
}

@keyframes tip-fade { to { opacity: 0; } }

#rotate {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 30;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    background: rgba(2, 4, 4, 0.94);
    text-align: center;
}

#rotate .title { font-size: 72px; color: var(--amber); }
#rotate .tagline { font-style: italic; color: var(--muted); font-size: 20px; }

@media (orientation: portrait) and (pointer: coarse) { #rotate { display: flex; } }

/* keep the HUD readable on phones in landscape */
@media (max-height: 480px) {
    .hud-left { top: 8px; left: 12px; width: min(240px, 36vw); }
    #score { font-size: 28px; }
    .hud-right { top: 8px; right: 14px; }
    .chapter { top: 14%; }
    .tc-top { top: 64px; }
}

.floater {
    position: fixed;
    left: 0;
    top: 0;
    pointer-events: none;
    font-weight: 900;
    font-size: 20px;
    letter-spacing: 0.03em;
    text-shadow: 0 2px 6px #000, 0 0 12px rgba(0, 0, 0, 0.7);
    z-index: 5;
    will-change: transform, opacity;
}

.floater.dmg { color: #fff3a8; }
.floater.hurt { color: #ff6a5a; font-size: 26px; }
.floater.cured { color: #b6ff5a; font-size: 15px; letter-spacing: 0.25em; }

#hurtFlash {
    position: fixed;
    inset: 0;
    pointer-events: none;
    background: radial-gradient(ellipse at center, rgba(255, 30, 20, 0) 40%, rgba(255, 30, 20, 0.55) 100%);
    opacity: 0;
    z-index: 4;
}

#hurtFlash.on { animation: hurt 0.45s ease-out; }

@keyframes hurt { 0% { opacity: 1; } 100% { opacity: 0; } }

body::after {
    content: "";
    position: fixed;
    inset: 0;
    pointer-events: none;
    background: radial-gradient(ellipse at center, rgba(0, 0, 0, 0) 55%, rgba(0, 0, 0, 0.55) 100%);
    z-index: 2;
}
