/* ============ PHONES + TABLETS: touch controls, safe areas, compact layouts ============
   html.touch is set by js/touch.js on touch-first devices. The size queries below apply to
   any small window (phone landscape is ~874×402 CSS px), touch or not. */

:root { --sl: env(safe-area-inset-left, 0px); --sr: env(safe-area-inset-right, 0px);
  --st: env(safe-area-inset-top, 0px); --sb: env(safe-area-inset-bottom, 0px); }

html.touch, html.touch body { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent; touch-action: manipulation; overscroll-behavior: none; }
html.touch #strat-canvas, html.touch #battle-container canvas { touch-action: none; }
html.touch kbd, html.touch #bh-hint, html.touch .tb-zoom { display: none; }

/* ---------- rotate prompt (battles are landscape-only) ---------- */
#rotate-hint { display: none; position: fixed; inset: 0; z-index: 100; background: #0b0e14; color: #f2ead4;
  flex-direction: column; align-items: center; justify-content: center; gap: 10px; text-align: center; padding: 24px; }
#rotate-hint b { font-family: 'Cinzel', serif; font-size: 22px; letter-spacing: .06em; margin-top: 14px; }
#rotate-hint span { font-family: 'Nunito Sans', sans-serif; font-size: 14px; color: #a8a090; }
.rh-phone { width: 44px; height: 76px; border: 3px solid #e8c46a; border-radius: 10px; animation: rhTurn 2.4s ease-in-out infinite; }
@keyframes rhTurn { 0%, 25% { transform: rotate(0); } 55%, 85% { transform: rotate(-90deg); } 100% { transform: rotate(0); } }
@media (orientation: portrait) { html.touch body[data-screen="battle"] #rotate-hint { display: flex; } }

/* ---------- battle: touch controls ---------- */
#touch-ui { position: absolute; inset: 0; touch-action: none; }
#touch-ui.off { display: none; }
#touch-ui.intro > * { display: none; }          /* the bare layer still catches the skip tap */
.tc-btn { position: absolute; display: flex; align-items: center; justify-content: center; width: 56px; height: 56px; padding: 0;
  border-radius: 50%; border: 2px solid rgba(255,255,255,.55); background: rgba(13,20,36,.42); color: #fff;
  -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px); box-shadow: 0 3px 10px rgba(0,0,0,.25);
  touch-action: none; transition: transform .07s, background .07s; }
.tc-btn svg.ic { width: 26px; height: 26px; pointer-events: none; }
.tc-btn > * { pointer-events: none; }
.tc-btn.on { transform: scale(.9); background: rgba(255,255,255,.32); }
.tc-btn.gone { display: none; }
#tc-attack { right: calc(var(--sr) + 22px); bottom: calc(var(--sb) + 22px); width: 96px; height: 96px;
  background: rgba(200,57,43,.5); border: 3px solid rgba(255,255,255,.85); }
#tc-attack span { display: flex; }
#tc-attack svg.ic { width: 42px; height: 42px; }
#tc-attack.on { background: rgba(255,120,90,.6); }
#tc-block { right: calc(var(--sr) + 128px); bottom: calc(var(--sb) + 16px); width: 66px; height: 66px; }
#tc-block svg.ic { width: 30px; height: 30px; }
#tc-jump { right: calc(var(--sr) + 36px); bottom: calc(var(--sb) + 130px); }
#tc-kick { right: calc(var(--sr) + 112px); bottom: calc(var(--sb) + 98px); width: 50px; height: 50px; }
#tc-kick svg.ic { width: 22px; height: 22px; }
#tc-cry { right: calc(var(--sr) + 188px); bottom: calc(var(--sb) + 92px); width: 46px; height: 46px; color: #9fb0cc; }
#tc-cry svg.ic { width: 21px; height: 21px; }
#tc-cry small { position: absolute; bottom: -17px; font-family: 'Lilita One', sans-serif; font-size: 12px; color: #c8d0e0; text-shadow: 0 1px 2px #000; }
#tc-cry.ready { color: #9adf6a; border-color: #9adf6a; animation: cryReady 1.4s infinite; }
@keyframes cryReady { 50% { box-shadow: 0 0 16px rgba(154,223,106,.6); } }
#tc-pause { left: calc(var(--sl) + 12px); top: calc(var(--st) + 10px); width: 44px; height: 44px; border-radius: 12px; }
#tc-pause svg.ic { width: 22px; height: 22px; }

