:root {
    color-scheme: dark;
    font-family: "Noto Sans SC", "Microsoft YaHei", system-ui, sans-serif;
    background: #07111b;
    color: #e8f4ff;
    --panel: rgba(11, 29, 45, 0.96);
    --panel-border: rgba(122, 190, 225, 0.26);
    --accent: #80d9ff;
    --accent-strong: #46c7ff;
    --muted: #9bb1c3;
    --danger: #ff8b86;
}

* {
    box-sizing: border-box;
}

html,
body {
    min-height: 100%;
    margin: 0;
    background:
        radial-gradient(circle at 50% -20%, rgba(33, 91, 126, 0.48), transparent 56%),
        #07111b;
}

body {
    min-height: 100vh;
    overscroll-behavior: none;
    overflow-x: hidden;
}

button,
canvas,
#joystick-pad {
    -webkit-tap-highlight-color: transparent;
    touch-action: none;
}

button {
    color: inherit;
    font: inherit;
}

#game-shell {
    width: min(100%, 1440px);
    margin: 0 auto;
    padding: clamp(12px, 2vw, 28px);
}

#brand-row {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 14px;
    margin: 0 auto 10px;
    max-width: 1280px;
}

#brand-row h1 {
    margin: 0;
    color: #d8f2ff;
    font-size: clamp(1.45rem, 3.2vw, 2.2rem);
    letter-spacing: 0.08em;
    line-height: 1.15;
}

#header-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 12px;
    min-width: 0;
}

#build-sha {
    color: var(--muted);
    font: 600 0.78rem/1.2 ui-monospace, SFMono-Regular, Consolas, monospace;
    white-space: nowrap;
}

#button-fullscreen {
    min-height: 38px;
    padding: 6px 12px;
    border: 1px solid rgba(128, 217, 255, 0.42);
    border-radius: 9px;
    background: linear-gradient(180deg, rgba(30, 74, 101, 0.88), rgba(12, 34, 52, 0.96));
    color: #dff7ff;
    font-size: 0.82rem;
    font-weight: 700;
    cursor: pointer;
}

#button-fullscreen:hover,
#button-fullscreen:focus-visible {
    border-color: var(--accent);
    outline: none;
}

#fullscreen-status {
    color: var(--danger);
    font-size: 0.78rem;
}

#runtime-status {
    width: min(100%, 1280px);
    min-height: 1.4em;
    margin: 0 auto 8px;
    color: var(--muted);
    font-size: 0.88rem;
}

#runtime-status[data-state="ready"] {
    color: #a7e8bf;
}

#runtime-error {
    width: min(100%, 1280px);
    margin: 0 auto 10px;
    padding: 10px 12px;
    border: 1px solid rgba(255, 139, 134, 0.55);
    border-radius: 9px;
    background: rgba(92, 23, 25, 0.75);
    color: #ffd3d1;
    white-space: pre-wrap;
}

#play-layout {
    display: grid;
    grid-template-columns: minmax(112px, 12vw) minmax(0, 1fr) minmax(168px, 20vw);
    grid-template-rows: minmax(0, auto);
    align-items: stretch;
    gap: clamp(6px, 1vw, 14px);
    width: min(100%, 1440px);
    margin: 0 auto;
}

#game-frame {
    position: relative;
    grid-column: 2;
    grid-row: 1;
    width: 100%;
    min-width: 0;
    margin: 0;
    overflow: hidden;
    border: 1px solid var(--panel-border);
    border-radius: 14px;
    background: #02070b;
    box-shadow: 0 20px 65px rgba(0, 0, 0, 0.32);
}

#game-version {
    position: absolute;
    left: 50%;
    bottom: 4px;
    z-index: 3;
    transform: translateX(-50%);
    padding: 2px 6px;
    border-radius: 4px;
    background: rgba(2, 7, 11, 0.75);
    color: #c3d4df;
    font: 11px/1.2 ui-monospace, Consolas, monospace;
    white-space: nowrap;
    pointer-events: none;
}

#canvas-wrap {
    position: relative;
    width: 100%;
    aspect-ratio: 16 / 9;
    background: #02070b;
}

#canvas {
    display: block;
    width: 100%;
    height: 100%;
    min-height: 0;
    outline: none;
    background: #050d14;
    image-rendering: auto;
}

#telemetry-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    min-height: 34px;
    padding: 6px 12px;
    border-top: 1px solid rgba(122, 190, 225, 0.18);
    background: rgba(7, 18, 29, 0.94);
    color: var(--muted);
    font: 600 0.75rem/1.25 ui-monospace, SFMono-Regular, Consolas, monospace;
}

#screen-state {
    color: var(--accent);
    white-space: nowrap;
}

#telemetry-state {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    text-align: right;
}

#control-dock {
    display: contents;
}

.control-panel {
    min-width: 0;
    padding: 10px;
    border: 1px solid var(--panel-border);
    border-radius: 12px;
    background: var(--panel);
}

