/* mobile-win.css — phones and tablets (2026-11-14); see mobile.js for the three screen kinds and their media queries:
   compact @media (max-width: 1099px) · phone @media (max-width: 699px), (max-height: 500px) · touch @media (pointer: coarse).
   Every rule here sits inside one of those, so a desktop with a mouse at 1100 px or wider is unchanged.
   This file: the windows — the big window #win and everything drawn in it (buildings, Shop, Reports, Mail, the march
   form…), the small window #pop over it, the front window #frontpop (Lucky Charm, what an item gave), the item tips. */

/* ================================================================== touch: fingers, not a mouse (iPads too) */
@media (pointer: coarse) {
  /* buttons, tabs and links in windows big enough for a finger, a little apart */
  #win button:not(.win-close), .pop button:not(.win-close) { min-height: 40px; }
  #win button:not(.win-close):not(.move-btn):not(.demo-btn), .pop button:not(.win-close) { min-width: 40px; }
  #win button.small:not(.win-close), .pop button.small:not(.win-close) { min-height: 36px; }
  #win .wtabs, #win .tabs.small { gap: 4px; }
  #win .wtabs button, #win .tabs.small button { min-height: 42px; }
  #win a[href], #win a.lordlink, .pop a[href] { padding-block: 6px; }
  /* typing in a window: 16 px, or iPhones zoom the page in on the box */
  #win input:not([type=checkbox]):not([type=radio]), #win select, #win textarea,
  .pop input:not([type=checkbox]):not([type=radio]), .pop select, .pop textarea { font-size: 16px; min-height: 38px; }
  #win input[type=checkbox], #win input[type=radio], .pop input[type=checkbox], .pop input[type=radio] { width: 22px; height: 22px; }
  /* the close and back buttons: a 44 px place to tap, the round brass knob drawn in its middle */
  #win .win-close, .pop .win-close { width: 44px; height: 44px; margin-top: 4px; border: 0; box-shadow: none; font-size: 16px;
    background: radial-gradient(circle closest-side, #4e443b 0 13px, #c9953e 13.5px 15.5px, #2a180a 16px 17px, transparent 17.5px); }
  #win .win-close:active, .pop .win-close:active { background: radial-gradient(circle closest-side, #a8432c 0 13px, #c9953e 13.5px 15.5px, #2a180a 16px 17px, transparent 17.5px); }
  #win .win-bar, .pop .win-bar { grid-template-columns: 1fr auto 1fr 44px; }
  .win.side .win-bar { grid-template-columns: 1fr auto 1fr 44px; }
  .win.side .win-close { width: 44px; height: 44px; margin-top: 0; font-size: 15px; }
  /* scrolling a window never scrolls (or bounces) the page behind it */
  .win-body, .pop-body, #frontpop-body, .iholds, .qfams, .qlist, .ggrid { overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
  /* the item tips that follow a mouse: on a touch screen they open with a long press (windows.js), in a box that fits */
  .itip { max-width: calc(100vw - 16px); max-height: calc(100vh - 16px); overflow-y: auto; pointer-events: auto; }
  .itip.wide { width: min(620px, calc(100vw - 16px)); }
  /* the (i) marks: a bigger target; their words open in the tip box (windows.js), not as a hover bubble */
  .info, .info-i { width: 24px; height: 24px; }
  .info::after, .info-i::after { display: none !important; }
}

/* ================================================================== compact: a tablet upright, a narrow window */
@media (max-width: 1099px) {
  /* the window takes the view's whole height instead of a desktop's 600 px */
  .win:not(.side) { width: calc(100% - 16px); height: calc(100% - 16px); max-height: calc(100% - 16px); top: 8px; }
  .win:has(.bk) { width: calc(100% - 16px); }
  .pop { width: min(560px, calc(100% - 24px)); }
  .frontpop .pop { min-width: 0; width: min(560px, calc(100vw - 24px)); }
  /* a table wider than its window (windows.js mobWin marks it .m-wide) slides sideways inside its own box, its first
     column staying in sight */
  table.m-wide { display: block; max-width: 100%; overflow-x: auto; overscroll-behavior-x: contain; }
  table.m-wide > tbody > tr > td:first-child, table.m-wide > tr > td:first-child { position: sticky; left: 0; z-index: 1; background: #fffaf0; }
  table.m-wide > tbody > tr > th:first-child, table.m-wide > tr > th:first-child { position: sticky; left: 0; z-index: 1; }
}

/* ================================================================== phone: either way up */
@media (max-width: 699px), (max-height: 500px) {
  /* the big window fills the screen, over the bars, inside the notch and the home bar */
  #win:not(.side) { position: fixed; inset: 0; width: auto; height: auto; max-height: none; transform: none; z-index: 60;
    padding: 0 max(4px, env(safe-area-inset-right)) max(4px, env(safe-area-inset-bottom)) max(4px, env(safe-area-inset-left));
    border-width: 8px 6px; border-image-width: 22px 16px 20px 16px; box-shadow: none; }
  #win:not(.side) > .win-bar { height: 44px; margin: calc(-8px + env(safe-area-inset-top)) 0 2px; grid-template-columns: 44px 1fr auto 1fr 44px; }
  #win:not(.side) > .win-bar::before { content: ''; grid-column: 1; grid-row: 1; }
  #win:not(.side) > .win-bar .win-back { position: static; grid-column: 1; grid-row: 1; margin-top: 0; }
  #win:not(.side) > .win-bar .win-close { margin-top: 0; }
  .win-title { height: 40px; min-width: 0; padding: 6px 8px 0; font-size: 16px; overflow: hidden; text-overflow: ellipsis;
    border-width: 0 22px; border-image-width: 0 22px; align-self: start; }
  #win:not(.side) .win-title { max-width: calc(100vw - 110px); }
  .win-body { margin: 2px 2px 0; padding: 8px 8px; }

  /* the small window over it: across the screen at the top (clear of the keyboard), the window behind dimmed */
  #win > #pop { position: fixed; top: max(6px, env(safe-area-inset-top)); left: max(4px, env(safe-area-inset-left)); right: max(4px, env(safe-area-inset-right));
    width: auto !important; max-height: calc(100% - max(6px, env(safe-area-inset-top)) - max(6px, env(safe-area-inset-bottom))); transform: none; z-index: 70;
    border-width: 8px 6px; border-image-width: 22px 16px 20px 16px; box-shadow: 0 0 0 100vmax rgba(20, 12, 4, .5); }
  #win > #pop > .win-bar { margin-top: -8px; height: 44px; }
  #win > #pop .pop-body { margin: 2px 2px 0; flex: 1; min-height: 0; overflow-y: auto; max-height: none !important; }
  /* the front window (Lucky Charm, what an item gave): the screen's width */
  .frontpop { padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); }
  .frontpop .pop { min-width: 0; width: calc(100% - 8px); max-width: none; max-height: calc(100% - 8px); border-width: 8px 6px; border-image-width: 22px 16px 20px 16px; }
  .frontpop .pop > .win-bar { margin-top: -8px; height: 44px; }
  #frontpop-body { flex: 1; min-height: 0; overflow-y: auto; margin: 2px 2px 0; }
  .ggrid { min-width: 0; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); }

  /* tab rows: one row that slides sideways, the next tab peeking in at the edge to show there are more (windows.js
     brings the open one into sight) */
  #win .wtabs, #win .tabs.small { flex-wrap: nowrap; overflow-x: auto; overflow-y: hidden; scrollbar-width: none; overscroll-behavior-x: contain; }
  #win .wtabs::-webkit-scrollbar, #win .tabs.small::-webkit-scrollbar { display: none; }
  #win .wtabs button, #win .tabs.small button { flex: none; white-space: nowrap; }
  #win .wtabs .act { flex: none; }

  /* the map's tile window: a sheet along the bottom (upright) — the map stays in sight above it */
  #win.side { position: fixed; top: auto; left: 0; right: 0; bottom: 0; width: auto; transform: none; z-index: 60;
    max-height: 62%; padding-bottom: env(safe-area-inset-bottom); border-width: 8px 6px; border-image-width: 22px 16px 20px 16px; }
  #win.side > .win-bar { margin-top: -8px; height: 40px; }
  #win.side .win-body { overflow-y: auto; }
}
/* a phone on its side: the tile window down the right, the bars slimmer */
@media (max-height: 500px) {
  #win.side { top: 0; left: auto; width: min(360px, 48vw); max-height: none; padding-right: env(safe-area-inset-right); }
  #win:not(.side) > .win-bar, #win > #pop > .win-bar, .frontpop .pop > .win-bar { height: 38px; }
  .win-title { height: 34px; padding-top: 4px; line-height: 22px; font-size: 15px; }
  #win:not(.side) > .win-bar .win-close, #win:not(.side) > .win-bar .win-back, #win > #pop .win-close, .frontpop .win-close { height: 38px; }
}
/* ================================================================== a phone upright (narrower than 700 px): one column
   (upright only, 2026-11-20: an iPhone SE on its side is 667 px wide and keeps the side-by-side layouts, mobile-land.css) */
