/* Phones and small tablets. Loaded last, so these rules win over the desktop ones.
   Tank Stars is played sideways: a touch screen held upright is asked to turn (#rotate below).
   Every layout change sits inside a phone media query, so big screens look exactly as before:
     phone held sideways:  @media (max-height: 500px) and (orientation: landscape)
     narrow screen:        @media (max-width: 600px)
   A 568x320 phone held sideways matches both, so each section's sideways rules come last and win.
   The narrow rules otherwise serve a narrow desktop window (and a 4-inch phone held upright in
   Safari is under 500 px tall, hence the landscape test).
   js/phone.js sets --vvh / --vvt (the part of the screen the on-screen keyboard leaves) and
   html.touch on touch screens. */

/* ---------- touch screens ---------- */
/* no double-tap zoom, no grey flash on tap, no text selection or callout on long press */
html { touch-action: manipulation; -webkit-text-size-adjust: 100%; }
body { -webkit-user-select: none; -webkit-touch-callout: none; -webkit-tap-highlight-color: transparent; overscroll-behavior: none; }
input, textarea, select { -webkit-user-select: text; user-select: text; -webkit-touch-callout: default; }
/* a tap leaves :hover on until the next tap, so hover lifts would stick */
@media (hover: none) {
  .nav-btn:hover, .play-btn:hover, .card:hover, .who-card:hover, .rg-c:hover:not(:disabled), .rt-row:hover, .rm-root:hover, .rm-node:hover { transform: none; }
  .fire-btn:hover:not(:active) { transform: none; }
  .wcard:not(.armed):hover { transform: none; box-shadow: none; }
}

