:root {
  --app-height: 100dvh;
  --app-width: 100vw;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --bg: #070605;
  --panel: rgba(17, 13, 11, 0.9);
  --panel-strong: rgba(10, 8, 7, 0.96);
  --line: rgba(205, 164, 105, 0.38);
  --line-bright: rgba(230, 190, 129, 0.66);
  --text: #f1e8d8;
  --muted: #b6a58e;
  --accent: #d8b77e;
  --accent-hot: #f08a48;
  --danger: #b52d24;
  --energy: #2e86bd;
  --shadow: rgba(0, 0, 0, 0.68);
  color-scheme: dark;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  width: 100%;
  min-width: 320px;
  height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  color: var(--text);
  font-family: Inter, Manrope, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at 50% -10%, rgba(147, 58, 25, 0.28), transparent 38%),
    linear-gradient(180deg, #17100c 0%, #080605 55%, #040303 100%);
  user-select: none;
}

button,
canvas {
  touch-action: none;
}

button {
  color: inherit;
  font: inherit;
}

button:focus-visible {
  outline: 2px solid #f2c786;
  outline-offset: 2px;
}

.backdrop-embers,
.backdrop-vignette {
  position: fixed;
  inset: 0;
  pointer-events: none;
}

.backdrop-embers {
  background:
    radial-gradient(circle at 12% 24%, rgba(255, 116, 42, 0.11), transparent 18%),
    radial-gradient(circle at 84% 20%, rgba(153, 38, 22, 0.14), transparent 24%),
    radial-gradient(circle at 52% 80%, rgba(255, 111, 39, 0.08), transparent 26%);
  filter: blur(28px);
}

.backdrop-vignette {
  background: radial-gradient(circle at center, transparent 48%, rgba(0, 0, 0, 0.62));
}

.layout {
  position: relative;
  z-index: 1;
  width: 100%;
  height: var(--app-height);
  padding: clamp(6px, 1vw, 14px);
}

.arena-panel {
  width: 100%;
  height: 100%;
  min-height: 0;
  border: 1px solid var(--line);
  border-radius: 18px;
  overflow: hidden;
  background: #080604;
  box-shadow: 0 22px 70px var(--shadow), inset 0 0 0 1px rgba(255, 238, 207, 0.035);
}

.canvas-wrap {
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 0;
  overflow: hidden;
  isolation: isolate;
  background: #050403;
}

#gameCanvas {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  background: #060504;
}

.background-music-frame,
.legacy-readout {
  position: fixed;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
  border: 0;
}

.scene-vignette {
  position: absolute;
  z-index: 1;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(180deg, rgba(0, 0, 0, 0.48) 0%, transparent 20%, transparent 68%, rgba(0, 0, 0, 0.72) 100%),
    radial-gradient(circle at center, transparent 42%, rgba(0, 0, 0, 0.46) 100%);
}

.hidden {
  display: none !important;
}

.btn {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.58rem 0.85rem;
  background: linear-gradient(180deg, rgba(67, 46, 31, 0.96), rgba(26, 18, 14, 0.97));
  box-shadow: inset 0 1px 0 rgba(255, 235, 199, 0.08), 0 6px 18px rgba(0, 0, 0, 0.34);
  color: #f0dfc2;
  font-weight: 700;
  font-size: 0.76rem;
  letter-spacing: 0.02em;
  cursor: pointer;
}

.btn:hover {
  border-color: var(--line-bright);
  background: linear-gradient(180deg, rgba(86, 57, 37, 0.98), rgba(31, 21, 15, 0.98));
}

.btn:active,
.is-pressed {
  transform: translateY(1px) scale(0.98);
}