#joystick-panel {
    grid-column: 1;
    grid-row: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 5px;
    min-height: 0;
}

#joystick-label {
    color: var(--muted);
    font-size: 0.78rem;
}

#joystick-pad {
    position: relative;
    width: min(clamp(100px, 20vw, 168px), 100%);
    aspect-ratio: 1;
    border: 2px solid rgba(128, 217, 255, 0.45);
    border-radius: 50%;
    background:
        radial-gradient(circle, rgba(128, 217, 255, 0.14) 0 24%, transparent 25%),
        radial-gradient(circle, rgba(128, 217, 255, 0.07) 0 53%, transparent 54%),
        rgba(4, 16, 25, 0.9);
    cursor: grab;
    user-select: none;
}

#joystick-pad:active {
    cursor: grabbing;
}

#joystick-stick {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 34%;
    aspect-ratio: 1;
    border: 2px solid rgba(226, 249, 255, 0.68);
    border-radius: 50%;
    background: rgba(70, 199, 255, 0.55);
    box-shadow: 0 0 18px rgba(70, 199, 255, 0.45);
    transform: translate(calc(-50% + var(--joy-x, 0px)), calc(-50% + var(--joy-y, 0px)));
    pointer-events: none;
}

#action-panel {
    grid-column: 3;
    grid-row: 1;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-content: center;
    min-height: 0;
    gap: 7px;
}

.action-button {
    min-height: 43px;
    padding: 5px 8px;
    overflow: hidden;
    border: 1px solid rgba(128, 217, 255, 0.32);
    border-radius: 9px;
    background: linear-gradient(180deg, rgba(30, 74, 101, 0.88), rgba(12, 34, 52, 0.96));
    color: #dff7ff;
    font-size: clamp(0.68rem, 1.5vw, 0.82rem);
    line-height: 1.2;
    text-overflow: clip;
    white-space: normal;
    user-select: none;
    cursor: pointer;
}

.action-button[hidden] {
    /* Keep inventory controls out of classic arena even when the playing
       layout's action-panel rule would otherwise force them back on screen. */
    display: none !important;
}

.action-button:hover,
.action-button:focus-visible {
    border-color: var(--accent);
    background: linear-gradient(180deg, rgba(52, 119, 151, 0.96), rgba(16, 53, 76, 0.98));
    outline: none;
}

.action-button:active,
.action-button[data-active="true"] {
    border-color: #dbf8ff;
    background: linear-gradient(180deg, rgba(84, 179, 218, 0.98), rgba(26, 81, 110, 0.98));
    color: #ffffff;
    transform: translateY(1px);
}

#runtime-log {
    display: none;
    width: min(100%, 1280px);
    max-height: 120px;
    margin: 10px auto 0;
    padding: 8px;
    overflow: auto;
    border: 1px solid rgba(255, 139, 134, 0.28);
    border-radius: 8px;
    background: rgba(6, 13, 21, 0.9);
    color: #ffb6b2;
    font: 0.72rem/1.35 ui-monospace, SFMono-Regular, Consolas, monospace;
    white-space: pre-wrap;
}

#runtime-log[data-visible="true"] {
    display: block;
}

@media (orientation: portrait) and (max-width: 900px) {
    #play-layout {
        display: flex;
        flex-direction: column;
        gap: 10px;
    }

    #game-frame {
        order: 1;
    }

    #control-dock {
        display: grid;
        grid-template-columns: 1fr;
        order: 2;
        gap: 10px;
    }

    #joystick-panel,
    #action-panel {
        grid-column: auto;
        grid-row: auto;
    }

    #action-panel {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }
}

@media (max-width: 720px) {
    #game-shell {
        padding: 10px;
    }

    #brand-row {
        align-items: flex-start;
        flex-direction: column;
        gap: 3px;
    }

    #header-actions {
        width: 100%;
        justify-content: space-between;
    }

    #joystick-panel {
        min-height: 160px;
    }
}

@media (orientation: landscape) {
    html,
    body {
        height: 100%;
        overflow: hidden;
    }

    #game-shell {
        height: 100dvh;
        max-height: 100dvh;
        min-height: 0;
        padding: 8px;
        overflow: hidden;
        display: flex;
        flex-direction: column;
    }

    #play-layout {
        flex: 1 1 auto;
        min-height: 0;
    }

    #game-frame,
    #joystick-panel,
    #action-panel {
        min-height: 0;
    }
}

