:root {
  --hb-safe-top: env(safe-area-inset-top, 0px);
  --hb-safe-right: env(safe-area-inset-right, 0px);
  --hb-safe-bottom: env(safe-area-inset-bottom, 0px);
  --hb-safe-left: env(safe-area-inset-left, 0px);
}

@media (max-width: 980px), (pointer: coarse) {
  html,
  body {
    min-width: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
  }

  .hb-standalone {
    width: 100dvw;
    height: 100svh;
    min-height: 100svh;
    overflow: hidden;
  }

  .hb-app {
    width: 100%;
    height: 100%;
    aspect-ratio: auto;
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
    padding:
      max(5px, var(--hb-safe-top))
      max(5px, var(--hb-safe-right))
      max(5px, var(--hb-safe-bottom))
      max(5px, var(--hb-safe-left));
    overflow: hidden;
  }

  .hb-app::after {
    top: max(4px, var(--hb-safe-top));
    right: max(4px, var(--hb-safe-right));
    bottom: max(4px, var(--hb-safe-bottom));
    left: max(4px, var(--hb-safe-left));
    border-width: 8px;
  }

  .hb-topbar {
    height: auto;
    min-height: 0;
    display: grid;
    grid-template-columns: 1fr;
    gap: 6px;
    padding: 8px;
  }

  .hb-topbar::after {
    width: 34px;
    height: 44px;
  }

  .hb-brand-lockup {
    min-width: 0;
    display: grid;
    grid-template-columns: minmax(104px, 142px) minmax(0, 1fr);
    gap: 8px;
    align-items: center;
  }

  .hb-wordmark {
    width: 100%;
    max-height: 34px;
    object-fit: contain;
    object-position: left center;
    transform: none;
  }

  .hb-brand-divider {
    display: none;
  }

  .hb-prestige {
    min-width: 0;
    overflow-wrap: anywhere;
    color: var(--hb-green);
    font-size: 12px;
    line-height: 1.05;
    white-space: normal;
  }

  .hb-resources {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr)) 44px;
    gap: 4px;
    align-items: stretch;
  }

  .hb-resource {
    --hb-resource-slot: 22px;
    min-width: 0;
    min-height: 32px;
    grid-template-columns: 22px minmax(0, 1fr);
    justify-content: start;
    column-gap: 3px;
    padding: 3px 4px;
    border: 1px solid rgba(216, 152, 32, .46);
    background: rgba(0, 0, 0, .22);
    font-size: 11px;
    letter-spacing: .035em;
  }

  .hb-resource__icon,
  .hb-resource--ticket .hb-resource__icon,
  .hb-resource--limited .hb-resource__icon {
    width: 22px;
    height: 22px;
  }

  .hb-resource > span {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .hb-resource--ticket {
    padding-left: 4px;
    border-left: 1px solid rgba(216, 152, 32, .46);
  }

  .hb-add {
    grid-column: 4;
    grid-row: 1 / span 2;
    width: 100%;
    height: auto;
    min-height: 44px;
  }

  .hb-shell-body {
    min-height: 0;
    height: 100%;
    display: grid;
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, 1fr) auto;
  }

  .hb-sidebar {
    grid-row: 2;
    min-height: 0;
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    grid-auto-flow: row;
    grid-auto-rows: 46px;
    gap: 4px;
    padding: 4px 0 0;
    overflow: hidden;
    border-right: 0;
    border-top: 2px solid var(--hb-gold);
  }

  .hb-sidebar::after,
  .hb-nav-item.is-active::after {
    display: none;
  }

  .hb-nav-item {
    min-width: 0;
    min-height: 46px;
    display: grid;
    grid-template-columns: 1fr;
    grid-template-rows: 1fr;
    justify-items: center;
    align-items: center;
    gap: 2px;
    padding: 4px 5px;
    border: 1px solid rgba(216, 152, 32, .55);
    font-size: 9px;
    letter-spacing: .035em;
    line-height: 1;
    text-align: center;
  }

  .hb-nav-item svg {
    width: 18px;
    height: 18px;
  }

  .hb-main {
    grid-row: 1;
    min-width: 0;
    min-height: 0;
    height: 100%;
    display: block;
    overflow-y: auto;
    overflow-x: hidden;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    background: var(--hb-ink);
  }

  .hb-hunt-hero,
  .hb-season-hero,
  .hb-ticket-hero,
  .hb-prepare-hero {
    min-height: 268px;
    height: auto;
    overflow: hidden;
  }

  .hb-promo-art {
    opacity: .72;
    object-position: 67% center;
  }

  .hb-hunt-panel,
  .hb-season-overview,
  .hb-ticket-overview,
  .hb-prepare-overview {
    width: auto;
    height: auto;
    min-height: 268px;
    padding: 14px 12px;
    background:
      linear-gradient(90deg, rgba(2, 14, 9, .99) 0%, rgba(2, 14, 9, .95) 78%, rgba(2, 14, 9, .36) 100%);
  }

  .hb-screen-heading {
    height: auto;
    min-height: 0;
    margin-bottom: 9px;
  }

  .hb-screen-heading h1,
  .hb-season-heading h1 {
    font-size: 32px;
    line-height: .95;
    white-space: normal;
  }

  .hb-screen-heading p,
  .hb-prepare-season-line {
    font-size: 12px;
    white-space: normal;
  }

  .hb-heading-rule {
    width: min(142px, 44vw);
    height: 8px;
    margin-top: 7px;
  }

  .hb-hunt-card {
    width: 100%;
    height: auto;
    min-height: 0;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto auto;
    gap: 7px 0;
    margin-top: 8px;
    padding: 12px 10px 10px;
  }

  .hb-hunt-card__icon svg {
    width: 30px;
    height: 30px;
  }

  .hb-hunt-card__copy h2,
  .hb-hunt-card__copy p {
    white-space: normal;
  }

  .hb-hunt-card__copy h2 {
    font-size: 18px;
  }

  .hb-hunt-card__copy p {
    font-size: 13px;
  }

  .hb-hunt-card > button {
    grid-column: 1 / -1;
    bottom: 0;
    margin-bottom: 9px;
    min-height: 44px;
    height: auto;
    font-size: 15px;
  }

  .hb-dashboard,
  .hb-season-dashboard,
  .hb-ticket-dashboard,
  .hb-leaderboard-dashboard,
  .hb-prepare-dashboard {
    min-height: 0;
    display: grid;
    grid-template-columns: 1fr;
  }

  .hb-dashboard > article,
  .hb-season-dashboard > article,
  .hb-ticket-dashboard > article,
  .hb-leaderboard-dashboard > article,
  .hb-prepare-dashboard > article {
    min-height: auto;
    overflow: visible;
    padding: 14px 12px;
    border-right: 0;
    border-bottom: 2px solid var(--hb-gold);
  }

  .hb-dashboard > article:last-child,
  .hb-season-dashboard > article:last-child,
  .hb-ticket-dashboard > article:last-child,
  .hb-leaderboard-dashboard > article:last-child,
  .hb-prepare-dashboard > article:last-child {
    border-bottom: 0;
  }

  .hb-panel-heading {
    display: grid;
    gap: 4px;
  }

  .hb-panel-heading h2,
  .hb-featured__heading h2,
  .hb-season-dashboard h2,
  .hb-ticket-dashboard h2,
  .hb-leaderboard-dashboard h2,
  .hb-prepare-dashboard h2 {
    font-size: 20px;
    line-height: 1;
  }

  .hb-bounty-list div,
  .hb-season-summary dl div,
  .hb-season-rules dl div,
  .hb-ticket-payment dl div,
  .hb-ticket-controller dl div,
  .hb-ticket-certificate__body dl div,
  .hb-ticket-record dl div,
  .hb-leaderboard-prize-card dl div,
  .hb-prepare-rules dl div,
  .hb-prepare-loadout dl div {
    min-height: 36px;
    gap: 8px;
    padding: 6px 0;
  }

  .hb-bounty-list dt,
  .hb-bounty-list dd,
  .hb-season-summary dt,
  .hb-season-summary dd,
  .hb-season-rules dt,
  .hb-season-rules dd,
  .hb-ticket-payment dt,
  .hb-ticket-payment dd,
  .hb-ticket-controller dt,
  .hb-ticket-controller dd,
  .hb-ticket-certificate__body dt,
  .hb-ticket-certificate__body dd,
  .hb-ticket-record dt,
  .hb-ticket-record dd,
  .hb-leaderboard-prize-card dt,
  .hb-leaderboard-prize-card dd,
  .hb-prepare-rules dt,
  .hb-prepare-rules dd,
  .hb-prepare-loadout dt,
  .hb-prepare-loadout dd {
    font-size: 13px;
    line-height: 1.15;
    white-space: normal;
  }

  .hb-season-tabs {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 5px;
    margin-top: 8px;
  }

  .hb-season-tabs button {
    min-width: 0;
    min-height: 44px;
    height: auto;
    padding: 5px;
    font-size: 11px;
    line-height: 1;
    white-space: normal;
  }

  .hb-season-summary,
  .hb-ticket-review-summary,
  .hb-ticket-secured-summary,
  .hb-prepare-state {
    width: 100%;
  }

  .hb-season-ticket ol {
    width: 100%;
  }

  .hb-season-ticket li,
  .hb-ticket-terms li,
  .hb-ticket-next li,
  .hb-prepare-state li {
    min-height: 38px;
    font-size: 13px;
    line-height: 1.15;
  }

  .hb-season-ticket__notes {
    position: relative;
    top: auto;
    right: auto;
    width: 100%;
    margin-top: 9px;
    padding-left: 10px;
  }

  .hb-season-ticket__notes p {
    margin-bottom: 8px;
    font-size: 12px;
  }

  .hb-season-ticket > .hb-ledger-button,
  .hb-season-leaderboard__actions,
  .hb-ticket-actions,
  .hb-full-leaderboard__actions,
  .hb-prepare-panel-action,
  .hb-prepare-final-actions {
    position: relative;
    left: auto;
    right: auto;
    bottom: auto;
    width: 100%;
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
    margin-top: 10px;
  }

  .hb-ledger-button,
  .hb-season-leaderboard__actions .hb-ledger-button,
  .hb-ticket-actions .hb-ledger-button,
  .hb-full-leaderboard__actions .hb-ledger-button,
  .hb-prepare-panel-action .hb-ledger-button,
  .hb-prepare-final-actions .hb-ledger-button {
    width: 100%;
    min-width: 0;
    min-height: 44px;
    height: auto;
    padding: 8px 10px;
    font-size: 14px;
    line-height: 1;
    white-space: normal;
  }

  .hb-prepare-foundation-list {
    gap: 8px;
  }

  .hb-prepare-foundation-option {
    min-height: 44px;
    padding: 8px 10px;
    font-size: 13px;
    line-height: 1.15;
    white-space: normal;
  }

  .hb-prepare-foundation-note,
  .hb-ticket-terms__timer,
  .hb-full-leaderboard__note,
  .hb-season-leaderboard__note {
    font-size: 12px;
    line-height: 1.2;
  }

  .hb-season-leaderboard table,
  .hb-full-leaderboard table {
    table-layout: auto;
  }

  .hb-season-leaderboard th,
  .hb-season-leaderboard td,
  .hb-full-leaderboard th,
  .hb-full-leaderboard td {
    height: auto;
    padding: 7px 4px;
    font-size: 11px;
    line-height: 1.1;
    white-space: normal;
  }

  .hb-full-leaderboard th:first-child,
  .hb-full-leaderboard td:first-child,
  .hb-full-leaderboard th:nth-child(2),
  .hb-full-leaderboard td:nth-child(2),
  .hb-full-leaderboard th:nth-child(3),
  .hb-full-leaderboard td:nth-child(3),
  .hb-full-leaderboard th:nth-child(4),
  .hb-full-leaderboard td:nth-child(4),
  .hb-full-leaderboard th:nth-child(5),
  .hb-full-leaderboard td:nth-child(5) {
    width: auto;
  }

  .hb-ticket-stamp {
    width: 100%;
    margin-top: 10px;
    padding: 5px 6px;
    font-size: 16px;
  }
}