.btn-primary {
  min-width: 180px;
  border-color: rgba(222, 146, 77, 0.78);
  background: linear-gradient(180deg, #9d4a27, #4c1f15);
}

.panel-ribbon {
  display: block;
  color: var(--accent);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.18em;
  line-height: 1.2;
  text-transform: uppercase;
}

.hud-card,
.ui-panel {
  border: 1px solid var(--line);
  background:
    linear-gradient(180deg, rgba(62, 41, 27, 0.7), transparent 28%),
    var(--panel);
  box-shadow: inset 0 1px 0 rgba(255, 231, 192, 0.06), 0 12px 30px rgba(0, 0, 0, 0.38);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.scene-chrome {
  position: absolute;
  z-index: 8;
  top: max(14px, calc(var(--safe-top) + 8px));
  left: 50%;
  width: min(620px, calc(100% - 420px));
  min-width: 370px;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  pointer-events: none;
}

.scene-brand {
  min-width: 210px;
  padding: 0.52rem 0.9rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(12, 9, 7, 0.8);
  box-shadow: inset 0 1px 0 rgba(255, 238, 206, 0.06);
  text-align: center;
}

.scene-brand span,
.scene-brand strong {
  display: block;
}

.scene-brand span {
  color: var(--accent);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 0.61rem;
  letter-spacing: 0.17em;
  text-transform: uppercase;
}

.scene-brand strong {
  margin-top: 2px;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 0.82rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.scene-actions {
  display: flex;
  gap: 7px;
  pointer-events: auto;
}

.icon-btn {
  white-space: nowrap;
}

.top-hud {
  position: absolute;
  z-index: 6;
  top: max(78px, calc(var(--safe-top) + 72px));
  left: max(14px, calc(var(--safe-left) + 8px));
  right: max(14px, calc(var(--safe-right) + 8px));
  display: grid;
  grid-template-columns: 190px minmax(280px, 520px) 220px;
  justify-content: space-between;
  align-items: start;
  gap: 12px;
  pointer-events: none;
}

.mini-map,
.quest-tracker,
.hero-status {
  border-radius: 12px;
}

.mini-map {
  position: relative;
  padding: 0.7rem;
}

.map-grid {
  position: relative;
  width: 100%;
  height: 96px;
  margin-top: 0.48rem;
  overflow: hidden;
  border: 1px solid rgba(204, 164, 106, 0.26);
  border-radius: 8px;
  background:
    radial-gradient(circle at 50% 54%, rgba(218, 84, 39, 0.22), transparent 33%),
    linear-gradient(rgba(212, 179, 126, 0.07) 1px, transparent 1px),
    linear-gradient(90deg, rgba(212, 179, 126, 0.07) 1px, transparent 1px),
    rgba(5, 5, 4, 0.74);
  background-size: auto, 12px 12px, 12px 12px, auto;
}

.map-player {
  position: absolute;
  width: 9px;
  height: 9px;
  border: 2px solid #fff3d8;
  border-radius: 50%;
  background: var(--accent-hot);
  box-shadow: 0 0 12px rgba(255, 130, 66, 0.92);
}

.map-meta-row {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-top: 0.48rem;
  color: var(--muted);
  font-size: 0.7rem;
}

.map-meta-row strong {
  color: var(--text);
}

.quest-tracker {
  justify-self: center;
  width: 100%;
  padding: 0.72rem 0.9rem 0.8rem;
  pointer-events: auto;
}

.quest-tracker h2 {
  margin: 0.24rem 0 0.28rem;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 0.92rem;
  letter-spacing: 0.04em;
}

.quest-tracker p {
  margin: 0;
  font-size: 0.8rem;
  line-height: 1.38;
}

.quest-tracker .quest-sub {
  margin-top: 0.28rem;
  color: var(--muted);
  font-size: 0.7rem;
}

.hero-status {
  justify-self: end;
  width: 220px;
  padding: 0.7rem;
}

.portrait-core {
  display: flex;
  gap: 0.56rem;
  align-items: center;
  margin-top: 0.42rem;
}

.portrait-rune {
  display: grid;
  flex: 0 0 42px;
  width: 42px;
  height: 42px;
  place-items: center;
  border: 1px solid var(--line-bright);
  border-radius: 10px;
  background: radial-gradient(circle, rgba(230, 164, 82, 0.28), rgba(31, 20, 14, 0.9));
  color: #ffd190;
  font-size: 1.2rem;
}

.portrait-core strong,
.portrait-core small {
  display: block;
}

.portrait-core strong {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 0.75rem;
  line-height: 1.2;
}

.portrait-core small {
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.61rem;
}

.status-grid {
  display: grid;
  gap: 3px;
  margin-top: 0.55rem;
  color: var(--muted);
  font-size: 0.62rem;
}

.status-grid span {
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

.status-grid b {
  color: var(--text);
  text-align: right;
}

.threat-meter {
  position: absolute;
  z-index: 6;
  top: 262px;
  left: max(14px, calc(var(--safe-left) + 8px));
  width: 190px;
  padding: 0.58rem 0.7rem;
  border-radius: 10px;
  pointer-events: none;
}

.threat-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}

.threat-heading .panel-ribbon {
  flex: 0 0 auto;
}

.threat-heading p {
  margin: 0;
  color: var(--muted);
  font-size: 0.58rem;
  text-align: right;
}

.threat-track,
.vital-track,
.xp-strip {
  overflow: hidden;
  border: 1px solid rgba(228, 188, 124, 0.2);
  background: rgba(0, 0, 0, 0.54);
}

.threat-track {
  height: 6px;
  margin-top: 0.45rem;
  border-radius: 999px;
}

#threatFill {
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #97632f, #d34b2f, #f13b30);
  transition: width 160ms linear;
}

.bottom-hud {
  position: absolute;
  z-index: 7;
  right: max(14px, calc(var(--safe-right) + 8px));
  bottom: max(12px, calc(var(--safe-bottom) + 8px));
  left: max(14px, calc(var(--safe-left) + 8px));
  display: grid;
  grid-template-columns: minmax(150px, 190px) minmax(420px, 760px) minmax(150px, 190px);
  align-items: end;
  justify-content: center;
  gap: 12px;
  pointer-events: none;
}

.vital-card,
.center-hud {
  border: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(54, 35, 23, 0.84), rgba(10, 8, 7, 0.94));
  box-shadow: inset 0 1px 0 rgba(255, 236, 204, 0.05), 0 12px 34px rgba(0, 0, 0, 0.44);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  pointer-events: auto;
}

.vital-card {
  align-self: end;
  padding: 0.62rem 0.72rem;
  border-radius: 12px;
}

.vital-header {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 0.42rem;
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.vital-header strong {
  color: var(--text);
  letter-spacing: 0;
}

.vital-track {
  height: 12px;
  border-radius: 999px;
}

.vital-fill {
  width: 100%;
  height: 100%;
  transform: scaleX(1) !important;
  transform-origin: left center !important;
  transition: width 130ms linear, transform 130ms linear;
}

.hp-vital .vital-fill {
  background: linear-gradient(90deg, #6f130e, #c33427, #ef6c44);
}

.energy-vital .vital-fill {
  background: linear-gradient(90deg, #124267, #287db1, #69b8db);
}

.center-hud {
  width: 100%;
  padding: 0.58rem;
  border-radius: 14px;
}

.skill-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
}

.skill-slot {
  position: relative;
  min-height: 54px;
  display: grid;
  grid-template-columns: 30px 1fr auto;
  grid-template-rows: 1fr 1fr;
  align-items: center;
  gap: 0 7px;
  padding: 0.38rem 0.46rem;
  border: 1px solid rgba(203, 161, 100, 0.32);
  border-radius: 9px;
  background: linear-gradient(180deg, rgba(60, 40, 27, 0.86), rgba(20, 14, 11, 0.92));
  cursor: pointer;
}

.skill-slot > span {
  grid-row: 1 / 3;
  display: grid;
  width: 28px;
  height: 28px;
  place-items: center;
  border: 1px solid rgba(232, 189, 122, 0.3);
  border-radius: 7px;
  color: #f1ba72;
}

.skill-slot strong {
  align-self: end;
  font-size: 0.72rem;
  text-align: left;
}

.skill-slot small {
  align-self: start;
  color: var(--muted);
  font-size: 0.57rem;
  text-align: left;
}

.skill-slot em {
  grid-column: 3;
  grid-row: 1 / 3;
  align-self: center;
  color: #efc282;
  font-size: 0.58rem;
  font-style: normal;
  font-weight: 800;
}

.progress-line {
  display: grid;
  grid-template-columns: auto minmax(100px, 1fr) auto;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
  color: var(--muted);
  font-size: 0.62rem;
}

.progress-line strong {
  color: var(--text);
}

.xp-strip {
  height: 6px;
  border-radius: 999px;
}

#xpProgress {
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #90723d, #e6b85f);
}

.meta-line {
  display: flex;
  justify-content: center;
  gap: 18px;
  margin-top: 5px;
  color: var(--muted);
  font-size: 0.62rem;
}

.meta-line strong {
  color: var(--text);
}

.menu-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 5px;
  margin-top: 6px;
}

.menu-btn,
.mobile-panel-btn {
  min-height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border: 1px solid rgba(203, 161, 100, 0.26);
  border-radius: 8px;
  background: rgba(23, 16, 12, 0.88);
  color: var(--muted);
  font-size: 0.66rem;
  cursor: pointer;
}

.menu-btn small {
  color: var(--accent);
  font-size: 0.56rem;
}

.menu-btn:hover,
.menu-btn.is-active,
.mobile-panel-btn.is-active {
  border-color: var(--line-bright);
  background: rgba(75, 48, 29, 0.9);
  color: var(--text);
}

.desktop-docks {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
  margin-top: 6px;
}

.dock-title {
  display: flex;
  justify-content: space-between;
  margin: 0 2px 3px;
  color: var(--muted);
  font-size: 0.56rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.weapon-dock,
.belt-dock {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 4px;
}

.weapon-dock-btn,
.belt-slot {
  min-width: 0;
  min-height: 46px;
  overflow: hidden;
  border: 1px solid rgba(201, 157, 98, 0.25);
  border-radius: 7px;
  padding: 0.32rem;
  background: rgba(17, 12, 10, 0.86);
  color: var(--muted);
  cursor: pointer;
}

.weapon-dock-btn strong,
.weapon-dock-btn span,
.weapon-dock-btn small,
.belt-slot strong,
.belt-slot span,
.belt-slot small,
.belt-slot em {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.weapon-dock-btn strong,
.belt-slot strong {
  color: #f1c98f;
  font-size: 0.66rem;
}

.weapon-dock-btn span,
.belt-slot span {
  margin-top: 2px;
  font-size: 0.54rem;
}

.weapon-dock-btn small,
.belt-slot small,
.belt-slot em {
  margin-top: 2px;
  color: #8f806e;
  font-size: 0.48rem;
  font-style: normal;
}

.weapon-dock-btn:hover,
.weapon-dock-btn.is-equipped,
.weapon-dock-btn.active,
.belt-slot:hover {
  border-color: var(--line-bright);
  background: linear-gradient(180deg, rgba(92, 57, 32, 0.74), rgba(28, 18, 13, 0.92));
  color: var(--text);
}

.weapon-dock-btn:disabled,
.belt-slot:disabled {
  opacity: 0.36;
  cursor: not-allowed;
}

.overlay,
.panel-stack {
  position: absolute;
  z-index: 20;
  inset: 0;
  display: grid;
  place-items: center;
  padding: max(18px, var(--safe-top)) max(18px, var(--safe-right)) max(18px, var(--safe-bottom)) max(18px, var(--safe-left));
  background: rgba(3, 3, 3, 0.56);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.overlay {
  text-align: center;
}

.overlay::before {
  content: "";
  position: absolute;
  width: min(420px, calc(100% - 32px));
  height: 280px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: linear-gradient(180deg, rgba(66, 40, 25, 0.96), rgba(11, 8, 7, 0.98));
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.72);
}

.overlay > * {
  position: relative;
  z-index: 1;
}

.overlay-kicker {
  color: var(--accent);
  font-size: 0.66rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
}

.overlay h2 {
  margin: 0.45rem 0 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.7rem;
}

.overlay p {
  max-width: 330px;
  margin: 0.9rem auto 1.2rem;
  color: var(--muted);
  line-height: 1.55;
}

.ui-panel {
  position: relative;
  width: min(720px, calc(100vw - 40px));
  max-height: min(78vh, 720px);
  overflow: auto;
  border-radius: 16px;
  padding: 1.15rem;
  user-select: text;
}

.ui-panel h2 {
  margin: 0.26rem 2.4rem 0.8rem 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.2rem;
  letter-spacing: 0.04em;
}

.ui-panel p {
  line-height: 1.55;
}

.panel-close {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 36px;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: rgba(20, 14, 11, 0.92);
  color: var(--muted);
  font-size: 1.35rem;
  cursor: pointer;
}

.panel-close:hover {
  border-color: var(--line-bright);
  color: var(--text);
}

.choice-list {
  display: grid;
  gap: 8px;
  margin-top: 1rem;
}

.choice-list button,
.inventory-slot {
  width: 100%;
  border: 1px solid rgba(204, 161, 100, 0.3);
  border-radius: 10px;
  padding: 0.78rem;
  background: rgba(18, 13, 10, 0.88);
  color: var(--text);
  text-align: left;
  cursor: pointer;
}

.choice-list button:hover,
.inventory-slot:hover,
.inventory-slot.is-equipped {
  border-color: var(--line-bright);
  background: rgba(71, 44, 26, 0.82);
}

.weapon-focus {
  padding: 0.85rem;
  border: 1px solid rgba(205, 164, 105, 0.26);
  border-radius: 12px;
  background: rgba(7, 6, 5, 0.42);
}

.weapon-head {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.weapon-icon {
  display: grid;
  flex: 0 0 52px;
  width: 52px;
  height: 52px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(67, 41, 25, 0.72);
  color: #ffd093;
  font-size: 1.45rem;
}

.weapon-head strong {
  font-family: Georgia, "Times New Roman", serif;
}

.weapon-stats,
.weapon-lore,
.asset-note {
  margin: 0.3rem 0 0;
}

.weapon-stats {
  color: var(--accent);
  font-size: 0.72rem;
}

.weapon-lore {
  color: var(--muted);
  font-size: 0.83rem;
}

.asset-note {
  color: #867764;
  font-size: 0.68rem;
}

.inventory-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: 10px;
}

.inventory-slot strong,
.inventory-slot span,
.inventory-slot small {
  display: block;
}

.inventory-slot strong {
  font-family: Georgia, "Times New Roman", serif;
}

.inventory-slot span {
  margin-top: 4px;
  color: var(--accent);
  font-size: 0.7rem;
}

.inventory-slot small {
  margin-top: 5px;
  color: var(--muted);
  font-size: 0.65rem;
}

.inventory-slot.is-locked {
  opacity: 0.44;
}

#eventLog {
  margin: 0;
  padding-left: 1.2rem;
  color: var(--muted);
}

#eventLog li + li {
  margin-top: 0.48rem;
}

.help-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.help-list p {
  display: grid;
  gap: 4px;
  margin: 0;
  padding: 0.7rem;
  border: 1px solid rgba(205, 164, 105, 0.22);
  border-radius: 9px;
  background: rgba(10, 8, 7, 0.48);
}

.help-list strong {
  color: var(--accent);
  font-size: 0.72rem;
}

.help-list span {
  color: var(--muted);
  font-size: 0.72rem;
}

.mobile-controls,
.orientation-hint {
  display: none;
}

.arena-panel:fullscreen,
.arena-panel:-webkit-full-screen,
.arena-panel.is-fullscreen-fallback {
  width: 100vw;
  height: 100dvh;
  border: 0;
  border-radius: 0;
}

.arena-panel:fullscreen .canvas-wrap,
.arena-panel:-webkit-full-screen .canvas-wrap,
.arena-panel.is-fullscreen-fallback .canvas-wrap {
  width: 100%;
  height: 100%;
}

body.fullscreen-fallback-active {
  overflow: hidden;
}

.arena-panel.is-fullscreen-fallback {
  position: fixed;
  z-index: 9999;
  inset: 0;
}

@media (max-width: 1120px) {
  .scene-chrome {
    width: min(520px, calc(100% - 380px));
    min-width: 330px;
  }

  .top-hud {
    grid-template-columns: 165px minmax(260px, 440px) 190px;
  }

  .mini-map,
  .threat-meter {
    width: 165px;
  }

  .hero-status {
    width: 190px;
  }

  .bottom-hud {
    grid-template-columns: 150px minmax(410px, 1fr) 150px;
  }

  .desktop-docks {
    grid-template-columns: 1fr;
  }

  .belt-dock,
  .weapon-dock {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .belt-slot em {
    display: none;
  }
}

@media (max-width: 900px), (pointer: coarse) and (max-width: 1100px) {
  .layout {
    padding: 0;
  }

  .hud-card,
  .ui-panel,
  .vital-card,
  .center-hud {
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
  }

  .arena-panel {
    border: 0;
    border-radius: 0;
  }

  .scene-chrome {
    top: max(7px, var(--safe-top));
    right: max(7px, var(--safe-right));
    left: max(7px, var(--safe-left));
    width: auto;
    min-width: 0;
    transform: none;
    justify-content: space-between;
  }

  .scene-brand {
    min-width: 0;
    padding: 0.4rem 0.65rem;
    text-align: left;
  }

  .scene-brand span {
    font-size: 0.52rem;
  }

  .scene-brand strong {
    font-size: 0.68rem;
  }

  .scene-actions {
    gap: 5px;
  }

  .icon-btn {
    min-height: 34px;
    padding: 0.42rem 0.58rem;
    font-size: 0.62rem;
  }

  .top-hud {
    top: calc(max(7px, var(--safe-top)) + 52px);
    right: max(7px, var(--safe-right));
    left: max(7px, var(--safe-left));
    display: block;
  }

  .mini-map,
  .hero-status {
    display: none;
  }

  .quest-tracker {
    width: min(520px, calc(100% - 120px));
    margin: 0 auto;
    padding: 0.48rem 0.68rem;
    text-align: center;
  }

  .quest-tracker .panel-ribbon,
  .quest-tracker h2 {
    display: inline;
  }

  .quest-tracker h2 {
    margin-left: 5px;
    font-size: 0.72rem;
  }

  .quest-tracker p {
    margin-top: 3px;
    font-size: 0.68rem;
  }

  .quest-tracker .quest-sub {
    display: none;
  }

  .threat-meter {
    top: calc(max(7px, var(--safe-top)) + 55px);
    left: max(7px, var(--safe-left));
    width: 96px;
    padding: 0.42rem 0.5rem;
  }

  .threat-heading {
    display: block;
  }

  .threat-heading p {
    display: none;
  }

  .bottom-hud {
    z-index: 9;
    inset: 0;
    display: block;
    pointer-events: none;
  }

  .vital-card {
    position: absolute;
    top: calc(max(7px, var(--safe-top)) + 54px);
    width: 104px;
    padding: 0.42rem 0.5rem;
    border-radius: 9px;
  }

  .hp-vital {
    left: max(7px, var(--safe-left));
    transform: translateY(52px);
  }

  .energy-vital {
    right: max(7px, var(--safe-right));
    transform: translateY(52px);
  }

  .vital-header {
    margin-bottom: 4px;
    font-size: 0.54rem;
  }

  .vital-track {
    height: 7px;
  }

  .center-hud {
    position: absolute;
    top: calc(max(7px, var(--safe-top)) + 98px);
    left: 50%;
    width: min(360px, calc(100% - 226px));
    padding: 0.4rem;
    transform: translateX(-50%);
    border-radius: 10px;
  }

  .skill-row,
  .desktop-docks {
    display: none;
  }

  .progress-line {
    margin: 0;
    font-size: 0.54rem;
  }

  .meta-line {
    gap: 9px;
    margin-top: 4px;
    font-size: 0.53rem;
  }

  .menu-row {
    gap: 3px;
    margin-top: 4px;
  }

  .menu-btn {
    min-height: 27px;
    padding: 0 0.3rem;
    font-size: 0.56rem;
  }

  .menu-btn small {
    display: none;
  }

  .mobile-controls {
    position: absolute;
    z-index: 12;
    right: max(12px, calc(var(--safe-right) + 8px));
    bottom: max(12px, calc(var(--safe-bottom) + 8px));
    left: max(12px, calc(var(--safe-left) + 8px));
    display: grid;
    grid-template-columns: 146px minmax(118px, 1fr) 176px;
    align-items: end;
    gap: 10px;
    pointer-events: none;
  }

  .mobile-controls[aria-hidden="true"] {
    display: none;
  }

  .mobile-stick {
    position: relative;
    width: 142px;
    height: 142px;
    border: 1px solid rgba(220, 181, 119, 0.3);
    border-radius: 50%;
    background: radial-gradient(circle, rgba(74, 49, 31, 0.56), rgba(10, 8, 7, 0.48));
    box-shadow: inset 0 0 32px rgba(0, 0, 0, 0.56), 0 12px 28px rgba(0, 0, 0, 0.28);
    pointer-events: auto;
  }

  .stick-ring {
    position: absolute;
    inset: 18%;
    border: 1px dashed rgba(224, 188, 130, 0.24);
    border-radius: 50%;
  }

  .stick-core {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 56px;
    height: 56px;
    margin: -28px 0 0 -28px;
    border: 1px solid rgba(233, 195, 135, 0.58);
    border-radius: 50%;
    background: radial-gradient(circle at 35% 30%, rgba(245, 205, 145, 0.28), rgba(55, 35, 23, 0.94));
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.48);
    transition: transform 80ms ease-out;
  }

  .mobile-quickbar {
    align-self: end;
    justify-self: center;
    width: min(170px, 100%);
    display: grid;
    gap: 5px;
    pointer-events: auto;
  }

  .mobile-panel-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 4px;
  }

  .mobile-panel-btn {
    min-height: 30px;
    padding: 0.22rem;
    color: var(--text);
    font-size: 0.54rem;
  }

  .mobile-belt {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 4px;
  }

  .mobile-belt .belt-slot {
    min-height: 45px;
    padding: 0.25rem;
    background: rgba(10, 8, 7, 0.76);
    backdrop-filter: blur(8px);
  }

  .mobile-belt .belt-slot span,
  .mobile-belt .belt-slot em {
    display: none;
  }

  .mobile-belt .belt-slot strong,
  .mobile-belt .belt-slot small {
    text-align: center;
  }

  .mobile-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 7px;
    align-items: end;
    pointer-events: auto;
  }

  .action-btn {
    min-height: 66px;
    display: grid;
    place-items: center;
    gap: 1px;
    border: 1px solid rgba(222, 181, 115, 0.4);
    border-radius: 50%;
    background: radial-gradient(circle at 38% 30%, rgba(135, 82, 43, 0.82), rgba(25, 16, 12, 0.94) 68%);
    box-shadow: inset 0 0 0 3px rgba(255, 226, 180, 0.035), 0 10px 26px rgba(0, 0, 0, 0.38);
    cursor: pointer;
  }

  .action-attack {
    grid-row: 1 / 3;
    min-height: 92px;
  }

  .action-btn strong {
    color: #ffd094;
    font-size: 1.08rem;
  }

  .action-btn span {
    font-size: 0.58rem;
    font-weight: 800;
  }

  .action-btn small {
    color: var(--accent);
    font-size: 0.49rem;
  }

  .panel-stack,
  .overlay {
    z-index: 30;
    padding: max(10px, var(--safe-top)) max(10px, var(--safe-right)) max(10px, var(--safe-bottom)) max(10px, var(--safe-left));
  }

  .ui-panel {
    width: min(660px, 100%);
    max-height: 92%;
    padding: 0.9rem;
  }

  .ui-panel h2 {
    font-size: 1rem;
  }
}

