/* SnarglyBarg Arcade - shared game header.
   See claude/header-spec.md. Load before the game's own stylesheet.

   Invariants: home is the first and leftmost control, account the last and rightmost.
   Everything between belongs to the game.

   Required ids, which are a contract with shared/arcade-bar.js:
     #accountBtn        the bar attaches itself to this (or #acctBtn); without it the bar
                        loads and renders nothing, with no error
     [data-arcade-nugs] host the bar appends its own nugs chip into (it styles .abchip itself,
                        so do not author the chip)

   Themeable with --ah-fg, --ah-bg, --ah-rule and --ah-accent.
   Set --ah-col to the game board's width so the header lines up with the board. */

.ah {
  display: flex;
  align-items: center;
  gap: 8px;
  box-sizing: border-box;
  width: 100%;
  max-width: var(--ah-col, 420px);
  margin: 0 auto;
  height: calc(56px + env(safe-area-inset-top, 0px));
  padding: env(safe-area-inset-top, 0px) 12px 0;
  color: var(--ah-fg, #fff3bb);
  background: var(--ah-bg, transparent);
  flex: 0 0 auto;
}

.ah-btn {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: inherit;
  font: inherit;
  cursor: pointer;
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
}

.ah-btn > svg { width: 22px; height: 22px; display: block; }
.ah-btn:hover { background: var(--ah-rule, #ffffff1f); }
.ah-btn:active { transform: translateY(1px); }
.ah-btn:focus-visible { outline: 2px solid var(--ah-accent, #ffe252); outline-offset: 2px; }

.ah-title {
  flex: 1 1 auto;
  min-width: 0;
  text-align: center;
  line-height: 1.1;
}

.ah-name {
  display: block;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  font-size: 15px;
  letter-spacing: .5px;
}

.ah-sub { display: none; }

.ah-right {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 8px;
  /* margin-left keeps the right group right-aligned even when the title is hidden
     on narrow phones and there is no flexible spacer left in the row. */
  margin-left: auto;
}

/* The account button may carry an avatar and a name once signed in. */
.ah-right .av { display: grid; place-items: center; }
.ah-right .av > svg { width: 22px; height: 22px; display: block; }
.ah-right .anm { display: none; }

/* Very narrow phones: the title is the first thing to go, never a control. */
@media (max-width: 379px) {
  .ah-title { display: none; }
  .ah { gap: 4px; padding-left: 8px; padding-right: 8px; }
}

@media (min-width: 720px) {
  .ah {
    height: calc(64px + env(safe-area-inset-top, 0px));
    padding-left: 16px;
    padding-right: 16px;
  }
  .ah-btn { width: 40px; height: 40px; }
  .ah-name { font-size: 17px; }
  .ah-sub {
    display: block;
    font-size: 12px;
    opacity: .72;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
  }
  .ah-right .anm { display: block; font-size: 13px; padding-right: 4px; }
  .ah-right #accountBtn,
  .ah-right #acctBtn { width: auto; gap: 6px; padding: 0 6px; grid-auto-flow: column; }
}

@media (prefers-reduced-motion: reduce) {
  .ah-btn:active { transform: none; }
}

/* ============================================================
   Normalizer for games that already have their own header skin.

   Add class "ah-norm" to the game's existing header container and load this
   file LAST in <head>, after the game's own <style>, so these rules win on
   equal specificity. The game keeps its colours, borders and type; only
   geometry and order are normalised.
   ============================================================ */

/* Deliberately no display/flex-direction here: several headers are multi-row by
   design (Driftword, Gridlock, Nova Dynasty) and forcing a single flex row
   collapses them. Only the band minimum and the safe-area inset are set. */
.ah-norm {
  box-sizing: border-box;
  min-height: 56px;
  padding-top: env(safe-area-inset-top, 0px);
}

/* Only home and account are sized here. They are the arcade's own furniture and
   the two controls the spec fixes; everything between them is the game's and
   keeps its own size. Sizing every control instead overflowed crowded headers
   (SNARGL carries six), which is a tool-budget problem for those games to fix,
   not something this layer should paper over.
   box-sizing matters: without it a padded text button adds its padding on top
   of the minimum and ends up far taller than 44. */
.ah-norm [href="/"],
.ah-norm [href="https://snarglbarg.com"],
.ah-norm [href="https://snarglbarg.com/"],
.ah-norm #homeBtn,
.ah-norm #home-btn,
.ah-norm #link-home,
.ah-norm #home,
.ah-norm .arcade-home,
.ah-norm #accountBtn,
.ah-norm #acctBtn {
  box-sizing: border-box;
  min-width: 44px;
  min-height: 44px;
}

@media (min-width: 720px) {
  .ah-norm [href="/"],
  .ah-norm [href="https://snarglbarg.com"],
  .ah-norm [href="https://snarglbarg.com/"],
  .ah-norm #homeBtn,
  .ah-norm #home-btn,
  .ah-norm #link-home,
  .ah-norm #home,
  .ah-norm .arcade-home,
  .ah-norm #accountBtn,
  .ah-norm #acctBtn { min-width: 40px; min-height: 40px; }
}

/* Home is always first and account always last, whatever the source order. */
.ah-norm [href="/"],
.ah-norm [href="https://snarglbarg.com"],
.ah-norm [href="https://snarglbarg.com/"],
.ah-norm #homeBtn,
.ah-norm #home-btn,
.ah-norm #link-home,
.ah-norm #home,
.ah-norm .arcade-home { order: -10; }

.ah-norm .abchip { order: 9; }

.ah-norm #accountBtn,
.ah-norm #acctBtn { order: 10; }

/* Anything the game marks as the flexible middle keeps the slack. */
.ah-norm .ah-flex { flex: 1 1 auto; min-width: 0; }

@media (min-width: 720px) {
  .ah-norm { min-height: 64px; }
}
