/* s2 — modern DOM UI over the WebGL arena (house rule: pixel-art only inside #gl).
   Palette: Widelands forest green + wood + parchment/gold. Theme via CSS vars. */
:root {
  --bg0: #0c160a; --bg1: #12210e;
  --panel0: #1d2f16; --panel1: #142310;
  --wood0: #3d5326; --wood1: #2a3c19;
  --line: #557235; --line2: #3c5222;
  --gold: #e9c766; --gold2: #f2d98a;
  --text: #ece6d0; --dim: #a2b585; --danger: #7a2320; --danger2: #a4322c;
  --safe-t: env(safe-area-inset-top, 0px); --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px); --safe-r: env(safe-area-inset-right, 0px);
}
* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { width: 100%; height: 100%; overflow: hidden; background: var(--bg0);
  font-family: system-ui, 'Segoe UI', Roboto, sans-serif; color: var(--text); }
img { max-width: 100%; }
.hidden { display: none !important; }
.dim { color: var(--dim); }

#gl { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
#minimap { position: fixed; right: calc(10px + var(--safe-r)); top: calc(10px + var(--safe-t));
  width: 192px; height: 192px; border: 2px solid var(--line); border-radius: 6px; background: #0a0f07;
  z-index: 5; display: none; box-shadow: 0 4px 16px rgba(0,0,0,.5); cursor: crosshair; }
html.ingame #minimap { display: block; }
html.ingame.mini-hidden #minimap { display: none; }
#hud { position: fixed; inset: 0; pointer-events: none; z-index: 6; }
#hud.hidden { display: none; }
#hud > * { pointer-events: auto; }
#menus { position: fixed; inset: 0; z-index: 10; }
#menus:empty { display: none; }
#toasts { position: fixed; left: 50%; top: calc(12px + var(--safe-t)); transform: translateX(-50%);
  z-index: 40; display: flex; flex-direction: column; gap: 6px; pointer-events: none; align-items: center; }
.toast { background: rgba(16,26,12,.95); border: 1px solid var(--line); padding: 9px 16px; border-radius: 7px;
  font-size: 14px; animation: fadein .18s; box-shadow: 0 4px 14px rgba(0,0,0,.5); max-width: 92vw; }
.toast.bad { border-color: var(--danger2); background: rgba(60,18,16,.95); }
@keyframes fadein { from { opacity: 0; transform: translateY(-6px);} to { opacity: 1; } }

