/* Mobile and touch layer. Loaded last, so it refines site.css / tracker.css / app.css
   without rewriting them: touch-sized targets, a compact hero, a sticky swipeable tab bar,
   bottom-sheet dialogs, press feedback and safe-area handling. */

:root {
  --tap: 2.75rem;                       /* 44px: the minimum comfortable touch target */
  --radius: 10px;
  --ease: cubic-bezier(.2, .7, .2, 1);
}
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; -webkit-tap-highlight-color: transparent; }
body { overflow-wrap: anywhere; overscroll-behavior-y: none; padding-bottom: env(safe-area-inset-bottom, 0px); }
button, a, summary, select, label, input[type=checkbox], input[type=radio] { touch-action: manipulation; }
img, svg, canvas { max-width: 100%; }

/* ---- touch devices and narrow screens: bigger hit areas, 16px fields (iOS zooms below that) */
@media (pointer: coarse), (max-width: 44rem) {
  :root { --btn-h: var(--tap); }
  .pe input, .pe select, .pe textarea, .pe-crop input, .pe-crop select, .app-dialog input, .app-dialog select, .app-dialog textarea {
    font-size: 1rem; min-height: var(--tap); padding: .45rem .7rem; border-radius: 8px;
  }
  .pe textarea { min-height: 5.5rem; }
  .pe input[type=checkbox], .pe input[type=radio] { width: 1.4rem; height: 1.4rem; min-height: 0; accent-color: var(--sodium); }
  .pe-check, label:has(> input[type=checkbox]) { min-height: var(--tap); }
  .pe input.sm { width: 5.5rem; }
  .pe-t input.st, .tr-stats input { min-height: 2.5rem; }
  .pe button, .pe .app-btnlink, .pe-crop button { font-size: 1rem; padding-inline: 1.1rem; border-radius: 8px; }
  .pe .pe-x, .pe button.pe-x:not(.fname):not(.xp-btn):not(.fc-close) { min-width: var(--tap); }
  .pe .app-gear li button.pe-x { min-width: 2.5rem; min-height: 2.5rem; }
  .pe-row { gap: .6rem; }
  .app-acts { gap: .6rem; }
  summary { min-height: var(--tap); display: flex; align-items: center; }
  .bench-panel summary, .app-more summary { min-height: var(--tap); }
  .tr-fighter summary { min-height: var(--tap); }
  .pe-t td, .pe-t th { padding: .5rem .5rem; }
  .fname, .sk { padding-block: .25rem; }
}