@media (max-width: 600px) and (orientation: portrait) {
  .threat-meter {
    display: none;
  }

  .scene-brand strong {
    display: none;
  }

  .scene-brand {
    padding: 0.46rem 0.58rem;
  }

  .icon-btn {
    max-width: 118px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .top-hud {
    top: calc(max(7px, var(--safe-top)) + 48px);
  }

  .quest-tracker {
    width: calc(100% - 14px);
    padding: 0.4rem 0.54rem;
  }

  .quest-tracker p {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .threat-meter {
    top: calc(max(7px, var(--safe-top)) + 96px);
    width: 88px;
  }

  .vital-card {
    top: calc(max(7px, var(--safe-top)) + 95px);
    width: 118px;
    transform: none;
  }

  .center-hud {
    top: calc(max(7px, var(--safe-top)) + 139px);
    width: calc(100% - 14px);
  }

  .progress-line {
    grid-template-columns: auto 1fr auto;
  }

  .mobile-controls {
    grid-template-columns: 126px 1fr 145px;
    gap: 7px;
  }

  .mobile-stick {
    width: 124px;
    height: 124px;
  }

  .stick-core {
    width: 50px;
    height: 50px;
    margin: -25px 0 0 -25px;
  }

  .mobile-quickbar {
    min-width: 88px;
  }

  .mobile-panel-btn {
    min-height: 30px;
    font-size: 0.56rem;
  }

  .mobile-belt .belt-slot {
    min-height: 40px;
  }

  .action-btn {
    min-height: 58px;
  }

  .action-attack {
    min-height: 82px;
  }

  .orientation-hint {
    position: absolute;
    z-index: 11;
    right: max(8px, calc(var(--safe-right) + 4px));
    bottom: calc(max(12px, var(--safe-bottom)) + 148px);
    display: flex;
    max-width: 155px;
    align-items: center;
    gap: 6px;
    padding: 0.38rem 0.48rem;
    border: 1px solid rgba(211, 170, 108, 0.22);
    border-radius: 8px;
    background: rgba(10, 8, 7, 0.68);
    color: #988772;
    font-size: 0.5rem;
    line-height: 1.25;
    opacity: 0;
    animation: orientation-tip 5s ease 1.2s 1;
    pointer-events: none;
  }

  .orientation-hint span {
    color: var(--accent);
    font-size: 1rem;
  }

  .inventory-list,
  .help-list {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 420px) and (orientation: portrait) {
  .scene-actions .audio-btn,
  .scene-actions .fullscreen-btn {
    width: 42px;
    padding: 0;
    font-size: 0;
  }

  .scene-actions .audio-btn::after {
    content: "♪";
    color: var(--text);
    font-size: 1rem;
  }

  .scene-actions .fullscreen-btn::after {
    content: "⛶";
    color: var(--text);
    font-size: 1rem;
  }

  .quest-tracker {
    text-align: left;
  }

  .quest-tracker .panel-ribbon,
  .quest-tracker h2 {
    display: none;
  }

  .center-hud {
    top: calc(max(7px, var(--safe-top)) + 135px);
  }

  .menu-btn span {
    font-size: 0.52rem;
  }

  .mobile-controls {
    right: max(6px, var(--safe-right));
    bottom: max(7px, var(--safe-bottom));
    left: max(6px, var(--safe-left));
    grid-template-columns: 112px minmax(72px, 1fr) 132px;
    gap: 5px;
  }

  .mobile-stick {
    width: 110px;
    height: 110px;
  }

  .stick-core {
    width: 44px;
    height: 44px;
    margin: -22px 0 0 -22px;
  }

  .mobile-belt .belt-slot {
    min-height: 36px;
  }

  .mobile-belt .belt-slot strong {
    font-size: 0.56rem;
  }

  .action-btn {
    min-height: 52px;
  }

  .action-attack {
    min-height: 74px;
  }

  .action-btn span {
    font-size: 0.52rem;
  }
}

@media (orientation: landscape) and (max-height: 560px) and (max-width: 1000px),
       (orientation: landscape) and (max-height: 560px) and (pointer: coarse) {
  .scene-chrome {
    top: max(5px, var(--safe-top));
  }

  .scene-brand {
    padding: 0.34rem 0.55rem;
  }

  .scene-brand strong {
    display: none;
  }

  .icon-btn {
    min-height: 30px;
    padding: 0.34rem 0.48rem;
    font-size: 0.55rem;
  }

  .top-hud {
    top: calc(max(5px, var(--safe-top)) + 39px);
    right: 190px;
    left: 190px;
  }

  .quest-tracker {
    width: 100%;
    padding: 0.34rem 0.52rem;
  }

  .quest-tracker .panel-ribbon,
  .quest-tracker h2,
  .quest-tracker .quest-sub {
    display: none;
  }

  .quest-tracker p {
    overflow: hidden;
    font-size: 0.58rem;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .threat-meter {
    top: calc(max(5px, var(--safe-top)) + 43px);
    width: 118px;
  }

  .vital-card {
    top: calc(max(5px, var(--safe-top)) + 42px);
    width: 128px;
    transform: none;
  }

  .hp-vital {
    left: max(8px, var(--safe-left));
  }

  .energy-vital {
    right: max(8px, var(--safe-right));
  }

  .center-hud {
    top: calc(max(5px, var(--safe-top)) + 80px);
    width: min(440px, calc(100% - 310px));
  }

  .menu-row {
    display: none;
  }

  .mobile-controls {
    right: max(10px, var(--safe-right));
    bottom: max(7px, var(--safe-bottom));
    left: max(10px, var(--safe-left));
    grid-template-columns: 116px 122px 150px;
    justify-content: space-between;
  }

  .mobile-stick {
    width: 112px;
    height: 112px;
  }

  .stick-core {
    width: 46px;
    height: 46px;
    margin: -23px 0 0 -23px;
  }

  .mobile-quickbar {
    justify-self: center;
  }

  .mobile-panel-btn {
    min-height: 27px;
    font-size: 0.52rem;
  }

  .mobile-belt .belt-slot {
    min-height: 34px;
  }

  .mobile-actions {
    gap: 5px;
  }

  .action-btn {
    min-height: 52px;
  }

  .action-attack {
    min-height: 74px;
  }

  .action-btn span {
    font-size: 0.5rem;
  }

  .orientation-hint {
    display: none;
  }

  .ui-panel {
    width: min(680px, calc(100% - 28px));
    max-height: calc(100% - 20px);
    padding: 0.78rem;
  }

  .ui-panel h2 {
    margin-bottom: 0.5rem;
    font-size: 0.92rem;
  }

  .weapon-focus {
    padding: 0.58rem;
  }

  .inventory-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (min-width: 901px) and (max-height: 760px) {
  .top-hud {
    grid-template-columns: 155px minmax(250px, 430px) 180px;
  }

  .mini-map {
    width: 155px;
  }

  .map-grid {
    height: 70px;
  }

  .hero-status {
    width: 180px;
  }

  .threat-meter {
    top: 130px;
    width: 155px;
  }

  .bottom-hud {
    grid-template-columns: 140px minmax(400px, 700px) 140px;
  }

  .skill-slot {
    min-height: 47px;
  }

  .desktop-docks {
    display: none;
  }
}

@keyframes orientation-tip {
  0%, 100% { opacity: 0; transform: translateY(5px); }
  12%, 78% { opacity: 1; transform: translateY(0); }
}

@media (max-width: 360px) and (orientation: portrait) {
  .mobile-controls {
    grid-template-columns: 96px minmax(72px, 1fr) 116px;
    gap: 4px;
  }

  .mobile-stick {
    width: 94px;
    height: 94px;
  }

  .stick-core {
    width: 40px;
    height: 40px;
    margin: -20px 0 0 -20px;
  }

  .mobile-panel-btn {
    min-height: 25px;
    font-size: 0.47rem;
  }

  .mobile-belt .belt-slot {
    min-height: 31px;
  }

  .action-btn {
    min-height: 46px;
  }

  .action-attack {
    min-height: 66px;
  }

  .action-btn strong {
    font-size: 0.9rem;
  }

  .action-btn span {
    font-size: 0.46rem;
  }
}