/* ── menus ── */
.menu-screen { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  padding: calc(12px + var(--safe-t)) 12px calc(12px + var(--safe-b));
  background: radial-gradient(ellipse at 50% 30%, #24361a 0%, var(--bg0) 70%); }
.menu-screen.over { background: rgba(0,0,0,.6); }
.menu-panel { background: linear-gradient(180deg, var(--panel0), var(--panel1)); border: 2px solid var(--line);
  border-radius: 12px; padding: 24px 28px; min-width: 330px; max-width: 620px; width: 100%;
  max-height: 92vh; overflow: auto; box-shadow: 0 16px 48px rgba(0,0,0,.7); }
.menu-panel h1 { font-size: 34px; letter-spacing: 3px; color: var(--gold); text-align: center; margin-bottom: 2px;
  text-shadow: 0 2px 8px #000; font-weight: 800; }
.menu-panel h1 .h1sub { font-size: 18px; letter-spacing: 4px; color: var(--dim); font-weight: 500; }
.menu-panel h2 { font-size: 22px; color: var(--gold); margin-bottom: 12px; }
.menu-sub { text-align: center; color: var(--dim); font-size: 13px; margin-bottom: 16px; line-height: 1.5; }
.menu-foot { text-align: center; color: #6f8256; font-size: 11px; margin-top: 16px; }
.menu-btn { display: block; width: 100%; padding: 13px 18px; margin: 8px 0; border-radius: 8px;
  background: linear-gradient(180deg, var(--wood0), var(--wood1)); color: var(--gold2);
  border: 1px solid var(--line); font-size: 17px; cursor: pointer; text-align: center; min-height: 48px;
  transition: filter .12s, transform .05s; }
.menu-btn small { color: var(--dim); font-size: 13px; }
.menu-btn:hover { filter: brightness(1.18); }
.menu-btn:active { transform: translateY(1px); }
.menu-btn:disabled { opacity: .45; cursor: default; filter: none; }
.menu-btn.ghost { background: transparent; color: var(--text); font-size: 15px; min-height: 42px; }
.menu-btn.ghost:hover { background: rgba(255,255,255,.05); }
.menu-btn.small { font-size: 14px; padding: 9px 12px; min-height: 40px; margin: 0; }
.menu-btn.menu-back { margin-top: 14px; background: transparent; border-color: var(--line2); color: var(--dim); }
.menu-row { display: flex; gap: 8px; align-items: center; margin: 8px 0; }
.menu-row label { flex: 0 0 96px; font-size: 14px; color: #cdd9b2; }
.menu-row input, .menu-row select { flex: 1; padding: 10px; background: #0f1a0b; color: var(--text);
  border: 1px solid var(--line); border-radius: 6px; font-size: 15px; min-height: 42px; }
.menu-row input[type=range] { padding: 0; min-height: 42px; accent-color: var(--gold); }
.rv { flex: 0 0 44px; text-align: right; color: var(--dim); font-size: 13px; }
.chk { display: flex; align-items: center; gap: 8px; font-size: 14px; color: #cdd9b2; margin: 6px 0 10px; cursor: pointer; }
.chk input { width: 18px; height: 18px; accent-color: var(--gold); }
.menu-list { margin: 8px 0; max-height: 46vh; overflow: auto; }
.menu-item { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 11px 12px;
  border: 1px solid var(--line2); border-radius: 8px; margin: 6px 0; cursor: pointer; font-size: 14px; }
.menu-item:hover { background: #24361a; border-color: var(--line); }
.menu-item .sub { color: var(--dim); font-size: 12px; text-align: right; }
.menu-item .live { color: #ff5c4d; font-weight: 700; }
.code { letter-spacing: 4px; color: var(--gold); font-weight: 800; }
.lnk { color: var(--gold2); text-decoration: none; }
.lnk:hover { text-decoration: underline; }
.spinner { width: 34px; height: 34px; margin: 16px auto; border: 3px solid var(--line2);
  border-top-color: var(--gold); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* lobby slots */
.slot-row { display: grid; grid-template-columns: 16px 1fr 128px 116px 104px; gap: 8px; align-items: center;
  margin: 5px 0; font-size: 14px; }
.slot-row .dot { width: 12px; height: 12px; border-radius: 50%; border: 1px solid rgba(0,0,0,.4); }
.slot-row .who { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.slot-row select { padding: 7px; background: #0f1a0b; color: var(--text); border: 1px solid var(--line);
  border-radius: 5px; font-size: 13px; min-height: 38px; }
.lobby-chat { margin: 12px 0; }
.chatbox { height: 110px; overflow: auto; background: #0f1a0b; border: 1px solid var(--line2);
  border-radius: 6px; padding: 8px; font-size: 13px; line-height: 1.5; }
.chatbox div { margin: 1px 0; }

/* map picker */
.map-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px;
  max-height: 60vh; overflow: auto; padding: 2px; }
.map-card { border: 1px solid var(--line2); border-radius: 8px; padding: 8px; cursor: pointer; text-align: center;
  background: #0f1a0b; transition: border-color .12s; }
.map-card:hover { border-color: var(--gold); background: #1a2712; }
.map-card.sea { opacity: .8; }
.map-card img { width: 100%; aspect-ratio: 1; object-fit: contain; image-rendering: pixelated; border-radius: 4px; background: #0a0f07; }
.map-card .nm { font-size: 13px; margin-top: 5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.map-card .sub { font-size: 11px; color: var(--dim); }
.help { font-size: 14px; line-height: 1.7; }
.help p { margin: 8px 0; }
.help b { color: var(--gold2); }

/* ── HUD ── */
#hud-bottom { position: absolute; left: 50%; bottom: calc(8px + var(--safe-b)); transform: translateX(-50%);
  display: flex; gap: 6px; background: rgba(14,24,10,.92); border: 1px solid var(--line);
  border-radius: 12px; padding: 6px; box-shadow: 0 4px 18px rgba(0,0,0,.5); }
#hud-bottom button { position: relative; display: flex; flex-direction: column; align-items: center; gap: 1px;
  min-width: 56px; min-height: 52px; padding: 5px 8px; background: transparent; border: none; color: var(--text);
  font-size: 20px; cursor: pointer; border-radius: 8px; }
#hud-bottom button span { font-size: 10px; color: var(--dim); }
#hud-bottom button:hover { background: rgba(255,255,255,.07); }
#hud-bottom button:active { background: rgba(255,255,255,.12); }
#hud-bottom .badge { position: absolute; top: 2px; right: 6px; background: var(--danger2); color: #fff;
  font-size: 10px; min-width: 16px; height: 16px; line-height: 16px; border-radius: 8px; padding: 0 4px; font-style: normal; }

#hint { position: absolute; left: 50%; bottom: calc(72px + var(--safe-b)); transform: translateX(-50%);
  background: rgba(16,26,12,.94); border: 1px solid var(--gold); color: var(--gold2); padding: 7px 14px;
  border-radius: 20px; font-size: 13px; white-space: nowrap; box-shadow: 0 2px 10px rgba(0,0,0,.5); }

#sel { position: absolute; left: 10px; top: calc(10px + var(--safe-t)); background: rgba(14,24,10,.92);
  border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; font-size: 13px; max-width: 60vw; }
#sel:empty { display: none; }
#chatlog { position: absolute; left: 10px; bottom: calc(72px + var(--safe-b)); font-size: 13px;
  text-shadow: 0 1px 2px #000; max-width: 46vw; }
#chatlog div { margin: 2px 0; background: rgba(0,0,0,.4); padding: 2px 8px; border-radius: 4px; }

/* build panel — side on desktop, bottom sheet on touch */
#build-panel { position: absolute; left: 0; top: 0; bottom: 0; width: 230px;
  background: linear-gradient(90deg, rgba(20,32,15,.97), rgba(18,29,13,.92)); border-right: 2px solid var(--line);
  display: flex; flex-direction: column; padding-top: var(--safe-t); }
.bp-head { display: flex; justify-content: space-between; align-items: center; padding: 10px 12px;
  border-bottom: 1px solid var(--line2); color: var(--gold); font-weight: 700; }
.bp-head button { background: none; border: none; color: var(--dim); font-size: 18px; cursor: pointer; }
.bp-body { flex: 1; overflow-y: auto; padding: 8px; }
.bcat { margin: 8px 0 6px; color: var(--gold); font-size: 12px; text-transform: uppercase; letter-spacing: 1px; }
.bgrid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-bottom: 8px; }
.bbtn { position: relative; aspect-ratio: 1; background: #0f1a0b; border: 1px solid var(--line2); border-radius: 7px;
  cursor: pointer; color: var(--text); font-size: 9px; overflow: hidden; display: flex; align-items: end;
  justify-content: center; padding: 2px; }
.bbtn:hover { border-color: var(--gold); }
.bbtn.act { border-color: var(--gold); box-shadow: 0 0 0 2px var(--gold) inset; }
.bbtn img { position: absolute; inset: 3px 3px 12px; width: calc(100% - 6px); height: calc(100% - 15px);
  object-fit: contain; image-rendering: pixelated; }
.bbtn span { position: relative; z-index: 1; text-shadow: 0 1px 3px #000; background: rgba(0,0,0,.55);
  border-radius: 3px; padding: 0 3px; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* popups (field / flag / attack) */
.popup { position: absolute; z-index: 8; background: rgba(16,26,12,.97); border: 1px solid var(--line);
  border-radius: 10px; padding: 6px; min-width: 190px; box-shadow: 0 8px 26px rgba(0,0,0,.6); display: flex; flex-direction: column; gap: 3px; }
.popup .pop-title { font-size: 12px; color: var(--gold); padding: 4px 6px; }
.popup button { text-align: left; padding: 10px 10px; background: transparent; border: none; color: var(--text);
  font-size: 14px; cursor: pointer; border-radius: 6px; min-height: 42px; }
.popup button:hover { background: rgba(255,255,255,.08); }
.popup .pop-cancel { color: var(--dim); border-top: 1px solid var(--line2); margin-top: 2px; }
.popup .danger { color: #ff8f84; }
.popup input[type=range] { width: 100%; accent-color: var(--gold); }

/* draggable-ish windows (building / messages / stats / settings) */
.win { position: absolute; right: calc(10px + var(--safe-r)); top: calc(214px + var(--safe-t)); z-index: 8;
  width: 288px; max-width: 92vw; max-height: 66vh; overflow: auto; background: linear-gradient(180deg, var(--panel0), var(--panel1));
  border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 10px 30px rgba(0,0,0,.6); }
.win-head { display: flex; justify-content: space-between; align-items: center; padding: 10px 12px;
  border-bottom: 1px solid var(--line2); color: var(--gold); position: sticky; top: 0;
  background: var(--panel0); border-radius: 10px 10px 0 0; }
.win-head .win-close { background: none; border: none; color: var(--dim); font-size: 17px; cursor: pointer; }
.win-body { padding: 12px; }
.pbar { height: 12px; background: #0f1a0b; border: 1px solid var(--line2); border-radius: 6px; overflow: hidden; margin: 4px 0; }
.pbar i { display: block; height: 100%; background: linear-gradient(90deg, #6b8a3f, var(--gold)); }
.qrow { display: grid; grid-template-columns: 22px 1fr auto auto auto auto auto; gap: 5px; align-items: center;
  padding: 4px 0; font-size: 13px; border-bottom: 1px solid rgba(255,255,255,.05); }
.qrow img { width: 22px; height: 22px; object-fit: contain; image-rendering: pixelated; }
.qrow .qn { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.qrow .qv { color: var(--dim); font-size: 12px; }
.qrow .qb, .qrow .qp { width: 26px; height: 26px; background: var(--wood1); border: 1px solid var(--line2);
  color: var(--text); border-radius: 5px; cursor: pointer; font-size: 12px; }
.qrow .qw { min-width: 16px; text-align: center; }
.qrow .qp.on { color: var(--gold); border-color: var(--gold); }
.win-actions { display: flex; flex-direction: column; gap: 6px; margin-top: 10px; }
.wbtn { padding: 9px 10px; background: var(--wood1); border: 1px solid var(--line2); color: var(--text);
  border-radius: 6px; cursor: pointer; font-size: 13px; min-height: 40px; }
.wbtn:hover { filter: brightness(1.15); }
.wbtn.up { border-color: var(--line); color: var(--gold2); }
.wbtn.danger { background: rgba(70,20,18,.7); border-color: var(--danger2); color: #ff9f95; }
#mm-pop { display: flex; flex-direction: column; gap: 8px; padding: 12px; width: 220px; right: calc(10px + var(--safe-r)); top: auto; bottom: calc(72px + var(--safe-b)); }
#mm-pop button { padding: 9px; background: var(--wood1); border: 1px solid var(--line2); color: var(--text); border-radius: 6px; cursor: pointer; min-height: 40px; }
#mm-pop label { font-size: 13px; color: var(--text); display: flex; flex-direction: column; gap: 3px; }
#mm-pop input[type=range] { width: 100%; accent-color: var(--gold); }
#mm-pop .danger { background: rgba(70,20,18,.75) !important; border-color: var(--danger2); }
.msg-list .msg-row { padding: 8px; border: 1px solid var(--line2); border-radius: 6px; margin-bottom: 6px; cursor: pointer; }
.msg-list .msg-row:hover { background: #24361a; }
.msg-list .msg-t { color: var(--gold2); font-size: 13px; }
.msg-list .msg-b { font-size: 12px; color: var(--dim); }
table.stat { width: 100%; border-collapse: collapse; font-size: 13px; }
table.stat th, table.stat td { text-align: left; padding: 5px 6px; border-bottom: 1px solid var(--line2); }
table.stat th { color: var(--gold); font-size: 11px; text-transform: uppercase; }
table.stat .dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; }

/* ── touch layout ── */
html.touch #build-panel { left: 0; right: 0; top: auto; bottom: 0; width: 100%; height: 46vh;
  border-right: none; border-top: 2px solid var(--line); border-radius: 14px 14px 0 0;
  transform: translateY(105%); transition: transform .2s; padding-top: 0; }
html.touch #build-panel.open { transform: none; }
html.touch #build-panel.hidden { display: flex !important; transform: translateY(105%); }
html.touch .bgrid { grid-template-columns: repeat(4, 1fr); }
html.touch .bbtn { font-size: 9px; }
html.touch #minimap { width: 132px; height: 132px; }
html.touch #hint { bottom: calc(78px + var(--safe-b)); }
html.touch .win { top: auto; bottom: calc(74px + var(--safe-b)); right: 8px; left: 8px; width: auto; max-height: 54vh; }
html.touch #mm-pop { left: 8px; right: 8px; width: auto; }
html.touch #sel { max-width: 70vw; font-size: 12px; }

/* landscape phone: keep the toolbar compact */
@media (max-height: 480px) and (orientation: landscape) {
  #hud-bottom button span { display: none; }
  #hud-bottom button { min-height: 44px; min-width: 46px; font-size: 18px; }
  html.touch #build-panel { height: 72vh; }
}