/* ---- press feedback for touch (there is no hover on a phone) */
@media (hover: none) {
  .pe button, .pe .app-btnlink, .app-tile, .tr-tile, .app-tabs a, .jump a { transition: transform .12s var(--ease), background-color .12s, filter .12s; }
  .pe button:active, .pe .app-btnlink:active { transform: scale(.97); filter: brightness(.9); }
  .app-tile:active, .tr-tile:active { transform: scale(.985); background: var(--panel-2); }
  .app-tabs a:active { background: var(--panel-2); }
  .tr-tile:hover, .app-tile:hover { background: var(--panel); }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

/* ---- phone layout */
@media (max-width: 44rem) {
  body { font-size: 1rem; line-height: 1.55; }
  .wrap { padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }

  /* a compact hero: the title should not cost a whole screen */
  .chevrons { height: 6px; background: repeating-linear-gradient(-45deg, var(--on-sodium) 0 6px, var(--sodium) 6px 12px); }
  .hero .wrap { padding-block: .3rem; gap: .25rem; }
  .hero h1 { font-size: clamp(1.5rem, 7.5vw, 2rem); }
  .hero .kicker { font-size: .85rem; }
  h2 { font-size: clamp(1.5rem, 7vw, 2rem); margin-bottom: 1rem; }
  main { gap: 2.25rem; padding-block: 1.25rem 3rem; }
  .app { padding-block: 1rem 3rem; }
  .pe { gap: 1.5rem; }
  #tab { gap: 2rem; }

  /* the top bar sticks, and the campaign tabs become one swipeable row */
  .jump.app-topnav { background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); }
  .jump.app-topnav ul { display: grid; grid-template-columns: 1fr auto; gap: 0 .5rem; flex-wrap: nowrap; justify-content: stretch; padding-block: 0; overflow: visible; }
  .app-topnav li.app-navtabs { grid-column: 1 / -1; grid-row: 2; order: 0; flex-basis: auto; min-width: 0; margin: 0 -16px; position: relative; display: block; }
  .app-topnav li.app-navtabs::after { content: ""; position: absolute; inset: 0 0 0 auto; width: 2rem; pointer-events: none; background: linear-gradient(90deg, transparent, var(--bg)); }
  .app-topnav .app-tabs { flex-wrap: nowrap; justify-content: flex-start; overflow-x: auto; overscroll-behavior-x: contain; scroll-snap-type: x proximity;
    scrollbar-width: none; gap: .15rem; padding-inline: 12px 2rem; border-top: 1px solid var(--line); }
  .app-topnav .app-tabs::-webkit-scrollbar { display: none; }
  .app-topnav .app-tabs a { flex: none; scroll-snap-align: center; display: inline-flex; align-items: center; min-height: var(--tap); padding: 0 .8rem; font-size: 1rem; white-space: nowrap; }
  .jump.app-topnav li:first-child { margin: 0; }
  .jump a.home { min-height: var(--tap); padding-right: .6rem; }
  .jump a.home .home-t, .jump a.home span { display: inline; }
  .app-topnav #userbtn { min-width: var(--tap); justify-content: center; }
  section { scroll-margin-top: 7rem; }

  /* cards and lists: full-bleed feel, rounded, comfortably spaced */
  .app-tiles, .tr-tiles { grid-template-columns: minmax(0, 1fr); gap: .75rem; }
  .app-tile, .tr-tile, .tr-battle, .tr-gang, .pe-gang, .app-link, .fighter, .app-side, .app-part { border-radius: var(--radius); }
  .app-tile { padding: 1rem 1.1rem; min-height: 5rem; align-content: center; }
  .tr-tile { min-height: 5.5rem; }
  .fighter { padding: .9rem .75rem; }
  .pe-gang, .tr-gang, .tr-battle { padding: .9rem .8rem 1.1rem; }
  .app-form, .app-inline { max-width: none; }
  .app-inline { grid-template-columns: minmax(0, 1fr); }
  .app-card { max-width: none; }
  .app-link .pe-row { flex-wrap: wrap; }
  .app-link input { flex: 1 1 100%; }

  /* the page heading rows: let the button drop under the title instead of squeezing it */
  .app-th, .app-headrow, .tr-head { flex-wrap: wrap; }
  .pe-row > button:only-child, .app-form > .pe-row > button { flex: 1 1 auto; }

  /* wide tables scroll sideways with a visible edge, rather than breaking the page */
  .pe-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; margin-inline: -.8rem; padding-inline: .8rem; scrollbar-width: thin; }
  .pe-t th { white-space: nowrap; }

  /* stat lines and sheets stay readable */
  .sheet, .sheet.four { gap: .6rem .75rem; }
  .sheet dd { font-size: 1.35rem; }
  .facts div { grid-template-columns: 6.5rem minmax(0, 1fr); }
  .c b { font-size: 1.1rem; }
  .c span { font-size: .78rem; }
  .wp { grid-template-columns: minmax(0, 1fr) repeat(5, 2.4rem); }
}

