/* Shell: the stage around the game screen, the HUD (player plates), the hub, the slide-in pane, the docked pane on
   desktop, the ticker, the gold footer menu and the Menu sheet.

   One grid holds everything (.bfc-app):
     phone/tablet   [ hud ] [ hub | pane (over the hub) ] [ ticker ] [ footer ]        one column, max 480 px
     >= 1100 px     [ hud / hub / ticker / footer ] [ pane, full height ]          game screen left, pane docked right */

/* ---------------------------------------------------------------- stage */
.bfc-stage {
  position: fixed; inset: 0; overflow: clip;   /* clip, not hidden: the blurred world (inset -24px) must never let the stage scroll */
  display: flex; justify-content: center; align-items: stretch;
  background: var(--bfc-night);
}
.bfc-stage::before {          /* the world around the screen: town art, blurred (wide screens only, see media query) */
  content: ""; position: absolute; inset: -24px; display: none;
  background: var(--bfc-night) var(--bfc-world, url(../assets/bg/town-wide.webp)) center 30% / cover no-repeat;
  filter: blur(6px) brightness(.5) saturate(1.15);
}
.bfc-stage::after {
  content: ""; position: absolute; inset: 0; pointer-events: none; display: none;
  background: radial-gradient(ellipse at center, transparent 35%, rgba(3, 6, 18, .85) 100%);
}
.bfc-stage[data-world="map"] { --bfc-world: url(../assets/bg/world.webp); }

/* ---------------------------------------------------------------- app grid */
.bfc-app {
  position: relative; z-index: 1;
  width: min(100%, var(--bfc-screen-max)); height: 100dvh;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr) auto auto;
  grid-template-areas: "hud" "body" "ticker" "foot";
  background: #0a1022 center / cover;           /* base.webp only once warm (shell.js warmPanes): Home never shows it */
  isolation: isolate; overflow: hidden;
  overflow: clip;            /* clip, not hidden: focus() / scrollIntoView can never scroll the frame itself */
}
.bfc-main { display: contents; }
.bfc-hud { grid-area: hud; }
.bfc-hub { grid-area: body; }
.bfc-pane { grid-area: body / body / ticker / ticker; }      /* phone: covers hub + ticker, never the footer */
.bfc-sheet { grid-area: body / body / ticker / ticker; }
.bfc-ticker { grid-area: ticker; }
.bfc-footer { grid-area: foot; }

@media (min-width: 700px) {
  .bfc-stage { align-items: center; }
  .bfc-stage::before, .bfc-stage::after { display: block; }
  .bfc-app {
    height: min(100dvh - 24px, var(--bfc-frame-h));
    border-radius: 6px;
    box-shadow: 0 0 0 2px #000, 0 0 0 4px var(--bfc-gold-2), 0 0 0 6px #000, 0 30px 80px rgba(0, 0, 0, .8);
  }
}

/* ---------------------------------------------------------------- HUD: header_ui frame with live numbers */
.bfc-hud {
  --bfc-hud-digit: 2.55cqw;
  position: relative; z-index: var(--bfc-z-hud);
  aspect-ratio: 644 / 160;
  background: url(../assets/ui/header.webp) center / 100% 100% no-repeat;
  container-type: inline-size;
}
.bfc-hud__home { position: absolute; left: 34%; top: 0; width: 32%; height: 100%; border-radius: 20px; }
/* number slots of header.webp, measured on the 1288 px art: each striped slot is ~3.6cqw tall (Lv/RC centre 8.15cqw,
   Gems 8.2, Zel 12.95, Karma 17.7). Digits sit at the game's own size, about 60% of the slot, never filling it. */