/* floating move stick: a faint ghost until your thumb lands, then it sits under it */
#tc-stick { position: absolute; left: calc(var(--sl) + 120px); top: calc(100% - var(--sb) - 125px); width: 0; height: 0; pointer-events: none; opacity: .4; }
#tc-stick.live { opacity: 1; }
#tc-stick .tc-base { position: absolute; left: -60px; top: -60px; width: 120px; height: 120px; border-radius: 50%;
  border: 2px solid rgba(255,255,255,.4); background: rgba(13,20,36,.25); }
#tc-stick .tc-knob { position: absolute; left: -26px; top: -26px; width: 52px; height: 52px; border-radius: 50%;
  background: rgba(255,255,255,.6); box-shadow: 0 2px 8px rgba(0,0,0,.35); }
#tc-stick.sprint .tc-base { border-color: #ffd35a; box-shadow: 0 0 14px rgba(255,211,90,.45); }

/* tappable HUD pieces; desktop key labels hidden */
html.touch #bh-hotbar { right: auto; left: 50%; transform: translateX(-50%); }
html.touch #bh-hotbar .slot, html.touch #bh-ladder .lad, html.touch #bh-prompt { pointer-events: auto; }
html.touch .slot .k:not(:last-child), html.touch .lad-k, html.touch #vt-cry { display: none; }
html.touch #bh-ladder { bottom: 118px; }
html.touch #bh-prompt { border: 2px solid var(--gold); background: rgba(13,20,36,.82); padding: 8px 18px; border-radius: 999px; }
html.touch #bh-prompt::after { content: ' ›'; color: var(--gold); }
html.touch #bh-glory { left: calc(var(--sl) + 66px); top: calc(var(--st) + 18px); bottom: auto; }
html.touch #bh-gloryfx { left: calc(var(--sl) + 160px); top: calc(var(--st) + 40px); bottom: auto; }

