/* Every interface surface follows the compact monochrome player frame. */
:root {
  color-scheme: dark;
  --font: "Cascadia Mono", Consolas, Menlo, "DejaVu Sans Mono", monospace;
  --ink: #e3e8e4;
  --muted: #bdc6c0;
  --quiet: #89958e;
  --line: #46524b;
  --frame: #c3ccc6;
  --surface: rgba(6, 9, 10, 0.88);
  --solid: #080c0d;
  --hover: #202824;
  --accent: #eef2ee;
  --health: var(--ink);
  --stamina: var(--ink);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #05060a; }
body { color: var(--ink); font: 12px/1.4 var(--font); }
button, input, select, kbd, pre { font: inherit; }
button, summary { -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; touch-action: manipulation; }
pre { margin: 0; }
[hidden] { display: none !important; }
:is(button, summary, input, select, [tabindex]):focus-visible { outline: 1px solid var(--accent); outline-offset: 3px; }
#screen:focus-visible { outline: none; }
button:disabled { cursor: default; opacity: 0.45; }
kbd { color: var(--ink); white-space: nowrap; }
kbd::before { content: "["; color: var(--quiet); }
kbd::after { content: "]"; color: var(--quiet); }
::selection { color: var(--solid); background: var(--ink); }
#screen { position: fixed; inset: 0; display: block; width: 100%; height: 100%; touch-action: none; }
#screen.projectile-aiming { cursor: crosshair; }
#hud-root, #inventory-root { position: fixed; inset: 0; pointer-events: none; }
#hud-root { z-index: 10; }
#inventory-root { z-index: 30; }
.hud { position: absolute; inset: 0; pointer-events: none; transition: opacity 120ms; }
.hud-panel { position: absolute; }

/* Player and party cards retain the reference's proportions. */
.hud-frames { top: max(12px, env(safe-area-inset-top)); left: max(12px, env(safe-area-inset-left)); width: 244px; display: flex; flex-direction: column; gap: 6px; pointer-events: auto; }
.hud-frame { padding: 5px 8px 6px; color: var(--ink); background: var(--surface); border: 1px solid var(--frame); font-size: 12px; }
.hud-name { margin: 0 0 3px; font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hud-vital { display: grid; grid-template-columns: 18px 1fr 64px; align-items: center; gap: 6px; margin-top: 1px; }
.hud-vital-label, .hud-vital-value { font-size: 11px; font-variant-numeric: tabular-nums; }
.hud-vital-value { text-align: right; }
.hud-vital-bar { display: block; height: 8px; background: repeating-linear-gradient(90deg, #343b38 0 3px, transparent 3px 4px); }
.hud-vital-filled { display: block; height: 100%; background: repeating-linear-gradient(90deg, var(--accent) 0 3px, transparent 3px 4px); }
.hud-frame-note, #carried-item.hud-frame-note { position: static; max-width: none; margin-top: 3px; padding: 0; color: var(--muted); background: none; border: 0; font: 11px/1.4 var(--font); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hud-frame-note:empty { display: none; }
.hud-party { display: flex; flex-direction: column; gap: 6px; }
.hud-party:empty { display: none; }
.hud-party-tab { align-self: flex-start; padding: 1px 6px; background: var(--surface); border: 1px solid var(--frame); font-size: 11px; }

/* Quick slots form one framed instrument with a shared caption. */
.hud-hotbar-wrap { position: absolute; left: 50%; bottom: max(12px, env(safe-area-inset-bottom)); transform: translateX(-50%); display: grid; grid-template-columns: auto 54px; gap: 6px 8px; padding: 6px 8px 8px; background: var(--surface); border: 1px solid var(--frame); }
.hud-hotbar-heading { grid-column: 1 / -1; display: flex; justify-content: space-between; align-items: baseline; gap: 16px; padding-bottom: 5px; border-bottom: 1px solid var(--line); }
.hud-selected-item { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; font-size: 11px; font-weight: 600; }
.hud-quick-hint { color: var(--quiet); font-size: 10px; white-space: nowrap; }
.hud-hotbar { display: grid; grid-template-columns: repeat(9, 48px); gap: 4px; }
.hud-slot, .hud-inventory-button { position: relative; display: grid; place-items: center; width: 48px; height: 54px; padding: 0; color: var(--muted); background: transparent; border: 1px solid var(--line); border-radius: 0; pointer-events: auto; }
.hud-slot:hover, .hud-inventory-button:hover { color: var(--ink); background: var(--hover); border-color: var(--frame); }
.hud-slot.selected { color: var(--solid); background: var(--ink); border-color: var(--ink); }
.hud-slot.empty { border-style: dotted; }
.hud-slot.empty::after { content: "·"; color: var(--quiet); }
.hud-slot-number { position: absolute; top: 3px; left: 4px; font-size: 9px; line-height: 1; }
.hud-slot-glyph { width: 11ch; margin-top: 1px; font-size: 4.8px; line-height: 4.8px; text-align: left; white-space: pre; }
.hud-slot-count { position: absolute; right: 3px; bottom: 3px; font-size: 9px; line-height: 1; }
.hud-slot-state { position: absolute; left: 4px; bottom: 2px; font-size: 10px; line-height: 1; }
.hud-inventory-button { width: 54px; align-content: center; gap: 3px; border-color: var(--frame); }
.hud-inventory-glyph { font-size: 5px; line-height: 5px; }
.hud-inventory-label { font-size: 9px; }
.hud-inventory-key { position: absolute; top: 3px; left: 4px; font-size: 9px; }
.hud-toasts { display: grid; gap: 4px; }
.hud-toast { padding: 5px 8px; background: var(--surface); border: 1px solid var(--line); font-size: 11px; overflow-wrap: anywhere; }
.hud-toast[data-kind="error"], .hud-toast[data-kind="damage"] { border-color: var(--frame); border-left-width: 3px; }
.hud-damage-layer { position: absolute; inset: 0; overflow: hidden; pointer-events: none; }
.hud-damage { position: absolute; color: var(--accent); font-size: 14px; font-weight: 600; text-shadow: 1px 1px #000, -1px -1px #000; white-space: nowrap; }
/* A wounded enemy's health: the status frame's segmented bar on its own. */
.hud-foe { position: absolute; left: 0; top: 0; width: 64px; height: 6px; filter: drop-shadow(0 0 1px #000) drop-shadow(0 0 1px #000); }
.hud-prompt { position: absolute; left: 50%; bottom: max(144px, calc(env(safe-area-inset-bottom) + 144px)); transform: translateX(-50%); max-width: calc(100% - 24px); padding: 4px 8px; background: var(--surface); border: 1px solid var(--frame); text-align: center; }
#hint { position: fixed; z-index: 5; left: 50%; bottom: max(112px, calc(env(safe-area-inset-bottom) + 112px)); transform: translateX(-50%); width: max-content; max-width: calc(100% - 24px); padding: 4px 8px; color: var(--muted); background: var(--surface); border: 1px solid var(--line); font-size: 11px; text-align: center; pointer-events: none; transition: opacity 1.5s; }
#hint.hidden { opacity: 0; }
#fire-status { position: fixed; z-index: 11; left: 50%; bottom: max(180px, calc(env(safe-area-inset-bottom) + 180px)); transform: translateX(-50%); max-width: calc(100% - 24px); padding: 5px 8px; background: var(--surface); border: 1px solid var(--frame); text-align: center; pointer-events: none; opacity: 0; transition: opacity 150ms; }
#fire-status.visible { opacity: 1; }
#carried-item { color: var(--muted); }
#status { position: fixed; z-index: 40; inset: 35% 20px auto; max-width: 440px; margin: auto; padding: 12px; background: var(--solid); border: 1px solid var(--frame); text-align: center; }

/* Utility panels share the player card's surface, type and hairline. */
#panel-dock { position: fixed; z-index: 15; top: max(12px, env(safe-area-inset-top)); right: max(12px, env(safe-area-inset-right)); display: flex; flex-direction: column; align-items: flex-end; gap: 4px; max-width: calc(100% - 24px); max-height: calc(100dvh - 24px); overflow-y: auto; overscroll-behavior: contain; scrollbar-width: thin; scrollbar-color: var(--line) var(--solid); pointer-events: none; }
#panel-dock > details { flex: 0 0 auto; max-width: 100%; color: var(--ink); background: var(--surface); border: 1px solid var(--frame); pointer-events: auto; }
#panel-dock > details[open] { width: 292px; background: rgba(6, 9, 10, 0.97); }
#panel-dock summary { padding: 5px 8px; font-size: 11px; font-weight: 500; cursor: pointer; list-style: none; user-select: none; }
#panel-dock summary::-webkit-details-marker { display: none; }
#panel-dock summary::before { content: "+ "; color: var(--quiet); }
#panel-dock details[open] > summary::before { content: "− "; color: var(--ink); }
#panel-dock > details[open] > summary { border-bottom: 1px solid var(--line); }
#panel-dock summary:hover { background: var(--hover); }
#panel-dock summary kbd { margin-left: 8px; font-size: 10px; }
#panel-dock button { min-height: 28px; padding: 4px 7px; color: var(--ink); background: transparent; border: 1px solid var(--line); border-radius: 0; font-size: 11px; }
#panel-dock button:hover:not(:disabled) { background: var(--hover); border-color: var(--frame); }
#panel-dock button[aria-pressed="true"] { color: var(--solid); background: var(--ink); border-color: var(--ink); }
#panel-dock :is(input:not([type="range"]), select) { width: 100%; min-height: 28px; padding: 4px 6px; color: var(--ink); background: var(--solid); border: 1px solid var(--line); border-radius: 0; font-size: 11px; }
input[type="range"] { appearance: none; height: 16px; margin: 0; background: transparent; cursor: pointer; }
input[type="range"]::-webkit-slider-runnable-track { height: 4px; border: 1px solid var(--line); background: var(--solid); }
input[type="range"]::-webkit-slider-thumb { appearance: none; width: 6px; height: 12px; margin-top: -5px; border: 0; border-radius: 0; background: var(--ink); }
input[type="range"]::-moz-range-track { height: 2px; border: 1px solid var(--line); background: var(--solid); }
input[type="range"]::-moz-range-thumb { width: 6px; height: 12px; border: 0; border-radius: 0; background: var(--ink); }
.builder-panel { padding: 8px; }
.builder-intro { margin: 0 0 8px; color: var(--quiet); font-size: 11px; }
#scenery-builder .builder-mode { width: 100%; border-color: var(--frame); }
.builder-tools, .builder-files { min-width: 0; margin: 10px 0 0; padding: 0; border: 0; }
#scenery-builder legend { padding: 0 0 5px; color: var(--muted); font-size: 11px; font-weight: 600; }
.builder-tool-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 4px; }
.builder-tool-grid button { text-align: left; white-space: nowrap; }
.builder-tool-grid button span { display: inline-block; width: 12px; text-align: center; }
.builder-tool-grid button[data-tool="erase"] { grid-column: span 2; }
.builder-prop-group + .builder-prop-group { margin-top: 8px; }
.builder-prop-group h3 { margin: 0 0 4px; color: var(--quiet); font-size: 10px; font-weight: 400; }
.builder-prop-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.builder-settings { display: grid; gap: 4px; margin: 10px 0; font-size: 11px; }
.builder-settings label { display: flex; justify-content: space-between; gap: 10px; }
.builder-settings output { font-variant-numeric: tabular-nums; }
.builder-settings input { width: 100%; margin-bottom: 4px; }
.builder-history { display: grid; grid-template-columns: 1fr 1fr 1.4fr; gap: 4px; }
.builder-file-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 4px; }
.builder-controls { margin: 10px 0 8px; color: var(--quiet); font-size: 10px; }
#builder-status { display: block; padding-top: 8px; border-top: 1px solid var(--line); font-size: 11px; overflow-wrap: anywhere; }
#builder-banner { position: fixed; z-index: 11; top: 126px; left: 12px; padding: 5px 8px; background: var(--surface); border: 1px solid var(--frame); pointer-events: none; }
#builder-banner span { display: block; color: var(--quiet); font-size: 11px; }
#builder-cursor { position: fixed; z-index: 4; width: 24px; height: 24px; border: 1px solid var(--ink); border-radius: 50%; background: #e3e8e40a; transform: translate(-50%, -50%); pointer-events: none; }
#audio-controls > :not(summary), #weather-panel > :not(summary), #multiplayer-controls > :not(summary), #help-controls > :not(summary) { margin: 8px; }
#audio-controls label, #weather-panel label { display: grid; grid-template-columns: 64px minmax(0, 1fr) 30px; align-items: center; gap: 8px; font-size: 11px; }
#audio-controls input, #weather-panel input { width: 100%; min-width: 0; }
#audio-controls output, #weather-panel output { color: var(--quiet); text-align: right; font-variant-numeric: tabular-nums; }
#audio-controls p, #weather-panel p { color: var(--muted); font-size: 11px; }
#audio-controls #audio-status { color: var(--quiet); }
#weather-panel .weather-controls + .weather-controls { padding-top: 8px; border-top: 1px solid var(--line); }
#weather-panel .weather-controls > label[for] { display: block; margin-bottom: 5px; color: var(--quiet); }
#weather-panel .weather-controls p { margin: 6px 0; }
#weather-panel .weather-controls button { margin-top: 5px; }
#audio-weather, #audio-season { margin-bottom: 6px; }
#multiplayer-controls p { font-size: 11px; }
#multiplayer-controls label { display: block; margin: 8px 0 4px; color: var(--muted); font-size: 11px; }
#lobby-code { text-transform: uppercase; letter-spacing: 3px; }
.lobby-actions { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 8px; }
.lobby-actions button { flex: 1; }
.lobby-server-settings { margin-top: 10px; padding-top: 5px; border-top: 1px solid var(--line); }
#panel-dock .lobby-server-settings summary { padding: 4px 0; color: var(--quiet); }
#multiplayer-controls .lobby-label { margin-top: 10px; color: var(--quiet); }
#multiplayer-status[data-state="error"] { border-left: 2px solid var(--frame); padding-left: 6px; }
#lobby-room-code { display: block; font-size: 20px; letter-spacing: 4px; user-select: all; }
#lobby-share { margin-top: 8px; }
#lobby-players { list-style: none; padding: 0; margin: 4px 0 8px; }
#lobby-players li { margin: 4px 0; overflow-wrap: anywhere; }
#lobby-players li::before { content: "> "; color: var(--quiet); }
.control-list { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 6px 12px; padding: 0; font-size: 11px; }
.control-list dt { color: var(--ink); }
.control-list dd { margin: 0; color: var(--muted); }
.controls-note { padding-top: 8px; border-top: 1px solid var(--line); color: var(--quiet); font-size: 10px; }

/* The inventory is a larger member of the same framed panel family. */
#inventory-root::before { content: ""; position: absolute; inset: 0; background: #0205059c; opacity: 0; transition: opacity 120ms; }
#inventory-root.is-open::before { opacity: 1; }
.inventory-open .hud { opacity: 0.2; }
.inventory-open .hud button { pointer-events: none; }
.inventory-open :is(#panel-dock, #touch-controls) { visibility: hidden; }
.inventory-open :is(#hint, #fire-status) { opacity: 0; }
.inventory-screen { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); width: min(740px, calc(100% - 32px)); max-height: calc(100dvh - 32px); padding: 10px; overflow: auto; overscroll-behavior: contain; scrollbar-width: thin; scrollbar-color: var(--line) var(--solid); color: var(--ink); background: rgba(6, 9, 10, 0.97); border: 1px solid var(--frame); font-size: 11px; pointer-events: auto; }
.inventory-header { position: sticky; top: 0; z-index: 2; display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 10px; padding-bottom: 8px; background: var(--solid); border-bottom: 1px solid var(--line); }
.inventory-identity { display: flex; align-items: baseline; gap: 12px; min-width: 0; }
.inventory-title { margin: 0; font-size: 13px; font-weight: 600; }
.inventory-character-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--quiet); }
.inventory-screen button { color: var(--muted); background: transparent; border: 1px solid var(--line); border-radius: 0; }
.inventory-screen button:hover:not(:disabled) { color: var(--ink); background: var(--hover); border-color: var(--frame); }
.inventory-screen .inventory-close { display: flex; align-items: center; gap: 7px; min-height: 24px; padding: 2px 6px; font-size: 11px; }
.inventory-body { display: grid; grid-template-columns: 244px minmax(0, 1fr); gap: 10px; }
.inventory-equipment, .inventory-carried, .inventory-bag, .inventory-details, .inventory-item-info { min-width: 0; }
.inventory-equipment, .inventory-bag { padding: 8px; border: 1px solid var(--line); }
.inventory-equipment { align-self: start; }
.inventory-heading { margin: 0; font-size: 11px; font-weight: 600; }
.inventory-equipment > .inventory-heading { padding-bottom: 6px; border-bottom: 1px solid var(--line); }
.inventory-character-stage { position: relative; height: 353px; margin-top: 8px; }
.inventory-portrait { position: absolute; top: 42px; left: 50%; transform: translateX(-50%); width: auto; height: 260px; filter: grayscale(1) brightness(1.5); pointer-events: none; }
.equipment-slots { position: absolute; inset: 0; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); grid-template-rows: repeat(5, 61px); gap: 12px 8px; }
.equipment-slot { position: relative; display: flex; align-items: center; justify-content: center; min-width: 0; padding: 0 0 12px; scroll-margin: 12px; }
.equipment-slot[data-equipment-slot="helm"] { grid-column: 2; grid-row: 1; }
.equipment-slot[data-equipment-slot="chest"] { grid-column: 1; grid-row: 2; }
.equipment-slot[data-equipment-slot="cape"] { grid-column: 3; grid-row: 2; }
.equipment-slot[data-equipment-slot="hands"] { grid-column: 1; grid-row: 3; }
.equipment-slot[data-equipment-slot="offHand"] { grid-column: 3; grid-row: 3; }
.equipment-slot[data-equipment-slot="mainHand"] { grid-column: 1; grid-row: 4; }
.equipment-slot[data-equipment-slot="legs"] { grid-column: 2; grid-row: 5; }
.equipment-slot-label { position: absolute; bottom: 4px; left: 0; right: 0; color: var(--quiet); text-align: center; font-size: 9px; line-height: 1; }
.equipment-slot-icon { width: 11ch; font-size: 4.5px; line-height: 4.5px; white-space: pre; text-align: left; }
.equipment-slot-name { display: none; }
.equipment-slot.empty { border-style: dotted; }
.equipment-slot.empty::after { content: "·"; color: var(--quiet); }
.inventory-bag-heading { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin-bottom: 8px; padding-bottom: 6px; border-bottom: 1px solid var(--line); }
.inventory-slot-total { color: var(--quiet); font-size: 10px; font-variant-numeric: tabular-nums; }
.inventory-slot-grid { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 4px; }
.inventory-slot { position: relative; display: grid; place-items: center; min-width: 0; height: 56px; padding: 0; scroll-margin: 12px; }
.inventory-slot.empty { border-style: dotted; }
.inventory-slot.empty::after { content: "·"; color: var(--quiet); }
.inventory-slot-number { position: absolute; top: 3px; left: 3px; color: var(--quiet); font-size: 8px; line-height: 1; }
.inventory-slot-icon { width: 11ch; font-size: 5px; line-height: 5px; white-space: pre; text-align: left; }
.inventory-slot-count { position: absolute; right: 3px; bottom: 3px; font-size: 9px; line-height: 1; }
.inventory-screen :is(.inventory-slot, .equipment-slot).selected { color: var(--accent); background: var(--hover); border-color: var(--frame); }
.inventory-slot.selected::before, .equipment-slot.selected::before { content: ""; position: absolute; left: -1px; top: 6px; bottom: 6px; width: 2px; background: var(--accent); }
.inventory-load { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 8px; }
.inventory-capacity { margin: 0; color: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.inventory-load-bar { color: var(--quiet); font-size: 9px; line-height: 1; letter-spacing: 1px; }
.inventory-details { display: grid; grid-template-columns: 52px minmax(0, 1fr); gap: 12px; margin-top: 10px; padding: 8px; border: 1px solid var(--line); }
.inventory-item-preview { align-self: start; width: 11ch; margin-top: 22px; font-size: 7px; line-height: 7px; white-space: pre; text-align: left; }
.inventory-item-preview[hidden] + .inventory-item-info { grid-column: 1 / -1; }
.inventory-item-type { margin: 0 0 3px; color: var(--quiet); font-size: 10px; }
.inventory-item-name { margin: 0 0 5px; font-size: 12px; font-weight: 600; }
.inventory-description { margin: 0 0 7px; color: var(--muted); font-size: 11px; }
.inventory-stats { display: grid; grid-template-columns: auto 1fr; gap: 2px 12px; margin: 0 0 6px; font-size: 11px; }
.inventory-stats dt { color: var(--quiet); }
.inventory-stats dd { margin: 0; color: var(--ink); }
.inventory-weight, .inventory-durability, .inventory-hotbar-assignment { margin: 3px 0; color: var(--quiet); font-size: 10px; }
.inventory-actions { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 8px; }
.inventory-actions button { display: inline-flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 28px; padding: 4px 7px; font-size: 11px; }
.inventory-actions kbd { color: var(--quiet); font-size: 10px; }
.inventory-feedback { margin: 8px 0 0; padding-top: 6px; border-top: 1px solid var(--line); font-size: 11px; }
.inventory-feedback[data-kind="error"]::before { content: "! "; }
.inventory-help { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 6px 12px; margin-top: 10px; padding-top: 8px; border-top: 1px solid var(--line); color: var(--quiet); font-size: 10px; }
.inventory-key-hint { display: inline-flex; align-items: center; gap: 5px; }
.inventory-key-hint kbd { font-size: 10px; }

/* Touch controls keep generous hit areas and the same square frame styling. */
#touch-controls { display: none; }
@media (any-pointer: coarse), (max-width: 900px) {
  #hint { display: none; }
  #touch-controls { display: block; position: fixed; z-index: 12; inset: 0; pointer-events: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
  #touch-controls button, #move-pad { pointer-events: auto; touch-action: none; color: var(--ink); background: var(--surface); border: 1px solid var(--frame); }
  #touch-controls button { min-width: 44px; min-height: 44px; padding: 6px; border-radius: 0; font-size: 10px; }
  #touch-controls button.pressed, #touch-controls button:active { color: var(--solid); background: var(--ink); }
  #move-pad { position: absolute; left: max(12px, env(safe-area-inset-left)); bottom: max(12px, env(safe-area-inset-bottom)); display: grid; place-items: center; width: 108px; height: 108px; }
  #move-stick { width: 36px; height: 36px; border: 1px solid var(--frame); background: #c3ccc624; pointer-events: none; }
  #move-pad.running { background: #202824eb; }
  .move-label { position: absolute; bottom: 7px; color: var(--muted); font-size: 9px; pointer-events: none; }
  .actions { position: absolute; right: max(12px, env(safe-area-inset-right)); bottom: max(12px, env(safe-area-inset-bottom)); display: grid; grid-template-columns: 50px 50px; gap: 4px; }
  #touch-controls .strike { grid-column: span 2; min-height: 52px; }
  .zoom-controls { position: absolute; top: max(12px, env(safe-area-inset-top)); right: max(12px, env(safe-area-inset-right)); display: flex; gap: 4px; }
  #touch-controls .zoom-controls button { font-size: 18px; }
  #panel-dock { top: calc(max(12px, env(safe-area-inset-top)) + 52px); max-height: calc(100dvh - 208px); }
  .hud-hotbar-wrap { bottom: max(132px, calc(env(safe-area-inset-bottom) + 132px)); }
  .hud-prompt { bottom: max(236px, calc(env(safe-area-inset-bottom) + 236px)); }
  #fire-status { bottom: max(272px, calc(env(safe-area-inset-bottom) + 272px)); }
  #panel-dock :is(button, input:not([type="range"]), select) { min-height: 36px; }
  #panel-dock summary { min-height: 32px; padding-top: 8px; padding-bottom: 8px; }
}
@media (max-width: 680px) {
  .hud-party { width: min(190px, calc(100vw - 192px)); }
  .hud-member .hud-vital { grid-template-columns: 18px 1fr; }
  .hud-member .hud-vital-value { display: none; }
  #panel-dock { top: 144px; max-height: calc(100dvh - 374px); }
  #panel-dock > details[open] { width: min(292px, calc(100vw - 24px)); }
  #builder-banner { top: auto; bottom: 236px; left: 12px; }
  .hud-hotbar-wrap { grid-template-columns: auto 44px; gap: 5px; padding: 5px 6px 6px; }
  .hud-hotbar { grid-template-columns: repeat(9, 40px); gap: 3px; }
  .hud-slot { width: 40px; height: 50px; }
  .hud-slot-glyph { font-size: 4px; line-height: 4px; }
  .hud-inventory-button { width: 44px; height: 50px; }
  .hud-inventory-label { font-size: 8px; }
  .hud-quick-hint { font-size: 9px; }
  .inventory-screen { width: calc(100% - 24px); max-height: calc(100dvh - 24px); padding: 8px; }
  .inventory-body { grid-template-columns: 204px minmax(0, 1fr); gap: 8px; }
  .equipment-slots { column-gap: 5px; }
  .equipment-slot-icon { font-size: 4px; line-height: 4px; }
  .equipment-slot-label { font-size: 8px; }
  .inventory-slot { height: 48px; }
  .inventory-slot-icon { font-size: 3.6px; line-height: 3.6px; }
  .inventory-load-bar { display: none; }
  .inventory-details { grid-template-columns: 1fr; gap: 0; }
  .inventory-item-preview { display: none; }
}
@media (max-width: 520px) {
  .hud-hotbar-wrap { width: 324px; grid-template-columns: 1fr; bottom: max(128px, calc(env(safe-area-inset-bottom) + 128px)); }
  .hud-hotbar-heading { gap: 8px; }
  .hud-hotbar { grid-template-columns: repeat(5, 1fr); gap: 4px; }
  .hud-slot { width: auto; height: 48px; }
  .hud-slot-glyph { font-size: 4.5px; line-height: 4.5px; }
  .hud-inventory-button { position: absolute; bottom: 6px; right: 6px; width: 59px; height: 48px; }
  .hud-prompt { bottom: max(282px, calc(env(safe-area-inset-bottom) + 282px)); font-size: 11px; }
  #fire-status { bottom: max(316px, calc(env(safe-area-inset-bottom) + 316px)); font-size: 11px; }
  .hud-frames { max-height: calc(100dvh - 380px); overflow-y: auto; scrollbar-width: thin; scrollbar-color: var(--line) var(--solid); }
  #panel-dock { max-height: calc(100dvh - 420px); }
  .inventory-body { grid-template-columns: 1fr; gap: 8px; }
  .inventory-equipment, .inventory-bag { padding: 6px; }
  .inventory-character-stage { height: auto; margin-top: 6px; }
  .inventory-portrait { display: none; }
  .equipment-slots { position: static; grid-template-columns: repeat(4, minmax(0, 1fr)); grid-template-rows: repeat(2, 52px); gap: 4px; }
  .equipment-slot[data-equipment-slot] { grid-column: auto; grid-row: auto; }
  .equipment-slot-icon { font-size: 4px; line-height: 4px; }
  .equipment-slot-label { font-size: 9px; }
  .inventory-slot { height: 48px; }
  .inventory-slot-icon { font-size: 4px; line-height: 4px; }
  .inventory-details { grid-template-columns: 44px minmax(0, 1fr); gap: 8px; margin-top: 8px; padding: 6px; }
  .inventory-item-preview { display: block; font-size: 6px; line-height: 6px; }
  .inventory-actions button { min-height: 44px; }
  .inventory-header { margin-bottom: 8px; padding-bottom: 6px; }
  .inventory-screen .inventory-close { min-height: 44px; }
  .inventory-help { justify-content: flex-start; gap: 6px 12px; }
}
@media (max-width: 360px) {
  .hud-frames { left: 8px; width: 232px; }
  .zoom-controls { flex-direction: column; }
  .hud-hotbar-wrap { width: calc(100% - 24px); }
  .hud-inventory-button { width: calc((100% - 28px) / 5); }
  .hud-quick-hint { font-size: 8px; }
  .inventory-screen { width: calc(100% - 16px); padding: 6px; }
  .inventory-slot-grid { grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 3px; }
  .inventory-slot-icon { font-size: 3.5px; line-height: 3.5px; }
  .inventory-slot-number { display: none; }
  .inventory-identity { gap: 8px; }
}
@media (max-height: 540px) and (min-width: 681px) {
  .hud-hotbar-wrap { bottom: 10px; }
  #move-pad { width: 88px; height: 88px; }
  .actions { grid-template-columns: 44px 44px; }
  #touch-controls .strike { min-height: 44px; }
  #panel-dock { max-height: calc(100dvh - 174px); }
  .hud-prompt { bottom: 112px; }
  #fire-status { bottom: 146px; }
}
/* On short, narrow landscapes, the two-row bar fits between the touch pads. */
@media (max-height: 540px) and (min-width: 521px) and (max-width: 780px) {
  .hud-frames { max-height: calc(100dvh - 172px); overflow-y: auto; scrollbar-width: thin; scrollbar-color: var(--line) var(--solid); }
  .hud-party { width: 190px; }
  .hud-member .hud-vital { grid-template-columns: 18px 1fr; }
  .hud-member .hud-vital-value { display: none; }
  .hud-hotbar-wrap { width: 324px; grid-template-columns: 1fr; bottom: max(12px, env(safe-area-inset-bottom)); gap: 5px; padding: 5px 6px 6px; }
  .hud-hotbar { grid-template-columns: repeat(5, 1fr); gap: 4px; }
  .hud-slot { width: auto; height: 48px; }
  .hud-slot-glyph { font-size: 4.5px; line-height: 4.5px; }
  .hud-inventory-button { position: absolute; bottom: 6px; right: 6px; width: 59px; height: 48px; }
  #panel-dock { top: 12px; max-height: calc(100dvh - 172px); }
  .zoom-controls { top: auto; bottom: 112px; }
  #move-pad { width: 88px; height: 88px; }
  .actions { grid-template-columns: 44px 44px; }
  #touch-controls .strike { min-height: 44px; }
  .hud-prompt { bottom: 164px; }
  #fire-status { bottom: 198px; }
}
@media (prefers-reduced-motion: reduce) {
  .hud, #hint, #fire-status, #inventory-root::before { transition: none; }
}
/* Rune casting sits above the hotbar and remains reachable on touch screens. */
#spell-controls { position: fixed; left: 50%; bottom: 104px; transform: translateX(-50%); display: flex;
  align-items: center; gap: 9px; padding: 7px 10px; background: #10191ef0; border: 1px solid #46535c;
  color: #d9e4dd; font: 12px Consolas, monospace; z-index: 15; max-width: calc(100vw - 24px); }
.spell-mana { display: grid; grid-template-columns: auto 90px; gap: 3px 7px; align-items: center; }
.spell-mana output { grid-column: 1 / 3; font-size: 10px; color: #99bddf; }
#spell-mana { width: 90px; height: 10px; accent-color: #638eca; }
#spell-cast { padding: 6px 10px; border: 1px solid #667780; background: #1e3039; color: #e6efdf;
  cursor: pointer; font: inherit; white-space: nowrap; }
#spell-cast:disabled { opacity: .45; cursor: default; }
#spell-ready { min-width: 35px; font-size: 10px; color: #a4c3d6; }
#spell-library { color: #c8d5cd; }
.inventory-open #spell-controls { visibility: hidden; }
.spell-library-panel { padding: 10px; display: grid; gap: 8px; width: 260px; font-size: 12px; }
.spell-library-panel select { width: 100%; background: #131d23; color: #d6e1d8; padding: 6px; border: 1px solid #46535c; }
.spell-library-panel p { margin: 0; line-height: 1.5; }
#spell-stats { color: #96c9ed; }
@media (max-width: 600px) { #spell-controls { bottom: 88px; gap: 5px; } .spell-mana { grid-template-columns: auto 60px; }
  #spell-mana { width: 60px; } #spell-cast { max-width: 180px; overflow: hidden; text-overflow: ellipsis; } }