/* ---- dialogs become bottom sheets on a phone */
@media (max-width: 44rem) {
  dialog.app-dialog, dialog.fc-pop, dialog.pe-crop, dialog.app-equipdlg {
    position: fixed; inset: auto 0 0 0; margin: 0; width: 100%; max-width: 100%;
    max-height: min(92dvh, 100dvh - env(safe-area-inset-top, 0px) - .5rem); overflow-y: auto; overscroll-behavior: contain;
    border-radius: 16px 16px 0 0; border-inline: 0; border-bottom: 0;
    padding-bottom: calc(1.25rem + env(safe-area-inset-bottom, 0px));
  }
  dialog.app-dialog[open], dialog.fc-pop[open], dialog.pe-crop[open] { animation: sheet-up .22s var(--ease); }
  dialog.app-dialog::before { content: ""; display: block; width: 2.5rem; height: 4px; border-radius: 2px; background: var(--line); margin: -.5rem auto .75rem; }
  .fc-pop .fc-close { min-width: var(--tap); min-height: var(--tap); }
  .app-dialog .pe-row { position: sticky; bottom: calc(-1.25rem - env(safe-area-inset-bottom, 0px)); background: var(--panel); padding-block: .6rem; }
  .app-dialog .pe-row button { flex: 1 1 8rem; }
}
@keyframes sheet-up { from { transform: translateY(2rem); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---- landscape phones: keep the hero and bars short */
@media (max-height: 30rem) and (orientation: landscape) {
  .hero .wrap { padding-block: .5rem; }
  .jump { position: static; }
}

/* ---- a visible, finger-and-keyboard friendly focus ring */
:focus-visible { outline: 2px solid var(--sodium); outline-offset: 2px; }
.pe input:focus, .pe select:focus, .pe textarea:focus { border-color: var(--sodium); outline: 2px solid color-mix(in srgb, var(--sodium) 45%, transparent); outline-offset: 0; }

/* ---- stacked "card per row" tables (the Players list): compact, label and value on one line */
@media (max-width: 40rem) {
  .app-users tr { padding: .5rem 0; }
  .app-users td, .pe .app-users td { padding: .1rem 0; min-height: 0; }
  .app-users td[data-l]:not([data-l="Username"]) { display: flex; align-items: center; gap: .4rem; }
  .app-users td[data-l]:not([data-l="Username"])::before { margin: 0; }
  .app-users td.app-acts { padding-top: .5rem; }
  .app-users td.app-acts button { flex: 1 1 auto; }
}

/* ================= fighter cards, gang header and battle pages (phone) ================= */
@media (max-width: 44rem) {
  /* gang header: picture and name side by side, "All gangs" on its own row below (it used to push the page 120px too wide) */
  .app-ganghead { flex-wrap: wrap; gap: .75rem 1rem; }
  .app-ganghead h2, .app-ganghead .app-gangname { flex: 1 1 8rem; min-width: 0; overflow-wrap: anywhere; font-size: clamp(1.6rem, 8vw, 2.2rem); }
  .app-gangpicwrap, .pe .app-ganghead button.app-gangpicbtn, .app-ganghead img.app-gangpicview { width: 4.5rem; height: 4.5rem; }
  .app-gangpicwrap { margin: .4rem 0 0 .4rem; }

  /* fighter cards: the stats scan as two tidy rows, details breathe, wide content never forces sideways scroll */
  .fighters { grid-template-columns: minmax(0, 1fr); gap: .9rem; }
  .fh { gap: .75rem; align-items: flex-start; }
  .fh .roundel { width: 3.5rem; height: 3.5rem; }
  h4 { font-size: 1.35rem; }
  .cost b { font-size: 1.4rem; }
  .foot { font-size: 1rem; gap: .35rem; }
  .foot p { line-height: 1.35; }
  .app-fboxes { grid-template-columns: minmax(0, 1fr); }
  .app-fbox { padding: .5rem; border-radius: var(--radius); }
  .app-skillpick select, .app-skillpick input, #addtype, #addrecruit, .app-buy select { flex: 1 1 100%; max-width: none; }
  .app-ftools { flex-wrap: wrap; }
  .xp-btn, .pe button.xp-btn { min-height: var(--tap); }

  /* battle page: section headings and folds */
  .app-fold { margin-bottom: 1.5rem; }
  .app-fold > summary { flex-wrap: wrap; gap: .1rem .5rem; min-height: var(--tap); }
  .app-fold .app-foldh { font-size: clamp(1.6rem, 8vw, 2rem); white-space: nowrap; }
  .app-fold > summary small { flex: 1 1 100%; padding-left: 1.6rem; line-height: 1.3; }
  .app-vs h2 { font-size: clamp(1.4rem, 7vw, 1.8rem); }
  .app-vs .app-th, .app-battlehead { flex-wrap: wrap; gap: .5rem; }

  /* the crews and the game: fighter rows are real touch targets */
  .app-ftiles { gap: .5rem; }
  .app-ftile { min-height: 3.25rem; padding-block: .5rem; border-radius: 8px; }
  .app-ftile b { line-height: 1.25; }
  .app-side { padding: .9rem .8rem; }
  .app-fpick { min-height: var(--tap); display: flex; align-items: center; gap: .6rem; }
  .app-fpick input { width: 1.4rem; height: 1.4rem; flex: none; accent-color: var(--sodium); }
  .app-orow span { flex-basis: 100%; }

  /* results: big segmented buttons, one per row when the names are long */
  .app-seg { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 9rem), 1fr)); gap: .5rem; }
  .app-segopt span { min-height: var(--tap); display: flex; align-items: center; justify-content: center; text-align: center; padding: .4rem .75rem; border-radius: 8px; }
  .app-segopt input { width: 100%; height: 100%; }
  .app-rewcard { border-radius: var(--radius); }
  #main form .pe-row > button[type=submit], #main form > button[type=submit] { width: 100%; }
}
@media (max-width: 44rem) {
  /* pop-up forms: a dropdown gets its own full row so its text isn't cut off beside the button */
  .app-dialog .pe-row select, .app-dialog .app-pick select, .fc-pop .pe-row select { flex: 1 1 100%; width: 100%; }
}