.bfc-hud__f { position: absolute; display: flex; align-items: center; height: 3.6cqw; font-size: var(--bfc-hud-digit); }
.bfc-hud__lv { left: 7.9cqw; top: 6.35cqw; width: 7.6cqw; box-sizing: border-box; justify-content: flex-end; padding-right: 1.1cqw; }   /* the dark Lv slot in header.webp: 7.4-15.9% */
.bfc-hud__rc { left: 22.9cqw; top: 6.35cqw; width: 5.6cqw; box-sizing: border-box; justify-content: flex-end; padding-right: 1.1cqw; }  /* the RC slot: 22.5-28.7% */
/* no raid class (never raided): the header without "RC" (_tools/build_header_norc.py), one long Lv slot 7.4-29% */
.bfc-hud.is-norc { background-image: url(../assets/ui/header-norc.webp); }
.bfc-hud.is-norc .bfc-hud__lv { width: 20.6cqw; }
/* the EXP and Energy slots of header.webp, measured on the 1288 px art: x 8.7-28.9cqw, EXP y 11.1-14.3, Energy y 15.8-18.6 */
.bfc-hud__g { position: absolute; left: 8.8cqw; width: 20cqw; height: 3cqw; border-radius: 2cqw; overflow: hidden; background: #0a0f1a; box-shadow: inset 0 1px 2px #000; }
.bfc-hud__g > i { position: absolute; inset: 0 auto 0 0; border-radius: inherit; }
.bfc-hud__exp { top: 11.2cqw; }
.bfc-hud__exp > i { background: linear-gradient(var(--bfc-exp-a), var(--bfc-exp-b) 30%, var(--bfc-exp-a) 62%, #d54a0c); }
.bfc-hud__nrg { top: 15.9cqw; height: 2.7cqw; }
.bfc-hud__nrg > i { background: linear-gradient(var(--bfc-nrg-a), var(--bfc-nrg-b) 30%, var(--bfc-nrg-a) 62%, #1bd407); }
.bfc-hud__g .bfc-num { position: absolute; right: 1cqw; top: 50%; transform: translateY(-50%); font-size: 2.3cqw; }
.bfc-hud__gem, .bfc-hud__zel, .bfc-hud__kar { left: 77.4cqw; width: 20.8cqw; box-sizing: border-box; justify-content: flex-end; padding-right: 1.6cqw; }
.bfc-hud__gem { top: 6.4cqw; } .bfc-hud__zel { top: 11.15cqw; } .bfc-hud__kar { top: 15.9cqw; }
/* the three orb sockets of header.webp (centres 86.3 / 90.4 / 94.4cqw, row centre 22.1cqw, 2.5cqw across): one orb per
   socket; a player with more than three shows "+N" on the last one */
.bfc-hud__orbs { position: absolute; inset: 0; pointer-events: none; }
.bfc-hud__orbs i { position: absolute; top: 20.85cqw; width: 2.5cqw; height: 2.5cqw; margin-left: -1.25cqw; border-radius: 50%; background: radial-gradient(circle at 35% 30%, #fff8c8, #ffb400 45%, #7a3d00); box-shadow: 0 0 1cqw #ffb400; }
.bfc-hud__orbs i:nth-child(1) { left: 86.3cqw; } .bfc-hud__orbs i:nth-child(2) { left: 90.4cqw; } .bfc-hud__orbs i:nth-child(3) { left: 94.4cqw; }
.bfc-hud__orbs i.is-off { background: transparent; box-shadow: none; }
.bfc-hud__orbs-more { position: absolute; left: 94.4cqw; top: 22.1cqw; transform: translate(-50%, -50%); font: 800 1.7cqw/1 var(--bfc-font-game); color: #fff3c4; text-shadow: var(--bfc-outline-thin); }
.bfc-hud.is-loading .bfc-hud__f, .bfc-hud.is-loading .bfc-hud__g > i { opacity: 0; }

/* ---------------------------------------------------------------- hub (the Home scene) */
.bfc-hub {
  position: relative; z-index: var(--bfc-z-content); min-height: 0;
  overflow-y: auto; overflow-x: hidden; overscroll-behavior: contain;
  background: #6aa8e8 url(../assets/bg/town.webp) center 0 / cover no-repeat;
}
.bfc-app.is-warm, .bfc-app.is-warm .bfc-pane, .bfc-app.is-warm .bfc-sheet { background-image: url(../assets/bg/base.webp); }
/* phone: the hub hides under an open pane or sheet only once the slide over it has ended (same duration). Phones only:
   on the desktop the hub stays in view, and a resize across the breakpoint must not wait out this delay. */
@media (max-width: 1099.98px) { .bfc-hub[inert] { visibility: hidden; transition: visibility 0s var(--bfc-dur-slow); } }

/* ---------------------------------------------------------------- pane: a section screen */
.bfc-pane {
  position: relative; z-index: var(--bfc-z-pane); min-height: 0;
  display: grid; grid-template-rows: auto minmax(0, 1fr); grid-template-columns: minmax(0, 1fr); min-width: 0;
  background: #0a1022 center / cover;
  box-shadow: 0 0 0 2px #000;
  transform: translateX(104%); visibility: hidden;
  transition: transform var(--bfc-dur-slow) var(--bfc-ease-out), visibility 0s var(--bfc-dur-slow);
}
.bfc-pane.is-open { transform: none; visibility: visible; transition: transform var(--bfc-dur-slow) var(--bfc-ease-out); }
@media (max-width: 1099.98px) { .bfc-pane { will-change: transform; } }
.bfc-pane.is-instant { transition: none; }   /* a deep link, or a screen put in place under the Menu sheet: no slide */
.bfc-pane__body { position: relative; min-height: 0; min-width: 0; overflow-y: auto; overflow-x: hidden; overscroll-behavior: contain; }
.bfc-pane__body.is-enter { animation: bfc-pane-in var(--bfc-dur) var(--bfc-ease-out) both; }   /* pane at rest */
.bfc-pane__body.is-fade { animation: bfc-pane-fade var(--bfc-dur) var(--bfc-ease-out) both; }  /* pane still sliding */
@keyframes bfc-pane-in { from { opacity: 0; transform: translateX(24px); } }
@keyframes bfc-pane-fade { from { opacity: 0; } }

/* title bar: Back + the gold title plate */
.bfc-titlebar {
  position: relative; z-index: 4; display: flex; align-items: center; gap: 8px;
  min-height: 54px; padding: 4px 10px 4px 6px;
  background: linear-gradient(#0d1a3e, #060d24); border-bottom: 2px solid #000;
  box-shadow: inset 0 -1px 0 rgba(255, 220, 140, .25);
}
.bfc-back {
  display: block; flex: none; width: 64px; height: 46px; border: 0; padding: 0; cursor: pointer; border-radius: 8px;
  background: url(../assets/ui/back.png) center / contain no-repeat;
  color: transparent; font-size: 0; transition: transform var(--bfc-dur-fast), filter .15s;
}
.bfc-back:hover { filter: brightness(1.15); }
.bfc-back:active { background-image: url(../assets/ui/back-down.png); transform: translateY(1px); }
.bfc-back[hidden] { display: none; }
.bfc-titlebar__plate {
  flex: 1; min-width: 0; height: 42px; display: flex; align-items: center; gap: 8px; padding: 0 40px 0 6px;
  border-style: solid; border-color: transparent; border-width: 0 34px 0 30px;
  border-image: url(../assets/ui/title-bar.webp) 0 110 0 200 fill / 0 34px 0 30px stretch;
}
.bfc-titlebar h1 {
  min-width: 0; flex: 1; margin-left: -16px; padding: 2px 4px;   /* padding: the clip box must not shave the first glyph or the outline */
  font: 800 var(--bfc-fs-xl)/1.1 var(--bfc-font-game); color: #fff; text-shadow: var(--bfc-outline);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.bfc-titlebar__extra { flex: none; display: flex; align-items: center; gap: 6px; font: 800 15px/1 var(--bfc-font-game); color: var(--bfc-ink-gold); text-shadow: var(--bfc-outline); white-space: nowrap; }
.bfc-titlebar__extra:empty { display: none; }
.bfc-titlebar__extra .bfc-num { font-size: 16px; }

/* ---------------------------------------------------------------- ticker (footer_base news strip) */
.bfc-ticker {
  position: relative; z-index: var(--bfc-z-ticker); height: 30px; overflow: hidden;
  background: url(../assets/ui/ticker.webp) center / 100% 100%;
  border-top: 1px solid #000; font-size: 13px;
}
.bfc-ticker p { position: absolute; top: 0; bottom: 0; left: 0; display: flex; align-items: center; padding-top: 1px; white-space: nowrap; line-height: 1; animation: bfc-tick 40s linear infinite; }
/* a run is never narrower than the screen, so the two copies always cover the strip */
.bfc-ticker__run { display: flex; flex: none; min-width: var(--bfc-screen-max); padding-left: var(--bfc-gutter); }
.bfc-ticker__run span { margin-right: 48px; }
.bfc-ticker p b { color: var(--bfc-ink-gold); }
.bfc-ticker:hover p, .bfc-ticker:focus-within p { animation-play-state: paused; }
@keyframes bfc-tick { to { transform: translateX(-50%); } }
@media (prefers-reduced-motion: reduce) { .bfc-ticker p { animation: none; } .bfc-ticker__run[aria-hidden] { display: none; } }

/* ---------------------------------------------------------------- footer: the gold menu bar (primary nav) */
.bfc-footer {
  position: relative; z-index: var(--bfc-z-footer);
  display: grid; grid-template-columns: repeat(5, 1fr); align-items: end;
  padding: 6px 4px calc(7px + env(safe-area-inset-bottom));
  background: url(../assets/ui/footer-base.webp) center / 100% 100%;
  border-top: 2px solid #000; box-shadow: 0 -2px 0 rgba(255, 255, 255, .08), 0 -8px 18px rgba(0, 0, 0, .55);
}
.bfc-fbtn {
  position: relative; display: block; margin: 0 auto; width: min(18.6vw, 84px); aspect-ratio: 111 / 108;
  background: url(../assets/ui/foot-plate.png) center / 100% 100% no-repeat; border: 0; padding: 0; border-radius: 16px;
  text-decoration: none; color: #fff; cursor: pointer;
  transition: transform var(--bfc-dur-fast) var(--bfc-ease-out), filter .15s;
}
.bfc-fbtn img { position: absolute; left: 50%; top: 9%; width: 72%; height: 58%; object-fit: contain; object-position: 50% 100%; transform: translateX(-50%); pointer-events: none; filter: drop-shadow(0 1px 0 rgba(0, 0, 0, .35)); }
.bfc-fbtn span {
  position: absolute; left: 0; right: 0; bottom: 9%; text-align: center;
  font: 800 clamp(11px, 3.6vw, 15px)/1 var(--bfc-font-game); letter-spacing: .01em;
  color: #fff; text-shadow: 0 2px 0 #000, 1px 1px 0 #000, -1px 1px 0 #000, 1px -1px 0 #000, -1px -1px 0 #000, 0 0 3px #000;
}
.bfc-fbtn:hover { filter: brightness(1.12) drop-shadow(0 0 6px rgba(255, 220, 120, .55)); }
.bfc-fbtn:active { transform: translateY(1px) scale(.97); background-image: url(../assets/ui/foot-plate-on.png); }
.bfc-fbtn[aria-current="page"], .bfc-fbtn[aria-expanded="true"] {
  background-image: url(../assets/ui/foot-plate-on.png);
  filter: drop-shadow(0 0 5px #ffe28a) drop-shadow(0 0 12px rgba(255, 196, 60, .75)); transform: translateY(-3px);
}
.bfc-fbtn[aria-current="page"]::after, .bfc-fbtn[aria-expanded="true"]::after {
  content: ""; position: absolute; left: 50%; bottom: -7px; width: 26%; height: 4px; transform: translateX(-50%);
  border-radius: 2px; background: #fff3b8; box-shadow: 0 0 8px 2px #ffc93c;
}
.bfc-fbtn:focus-visible { box-shadow: var(--bfc-focus); }
/* while the Menu sheet is up, only Menu is lit: the section under it is not where the player is looking */
.bfc-app.is-menu .bfc-fbtn[aria-current="page"] { background-image: url(../assets/ui/foot-plate.png); filter: none; transform: none; }
.bfc-app.is-menu .bfc-fbtn[aria-current="page"]::after { content: none; }
.bfc-fbtn .bfc-badge-dot { position: absolute; right: -2px; top: -4px; }

/* ---------------------------------------------------------------- Menu sheet: every section
   It rises from behind the gold footer (the footer is the higher layer, see the z tokens) and covers hub, pane and
   ticker. shell.js owns its states: .is-shown makes it visible for the whole motion and is only taken away once the
   closing slide has ended; .is-open only moves it. Never animate anything but transform/opacity here. */
.bfc-sheet {
  position: relative; z-index: var(--bfc-z-sheet); min-height: 0;
  display: grid; grid-template-rows: auto minmax(0, 1fr); grid-template-columns: minmax(0, 1fr); min-width: 0;
  background: rgba(4, 9, 26, .97) center / cover;
  box-shadow: 0 0 0 2px #000;
  transform: translateY(104%); visibility: hidden;
  transition: transform var(--bfc-dur-slow) var(--bfc-ease-out);
  will-change: transform;
}
.bfc-sheet.is-shown { visibility: visible; }
.bfc-sheet.is-open { transform: none; }
.bfc-menu--last { margin-top: 18px; }
.bfc-sheet__body { min-height: 0; overflow-y: auto; padding: var(--bfc-sp-3) var(--bfc-gutter) var(--bfc-sp-5); }
.bfc-menu { display: grid; gap: 8px; list-style: none; }
.bfc-menu__group { margin: 14px 2px 6px; }
.bfc-menu .bfc-row[aria-current="page"] { filter: brightness(1.18); box-shadow: 0 2px 0 #000, 0 0 0 2px var(--bfc-gold-1), 0 0 14px rgba(255, 220, 120, .5); }
.bfc-menu .bfc-row[aria-current="page"] .bfc-row__title::after { content: "You are here"; margin-left: 8px; padding: 1px 7px; border-radius: 4px; font: 800 10.5px/1.5 var(--bfc-font-game); color: var(--bfc-ink-dark); text-shadow: none; background: linear-gradient(#fff3c4, #e2b450); vertical-align: 2px; }
.bfc-menu__ico { flex: none; width: 52px; height: 44px; object-fit: contain; filter: drop-shadow(0 2px 1px rgba(0, 0, 0, .6)); }
.bfc-menu__ico--crest { object-fit: cover; object-position: 50% 80%; }

/* ---------------------------------------------------------------- full-bleed screens (sign-in) hide the chrome */
.bfc-app.is-bare { grid-template-rows: minmax(0, 1fr); grid-template-areas: "body"; }
.bfc-app.is-bare .bfc-hud, .bfc-app.is-bare .bfc-ticker, .bfc-app.is-bare .bfc-footer, .bfc-app.is-bare .bfc-hub { display: none; }
.bfc-app.is-bare .bfc-pane { grid-area: body; transform: none; visibility: visible; box-shadow: none; transition: none; }
.bfc-app.is-bare .bfc-pane .bfc-titlebar { display: none; }

/* ---------------------------------------------------------------- desktop: the pane docks beside the game screen */
@media (min-width: 1100px) {
  .bfc-app:not(.is-bare) {
    width: min(100% - 48px, calc(var(--bfc-screen-two) + var(--bfc-dock-max)));
    grid-template-columns: var(--bfc-screen-two) minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr) auto auto;
    grid-template-areas: "hud dock" "body dock" "ticker dock" "foot dock";
  }
  .bfc-app:not(.is-bare) .bfc-pane, .bfc-app:not(.is-bare) .bfc-sheet { grid-area: dock; }
  .bfc-app:not(.is-bare) .bfc-pane {
    transform: none; visibility: visible; transition: none;
    background: #0a1022 url(../assets/bg/emblem.webp) center / cover;
    border-left: 2px solid #000; box-shadow: inset 2px 0 0 var(--bfc-gold-3), inset 4px 0 0 #000;
  }
  .bfc-app:not(.is-bare) .bfc-hub[inert] { visibility: visible; }
  .bfc-app:not(.is-bare) .bfc-sheet { transform: translateX(-8px); opacity: 0; transition: opacity var(--bfc-dur), transform var(--bfc-dur) var(--bfc-ease-out); }
  .bfc-app:not(.is-bare) .bfc-sheet.is-open { transform: none; opacity: 1; }
  .bfc-app:not(.is-bare) .bfc-back.is-phone-only { display: none; }
}
@media (min-width: 1100px) and (max-width: 1259px) { .bfc-app:not(.is-bare) { --bfc-screen-two: 420px; } }
@media (min-width: 700px) { .bfc-app.is-bare { width: min(100% - 48px, 520px); } }
/* Reduced motion: the sheet and the pane are simply there or gone (shell.js finishes their states at once). */
@media (prefers-reduced-motion: reduce) {
  .bfc-sheet, .bfc-app:not(.is-bare) .bfc-sheet, .bfc-pane, .bfc-pane.is-open, .bfc-hub[inert] { transition: none; }
}