@media (max-width: 980px) and (orientation: landscape) {
  .hb-app {
    grid-template-rows: auto minmax(0, 1fr);
    padding:
      max(4px, var(--hb-safe-top))
      max(4px, var(--hb-safe-right))
      max(4px, var(--hb-safe-bottom))
      max(4px, var(--hb-safe-left));
  }

  .hb-topbar {
    grid-template-columns: minmax(178px, .56fr) minmax(0, 1fr);
    align-items: center;
    padding: 5px 7px;
  }

  .hb-wordmark {
    max-height: 28px;
  }

  .hb-prestige {
    font-size: 10px;
  }

  .hb-resources {
    grid-template-columns: repeat(6, minmax(0, 1fr)) 36px;
    gap: 3px;
  }

  .hb-resource {
    min-height: 28px;
    grid-template-columns: 18px minmax(0, 1fr);
    font-size: 10px;
  }

  .hb-resource__icon,
  .hb-resource--ticket .hb-resource__icon,
  .hb-resource--limited .hb-resource__icon {
    width: 18px;
    height: 18px;
  }

  .hb-add {
    grid-column: 7;
    grid-row: 1;
    min-height: 28px;
  }

  .hb-shell-body {
    grid-template-columns: 84px minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr);
  }

  .hb-sidebar {
    grid-column: 1;
    grid-row: 1;
    grid-auto-flow: row;
    grid-auto-columns: auto;
    grid-template-rows: repeat(8, minmax(0, 1fr));
    gap: 3px;
    padding: 0 4px 0 0;
    overflow: hidden;
    border-top: 0;
    border-right: 2px solid var(--hb-gold);
  }

  .hb-nav-item {
    min-width: 0;
    min-height: 0;
    grid-template-rows: 18px 1fr;
    padding: 2px 3px;
    font-size: 8px;
  }

  .hb-nav-item svg {
    width: 16px;
    height: 16px;
  }

  .hb-main {
    grid-column: 2;
    grid-row: 1;
  }

  .hb-hunt-hero,
  .hb-season-hero,
  .hb-ticket-hero,
  .hb-prepare-hero {
    min-height: 218px;
  }

  .hb-hunt-panel,
  .hb-season-overview,
  .hb-ticket-overview,
  .hb-prepare-overview {
    min-height: 218px;
    width: min(55%, 390px);
    padding: 10px;
  }

  .hb-screen-heading h1,
  .hb-season-heading h1 {
    font-size: 32px;
  }

  .hb-hunt-card {
    grid-template-columns: minmax(0, 1fr);
    padding: 8px;
  }

  .hb-hunt-card__copy h2 {
    font-size: 16px;
  }

  .hb-hunt-card__copy p {
    font-size: 11px;
  }

  .hb-hunt-card > button {
    min-height: 34px;
    font-size: 12px;
  }

  .hb-dashboard,
  .hb-season-dashboard,
  .hb-ticket-dashboard,
  .hb-leaderboard-dashboard,
  .hb-prepare-dashboard {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .hb-dashboard > article,
  .hb-season-dashboard > article,
  .hb-ticket-dashboard > article,
  .hb-leaderboard-dashboard > article,
  .hb-prepare-dashboard > article {
    border-right: 2px solid var(--hb-gold);
    border-bottom: 2px solid var(--hb-gold);
    padding: 10px;
  }

  .hb-dashboard > article:nth-child(2n),
  .hb-season-dashboard > article:nth-child(2n),
  .hb-ticket-dashboard > article:nth-child(2n),
  .hb-leaderboard-dashboard > article:nth-child(2n),
  .hb-prepare-dashboard > article:nth-child(2n) {
    border-right: 0;
  }

  .hb-leaderboard-dashboard .hb-full-leaderboard,
  .hb-prepare-dashboard .hb-prepare-foundation {
    grid-column: 1 / -1;
  }
}