/* ---------- Tank Stars is played sideways ---------- */
/* above everything, popups and celebrations included */
#rotate { display: none; position: fixed; inset: 0; z-index: 90; place-items: center; padding: 24px; text-align: center;
  background: radial-gradient(circle at 50% 30%, #1d2f63, #070b18 75%); }
.rot-card { display: flex; flex-direction: column; align-items: center; gap: 10px; max-width: 320px; }
.rot-icon { font-size: 72px; animation: rot-turn 2.4s ease-in-out infinite; }
.rot-card b { font-family: var(--head); font-weight: 400; font-size: 26px; }
.rot-card p { margin: 0; color: var(--muted); font-weight: 700; }
.rot-card .rot-lock { font-size: 14px; }
.rot-card .btn { margin-top: 8px; }
@keyframes rot-turn { 0%, 30% { transform: rotate(0); } 60%, 100% { transform: rotate(-90deg); } }
/* any touch screen held upright, phone or tablet, on every screen of the game; a desktop window
   is left alone. Leave battle shows only during a battle. */
@media (orientation: portrait) {
  html.touch #rotate { display: grid; }
}
body:not(:has(#battle.on)) #rotQuit { display: none; }


/* ========== MENUS: who's playing, sign-in, home, settings, popups, power drops ========== */
/* On phones the home scrolls instead of pinning blocks to the corners: one column upright, three
   columns sideways. The sky canvas sits behind the top of it, and js/screens.js homeLoop draws the
   tank in the space below the tank's name: .tank-name's bottom margin is the tank's stage. */

/* ---------- both ways round ---------- */
@media (max-width: 600px), (max-height: 500px) {
  /* loading and who's playing: the logo fits on one line */
  .logo, .who-wrap > .logo { font-size: 40px; }
  .logo small, .who-wrap > .logo small { font-size: 16px; letter-spacing: 8px; }
  .who-wrap { padding: 18px 12px 28px; gap: 12px; }
  .who-title { font-size: 26px; margin: 2px 0 0; }
  .who-list { width: 100%; gap: 12px; }
  .who-card { width: calc(50% - 6px); max-width: 180px; padding: 14px 8px 12px; border-radius: 20px; }
  .who-av { width: 72px; height: 72px; font-size: 42px; margin-bottom: 8px; }
  .who-name { font-size: 20px; overflow-wrap: anywhere; }
  .who-sub { font-size: 13px; }
  .who-edit { width: 40px; height: 40px; top: 4px; right: 4px; }
  .who-note { font-size: 15px; overflow-wrap: anywhere; }
  .who-note .link-btn { min-height: 40px; }
  .who-msg { margin-top: 4px; }
  .who-big { font-size: 52px; }
  /* add and edit player */
  .su-sec { padding: 12px; }
  .su-av { gap: 6px; }
  .su-av button { width: 48px; height: 48px; font-size: 26px; }
  .su-col { flex-wrap: wrap; gap: 6px; }
  .su-col button { width: 40px; height: 40px; }
  .su-lvls { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); }
  .su-imp { flex-basis: 220px; }
  .su-b .btn { min-height: 44px; }

  /* home: everything stays in the normal flow and the screen scrolls */
  #home.on { overflow-y: auto; overflow-x: hidden; overscroll-behavior: contain; }
  #home > .topbar, #home > .side-nav, #home > .learn-zone, #home > .play-zone { position: relative; inset: auto; transform: none; z-index: 1; width: auto; }
  #home .right-col { display: contents; }
  #home .stage-info, #home .quest-card { position: relative; inset: auto; z-index: 1; width: auto; }
  #homeBg { position: absolute; inset: 0 auto auto 0; width: 100%; z-index: 0; -webkit-mask-image: linear-gradient(#000 70%, transparent); mask-image: linear-gradient(#000 70%, transparent); }
  #home .profile { padding: 5px 12px 5px 5px; gap: 10px; min-width: 0; }
  #home .pav { flex: none; width: 40px; height: 40px; font-size: 24px; }
  #home .profile > div:last-child { flex: 1; min-width: 0; }
  #home .pname { font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  #home .xpbar { width: 100%; min-width: 50px; }
  #home .chip { justify-content: center; min-height: 40px; padding: 6px 12px; font-size: 15px; white-space: nowrap; }
  #home .rank-chip { flex-direction: row; align-items: center; gap: 10px; min-width: 0; max-width: none; min-height: 40px; padding: 6px 12px; }
  #home .rkc-n { font-size: 15px; white-space: nowrap; }
  #home .rkc-bar { flex: 1; min-width: 30px; }
  #home .rank-chip small { display: none; }
  #home .tank-name, #home .stats-panel { position: relative; z-index: 1; }
  #home .tank-name { justify-content: center; }
  /* stats: two to a row where they fit, each with its name above its bar */
  #home .stats-panel { display: flex; flex-wrap: wrap; align-items: center; column-gap: 10px; padding: 8px 12px 10px; }
  #home .st { flex: 1 1 calc(50% - 5px); min-width: 0; grid-template-columns: 18px minmax(0, 1fr) auto; grid-template-rows: auto auto; gap: 1px 6px; margin: 3px 0; }
  #home .st-i { grid-row: 1 / 3; }
  #home .st-n { grid-column: 2; font-size: 12px; line-height: 1.1; }
  #home .st-bar { grid-column: 2; grid-row: 2; }
  #home .st b { grid-column: 3; grid-row: 1 / 3; }
  #home .power { flex: none; margin-top: 6px; font-size: 15px; }
  #home .kit-line { flex: 1 1 110px; min-width: 0; margin-top: 6px; gap: 4px; }
  #home .kit-line span { min-width: 0; gap: 2px; font-size: 18px; }
  #home .kit-line small { font-size: 12px; }
  #home .drone-line { flex: 1 1 100%; margin-top: 6px; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden; }
  #home .modes { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
  #home .mode { justify-content: center; text-align: center; min-height: 44px; padding: 6px 4px; gap: 5px; font-size: 13px; line-height: 1.15; }
  #home .play-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  #home .drops { width: auto; padding: 8px 10px; }
  #home .drops-sub, #home .drops-pity { font-size: 12px; line-height: 1.25; }
  #home .play-btn { width: auto; min-height: 100px; }
  #home .play-btn span { font-size: 40px; }
  #home .learn-zone { left: auto; bottom: auto; }
  #home .road-chip { padding: 8px 12px; }
  #home .road-chip small { font-size: 12px; }
  #home .roots-btn { flex-wrap: wrap; row-gap: 4px; min-height: 44px; padding: 8px 12px; font-size: 15px; white-space: normal; }
  /* Practice and Sentences share a row when they fit */
  #home .learn-btns { flex-wrap: wrap; }
  #home .learn-btns .train-btn { flex: 1 1 0; min-width: max-content; min-height: 44px; padding: 8px; font-size: 15px; }
  #home .learn-btns .train-btn em { font-size: 12px; }
  #home .quest { grid-template-columns: 26px minmax(0, 1fr) 46px; }
  #home .q-t { font-size: 14px; }
  #home .q-bar { height: 16px; }
  #home .q-bar span { font-size: 12px; }
  #home .q-chest { height: 44px; }
  #home .side-nav { display: grid; gap: 8px; }
  #home .side-nav .nav-btn { width: auto; min-height: 60px; flex-direction: column; justify-content: center; gap: 2px; padding: 6px 4px; font-size: 12px; line-height: 1.15; text-align: center; }
  #home .side-nav .nav-btn span { font-size: 22px; }

  /* popups and celebrations scroll when taller than the screen, and stay centred when not */
  .popup, .celebrate { display: flex; overflow-y: auto; padding: 12px; }
  .popup-card, .cel-card { margin: auto; }
  .cel-card > .btn { position: sticky; bottom: 0; }   /* a long rank-up list never hides its button */
  .popup-b .btn { min-height: 44px; }
  .cel-card { padding: 20px 18px; border-radius: 24px; }
  .cel-icon { font-size: 64px; }
  .cel-title { font-size: 28px; }
  .cel-text { font-size: 16px; line-height: 1.5; margin-bottom: 14px; }
  /* left: 50% would squeeze the toast into half the screen, so its width is set outright; it sits at
     the bottom so it never covers a panel's Back button and coins right after an upgrade */
  #toast { top: auto; bottom: 12px; width: max-content; max-width: calc(100vw - 24px); padding: 10px 16px; }

  /* Power Drops */
  .crate-rar { font-size: 40px; letter-spacing: 3px; }
  .crate-hint { font-size: 16px; padding: 0 16px; }
  #crate .crate-reward.show { display: flex; overflow-y: auto; padding: 12px; }
  .rew-card { min-width: 0; width: min(360px, 100%); margin: auto; padding: 20px 16px; }
  .rew-rar { font-size: 24px; margin-bottom: 12px; }
  .rew-list { gap: 8px; margin-bottom: 16px; }
  .rew-item { padding: 10px 12px; font-size: 17px; }
}

/* ---------- phone upright: one column ---------- */
@media (max-width: 600px) {
  #home.on { display: flex; flex-direction: column; gap: 10px; padding: 10px 12px 28px; }
  #homeBg { height: 430px; }
  #home .topbar { order: 1; display: grid; grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "me coins" "rank streak"; gap: 8px; }
  #home .profile { grid-area: me; }
  #home .rank-chip { grid-area: rank; }
  #home .topbar .chips { display: contents; }
  #home .chip.coins { grid-area: coins; }
  #home .chip.streak { grid-area: streak; }
  /* the tank stands under its name, a little smaller on short phones so PLAY stays near the top */
  #home .stage-info { order: 2; }
  #home .tank-name { font-size: 26px; margin-bottom: clamp(84px, 18vh, 140px); }
  /* PLAY comes right after the tank */
  #home .play-zone { order: 3; align-items: stretch; }
  #home .learn-zone { order: 4; }
  #home .quest-card { order: 5; }
  #home .side-nav { order: 6; grid-template-columns: repeat(4, minmax(0, 1fr)); }
}

/* ---------- phone sideways: three columns (after the upright rules, so it wins on a small phone that matches both) ---------- */
@media (max-height: 500px) and (orientation: landscape) {
  /* first screen: the top bar, then learning, the tank and PLAY side by side, then the hangar
     buttons in one row; daily quests and the tank's stats come below */
  #home.on { display: grid; grid-template-columns: minmax(150px, 1.2fr) minmax(100px, .7fr) minmax(210px, 1.2fr); grid-template-rows: none;
    grid-template-areas: "top top top" "learn stage play" "nav nav nav" "quest quest stats"; align-items: start; gap: 8px 10px; padding: 8px 10px 14px; }
  #homeBg { height: 100%; }
  #home .topbar { grid-area: top; display: flex; gap: 8px; }
  #home .profile { flex: 0 1 220px; }
  #home .rank-chip { flex: 0 1 230px; }
  #home .topbar .chips { display: flex; gap: 8px; }
  #home .stage-info { display: contents; }
  #home .tank-name { grid-area: stage; font-size: 22px; margin-bottom: 140px; }
  #home .stats-panel { grid-area: stats; }
  #home .st { flex-basis: 100%; }
  #home .kit-line { flex-basis: 100%; }   /* the stats column is narrow: the special chips get their own row */
  #home .play-zone { grid-area: play; align-items: stretch; gap: 8px; }
  #home .play-row { grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); gap: 8px; }
  #home .drops { padding: 6px 8px; }
  #home .drops-title { font-size: 12px; letter-spacing: .5px; }
  #home .drops-slots { margin: 4px 0; }
  #home .slot { font-size: 18px; padding: 2px 0; }
  #home .play-btn { min-height: 0; }
  #home .play-btn span { font-size: 30px; }
  #home .pav { width: 34px; height: 34px; font-size: 20px; }
  #home .roots-btn { padding: 8px 10px; }
  #home .learn-btns .train-btn { padding: 8px 6px; font-size: 14px; }
  #home .learn-zone { grid-area: learn; }
  #home .quest-card { grid-area: quest; }
  #home .side-nav { grid-area: nav; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 6px; }
  #home .side-nav .nav-btn { min-height: 56px; }
  /* who's playing: smaller logo and cards so a row of players shows */
  .logo, .who-wrap > .logo { font-size: 32px; }
  .logo small, .who-wrap > .logo small { font-size: 14px; letter-spacing: 6px; }
  .who-wrap { padding: 10px 12px 20px; gap: 8px; }
  .who-title { font-size: 22px; margin: 0; }
  .who-card { width: 150px; padding: 10px 8px; }
  .who-av { width: 56px; height: 56px; font-size: 32px; margin-bottom: 4px; }
  .who-name { font-size: 18px; }
  /* popups, celebrations and drops are short on space here */
  .popup, .celebrate { padding: 8px; }
  .cel-card { padding: 12px 18px; }
  .cel-card .btn.big { padding: 10px 24px; font-size: 18px; }
  .cel-icon { font-size: 48px; }
  .cel-title { font-size: 24px; margin: 2px 0; }
  .cel-text { font-size: 15px; line-height: 1.4; margin-bottom: 10px; }
  .crate-ui { top: 3%; }
  .crate-rar { font-size: 32px; }
  .crate-hint { bottom: 4%; font-size: 15px; }
  .rew-card { padding: 14px 16px; }
  .rew-rar { font-size: 22px; margin-bottom: 8px; }
  .rew-list { gap: 6px; margin-bottom: 12px; }
  .rew-item { padding: 6px 12px; font-size: 16px; }
  .rew-item span { font-size: 24px; }
}
/* ---------- end MENUS ---------- */


/* ========== PANELS: hangars, battle pass, word book, rank, road map, word roots ========== */
/* Upright, a screen scrolls as one page (the hangar cards become a strip to swipe). Sideways the
   screen is short, so lists and details sit side by side and each scrolls on its own. A small
   phone held sideways (568 px) matches both queries: the sideways rules come last and win. */
@media (max-width: 600px), (max-height: 500px) {
  /* a slim head bar with a 40 px Back button */
  .panel-head { gap: 10px; padding: 6px 14px; }
  .panel-head h2 { font-size: 20px; line-height: 1.15; min-width: 0; }
  .panel-head .back { min-height: 40px; padding: 6px 12px; }
  .panel-head .chip { padding: 6px 12px; font-size: 15px; }
  .panel-body { padding: 10px 12px; }
  #panel .btn.small { min-height: 40px; }
  #panel .btn.big { padding: 10px 18px; font-size: 17px; }
  #panel .btn em { white-space: nowrap; }
  .p-tier, .lr-name em, .rm-root em { font-size: 12px; }
  /* hangars */
  .h-title { font-size: 22px; }
  .h-actions { flex-wrap: wrap; }
  .h-actions .btn { flex: 1 1 auto; min-height: 44px; }
  /* a part's upgrade button drops under its text when the row is too narrow for both */
  .part { flex-wrap: wrap; }
  .p-txt { flex: 1 1 170px; min-width: 0; }
  .part > .btn, .part > .maxed { margin-left: auto; }
  .part .btn.up { min-width: 76px; }
  /* battle pass: the tiers keep their size and the page scrolls when it must */
  .pass { height: auto; }
  .pass-track { flex: none; }
  .pass-prog { min-width: 0; flex: 1 1 220px; }
  /* word book */
  .tw .spk { min-width: 40px; min-height: 40px; }
  /* ranks: rows a little tighter so the reward text has room */
  .rank-card { padding: 12px; gap: 8px; }
  .rk-big { font-size: 24px; }
  .rk-row { gap: 8px; padding: 8px 10px; }
  .rk-n { width: 30px; height: 30px; flex-basis: 30px; }
  .rk-cv { width: 64px; height: 38px; flex-basis: 64px; }
  .rk-p { font-size: 12px; }
  /* settings */
  .settings label.tog { min-height: 40px; }
  .set-row .btn { flex: 1 1 auto; min-height: 44px; }
  /* road map and word roots: the card beside the map */
  .road-side { overflow-y: auto; border-radius: 20px; }
  .road-card { padding: 12px; gap: 8px; }
  .rc-big { font-size: 20px; }
  .rc-s { font-size: 14px; }
  .rt-scroll { padding: 8px 10px; }
  .rt-row { grid-template-columns: 26px 22px minmax(0, 1fr); gap: 2px 8px; padding: 8px 10px; }
  .rt-row em { grid-column: 3; justify-self: start; }
  .rt-fs i { margin: 0 4px; }
  /* lessons in the road map popup: the Start button beside the title, the roots below */
  .up-w.rt-pw { grid-template-columns: 26px minmax(0, 1fr) auto; }
  .up-w.rt-pw small { grid-column: 2 / -1; grid-row: 2; }
  .rt-pw .btn { grid-column: 3; grid-row: 1; min-height: 40px; }
}

/* ---------- held upright ---------- */
@media (max-width: 600px) {
  .panel-head h2 { font-size: 18px; }
  /* hangars: swipe the cards sideways, the details of the picked one follow below */
  .hangar { display: flex; flex-direction: column; height: auto; gap: 12px; }
  .h-list { display: flex; overflow-x: auto; overflow-y: hidden; gap: 10px; margin: 0 -12px; padding: 6px 12px 10px; }
  .h-list .card { flex: 0 0 116px; }
  .h-list .thumb { height: 64px; }
  .h-detail { overflow: visible; padding: 12px; }
  .h-preview { height: 150px; flex: none; }
  /* battle pass */
  .pass { gap: 12px; }
  .pass-head { padding: 12px 14px; gap: 10px; }
  .season-name { font-size: 26px; }
  .tier { height: 200px; }
  /* word book: the four counts in two rows */
  .w-stats { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .w-stats div { padding: 8px; }
  .w-stats b { font-size: 24px; }
  /* ranks: the rank card on top (it scrolls if long), the rank list fills the rest */
  .rank-wrap { display: flex; flex-direction: column; gap: 10px; }
  .rank-card { flex: none; max-height: 46%; }
  .rank-list { flex: 1 1 0; min-height: 0; padding-right: 0; }
  /* road map and word roots: the card on top, the map or lesson list fills the rest */
  .road-wrap { display: flex; flex-direction: column; gap: 10px; }
  .road-side { flex: none; max-height: 44%; }
  .road-scroll { flex: 1 1 0; min-height: 0; }
  /* a word in the unit popup: its meaning goes under it */
  .up-w { grid-template-columns: 26px minmax(0, 1fr); }
  .up-w small { grid-column: 2; }
  /* training grounds */
  .rg-load { grid-template-columns: minmax(0, 1fr); }
  .rg-prev { height: 120px; }
  .rg-c.lab { grid-column: 1 / -1; }
}

/* ---------- held sideways ---------- */
@media (max-height: 500px) and (orientation: landscape) {
  .panel-head h2 { font-size: 20px; }
  /* hangars: the cards on the left, the picked one on the right */
  .hangar { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.15fr); grid-template-rows: minmax(0, 1fr); height: 100%; gap: 12px; }
  .h-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); grid-auto-rows: max-content; overflow: auto; gap: 8px; margin: 0; padding: 4px; }
  .h-list .thumb { height: 52px; }
  .h-detail { overflow: auto; padding: 12px; gap: 8px; }
  .h-preview { height: 110px; flex: none; }
  /* battle pass: a one-line season bar and shorter tiers */
  .pass { gap: 8px; }
  .pass-head { padding: 8px 14px; gap: 4px 16px; flex-wrap: nowrap; }
  .season { font-size: 12px; letter-spacing: 2px; }
  .season-name { font-size: 20px; }
  .pass-prog b { font-size: 18px; }
  .pass-prog .bar { height: 10px; margin: 4px 0; }
  .pass-prog small { font-size: 12px; }
  .pass-track { padding: 4px 4px 8px; }
  .tier { height: 150px; padding: 8px; }
  .t-num { font-size: 16px; }
  .t-ic { font-size: 34px; }
  .pass-note { margin-top: 0; font-size: 13px; }
  /* word book */
  .w-stats { grid-template-columns: repeat(4, 1fr); }
  /* ranks, road map and word roots: the card on the left, the list or map on the right */
  .rank-wrap { display: grid; grid-template-columns: minmax(190px, .72fr) minmax(0, 1fr); grid-template-rows: minmax(0, 1fr); gap: 12px; }
  .rank-card { max-height: none; }
  .road-wrap { display: grid; grid-template-columns: minmax(190px, 340px) minmax(300px, 1fr); grid-template-rows: minmax(0, 1fr); gap: 12px; }
  .road-side { max-height: none; }
  /* a word in the unit popup: its meaning beside it, so more words show */
  .up-w { grid-template-columns: 26px 120px minmax(0, 1fr); }
  .up-w small { grid-column: auto; }
  /* training grounds */
  .rg-load { grid-template-columns: 170px minmax(0, 1fr); }
  .rg-prev { height: 130px; }
}
/* ---------- end PANELS ---------- */


