/* Skirmish II play page — AoE2-style interface layout + painterly chrome.
 *
 * Functional organization in the classic RTS pattern: a resource bar
 * across the TOP, a contextual COMMAND PANEL bottom-left, a SELECTION
 * PANEL bottom-center, and a MINIMAP bottom-right. The layout idea is
 * the genre-standard one; every visual is ours — original generated
 * art (ui-art/: walnut wood and parchment textures, a carved medallion
 * frame, and the painterly icon set v2) in a warm walnut / aged-gold /
 * parchment scheme. Nothing is copied from any other game.
 *
 * Loaded AFTER play.css. Everything is namespaced under .ui-* /
 * .cmd-* / .sel-* / .res-* so it cannot collide with other rules. */

:root {
  --ui-wood: #2a1a0e;
  --ui-gold: #c9a227;
  --ui-gold-bright: #e8c95a;
  --ui-edge: rgba(201, 162, 39, 0.38);
  --ui-edge-strong: rgba(201, 162, 39, 0.65);
  --ui-text: #f0e5c8;
  --ui-dim: #cdbfa4;
  --ui-faint: #a8915f;
  --ui-warn: #ff9d7a;
  --ui-ink: #3d2a12;        /* dark umber text on parchment */
  --ui-ink-dim: #6f573a;
  --ui-ink-warn: #9c2b16;   /* rich red, warnings on parchment only */
}

/* ---------- shared bits ---------- */

.ui-icon {
  display: inline-block;
  flex: none;
  vertical-align: middle;
}

.ui-panel-title {
  font: 700 10px/1.2 system-ui, sans-serif;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ui-faint);
  margin: 0 0 4px;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.7);
}

/* ---------- top resource bar ---------- */

.ui-topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 20;
  height: 42px;
  display: flex;
  align-items: center;
  gap: 18px;
  /* the site link moved into the pause menu (2026-10-17) — the
     topbar no longer needs to leave room for a floating link */
  padding: 0 12px;
  background:
    linear-gradient(rgba(22, 11, 3, 0.38), rgba(22, 11, 3, 0.38)),
    var(--ui-wood) url("ui-art/tex-wood.webp") center 30% / cover no-repeat;
  border-bottom: 2px solid #6d5426;
  box-shadow: inset 0 -1px 0 rgba(232, 201, 90, 0.35), 0 2px 8px rgba(0, 0, 0, 0.45);
  color: var(--ui-text);
  font: 600 13.5px/1 system-ui, sans-serif;
}

.ui-res-group {
  display: flex;
  align-items: center;
  gap: 16px;
  min-width: 0;
}

