/* Dune II shell: original indexed battlefield plus a responsive DOM recreation
   of the 1992 sand/rust command console. Historical .ra-* class names are kept
   only as the stable menu DOM contract. */
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { width: 100%; height: 100%; overflow: hidden; background: #000; }
body { font-family: "Trebuchet MS", system-ui, sans-serif; color: #ead6a0; }

#gl { position: fixed; top: 40px; left: 0; right: 260px; bottom: 0; width: calc(100vw - 260px); height: calc(100vh - 40px); display: block; touch-action: none; image-rendering: pixelated; image-rendering: crisp-edges; }

#hud { position: fixed; inset: 0; pointer-events: none; }
#hud > * { pointer-events: auto; }
#topbar { position: absolute; top: 0; left: 0; right: 0; height: 40px; }
#sidebar { position: absolute; top: 40px; right: 0; bottom: 0; width: 260px; }
#selection, #chat { position: static; }

#menus { position: fixed; inset: 0; z-index: 20; }
#menus:empty { display: none; }

#fps { position: fixed; left: 6px; bottom: 4px; z-index: 40; font: 12px monospace; color: #7f7; display: none; }

#loading {
  position: fixed; inset: 0; z-index: 30;
  background: radial-gradient(circle at 50% 35%, #6b3f1d, #1a0e07 60%, #050302);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px;
}
#loading-title { font-size: 42px; font-weight: 800; letter-spacing: 8px; color: #e5b64f; text-shadow: 0 3px #4b2510; }
#loading-label { font-size: 14px; color: #c8a76b; }
#loading-label.error { color: #f66; }
#loading-bar { width: min(420px, 70vw); height: 10px; border: 1px solid #9b6931; background: #170b05; }
#loading-fill { width: 0; height: 100%; background: linear-gradient(90deg, #8b451d, #e5b64f); transition: width .15s; }

/* ==========================================================================
   Design tokens
   ========================================================================== */
:root {
  --ra-red: #a94f24; --ra-red-lite: #d87636; --ra-red-dim: #633018; --ra-edge: #5b371d;
  --ra-gold: #e5b64f; --ra-gold-dim: #9a6b2e;
  --ra-led: #a9ce73; --ra-led-dim: #536c38;
  --ra-ink: #f0dfae; --ra-mut: #c3a875; --ra-faint: #816d4e;
  --ra-panel: #24150c; --ra-panel-2: #321e10; --ra-panel-3: #422817;
  --ra-steel: #654326; --ra-steel-hi: #916239;
  --ra-line: #694522; --ra-ok: #73b95a; --ra-warn: #e8974a;
  --ra-shadow: 0 18px 48px rgba(0,0,0,.6);
  --ra-tap: 52px;                    /* min thumb target */
}

/* ==========================================================================
   Backdrop — one full-screen RA scene behind every menu screen
   ========================================================================== */
.ra-menu {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
  z-index: 25; overflow-y: auto; -webkit-overflow-scrolling: touch;
  /* authentic RA title screen (title.pcx → assets/ui/title.png) under a dark wash
     so the metal-console frame + red command-grid read as backdrop texture while
     panels/labels stay legible. Falls back to the dark gradient if the art 404s. */
  background:
    radial-gradient(110% 80% at 50% 0%, rgba(173,99,39,.34), transparent 62%),
    repeating-linear-gradient(112deg, rgba(232,177,87,.035) 0 2px, transparent 2px 12px),
    linear-gradient(180deg, #3d2312 0%, #1d1008 65%, #080402 100%);
}
/* scanline wash + faint grid — pure CSS texture, no assets */
.ra-menu::before {
  content: ''; position: absolute; inset: 0; pointer-events: none; z-index: 0; opacity: .5;
  background:
    repeating-linear-gradient(0deg, transparent 0 2px, rgba(0,0,0,.30) 2px 3px),
    repeating-linear-gradient(90deg, rgba(255,255,255,.012) 0 1px, transparent 1px 46px);
}
/* corner spice markings */
.ra-menu::after {
  content: ''; position: absolute; inset: 0; pointer-events: none; z-index: 0; opacity: .12;
  background:
    repeating-linear-gradient(-45deg, var(--ra-gold) 0 8px, #0000 8px 20px) left top / 130px 6px no-repeat,
    repeating-linear-gradient(45deg, var(--ra-gold) 0 8px, #0000 8px 20px) right bottom / 130px 6px no-repeat;
}
.ra-menu--dim { background: rgba(6, 7, 9, .82); }
.ra-menu--dim::after { display: none; }

/* ==========================================================================
   Panel — a bolted steel console. Card on desktop, full-bleed on phone.
   ========================================================================== */
.ra-panel {
  position: relative; z-index: 1; width: 100%; max-width: 440px;
  background:
    linear-gradient(180deg, rgba(255,255,255,.045), rgba(255,255,255,0) 60px),
    linear-gradient(180deg, rgba(58,33,17,.96), rgba(28,15,8,.97));
  border: 1px solid var(--ra-steel); border-top: 2px solid var(--ra-red);
  box-shadow: var(--ra-shadow), inset 0 0 0 1px rgba(0,0,0,.4), inset 0 1px 0 rgba(255,255,255,.05);
  padding: 22px clamp(16px, 4vw, 28px) 20px; color: var(--ra-ink);
  display: flex; flex-direction: column;
}
/* desktop: overlay the authentic DD-*.SHP metal dialog frame (assets/ui/frame.png,
   96px 9-slice) as a border-image. Kept off phones (border-width would eat the
   narrow viewport) — mobile stays on the crisp CSS steel border above. */
@media (min-width: 761px) {
  .ra-panel {
    border: 7px ridge #8b5a2d;
    padding: 18px clamp(12px, 3vw, 22px) 16px;
  }
  .ra-panel::before { inset: 3px; }   /* pull rivet dots inside the metal frame */
}
/* rivet dots in the corners */
.ra-panel::before {
  content: ''; position: absolute; inset: 6px; pointer-events: none; border-radius: 2px;
  background:
    radial-gradient(circle 2.5px at 0 0, #0008 60%, transparent 62%) left top,
    radial-gradient(circle 2.5px at 100% 0, #0008 60%, transparent 62%) right top,
    radial-gradient(circle 2.5px at 0 100%, #0008 60%, transparent 62%) left bottom,
    radial-gradient(circle 2.5px at 100% 100%, #0008 60%, transparent 62%) right bottom;
  background-repeat: no-repeat; background-size: 8px 8px;
}
.ra-panel--wide { max-width: 680px; }
.ra-panel--lobby { max-width: 1000px; }
.ra-panel--modal { max-width: 380px; }

/* ==========================================================================
   Title / stencil logotype
   ========================================================================== */
.ra-title { text-align: center; margin-bottom: 16px; }
.ra-title h1 {
  font-size: clamp(30px, 8vw, 46px); letter-spacing: .16em; font-weight: 900; color: var(--ra-gold);
  line-height: 1; text-transform: uppercase;
  text-shadow: 0 0 1px #000, 0 3px 0 #5b2b12, 0 0 22px rgba(229,182,79,.28);
}
.ra-title h1::after {   /* hazard underbar under the logotype */
  content: ''; display: block; height: 3px; width: min(78%, 320px); margin: 10px auto 0;
  background:
    linear-gradient(90deg, transparent, var(--ra-red) 18%, var(--ra-red) 82%, transparent),
    repeating-linear-gradient(90deg, rgba(0,0,0,.5) 0 6px, transparent 6px 12px);
}
.ra-title h2 {
  font-size: 12px; color: var(--ra-led); font-weight: 600; margin-top: 9px; letter-spacing: .14em;
  text-transform: uppercase; text-shadow: 0 0 8px rgba(92,240,122,.35);
}
.ra-h {
  font-size: 11px; letter-spacing: .18em; text-transform: uppercase; color: var(--ra-gold);
  margin: 16px 0 8px; display: flex; align-items: center; gap: 8px;
}
.ra-h::before { content: ''; width: 8px; height: 8px; flex: 0 0 auto; background: var(--ra-red);
  clip-path: polygon(0 0, 100% 50%, 0 100%); }
.ra-h::after { content: ''; flex: 1 1 auto; height: 1px; background: linear-gradient(90deg, var(--ra-line), transparent); }
.ra-h:first-child { margin-top: 0; }

/* ==========================================================================
   Buttons
   ========================================================================== */
.ra-btn {
  display: flex; align-items: center; gap: 10px; width: 100%; margin: 8px 0;
  padding: 13px 16px; min-height: var(--ra-tap);
  background: linear-gradient(180deg, var(--ra-steel), var(--ra-panel-2));
  color: var(--ra-ink); border: 1px solid var(--ra-steel-hi); border-left: 3px solid var(--ra-red-dim);
  cursor: pointer; font: 600 15px/1.15 system-ui, sans-serif; text-align: left; letter-spacing: .04em;
  text-transform: uppercase; transition: background .12s, border-color .12s, transform .04s, box-shadow .12s;
}
.ra-btn:hover { background: linear-gradient(180deg, var(--ra-steel-hi), var(--ra-steel)); border-left-color: var(--ra-red); }
.ra-btn:active { transform: translateY(1px); }
.ra-btn:focus-visible { outline: 2px solid var(--ra-gold); outline-offset: 2px; }
.ra-btn::before {   /* chevron marker */
  content: '›'; flex: 0 0 auto; color: var(--ra-red); font-weight: 900; font-size: 20px; line-height: 1;
  width: 12px; text-align: center; transition: transform .12s, color .12s;
}
.ra-btn:hover::before { transform: translateX(2px); color: var(--ra-red-lite); }
.ra-btn--primary {
  background: linear-gradient(180deg, #b3281c, #7c1810); border-color: #d8443a; border-left-color: var(--ra-gold);
  color: #fff; font-weight: 800; letter-spacing: .07em;
  box-shadow: 0 0 22px rgba(216,52,42,.30), inset 0 1px 0 rgba(255,255,255,.14);
  justify-content: center; text-align: center;
}
.ra-btn--primary::before { content: '▶'; font-size: 13px; color: var(--ra-gold); }
.ra-btn--primary:hover { background: linear-gradient(180deg, #cc3226, #8e1c12); }
.ra-btn:disabled { opacity: .38; cursor: not-allowed; }
.ra-btn:disabled:hover { background: linear-gradient(180deg, var(--ra-steel), var(--ra-panel-2)); border-left-color: var(--ra-red-dim); }
.ra-btn:disabled::before { color: var(--ra-faint); }
.ra-btn--ghost {
  background: transparent; border-color: var(--ra-line); border-left-color: var(--ra-line);
  color: var(--ra-mut); text-transform: none; letter-spacing: .02em; font-weight: 500;
}
.ra-btn--ghost::before { display: none; }
.ra-btn--ghost:hover { color: var(--ra-ink); background: rgba(255,255,255,.03); border-left-color: var(--ra-mut); }
.ra-btn--sm {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  width: auto; min-height: 44px; margin: 0; padding: 9px 14px; font-size: 13px; text-transform: none;
  letter-spacing: .02em; text-align: center;
}
.ra-btn--sm::before { display: none; }
.ra-btn--kicon { font-size: 16px; }

.ra-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin: 10px 0; }
.ra-row--end { justify-content: flex-end; }
.ra-grow { flex: 1 1 auto; min-width: 0; }
.ra-spacer { flex: 1 1 auto; }

/* ==========================================================================
   Inputs / selects
   ========================================================================== */
.ra-input, .ra-select {
  width: 100%; padding: 11px 12px; min-height: 46px; background: #0c0e12; color: var(--ra-ink);
  border: 1px solid var(--ra-steel-hi); font: 14px system-ui, sans-serif; outline: none; border-radius: 2px;
}
.ra-input:focus, .ra-select:focus { border-color: var(--ra-red); box-shadow: 0 0 0 1px rgba(216,52,42,.35); }
.ra-select {
  appearance: none; -webkit-appearance: none; cursor: pointer;
  background-image: linear-gradient(45deg, transparent 50%, var(--ra-mut) 50%), linear-gradient(135deg, var(--ra-mut) 50%, transparent 50%);
  background-position: calc(100% - 16px) 50%, calc(100% - 11px) 50%; background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat; padding-right: 30px;
}
.ra-select:disabled { opacity: .55; cursor: default; }
.ra-input--code { text-transform: uppercase; letter-spacing: .25em; font-weight: 700; text-align: center; font-size: 18px; }

.ra-note { color: var(--ra-faint); font-size: 12px; line-height: 1.5; margin-top: 16px; text-align: center; }
.ra-note a { color: var(--ra-mut); }

.ra-share {
  display: flex; gap: 8px; align-items: center; font-size: 12px; color: var(--ra-mut);
  background: #0c0e12; border: 1px solid var(--ra-line); border-left: 3px solid var(--ra-gold-dim);
  padding: 8px 11px; margin: 4px 0 14px;
}
.ra-share code { color: var(--ra-ink); font: 12px/1 monospace; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1 1 auto; }

/* ==========================================================================
   Lists (rooms / replays)
   ========================================================================== */
.ra-list { max-height: min(46vh, 380px); overflow-y: auto; margin: 6px 0 12px; border: 1px solid var(--ra-line); background: #0c0e12; }
.ra-list__item {
  display: flex; align-items: center; gap: 10px; padding: 11px 12px; border-bottom: 1px solid var(--ra-line);
  font-size: 14px;
}
.ra-list__item:last-child { border-bottom: 0; }
.ra-list__item:nth-child(odd) { background: rgba(255,255,255,.018); }
.ra-list__empty { padding: 20px; text-align: center; color: var(--ra-faint); font-size: 13px; }
.ra-list__main { flex: 1 1 auto; min-width: 0; }
.ra-list__sub { color: var(--ra-mut); font-size: 12px; margin-top: 2px; }

.ra-badge {
  display: inline-block; padding: 1px 8px; border-radius: 2px; font-size: 11px; font-weight: 700;
  background: var(--ra-steel); color: var(--ra-mut); border: 1px solid var(--ra-steel-hi);
}
.ra-badge--live { background: var(--ra-red-dim); color: #ffddd6; border-color: #b33; }
.ra-badge--warn { background: #3a2c14; color: var(--ra-warn); border-color: #7a5a20; }

/* ==========================================================================
   Lobby
   ========================================================================== */
.ra-lobby-grid { display: grid; grid-template-columns: 1.1fr 1fr; gap: 18px; align-items: start; }
.ra-col { min-width: 0; }

.ra-slots { display: grid; grid-template-columns: 1fr; gap: 7px; }
.ra-slot {
  display: grid; grid-template-columns: 24px 1fr auto; gap: 9px; align-items: center;
  padding: 9px 10px; background: linear-gradient(180deg, var(--ra-panel-3), var(--ra-panel-2));
  border: 1px solid var(--ra-line); border-left: 3px solid var(--ra-steel-hi); border-radius: 2px;
}
.ra-slot--you { border-left-color: var(--ra-red); background: linear-gradient(180deg, #2a1d1a, #201715); }
.ra-slot__num { color: var(--ra-faint); font: 700 13px/1 monospace; text-align: center; }
.ra-slot__body { min-width: 0; display: flex; flex-direction: column; gap: 7px; }
.ra-slot__name { display: flex; align-items: center; gap: 7px; font-size: 14px; }
.ra-slot__name b { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ra-slot__dim { color: var(--ra-faint); font-style: italic; }
.ra-slot__ctrls { display: flex; gap: 6px; flex-wrap: wrap; }
.ra-slot__ctrls .ra-select { width: auto; min-width: 96px; flex: 1 1 auto; padding: 6px 26px 6px 9px; min-height: 38px; font-size: 12px; }
.ra-slot__side { display: flex; align-items: center; }
.ra-slot__side .ra-select { min-height: 40px; }
.ra-dot { width: 10px; height: 10px; border-radius: 50%; flex: 0 0 auto; box-shadow: 0 0 0 1px rgba(0,0,0,.7), 0 0 6px currentColor; }
.ra-crown { color: var(--ra-gold); }
.ra-away { color: var(--ra-warn); }

.ra-swatches { display: flex; gap: 6px; flex-wrap: wrap; }
.ra-swatch {
  width: 30px; height: 30px; min-height: 30px; border-radius: 3px; border: 2px solid transparent;
  cursor: pointer; padding: 0; box-shadow: inset 0 0 0 1px rgba(0,0,0,.55);
}
.ra-swatch--on { border-color: #fff; box-shadow: 0 0 8px rgba(255,255,255,.6); }
.ra-swatch:disabled { cursor: default; opacity: .8; }

.ra-opts { display: flex; flex-direction: column; gap: 10px; }
.ra-field { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.ra-field > span:first-child { color: var(--ra-mut); font-size: 13px; }
.ra-field .ra-select { width: auto; min-width: 128px; flex: 0 1 auto; }
.ra-check { display: flex; align-items: center; gap: 10px; cursor: pointer; font-size: 13px; color: var(--ra-ink); min-height: 40px; }
.ra-check input { width: 22px; height: 22px; accent-color: var(--ra-red); cursor: pointer; flex: 0 0 auto; }

.ra-range { display: flex; align-items: center; gap: 12px; }
.ra-range input[type=range] { flex: 1 1 auto; accent-color: var(--ra-red); height: 28px; cursor: pointer; }
.ra-range__val { min-width: 46px; text-align: right; font: 13px monospace; color: var(--ra-gold); }

/* map picker: a current-map card + a full-screen overlay list (one impl, both
   viewports). On desktop the overlay wrap is shown inline in the lobby column;
   on phone it opens as a full-screen sheet from the "Zmień mapę" button. */
.ra-map-current {
  display: flex; align-items: center; gap: 10px; padding: 10px 11px;
  background: linear-gradient(180deg, var(--ra-panel-3), var(--ra-panel-2));
  border: 1px solid var(--ra-line); border-left: 3px solid var(--ra-gold-dim); border-radius: 2px;
}
.ra-map-current__t { flex: 1 1 auto; min-width: 0; }
.ra-map-current__t b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ra-map-current__t span { color: var(--ra-mut); font-size: 12px; }
.ra-map-change { display: none; }                    /* shown only on phone */

.ra-mapwrap { margin-top: 8px; }
.ra-mapwrap__close { display: none; }
.ra-mapsearch { margin-bottom: 8px; }
.ra-maps { max-height: 260px; overflow-y: auto; border: 1px solid var(--ra-line); background: #160c06; }
.ra-map-row {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px; cursor: pointer;
  border-bottom: 1px solid var(--ra-line); font-size: 13px; min-height: 44px;
}
.ra-map-row:last-child { border-bottom: 0; }
.ra-map-row:hover { background: rgba(255,255,255,.03); }
.ra-map-row--on { background: #2a1d18; border-left: 3px solid var(--ra-red); padding-left: 9px; }
.ra-map-row__t { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ra-map-row__meta { color: var(--ra-faint); font-size: 11px; }

/* chat */
.ra-chat { display: flex; flex-direction: column; }
.ra-chat__log {
  flex: 1 1 auto; min-height: 96px; max-height: 200px; overflow-y: auto; background: #160c06;
  border: 1px solid var(--ra-line); padding: 8px; font-size: 13px; line-height: 1.5; margin-bottom: 6px;
}
.ra-chat__msg { word-wrap: break-word; }
.ra-chat__from { font-weight: 700; }
.ra-chat__empty { color: var(--ra-faint); font-style: italic; }

/* ==========================================================================
   Game-over
   ========================================================================== */
.ra-over__head { text-align: center; font: 900 clamp(26px, 7vw, 34px)/1 system-ui; letter-spacing: .1em; margin-bottom: 4px; text-transform: uppercase; color: var(--ra-mut); }
.ra-over__head--win { color: var(--ra-ok); text-shadow: 0 0 22px rgba(74,232,124,.45); }
.ra-over__head--lose { color: var(--ra-red); text-shadow: 0 0 22px rgba(216,52,42,.45); }
.ra-over__sub { text-align: center; color: var(--ra-mut); font-size: 13px; margin-bottom: 16px; }
.ra-stats { width: 100%; border-collapse: collapse; font-size: 13px; margin-bottom: 8px; }
.ra-stats th, .ra-stats td { padding: 8px; text-align: right; border-bottom: 1px solid var(--ra-line); white-space: nowrap; }
.ra-stats th { color: var(--ra-gold); font-weight: 700; font-size: 10px; text-transform: uppercase; letter-spacing: .1em; }
.ra-stats td:first-child, .ra-stats th:first-child { text-align: left; }
.ra-stats tr.ra-me td { background: rgba(216,52,42,.10); color: var(--ra-ink); }
.ra-stats__name { display: inline-flex; align-items: center; gap: 6px; }
.ra-stats__win { color: var(--ra-gold); }
.ra-stats__dead { color: var(--ra-faint); text-decoration: line-through; }
.ra-stats-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* ==========================================================================
   How-to
   ========================================================================== */
.ra-howto { max-height: 62vh; overflow-y: auto; }
.ra-howto table { width: 100%; border-collapse: collapse; font-size: 13px; margin-bottom: 14px; }
.ra-howto td { padding: 7px 8px; border-bottom: 1px solid var(--ra-line); vertical-align: top; }
.ra-howto td:first-child { color: var(--ra-red); font-weight: 700; white-space: nowrap; width: 38%; }
.ra-kbd { display: inline-block; background: var(--ra-steel); border: 1px solid var(--ra-steel-hi); border-bottom-width: 2px;
  border-radius: 3px; padding: 1px 6px; font: 12px monospace; color: var(--ra-ink); }

/* ==========================================================================
   In-game gear + reconnect banner + toast (live outside #menus)
   ========================================================================== */
#ra-gear {
  position: fixed; top: max(6px, env(safe-area-inset-top)); left: 6px; width: 40px; height: 40px; z-index: 41;
  display: none; align-items: center; justify-content: center; padding: 0; cursor: pointer;
  background: linear-gradient(180deg, var(--ra-steel), var(--ra-panel)); color: var(--ra-ink);
  border: 1px solid var(--ra-steel-hi); border-radius: 3px; font-size: 19px; line-height: 1;
  box-shadow: 0 2px 8px rgba(0,0,0,.5);
}
#ra-gear:hover { background: linear-gradient(180deg, #52201a, #3a1512); border-color: var(--ra-red); }
#ra-gear.on { display: flex; }
#hud #ra-top { padding-left: 52px; }   /* reserve the top-left corner for the gear */

#ra-reconnect {
  position: fixed; top: 12px; left: 50%; transform: translateX(-50%); z-index: 55; display: none;
  align-items: center; gap: 10px; background: rgba(60,18,14,.95); color: #ffe4de;
  border: 1px solid #b33; padding: 9px 18px; font: 13px system-ui; box-shadow: 0 4px 18px rgba(0,0,0,.5);
}
#ra-reconnect.on { display: flex; }
.ra-spin { width: 14px; height: 14px; border: 2px solid rgba(255,255,255,.3); border-top-color: #fff;
  border-radius: 50%; animation: ra-spin 0.8s linear infinite; }
@keyframes ra-spin { to { transform: rotate(360deg); } }

.ra-toast {
  position: fixed; top: 52px; left: 50%; transform: translateX(-50%); z-index: 60;
  background: linear-gradient(180deg, #52140f, #390d0a); color: #ffe4de; border: 1px solid #7a2018;
  border-left: 3px solid var(--ra-red); padding: 10px 18px;
  font: 14px system-ui; box-shadow: 0 4px 18px rgba(0,0,0,.55); max-width: 90vw; text-align: center;
}

/* ==========================================================================
   Responsive — phone-first tuning. Base rules above are already mobile-safe;
   these adapt the panels to small viewports and open the map sheet.
   ========================================================================== */

/* map picker as a full-screen sheet — every phone form factor: narrow/portrait
   OR short landscape. Desktops (both test viewports are >760w AND >560h) keep the
   map list inline in the lobby column. */
@media (max-width: 760px), (max-height: 560px) and (orientation: landscape) {
  .ra-map-change { display: inline-flex; }
  .ra-mapwrap {
    position: fixed; inset: 0; z-index: 70; margin: 0; padding: max(12px, env(safe-area-inset-top)) 12px 12px;
    background: linear-gradient(180deg, #2e1a0d, #0d0704);
    display: none; flex-direction: column;
  }
  .ra-mapwrap.open { display: flex; }
  .ra-mapwrap__close { display: inline-flex; margin-bottom: 10px; align-self: flex-end; }
  .ra-maps { max-height: none; flex: 1 1 auto; }
  .ra-map-row { min-height: var(--ra-tap); padding: 13px 12px; }
}

/* narrow / portrait: single-column full-bleed console */
@media (max-width: 760px) {
  .ra-menu { padding: max(10px, env(safe-area-inset-top)) 10px max(10px, env(safe-area-inset-bottom)); align-items: stretch; }
  .ra-menu::after { display: none; }
  .ra-panel, .ra-panel--wide, .ra-panel--lobby { max-width: none; }
  .ra-panel { padding: 18px 14px 16px; border-radius: 0; }
  .ra-panel--modal { max-width: 440px; margin: auto; }
  .ra-lobby-grid { grid-template-columns: 1fr; gap: 12px; }
  .ra-chat__log { max-height: 30vh; }
}

/* landscape phone: fit the whole console into ~400px of height */
@media (max-height: 460px) and (orientation: landscape) {
  .ra-menu { padding: 8px 12px; align-items: stretch; }
  .ra-menu::after { display: none; }
  .ra-panel { padding: 12px 16px; }
  .ra-title { margin-bottom: 10px; }
  .ra-title h1 { font-size: clamp(24px, 6.2vh, 34px); }
  .ra-title h1::after { margin-top: 6px; }
  .ra-title h2 { margin-top: 5px; }
  .ra-note { margin-top: 10px; }
  /* two-up button grid on the main screen so 4 secondary buttons fit the height */
  .ra-btns { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
  .ra-btns .ra-btn { margin: 0; min-height: 48px; }
  .ra-btns .ra-btn--primary { grid-column: 1 / -1; }
  .ra-lobby-grid { grid-template-columns: 1.2fr 1fr; }
  .ra-slots { grid-template-columns: 1fr 1fr; }   /* 8 slots as 2×4 */
  .ra-chat__log { max-height: 26vh; }
}

/* ==========================================================================
   In-game chat (chat.js) — fading log + Enter-to-open input, bottom-left above
   #ra-selinfo. The LOG never captures pointer (nothing over #gl swallows taps);
   the input captures only its own box, and only while open.
   ========================================================================== */
#ra-chat-ig {
  position: fixed; left: 8px; bottom: 96px; z-index: 19; width: min(440px, 62vw);
  display: flex; flex-direction: column; gap: 3px; pointer-events: none;
}
html.touch #ra-chat-ig { bottom: 116px; }   /* clear the touch action bar + selinfo */
#ra-chat-ig .ra-chatig__log { display: flex; flex-direction: column; gap: 3px; }
#ra-chat-ig .ra-cmsg {
  align-self: flex-start; max-width: 100%; pointer-events: none;
  background: rgba(31, 17, 8, .82); border-left: 2px solid var(--ra-gold);
  padding: 2px 8px; border-radius: 2px; font: 13px/1.35 system-ui; color: #f0dbad;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  opacity: 1; transition: opacity .55s;
}
#ra-chat-ig .ra-cmsg.gone { opacity: 0; }
#ra-chat-ig .ra-cmsg .nm { font-weight: 700; }
#ra-chat-ig .ra-chatig__in {
  display: none; pointer-events: auto; width: 100%; margin-top: 3px;
  padding: 8px 10px; background: rgba(23, 12, 6, .97); color: #f4dfaf;
  border: 1px solid var(--ra-gold); border-radius: 2px; font: 14px system-ui; outline: none;
}
#ra-chat-ig.open .ra-chatig__in { display: block; }

/* ==========================================================================
   Replay playback bar (replaybar.js) — bottom-center, spectators only.
   ========================================================================== */
#ra-replaybar {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: 12px; z-index: 20;
  display: none; align-items: center; gap: 8px; padding: 8px 12px; max-width: min(94vw, 760px);
  background: linear-gradient(180deg, rgba(73, 41, 19, .97), rgba(28, 15, 7, .97));
  border: 2px ridge #8c5b2c; border-top-color: var(--ra-gold);
  box-shadow: 0 4px 18px rgba(0, 0, 0, .55); font: 12px system-ui; color: var(--ra-ink);
}
#ra-replaybar.on { display: flex; }
#ra-replaybar button {
  flex: 0 0 auto; min-height: 34px; padding: 6px 9px; cursor: pointer; border-radius: 2px;
  background: linear-gradient(180deg, #68401f, #321b0d); color: #edcf8b; border: 1px solid #140a04; font: 12px system-ui;
}
#ra-replaybar button:hover { border-color: var(--ra-red); color: #fff; }
#ra-replaybar button.on { background: linear-gradient(180deg, #a35c24, #633013); color: #fff1c4; }
#ra-replaybar .rb-play { min-width: 40px; font-size: 15px; line-height: 1; }
#ra-replaybar .rb-speeds { display: flex; gap: 3px; }
#ra-replaybar .rb-seek { flex: 1 1 auto; min-width: 90px; accent-color: var(--ra-red); height: 26px; cursor: pointer; }
#ra-replaybar .rb-time { font: 12px monospace; color: var(--ra-gold); white-space: nowrap; min-width: 92px; text-align: center; }
html.touch #ra-replaybar { bottom: 8px; max-width: 96vw; padding: 7px 9px; gap: 6px; }
html.coarse #ra-replaybar button { min-height: 44px; }
html.coarse #ra-replaybar .rb-seek { height: 40px; }

/* coarse pointer: enforce comfortable tap targets regardless of size */
html.coarse .ra-btn--sm { min-height: 46px; padding: 11px 16px; }
html.coarse .ra-select, html.coarse .ra-input { min-height: 48px; }
html.coarse .ra-slot__ctrls .ra-select, html.coarse .ra-slot__side .ra-select { min-height: 42px; }
html.coarse .ra-swatch { width: 36px; height: 36px; }
html.coarse .ra-map-row { padding: 14px 12px; }
html.coarse .ra-check input { width: 24px; height: 24px; }

/* ==========================================================================
   Dune II in-game chrome — composition follows port/reference screenshot.
   ========================================================================== */
.d2-topbar {
  z-index: 12; display: flex; align-items: stretch; min-width: 0;
  background: linear-gradient(#b77a35, #6e3c18 52%, #2a1509 54%, #43240f);
  border-bottom: 3px ridge #c89955; color: #170b04;
  box-shadow: 0 2px 8px #000b; font: 700 12px/1 monospace;
}
.d2-top-button {
  flex: 0 0 auto; min-width: 72px; padding: 0 12px; border: 0; border-right: 3px ridge #c89955;
  background: linear-gradient(#ddb663, #8b5525); color: #281206; font: 900 13px/1 monospace;
  text-shadow: 0 1px #f2d58f; cursor: pointer;
}
.d2-top-button:hover { filter: brightness(1.18); }
.d2-top-title { flex: 1 1 auto; display: flex; align-items: center; padding: 0 14px; color: #f0cd78; letter-spacing: .12em; text-shadow: 1px 1px #321505; overflow: hidden; white-space: nowrap; }
.d2-credits { flex: 0 0 auto; display: flex; align-items: center; gap: 9px; padding: 0 12px; border-left: 3px ridge #c89955; background: #2a160b; color: #d9b05a; }
.d2-credits b { min-width: 64px; padding: 4px 7px; background: #080603; border: 2px inset #8f6531; color: #e7c566; text-align: right; letter-spacing: .14em; }
#d2-speed { width: 70px; border: 0; border-left: 3px ridge #c89955; background: #3a210f; color: #e5bd69; padding: 0 6px; font: 700 11px monospace; }
#d2-speed:disabled { display: none; }

.d2-sidebar {
  z-index: 11; display: flex; flex-direction: column; overflow: hidden;
  padding: 7px; background: linear-gradient(90deg, #271307, #5b3216 5%, #3a1f0e 96%, #1c0d05);
  border-left: 5px ridge #c28b47; box-shadow: -4px 0 12px #000b; color: #ead29a;
}
#d2-context { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; overflow: hidden; border: 3px inset #8f6030; background: #160d07; }
#d2-context.deny { animation: d2-deny .23s 2; }
@keyframes d2-deny { 50% { box-shadow: inset 0 0 0 3px #e74425; } }
#selection { flex: 0 0 auto; padding: 8px; border-bottom: 2px ridge #6f4824; }
#build { flex: 1 1 auto; min-height: 0; overflow-y: auto; padding: 7px; scrollbar-color: #976332 #211108; }
.d2-context-empty { min-height: 70px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 7px; color: #8e774f; text-align: center; font: 11px monospace; }
.d2-context-empty b { color: #d9b65e; letter-spacing: .18em; }
.d2-selected { display: grid; grid-template-columns: 62px 1fr; gap: 8px; min-height: 62px; }
.d2-selected-icon, .d2-cameo { background-position: center; background-repeat: no-repeat; background-size: contain; image-rendering: pixelated; image-rendering: crisp-edges; }
.d2-selected-icon { width: 62px; height: 54px; background-color: #090604; border: 2px inset #805526; }
.d2-selected-meta { min-width: 0; display: flex; flex-direction: column; gap: 3px; font: 10px monospace; color: #a98d5e; }
.d2-selected-meta b { overflow: hidden; color: #efd078; font-size: 12px; white-space: nowrap; text-overflow: ellipsis; }
.d2-selected-meta small { color: #bda16d; }
.d2-hp { height: 7px; background: #251008; border: 1px solid #5f371c; }
.d2-hp i { display: block; height: 100%; background: linear-gradient(90deg, #7c1c12, #e5a23b, #6eb44d); }
.d2-selection-title { color: #efd078; font: 12px monospace; letter-spacing: .08em; }
.d2-group-list { max-height: 54px; overflow: hidden; margin-top: 5px; color: #bfa671; font: 10px/1.35 monospace; }
.d2-actions { display: grid; grid-template-columns: repeat(2, 1fr); gap: 4px; margin-top: 7px; }
.d2-action {
  min-height: 28px; padding: 4px 5px; border: 2px outset #8c5a29; background: linear-gradient(#8c5526, #48240f); color: #f0d080;
  font: 700 9px monospace; cursor: pointer; text-transform: uppercase;
}
.d2-action:active { border-style: inset; }
.d2-action:disabled { opacity: .4; cursor: default; }
.d2-build-title, .d2-power-label { display: flex; justify-content: space-between; align-items: center; color: #daba68; font: 9px monospace; letter-spacing: .08em; }
.d2-build-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 5px; margin-top: 6px; }
.d2-build-card {
  position: relative; min-width: 0; min-height: 84px; padding: 4px 3px 14px; overflow: hidden;
  border: 2px outset #85582c; background: linear-gradient(#39200f, #160c06); color: #e9cd88; cursor: pointer; font: 9px monospace;
}
.d2-build-card:hover { filter: brightness(1.18); }
.d2-build-card:disabled { opacity: .34; cursor: not-allowed; filter: grayscale(.5); }
.d2-build-card .d2-cameo { display: block; height: 46px; margin-bottom: 2px; }
.d2-build-card b, .d2-build-card small { display: block; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.d2-build-card small { color: #a98b5d; margin-top: 2px; }
.d2-build-card > i { position: absolute; left: 0; bottom: 0; height: 11px; background: #a85a21; }
.d2-build-card > em { position: absolute; left: 0; right: 0; bottom: 1px; z-index: 1; color: #fff2ba; font: 700 8px monospace; text-align: center; font-style: normal; }
.d2-build-card.ready { border-color: #d4b246; animation: d2-ready .8s steps(2) infinite; }
.d2-build-card.paused > i { background: #685b44; }
@keyframes d2-ready { 50% { filter: brightness(1.35); } }
.d2-upgrade { width: 100%; margin-top: 7px; }
.d2-no-build { grid-column: 1/-1; color: #786747; padding: 14px 4px; text-align: center; font: 10px monospace; }

#power { flex: 0 0 38px; padding: 5px 4px; border: 3px inset #835829; background: #1b0f07; }
.d2-power-label b.low { color: #ef5734; }
.d2-power-track { position: relative; height: 9px; margin-top: 4px; background: #080503; border: 1px inset #755126; overflow: hidden; }
.d2-power-track i { position: absolute; left: 0; top: 0; bottom: 0; }
.d2-power-track .provided { background: #497e37; }
.d2-power-track .used { height: 3px; top: 3px; background: #d6ad4e; }
.d2-power-track .used.low { background: #df3c25; }

#radar { flex: 0 0 34%; min-height: 145px; padding-bottom: 5px; position: relative; }
.d2-radar-frame { position: relative; width: 100%; height: 100%; padding: 5px; border: 4px ridge #9a6935; background: #090604; overflow: hidden; }
#ra-radar { width: 100%; height: 100%; }
.d2-minimap { width: 100%; height: 100%; display: block; object-fit: fill; image-rendering: pixelated; cursor: crosshair; }
.d2-radar-off { display: none; position: absolute; inset: 5px; align-items: center; justify-content: center; background: #090604cc; color: #9a7040; font: 700 10px monospace; letter-spacing: .08em; text-align: center; pointer-events: none; }
#radar.is-offline .d2-radar-off { display: flex; }

#ra-gear.on { display: none; }

@media (max-width: 760px) and (orientation: portrait) {
  #gl { top: 40px; right: 0; bottom: 39vh; width: 100vw; height: calc(61vh - 40px); }
  #sidebar { top: auto; left: 0; right: 0; bottom: 0; width: 100%; height: 39vh; flex-direction: row; border-left: 0; border-top: 5px ridge #c28b47; }
  #d2-context { flex: 1 1 66%; }
  #power { flex: 0 0 30px; width: 22px; padding: 3px; }
  .d2-power-label { writing-mode: vertical-rl; font-size: 7px; }
  .d2-power-track { display: none; }
  #radar { flex: 0 0 32%; min-height: 0; padding: 0 0 0 5px; }
  .d2-top-title { display: none; }
  .d2-top-button { min-width: 58px; padding: 0 7px; font-size: 11px; }
  .d2-credits { margin-left: auto; padding: 0 7px; }
  .d2-credits span { display: none; }
  #d2-speed { width: 56px; }
  .d2-selected { grid-template-columns: 48px 1fr; }
  .d2-selected-icon { width: 48px; }
  .d2-build-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .d2-build-card { min-height: 72px; }
  .d2-build-card .d2-cameo { height: 36px; }
}

@media (max-height: 560px) and (orientation: landscape) {
  #gl { right: 220px; width: calc(100vw - 220px); }
  #sidebar { width: 220px; }
  #radar { min-height: 110px; flex-basis: 32%; }
  .d2-build-card { min-height: 70px; }
  .d2-build-card .d2-cameo { height: 34px; }
}

html.coarse .d2-action, html.coarse .d2-top-button { min-height: 40px; }
html.coarse .d2-build-card { min-height: 76px; }