@media (max-width: 359px) {
  .hb-topbar {
    padding: 6px;
  }

  .hb-brand-lockup {
    grid-template-columns: minmax(92px, 118px) minmax(0, 1fr);
  }

  .hb-resource {
    font-size: 10px;
  }

  .hb-nav-item {
    font-size: 8px;
  }
}

/* Pre-Senior mobile containment audit V7. These rules deliberately sit last
   so every mobile screen shares one scroll, wrapping and action contract. */
@media (max-width: 980px), (pointer: coarse) {
  .hb-shell-body {
    height: auto;
    align-self: stretch;
    overflow: hidden;
  }

  .hb-main {
    align-self: stretch;
    overflow-x: hidden;
    overflow-y: auto;
  }

  .hb-main > section,
  .hb-main article,
  .hb-main header,
  .hb-main footer,
  .hb-main table {
    min-width: 0;
    max-width: 100%;
  }

  .hb-main h1,
  .hb-main h2,
  .hb-main h3,
  .hb-main p,
  .hb-main dt,
  .hb-main dd,
  .hb-main li,
  .hb-main button {
    max-width: 100%;
    overflow-wrap: break-word;
  }

  .hb-hunt-card > button,
  .hb-ledger-button,
  .hb-season-tabs button,
  .hb-prepare-foundation-option,
  .hb-featured__footer button {
    min-height: 44px;
  }

  .hb-featured {
    overflow: visible;
    padding-bottom: 12px;
  }

  .hb-featured__heading h2 {
    white-space: normal;
  }

  .hb-featured__footer {
    position: relative;
    left: auto;
    right: auto;
    bottom: auto;
    grid-template-columns: minmax(0, 1fr);
    gap: 8px;
    margin-top: 12px;
  }

  .hb-pity {
    min-height: 34px;
    flex-wrap: wrap;
    gap: 4px 10px;
    padding: 5px 6px;
    white-space: normal;
  }

  .hb-season-leaderboard table,
  .hb-full-leaderboard table {
    width: 100%;
    max-width: 100%;
    table-layout: fixed;
  }

  .hb-season-leaderboard th,
  .hb-season-leaderboard td,
  .hb-full-leaderboard th,
  .hb-full-leaderboard td {
    min-width: 0;
    overflow-wrap: anywhere;
  }
}