/* ---------- battle HUD: short screens (phone landscape) ---------- */
@media (max-height: 520px) {
  #bh-score { top: calc(var(--st) + 6px); transform: translateX(-50%) scale(.62); transform-origin: top center; }
  #bh-progress { top: calc(var(--st) + 42px); width: 260px; gap: 70px; }
  #bh-flags { top: calc(var(--st) + 52px); transform: translateX(-50%) scale(.7); transform-origin: top center; }
  #bh-objective { top: calc(var(--st) + 86px); font-size: 13px; }
  #bh-mapwrap { top: calc(var(--st) + 8px); right: calc(var(--sr) + 10px); width: 96px; height: 96px; border-radius: 10px; }
  #bh-feed { top: calc(var(--st) + 112px); right: calc(var(--sr) + 10px); transform: scale(.75); transform-origin: top right; }
  #bh-feed .feed-row:nth-child(n+4) { display: none; }
  #bh-vitals { left: calc(var(--sl) + 14px); bottom: calc(var(--sb) + 8px); width: 210px; }
  .vt-name { font-size: 12px; }
  .vt-ability { font-size: 10px; }
  .vt-bar { height: 18px; border-width: 1.5px; }
  #vt-hp-num { font-size: 13px; line-height: 15px; right: 8px; }
  #vt-ammo { font-size: 11px; margin-top: 3px; }
  #bh-glory { left: calc(var(--sl) + 14px); bottom: calc(var(--sb) + 64px); font-size: 16px; }
  #bh-glory svg.ic { width: 18px; height: 18px; }
  #bh-hotbar { bottom: calc(var(--sb) + 8px); gap: 6px; }
  .slot { width: 52px; height: 52px; border-width: 2px; border-radius: 8px; }
  .slot.util { width: 40px; height: 40px; }
  .slot.util.off { width: 48px; }
  .slot .ico svg.ic { width: 24px; height: 24px; }
  .slot.util .ico svg.ic { width: 18px; height: 18px; }
  .slot .nm { font-size: 9px; margin-top: 1px; }
  .slot .k { font-size: 10px; }
  .slot .ammo { font-size: 12px; }
  .slot.sel { transform: translateY(-4px); }
  #bh-ladder, html.touch #bh-ladder { bottom: calc(var(--sb) + 70px); gap: 5px; }
  .lad { width: auto; padding: 4px 8px 6px 30px; }
  .lad-name { display: none; }
  .lad-ic { left: 7px; margin-top: -10px; }
  .lad-ic svg.ic { width: 18px; height: 18px; }
  .lad-sub { font-size: 9px; letter-spacing: .6px; }
  #bh-prompt, html.touch #bh-prompt { top: 60%; font-size: 14px; }
  #bh-toast { top: 28%; }
  .toast { font-size: 16px; }
  .toast.sever { font-size: 20px; }
  #bh-banner { font-size: 24px; top: 22%; }
  #bh-elim { top: 66%; }
  .el-name { font-size: 20px; }
  .el-top, .el-sub { font-size: 11px; }
  #bh-streak { top: 15%; }
  .sk-name { font-size: 30px; }
  .sk-n, .sk-desc { font-size: 12px; }
  #bh-aimhint { font-size: 12px; top: 63%; }
  .hbar span { font-size: 11px; }

  /* intro */
  #in-title { top: 22%; }
  #in-title h1 { font-size: 42px; }
  #in-title h2 { font-size: 16px; }
  #in-card { min-width: 0; padding: 10px 18px 12px; bottom: 14vh; }
  .ic-k { font-size: 11px; letter-spacing: 3px; }
  .ic-name { font-size: 30px; }
  .ic-n { font-size: 24px; }
  .ic-n small { font-size: 13px; }
  .ic-comp { font-size: 12px; }
  #in-count { font-size: 90px; }
  #in-count.go { font-size: 76px; }
  #in-skip { right: calc(var(--sr) + 16px); }

  /* respawn shop: scrolls if it must */
  #bh-respawn { justify-content: flex-start; overflow-y: auto; -webkit-overflow-scrolling: touch;
    padding: calc(var(--st) + 8px) calc(var(--sr) + 8px) calc(var(--sb) + 8px) calc(var(--sl) + 8px); }
  .rs-panel { width: 100%; margin: auto 0; padding: 10px 14px 12px; border-radius: 12px; }
  .rs-top { margin-bottom: 6px; padding-bottom: 6px; }
  .rs-head { font-size: 26px; }
  .rs-by { font-size: 13px; }
  .rs-glory b { font-size: 26px; }
  .rs-glory svg.ic { width: 20px; height: 20px; }
  .rs-cols { gap: 12px; }
  .rs-col.side { width: 200px; gap: 5px; }
  .rs-label { margin: 3px 0 1px; font-size: 10px; }
  .sh-grid { gap: 5px; }
  .sh-opt { padding: 6px 8px; }
  .sh-txt small { display: none; }
  .sh-txt b { font-size: 13px; }
  .sh-need { position: static; grid-column: 2; margin-top: 1px; font-size: 9.5px; }
  .rs-pt { padding: 6px 10px; font-size: 14px; }
  .rs-receipt { font-size: 11.5px; padding: 6px 10px; }
  .rs-deploy { font-size: 18px; padding: 9px 20px; }

  /* end screen */
  .end-banner { margin-bottom: 8px; }
  .end-banner h1 { font-size: 60px; }
  .end-banner p { font-size: 15px; }
  .end-score { font-size: 20px; margin-bottom: 8px; }
  .end-stats { grid-template-columns: repeat(6, 1fr); gap: 6px; margin-bottom: 8px; }
  .end-stats .stat { padding: 6px 8px; }
  .end-stats b { font-size: 22px; }
  .end-stats span { font-size: 9px; letter-spacing: 1px; }
  .end-loss { font-size: 12px; margin-bottom: 10px; }
  #bh-end .big-btn { font-size: 18px; padding: 9px 30px; }
}

