.mast {
  display: grid;
  grid-template-columns: max-content max-content minmax(0, 1fr) minmax(0, 1.2fr) max-content max-content;
  grid-template-areas: "brand health room boss map actions";
  align-items: center;
  gap: clamp(4px, 1.3vw, 22px);
  min-height: clamp(32px, calc(var(--screen-h) * .066), 56px);
  padding: 3px clamp(4px, 1.25vw, 20px);
  border: 1px solid #647383;
  border-bottom-color: #303a4b;
  border-radius: 4px 4px 0 0;
  background: #131722 url("../assets/deep-space/ui/hud-plate.png") repeat;
  box-shadow: inset 0 1px #c5dce82c;
}
.identity {
  grid-area: brand;
  display: flex;
  align-items: center;
  gap: 4px;
  margin: 0;
  color: #c2d5dc;
  font: 650 clamp(.70rem, calc(var(--screen-w) * .017), 1.28rem)/1 system-ui, sans-serif;
  letter-spacing: .105em;
}
.seal {
  width: 1.4em;
  height: 1.5em;
  background: url("../assets/deep-space/ui/crest.png") center / contain no-repeat;
}
.health {
  grid-area: health;
  --pip-width: clamp(10px, calc(var(--screen-w) * .016), 19px);
  display: grid;
  grid-template-columns: repeat(6, var(--pip-width));
  gap: 1px;
  width: max-content;
}
.health span {
  width: var(--pip-width);
  aspect-ratio: 21 / 19;
  background: url("../assets/deep-space/ui/durability-empty.png") center / contain no-repeat;
}
.health .filled { background-image: url("../assets/deep-space/ui/durability-full.png"); }
.health[data-hit] span { animation: durability-impact .25s ease-out; }
@keyframes durability-impact {
  from { filter: hue-rotate(133deg) brightness(1.6) drop-shadow(0 0 3px #ff8080); }
  to { filter: none; }
}
.location {
  grid-area: room;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 2px;
  min-width: 0;
  padding-left: clamp(4px, 1vw, 16px);
  border-left: 1px solid #81939e;
}
#room, #boss span, #supplies {
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
#room { font: 550 clamp(.65rem, calc(var(--screen-w) * .013), .93rem)/1.15 Menlo, Consolas, monospace; }
#supplies { display: flex; gap: .7em; color: #b4c6d1; font: .66rem/1 Menlo, Consolas, monospace; }
#supplies > span { display: inline-flex; gap: .2em; align-items: center; }
.hud-glyph {
  display: inline-block;
  width: 1em;
  height: 1em;
  flex: none;
  vertical-align: -.13em;
  object-fit: contain;
}
#boss {
  grid-area: boss;
  align-self: center;
  min-width: 0;
  color: #d5e6ef;
  text-transform: uppercase;
  font: clamp(.66rem, calc(var(--screen-w) * .012), .92rem)/1 Menlo, Consolas, monospace;
  letter-spacing: .06em;
}
#boss span { display: block; margin-bottom: 2px; }
#boss div {
  height: clamp(5px, .9vh, 9px);
  padding: 1px;
  border: 1px solid #8fa6b3;
  border-radius: 9px;
  background: #070c11;
  position: relative;
  overflow: hidden;
}
#boss div::after {
  content: "";
  display: block;
  position: absolute;
  inset: 0 auto 0 var(--stage-cut, 50%);
  width: 1px;
  background: #dde9f6a6;
}
#boss i {
  display: block;
  height: 100%;
  border-radius: 9px;
  background: linear-gradient(#ff9b9b 1px, #f26866 70%, #a9333c);
}
.explore {
  grid-area: map;
  display: grid;
  min-height: 24px;
  min-width: 38px;
  width: max-content;
  place-items: center;
  padding: 2px;
  border: 1px solid #a8c0d2;
  background: #101720c7;
}
.map { display: grid; --map-unit: 7px; gap: 0; }
.map i { position: relative; display: block; border: 1px solid #647a8a; background: #1a2632; }
.map .visited, .map .cleared { background: #365061; border-color: #90aab6; }
.map .current { background: #214757; border-color: #94d8e8; }
.map .current::before {
  content: "";
  display: block;
  position: absolute;
  inset: 1px;
  border-radius: 50%;
  background: #b7f8ff;
  box-shadow: 0 0 5px #4ae3ff;
}
.map [data-kind]:not(.current)::after {
  content: "";
  position: absolute;
  inset: 0;
  background: var(--room-glyph) center / contain no-repeat;
}
.map [data-kind="start"] { --room-glyph: url("../assets/deep-space/ui/room-start.svg"); }
.map [data-kind="combat"] { --room-glyph: url("../assets/deep-space/ui/room-combat.svg"); }
.map [data-kind="elite"] { --room-glyph: url("../assets/deep-space/ui/room-elite.svg"); }
.map [data-kind="reward"] { --room-glyph: url("../assets/deep-space/ui/room-reward.svg"); }
.map [data-kind="shop"] { --room-glyph: url("../assets/deep-space/ui/room-shop.svg"); }
.map [data-kind="boss"] { --room-glyph: url("../assets/deep-space/ui/room-boss.svg"); }
.map .unvisited::after { opacity: .37; }
.mast-actions {
  grid-area: actions;
  display: flex;
  gap: 4px;
  --mast-button-size: clamp(29px, calc(var(--screen-w) * .032), 44px);
}
.mast-actions button {
  min-width: var(--mast-button-size);
  height: var(--mast-button-size);
  display: grid;
  place-items: center;
  padding: 0;
  border: 1px solid #768fa0;
  border-radius: 4px;
  background: #111a25;
}
.mast-actions button:hover:enabled, .header-tools button:hover:enabled { border-color: #b9efff; background: #243647; }
#debug {
  padding-inline: 4px;
  font-size: .68rem;
  white-space: nowrap;
}
.mast-actions #debug[data-running] { color: #ffd396; border-color: #b48850; }
.pause-glyph {
  width: 30%;
  height: 52%;
  border-inline: 2px solid #b7cddc;
  border-radius: 1px;
}
#pause[data-resume] { border-color: #9ed9e8; }

[data-layout="portrait"] .mast {
  grid-template-columns: max-content max-content minmax(0, 1fr) max-content max-content;
  grid-template-areas: "brand health room map actions" "boss boss boss boss boss";
  gap: 3px clamp(3px, calc(var(--screen-w) * .013), 12px);
}
[data-layout="portrait"] #boss {
  width: min(100%, 360px, 74%);
  justify-self: center;
  padding-bottom: 4px;
}
[data-layout="portrait"] #room { font-size: clamp(.62rem, calc(var(--screen-w) * .024), .9rem); }
[data-layout="portrait"] #supplies { font-size: .61rem; }
[data-layout="portrait"] .identity { letter-spacing: .05em; }
@media (max-width: 360px), (max-height: 360px) {
  [data-layout="portrait"] .identity > :not(.seal) { display: none; }
}
[data-touch] .mast-actions { --mast-button-size: clamp(36px, calc(var(--screen-h) * .105), 42px); }
[data-compact] .mast { padding-block: 1px; }
[data-compact] .location { border-left-color: #5b7080; }
[data-compact] .map, [data-layout="portrait"] .map { --map-unit: 6px; }

.control {
  display: none;
  position: absolute;
  bottom: clamp(10px, 6%, 52px);
  width: var(--pad-size);
  aspect-ratio: 1;
  place-items: center;
  padding: 0;
  border: 1.5px solid #c2d8e5bc;
  border-radius: 50%;
  background: radial-gradient(circle at 42% 35%, #788c9a25 25%, #4454614f 79%, #b2cad14e 100%);
  box-shadow: inset 0 0 4px #e2edf35e, 0 2px 7px #090c194f;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}
[data-touch] .control { display: grid; }
.stick { left: clamp(11px, 10%, 160px); cursor: grab; }
.fire { right: clamp(11px, 4%, 64px); width: calc(var(--pad-size) * .82); }
[data-layout="portrait"] .stick { left: 7.5%; }
[data-layout="portrait"] .fire { right: 6%; width: calc(var(--pad-size) * .85); }
.control[data-active] {
  border-color: #d9f8ff;
  background-color: #78aeb73b;
  box-shadow: inset 0 0 10px #a8edff9c, 0 0 6px #8ee9ff6e;
}
.stick[data-active] { cursor: grabbing; }
.stick-grid { position: absolute; inset: 0; }
.stick-grid i {
  --direction: 0deg;
  position: absolute;
  width: 15%;
  height: 15%;
  top: 8%;
  left: 42.5%;
  transform: rotate(var(--direction));
  transform-origin: 50% 280%;
  clip-path: polygon(50% 0, 100% 85%, 0 85%);
  background: #b9d6e5be;
}
.stick-grid i:nth-child(2) { --direction: 90deg; }
.stick-grid i:nth-child(3) { --direction: 180deg; }
.stick-grid i:nth-child(4) { --direction: 270deg; }
.stick-knob {
  z-index: 1;
  width: 38%;
  aspect-ratio: 1;
  border: 1px solid #bad5e3c4;
  border-radius: 50%;
  background: radial-gradient(circle at 36% 28%, #9ab2c6d0, #648196ad);
  box-shadow: inset 0 0 4px #d1f3ff58, 0 2px 4px #0a121744;
  transform: translate(var(--stick-x, 0px), var(--stick-y, 0px));
}
.fire-glyph {
  width: 58%;
  height: 58%;
  background: url("../assets/deep-space/ui/fire-glyph.png") center / contain no-repeat;
}
.active-tool:not([hidden]), .pocket-tool:not([hidden]) { display: grid; }
.active-tool, .pocket-tool {
  right: 4%;
  width: 44px;
  height: 44px;
  border-color: #b8916e;
  color: #ffe0b5;
  background: #16222edb;
  font-size: .74rem;
}
.pocket-tool { right: calc(4% + 50px); border-color: #90bacd; color: #c4efff; }
[data-touch] :is(.active-tool, .pocket-tool) { bottom: calc(clamp(10px, 6%, 52px) + var(--pad-size) + 4px); }
:is(.active-tool, .pocket-tool)[aria-disabled="true"] { opacity: .65; }
.arena:has(#overlay:not([hidden]), #debug-panel:not([hidden]), #flow:not([hidden]):not([data-flow-screen="pause"])) .control { visibility: hidden; }
.arena:has(#flow[data-flow-screen="pause"]:not([hidden])) .control { pointer-events: none; }
.arena:has(#flow[data-flow-screen="pause"]:not([hidden])) .fire:disabled { opacity: 1; }

.banner-area {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: clamp(4px, .8vw, 12px);
  padding: 2px clamp(4px, .9vw, 12px);
  border: 1px solid #5a6b7c;
  border-top-color: #344859;
  border-radius: 0 0 4px 4px;
  background: #121722;
  font: clamp(.68rem, calc(var(--screen-w) * .012), .86rem)/1.17 Menlo, Consolas, monospace;
}
#banner-slot { width: 100%; min-width: 0; }
#banner-slot > ins[data-ad-status="unfilled"] { display: none !important; }
.play-info { display: flex; min-width: 0; flex: 1; align-items: center; justify-content: space-between; gap: 2px; }
.run-feedback { display: grid; min-width: 0; gap: 2px; }
#status, #run-mechanic { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#run-mechanic { color: #f4cd97; }
#status { color: #b3c8d8; }
.header-tools { display: flex; gap: 3px; align-items: center; }
.header-tools button {
  display: grid;
  place-items: center;
  width: clamp(25px, 3.4vw, 41px);
  height: 26px;
  padding: 0;
  border: 1px solid #607887;
  border-radius: 4px;
  background: #16202b;
}
[data-touch] .header-tools button { width: 36px; height: 36px; }
.header-tools [aria-pressed="true"] { color: var(--cyan); border-color: #7bc6dc; }
#orientation, [data-native-touch] #touch-preview { display: none; }
[data-touch] #orientation { display: grid; }
.utility-icon { font-size: 17px; line-height: 1; }
.sound-glyph {
  display: block;
  width: 13px;
  height: 14px;
  background: currentColor;
  clip-path: polygon(0 28%, 35% 28%, 78% 0, 78% 100%, 35% 72%, 0 72%);
}
#sound[aria-pressed="false"] { color: #8c9fac; }
[data-layout="portrait"] .banner-area { gap: 4px; }

#flow { z-index: 2; background: #0b1018a6; color: var(--ink); }
#flow .mf-panel { background: #18232c; border-color: #657f8b; }
#overlay .panel, #debug-panel .panel, #flow:not([data-flow-screen="pause"]) .mf-panel {
  background: linear-gradient(155deg, #263744, #161f29 43%, #121b24);
  border-color: #657d8d;
  box-shadow: inset 0 1px #a8d9eb3d, inset 0 0 18px #101820ba, 0 11px 28px #05090eb5;
}
#flow[data-flow-screen="menu"] .mf-title, #flow[data-flow-screen="summary"] .mf-title {
  color: #cfebf5;
  letter-spacing: .08em;
}
#overlay[data-screen="floor-clear"] .panel {
  border-top-color: #c58a59;
  box-shadow: inset 0 2px #df965855, 0 11px 28px #05090eb5;
}
#overlay[data-screen="floor-clear"] .kicker { color: #e1ae7f; }
#flow :is(select, button) { color: var(--ink); border-color: #637c89; background: #222f3a; }
#flow :is(.mf-label, .mf-choice-detail, .mf-run-info, .mf-changes, .mf-stats dt) { color: #bfd0d8; }
#flow .mf-primary { color: #e8fbff; background: #284754; border-color: #97ddea; }
#flow .mf-primary:hover:enabled { background: #365b6b; }
#flow .mf-secondary:hover:enabled { background: #354955; }
#flow :is(button, select, input):focus-visible { outline-color: var(--cyan); }
#flow .mf-stats > div { background: #263846; }
#flow .mf-guide dt { color: var(--cyan); }
#flow .mf-setting input { accent-color: var(--cyan); }

#flow[data-flow-screen="pause"] {
  container-type: size;
  background: #10162091;
}
#flow[data-flow-screen="pause"] .mf-panel {
  width: min(86%, clamp(236px, 31cqw, 420px));
  position: relative;
  gap: clamp(5px, 1.6cqh, 12px);
  padding: clamp(12px, 3.9cqh, 27px) clamp(17px, 5.3cqw, 69px);
  border: none;
  border-radius: 0;
  background: radial-gradient(ellipse at 45% 2%, #263643, #1b272f 38%, #182229 80%);
  clip-path: polygon(13px 0, calc(100% - 13px) 0, 100% 13px, 100% calc(100% - 13px), calc(100% - 13px) 100%, 13px 100%, 0 calc(100% - 13px), 0 13px);
  box-shadow: none;
}
#flow[data-flow-screen="pause"] .mf-panel::before {
  content: "";
  position: absolute;
  inset: 0;
  border: 14px solid transparent;
  border-image: url("../assets/deep-space/ui/pause-rim.png") 18 22 18 22 stretch;
  pointer-events: none;
}
#flow[data-flow-screen="pause"] .mf-title {
  display: flex;
  gap: .4em;
  align-items: center;
  justify-content: center;
  color: #c2d8e6;
  font: 550 clamp(1.16rem, calc(2cqw + .2rem), 2.05rem)/1.15 system-ui, sans-serif;
  letter-spacing: .15em;
  text-transform: uppercase;
  text-align: center;
}
#flow[data-flow-screen="pause"] .mf-title::before, #flow[data-flow-screen="pause"] .mf-title::after {
  content: "";
  flex: 1 0 .45em;
  height: 1px;
  background: linear-gradient(90deg, transparent, #a2bfce9e);
}
#flow[data-flow-screen="pause"] .mf-title::after { transform: scaleX(-1); }
#flow[data-flow-screen="pause"] .mf-actions { display: grid; gap: clamp(5px, 1.5cqh, 12px); }
#flow[data-flow-screen="pause"] .mf-actions button {
  min-height: clamp(31px, 8.5cqh, 49px);
  padding: 3px 8px;
  color: #e1eef6;
  border: 1.5px solid #647a86;
  border-radius: 4px;
  background: #253039;
  font: 550 clamp(.78rem, 2.1cqh, 1.35rem)/1.12 Menlo, Consolas, monospace;
  letter-spacing: .05em;
  text-transform: uppercase;
}
[data-touch] #flow[data-flow-screen="pause"] .mf-actions button { min-height: 40px; }
#flow[data-flow-screen="pause"] .mf-actions .mf-primary {
  border-color: #a5f3ff;
  background: #2b434d;
  box-shadow: inset 0 0 5px #91ebff8c, 0 0 5px #8edbff82;
}
#flow[data-flow-screen="pause"] .mf-actions button:hover:enabled { background: #395764; }
.mf-pause-details { color: #9aafbc; font-size: .74rem; }
.mf-pause-details summary { cursor: pointer; text-align: center; }
.mf-pause-details[open] > :not(summary) { margin-top: 7px !important; }
#flow[data-flow-screen="pause"] .mf-pause-details .mf-stats { grid-template-columns: 1fr; }
