/* ==========================================================================
   Mobile layout (portrait phones). Everything here is scoped to html.mobile-ui, which client/ui/layout.js
   sets for portrait viewports ≤ 700px wide (or ?layout=mobile). Touch-only tweaks use (hover: none).
   Secondary screens (multiplayer, lobby, game over, modals) keep their mobile rules next to their
   desktop rules in menu.css / modals.css.
   The HUD regroups into .m-top and .m-bottom (see Hud.applyLayout); their extents are published as
   --hud-top / --hud-bottom (px from the top / bottom edge) for everything floating in between.
   ========================================================================== */

/* 1rem ≈ 12px on a 393px-wide phone; scales with the width, not the (URL-bar dependent) height. */
html.mobile-ui { font-size: clamp(10px, calc(3.05vw * var(--ui-scale)), 16px); --hud-top: 9rem; --hud-bottom: 22rem; }

/* ---------- Touch devices: no hover, no keyboard ------------------------- */
body { -webkit-touch-callout: none; -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
#view-root canvas { touch-action: none; }
@media (hover: none) {
  .kbd, .menu-footer-keys { display: none !important; }
  /* :hover sticks after a tap on touch screens — no lifted cards or nudged rows */
  .shop-card:hover, .aug-card:hover, .trait-row:hover, .btn:hover, .shop-btn:hover, .hud-icon-btn:hover, .item-slot:hover { transform: none; }
  .shop-card:hover .card-portrait { transform: none; }
}

/* Phones held sideways: this game is laid out for portrait. */
@media (orientation: landscape) and (max-height: 500px) and (hover: none) {
  body::before, body::after { position: fixed; left: 0; right: 0; z-index: 200; text-align: center; color: var(--gold-hi); }
  body::before {
    content: '↻';
    top: 0;
    bottom: 0;
    padding-top: calc(50vh - 4.6rem);
    background: radial-gradient(ellipse at 50% 45%, #1b1644, #05070f 70%);
    font: 3.2rem/1 system-ui, sans-serif;
  }
  body::after { content: 'Rotate your phone to portrait to play'; top: calc(50vh + 0.4rem); font: 700 1.1rem var(--font-display); letter-spacing: 0.08em; }
}

/* ---------- Main menu: title + choices on top, spotlight teaser at the bottom ---------- */
html.mobile-ui .screen-menu { flex-direction: column; overflow-x: hidden; overflow-y: auto; }
html.mobile-ui .menu-vignette {
  background: linear-gradient(180deg, rgba(4, 5, 14, 0.9) 0%, rgba(4, 5, 14, 0.78) 40%, rgba(4, 5, 14, 0.15) 60%, rgba(4, 5, 14, 0.1) 72%, rgba(4, 5, 14, 0.85) 100%);
}
html.mobile-ui .menu-art { width: 100%; height: 62%; -webkit-mask-image: linear-gradient(180deg, #000 45%, transparent); mask-image: linear-gradient(180deg, #000 45%, transparent); }
html.mobile-ui .menu-art .art-img { object-position: 30% 20%; }
html.mobile-ui .menu-left {
  flex: none;
  width: 100%;
  max-width: 30rem;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 1.4rem) 1.2rem 0.6rem;
  gap: 1rem;
  justify-content: flex-start;
}
html.mobile-ui .menu-lang { position: fixed; top: calc(env(safe-area-inset-top) + 0.6rem); right: 0.8rem; }
html.mobile-ui .menu-home { position: fixed; top: calc(env(safe-area-inset-top) + 0.6rem); left: 0.8rem; padding: 0.45rem 0.7rem; }
html.mobile-ui .menu-left .logo { margin-bottom: 0; }
html.mobile-ui .menu-left .prism-emblem { width: 4.4rem; height: 4.4rem; }
html.mobile-ui .menu-left .logo-word { font-size: 3.3rem; }
html.mobile-ui .menu-left .logo-sub { font-size: 1rem; gap: 0.6rem; }
html.mobile-ui .menu-left .logo-line { width: 2.4rem; }
html.mobile-ui .menu-left .logo-tagline { margin-top: 0.55rem; font-size: 0.74rem; letter-spacing: 0.14em; }
html.mobile-ui .menu-btn.btn-lg { --btn-h: 3.9rem; }
html.mobile-ui .menu-fast { align-self: center; text-shadow: 0 1px 3px #000, 0 0 0.6rem #000; }
html.mobile-ui .spotlight {
  position: relative;
  right: auto;
  bottom: auto;
  flex: none;
  width: auto;
  max-width: 30rem;
  margin: auto 1rem 0.4rem;
  align-self: stretch;
}
@media (min-width: 32rem) { html.mobile-ui .spotlight { align-self: center; width: 28rem; } }
html.mobile-ui .spot-portrait { width: 4.6rem; height: 4.6rem; }
html.mobile-ui .spot-lore { margin-top: 0.5rem; font-size: 0.74rem; }
html.mobile-ui .menu-footer {
  position: relative;
  left: auto;
  right: auto;
  bottom: auto;
  flex: none;
  justify-content: center;
  padding: 0.2rem 1rem calc(env(safe-area-inset-bottom) + 0.5rem);
  font-size: 0.66rem;
}

/* ---------- HUD stacks ---------------------------------------------------- */
html.mobile-ui .m-top,
html.mobile-ui .m-bottom {
  position: absolute;
  left: 0.4rem;
  right: 0.4rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  pointer-events: none !important;
}
html.mobile-ui .m-top { top: calc(env(safe-area-inset-top) + 0.4rem); }
html.mobile-ui .m-bottom { bottom: calc(env(safe-area-inset-bottom) + 0.35rem); }
html.mobile-ui .m-top-row { display: flex; align-items: flex-start; gap: 0.35rem; }
html.mobile-ui .m-top-row > *, html.mobile-ui .m-top > *, html.mobile-ui .m-bottom > * { pointer-events: auto; }
html.mobile-ui #ui-root.is-dragging .m-top *, html.mobile-ui #ui-root.is-dragging .m-bottom * { pointer-events: none !important; }

/* Menu button (How to Play lives in the game menu on phones) */
html.mobile-ui .hud-menu { position: static; flex: none; flex-direction: column; }
html.mobile-ui .hud-howto { display: none; }
html.mobile-ui .hud-icon-btn { width: 2.9rem; height: 2.9rem; font-size: 1.15rem; }

/* Round tracker: fills the row between the menu button and the player-list toggle */
html.mobile-ui .round-tracker { top: auto; left: auto; translate: none; flex: 1; min-width: 0; padding: 0.35rem 0.55rem 0.45rem; }
html.mobile-ui .rt-top { gap: 0.5rem; }
html.mobile-ui .rt-stage { padding-right: 0.5rem; }
html.mobile-ui .rt-stage-label { font-size: 0.5rem; }
html.mobile-ui .rt-stage-num { font-size: 1.2rem; }
html.mobile-ui .rt-pips { gap: 0.32rem; justify-content: flex-start; }
html.mobile-ui .rt-pip { width: 1.4rem; height: 1.4rem; font-size: 0.7rem; }
html.mobile-ui .rt-mid { margin-top: 0.3rem; gap: 0.35rem; }
html.mobile-ui .rt-round { font-size: 0.85rem; }
html.mobile-ui .rt-phase { font-size: 0.66rem; letter-spacing: 0.12em; }
html.mobile-ui .rt-sec { font-size: 1rem; }
html.mobile-ui .rt-ready { margin-left: 0.25rem; min-height: 1.9rem; padding: 0 0.6rem; font-size: 0.66rem; }
html.mobile-ui .rt-bar { margin-top: 0.35rem; }

/* Player list: collapsed behind a toggle, opens as a drop-down over the board */
.pl-toggle { display: none; }
html.mobile-ui .pl-toggle { display: flex; flex: none; width: auto; min-width: 2.9rem; padding: 0 0.5rem; gap: 0.25rem; }
html.mobile-ui .pl-toggle.on { border-color: var(--gold); box-shadow: 0 0 0.9rem rgba(232, 193, 112, 0.35); }
.pl-toggle-rank { font-family: var(--font-num); font-weight: 900; font-size: 0.9rem; color: var(--text); }
.pl-toggle-caret { font-size: 0.65rem; color: var(--text-3); transition: transform 0.2s; }
.pl-toggle.on .pl-toggle-caret { transform: rotate(180deg); }
html.mobile-ui .player-list {
  display: none;
  top: calc(env(safe-area-inset-top) + 3.7rem);
  right: 0.4rem;
  width: min(17rem, calc(100% - 0.8rem));
  max-height: calc(100% - var(--hud-bottom) - env(safe-area-inset-top) - 4.4rem);
  padding: 0.4rem;
  overflow-y: auto;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: rgba(8, 10, 26, 0.94);
  box-shadow: var(--shadow);
  z-index: 3;
  animation: dropIn 0.2s var(--ease-out);
}
html.mobile-ui .player-list.open { display: block; }
html.mobile-ui .pl-row { height: 3rem; }

/* Boons + traits: one horizontally scrolling strip under the top row */
html.mobile-ui .trait-tracker {
  top: auto;
  left: auto;
  width: auto;
  max-height: none;
  flex-direction: row;
  align-items: center;
  gap: 0.35rem;
  overflow: visible;
}
html.mobile-ui .trait-tracker .panel-kicker { display: none; }
html.mobile-ui .boon-strip { margin-left: 0; gap: 0.2rem; flex: none; }
html.mobile-ui .trait-tracker .hud-pause { flex: none; height: 2.3rem; }
html.mobile-ui .boon-strip:empty { display: none; }
html.mobile-ui .boon { width: 1.9rem; height: 2.1rem; font-size: 0.85rem; }
html.mobile-ui .traits-list {
  flex: 1;
  min-width: 0;
  flex-direction: row;
  gap: 0.3rem;
  padding: 0.1rem 1.2rem 0.1rem 0.05rem;
  overflow-x: auto;
  overflow-y: hidden;
  touch-action: pan-x;
  -webkit-mask-image: linear-gradient(90deg, #000 calc(100% - 1.4rem), transparent);
  mask-image: linear-gradient(90deg, #000 calc(100% - 1.4rem), transparent);
}
html.mobile-ui .trait-row { flex: none; gap: 0.3rem; padding: 0.15rem 0.5rem 0.15rem 0.2rem; }
html.mobile-ui .trait-row .tbadge { width: 1.55rem; height: 1.75rem; }
html.mobile-ui .trait-row .tbadge-ico { font-size: 0.75rem; }
html.mobile-ui .trait-count { min-width: 0.8rem; font-size: 0.9rem; }
html.mobile-ui .trait-row.inactive .trait-count { font-size: 0.8rem; }
html.mobile-ui .trait-name { font-size: 0.7rem; }
html.mobile-ui .trait-bps { font-size: 0.58rem; }
html.mobile-ui .traits-empty { padding: 0.3rem 0.6rem; font-size: 0.68rem; }

/* Items: one row of orbs above the shop */
html.mobile-ui .item-bench { left: auto; bottom: auto; }
html.mobile-ui .item-bench .panel-kicker { display: none; }
html.mobile-ui .item-bench.empty { opacity: 0.8; }
html.mobile-ui .item-grid { grid-template-columns: repeat(10, minmax(0, 1fr)); gap: 0.2rem; padding: 0.22rem 0.3rem; }
html.mobile-ui .item-slot { width: 100%; height: auto; aspect-ratio: 1; max-width: 2.6rem; justify-self: center; }
html.mobile-ui .item-slot .item-orb { width: 90%; height: 90%; }
html.mobile-ui .item-slot .item-orb-ico { font-size: 1rem; }
html.mobile-ui .item-bench { display: flex; align-items: stretch; gap: 0.3rem; }
html.mobile-ui .item-grid { flex: 1; min-width: 0; }
html.mobile-ui .ib-team {
  display: flex;
  flex: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.05rem;
  width: 2.9rem;
  border-radius: 0.6rem;
  border: 1px solid var(--line);
  background: rgba(8, 10, 26, 0.65);
  color: var(--gold-hi);
  font-size: 1rem;
}
html.mobile-ui .ib-team.on { border-color: var(--gold); background: rgba(40, 32, 12, 0.85); box-shadow: 0 0 0.9rem rgba(232, 193, 112, 0.35); }
html.mobile-ui .ib-team-label { font-size: 0.5rem; font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase; color: var(--text-2); }

/* Item sheet: covers the (hidden, still laid out) shop at its height — the board keeps its framing, and the shop
   doesn't replay its entrance animations when it comes back */
html.mobile-ui .m-bottom.sheet-open .shop-panel { visibility: hidden; }
html.mobile-ui .item-combos {
  position: absolute;
  left: 0 !important;
  right: 0;
  top: auto !important;
  bottom: 0;
  display: flex;
  flex-direction: column;
  width: auto;
  height: var(--sheet-h, 17rem);
  max-height: none;
  overflow: hidden;
  padding: 0.5rem 0.5rem 0.4rem;
  animation: riseIn 0.2s var(--ease-out);
}
html.mobile-ui .ic-body { flex: 1; min-height: 0; margin-top: 0.4rem; overflow-y: auto; overscroll-behavior: contain; touch-action: pan-y; scrollbar-width: none; }
html.mobile-ui .ic-close { width: 2.3rem; height: 2.3rem; font-size: 0.9rem; }
html.mobile-ui .ic-name { font-size: 1rem; }
html.mobile-ui .ic-kind, html.mobile-ui .ic-good { font-size: 0.72rem; }
html.mobile-ui .ic-section { margin-top: 0.45rem; }
html.mobile-ui .ic-body > .ic-section:first-child { margin-top: 0; }
html.mobile-ui .ic-champ, html.mobile-ui .ic-itemrow, html.mobile-ui .ic-teamrow { min-height: 3.4rem; margin-bottom: 0.25rem; }
html.mobile-ui .ic-portrait { width: 2.4rem; height: 2.4rem; }
html.mobile-ui .ic-portrait.lg { width: 2.9rem; height: 2.9rem; }
html.mobile-ui .ic-unit-name { font-size: 0.86rem; }
html.mobile-ui .ic-stars { font-size: 0.66rem; }
html.mobile-ui .ic-why { font-size: 0.72rem; }
html.mobile-ui .ic-rank { font-size: 0.9rem; }
html.mobile-ui .ic-tier { font-size: 0.66rem; }
html.mobile-ui .ic-slots .item-orb.xs, html.mobile-ui .ic-slot.xs { width: 1.2rem; height: 1.2rem; }
html.mobile-ui .ic-load-name { font-size: 0.66rem; }
html.mobile-ui .ic-hint { margin-top: 0.3rem; font-size: 0.66rem; }

/* Shop: player bar, then 5 cards in a 3 + 2 grid with Buy XP / Reroll / Lock in the sixth cell */
html.mobile-ui .shop-panel { left: auto; bottom: auto; translate: none; width: auto; padding: 0.3rem 0.4rem 0.4rem; }
html.mobile-ui .shop-top { padding: 0 0.1rem 0.3rem; }
html.mobile-ui .player-bar { grid-template-columns: auto 1fr auto; gap: 0.4rem; height: auto; min-height: 2.3rem; }
html.mobile-ui .pb-left { flex-direction: column; align-items: flex-start; gap: 0.12rem; }
html.mobile-ui .pb-level { gap: 0.35rem; }
html.mobile-ui .pb-level-badge { padding: 0.08rem 0.4rem; }
html.mobile-ui .pb-level-num { font-size: 1rem; }
html.mobile-ui .pb-xp-bar { width: 3.8rem; height: 0.42rem; }
html.mobile-ui .pb-xp-text { font-size: 0.66rem; }
html.mobile-ui .pb-odds { gap: 0.28rem; font-size: 0.56rem; }
html.mobile-ui .pb-gold { gap: 0.3rem; padding: 0.08rem 0.55rem 0.08rem 0.3rem; }
html.mobile-ui .pb-coin { font-size: 1.2rem; }
html.mobile-ui .pb-gold-num { font-size: 1.2rem; min-width: 1.3rem; }
html.mobile-ui .pb-pip { width: 0.34rem; height: 0.34rem; }
html.mobile-ui .pb-right { gap: 0.25rem; }
html.mobile-ui .pb-hp, html.mobile-ui .pb-board, html.mobile-ui .pb-streak { gap: 0.2rem; padding: 0.12rem 0.35rem; font-size: 0.76rem; }
html.mobile-ui .shop-body { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); grid-template-rows: repeat(2, 6.8rem); gap: 0.35rem; }
html.mobile-ui .shop-cards { display: contents; }
html.mobile-ui .shop-slot { height: auto; min-width: 0; }
html.mobile-ui .shop-actions { grid-area: 2 / 3; width: auto; gap: 0.35rem; }
html.mobile-ui .shop-actions .reroll { margin-right: 2.95rem; }
html.mobile-ui .shop-lock { grid-area: 2 / 3; align-self: end; justify-self: end; width: 2.6rem; height: calc((100% - 0.35rem) / 2); }
html.mobile-ui .shop-btn { gap: 0.4rem; padding: 0 0.45rem; }
html.mobile-ui .shop-btn-ico { width: 1.8rem; height: 1.8rem; font-size: 0.95rem; }
html.mobile-ui .shop-btn-label { font-size: 0.74rem; }
html.mobile-ui .card-traits { left: 0.25rem; top: 0.25rem; }
html.mobile-ui .card-trait { width: 1.4rem; height: 1.4rem; }
html.mobile-ui .card-trait-ico { font-size: 0.85rem; }
html.mobile-ui .card-bottom { padding: 0.25rem 0.35rem 0.28rem; }
html.mobile-ui .card-name { font-size: 0.7rem; }
html.mobile-ui .card-cost { font-size: 0.8rem; }
html.mobile-ui .sell-coin { font-size: 2.4rem; }
html.mobile-ui .sell-label { font-size: 1.3rem; }
html.mobile-ui .sell-value { font-size: 1.9rem; }

/* ---------- Floating pills, banners, toasts (between the stacks) -------------- */
html.mobile-ui .matchup,
html.mobile-ui .scout-bar,
html.mobile-ui .aug-pill { top: calc(var(--hud-top) + 0.45rem); max-width: calc(100% - 0.8rem); }
html.mobile-ui .layer-hud.with-matchup .scout-bar,
html.mobile-ui .layer-hud.with-matchup .aug-pill { top: calc(var(--hud-top) + 3rem); }
html.mobile-ui .scout-bar { gap: 0.45rem; padding: 0.3rem 0.35rem 0.3rem 0.7rem; }
html.mobile-ui .scout-text { font-size: 0.78rem; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
html.mobile-ui .scout-return { padding: 0.35rem 0.7rem; }
html.mobile-ui .mu-name { max-width: 8.5rem; }
html.mobile-ui .spectate-note { bottom: calc(var(--hud-bottom) + 0.5rem); }
html.mobile-ui .ingame-chat { left: 0.5rem; bottom: calc(var(--hud-bottom) + 0.4rem); width: min(18rem, 70%); }
html.mobile-ui .scoreboard { display: none !important; }

html.mobile-ui .banner-wrap { top: calc(var(--hud-top) + 3.5rem); }
html.mobile-ui .banner { gap: 0.6rem; padding: 0.6rem 1.2rem 0.7rem; max-width: 100vw; }
html.mobile-ui .banner-line { width: 1.8rem; }
html.mobile-ui .banner-title { font-size: 1.9rem; }
html.mobile-ui .banner-stage .banner-title { font-size: 2.4rem; }
html.mobile-ui .banner-combat .banner-title { font-size: 2.2rem; }
html.mobile-ui .banner-sub { font-size: 0.82rem; white-space: normal; }
html.mobile-ui .banner-defeat .banner-sub { font-size: 1.1rem; }
html.mobile-ui .banner-flare { width: 16rem; }

html.mobile-ui body[data-screen='game'] .toasts,
html.mobile-ui body[data-screen='gameover'] .toasts {
  top: calc(var(--hud-top) + 0.45rem);
  right: auto;
  left: 50%;
  translate: -50% 0;
  width: min(20rem, calc(100% - 1rem));
}
html.mobile-ui .toasts { right: 0.5rem; width: min(20rem, calc(100% - 1rem)); }

/* ---------- Tooltips ------------------------------------------------------------ */
html.mobile-ui .tip { max-width: min(21rem, calc(100vw - 1rem)); }
html.mobile-ui .unit-tip { width: min(20rem, calc(100vw - 1rem)); }

/* ---------- Boon picker: cards stacked vertically, icon left / text right ---------- */
html.mobile-ui .aug-overlay { align-items: flex-start; overflow-y: auto; }
html.mobile-ui .aug-backdrop { position: fixed; }
html.mobile-ui .aug-content { width: 100%; max-width: 30rem; margin: auto; padding: calc(env(safe-area-inset-top) + 1rem) 0.8rem calc(env(safe-area-inset-bottom) + 1rem); }
html.mobile-ui .aug-title { font-size: 1.8rem; text-align: center; }
html.mobile-ui .aug-sub { margin-bottom: 1rem; font-size: 0.8rem; text-align: center; }
html.mobile-ui .aug-cards { flex-direction: column; width: 100%; gap: 0.7rem; }
html.mobile-ui .aug-card {
  display: grid;
  grid-template-columns: 4.8rem minmax(0, 1fr);
  grid-template-rows: auto auto 1fr auto;
  column-gap: 0.9rem;
  align-items: start;
  width: 100%;
  height: auto;
  padding: 0.85rem 0.9rem 0.8rem;
  text-align: left;
}
@keyframes augInMobile { 0% { opacity: 0; transform: translateX(2rem); } 100% { opacity: 1; transform: none; } }
html.mobile-ui .aug-card { animation-name: augInMobile; }
html.mobile-ui .aug-card-glow { inset: -60% -10%; }
html.mobile-ui .aug-card-tier { grid-column: 2; grid-row: 1; }
html.mobile-ui .aug-card-icon,
html.mobile-ui .aug-card-icon.has-art-src { grid-column: 1; grid-row: 1 / span 4; align-self: center; width: 4.6rem; height: 5.15rem; margin: 0; font-size: 2rem; }
html.mobile-ui .aug-card-name { grid-column: 2; grid-row: 2; margin-top: 0.15rem; font-size: 1.08rem; }
html.mobile-ui .aug-card-desc { grid-column: 2; grid-row: 3; margin-top: 0.3rem; font-size: 0.8rem; line-height: 1.4; }
html.mobile-ui .aug-card-cta { grid-column: 2; grid-row: 4; justify-self: start; margin-top: 0.5rem; padding: 0.3rem 1rem; }
html.mobile-ui .aug-card.chosen { transform: scale(1.03); }
html.mobile-ui .aug-footer { margin-top: 1rem; }

/* Damage meter: toggle in the top row, opens as a drop-down like the player list */
html.mobile-ui .dm-toggle { display: grid; flex: none; }
html.mobile-ui .dm-toggle.hidden { display: none; }
html.mobile-ui .dm-toggle.on { border-color: var(--gold); box-shadow: 0 0 0.9rem rgba(232, 193, 112, 0.35); }
html.mobile-ui .damage-meter {
  display: none;
  top: calc(var(--hud-top, 7rem) + 0.3rem);
  right: 0.4rem;
  width: min(17rem, calc(100% - 0.8rem));
  z-index: 3;
  background: rgba(8, 10, 26, 0.94);
  animation: dropIn 0.2s var(--ease-out);
}
html.mobile-ui .damage-meter.open { display: block; }
html.mobile-ui .damage-meter .dm-head { pointer-events: none; }
html.mobile-ui .damage-meter .dm-caret { display: none; }
html.mobile-ui .damage-meter.collapsed .dm-body { display: block; }
html.mobile-ui .dm-list { max-height: calc(100vh - var(--hud-bottom) - env(safe-area-inset-top) - 9rem); }
html.mobile-ui .dm-row { height: 2rem; }
html.mobile-ui .ready-btn { display: none !important; }