/* ---------- strategy board ---------- */
@media (max-height: 520px), (max-width: 760px) {
  #strat-topbar { top: calc(var(--st) + 8px); left: calc(var(--sl) + 8px); right: calc(var(--sr) + 8px); width: auto; transform: none;
    height: 46px; gap: 10px; padding: 0 6px 0 12px; font-size: 13px; }
  #hud-tribe { font-size: 14px; gap: 6px; }
  #hud-gold { padding: 4px 9px; }
  #hud-gold b { font-size: 15px; }
  #hud-turn b { font-size: 16px; }
  #btn-tech, #btn-gamemenu { font-size: 0; gap: 0; padding: 9px; }
  #strat-topbar .tb-btn svg.ic { width: 18px; height: 18px; }
  .tb-btn.endturn { padding: 9px 14px; font-size: 12px; letter-spacing: .1em; }

  #strat-panel { top: calc(var(--st) + 62px); left: calc(var(--sl) + 8px); width: 240px; padding: 10px;
    max-height: calc(100% - 72px - var(--st) - var(--sb)); font-size: 12px; -webkit-overflow-scrolling: touch; }
  #strat-panel h3 { font-size: 15px; }
  .sp-badge { width: 32px; height: 32px; }
  .sp-stats { margin: 8px 0 6px; gap: 4px; }
  .sp-stats small { font-size: 8.5px; letter-spacing: .04em; }
  #strat-log { top: calc(var(--st) + 62px); right: calc(var(--sr) + 10px); width: 220px; font-size: 11px; }

  #strat-citybar { bottom: calc(var(--sb) + 6px); width: calc(100% - var(--sl) - var(--sr) - 16px);
    left: calc(50% + (var(--sl) - var(--sr)) / 2); padding: 8px 10px; border-radius: 12px; }
  #strat-citybar h3 { font-size: 15px; }
  .cb-stats { font-size: 11.5px; }
  .cb-close { width: 30px; height: 30px; }
  .cb-actions { flex-wrap: nowrap; overflow-x: auto; gap: 10px; margin-top: 6px; padding-top: 6px; -webkit-overflow-scrolling: touch; }
  .cb-group { flex-wrap: nowrap; }
  #strat-citybar button.ca { width: 70px; min-height: 62px; padding: 5px 4px; flex-shrink: 0; }
  .ca-ic { width: 26px; height: 26px; }
  .ca-name { font-size: 10.5px; }
  .ca-cost { font-size: 11px; }

  /* modals fill the phone instead of floating */
  .modal .modal-inner { padding: 14px 16px; border-radius: 14px; max-height: calc(100% - 16px - var(--st) - var(--sb)); -webkit-overflow-scrolling: touch; }
  .modal .modal-inner.research { width: calc(100% - 16px - var(--sl) - var(--sr)); max-height: calc(100% - 16px - var(--st) - var(--sb)); }
  .mh { margin-bottom: 10px; }
  .tree { grid-template-columns: repeat(5, minmax(170px, 1fr)); overflow: auto; }
  .modal-inner.bp h2 { font-size: 22px; margin: 2px 0 8px; }
  .vs-side { padding: 8px; }
  .vs-n { font-size: 24px; }
  .bp-desc { font-size: 12px; margin-bottom: 10px; }
  .modal-inner.bp .cta { padding: 11px 26px; font-size: 14px; }
  #game-menu .gm-inner { width: min(380px, calc(100% - 24px)); }
  #game-menu .menu-runes { display: none; }
  #game-menu h2 { font-size: 22px; margin-bottom: 6px; }
  #game-menu .gm-row { padding: 5px 0; }
  #game-menu .cta { margin-top: 10px; padding: 11px 20px; }
  #game-menu .ghost { padding: 9px 16px; }
}
@media (max-width: 560px) {
  #hud-tribe span, #hud-gold small, #hud-turn small { display: none; }
}