@media (max-width: 980px) and (orientation: landscape) {
  .hb-season-dashboard .hb-season-leaderboard,
  .hb-ticket-dashboard .hb-ticket-terms,
  .hb-ticket-dashboard .hb-ticket-next {
    grid-column: 1 / -1;
  }
}

@media (max-width: 720px) and (orientation: landscape) {
  .hb-featured {
    overflow: visible;
    padding-bottom: 10px;
  }

  .hb-featured__heading h2 {
    white-space: normal;
  }

  .hb-featured__footer {
    position: relative;
    left: auto;
    right: auto;
    bottom: auto;
    grid-template-columns: minmax(0, 1fr);
    gap: 6px;
    margin-top: 10px;
  }

  .hb-pity {
    min-height: 34px;
    flex-wrap: wrap;
    gap: 4px 10px;
    padding: 4px 6px;
    white-space: normal;
  }

  .hb-featured__footer button {
    width: 100%;
    min-height: 44px;
  }
}

/* Mobile shell correction V2: resources stay on one line and navigation owns
   the left rail at every phone orientation. */
@media (max-width: 980px), (pointer: coarse) {
  .hb-app {
    grid-template-rows: auto minmax(0, 1fr);
  }

  .hb-topbar {
    min-height: 40px;
    display: block;
    padding: 6px 5px 4px;
  }

  .hb-topbar::after,
  .hb-brand-lockup {
    display: none;
  }

  .hb-resources {
    width: 100%;
    min-width: 0;
    display: grid;
    grid-template-columns: repeat(6, minmax(0, 1fr)) 32px;
    gap: 3px;
    align-items: center;
  }

  .hb-resource,
  .hb-resource--ticket {
    --hb-resource-slot: 16px;
    min-width: 0;
    min-height: 30px;
    display: grid;
    grid-template-columns: 16px minmax(0, 1fr);
    column-gap: 2px;
    justify-content: stretch;
    padding: 2px 3px;
    border: 1px solid rgba(216, 152, 32, .46);
    background: rgba(0, 0, 0, .22);
    font-size: 9px;
    letter-spacing: 0;
    white-space: nowrap;
  }

  .hb-resource__icon,
  .hb-resource--ticket .hb-resource__icon,
  .hb-resource--limited .hb-resource__icon {
    width: 16px;
    height: 16px;
  }

  .hb-resource > span {
    min-width: 0;
    overflow: visible;
    text-overflow: clip;
    white-space: nowrap;
  }

  .hb-add {
    grid-column: 7;
    grid-row: 1;
    width: 32px;
    min-width: 32px;
    height: 30px;
    min-height: 30px;
  }

  .hb-shell-body {
    min-height: 0;
    height: 100%;
    display: grid;
    grid-template-columns: clamp(110px, 30vw, 126px) minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr);
  }

  .hb-sidebar {
    grid-column: 1;
    grid-row: 1;
    min-width: 0;
    min-height: 0;
    display: grid;
    grid-template-columns: 1fr;
    grid-template-rows: repeat(8, minmax(0, 1fr));
    grid-auto-flow: row;
    grid-auto-rows: auto;
    gap: 3px;
    padding: 0 4px 0 0;
    overflow: hidden;
    border-top: 0;
    border-right: 2px solid var(--hb-gold);
  }

  .hb-nav-item {
    min-width: 0;
    min-height: 0;
    display: grid;
    grid-template-columns: 22px minmax(0, 1fr);
    grid-template-rows: 1fr;
    align-items: center;
    justify-items: start;
    gap: 4px;
    padding: 4px;
    border: 1px solid rgba(216, 152, 32, .55);
    font-size: 10px;
    letter-spacing: .015em;
    line-height: 1.05;
    text-align: left;
  }

  .hb-nav-item span {
    width: 100%;
    min-width: 0;
    max-width: 100%;
    overflow: hidden;
    overflow-wrap: normal;
    word-break: normal;
    white-space: normal;
    text-overflow: clip;
  }

  .hb-nav-item svg {
    width: 22px;
    height: 22px;
  }

  .hb-main {
    grid-column: 2;
    grid-row: 1;
    min-width: 0;
    min-height: 0;
    height: 100%;
  }
}

@media (max-width: 359px) {
  .hb-resources {
    grid-template-columns: repeat(6, minmax(0, 1fr)) 30px;
    gap: 2px;
  }

  .hb-resource,
  .hb-resource--ticket {
    grid-template-columns: 14px minmax(0, 1fr);
    column-gap: 1px;
    padding-inline: 2px;
    font-size: 8px;
  }

  .hb-resource__icon,
  .hb-resource--ticket .hb-resource__icon,
  .hb-resource--limited .hb-resource__icon {
    width: 14px;
    height: 14px;
  }

  .hb-add {
    grid-column: 7;
    width: 30px;
    min-width: 30px;
  }
}