.res {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8);
}
.res .ui-icon {
  width: 18px;
  height: 18px;
  background: #241407;
  border: 1px solid var(--ui-edge);
  border-radius: 3px;
}
.res .res-val { font-variant-numeric: tabular-nums; }
.res-pop .res-val.warn { color: var(--ui-warn); } /* at cap / housed */
.res-age .res-val { color: #ffd75e; font-weight: 600; } /* M6: the age chip */

/* Idle indicators (M4, INF-03): quiet while nobody is idle, lit
   gold while someone stands free. They are buttons — clicking runs
   the idle key's cycle (SEL-08/09). */
.idle-ind {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 8px 2px 3px;
  background: rgba(22, 11, 3, 0.45);
  border: 1px solid rgba(201, 162, 39, 0.35);
  border-radius: 4px;
  color: var(--ui-text);
  font: inherit;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  opacity: 0.55;
  white-space: nowrap;
}
.idle-ind .ui-icon {
  width: 18px;
  height: 18px;
  background: #241407;
  border: 1px solid var(--ui-edge);
  border-radius: 3px;
}
.idle-ind.has-idle {
  opacity: 1;
  border-color: var(--ui-gold, #c9a227);
  box-shadow: 0 0 6px rgba(201, 162, 39, 0.45);
}
.idle-ind:hover { filter: brightness(1.25); }
.idle-ind:active { transform: translateY(1px); }

.ui-topbar-spacer { flex: 1; }

/* ---------- bottom strip: commands | selection | minimap ---------- */

.ui-bottombar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  /* ONE shallow strip, DE-style (Claudio, 2026-10-19: the old
     content-sized bar ate ~half of a short desktop viewport —
     the 3-row command grid + hint row set the height and the
     selection panel stretched to match). The height is now
     capped against the viewport; the panels inside flex and
     shrink to fit it, and the canvas shows above it. */
  height: clamp(150px, 20vh, 232px);
  box-sizing: border-box;
  display: flex;
  align-items: stretch;
  background:
    linear-gradient(rgba(22, 11, 3, 0.30), rgba(22, 11, 3, 0.30)),
    var(--ui-wood) url("ui-art/tex-wood.webp") center 65% / cover no-repeat;
  border-top: 2px solid #6d5426;
  box-shadow: inset 0 1px 0 rgba(232, 201, 90, 0.30), 0 -2px 10px rgba(0, 0, 0, 0.45);
  color: var(--ui-text);
  font-family: system-ui, sans-serif;
}

/* command panel (bottom-left) */

.ui-cmd-panel {
  /* UI FIX 4 (Claudio, 2026-10-19): the panel is only as wide
     as three square cells need — the grid rows are ~54-60px in
     the capped strip, so a ~228px panel gives the columns room
     for squares; the freed width goes to the selection panel */
  flex: 0 0 228px;
  display: flex;
  flex-direction: column;
  padding: 5px 8px;
  border-right: 1px solid rgba(0, 0, 0, 0.5);
}
.ui-cmd-panel .ui-panel-title { margin-bottom: 2px; }

.cmd-grid {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  /* the three button rows share the strip height equally; the
     hint (always the grid's last child) takes only the line(s)
     it needs, so the grid fits the capped bar at any height */
  grid-template-rows: repeat(3, minmax(0, 1fr)) minmax(0, auto);
  gap: 4px;
}
/* nothing selected: the hint is the grid's only child — give it
   the whole grid instead of the first of four rows */
.cmd-grid:has(> .ui-cmd-hint:only-child) {
  grid-template-rows: minmax(0, 1fr);
}

.cmd-btn {
  position: relative;
  /* SQUARE, ICON-ONLY cell (UI FIX 4, Claudio, 2026-10-19:
     exactly the reference game's command button — a square
     whose whole face is the icon; name and cost print nowhere
     on it, they live in the hover tooltip). The cell takes its
     height from the grid row and its width from the 1:1 ratio,
     centered in its column; the max-width guard keeps it inside
     a too-narrow column instead of overflowing. The only marks
     on the face are the hotkey letter (top-left) and the
     production queue badge (top-right), as in DE. */
  aspect-ratio: 1 / 1;
  height: 100%;
  justify-self: center;
  max-width: 100%;
  min-height: 0;
  min-width: 0;
  overflow: hidden;
  padding: 0;
  background:
    linear-gradient(rgba(26, 13, 4, 0.52), rgba(26, 13, 4, 0.52)),
    var(--ui-wood) url("ui-art/tex-wood.webp") center / cover no-repeat;
  border: 1px solid #7a5c22;
  border-radius: 8px;
  box-shadow:
    inset 0 1px 0 rgba(255, 220, 150, 0.28),
    inset 0 -3px 0 rgba(0, 0, 0, 0.45),
    0 2px 5px rgba(0, 0, 0, 0.45);
  color: var(--ui-text);
  font: inherit;
  cursor: pointer;
}
.cmd-btn:hover:not(:disabled) {
  background:
    linear-gradient(rgba(70, 42, 10, 0.38), rgba(70, 42, 10, 0.38)),
    var(--ui-wood) url("ui-art/tex-wood.webp") center / cover no-repeat;
  border-color: var(--ui-gold);
}
.cmd-btn:active:not(:disabled) {
  transform: translateY(1px);
  box-shadow:
    inset 0 2px 6px rgba(0, 0, 0, 0.55),
    inset 0 -1px 0 rgba(255, 220, 150, 0.15),
    0 1px 2px rgba(0, 0, 0, 0.4);
}
/* disabled/unaffordable: the CELL darkens and the icon greys
   (the old whole-button opacity: .42 greyed everything) */
.cmd-btn:disabled {
  cursor: not-allowed;
  background:
    linear-gradient(rgba(8, 4, 1, 0.78), rgba(8, 4, 1, 0.78)),
    var(--ui-wood) url("ui-art/tex-wood.webp") center / cover no-repeat;
  border-color: #57431d;
  box-shadow:
    inset 0 1px 0 rgba(255, 220, 150, 0.12),
    inset 0 -3px 0 rgba(0, 0, 0, 0.5),
    0 2px 5px rgba(0, 0, 0, 0.45);
}
.cmd-btn:disabled .cmd-icon { opacity: 0.45; filter: saturate(0.45); }
.cmd-btn.active { /* placement armed */
  outline: 2px solid var(--gold-bright, #ffcf4d);
  outline-offset: 1px;
}
/* The icon area: the wrap fills the whole square cell and
   hosts the one overlay, the hotkey letter at its top-left.
   The glyph fills the wrap completely. PNG set
   (ui-art/icons/): full-bleed squares carrying their own
   walnut background and gold frame, made to fill a square
   exactly — cell and art are both square, so nothing crops. */
.cmd-icon-wrap {
  position: absolute;
  inset: 0;
  line-height: 0;
}
.cmd-btn .cmd-icon {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 0;
}
.cmd-btn img.cmd-icon { object-fit: cover; }
.cmd-btn .cmd-badge { /* e.g. training queue length */
  position: absolute;
  top: 3px;
  right: 5px;
  font: 700 10px/1.4 ui-monospace, Menlo, monospace;
  color: var(--gold-bright, #ffcf4d);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.9);
}
.cmd-btn .cmd-key { /* M13: the grid hotkey letter for this button */
  position: absolute;
  top: 2px;
  left: 2px;
  box-sizing: border-box;
  min-width: 13px;
  text-align: center;
  font: 700 10px/1.2 ui-monospace, Menlo, monospace;
  color: var(--ui-gold-bright); /* gold letter on a dark chip */
  background: rgba(0, 0, 0, 0.55);
  border: 1px solid rgba(232, 201, 90, 0.5);
  border-radius: 3px;
  padding: 1px 3px;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.9);
}

.ui-cmd-hint {
  grid-column: 1 / -1;
  align-self: center;
  color: var(--ui-dim);
  font-size: 10.5px;
  line-height: 1.3;
  margin: 0;
  padding: 1px 2px;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8);
}

/* selection panel (bottom-center) — the parchment slab */

.ui-sel-panel {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  /* content hugs the top of the capped strip — the parchment
     fills the strip height but never grows it */
  align-items: flex-start;
  gap: 12px;
  padding: 8px 14px;
  overflow: hidden;
  background: #d9c49a url("ui-art/tex-parchment.webp") center / cover no-repeat;
  box-shadow: inset 0 0 24px rgba(101, 72, 28, 0.35);
  color: var(--ui-ink);
}

.sel-portrait {
  flex: none;
  width: 64px;
  height: 64px;
  display: grid;
  place-items: center;
  /* the carved medallion is the frame; the icon rests on its center */
  background: url("ui-art/medallion.webp") center / cover no-repeat;
  border-radius: 8px;
  box-shadow: 0 2px 6px rgba(40, 24, 4, 0.45);
  color: var(--ui-ink);
}
.sel-portrait .ui-icon { width: 38px; height: 38px; }
/* PNG portraits fill their slot as-is (own bg + gold frame) */
.sel-portrait img.ui-icon, .sel-cell img.ui-icon { border-radius: 2px; object-fit: cover; }
.sel-portrait.empty { color: var(--ui-ink-dim); }

.sel-main { min-width: 0; overflow: hidden; }
.sel-name { font-size: 14.5px; font-weight: 700; margin: 0 0 2px; }
.sel-line {
  font-size: 12.5px;
  color: var(--ui-ink-dim);
  line-height: 1.35;
  margin: 0;
  /* at most two lines of description inside the capped strip */
  max-height: 34px;
  overflow: hidden;
}
.sel-line.warn { color: var(--ui-ink-warn); }

/* group selection: one mini-cell per unit (cap the row with CSS;
   the panel shows the first N and a "+k more" cell) */
.sel-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 5px;
  max-width: 300px;
  /* at most two icon rows; a longer group scrolls in place
     (app.js already caps the row with a "+k more" cell) */
  max-height: 58px;
  overflow-y: auto;
}
.sel-cell {
  width: 27px;
  height: 27px;
  display: grid;
  place-items: center;
  background: rgba(61, 42, 18, 0.14);
  border: 1px solid rgba(61, 42, 18, 0.38);
  border-radius: 5px;
  color: var(--ui-ink);
}
.sel-cell .ui-icon { width: 16px; height: 16px; }
.sel-cell.more {
  font: 700 10.5px/1 ui-monospace, Menlo, monospace;
  color: var(--ui-ink-dim);
}

