/* Final-order HUD rules: keep every panel on one clean nine-slice layer. */
:root {
  --hud-frame: url("assets/ui/hud/ch1-ui-panel-frame-9slice-v2.png");
  --hud-frame-slice: 42 42 42 42;
  --hud-frame-width: 20px;
}

.status-panel,
.chapter-hud,
.minimap-panel,
.boss-panel,
.interaction-prompt,
.toast,
.inventory-panel,
.bottom-dock {
  border: var(--hud-frame-width) solid transparent;
  border-image: var(--hud-frame) var(--hud-frame-slice) / var(--hud-frame-width) stretch;
  border-radius: 0;
  background: rgba(249, 239, 216, .96);
  background-clip: padding-box;
  backdrop-filter: none;
}

.status-panel::before,
.status-panel::after,
.chapter-hud::before,
.chapter-hud::after,
.minimap-panel::before,
.minimap-panel::after,
.boss-panel::before,
.boss-panel::after,
.interaction-prompt::before,
.interaction-prompt::after,
.toast::before,
.toast::after {
  content: none;
}

.bottom-dock .public-chat,
.bottom-dock .quickbar {
  border: 0;
  border-image: none;
  background: transparent;
  box-shadow: none;
}

.chapter-hud.collapsed,
.minimap-panel.collapsed {
  box-sizing: border-box;
  height: 58px;
  min-height: 58px;
  padding: 0 2px;
}

.chapter-hud.collapsed {
  width: 184px;
}

.minimap-panel.collapsed {
  width: 150px;
}

.chapter-hud.collapsed .chapter-head,
.minimap-panel.collapsed .minimap-head {
  height: 18px;
  min-height: 18px;
  padding: 0;
}

.chapter-hud.collapsed .chapter-kicker,
.minimap-panel.collapsed .minimap-head span {
  display: none;
}

.chapter-hud.collapsed .chapter-head strong,
.minimap-panel.collapsed .minimap-head strong {
  display: block;
  overflow: hidden;
  font-size: 10px;
  line-height: 18px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

@media (max-width: 760px) {
  .bottom-dock,
  .bottom-dock:has(.public-chat.collapsed) {
    bottom: max(178px, calc(env(safe-area-inset-bottom) + 166px));
  }

  html.touch-ui .bottom-dock .quickbar,
  .bottom-dock .quickbar {
    position: static;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    width: 100%;
    max-width: none;
    transform: none;
  }

  .boss-panel,
  .interaction-prompt {
    bottom: max(300px, calc(env(safe-area-inset-bottom) + 288px));
  }
}

@media (max-width: 760px) and (orientation: landscape) {
  .bottom-dock,
  .bottom-dock:has(.public-chat.collapsed) {
    bottom: max(6px, env(safe-area-inset-bottom));
  }

  html.touch-ui .bottom-dock .quickbar,
  .bottom-dock .quickbar {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    width: 190px;
    max-width: none;
  }

  .boss-panel,
  .interaction-prompt {
    bottom: 104px;
  }
}

/* Compact public-channel dock: two rows of three icon buttons. Descriptions
   are exposed through the shared in-game tooltip instead of permanent labels. */
@media (min-width: 761px) {
  .bottom-dock,
  .bottom-dock:has(.public-chat.collapsed) {
    grid-template-columns: minmax(0, 1fr) 132px;
    gap: 6px;
    width: min(790px, calc(100vw - 32px));
    padding: 0 4px 4px;
  }

  .bottom-dock .public-chat {
    grid-template-rows: auto minmax(22px, 1fr) auto;
    min-height: 104px;
    height: 104px;
    max-height: 112px;
    padding: 5px 7px 4px;
  }

  .bottom-dock .chat-head {
    min-height: 18px;
  }

  .bottom-dock .chat-messages {
    max-height: 30px;
    margin-top: 1px;
  }

  .bottom-dock .chat-form {
    margin-top: 2px;
  }

  .bottom-dock .quickbar {
    display: grid;
    grid-template-columns: repeat(3, 40px);
    grid-template-rows: repeat(2, 36px);
    justify-content: center;
    align-content: center;
    gap: 4px;
    width: 132px;
    min-height: 78px;
    padding: 2px;
  }

  .bottom-dock .quickbar button {
    position: relative;
    display: grid;
    grid-template-columns: 1fr;
    place-items: center;
    min-width: 36px;
    min-height: 34px;
    padding: 0;
  }

  .bottom-dock .quickbar button::before {
    width: 28px;
    height: 28px;
  }

  .bottom-dock .quickbar button span {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    clip-path: inset(50%);
    white-space: nowrap;
  }

  .bottom-dock .quickbar button small {
    left: 24px;
    bottom: -1px;
  }
}

@media (max-width: 760px) {
  html.touch-ui .bottom-dock .quickbar,
  .bottom-dock .quickbar {
    grid-template-columns: repeat(3, 1fr);
  }
}

/* M04 uses a compact text-only encounter progress indicator. */
.boss-panel.m04-text-only {
  display: block;
  width: max-content;
  min-width: 0;
  max-width: calc(100vw - 40px);
  padding: 0;
  border: 0;
  border-image: none;
  color: #fff8dc;
  background: transparent;
  box-shadow: none;
  backdrop-filter: none;
  contain: none;
  text-align: center;
}

.boss-panel.m04-text-only > div,
.boss-panel.m04-text-only .boss-meter {
  display: none;
}

.boss-panel.m04-text-only b {
  display: block;
  overflow: hidden;
  max-width: calc(100vw - 40px);
  font: 900 16px/1.35 "Microsoft YaHei", "PingFang SC", sans-serif;
  letter-spacing: .02em;
  text-overflow: ellipsis;
  text-shadow:
    0 2px 2px rgba(22, 18, 32, .95),
    1px 0 0 rgba(22, 18, 32, .95),
    -1px 0 0 rgba(22, 18, 32, .95),
    0 0 8px rgba(22, 18, 32, .72);
  white-space: nowrap;
}

/* The final structural boss owns a full, top-centred three-stage HUD. */
.boss-panel.m04-three-phase {
  top: max(14px, calc(env(safe-area-inset-top) + 8px));
  right: auto;
  bottom: auto !important;
  left: 50%;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 8px;
  box-sizing: border-box;
  width: min(860px, calc(100vw - 700px));
  min-width: 520px;
  max-width: calc(100vw - 28px);
  padding: 8px 14px 12px;
  color: #fff9e8;
  border-width: 22px;
  background:
    linear-gradient(180deg, rgba(35, 29, 48, .96), rgba(21, 22, 35, .94)) padding-box;
  box-shadow:
    0 12px 30px rgba(12, 15, 25, .34),
    0 0 0 1px rgba(255, 221, 145, .16) inset;
  transform: translate(-50%, -14px);
  contain: layout paint;
  text-align: left;
}

.boss-panel.m04-three-phase.open {
  transform: translate(-50%, 0);
}

.boss-panel.m04-three-phase .boss-heading {
  display: flex;
  min-width: 0;
  align-items: baseline;
  gap: 10px;
  padding-right: 150px;
}

.boss-panel.m04-three-phase .boss-heading span {
  flex: none;
  color: #8feaff;
  font: 900 11px/1.1 "Microsoft YaHei", "PingFang SC", sans-serif;
  letter-spacing: .12em;
}

.boss-panel.m04-three-phase .boss-heading strong {
  overflow: hidden;
  margin: 0;
  color: #fff4cf;
  font: 900 18px/1.2 "Microsoft YaHei", "PingFang SC", sans-serif;
  letter-spacing: .04em;
  text-overflow: ellipsis;
  text-shadow: 0 2px 5px rgba(0, 0, 0, .58);
  white-space: nowrap;
}

.boss-panel.m04-three-phase .boss-meter-legacy {
  display: none;
}

.boss-panel.m04-three-phase > #bossHpText {
  position: absolute;
  top: 10px;
  right: 16px;
  display: block;
  color: #ffdba4;
  font: 900 13px/1.2 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  letter-spacing: .02em;
  text-shadow: 0 2px 4px rgba(0, 0, 0, .62);
}