/* ================= post-cycle, tables and forms (phone) ================= */
@media (max-width: 44rem) {
  /* tables fit the screen: the first column may wrap instead of forcing the numbers off the right edge */
  .pe-t td:first-child { white-space: normal; }
  .app-facts th { white-space: nowrap; width: auto; padding-right: 1rem; vertical-align: top; }   /* row labels (Attacker, Defender, Stake) stay on one line */
  .app-facts { margin-bottom: 1.5rem; }
  .pe-t { font-size: 1rem; }
  .pe-t td.num, .pe-t td.app-num { white-space: nowrap; }   /* numbers stay on one line; text cells wrap */
  .pe-t select { min-width: 0; max-width: 100%; }
  .pe-t td select, .pe-t td input { width: 100%; }
  /* section headings get room above them (they ran into the table or text before) */
  .pe h2:not(:first-child), #main section > h2:not(:first-child) { margin-top: 2rem; }
  .pe h3 { margin-top: 1.75rem; }
  .pe h4 { margin-top: 1.25rem; }
  /* small icon buttons in rows (move up/down, remove) get a proper target */
  .app-ftools .pe-x, .app-ftools button.pe-add { min-width: var(--tap); }
  .pe-add { min-height: var(--tap); }
  /* inline add-buttons read as buttons, not loose text */
  .pe button.pe-add:not(.fname):not(.xp-btn):not(.fc-close) { padding-inline: 1rem; }
}
@media (max-width: 44rem) {
  #post > section + section, #post section + section { margin-top: 2.25rem; }
}

/* ================= overview: cycle tracker and Ascendancy card ================= */
/* (desktop keeps its order: heading, Ascendancy, dates, tracker; the phone puts the tracker first) */
.app-cycle { display: flex; flex-direction: column; }
.app-cycle > h2 { order: 0; }
.app-cycle > .app-ascend { order: 1; }
.app-cycle > .pe-note { order: 2; }
.app-cycle > .app-sched { order: 3; }
.app-herohome, .app-herouser { display: none; }