/* minimap (bottom-right) */

.ui-minimap-wrap {
  flex: none;
  display: flex;
  align-items: center;
  padding: 6px 10px;
  border-left: 1px solid rgba(0, 0, 0, 0.5);
}

#minimap {
  display: block;
  /* the map fills the capped strip's height (to a sane ceiling)
     and its width follows the canvas aspect; minimap.js draws
     into the attribute size and converts clicks via the
     bounding rect, so CSS scaling is safe */
  height: min(190px, calc(clamp(150px, 20vh, 232px) - 24px));
  width: auto;
  aspect-ratio: 220 / 124;
  background: #0b0f14;
  border: 2px solid #8a6a1f;
  border-radius: 4px;
  box-shadow: 0 0 0 1px #2a1a08, 0 0 0 3px rgba(201, 162, 39, 0.25), 0 2px 8px rgba(0, 0, 0, 0.5);
  cursor: pointer;
  touch-action: none;
}

/* ---------- narrow screens ---------- */

@media (max-width: 980px) {
  .sel-portrait { width: 58px; height: 58px; }
  .sel-portrait .ui-icon { width: 34px; height: 34px; }
  #minimap { width: 176px; height: 99px; } /* geometry math uses the
     canvas attribute size; click handlers convert via bounding rect */
}