@media (max-height: 520px) and (orientation: landscape) {
    #game-shell {
        padding: 4px 6px;
    }

    #brand-row {
        margin-bottom: 2px;
        gap: 4px;
    }

    #brand-row h1 {
        font-size: 1.18rem;
    }

    #runtime-status {
        display: none;
    }

    #play-layout {
        grid-template-columns: minmax(94px, 14vw) minmax(0, 1fr) minmax(146px, 23vw);
        gap: 6px;
    }

    .control-panel {
        padding: 4px;
    }

    #telemetry-bar {
        display: none;
    }

    #joystick-panel {
        gap: 2px;
        overflow: hidden;
    }

    #joystick-pad {
        width: min(100%, 27vh);
        min-width: 86px;
        max-width: 108px;
    }

    #action-panel {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 4px;
        overflow: hidden;
    }

    .action-button {
        min-height: 44px;
        padding: 2px 3px;
        font-size: 0.64rem;
        line-height: 1.12;
    }
}

#game-shell:fullscreen {
    display: flex;
    flex-direction: column;
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    max-width: none;
    max-height: none;
    min-height: 0;
    margin: 0;
    padding: env(safe-area-inset-top, 0) env(safe-area-inset-right, 0)
        env(safe-area-inset-bottom, 0) env(safe-area-inset-left, 0);
    overflow: hidden;
    background: #02070b;
}

#game-shell:fullscreen #brand-row,
#game-shell:fullscreen #runtime-status {
    display: none;
}

#game-shell:fullscreen #play-layout {
    flex: 1 1 auto;
    min-height: 0;
    width: 100%;
}

#game-shell:fullscreen #game-frame {
    border: 0;
    border-radius: 0;
    box-shadow: none;
}

#game-shell:fullscreen #play-layout[data-screen="Playing"] {
    width: var(--combat-width, 100%);
    flex: 0 0 auto;
    margin: auto;
}

/* Combat is a clean full-width arena with just the two touch actions. Menus
   regain the complete control dock after the wave ends. */
#play-layout[data-screen="Playing"] {
    position: relative;
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto;
    min-height: 0;
    width: var(--combat-width, 100%);
    flex: 0 0 auto;
    margin: 0 auto;
}

#play-layout[data-screen="Playing"] #game-frame {
    grid-column: 1;
    grid-row: 1;
    width: 100%;
    margin: 0 auto;
}

#play-layout[data-screen="Playing"] #telemetry-bar {
    display: none;
}

#play-layout[data-screen="Playing"] #control-dock {
    position: absolute;
    inset: 0;
    z-index: 2;
    display: block;
    pointer-events: none;
}

#play-layout[data-screen="Playing"] #joystick-panel {
    position: absolute;
    inset: 0 auto 0 0;
    width: 50%;
    min-height: 0;
    padding: 0;
    border: 0;
    border-radius: 0;
    background: transparent;
    pointer-events: auto;
    touch-action: none;
}

#play-layout[data-screen="Playing"] #joystick-label {
    display: none;
}

#play-layout[data-screen="Playing"] #joystick-pad {
    position: absolute;
    left: var(--joy-left, 50%);
    top: var(--joy-top, 72%);
    width: clamp(92px, 14vw, 156px);
    max-width: 42%;
    transform: translate(-50%, -50%);
    opacity: 0.78;
}

#play-layout[data-screen="Playing"] #joystick-panel[data-active="true"] #joystick-pad {
    opacity: 1;
}

#play-layout[data-screen="Playing"] #action-panel {
    position: absolute;
    inset: 0 0 0 auto;
    display: block;
    width: 50%;
    min-height: 0;
    padding: 0;
    border: 0;
    border-radius: 0;
    background: transparent;
    pointer-events: none;
}

#play-layout[data-screen="Playing"] #action-panel .action-button:not(#button-cast-gem) {
    display: none;
}

#play-layout[data-screen="Playing"] #button-cast-gem {
    position: absolute;
    right: 7%;
    bottom: 8%;
    width: clamp(84px, 12vw, 142px);
    min-height: 0;
    aspect-ratio: 1;
    padding: 10px;
    border-radius: 50%;
    background: linear-gradient(180deg, rgba(42, 107, 139, 0.9), rgba(12, 34, 52, 0.94));
    box-shadow: 0 4px 22px rgba(0, 0, 0, 0.36);
    font-size: clamp(0.78rem, 1.4vw, 1rem);
    pointer-events: auto;
}

@media (max-height: 520px) and (orientation: landscape) {
    #play-layout[data-screen="Playing"] #joystick-pad {
        width: clamp(86px, 23vh, 132px);
    }

    #play-layout[data-screen="Playing"] #button-cast-gem {
        width: clamp(76px, 21vh, 118px);
        right: 6%;
        bottom: 7%;
    }
}

/* Browser-native intermission UI. Combat canvas is kept mounted for SDL/WebGL
   lifecycle continuity, while scalable text and actions live in the DOM. */
#menu-stage[hidden] { display: none !important; }
#menu-stage {
    position: absolute;
    inset: 0;
    z-index: 5;
    overflow: auto;
    overscroll-behavior: contain;
    background: radial-gradient(circle at 15% 3%, #17354d, #0a1929 58%, #06111c);
    padding: clamp(12px, 2.7vw, 32px);
    font-family: "Noto Sans SC", "Microsoft YaHei", "PingFang SC", system-ui, sans-serif;
    font-synthesis: none;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}