@media (max-width: 699px) and (orientation: portrait) {
  /* side-by-side layouts stack: the barracks' line over its troops, the Rally Spot's limits over its tabs, the
     Quests' list over the quest, the hero's picture over his numbers, Town Hall's two boxes, the forts, the packs */
  .bk, .book, .two, .fortcards, .quest, .ha, .ha-top, .ha-stats, .rp-grid, .sea-row, .mw, .mw-troops { grid-template-columns: minmax(0, 1fr); }
  .bk-line { position: static; }
  .bhead { grid-template-columns: 110px minmax(0, 1fr); gap: 8px; }
  .bhead .pic { height: 100px; }
  .bhead .desc { padding: 6px 8px; font-size: 13px; }
  .igrid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
  .packs { grid-template-columns: repeat(auto-fill, minmax(165px, 1fr)); }
  .hchips, .iholds .hchips { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
  .giftform .gift-names { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .sea-tiles { grid-template-columns: repeat(2, 1fr); }
  .quest { min-height: 0; }
  .qfams { height: 180px; }
  .qlist { min-height: 0; max-height: 220px; }
  .qright { padding: 8px 2px 0; border-left: 0; border-top: 1px solid #d4b47a; }
  /* a troop's (or a fort's) rows of box and buttons wrap under each other */
  .troopcard .count, .fortcard .count { flex-wrap: wrap; }
  .troopcard .count input, .fortcard .count input { flex: 1 1 90px; min-width: 0; }
  .troopcard.unit .tc-pic { width: 56px; height: 56px; }
  .troopcard.unit .tc-pic svg, .troopcard.unit .tc-pic img { max-width: 52px; max-height: 52px; }
  .opt { flex-wrap: wrap; }
  .row { flex-wrap: wrap; }
  .wfoot { flex-wrap: wrap; }
}

/* ================================================================== phone, either way up: no empty rows, bigger knobs */
@media (max-width: 699px), (max-height: 500px) {
  /* the original's lists stand at their full height with empty rows; a phone has no room to spare for them */
  #win .wt tr.blank { display: none; }
}
@media (pointer: coarse) {
  /* a building's Move and Demolish knobs on its picture */
  .bhead .move-btn, .bhead .demo-btn { width: 40px; height: 40px; display: grid; place-items: center; }
  .bhead .move-btn { right: 46px; }
  .bhead .demo-btn { right: 2px; bottom: 2px; }
  .bhead .move-btn svg, .bhead .demo-btn svg { width: 32px; height: 32px; }
}
@media (max-width: 1099px) {
  /* the march form's two halves share the width, neither pushing the other off */
  .mw { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .mw > * { min-width: 0; }
}
@media (max-width: 699px) and (orientation: portrait) { .mw { grid-template-columns: minmax(0, 1fr); } }
@media (pointer: coarse) {
  .mw-form .mw-camp { flex-wrap: wrap; white-space: normal; }
  .mw-form .mw-camp input[type=number], .mw-form .mw-camp input.ms { width: 52px; }
  .mw-form input[type=number] { width: 64px; }
}

/* ================================================================== the battle report (report.js) on a phone upright */
@media (max-width: 699px) and (orientation: portrait) {
  /* the two sides stay side by side, as the original's: each troop by its picture, the name column folded away */
  .rv:not(.rv-one) td.rv-name, .rv:not(.rv-one) .rv-cols th:nth-child(4n+2) { width: 0; padding: 0; font-size: 0; }
  .rv td, .rv th { padding: 3px 3px; }
  .rv td.rv-side { padding: 6px 4px; }
  .rv-head { flex-wrap: wrap; gap: 4px 6px; }
  .rv-figs { flex-wrap: wrap; }
}
@media (max-width: 1099px) { table.m-wide.rv td:first-child, table.m-wide.rv th:first-child { position: static; } }
@media (pointer: coarse) {
  /* an item in a chest's list opens its own window on a tap: a row a finger can hit */
  .hchip[data-detail], .seasonpop [data-detail].hchip { min-height: 32px; }
  .iholds { max-height: 40vh; }
}
@media (max-width: 699px), (max-height: 500px) {
  /* the march form's Send / Return row stays at the foot of the window, edge to edge of its (narrower) paper */
  .mw-buttons { bottom: -8px; margin: 0 -8px -8px; padding: 8px; }
}
@media (max-height: 500px) {
  /* a phone on its side: the building's head shorter, so its own panel starts in sight */
  .bhead { grid-template-columns: 110px minmax(0, 1fr); gap: 8px; margin-bottom: 6px; }
  .bhead .pic { height: 84px; }
  .bhead .desc { padding: 4px 8px; font-size: 13px; }
}
