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

:root {
    --glass: rgba(16, 20, 24, 0.5);
    --glass-strong: rgba(16, 20, 24, 0.78);
    --hairline: rgba(255, 255, 255, 0.1);
    --text-dim: rgba(255, 255, 255, 0.62);
    --accent: #ffc83a;
    --danger: #ef5350;
    --info: #7cc4ff;
    --safe-top: max(0.6rem, env(safe-area-inset-top));
    --safe-bottom: max(0.9rem, env(safe-area-inset-bottom));
}

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: #8fb8d8;
    color: #fff;
    font: 14px/1.35 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
}

#scene {
    position: fixed;
    inset: 0;
    display: block;
    width: 100vw;
    height: 100vh;
    height: 100dvh;
}

button { font: inherit; color: inherit; cursor: pointer; border: none; background: none; }
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }

.hud-strip, .hud-job, .tool-button, .toast {
    background: var(--glass);
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
    border: 1px solid var(--hairline);
}

/* ---- Top-left status ---------------------------------------------- */

.hud {
    position: fixed;
    top: var(--safe-top);
    left: 0.6rem;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.3rem;
    max-width: calc(100vw - 170px);
    pointer-events: none;
}

.hud-strip {
    display: flex;
    align-items: baseline;
    gap: 0.85rem;
    padding: 0.28rem 0.85rem;
    border-radius: 999px;
    font-variant-numeric: tabular-nums;
}

.hud-money { color: var(--accent); font-size: 1.15rem; font-weight: 750; letter-spacing: -0.01em; }
.hud-stat b { font-weight: 600; }
.hud-label { color: var(--text-dim); font-size: 0.72rem; margin-right: 0.3rem; }

.hud-job {
    padding: 0.2rem 0.75rem;
    border-radius: 999px;
    font-size: 0.78rem;
    color: rgba(255, 255, 255, 0.88);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}

.hud-job-title { color: var(--text-dim); margin-right: 0.45rem; }