#play-layout:not([data-screen="Playing"]) {
    position: relative;
    display: block;
    width: 100%;
    max-width: 1280px;
    min-height: 0;
    margin: 0 auto;
}
#play-layout:not([data-screen="Playing"]) #game-frame {
    position: relative;
    display: block;
    width: 100%;
    height: clamp(470px, 77dvh, 760px);
    margin: 0;
    min-height: 0;
}
#play-layout:not([data-screen="Playing"]) #canvas-wrap {
    position: absolute;
    inset: 0;
    height: 100%;
    aspect-ratio: auto;
    /* Never fade an active WebGL canvas to 1% during intermissions.
       Android WebViews can discard its composited surface and return a white
       game layer when the next wave resumes. The menu itself is opaque. */
    opacity: 1;
    pointer-events: none;
}
#graphics-warning[hidden] { display: none !important; }
#graphics-warning {
    position: absolute;
    inset: auto 7% 15%;
    z-index: 12;
    display: grid;
    gap: 12px;
    justify-items: center;
    padding: 16px 20px;
    background: rgba(10, 27, 41, 0.96);
    border: 2px solid #ffcf7e;
    border-radius: 14px;
    box-shadow: 0 4px 36px rgba(0,0,0,.6);
    color: #fff1cc;
    text-align: center;
    font-size: clamp(.82rem, 2vw, 1.1rem);
}
#graphics-reload {
    border: 1px solid #8cebd8;
    background: #244b55;
    color: white;
    padding: 9px 14px;
    border-radius: 9px;
    cursor: pointer;
}
#play-layout:not([data-screen="Playing"]) #control-dock { display: none !important; }
#play-layout:not([data-screen="Playing"]) #telemetry-bar { display: none; }
#play-layout:not([data-screen="Playing"]) #game-version {
    z-index: 7;
    left: auto;
    right: 8px;
    transform: none;
    background: #091725;
}
.ui-panel {
    width: min(100%, 980px);
    margin: 0 auto;
    color: #f1f8ff;
    padding-bottom: 32px;
}
.ui-title {
    margin: 14px 0 5px;
    font-size: clamp(1.5rem, 3.5vw, 2.25rem);
    font-weight: 750;
    letter-spacing: 0.02em;
    line-height: 1.25;
}
.ui-lead { margin: 0 0 17px; color: #bad0de; font-size: clamp(0.88rem, 1.8vw, 1rem); line-height: 1.55; }
.ui-summary, .ui-result-stats {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}
.ui-summary { border-bottom: 1px solid rgba(128, 217, 255, 0.15); padding: 3px 0 13px; }
.ui-stat {
    display: flex;
    flex-direction: column;
    gap: 3px;
    min-width: 80px;
    padding: 5px 11px;
    border-radius: 9px;
    background: rgba(62, 113, 144, 0.2);
}
.ui-stat-name { color: #a9c5d7; font-size: 0.74rem; }
.ui-stat-value { color: #f3fbff; font-size: 1rem; font-variant-numeric: tabular-nums; }
.ui-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 210px), 1fr));
    gap: clamp(9px, 1.5vw, 16px);
}
.ui-choice, .ui-button {
    appearance: none;
    -webkit-appearance: none;
    border: 1px solid #45657a;
    border-radius: 14px;
    background: linear-gradient(145deg, #18384e, #0d2134);
    box-shadow: 0 7px 20px rgba(0, 0, 0, 0.22);
    padding: 17px;
    text-align: left;
    color: #eff9ff;
    font: 700 clamp(1rem, 2vw, 1.25rem)/1.4 "Noto Sans SC", "Microsoft YaHei", system-ui, sans-serif;
    cursor: pointer;
    touch-action: manipulation;
    white-space: normal;
    overflow-wrap: anywhere;
}
.ui-choice { display: flex; flex-direction: column; gap: 8px; min-height: 110px; }
.ui-caption { color: #b5ccda; font-size: clamp(0.83rem, 1.5vw, 0.96rem); font-weight: 400; line-height: 1.5; }
.ui-choice:hover, .ui-button:hover, .ui-choice:focus-visible, .ui-button:focus-visible {
    outline: 2px solid #8cdfff; outline-offset: -2px; background: #24465d;
}
.ui-choice:active, .ui-button:active { transform: translateY(1px); }
.ui-choice[data-selected="true"] { border-color: #78eed4; box-shadow: inset 0 0 0 1px #78eed4; }
.ui-choice:disabled, .ui-button:disabled { opacity: .48; cursor: not-allowed; box-shadow: none; }
.ui-choice-character { position: relative; min-height: 150px; padding-top: 24px; }
.ui-cell-mark { position: absolute; right: 17px; top: 10px; font-size: 2rem; color: #8acbe8; }
.ui-macro { color: #ffc779; }
.ui-gem-choice { min-height: 102px; border-color: #517e9b; }
.ui-gem-card { min-width: 0; padding: 8px; border: 1px solid #33536c; border-radius: 15px; }
.ui-gem-card .ui-gem-choice { width: 100%; }
.ui-gem-card[data-swap-source="true"] { border-color: #f2cc77; }
.ui-gem-card .ui-toolbar { margin-top: 8px; }
.ui-gem-card .ui-button { flex: 1 1 120px; padding: 9px; }
.ui-gem-preview { margin-top: 14px; padding: 12px 16px; border: 1px solid #426780; border-radius: 12px; background: #102a3d; }
.ui-gem-preview h3 { margin: 0 0 7px; color: #f6d794; font-size: 1rem; }
.ui-gem-preview-text { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.6; color: #d8e9f4; }
.ui-gem-swap-preview { border-color: #b79553; }
.ui-shop-choice { min-height: 115px; }
.ui-toolbar { display: flex; flex-wrap: wrap; align-items: stretch; gap: 10px; margin-top: 19px; }
.ui-button { min-height: 46px; padding: 11px 19px; font-size: .95rem; text-align: center; }
.ui-button-primary { color: #071925; border-color: #83eacf; background: #8cebd8; }
.ui-button-primary:hover, .ui-button-primary:focus-visible { color: #061522; background: #b1fbe9; }
.ui-button .ui-caption { display: block; color: inherit; opacity: .82; margin-top: 3px; }
.ui-button-secondary { background: #183345; }
.ui-feedback { color: #f9d495; margin: 11px 0 0; font-size: .9rem; }
.ui-hint { margin: 15px 0 0; color: #9fb8c9; font-size: .8rem; line-height: 1.5; }
.ui-result-stats { margin-top: 18px; }
.ui-result-stats .ui-stat { min-width: 116px; padding: 14px; }
@media (max-width: 720px) {
    #menu-stage { padding: 12px; }
    .ui-panel { padding-bottom: 38px; }
    .ui-cards { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; }
    .ui-choice { padding: 12px; min-height: 98px; font-size: 1rem; }
    .ui-choice-character { min-height: 140px; }
    .ui-caption { font-size: .84rem; }
    .ui-title { margin-top: 9px; }
    .ui-stat { min-width: 62px; padding: 4px 8px; }
}
@media (max-width: 380px) {
    .ui-cards { grid-template-columns: 1fr; }
    .ui-choice { min-height: 77px; }
}
@media (orientation: landscape) {
    #play-layout:not([data-screen="Playing"]) {
        flex: 1 1 auto;
        height: 100%;
        min-height: 0;
    }
    #play-layout:not([data-screen="Playing"]) #game-frame {
        height: 100%;
        min-height: 0;
    }
    #menu-stage { padding: clamp(9px, 2vw, 26px); }
}
@media (max-height: 500px) and (orientation: landscape) {
    .ui-title { font-size: 1.42rem; margin: 8px 0 3px; }
    .ui-lead { margin-bottom: 8px; }
    .ui-summary { padding-bottom: 7px; }
    .ui-choice { min-height: 90px; padding: 10px 12px; }
    .ui-toolbar { margin-top: 10px; }
    .ui-hint { margin-top: 7px; }
}

#menu-fullscreen-exit { display: none; position: absolute; top: 9px; right: 9px;
  z-index: 8; padding: 6px 12px; border: 1px solid #477590; border-radius: 7px;
  background: #183b52; color: #f3fbff; font: 700 .85rem/1.4 system-ui, sans-serif;
  cursor: pointer; }
#game-shell:fullscreen #play-layout:not([data-screen="Playing"]) #menu-fullscreen-exit { display: block; }

/* Browser combat HUD: sharp system fonts; SDL draws game-world only. */
#combat-hud {
    display: none;
    position: absolute;
    inset: 0 0 auto;
    z-index: 2;
    padding: clamp(8px, 1.5vw, 20px);
    justify-content: space-between;
    gap: 8px;
    pointer-events: none;
    color: #f6fcff;
    font: 650 clamp(12px, 1.3vw, 17px)/1.45 "Noto Sans SC", system-ui, sans-serif;
    text-shadow: 0 1px 3px rgba(0,0,0,.85);
}
#play-layout[data-screen="Playing"] #combat-hud { display: flex; }
.hud-left, .hud-right {
    display: flex; flex-direction: column; gap: 4px;
    padding: clamp(7px, 1vw, 11px);
    border: 1px solid rgba(130, 212, 244, .25);
    border-radius: 10px;
    background: rgba(5, 17, 30, .75);
}
.hud-right { text-align: right; align-items: flex-end; }
.hud-charge { width: clamp(72px, 14vw, 180px); }
.hud-charge-track { margin-top: 4px; height: 6px; background: rgba(94, 114, 134, .55); border-radius: 9px; overflow: hidden; }
#hud-charge-fill { height: 100%; width: 0; background: #77daff; border-radius: inherit; }
#telemetry-bar { display: none; }
body[data-debug="true"] #play-layout:not([data-screen="Playing"]) #telemetry-bar { display: flex; }
@media (max-height: 460px) and (orientation: landscape) {
    #combat-hud { padding: 5px 9px; font-size: 12px; line-height: 1.25; }
    .hud-left, .hud-right { padding: 4px 7px; gap: 1px; }
    .hud-charge-track { height: 4px; }
}
@media (orientation: portrait) and (max-width: 480px) {
    #combat-hud { padding: 5px; font-size: 11px; }
    .hud-left, .hud-right { padding: 4px; gap: 1px; }
}

/* v0.3 opt-in hunting controls: left-half touch activates a truly floating
   stick. The invisible hit area stays interactive; only the artwork hides. */
#play-layout[data-screen="Playing"] #joystick-panel[data-active="false"] #joystick-pad {
    opacity: 0 !important;
}
#play-layout[data-screen="Playing"] #joystick-panel[data-active="true"] #joystick-pad {
    opacity: 0.95 !important;
}
#play-layout[data-screen="Playing"] #button-cast-gem {
    --skill-angle: 0deg;
    border: 0;
    background:
        radial-gradient(circle closest-side, #17384b 88%, transparent 90%),
        conic-gradient(from 0deg, var(--skill-ring, #67bcde) var(--skill-angle),
            rgba(81, 115, 130, 0.68) var(--skill-angle));
    box-shadow: 0 3px 19px rgba(0, 0, 0, .45);
    color: #e8fcff;
    text-shadow: 0 1px 2px #0c1e2a;
    padding: 13px;
    font-weight: 800;
    white-space: normal;
}
#play-layout[data-screen="Playing"] #button-cast-gem[data-ready="true"] {
    --skill-ring: #7befc6;
    box-shadow: 0 0 17px rgba(96, 230, 195, .4);
}
#play-layout[data-screen="Playing"] #button-cast-gem[data-busy="true"] {
    --skill-ring: #f5bf7d;
}
#hunt-radar[hidden], #immunity-hud[hidden] { display: none !important; }
#hunt-radar {
    position: absolute;
    z-index: 3;
    top: 8px;
    right: 10px;
    width: clamp(120px, 17vw, 170px);
    padding: 5px;
    border-radius: 11px;
    border: 1px solid rgba(113, 212, 218, .45);
    background: rgba(7, 25, 35, .85);
    box-shadow: 0 2px 12px rgba(0,0,0,.45);
    pointer-events: none;
}
#radar-canvas { width: 100%; height: auto; display: block; aspect-ratio: 1; }
.radar-caption {
    color: #cbe9e3; display: block; text-align: center;
    font: 600 10px/1.3 system-ui, sans-serif;
}
#immunity-hud { display: flex; gap: 5px; align-items: center; }
#immunity-rings { width: 57px; height: 57px; flex: 0 0 auto; }
.immunity-ring { transform: rotate(-90deg); transform-origin: 38px 38px; }
#immunity-label { font-size: 11px; line-height: 1.35; }
#surge-warning-layer,
#surge-warning-layer[hidden] {
    position: absolute;
    inset: 0;
    z-index: 6;
    pointer-events: none;
}
#surge-warning-layer[hidden] { display: none !important; }
.surge-warning-countdown {
    position: absolute;
    min-width: 156px;
    padding: 6px 12px;
    transform: translate(-50%, -50%);
    border: 2px solid #ff983f;
    border-radius: 5px;
    background: rgba(30, 19, 13, .94);
    box-shadow: 0 0 16px rgba(255, 132, 40, .46);
    color: #fff0cc;
    font: 800 20px/1.25 system-ui, "Noto Sans SC", sans-serif;
    letter-spacing: .02em;
    text-align: center;
    white-space: nowrap;
}
.surge-warning-markers { position: absolute; inset: 0; }
.surge-warning-marker {
    position: absolute;
    display: grid;
    place-items: center;
    width: 44px;
    height: 44px;
    transform: translate(-50%, -50%);
    border: 3px solid #ff9a42;
    border-radius: 50%;
    background: rgba(49, 23, 10, .94);
    box-shadow: 0 0 0 3px rgba(255, 195, 104, .22), 0 0 18px rgba(255, 115, 28, .64);
    color: #fff1bf;
    font: 900 30px/1 system-ui, "Noto Sans SC", sans-serif;
    text-shadow: 0 1px 3px #241108;
}
.surge-warning-arrow { display: block; transform: translateY(-1px); }
#play-layout[data-screen="Playing"] #combat-hud .hud-right {
    margin-right: 0;
}
#play-layout[data-screen="Playing"] #hunt-radar:not([hidden]) ~ #menu-stage { pointer-events: none; }

/* v0.6 Hunt preparation/inventory screens.  These controls are deliberately
   compact so the same DOM remains usable at the 844x390 mobile viewport. */
.ui-inventory-status { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0 15px; }
.ui-inventory-status .ui-stat { min-width: 100px; }
.ui-inventory-filters {
    display: flex; flex-wrap: wrap; align-items: end; gap: 8px;
    padding: 10px; margin: 12px 0; border: 1px solid rgba(128,217,255,.2);
    border-radius: 12px; background: rgba(8,27,42,.62);
}
.ui-filter, .ui-quantity-picker { display: grid; gap: 4px; min-width: 88px; }
.ui-filter-label { color: #a9c5d7; font-size: .72rem; }
.ui-filter select, .ui-quantity-input {
    min-height: 33px; padding: 5px 7px; border: 1px solid #45657a; border-radius: 7px;
    background: #102b40; color: #eff9ff; font: inherit;
}
.ui-quantity-picker { display: flex; flex-wrap: wrap; align-items: center; gap: 5px; }
.ui-quantity-button {
    appearance: none; border: 1px solid #45657a; border-radius: 7px; padding: 6px 9px;
    background: #16384e; color: #eff9ff; cursor: pointer; font: 700 .78rem/1.1 system-ui,sans-serif;
}
.ui-quantity-button[data-selected="true"] { border-color: #7be9d0; background: #205e63; }
.ui-quantity-input { width: 64px; }
.ui-item-card {
    display: flex; flex-direction: column; gap: 5px; min-height: 135px; padding: 13px;
    border: 1px solid #385a70; border-radius: 12px; background: linear-gradient(145deg,#17384e,#0e2235);
}
.ui-item-card[data-item-key$=":1"] { border-color: #6784a0; }
.ui-item-title, .ui-section-title { margin: 0; color: #edfbff; font-size: 1rem; }
.ui-item-detail, .ui-item-effect { margin: 0; color: #b9d0dd; font-size: .78rem; line-height: 1.45; }
.ui-item-effect { color: #8fd9ca; }
.ui-item-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: auto; }
.ui-item-actions .ui-button { min-height: 35px; padding: 7px 9px; border-radius: 8px; font-size: .78rem; }
.ui-button-danger { border-color: #a96569; background: #472936; }
.ui-empty { min-height: 70px; padding: 20px; color: #a9c5d7; border: 1px dashed #45657a; border-radius: 10px; }
.ui-inventory-section { margin-top: 13px; }
.ui-section-heading { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 13px 0 8px; }
.ui-toolbar-tight { margin: 0; }
.ui-equipment-grid, .ui-socket-grid { display: grid; grid-template-columns: repeat(auto-fit,minmax(155px,1fr)); gap: 8px; }
.ui-equipment-slot, .ui-socket-slot {
    display: flex; flex-direction: column; gap: 7px; min-height: 91px; padding: 10px;
    border: 1px solid #385a70; border-radius: 10px; background: rgba(21,51,71,.65);
}
.ui-equipment-slot[data-selected="true"], .ui-socket-slot[data-selected="true"] {
    border-color: #7be9d0; box-shadow: inset 0 0 0 1px #7be9d0;
}
.ui-slot-label { color: #a9c5d7; font-size: .76rem; }
.ui-slot-value { min-height: 22px; color: #eff9ff; font-size: .8rem; line-height: 1.35; }
.ui-stats-breakdown { margin: 12px 0; overflow-x: auto; }
.ui-stat-table { min-width: 500px; border: 1px solid rgba(128,217,255,.2); border-radius: 10px; overflow: hidden; }
.ui-stat-row { display: grid; grid-template-columns: minmax(108px,1.2fr) repeat(4,minmax(65px,1fr)); gap: 5px; padding: 8px 10px; border-top: 1px solid rgba(128,217,255,.12); color: #dcebf4; font-size: .82rem; }
.ui-stat-row:first-child { border-top: 0; }
.ui-stat-row:nth-child(even) { background: rgba(28,66,87,.3); }
.ui-stat-header { color: #93bacd; font-size: .72rem; }
.ui-derived-stats { margin: 10px 0; }
.ui-warning { margin: 9px 0; padding: 8px 10px; border: 1px solid #d9a35f; border-radius: 8px; background: rgba(78,51,20,.48); color: #ffe1a5; font-size: .82rem; }
.ui-muted { color: #9db2bf; }
#hud-inventory-counts { color: #a8eddd; }
#hud-pickup-notices { display: grid; gap: 3px; min-width: 125px; max-width: 190px; }
.pickup-notice { padding: 3px 7px; border-radius: 5px; background: rgba(9,32,45,.88); font: 700 11px/1.25 system-ui,"Noto Sans SC",sans-serif; }
.pickup-notice-kind-0 { color: #ffe39d; }
.pickup-notice-kind-1 { color: #ffaaa3; }
.pickup-notice-kind-2 { color: #8debd2; }
.pickup-notice-kind-3 { color: #d8b7ff; }
.pickup-notice-kind-4 { color: #9edbff; }
[data-inventory-open] { display: none; }
#play-layout[data-screen="Playing"] #action-panel .action-button[data-inventory-open]:not(#button-cast-gem) {
    display: block; position: relative; z-index: 4; pointer-events: auto;
    width: min(92px, 22vw); margin: 8px 8px 0 auto; min-height: 34px;
    padding: 6px 8px; border-radius: 9px; font-size: .74rem;
}
@media (max-width: 700px) {
    .ui-inventory-filters { gap: 6px; padding: 8px; }
    .ui-filter { min-width: 76px; }
    .ui-filter select, .ui-quantity-input { min-height: 30px; font-size: .78rem; }
    .ui-item-card { min-height: 120px; padding: 10px; }
    .ui-item-actions .ui-button { padding: 6px 7px; font-size: .72rem; }
    .ui-stat-row { padding: 7px 8px; }
}
@media (max-height: 520px) and (orientation: landscape) {
    .ui-panel { padding-bottom: 18px; }
    .ui-title { margin-top: 4px; }
    .ui-lead { margin-bottom: 8px; }
    .ui-choice { min-height: 70px; }
    .ui-item-card { min-height: 100px; }
    .ui-inventory-filters { margin: 7px 0; padding: 6px; }
}
#mode-switch {
    display: inline-block; border: 1px solid #44798a; border-radius: 7px;
    padding: 6px 10px; color: #a8ecde; text-decoration: none;
    font: 600 12px/1.2 system-ui,sans-serif;
}
#mode-switch:hover { background: #1c4050; }
@media (max-height: 500px) and (orientation: landscape) {
    #hunt-radar { width: clamp(105px, 29vh, 142px); top: 4px; right: 5px; }
    #immunity-rings { width: 43px; height: 43px; }
    #play-layout[data-screen="Playing"] #combat-hud .hud-right { margin-right: 0; }
    #play-layout[data-screen="Playing"] #combat-hud .hud-right #hud-kills,
    #play-layout[data-screen="Playing"] #combat-hud .hud-right #hud-materials {
        max-width: 95px;
    }
}

/* v0.7 switch control is separate from Q and the movement touch area. */
#hud-weapons { color: #d8f7f0; font-size: clamp(9px, 1.15vw, 12px); line-height: 1.35; }
#hud-weapons [data-active="false"] { color: #9fbbcf; }
#hud-weapons[hidden], #button-switch-weapon[hidden] { display: none !important; }
#play-layout[data-screen="Playing"] #action-panel #button-switch-weapon:not([hidden]) {
    display: block; position: absolute; z-index: 5; pointer-events: auto;
    /* Keep the switch affordance to the left of the stacked backpack/stats
       buttons on narrow touch layouts; their width is min(92px, 22vw). */
    right: calc(7% + min(92px, 22vw) + 14px);
    bottom: calc(8% + clamp(84px, 12vw, 142px) + 10px); width: 108px; min-height: 46px;
    margin: 0; padding: 7px; border-radius: 12px; font-size: .75rem;
    background: #204c5f; border: 2px solid #7bbbcf; color: #e8fcff;
}
.ui-weapon-setup { margin: 12px 0; padding: 10px; border: 1px solid #497588; border-radius: 12px; }
.ui-weapon-setup .ui-cards { grid-template-columns: repeat(2,minmax(0,1fr)); }
.ui-weapon-setup .ui-item-card[data-active="true"] { border-color: #83eacb; }
.ui-weapon-growth { margin: 14px 0; padding: 10px; border: 1px solid #497588; border-radius: 12px; }
.ui-growth-mastery { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 7px; margin: 8px 0; }
.ui-growth-mastery .ui-stat { min-width: 0; }
.ui-weapon-growth-grid { grid-template-columns: repeat(auto-fit,minmax(220px,1fr)); }
.ui-weapon-item { min-height: 145px; }
.ui-weapon-item .ui-item-title { font-size: .88rem; line-height: 1.35; }
.ui-weapon-item[data-locked="true"] { border-color: #f4c95d; }
.ui-weapon-growth .ui-toolbar { flex-wrap: wrap; }
.ui-weapon-growth .ui-item-actions { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 8px; }
.ui-weapon-growth .ui-item-actions .ui-button { min-width: 72px; }
.ui-weapon-replacement { max-width: 100%; min-width: 0; flex: 1 1 160px; }
.ui-weapon-growth .ui-inventory-status { color: #a8eddd; }
@media (max-width: 700px) {
    .ui-growth-mastery { grid-template-columns: 1fr; }
    .ui-weapon-growth-grid { grid-template-columns: 1fr; }
}
@media (max-height: 520px) and (orientation: landscape) {
    #play-layout[data-screen="Playing"] #action-panel #button-switch-weapon:not([hidden]) {
        bottom: calc(7% + clamp(76px, 21vh, 118px) + 8px); width: 86px; min-height: 36px; font-size: .66rem;
    }
}