@media (max-width: 44rem) {
  /* the hero carries the Campaigns link and the account button, and scrolls away with the title; only the tabs stay pinned */
  .app-herorow { display: flex; align-items: center; gap: .25rem; margin-inline: -.6rem; }
  .app-herorow h1 { flex: 1 1 auto; min-width: 0; text-align: left; }
  .app-herohome, .app-herouser { flex: none; display: inline-flex; align-items: center; justify-content: center; width: var(--tap); height: var(--tap); padding: 0; color: var(--on-sodium); background: none; border: 0; cursor: pointer; border-radius: 10px; }
  .app-herohome svg { width: 1.7rem; height: 1.7rem; }
  .app-herouser svg { width: 1.7rem; height: 1.7rem; }
  .app-herohome:active, .app-herouser:active { background: rgb(0 0 0 / .12); }
  .app-herorow:has(> h1:first-child) h1 { margin-left: .6rem; }
  .jump.app-topnav li:not(.app-navtabs) { display: none; }                 /* Campaigns and the account button moved into the hero */
  .jump.app-topnav:not(:has(.app-navtabs)) { display: none; }              /* pages without tabs have no bar at all */
  .app-topnav li.app-navtabs { grid-row: 1; }

  /* the cycle tracker: one row, just the cycle numbers; the phase shows as the colour of each box's top edge */
  .app-cycle > h2.app-cyc-d { display: none; }
  #main .app-cycle > h2.app-cyc-m { order: -1; display: block; font-size: 1.5rem; margin: 0 0 .7rem; }
  .app-cycle > .app-sched { display: none; }   /* the 1-7 cycle tracker is desktop only; the heading already says which cycle and phase */
  .app-sched li { padding: .55rem 0; min-height: var(--tap); align-content: center; border-radius: 6px; }
  .app-sched li b { font-size: 1.2rem; }
  .app-sched li span, .app-sched li small { display: none; }
  .app-cycle > .app-ascend { order: 1; }
  .app-cycle > .pe-note { order: 2; margin: .6rem 0 0; }

  /* Ascendancy: two pills with this cycle's wins; the ascendant side is highlighted and says so */
  .app-ascend { margin: .6rem 0 0; display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; align-items: stretch; }
  .asc-pill { align-content: start; }
  .asc-pill small.ghost { visibility: hidden; }
}
.app-cyc-m { display: none; }
.asc-pill { --tone: var(--muted); display: flex; align-items: baseline; gap: .45rem; flex-wrap: wrap; padding: .5rem .75rem; background: var(--panel); border: 2px solid transparent; border-radius: 10px;
  font-family: var(--label); text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.asc-pill.o { --tone: #5aa0e6; } .asc-pill.c { --tone: #e0623e; }
.asc-pill b { font-size: 1.6rem; line-height: 1; letter-spacing: 0; color: var(--tone); }
.asc-pill span { font-size: .95rem; }
.asc-pill small { flex-basis: 100%; font-size: .72rem; font-weight: 700; letter-spacing: .1em; color: var(--tone); }
.asc-pill small.ghost { display: none; }
.asc-pill.now { border-color: var(--tone); background: color-mix(in srgb, var(--tone) 16%, var(--panel)); color: var(--ink); }
@media (min-width: 44.01rem) { .app-ascend { display: flex; gap: .6rem; margin: .25rem 0 .75rem; } .asc-pill small { flex-basis: auto; } }

/* ================= Territories: collapsible cards, ruined state ================= */
.app-tcard > summary { list-style: none; cursor: pointer; }
.app-tcard > summary::-webkit-details-marker { display: none; }
.app-tcard > summary header { align-items: center; }
.app-tcard[open] > summary { margin-bottom: .4rem; }
.app-badge.ruined { background: #7a1f1f; color: #fff; padding: .1rem .5rem; border-radius: 4px; font-weight: 700; }
.app-tcard.is-ruined { border-left-color: #c0432e; background: color-mix(in srgb, #7a1f1f 14%, var(--panel)); }
.app-tcard.is-ruined .app-tline, .app-tcard.is-ruined .app-teffect { opacity: .6; }
.app-tcard.is-ruined .app-truined { border: 1px solid #c0432e; background: color-mix(in srgb, #7a1f1f 22%, var(--panel-2)); }
.app-tcard.is-ruined .app-truined h4 { color: #ff9a85; }
@media (max-width: 44rem) {
  .app-tcards { grid-template-columns: minmax(0, 1fr); gap: .5rem; }
  .app-tcard { padding: .25rem .9rem; border-radius: 0 var(--radius) var(--radius) 0; }
  .app-tcard > summary { min-height: var(--tap); display: flex; align-items: center; gap: .5rem; }
  .app-tcard > summary::before { content: '▸'; color: var(--sodium); font-size: 1.1rem; flex: none; transition: transform .15s; }
  .app-tcard[open] > summary::before { transform: rotate(90deg); }
  .app-tcard > summary header { flex: 1; min-width: 0; }
  .app-tcard[open] { padding-bottom: .8rem; }
}
.pe .app-tcard h3 { margin: 0; }
.app-tcard.is-ruined .app-truined .app-tline { opacity: 1; }


/* ================= gang details: two columns (House, Allegiance, Player, Rating | Reputation, Stash, Meat, Scavenging, Wealth) ================= */
.app-factcols { gap: 0 2.5rem; }
.app-factcol { min-width: 0; }
@media (max-width: 44rem) {
  .app-facts2.app-factcols { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 1rem; }   /* stays two columns on a phone */
  .app-factcols .app-fact { flex-wrap: wrap; justify-content: space-between; align-items: baseline; gap: 0 .5rem; padding: .45rem 0; }
  .app-factcols .app-fact span { font-size: .9rem; }
  .app-factcols .app-fact b { text-align: right; font-size: 1.05rem; overflow-wrap: anywhere; margin-left: auto; }
  .app-factcols .app-fact .pe-add { min-height: 2rem; margin-top: .25rem; }
}

/* the Variant / Path line is longer text: smaller, so it wraps less */
.app-factcols .app-fact.small b { font-size: .85rem; font-weight: 600; line-height: 1.25; }

/* ================= Account: identity card, grouped settings, clear Log out ================= */
.app-dialog .app-close { flex: none; width: var(--tap, 2.75rem); height: var(--tap, 2.75rem); display: grid; place-items: center; padding: 0; border: 0; border-radius: 50%; background: var(--panel-2); color: var(--ink); cursor: pointer; }
.app-dialog .app-close svg { width: 1.1rem; height: 1.1rem; }
.app-dialog .app-close:hover, .app-dialog .app-close:focus-visible { background: var(--line); }
.app-ident { display: flex; align-items: center; gap: .9rem; margin: .25rem 0 .25rem; }
.app-avatar { flex: none; width: 3.6rem; height: 3.6rem; border-radius: 50%; display: grid; place-items: center; background: var(--sodium); color: var(--on-sodium); font-family: var(--display); font-size: 1.7rem; line-height: 1; }
.app-ident div { display: grid; gap: .05rem; min-width: 0; }
.app-ident b { font-family: var(--label); font-size: 1.4rem; line-height: 1.15; overflow-wrap: anywhere; }
.app-ident small { color: var(--muted); font-family: var(--label); font-size: 1rem; }
.app-badge.adm { justify-self: start; margin-top: .25rem; padding: .1rem .5rem; border-radius: 4px; background: var(--panel-2); color: var(--sodium); font-weight: 700; }
.app-card2 { margin: .9rem 0 0; padding: 1rem; background: color-mix(in srgb, var(--bg) 60%, transparent); border: 1px solid var(--line); border-radius: 12px; max-width: none; }
.app-card2 h3 { margin: 0 0 .1rem; font-size: .95rem; color: var(--muted); }
.app-card2 .pe-f small { line-height: 1.35; }
.app-card2 .pe-row button { width: 100%; }
.app-pwbox summary { display: flex; align-items: center; justify-content: space-between; margin: 0; min-height: 2.75rem; padding: 0; color: var(--ink); font-family: var(--label); font-weight: 700; font-size: 1.05rem; cursor: pointer; list-style: none; }
.app-pwbox summary::-webkit-details-marker { display: none; }
.app-pwbox summary::after { content: '›'; font-size: 1.5rem; line-height: 1; color: var(--muted); transition: transform .15s; }
.app-pwbox[open] summary::after { transform: rotate(90deg); }
.app-pwbox[open] summary { margin-bottom: .4rem; }
.app-linkrow { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin: .9rem 0 0; padding: .8rem 1rem; background: color-mix(in srgb, var(--bg) 60%, transparent); border: 1px solid var(--line); border-radius: 12px; color: var(--ink); text-decoration: none; }
.app-linkrow span { display: grid; gap: .1rem; min-width: 0; }
.app-linkrow b { font-family: var(--label); font-size: 1.05rem; }
.app-linkrow small { color: var(--muted); font-size: .85rem; line-height: 1.3; }
.app-linkrow i { font-style: normal; font-size: 1.5rem; color: var(--muted); }
.app-linkrow:hover, .app-linkrow:focus-visible { border-color: var(--sodium); }
.app-dlg-foot { border-top: 0; padding-top: 0; margin-top: .9rem; }
.app-dlg-foot .app-logout, .pe .app-dlg-foot .app-btnlink.app-logout { width: 100%; min-height: var(--tap, 2.75rem); border: 1px solid #c0432e; color: #f59a7a; background: none; border-radius: 10px; }
.app-dlg-foot .app-logout:hover, .app-dlg-foot .app-logout:focus-visible { background: color-mix(in srgb, #7a1f1f 25%, transparent); }
.app-dialog .app-card2 .pe-row { position: static; background: none; padding-block: 0; }   /* not the sticky action row of other sheets */
.app-linkrow small { font-family: var(--label); }

/* ================= Messages: a chat (phone and desktop) ================= */
.app-chat { padding-bottom: 8rem; }                          /* room for the pinned composer */
.app-chat > h2 { display: none; }
.app-chat .app-to > span, .app-chat .app-body > span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }   /* labels stay for screen readers */

/* the composer: the text box on top, then the "To" drop-down and Send on one line, pinned to the bottom of the screen
   (as wide as the page on a desktop) */
.app-chat #msgform { position: fixed; inset: auto 0 0 0; z-index: 8; max-width: none; margin: 0;
  padding: .6rem max(16px, calc((100vw - 68rem) / 2 + 16px), env(safe-area-inset-right)) calc(.6rem + env(safe-area-inset-bottom, 0px)) max(16px, calc((100vw - 68rem) / 2 + 16px), env(safe-area-inset-left));
  background: var(--panel); border-top: 1px solid var(--line); box-shadow: 0 -6px 18px rgb(0 0 0 / .35);
  display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: .5rem; align-items: center; }
.app-chat #msgform .app-body { grid-column: 1 / -1; grid-row: 1; margin: 0; }
.app-chat #msgform textarea { height: 2.75rem; min-height: 2.75rem; max-height: 7rem; resize: none; width: 100%; line-height: 1.3; }
.app-chat #msgform .app-to { grid-column: 1; grid-row: 2; margin: 0; min-width: 0; }
.app-chat #msgform .app-to select { width: 100%; }
.app-chat #msgform .pe-row { display: contents; }
.app-chat #msgform .pe-row button { grid-column: 2; grid-row: 2; }
.app-chat #msgform .app-msg { grid-column: 1 / -1; grid-row: 3; margin: 0; font-size: .9rem; }

/* the conversation: oldest at the top, newest at the bottom, as bubbles */
.app-chat .app-msgs { display: flex; flex-direction: column-reverse; gap: .5rem; margin: 0; }
.app-chat .app-msgs li { max-width: min(88%, 40rem); align-self: flex-start; border-left: 0; border-radius: 14px 14px 14px 4px; padding: .55rem .8rem; }
.app-chat .app-msgs li.mine { align-self: flex-end; border-radius: 14px 14px 4px 14px; background: color-mix(in srgb, var(--sodium) 18%, var(--panel)); }
.app-chat .app-msgs li.unread { box-shadow: inset 3px 0 0 var(--sodium); }
.app-chat .app-msghead { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0 .5rem; }
.app-chat .app-msghead small { color: var(--muted); font-size: .78rem; }
.app-chat .app-msgs p { margin: .2rem 0 0; }
.app-chat .pe-note { text-align: center; }

.asc-pill.next { border-color: var(--tone); border-style: dashed; }   /* post-cycle: the side that takes Ascendancy next cycle */

/* ================= Battle results: the credits total and the Territory outcome ================= */
.app-rtots { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .5rem; margin: .4rem 0 .6rem; }
.app-rtot { display: grid; gap: .05rem; padding: .5rem .75rem; background: var(--bg); border-radius: 10px; font-family: var(--label); }
.app-rtot span { font-size: .85rem; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.app-rtot b { font-size: 2rem; line-height: 1.05; color: var(--sodium); }
.app-rtot.rep b { color: var(--ink); }
.app-rtot small { font-size: .8rem; color: #f59a7a; font-weight: 700; }
.app-terrres { margin: .9rem 0; padding: .8rem 1rem; border-radius: 12px; background: var(--panel); border-left: 5px solid var(--line); font-family: var(--label); }
.app-terrres .k { display: block; font-size: .85rem; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); font-weight: 700; }
.app-terrres p { margin: .15rem 0 0; font-size: 1.25rem; line-height: 1.25; }
.app-terrres small { color: var(--muted); font-size: .95rem; }
.app-terrres p small { font-size: .85em; }
.app-terrres.taken { border-left-color: #6cb4ff; background: color-mix(in srgb, #6cb4ff 12%, var(--panel)); }
.app-terrres.taken .k { color: #6cb4ff; }
.app-terrres.by-attacker { border-left-color: var(--sodium); background: color-mix(in srgb, var(--sodium) 14%, var(--panel)); }
.app-terrres.by-attacker .k { color: var(--sodium); }
/* table cells wrap at spaces, never inside a word */
.pe-t td, .pe-t th { overflow-wrap: normal; word-break: normal; }
.app-incsum td:first-child { min-width: 5.2rem; }
.app-incsum select { min-width: 5.5rem; }

.app-rtots.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }   /* Damnation: Meat, Scavenging, Reputation */
.app-rtots.three .app-rtot { padding: .5rem .6rem; }
.app-rtots.three .app-rtot span { font-size: .78rem; }
.app-rtots.three .app-rtot b { font-size: 1.7rem; }
.app-rtots.three .app-rtot:not(.rep) b { color: #e0623e; }

/* ================= Battle: step tracker and compact matchup ================= */
.app-bsteps ol { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); gap: .25rem; list-style: none; margin: .5rem 0 1.1rem; padding: 0; }
.app-bsteps a { display: grid; justify-items: center; gap: .2rem; padding: .45rem .1rem .3rem; border-top: 3px solid var(--line); text-decoration: none; color: var(--muted);
  font-family: var(--label); font-size: .78rem; font-weight: 600; letter-spacing: .05em; text-transform: uppercase; min-height: var(--tap, 2.75rem); }
.app-bsteps i { width: 1.6rem; height: 1.6rem; display: grid; place-items: center; border-radius: 50%; border: 2px solid var(--line); font-style: normal; font-size: .85rem; font-weight: 700; line-height: 1; }
.app-bsteps li.done a { border-top-color: var(--sodium); }
.app-bsteps li.done i { background: var(--sodium); border-color: var(--sodium); color: var(--on-sodium); }
.app-bsteps li.now a { border-top-color: var(--sodium); color: var(--ink); }
.app-bsteps li.now i { border-color: var(--sodium); color: var(--sodium); box-shadow: 0 0 0 3px color-mix(in srgb, var(--sodium) 25%, transparent); }
#scenario, #crews, #log, #results, #approvals { scroll-margin-top: 7rem; }
@media (max-width: 44rem) {
  /* Attacker and Defender side by side, the Stake (and anything else) full width underneath */
  .app-vs .app-facts, .app-fold .app-facts { display: block; }
  .app-vs .app-facts tbody, .app-fold .app-facts tbody { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .5rem; }
  .app-facts tr { display: block; padding: .55rem .75rem; background: var(--panel); border-radius: 10px; border: 0; }
  .app-facts tr:nth-child(n+3) { grid-column: 1 / -1; }
  .app-facts th, .app-facts td { display: block; padding: 0; border: 0; }
  .app-facts th { font-size: .78rem; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); padding: 0 0 .1rem; width: auto; }
  .app-facts td { font-size: 1.05rem; line-height: 1.25; }
  .app-vs .app-facts tr:nth-child(1) { border-left: 4px solid var(--cawdor, var(--sodium)); }   /* (Attacker and Defender only) */
  .app-vs .app-facts tr:nth-child(2) { border-left: 4px solid var(--delaque, var(--line)); }
}