.hud-tilt {
    display: flex;
    gap: 0.7rem;
    padding: 0.2rem 0.7rem;
    border-radius: 999px;
    background: var(--glass);
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
    width: fit-content;
}
.tilt-gauge { display: flex; align-items: center; gap: 0.35rem; font-size: 0.72rem; --tilt-color: #8bd17c; }
.tilt-gauge.warn { --tilt-color: var(--accent); }
.tilt-gauge.danger { --tilt-color: var(--danger); }
.tilt-icon { width: 1.5rem; height: 1.2rem; overflow: visible; }
.tilt-body { fill: var(--tilt-color); }
.tilt-wheel { fill: #e8e8e8; }
.tilt-ground { stroke: rgba(255, 255, 255, 0.35); stroke-width: 1; }
.tilt-bar { width: 2.6rem; height: 0.25rem; border-radius: 999px; background: rgba(255, 255, 255, 0.15); overflow: hidden; }
.tilt-fill { display: block; height: 100%; width: 0; border-radius: inherit; background: var(--tilt-color); }
.tilt-value { min-width: 1.6rem; font-weight: 600; font-variant-numeric: tabular-nums; }

/* ---- Top-right minimap and tools ---------------------------------- */

.side-panel {
    position: fixed;
    top: var(--safe-top);
    right: 0.6rem;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 0.4rem;
}

#minimap {
    width: 148px;
    height: 148px;
    border-radius: 50%;
    box-shadow: 0 0 0 1px var(--hairline), 0 4px 14px rgba(0, 0, 0, 0.25);
    pointer-events: none;
}

.tool-row { display: flex; gap: 0.3rem; justify-content: center; white-space: nowrap; }

.tool-button {
    min-width: 1.9rem;
    height: 1.9rem;
    padding: 0 0.5rem;
    border-radius: 999px;
    font-size: 0.78rem;
    line-height: 1;
    color: rgba(255, 255, 255, 0.9);
}

.tool-button:hover { background: var(--glass-strong); }
.tool-wide { min-width: 3.2rem; }
.tool-button.off { color: var(--text-dim); text-decoration: line-through; }

/* ---- Messages ----------------------------------------------------- */

.toast {
    position: fixed;
    top: calc(var(--safe-top) + 4.4rem);
    left: 50%;
    transform: translate(-50%, -6px);
    padding: 0.4rem 0.95rem;
    border-radius: 999px;
    font-size: 0.9rem;
    font-weight: 600;
    text-align: center;
    max-width: min(30rem, 86vw);
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.25s, transform 0.25s;
}

.toast.visible { opacity: 1; transform: translate(-50%, 0); }
.toast.good { color: #a5f0a5; }
.toast.bad { color: #ffab9f; }

/* ---- Actions ------------------------------------------------------ */

.action-bar {
    position: fixed;
    bottom: var(--safe-bottom);
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 0.45rem;
}

.action-button {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    border-radius: 999px;
    background: var(--accent);
    color: #1c1c1c;
    font-weight: 700;
    font-size: 0.92rem;
    white-space: nowrap;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.25);
    transition: transform 0.08s, filter 0.15s;
}

.action-button:hover { filter: brightness(1.06); }
.action-button:active { transform: scale(0.97); }
.action-button:disabled { opacity: 0.4; cursor: default; filter: none; transform: none; }
.action-dump { background: #ffa040; }
.action-recover { background: var(--danger); color: #fff; }
.action-shop { background: var(--info); }

kbd {
    font: 600 0.66rem/1 system-ui, sans-serif;
    padding: 0.18rem 0.35rem;
    border-radius: 0.3rem;
    background: rgba(0, 0, 0, 0.14);
    color: inherit;
    opacity: 0.75;
}

.touch-mode kbd { display: none; }

.keyboard-help {
    position: fixed;
    bottom: calc(var(--safe-bottom) + 0.1rem);
    left: 0.7rem;
    font-size: 0.7rem;
    color: rgba(255, 255, 255, 0.7);
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6);
    pointer-events: none;
}

/* ---- Touch controls ----------------------------------------------- */

.steer-buttons {
    position: fixed;
    left: max(0.8rem, env(safe-area-inset-left));
    bottom: var(--safe-bottom);
    display: flex;
    gap: 0.6rem;
}

.steer-button {
    width: 3.9rem;
    height: 3.9rem;
    border-radius: 50%;
    background: var(--glass);
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
    border: 1px solid var(--hairline);
    font-size: 1.25rem;
    color: rgba(255, 255, 255, 0.9);
    touch-action: none;
}

.steer-button.pressed { background: rgba(255, 200, 58, 0.55); color: #1c1c1c; }

.power-slider-wrap {
    position: fixed;
    right: max(0.8rem, env(safe-area-inset-right));
    bottom: var(--safe-bottom);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.3rem;
}

.power-label { font-size: 0.65rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--text-dim); }

.power-slider {
    position: relative;
    width: 2.8rem;
    height: 9.5rem;
    border-radius: 999px;
    background: var(--glass);
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
    border: 1px solid var(--hairline);
    touch-action: none;
    overflow: hidden;
}

.power-slider-zero {
    position: absolute;
    left: 0.45rem;
    right: 0.45rem;
    top: 66.66%;
    height: 1px;
    background: rgba(255, 255, 255, 0.5);
}

.power-slider-fill {
    position: absolute;
    left: 0;
    right: 0;
    background: rgba(255, 200, 58, 0.5);
}

.power-slider-fill.reverse { background: rgba(239, 83, 80, 0.55); }

.power-slider-thumb {
    position: absolute;
    left: 0.25rem;
    right: 0.25rem;
    height: 0.9rem;
    margin-top: -0.45rem;
    border-radius: 999px;
    background: #fff;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.35);
    pointer-events: none;
}

/* ---- Dialogs ------------------------------------------------------ */

.overlay {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(10, 14, 18, 0.35);
    -webkit-backdrop-filter: blur(3px);
    backdrop-filter: blur(3px);
}

.card {
    width: min(24rem, 92vw);
    padding: 1.1rem 1.2rem;
    border-radius: 1rem;
    background: rgba(24, 28, 33, 0.88);
    border: 1px solid var(--hairline);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.card-header { display: flex; align-items: center; justify-content: space-between; }
.card h2 { font-size: 1.05rem; font-weight: 700; }
.card h3 { font-size: 0.85rem; font-weight: 650; }
.shop-note { font-size: 0.8rem; color: var(--text-dim); }

.shop-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.8rem;
    padding-top: 0.7rem;
    border-top: 1px solid var(--hairline);
}

.shop-info p { font-size: 0.78rem; color: var(--text-dim); margin: 0.1rem 0 0.35rem; }
.shop-row .action-button { font-size: 0.8rem; padding: 0.45rem 0.8rem; }

.level-pips { display: flex; gap: 0.2rem; }
.level-pips span { width: 1.1rem; height: 0.3rem; border-radius: 999px; background: rgba(255, 255, 255, 0.15); }
.level-pips span.owned { background: var(--accent); }

.start-overlay { background: rgba(10, 14, 18, 0.25); }
.start-card { text-align: center; align-items: center; }
.start-card h1 { font-size: 2.2rem; font-weight: 800; letter-spacing: -0.02em; color: var(--accent); }
.start-card p { color: rgba(255, 255, 255, 0.85); }
.start-button { padding: 0.65rem 2.2rem; font-size: 1rem; }
.start-hint { font-size: 0.75rem; color: var(--text-dim) !important; }
.start-version { font-size: 0.7rem; color: rgba(255, 255, 255, 0.4) !important; }

/* ---- Small screens ------------------------------------------------ */

@media (max-width: 640px) {
    #minimap { width: 112px; height: 112px; }
    .hud { max-width: calc(100vw - 132px); }
    .hud-strip { gap: 0.6rem; padding: 0.25rem 0.7rem; }
    .hud-money { font-size: 1rem; }
    .hud-label { display: none; }
    .keyboard-help { display: none; }
    .touch-mode .action-bar { bottom: calc(var(--safe-bottom) + 4.6rem); }
    .action-button { padding: 0.45rem 0.85rem; font-size: 0.85rem; }
}