.boss-phase-stack {
  display: none;
}

.boss-panel.m04-three-phase .boss-phase-stack {
  display: grid;
  gap: 5px;
}

.boss-phase-row {
  display: grid;
  grid-template-columns: 112px minmax(0, 1fr) 70px;
  gap: 8px;
  align-items: center;
  min-width: 0;
  opacity: .72;
  transition: opacity .18s ease, filter .18s ease;
}

.boss-phase-row > span {
  overflow: hidden;
  color: #d8d1e5;
  font: 800 11px/1.1 "Microsoft YaHei", "PingFang SC", sans-serif;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.boss-phase-row > em {
  color: #c7c3d2;
  font: normal 800 10px/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  text-align: right;
  white-space: nowrap;
}

.boss-phase-row.active {
  opacity: 1;
  filter: drop-shadow(0 0 7px rgba(112, 222, 255, .22));
}

.boss-phase-row.active > span,
.boss-phase-row.active > em {
  color: #fff0bd;
}

.boss-phase-row.completed {
  opacity: .46;
}

.boss-phase-meter {
  position: relative;
  height: 14px;
  overflow: hidden;
  border: 2px solid rgba(255, 232, 186, .62);
  border-radius: 3px;
  background:
    repeating-linear-gradient(90deg, rgba(255,255,255,.035) 0 17%, rgba(0,0,0,.12) 17% 18%),
    rgba(8, 12, 22, .92);
  box-shadow: 0 2px 7px rgba(0, 0, 0, .42) inset;
}

.boss-phase-meter i {
  display: block;
  width: 100%;
  height: 100%;
  transform-origin: left center;
  transition: width .16s ease;
}

#bossPhaseBar1 {
  background: linear-gradient(90deg, #ef5e89, #ff96b2 62%, #ffd095);
  box-shadow: 0 0 9px rgba(255, 105, 150, .5);
}

#bossPhaseBar2 {
  background: linear-gradient(90deg, #8f60e8, #63c9f1 58%, #a8fbff);
  box-shadow: 0 0 9px rgba(112, 213, 255, .52);
}

#bossPhaseBar3 {
  background: linear-gradient(90deg, #ff6a3d, #f5c353 52%, #fff0a4);
  box-shadow: 0 0 10px rgba(255, 137, 67, .55);
}

@media (max-width: 1100px) {
  .boss-panel.m04-three-phase {
    width: min(680px, calc(100vw - 32px));
    min-width: 0;
  }
}

@media (max-width: 620px) {
  .boss-panel.m04-three-phase {
    top: max(6px, env(safe-area-inset-top));
    gap: 6px;
    width: calc(100vw - 16px);
    padding: 7px 9px 9px;
    border-width: 16px;
  }

  .boss-panel.m04-three-phase .boss-heading {
    padding-right: 0;
  }

  .boss-panel.m04-three-phase .boss-heading strong {
    font-size: 14px;
  }

  .boss-panel.m04-three-phase > #bossHpText {
    position: static;
    font-size: 11px;
    text-align: right;
  }

  .boss-phase-row {
    grid-template-columns: 86px minmax(0, 1fr) 54px;
    gap: 5px;
  }

  .boss-phase-row > span,
  .boss-phase-row > em {
    font-size: 9px;
  }
}