/* ========== QUIZ: questions, flashcards, results, sentence challenge ========== */
/* The quiz fills the part of the screen the keyboard leaves (--vvh, --vvt). Only its middle scrolls,
   so the title and the Check / Continue buttons are always in view. #quiz is a size container:
   the @container rules below shrink the quiz while the on-screen keyboard is open. */
@media (max-width: 600px), (max-height: 500px) {
  #quiz { bottom: auto; top: var(--vvt, 0px); height: var(--vvh, 100%); padding: 6px; container-type: size; }
  .quiz-panel { width: 100%; max-height: 100%; border-radius: 18px; }
  .quiz-head, .quiz-pips, .quiz-stages { flex: none; }   /* only the middle gives way when space is short */
  .quiz-head { gap: 8px; padding: 8px 10px 8px 12px; }
  .qh-icon { font-size: 26px; }
  .qh-txt { min-width: 0; }
  .qh-title { font-size: 18px; line-height: 1.15; }
  .qh-sub { font-size: 13px; line-height: 1.25; }
  .qh-x { flex: none; width: 40px; height: 40px; }
  .qh-quit { min-height: 40px; }
  .qh-combo { font-size: 13px; white-space: nowrap; }
  .quiz-pips { gap: 4px; padding: 0 12px 6px; }
  .pip { height: 8px; }
  .quiz-stages { height: 22px; margin: -2px 14px 2px; }
  .quiz-stages .qs { font-size: 17px; }
  .quiz-body { flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 4px 12px 12px; }
  .quiz-foot { flex: none; min-height: 0; gap: 8px; padding: 8px 10px; }
  .quiz-foot:empty { display: none; }   /* a tap-the-answer question has nothing down here */
  .quiz-foot .btn { min-height: 44px; }
  .fb-info { min-width: 0; max-height: 38cqh; overflow-y: auto; overscroll-behavior: contain; line-height: 1.3; }
  .fb-title { font-size: 16px; }
  .fb-def, .fb-guess { font-size: 14px; }
  .fb-info .sc-ms { max-height: none; overflow: visible; }
  /* questions */
  .q-label { font-size: 12px; letter-spacing: 1px; margin: 4px 0; }
  /* big words shrink with the quiz's width, and a very long one breaks rather than running off */
  .q-big, .lc-word, .sc-word { overflow-wrap: anywhere; }
  .q-big { font-size: clamp(22px, 9cqi, 34px); margin: 2px 0; }
  .q-clue { font-size: 18px; margin: 6px 0; }
  .q-sentence { font-size: 18px; line-height: 1.4; margin: 8px 0; }
  .q-shape { font-size: 32px; margin: 6px 0 2px; }
  .q-family { margin: 6px auto 2px; }
  .qf { gap: 8px; padding: 6px 10px; }
  .qf-w { font-size: 18px; }
  .q-options { gap: 8px; margin-top: 10px; }
  .opt { min-height: 48px; padding: 10px 12px; font-size: 16px; line-height: 1.25; overflow-wrap: anywhere; }
  .q-options.words .opt { font-size: 18px; }
  .opt .k { display: none; }   /* the 1-4 keys are for keyboards */
  .quiz-body .spk { min-width: 40px; min-height: 40px; margin: -8px 0; vertical-align: middle; }
  .quiz-body .spk.listen { margin: 6px auto 0; }
  .tile-slot, .tile-bank { gap: 6px; margin: 10px 0; }
  .tile { min-width: 40px; height: 46px; font-size: 22px; }
  .tile.slot { min-width: 36px; height: 42px; }
  .type-wrap { margin: 8px auto; }
  .type-hint { font-size: 24px; letter-spacing: 4px; margin-bottom: 6px; }
  .type-in { font-size: 22px; padding: 8px; }
  .write-wrap { margin-top: 8px; }
  .write-wrap textarea, .quiz-panel.sentence textarea { min-height: 72px; font-size: 17px; padding: 8px 12px; }
  /* new word cards: the buttons stay at the bottom while a long card scrolls */
  .learn-card { padding: 4px 0 0; }
  .lc-tag { font-size: 12px; letter-spacing: 1px; padding: 3px 12px; }
  .lc-word { font-size: clamp(24px, 10cqi, 38px); margin-top: 6px; }
  .lc-def { font-size: 18px; margin: 8px 0; }
  .lc-ex { font-size: 15px; margin: 6px 0; }
  .lc-syn { font-size: 14px; margin-bottom: 8px; }
  .lc-roots { font-size: 14px; padding: 6px 10px; }
  .lc-roots small { font-size: 13px; }
  .lc-dots { margin: 2px 0 6px; }
  .lc-b { position: sticky; bottom: -12px; flex-wrap: nowrap; padding: 10px 0 12px; margin-bottom: -12px; background: linear-gradient(rgba(14,21,41,0), #0e1529 12px); }
  .lc-b .btn { min-height: 44px; }
  .lc-b .btn.big, .quiz-foot .btn.big { padding: 10px 18px; font-size: 18px; }
  .root-card .lc-word { font-size: 34px; }
  .rc-tip { font-size: 14px; }
  .rc-ex { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 8px; }
  .rce { padding: 8px 10px; }
  .rce-w { font-size: 19px; }
  /* results */
  .quiz-result { padding: 8px 0; }
  .qr-icon { font-size: 56px; }
  .qr-title { font-size: 24px; }
  .qr-score { font-size: 18px; margin: 4px 0; }
  .qr-stages { gap: 8px; margin: 8px 0 4px; }
  .qr-stages span { padding: 4px 10px; }
  /* sentence challenge */
  .quiz-panel.sentence .quiz-body { gap: 6px; }
  .sc-word { font-size: 30px; gap: 4px; }
  .sc-def { font-size: 16px; }
  .sc-result { padding: 10px 12px; }
  .sc-stars { font-size: 30px; }
  .sc-fb { font-size: 16px; }
  .sc-m { font-size: 14px; }
}
/* Upright: the Stop button sits beside the title with the streak under it, and the buttons at the
   bottom share the width. */
@media (max-width: 600px) and (orientation: portrait) {
  .quiz-head { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; column-gap: 8px; }
  .qh-icon { grid-row: 1 / 3; }
  .qh-txt { grid-column: 2; grid-row: 1 / 3; }
  .qh-x, .qh-quit { grid-column: 3; grid-row: 1; }
  .qh-quit { max-width: 116px; padding: 4px 10px; white-space: normal; line-height: 1.15; }
  .qh-combo { grid-column: 3; grid-row: 2; justify-self: end; }
  .quiz-foot { flex-wrap: nowrap; }
  .quiz-foot .btn { flex: 1 1 auto; }
  .quiz-foot.good, .quiz-foot.bad { flex-direction: column; align-items: stretch; }
}
/* Sideways: little height, so the title and its line share one row. */
@media (max-height: 500px) and (orientation: landscape) {
  .quiz-head { padding: 6px 10px 6px 14px; }
  .qh-icon { font-size: 24px; }
  .qh-txt { display: flex; flex-wrap: wrap; align-items: baseline; column-gap: 10px; }
  .qh-title { font-size: 17px; }
  .q-big { font-size: clamp(20px, 4.2cqi, 30px); }   /* in the left column, about 40% of the width */
  .q-clue { font-size: 17px; }
  .q-sentence { font-size: 17px; }
  .lc-word { font-size: clamp(22px, 4.6cqi, 32px); margin-top: 4px; }
  .lc-def { font-size: 17px; margin: 6px 0; }
  .tile-slot, .tile-bank { margin: 6px 0; }
  .tile { height: 42px; }
  .tile.slot { height: 38px; }
  .quiz-result { padding: 2px 0; }
  .qr-icon { font-size: 44px; }
  .quiz-foot { flex-wrap: nowrap; }
  .fb-info { max-height: 40cqh; }
}
/* Sideways and wide: the question on the left, the answers on the right; a word card in two columns. */
@media (max-height: 500px) and (min-aspect-ratio: 3/2) {
  .q-card { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 3fr); grid-template-rows: repeat(7, auto) 1fr; column-gap: 18px; align-items: start; }
  .q-card > * { grid-column: 1; }
  .q-card > .q-answer { grid-column: 2; grid-row: 1 / -1; align-self: center; }
  .q-card > .spk.listen { justify-self: center; }
  .q-answer > :first-child { margin-top: 0; }
  .learn-card:not(.root-card) { columns: 2; column-gap: 24px; }
  .learn-card:not(.root-card) .lc-def { break-after: column; }
  .learn-card:not(.root-card) .lc-b { column-span: all; }
  .learn-card .lc-dots { display: none; }   /* the tag already says "2 of 3" */
}
/* Typing with the on-screen keyboard open: upright it leaves about half the screen, sideways a thin
   strip. While the box has focus, hide the extras so the clue, the box and its Check button fit;
   in the thin strip the buttons move beside the box. */
@media (max-width: 600px), (max-height: 500px) {
  @container (max-height: 420px) and (max-aspect-ratio: 3/2) {
    .quiz-panel:has(.type-in:focus, textarea:focus) :is(.quiz-head, .quiz-pips, .quiz-stages, .q-label, .q-sub, .sc-tips) { display: none; }
  }
  @container (max-height: 250px) {
    .quiz-panel:has(.type-in:focus, textarea:focus) { flex-direction: row; }
    .quiz-panel:has(.type-in:focus, textarea:focus) :is(.quiz-head, .quiz-pips, .quiz-stages, .q-label, .q-sub, .sc-tips) { display: none; }
    .quiz-panel:has(.type-in:focus, textarea:focus) .quiz-body { padding: 8px 12px; }
    .quiz-panel:has(.type-in:focus, textarea:focus) .q-card > .q-answer { align-self: start; }
    .quiz-panel:has(.type-in:focus, textarea:focus) .quiz-foot { flex-direction: column; justify-content: center; max-width: 150px; border-top: 0; border-left: 1px solid var(--line); }
    .quiz-panel:has(.type-in:focus, textarea:focus) .quiz-foot .btn { width: 100%; }
    /* the box keeps most of the row so a long word stays readable; the letter hint gives way */
    .type-wrap { display: flex; align-items: center; gap: 10px; margin: 0; }
    .type-in { flex: 1 1 0; min-width: 60%; }
    .type-hint { flex: 0 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; margin: 0; font-size: 18px; letter-spacing: 1px; white-space: nowrap; }
    .type-hint small { display: none; }
    .write-wrap textarea, .quiz-panel.sentence textarea { min-height: 56px; }
    .sc-word { font-size: 24px; }
  }
}

/* ---------- end QUIZ ---------- */


/* ========== BATTLE: HUD, banners, battle end ========== */
/* Phone held sideways: a slim HUD that keeps the ground and the tanks in view. Health bars, wind
   and Quit share one row at the top; move pad, weapon cards, aim and FIRE share one row at the
   bottom. Dragging on the field is the main way to aim; the sliders fine-tune it. */
@media (max-height: 500px) and (orientation: landscape) {
  .hud-top { top: 6px; left: 6px; right: 6px; gap: 6px; }
  .team-bars { flex: 0 1 200px; width: auto; min-width: 0; gap: 3px; }
  /* name and health number on one line, the bar under them */
  .tb { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; column-gap: 6px; padding: 3px 8px 4px; border-radius: 9px; }
  /* short of room, the tank's name gives way first, then the status icons (they show over the tank
     too); the player's name stays */
  .tb-name { min-width: 0; gap: 4px; font-size: 12px; }
  .tb-name > span:first-child { flex: none; max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
  .tb-tank { flex: 0 100 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; font-size: 12px; }
  .tb-st { flex: 0 1 auto; min-width: 0; overflow: hidden; font-size: 12px; letter-spacing: 0; }
  .tb-hp { grid-column: 2; grid-row: 1; font-size: 12px; }
  .tb-bar { grid-column: 1 / -1; height: 7px; margin: 2px 0 0; }
  .tb-bar s { height: 3px; }
  .hud-center { flex: none; flex-direction: row; flex-wrap: wrap; justify-content: center; gap: 6px; }
  .wind { min-height: 40px; padding: 4px 10px; gap: 5px; font-size: 14px; }
  .wl { letter-spacing: 1px; }
  /* low or heavy gravity: its badge goes under the wind and takes the place of the WIND label */
  .wind:has(.wg:not(:empty)) { flex-wrap: wrap; justify-content: center; max-width: 130px; padding: 2px 10px; row-gap: 0; line-height: 1.2; }
  .wind:has(.wg:not(:empty)) .wl { display: none; }
  .wind:has(.wg:not(:empty)) .wg { flex-basis: 100%; text-align: center; }
  #hQuit, #hFull { min-height: 40px; padding: 4px 10px; }
  #hFull { min-width: 40px; padding: 0; font-size: 18px; }
  .hud-banner { top: 24%; padding: 0 16px; font-size: 26px; line-height: 1.1; }
  .hud-note { top: calc(24% + 64px); padding: 0 16px; font-size: 14px; }
  /* the tip stays in the middle, between the two sides' tanks */
  .hud-tip { bottom: 66px; width: min(440px, 56%); white-space: normal; text-align: center; font-size: 12px; line-height: 1.3; text-shadow: 0 1px 4px rgba(0,0,0,.9); }
  /* Training Grounds: the score line goes under the course name, the lab switches get a row of their own */
  .rbar .rb-row { grid-column: 1 / -1; flex-wrap: wrap; gap: 0 8px; margin-top: 2px; font-size: 12px; }
  .range-ctl { position: absolute; top: calc(100% + 4px); left: 0; right: 0; max-width: none; gap: 4px; }
  .range-ctl button { min-height: 36px; }
  .hud:has(.range-ctl) .hud-banner { top: 38%; }
  .hud:has(.range-ctl) .hud-note { top: calc(38% + 64px); }

  .hud-bottom { left: 6px; right: 6px; bottom: 6px; gap: 6px; }
  .hb-move { gap: 4px; padding: 4px; border-radius: 12px; }
  .mv { width: 44px; height: 44px; border-radius: 10px; font-size: 18px; }
  .fuel { width: 36px; }
  .fl { font-size: 12px; letter-spacing: 0; }
  .fb { height: 6px; margin-top: 3px; }
  .hb-weapons { flex-wrap: nowrap; gap: 4px; min-width: 0; }
  .wcard { flex: 0 1 84px; width: auto; min-width: 54px; padding: 2px 3px; border-radius: 10px; container-type: inline-size; }
  .wcard .wk { display: none; }
  .wcard.armed { transform: translateY(-3px); }
  .wcard .won { top: -7px; right: -4px; padding: 0 5px; font-size: 12px; }
  .wi { font-size: 19px; line-height: 22px; }
  .wn { line-height: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .wq { margin-top: 0; font-size: 12px; line-height: 14px; }
  .wcd { border-radius: 8px; font-size: 20px; }
  /* too narrow for a name: the icon and the word count are enough */
  @container (max-width: 66px) { .wn { display: none; } .wi { font-size: 22px; line-height: 26px; } }
  /* angle and power: number and slider side by side, FIRE beside them */
  .hb-aim { grid-template-columns: auto minmax(60px, 100px) auto; grid-template-rows: auto auto; align-items: center; gap: 2px 6px; padding: 4px 4px 4px 8px; border-radius: 12px; }
  .aim-read, .sl { display: contents; }
  .aim-read span { grid-column: 1; grid-row: 1; font-size: 12px; white-space: nowrap; }
  .aim-read span:last-child { grid-row: 2; }
  .aim-read b { font-size: 15px; }
  .sl > span { display: none; }
  .sl input { grid-column: 2; grid-row: 1; width: 100%; height: 22px; margin: 0; }
  .sl input#hPowR { grid-row: 2; }
  /* each slider reaches out past its thin row (up for angle, down for power), so a finger needn't be exact */
  .sl input#hAngR { box-sizing: content-box; padding-top: 14px; margin-top: -14px; }
  .sl input#hPowR { box-sizing: content-box; padding-bottom: 10px; margin-bottom: -10px; }
  .fire-btn { grid-column: 3; grid-row: 1 / 3; width: 70px; height: 46px; aspect-ratio: auto; border-radius: 50%; box-shadow: 0 4px 0 #7a0c18, 0 0 18px rgba(255,60,80,.5); }
  .fire-btn .fb-t { font-size: 18px; }
  .fire-btn small { font-size: 12px; }

  /* battle end: the whole card fits a short screen (and scrolls inside if a long tip ever overflows) */
  .be-card { min-width: 0; width: min(560px, calc(100vw - 16px)); max-height: calc(100% - 16px); overflow-y: auto; padding: 10px 18px 12px; border-radius: 18px; }
  .be-title { font-size: 34px; line-height: 1.15; }
  .be-sub { font-size: 14px; }
  .be-rewards { gap: 6px; margin: 8px 0 10px; }
  .be-rewards div { padding: 5px 4px; border-radius: 10px; }
  .be-rewards span { font-size: 20px; line-height: 1.2; }
  .be-rewards b { font-size: 18px; }
  .be-rewards small { font-size: 12px; line-height: 1.25; }
  .be-btns .btn { min-width: 130px; min-height: 44px; }
}
/* A narrow upright window (a touch screen is asked to turn sideways instead): the result card fits. */
@media (orientation: portrait) and (max-width: 600px) {
  .battle-end { padding: 12px; }
  .be-card { min-width: 0; width: 100%; max-width: 420px; max-height: 100%; overflow-y: auto; padding: 18px 14px; }
  .be-title { font-size: 44px; }
  .be-rewards { grid-template-columns: repeat(2, 1fr); gap: 8px; margin: 14px 0; }
  .be-rewards small { font-size: 12px; }
  .be-btns .btn { flex: 1; min-width: 0; min-height: 48px; }
}
/* small phones sideways: no room for the sliders, so the cards keep theirs; dragging still aims */
@media (max-height: 500px) and (max-width: 700px) and (orientation: landscape) {
  .sl input { display: none; }
  .hb-aim { grid-template-columns: auto auto; }
  .fire-btn { grid-column: 2; }
}

/* ---------- end BATTLE ---------- */