/* ---------- main menu ---------- */
.menu-box { width: min(1180px, calc(100vw - var(--sl) - var(--sr) - 24px)); }
@media (max-height: 520px) {
  .menu-box { padding: calc(var(--st) + 10px) 0 calc(var(--sb) + 12px); }
  .menu-head { margin-bottom: 8px; }
  .game-title { font-size: 44px; }
  .tagline { font-size: 11px; margin-top: 4px; }
  .menu-tabs { margin-bottom: 10px; }
  .menu-tab { padding: 7px 18px; font-size: 13px; }
  .menu-panel { padding: 14px 16px 16px; }
  .tribe-grid { margin-bottom: 12px; gap: 8px; }
  .tribe-card { padding: 10px 8px; }
  .tribe-card p { font-size: 11px; }
}
@media (max-width: 560px) {
  #qb-presets { grid-template-columns: repeat(2, 1fr); }
  .qb-dim label { width: 88px; }
  .menu-tab { padding: 8px 16px; font-size: 13px; }
  .cta { padding: 14px 30px; }
}

/* ---------- install banner (main menu) ---------- */
#install-banner { position: fixed; z-index: 40; left: 50%; bottom: calc(var(--sb) + 12px); width: min(560px, calc(100% - var(--sl) - var(--sr) - 24px));
  display: flex; align-items: center; gap: 12px; padding: 10px 10px 10px 12px; border-radius: 16px;
  background: rgba(248, 244, 236, .97); color: #24222b; border: 1px solid rgba(255,255,255,.8);
  box-shadow: 0 18px 50px rgba(10,14,22,.45); font-family: 'Nunito Sans', sans-serif;
  transform: translate(-50%, 140%); transition: transform .45s cubic-bezier(.2,1.2,.4,1); }
