/* The Games on phones and tablets, plus the feedback every choice gets.
   Loaded last, so it only adjusts what the other stylesheets set up.
   - Result cards: what you chose and what it changed, fights blow by blow.
   - Overlays that always scroll, never trap you, and respect the notch and home bar.
   - At 860px and below: a compact sticky HUD, the arena as four tabs, 44px targets,
     14px body text, and the choice you need within reach of your thumb. */

/* ---------------------------------------------------------------- result cards */
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.result-card { position: relative; }
.result-card.fresh { animation: result-in .9s ease-out; }
@keyframes result-in { from { box-shadow: 0 0 0 2px rgba(220,174,104,.85); } to { box-shadow: 0 0 0 2px rgba(220,174,104,0); } }
.result-head { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; padding-bottom: 8px; margin-bottom: 2px; border-bottom: 1px solid var(--line); }
.result-head .eyebrow { flex-basis: 100%; }
.result-label { font-size: 16px; font-weight: 700; }
.result-log { margin-left: auto; padding: 4px 0; }
.deltas { display: inline-flex; flex-wrap: wrap; gap: 6px; }
.delta { display: inline-flex; align-items: center; gap: 4px; padding: 2px 9px; border-radius: 99px; border: 1px solid; font-size: 13px; font-weight: 700; line-height: 1.5; white-space: nowrap; }
.delta.good { color: var(--green); border-color: rgba(143,193,154,.45); background: rgba(143,193,154,.1); }
.delta.bad { color: #f4a79e; border-color: rgba(216,106,95,.5); background: rgba(216,106,95,.12); }
#result, .pack-result { scroll-margin-top: calc(var(--sticky-h, 0px) + 10px); }
.pack-result { display: none; }
.report-more { display: none; }

/* A fight, blow by blow */
.round-log { display: grid; gap: 8px; padding: 12px; border: 1px solid var(--line-2); border-left-width: 1px; border-radius: 8px; background: var(--bg-2); }
.line-blows { display: block; }
.blows-wrap { display: grid; gap: 6px; }
.blows-title { color: var(--muted); }
.blows { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.blow { display: grid; grid-template-columns: 18px minmax(0, 1fr) auto; gap: 8px; align-items: start; padding: 6px 8px; border-radius: 6px; border-left: 3px solid var(--line-2); background: rgba(255,255,255,.025); font-size: 14px; color: #d3d9d6; }
.blow-icon { display: grid; place-items: center; height: 21px; color: var(--dim); }
.blow-icon .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--dim); }
.blow-src { display: inline-block; margin-right: 6px; font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.blow-dmg { min-width: 32px; text-align: right; font-size: 15px; font-weight: 800; line-height: 1.4; }
.blow-dmg.to-foe { color: var(--gold-2); }
.blow-dmg.to-you, .blow-dmg.to-ally { color: #f4a79e; }
.blow-dmg.miss { color: var(--dim); font-size: 12px; font-weight: 600; text-transform: lowercase; }
.blow-you { border-left-color: var(--gold); } .blow-you .blow-icon, .blow-you .blow-src { color: var(--gold); }
.blow-ally { border-left-color: var(--green); } .blow-ally .blow-icon, .blow-ally .blow-src { color: var(--green); }
.blow-foe { border-left-color: var(--red); } .blow-foe .blow-icon, .blow-foe .blow-src { color: #f19c92; }
.blow-snare, .blow-rescue { border-left-color: var(--blue); } .blow-snare .blow-icon, .blow-snare .blow-src, .blow-rescue .blow-icon, .blow-rescue .blow-src { color: var(--blue); }
.blow-joins { border-left-color: #e0a15f; background: rgba(224,161,95,.08); } .blow-joins .blow-icon, .blow-joins .blow-src { color: #e0a15f; }
.blow-down { border-left-color: #8c1f1a; } .blow-down .blow-icon { color: var(--red); }
.blow-guard .blow-icon, .blow-move .blow-icon { color: var(--muted); }
.blow.missed { background: transparent; }
.blows-sum { font-size: 13px; font-weight: 600; color: var(--muted); }

/* HP bars drain hit by hit: your blows gold, allies green, the enemy's pale red */
.meter.hitbar { position: relative; }
.hitbar .chunk { position: absolute; top: 0; bottom: 0; transform-origin: left center; animation: drain .45s ease-in forwards; }
.chunk-you { background: var(--gold-2); }
.chunk-ally { background: #b6e6c0; }
.chunk-foe { background: #ffd9d2; }
.chunk-rescue, .chunk-snare, .chunk-other { background: #c5e6f0; }
@keyframes drain { to { transform: scaleX(0); opacity: .35; } }
.hp-drop { color: #f4a79e; font-weight: 800; }

/* ---------------------------------------------------------------- overlays, every size */
/* Nothing behind an open overlay scrolls (app.js sets the class). */
html.has-overlay, html.has-overlay body { overflow: hidden; }
/* An overlay always scrolls when it has to, and a tall sheet never centers itself out of reach. */
.overlay { overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; place-items: start center;
  padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left)); }
.overlay > .sheet { margin-block: auto; max-height: calc(100vh - 32px); overscroll-behavior: contain; }
@supports (height: 100dvh) {
  .overlay > .sheet { max-height: calc(100dvh - 32px - env(safe-area-inset-top) - env(safe-area-inset-bottom)); }
  .title-screen { min-height: 100dvh; }
  @media (min-width: 1281px) { .arena { height: calc(100dvh - var(--hud-h)); } }
}
button, a, [data-zone] { touch-action: manipulation; }

/* The nightly broadcast: the faces scroll, the stars stay, and the way on stays at the bottom. */
.overlay.broadcast { display: flex; flex-direction: column; align-items: stretch; padding: 0; overflow-y: auto; overscroll-behavior: contain; }
.overlay.broadcast .sky { position: fixed; }
.overlay.broadcast .broadcast-body { flex: none; min-height: 0; width: 100%; margin: auto auto 0; padding: max(24px, env(safe-area-inset-top)) 16px 12px; }
.broadcast-foot { position: sticky; bottom: 0; z-index: 2; flex: none; margin-bottom: auto; display: grid; justify-items: center; gap: 10px; text-align: center;
  padding: 18px 16px max(16px, env(safe-area-inset-bottom)); background: linear-gradient(rgba(7,12,18,0), rgba(7,12,18,.94) 32%); }
.broadcast-foot .button { min-width: 200px; justify-content: center; }
/* With reduced motion the faces must still appear (their entrance animation is skipped). */
@media (prefers-reduced-motion: reduce) {
  .sky-faces li, .score-card:not(.dead) { opacity: 1 !important; }
  .hitbar .chunk { opacity: .5; }
}

/* Toasts clear the home bar and the arena's tab bar. */
.toast { bottom: max(20px, calc(env(safe-area-inset-bottom) + 12px)); }
.arena-tabs ~ .toast { bottom: calc(76px + env(safe-area-inset-bottom)); }

/* The Arcade's own back pill sits bottom-left on wide screens: keep content clear of it. */
.arcade-link { text-decoration: none; color: var(--text); justify-content: center; }
@media (min-width: 861px) {
  body:has(#arcade-back) .col-map, body:has(#arcade-back) .col-pack { padding-bottom: 52px; }
  body:has(#arcade-back) .setup, body:has(#arcade-back) .capitol, body:has(#arcade-back) .ending { padding-bottom: 64px; }
}

/* Fighters: a face, then name, HP and a draining bar, then the weapon. Compact at every size. */
.fighter, .fighter.foe { grid-template-columns: auto minmax(0, 1fr) auto; grid-template-areas: "face name hp" "face bar bar" "face gear gear"; justify-items: stretch; text-align: left; column-gap: 10px; row-gap: 3px; align-items: center; }
.fighter > .fighter-portrait, .fighter > .beast-art { grid-area: face; width: 56px; height: 67px; }
.fighter > .beast-art { width: 76px; height: 60px; box-shadow: none; }
.fighter > strong { grid-area: name; font-size: 15px; min-width: 0; overflow-wrap: anywhere; }
.fighter > .meter, .fighter > .beast-bodies { grid-area: bar; width: 100%; max-width: none; }
.fighter .meter { max-width: none; }
.fighter > .meter + small, .beast-foe > .beast-bodies + small { grid-area: hp; font-size: 13px; font-weight: 700; color: var(--text); white-space: nowrap; }
.fighter > small:last-child:not(.meter + small) { grid-area: gear; font-size: 13px; }
.duel { grid-template-columns: minmax(0, 1fr) 40px minmax(0, 1fr); }

/* ---------------------------------------------------------------- wide screens */
.arena-tabs, .zone-chips, .zone-go { display: none; }
/* A creature fight has many options: two columns keep them on screen at 1440×900. */
@media (min-width: 1281px) {
  .choices-combat { grid-template-columns: repeat(auto-fill, minmax(205px, 1fr)); gap: 6px; }
  .combat { gap: 10px; }
  .choices-combat .choice { padding: 8px 10px; gap: 8px; }
  .choices-combat .choice-body strong { font-size: 14px; line-height: 1.3; }
  .choices-combat .choice-body small, .choices-combat .choice-body em { font-size: 12px; line-height: 1.35; }
  .combat .round-log { padding: 10px; gap: 6px; }
  .combat .blow { padding: 4px 8px; }
  .combat .intent { padding: 10px 12px; }
  .beast-traits { gap: 4px; }
  .beast-traits li { padding: 2px 7px; font-size: 10px; }
}

/* ---------------------------------------------------------------- phones and tablets */
@media (max-width: 860px) {
  :root { --sticky-h: 56px; }
  body { padding-left: env(safe-area-inset-left); padding-right: env(safe-area-inset-right); }
  /* On phones the game offers its own way back to the Arcade (title screen and menu). */
  html body #arcade-back { display: none !important; }

  /* Readable text and thumb-sized targets */
  .small, .muted.small, .hint, .choice-body small, .card small, .pile small, .item small, .ally small, .person-body small,
  .exit-grid small, .pick-grid small, .background-grid small, .difficulty-grid small, .stat-row small,
  .zone-card p, .whisper-replies small, .plan-facts dd, .ms, .beast-lore, .sky-note { font-size: 14px; }
  .line, .alert { font-size: 14.5px; }
  .report { gap: 4px; }
  .choice-body strong, .card strong { font-size: 16px; }
  .icon-button { min-width: 44px; min-height: 44px; justify-content: center; }
  .segmented button, .segmented.small button { min-height: 44px; }
  .text-button { min-height: 44px; }
  .stepper button { width: 44px; height: 44px; }
  .item-actions button, .person-actions button, .hint-card button, .gifts button, .whisper-replies button, .ally-gear button { min-height: 44px; font-size: 14px; padding: 6px 12px; }
  .choice { min-height: 60px; }
  .tabs button { min-height: 44px; }
  .button { min-height: 48px; }

  /* Sticky action bars keep the next step at the bottom of the screen. */
  .sticky-actions { position: sticky; bottom: 0; z-index: 4; margin-top: 4px; padding: 16px 0 max(10px, env(safe-area-inset-bottom)); background: linear-gradient(rgba(12,21,24,0), var(--bg) 38%); }
  .plan-commit { padding-bottom: max(10px, env(safe-area-inset-bottom)); }

  /* Title and top bars */
  .title-screen { padding: 28px 20px max(28px, env(safe-area-inset-bottom)); }
  .topbar { flex-wrap: nowrap; gap: 8px; min-height: 56px; padding: 6px 12px; }
  .topbar .brand small, .topbar-note { display: none; }
  .topbar .brand strong { font-size: 15px; }
  .stages { order: 0; flex: 1 1 auto; flex-basis: auto; min-width: 0; flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; padding: 2px 0; }
  .stages::-webkit-scrollbar { display: none; }
  .stages li { flex: none; white-space: nowrap; font-size: 13px; }
  .capitol .stage h1, .setup h1 { font-size: 34px; }
  .setup { grid-template-columns: minmax(0, 1fr); }
  .district-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .district-grid button { min-height: 56px; min-width: 0; }
  .district-grid button small { font-size: 12px; }
  .field .row input { min-width: 0; }
  .capitol { padding-top: 16px; gap: 20px; }
  .capitol-main { gap: 14px; }

  /* The HUD: identity, day and menus scroll away; health, energy, visibility and crowd stay pinned. */
  .hud { --row1: 44px; display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; height: auto;
    padding: 6px 12px 8px; top: calc(-1 * (var(--row1) + 12px)); z-index: 6; }
  .hud::after { content: ''; order: 4; flex-basis: 100%; height: 0; }
  .hud-id { order: 0; min-height: var(--row1); }
  .hud-portrait { width: 32px; height: 38px; }
  .hud-id strong { font-size: 14px; max-width: 110px; overflow: hidden; text-overflow: ellipsis; }
  .hud-time { order: 1; flex: 1 1 auto; text-align: left; }
  .hud-alive { order: 2; }
  .hud-time strong, .hud-alive strong { font-size: 16px; }
  .hud-time span, .hud-alive span { font-size: 11px; }
  .hud-nav { order: 3; gap: 4px; }
  .hud-nav .icon-button { padding: 0; }
  .hud-nav .icon-button span { display: none; }
  .hud-stats { order: 5; flex: 1 1 0; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; min-width: 0; }
  .hud-stat { grid-template-columns: auto minmax(0, 1fr); column-gap: 6px; row-gap: 4px; min-width: 0; }
  .hud-label { grid-column: 1; font-size: 11px; gap: 4px; }
  .hud-stat b { grid-column: 2; grid-row: 1; font-size: 16px; line-height: 1; justify-self: start; }
  .hud-stat .meter, .hud-stat .pips { grid-column: 1 / -1; grid-row: 2; width: 100%; }
  .hud-stat .meter { height: 6px; }
  .pips { gap: 2px; }
  .pips i { flex: 1; width: auto; height: 6px; }
  .hud-stat.crowd b { font-size: 18px; }
  .hud-plan { order: 6; display: flex; align-items: center; gap: 6px; min-height: 40px; padding: 4px 10px; }

  /* The arena as tabs: Act, Map, Pack, Allies */
  .arena { padding-bottom: calc(64px + env(safe-area-inset-bottom)); }
  .arena > section, .arena > aside { padding: 14px 16px; }
  .arena-tabs { display: grid; grid-template-columns: repeat(4, 1fr); position: fixed; left: 0; right: 0; bottom: 0; z-index: 15;
    padding: 0 env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
    background: #111d21; border-top: 1px solid var(--line-2); box-shadow: 0 -8px 24px rgba(0,0,0,.35); }
  .arena-tabs button { position: relative; min-height: 58px; display: grid; justify-items: center; align-content: center; gap: 2px; padding: 6px 0;
    background: none; border: 0; color: var(--muted); font-size: 12px; font-weight: 700; letter-spacing: .03em; }
  .arena-tabs button[aria-selected="true"] { color: var(--gold-2); box-shadow: inset 0 3px 0 var(--gold); background: rgba(220,174,104,.06); }
  .tab-badge { position: absolute; top: 5px; left: calc(50% + 7px); min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; display: grid; place-items: center;
    font: 800 11px/1 var(--sans); color: #0c1518; background: var(--blue); }
  .tab-badge.quiet { background: var(--line-2); color: var(--text); }
  .tab-badge.alert { background: var(--red); color: #fff; }
  .arena.tab-act .col-map, .arena.tab-act .col-pack { display: none; }
  .arena.tab-map .col-console { display: none; }
  .arena.tab-map .col-map { border-top: 0; }
  .arena.tab-map .col-pack { border-top: 0; padding-top: 0; }
  .arena.tab-map .col-pack > :not(.rival-panel):not(.plan-panel) { display: none; }
  .arena.tab-pack .col-console, .arena.tab-pack .col-map, .arena.tab-allies .col-console, .arena.tab-allies .col-map { display: none; }
  .arena.tab-pack .col-pack > :not(.pack-result):not(.panel-pack):not(.panel-gifts) { display: none; }
  .arena.tab-allies .col-pack > :not(.panel-allies) { display: none; }
  .arena.tab-pack .col-pack, .arena.tab-allies .col-pack { border-top: 0; background: transparent; }
  .pack-result { display: grid; }
  .map-wrap { max-width: min(100%, 520px); }
  .zone-go { display: flex; justify-content: center; width: 100%; }

  /* Moving without the map */
  .zone-chips { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; margin: 0 -16px; padding: 2px 16px 4px; }
  .zone-chips::-webkit-scrollbar { display: none; }
  .zone-chip { flex: none; min-height: 44px; padding: 0 14px; border-radius: 99px; border: 1px solid var(--line-2); background: var(--panel); color: var(--text); font-size: 14px; font-weight: 600; white-space: nowrap; }
  .zone-chip[aria-pressed="true"] { border-color: var(--gold); background: #2a2c24; color: var(--gold-2); }
  .zone-chip.danger { border-color: #7a3a35; }
  .zone-chip em { font-style: normal; font-size: 12px; color: #f19c92; }

  /* The decision */
  .decision-head h2, .combat .decision-head h2, .event h2 { font-size: 24px; }
  .decision-head { flex-wrap: wrap; }
  .combat .decision-head { flex-wrap: nowrap; align-items: center; }
  .result-card { padding: 12px; }
  .report .folded { display: none; }
  .report-more { display: inline-flex; justify-self: start; color: var(--gold-2); padding-left: 0; }
  .map-hint { display: none; }

  /* Fights */
  .combat, .event { padding: 12px; }
  .intent p { font-size: 15px; }
  .whisper-replies { grid-template-columns: 1fr; }

  /* Sheets become bottom sheets with a pinned header */
  .overlay:not(.broadcast) { padding: max(10px, env(safe-area-inset-top)) 0 0; place-items: stretch; }
  .overlay > .sheet { --pad: 16px; width: 100%; max-width: none; margin: auto 0 0; padding: var(--pad) var(--pad) max(var(--pad), env(safe-area-inset-bottom));
    border-radius: 14px 14px 0 0; border-bottom: 0; max-height: calc(100vh - 10px); }
  @supports (height: 100dvh) { .overlay > .sheet { max-height: calc(100dvh - max(10px, env(safe-area-inset-top))); } }
  .sheet > .sheet-head { position: sticky; top: calc(-1 * var(--pad)); z-index: 3; margin: calc(-1 * var(--pad)) calc(-1 * var(--pad)) 0; padding: 10px var(--pad) 8px; background: var(--bg-2); border-bottom: 1px solid var(--line); }
  .sheet-head h2 { font-size: 22px; }
  .menu-actions .button { justify-content: center; }

  /* Ending */
  .ending { padding: 32px 16px max(40px, env(safe-area-inset-bottom)); }
  .share-actions .button, .ending .row.center .button { flex: 1 1 150px; justify-content: center; }
}

/* ---------------------------------------------------------------- small phones */
@media (max-width: 480px) {
  .hud { column-gap: 8px; padding-left: 10px; padding-right: 10px; }
  .hud-id > span:last-child { display: none; }
  .hud-label { font-size: 0; }
  .hud-label .icon { width: 15px; height: 15px; }
  .hud-plan .hud-label { font-size: 0; }
  .topbar .brand strong { display: none; }
  .title-actions { display: grid; }
  .district-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .title-actions .button { justify-content: center; }
  .card-grid, .people-grid, .plan-grid, .replan-grid { grid-template-columns: minmax(0, 1fr); }
  .card { padding: 12px 14px; }
  .arena > section, .arena > aside { padding: 12px; }
  .zone-chips { margin: 0 -12px; padding: 2px 12px 4px; }

  /* A fight fits a phone: you and your opponent stacked, each one line and a bar. */
  .duel, .beast-duel { grid-template-columns: minmax(0, 1fr); gap: 8px; }
  .duel-gap { display: none; }
  .fighter > .fighter-portrait { width: 48px; height: 58px; }
  .fighter > .beast-art { width: 56px; height: 46px; }
  .combat .decision-head .range { font-size: 11px; padding: 4px 8px; }
  .beast-traits { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; margin: 0 -12px; padding: 0 12px; }
  .beast-traits li { font-size: 11px; flex: none; white-space: nowrap; }

  /* The broadcast: three small faces a row */
  .broadcast-body { gap: 8px; }
  .broadcast-seal { font-size: 30px; }
  .broadcast-body h2 { font-size: 32px; }
  .sky-faces, .sky-faces.many { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px 8px; width: 100%; margin: 4px 0; }
  .sky-faces li, .sky-faces.many li { max-width: none; min-width: 0; gap: 2px; }
  .sky-portrait, .sky-faces.many .sky-portrait { width: 64px; height: 76px; }
  .sky-faces strong { font-size: 13px; line-height: 1.2; overflow-wrap: anywhere; }
  .sky-faces small { font-size: 12px; }
  .sky-cause { font-size: 12px; max-width: none; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
  .sky-note { font-size: 12px; max-width: none; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
  .broadcast-count { font-size: 12px; }
}
@media (max-width: 340px) {
  .sky-faces, .sky-faces.many { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* Keep setup controls and secondary action details comfortable on narrow screens. */
@media (max-width: 860px) {
  .stepper { flex-shrink: 0; gap: 5px; }
  .stat-row { padding: 8px; gap: 8px; }
  .bonus { white-space: normal; }
  .choice-stats { flex-direction: column; gap: 4px; }
  .arena .col-pack { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 380px) {
  .roster-head { gap: 10px; }
  .roster-portrait { width: 90px; height: 108px; }
  .roster-head h3 { font-size: 24px; }
  .setup-actions { flex-wrap: wrap; }
}
@media (hover: none) {
  .choice:hover:not(:disabled) { transform: none; }
}
/* Let short landscape screens scroll past the HUD and reclaim space for decisions. */
@media (max-width: 860px) and (max-height: 500px) {
  .hud { position: static; }
  .arena-tabs button { display: flex; justify-content: center; min-height: 44px; gap: 8px; }
}