/* short viewports (small laptop windows): the strip sits at
   its 150px floor — slim the panel chrome (padding, title
   margin, hint, gaps) so the square cells keep their size */
@media (max-height: 780px) {
  .ui-cmd-panel { padding-top: 3px; padding-bottom: 3px; }
  .ui-cmd-panel .ui-panel-title { margin-bottom: 1px; }
  .cmd-grid { gap: 3px; }
  .ui-cmd-hint { padding-top: 0; padding-bottom: 0; }
}

@media (max-width: 700px) {
  /* no floating site link anymore: the topbar reclaims its row */
  .ui-topbar { padding: 6px 12px; height: auto; min-height: 42px; flex-wrap: wrap; gap: 6px 14px; }
  .sel-line { display: none; }
  .sel-grid { display: none; }
  /* bottom strip must FIT a phone: it may take a larger share
     of a short screen than on desktop, but never over ~30vh;
     shrink all three panels instead of letting the selection
     panel and minimap slide off-screen */
  .ui-bottombar { height: clamp(134px, 27vh, 30vh); }
  /* a slightly wider panel than the old pill layout: the three
     columns (~52px) let the cells stay square at ~44px+ on a
     typical phone, sized by their row height as on desktop */
  .ui-cmd-panel { flex-basis: 176px; padding: 5px 6px; }
  .cmd-grid { gap: 3px; }
  .cmd-btn .cmd-key { font-size: 8px; min-width: 11px; padding: 0 2px; }
  .ui-cmd-hint { font-size: 9.5px; }
  .ui-sel-panel { padding: 6px 8px; gap: 8px; }
  .sel-portrait { width: 44px; height: 44px; }
  .sel-portrait .ui-icon { width: 26px; height: 26px; }
  .sel-name { font-size: 13px; }
  .ui-minimap-wrap { padding: 6px 6px 8px; }
  #minimap { width: 118px; height: 66px; }
}