#install-banner.in { transform: translate(-50%, 0); }
#install-banner img { width: 46px; height: 46px; border-radius: 11px; flex-shrink: 0; box-shadow: 0 3px 8px rgba(0,0,0,.25); }
.ib-txt { flex: 1; min-width: 0; line-height: 1.3; }
.ib-txt > b { display: block; font-family: 'Cinzel', serif; font-size: 15px; letter-spacing: .04em; }
.ib-txt span { font-size: 12.5px; color: #5d5866; }
.ib-txt span b { color: #24222b; }
.ib-txt svg.ic { width: 15px; height: 15px; vertical-align: -3px; color: #2a7ae2; }
.ib-go { flex-shrink: 0; padding: 10px 18px; border: none; border-radius: 10px; background: linear-gradient(180deg, #c95a3e, #9c3624); color: #fff8ea;
  font-family: 'Cinzel', serif; font-weight: 900; font-size: 13px; letter-spacing: .1em; text-transform: uppercase; cursor: pointer; }
.ib-x { flex-shrink: 0; width: 32px; height: 32px; border-radius: 50%; border: none; background: rgba(60,50,40,.08); color: #5d5866; display: flex; align-items: center; justify-content: center; cursor: pointer; }
.ib-x svg.ic { width: 16px; height: 16px; }

/* ============ MOBILE UX PASS: menus + modals ============ */

/* bigger tap targets everywhere on touch */
html.touch .qb-chip { min-height: 36px; padding: 6px 13px; }
html.touch .menu-tab { min-height: 40px; }

/* main menu header: squeeze hard on short landscape screens (Safari bars showing) */
@media (max-height: 420px) {
  .menu-runes, .tagline { display: none; }
  .game-title { font-size: 34px; }
  .menu-head { margin-bottom: 6px; }
  .menu-tabs { margin-bottom: 8px; }
  .menu-tab { padding: 5px 16px; font-size: 12px; }
  html.touch .menu-tab { min-height: 34px; }
}

@media (max-height: 520px), (max-width: 760px) {
  .menu-panel { padding: 14px 16px 16px; }

  /* quick battle presets: one swipeable row instead of a wall of big cards */
  #qb-presets { display: flex; overflow-x: auto; scroll-snap-type: x mandatory; gap: 10px;
    margin: 0 -16px; padding: 2px 16px 10px; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
  #qb-presets::-webkit-scrollbar { display: none; }
  .qb-preset { flex: 0 0 196px; scroll-snap-align: start; }
  .qb-preset:hover { transform: none; }
  .qp-art { aspect-ratio: 240 / 96; }
  .qp-body { padding: 16px 11px 11px; }
  .qb-preset h3 { font-size: 13.5px; }
  .qb-preset p { font-size: 11px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

  /* dials: label above its chips, chips get the full width */
  .qb-dim { flex-direction: column; gap: 6px; padding: 8px 0; }
  .qb-dim label { width: auto; padding-top: 0; }
  .qb-chips { gap: 6px; }

  /* the go button and matchup stay pinned to the bottom while you scroll the dials */
  .qb-foot { position: sticky; bottom: 0; z-index: 3; flex-direction: row; align-items: center; gap: 12px;
    margin: 12px -16px -16px; padding: 10px 16px calc(var(--sb) + 10px);
    background: #f8f4ec; border-top: 1px solid var(--line); border-radius: 0 0 14px 14px;
    box-shadow: 0 -8px 20px rgba(40,30,20,.08); }
  #qb-summary { flex: 1; min-width: 0; gap: 2px 10px; }
  #qb-summary em { display: none; }
  .sm-side b { font-size: 14px; }
  .sm-side span { font-size: 11px; }
  .sm-side .emblem { width: 24px; height: auto; }
  .qb-foot .cta { flex-shrink: 0; white-space: nowrap; padding: 12px 22px; font-size: 14px; }

  /* campaign: Begin / New Conquest always in reach */
  #btn-start { position: sticky; bottom: calc(var(--sb) + 10px); z-index: 3; }
  .continue-card { margin-bottom: 12px; padding: 10px 12px; }
  .ct-txt b { font-size: 16px; }

  /* battle prompt: compact sides, buttons pinned to the bottom of the sheet */
  .modal-inner.bp .vs-row { gap: 10px; margin-bottom: 8px; }
  .vs-side { display: grid; grid-template-columns: 40px 1fr; align-items: center; column-gap: 10px; text-align: left; padding: 8px 10px; }
  .vs-em { grid-row: span 3; }
  .vs-em svg { width: 40px; height: auto; }
  .vs-name { margin-top: 0; font-size: 15px; }
  .vs-n { font-size: 18px; }
  .vs-n small { display: inline; margin-left: 4px; font-size: 9.5px; }
  .vs-comp, .vs-walls { justify-content: flex-start; margin-top: 2px; font-size: 11.5px; }
  .vs-walls { display: flex; align-items: center; gap: 4px; }
  .vs-mid { font-size: 14px; }
  .bp-kicker { font-size: 10px; }
  .modal-inner.bp .battle-choice { position: sticky; bottom: -14px; z-index: 2; margin: 0 -16px -14px; padding: 10px 16px calc(var(--sb) + 12px);
    background: #f8f4ec; border-top: 1px solid var(--pk-line); flex-wrap: nowrap; }
  .modal-inner.bp .battle-choice .ghost { padding: 10px 14px; font-size: 13px; }

  /* stack panel: drop the hint line on short screens so the Manage button stays visible */
  .sp-legend { display: none; }
}
@media (max-width: 560px) {
  .qb-preset { flex-basis: 170px; }
  .qb-foot .cta { padding: 12px 16px; }
  .sm-vs { display: none; }
  .modal-inner.bp .battle-choice { flex-wrap: wrap; }
  .modal-inner.bp .vs-row { flex-direction: column; align-items: stretch; }
  .modal-inner.bp .vs-mid { text-align: center; }
}
