/* RTS interface in the HerpDerp skin of Puddlehold: Siege Happens: flat brown slabs with a thick ink outline,
   gold corner ornaments (9-slice panel.png), parchment plaques, pixel fonts at design size. */
@font-face { font-family: 'Jersey 10'; src: url(/assets/Jersey10.woff2) format('woff2'), url(../assets/herpderp/ui/fonts/Jersey10.ttf) format('truetype'); font-display: swap; }
@font-face { font-family: 'Micro 5'; src: url(../assets/herpderp/ui/fonts/Micro5.ttf) format('truetype'); font-display: swap; }

:root {
  --wood: #6e3f1c;
  --wood-dark: #3a2210;
  --wood-light: #8f5a2c;
  --parch: #fff1c2;
  --gold: #ffd43a;
  --ink: #2b1a0e;
  --text: #fff6dc;
  --muted: #eed9a8;
  --good: #59d24a;
  --bad: #ff5a3c;
  /* Readable text (15.11.2026): sans face for all text; Jersey 10 (--title) only for gold
     titles and names, at --tpx or --px2. */
  --px: 16px;
  --tpx: 18.667px;
  --px2: 37.333px;
  --tiny: 600 13px system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --font: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --title: 'Jersey 10', 'Trebuchet MS', 'Segoe UI', sans-serif;
  --rim: 0 0 0 3px var(--ink), 0 6px 0 rgba(0, 0, 0, .3);
  --slab: #5a3a1c;
  --slab-hover: #7a4f26;
  --deep: #1a1209;
  --shade: rgba(43, 26, 14, .9);
  --panel-img: url(../assets/herpderp/ui/panel.png);
  --hud-h: 236px;
  --slot-img: url(../assets/herpderp/ui/slot.png);
}

* { box-sizing: border-box; font-size: var(--px); font-weight: 600; letter-spacing: 0; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #1d140b; color: var(--text); font-family: var(--font); font-synthesis: none; -webkit-font-smoothing: antialiased; user-select: none; }
/* gold titles and names keep the pixel face */
h1, h2, h3, .logo, .fac b, #result-title, #players .ph, #tips .ph, .phl .facpick > span { font-family: var(--title) !important; font-weight: 400; -webkit-font-smoothing: none; }
h1, h2, h3, .fac b, #players .ph, #tips .ph, .phl .facpick > span { font-size: var(--tpx); }
canvas#view { position: fixed; inset: 0; width: 100vw; height: 100vh; display: block; image-rendering: pixelated; cursor: url(../assets/ui/cursor_move.png) 2 2, default; }
/* HerpDerp v6: light haze at the top, soft dark edge and a warm wash over the world, same as Raid. */
#atmosphere {
  position: fixed; inset: 0; pointer-events: none;
  background:
    linear-gradient(to bottom, rgba(206,214,222,.14) 0%, rgba(206,214,222,.05) 18%, rgba(206,214,222,0) 36%),
    radial-gradient(ellipse 78% 72% at 50% 55%, rgba(20,12,4,0) 60%, rgba(20,12,4,.26) 100%),
    linear-gradient(rgba(255,186,96,.06), rgba(255,186,96,.06));
}
/* Context cursors (input.js sets data-cur): target ring in attack/move mode, sword on enemies, axe on trees, pickaxe on mines, hammer to build, wrench to repair. */
canvas#view[data-cur=aim] { cursor: url(../assets/ui/cursor_aim.png) 14 14, crosshair; }
canvas#view[data-cur=attack] { cursor: url(../assets/ui/cursor_attack.png) 2 2, pointer; }
canvas#view[data-cur=axe] { cursor: url(../assets/ui/cursor_axe.png) 16 16, pointer; }
canvas#view[data-cur=pick] { cursor: url(../assets/ui/cursor_pick.png) 16 16, pointer; }
canvas#view[data-cur=build] { cursor: url(../assets/ui/cursor_build.png) 16 16, pointer; }
canvas#view[data-cur=repair] { cursor: url(../assets/ui/cursor_repair.png) 16 16, pointer; }
.hidden { display: none !important; }
#loading { position: fixed; inset: 0; display: grid; place-items: center; background: #1d140b; z-index: 50; }

.panel {
  background: var(--wood); color: var(--text);
  border: 12px solid transparent; border-image-source: var(--panel-img);
  border-image-slice: 36 fill; border-image-width: 36px; border-image-repeat: round;
  padding: 18px 26px 22px; box-shadow: 0 8px 0 rgba(0, 0, 0, .35);
}
.btn {
  font-family: var(--font); color: var(--ink); background: linear-gradient(#fff5d0, #efd48f);
  border: 3px solid var(--ink); border-radius: 10px; padding: 4px 14px; cursor: pointer; box-shadow: 0 3px 0 var(--ink);
}
.btn:hover { background: linear-gradient(#fffbe8, #f6dc9c); }
.btn:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--ink); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.big { padding: 8px 22px; }
.btn.small { padding: 0 10px; }
input, select {
  font-family: var(--font); color: var(--ink); background: var(--parch); border: 3px solid var(--ink);
  border-radius: 8px; padding: 2px 8px;
}
.row { display: flex; gap: 10px; align-items: center; justify-content: center; margin: 8px 0; }
.hint { color: var(--muted); text-align: center; min-height: 1em; }
.fine { color: var(--muted); text-align: center; margin: 4px 0 0; line-height: 1.1; }
.error { color: #ffb4a0; text-align: center; min-height: 1em; }

/* Screens */
.screen { position: fixed; inset: 0; display: grid; place-items: center; z-index: 20; background: radial-gradient(ellipse at 50% 40%, rgba(36, 19, 7, .25), rgba(24, 12, 4, .8)); overflow: auto; }
.menu-panel { width: min(640px, 94vw); text-align: center; position: relative; }
.logo { font-size: var(--px2); color: var(--gold); text-shadow: 0 3px 0 var(--ink); margin: 6px 0 0; }
.sublogo { color: var(--muted); margin-bottom: 12px; }
.lang { position: absolute; right: 4px; top: 2px; display: flex; gap: 6px; z-index: 1; }
.lang button.on { background: var(--gold); color: var(--ink); }
/* Primary menu actions: orange like the play buttons on puddlehold.com. */
#menu .btn.big, #lobby .btn.big { background: linear-gradient(#ffb64a, #ec8c22); box-shadow: 0 4px 0 var(--ink), inset 0 2px 0 rgba(255, 255, 255, .45); transition: transform .1s ease, filter .1s ease; }
#menu .btn.big:hover:not(:disabled), #lobby .btn.big:hover:not(:disabled) { filter: brightness(1.08); transform: translateY(-1px); }
#menu .btn.big:active:not(:disabled), #lobby .btn.big:active:not(:disabled) { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); background: linear-gradient(#e07f1f, #c86a14); }
.name-hint { margin: -2px auto 6px; max-width: 34em; font-size: 11px; line-height: 1.3; color: var(--muted); text-align: center; }
.field { display: flex; gap: 10px; align-items: center; justify-content: center; margin: 6px 0; }
.facs { display: flex; gap: 12px; justify-content: center; margin: 6px 0 10px; }
.fac {
  width: 31%; display: flex; flex-direction: column; align-items: center; gap: 2px; cursor: pointer; font-family: var(--font);
  background: var(--slab); color: var(--text); border: 3px solid var(--ink); border-radius: 12px; padding: 8px;
}
.fac.on { background: var(--wood-light); outline: 3px solid var(--gold); }
.fac b { color: var(--gold); text-shadow: 0 2px 0 var(--ink); display: flex; align-items: center; gap: 6px; }
.fac b canvas { width: 24px; height: 24px; }
.fac small { font: var(--tiny); line-height: 1.05; color: var(--text); }
.fac canvas { image-rendering: pixelated; }
.howto { text-align: left; margin-top: 10px; color: var(--muted); }
.howto summary { cursor: pointer; }
.imprint-link a { color: inherit; }
/* Pixel font sharp at its design size; tiny (11px) was too small for the controls text. */
.howto-text { white-space: pre-line; font-family: var(--font); font-size: var(--px); line-height: 1.35; color: var(--text); text-align: left; overflow-wrap: anywhere; }
.howto-text { max-height: min(40vh, 320px); overflow-y: auto; margin-top: 6px; padding: 8px 12px; background: rgba(43, 26, 14, .55); border: 3px solid var(--ink); border-radius: 10px; user-select: text; }

.lobby-panel h2 { margin: 0 0 8px; color: var(--gold); }
#lobby-players { width: 100%; border-collapse: collapse; }
#lobby-players td { padding: 3px 6px; border-bottom: 2px solid rgba(0, 0, 0, .25); }
#lobby-players .sw { width: 18px; height: 18px; border: 2px solid var(--ink); border-radius: 4px; display: inline-block; vertical-align: middle; }
#lobby-players select { padding: 0 4px; }

/* HUD */
/* viewport-fit=cover: the field fills the screen, the HUD keeps clear of a notch (LOR-31) */
#hud { position: fixed; inset: 0 env(safe-area-inset-right, 0px) 0 env(safe-area-inset-left, 0px); pointer-events: none; z-index: 10; --parch-img: url(../assets/herpderp/ui/parchment.png); --slot: 58px; --mm: 176px; --bw: min(1240px, 100%); }
#hud > * { pointer-events: auto; }

/* Flat ink-outlined slab used by the smaller HUD panels. */
.hpanel { background: var(--wood); border: 3px solid var(--ink); border-radius: 14px; box-shadow: 0 6px 0 rgba(0, 0, 0, .28), inset 0 2px 0 var(--wood-light); }

/* Top bar: floating strip with rounded ends and gold studs. */
#topbar {
  position: absolute; left: 50%; top: 0; transform: translateX(-50%); display: flex; align-items: center; gap: 20px; padding: 6px 30px 7px;
  background: var(--wood); border: 3px solid var(--ink); border-top: 0; border-radius: 0 0 26px 26px;
  box-shadow: 0 6px 0 rgba(0, 0, 0, .28), inset 0 2px 0 var(--wood-light), inset 0 -3px 0 var(--wood-dark);
}
#topbar::before, #topbar::after { content: ''; position: absolute; bottom: 8px; width: 9px; height: 9px; background: var(--gold); border: 2px solid var(--ink); transform: rotate(45deg); }
#topbar::before { left: 9px; }
#topbar::after { right: 9px; }
.res { display: flex; align-items: center; gap: 6px; min-width: 84px; }
.res b { color: var(--parch); text-shadow: 0 2px 0 var(--ink); font-variant-numeric: tabular-nums; display: inline-block; min-width: 5ch; }
#r-supply { min-width: 7ch; }
.res b.low { color: var(--bad); }
.ico { width: 28px; height: 28px; display: inline-block; background: center / contain no-repeat; image-rendering: pixelated; }
.ico-gold { background-image: url(../assets/herpderp/coins.png); }
.ico-wood { background-image: url(../assets/herpderp/woodpile.png); }
.ico-food { background-image: url(../assets/herpderp/ico_food.png); }
/* Tabular digits and a fixed width: the bar must not change width while the clock ticks. */
#clock { color: var(--muted); font-variant-numeric: tabular-nums; min-width: calc(4.5ch + 24px); text-align: center; padding: 0 10px; border: 2px dashed var(--wood-light); border-radius: 8px; }
.tb-btns { display: flex; gap: 7px; margin-left: 4px; }
.rbtn {
  position: relative; width: 30px; height: 30px; padding: 0; border-radius: 50%; border: 3px solid var(--ink); cursor: pointer; line-height: 1; font-family: var(--font);
  color: var(--ink); background: linear-gradient(#ffb64a, #ec8c22); box-shadow: 0 3px 0 var(--ink), inset 0 2px 0 rgba(255, 255, 255, .45);
}
.rbtn:hover { filter: brightness(1.1); }
.rbtn:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--ink); }
.rbtn.off { background: linear-gradient(#c9b088, #a8906a); }
/* Painted top bar icons (scripts/lords-sprites.py --tb), shared with the other Puddlehold games. */
.tbi { display: block; width: 18px; height: 18px; margin: auto; background: center / contain no-repeat; image-rendering: pixelated; pointer-events: none; }
.tbi-music { background-image: url(../assets/ui/tb_music.png); }
.tbi-sound { background-image: url(../assets/ui/tb_sound.png); }
.tbi-lock { background-image: url(../assets/ui/tb_lock.png); }
.tbi-help { background-image: url(../assets/ui/tb_help.png); }
.tbi-menu { background-image: url(../assets/ui/tb_menu.png); }
.rbtn.off::after { content: ''; position: absolute; left: 3px; right: 3px; top: 50%; height: 3px; background: var(--ink); transform: rotate(-45deg); }

/* Messages: parchment plaques, top left. */
#msgs { position: absolute; left: 12px; top: 12px; width: min(340px, 34vw); display: flex; flex-direction: column; align-items: stretch; gap: 2px; pointer-events: none; }
#msgs div {
  color: var(--ink); line-height: 1.1; overflow-wrap: anywhere; transition: opacity .5s;
  border: 10px solid transparent; border-image: var(--parch-img) 20 fill / 10px stretch; margin: -3px 0; padding: 0 4px;
}
#msgs div.err { color: #8a3f00; }
#msgs div.alert, #msgs div.camplost { color: #b01c0c; }
#msgs div.found { color: #7a4f00; }
#msgs div.campwon { color: #1f6b1a; }

/* Shortcut overview (top bar "?"): dimmed backdrop, wood panel, gold key caps. */
#help { position: absolute; inset: 0; z-index: 5; display: flex; align-items: flex-start; justify-content: center; padding-top: 50px; background: rgba(0, 0, 0, .45); }
.help-panel { width: min(1240px, 96vw); max-height: calc(100vh - 54px); overflow: hidden; text-align: center; padding: 8px 16px 8px; }
.help-panel h2 { margin: 0 0 8px; color: var(--gold); text-shadow: 0 2px 0 var(--ink); }
/* Three columns, so the whole list fits a 1280x720 window without a scroll bar. */
.sc-grid { columns: 3; column-gap: 10px; text-align: left; }
.sc-sec { break-inside: avoid; margin-bottom: 6px; background: rgba(43, 26, 14, .55); border: 3px solid var(--ink); border-radius: 10px; padding: 4px 10px 6px; }
.sc-sec h3 { margin: 0 0 2px; color: var(--gold); text-shadow: 0 2px 0 var(--ink); }
.sc-sec ul { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.sc-sec li { display: grid; grid-template-columns: minmax(96px, auto) 1fr; gap: 8px; align-items: start; line-height: 1.05; font: var(--tiny); }
.sc-keys { display: flex; flex-wrap: wrap; align-items: center; gap: 2px; }
.sc-keys i { font-style: normal; color: var(--muted); padding: 0 1px; }
.sc-keys kbd {
  font: var(--tiny); color: var(--ink); background: linear-gradient(#ffe27a, var(--gold)); border: 2px solid var(--ink); border-radius: 6px;
  padding: 0 5px; min-width: 22px; height: 22px; display: inline-grid; place-items: center; box-shadow: 0 2px 0 rgba(0, 0, 0, .35); white-space: nowrap;
}
.sc-desc { color: var(--text); font: var(--tiny); }
/* Close button in the header row instead of below the list: saves the height of one row at 720 px. */
.help-panel { position: relative; }
.help-panel #help-close { position: absolute; top: 4px; right: 14px; margin: 0; }

/* Players panel (right column, collapsible) */
#right-col { position: absolute; right: 12px; top: 58px; width: 230px; display: flex; flex-direction: column; align-items: flex-end; gap: 8px; pointer-events: none; }
#right-col > * { pointer-events: auto; }
#players, #tips { width: 100%; padding: 4px 10px 6px; }
#players .ph, #tips .ph { all: unset; box-sizing: border-box; display: flex; width: 100%; justify-content: space-between; align-items: center; cursor: pointer; color: var(--gold); font-family: var(--font); font-size: var(--px); text-shadow: 0 2px 0 var(--ink); }
#players .chev, #tips .chev { width: 0; height: 0; border: 6px solid transparent; border-top-color: var(--gold); border-bottom: 0; transition: transform .15s; }
#players.closed .chev, #tips.closed .chev { transform: rotate(-90deg); }
#players.closed #players-list, #tips.closed #tips-body { display: none; }
#tips-body { margin-top: 4px; padding: 4px 8px 6px; background: rgba(43, 26, 14, .45); border-radius: 8px; }
#tip-now { color: var(--parch); line-height: 1.1; min-height: 3.3em; }
#tip-now.now { box-shadow: -4px 0 0 var(--gold); padding-left: 6px; }
#tip-now.now::before { content: attr(data-now); display: inline-block; margin-right: 6px; padding: 0 4px; font: var(--tiny); color: var(--ink); background: var(--gold); border-radius: 4px; }
.tip-nav { display: flex; justify-content: space-between; align-items: center; margin-top: 4px; color: var(--muted); font: var(--tiny); }
.rbtn.sm { width: 22px; height: 22px; border-width: 2px; font-size: var(--px); }
.rbtn.on { background: linear-gradient(#ffe06a, #d9a01a); }
#players-list { margin-top: 4px; display: grid; gap: 3px; }
#players .pl { display: flex; gap: 8px; align-items: center; padding: 2px 6px; background: rgba(43, 26, 14, .45); border-radius: 8px; }
#players .pl.me { box-shadow: inset 0 0 0 2px var(--gold); }
#players .sw { flex: none; width: 28px; height: 28px; border: 2px solid var(--ink); border-radius: 6px; display: grid; place-items: center; }
#players .sw canvas { width: 22px; height: 22px; image-rendering: pixelated; }
#players .pt { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1; }
#players .pt b { color: var(--parch); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#players .pt small { font: var(--tiny); color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#players .st { color: var(--good); }
#players .dead { opacity: .55; }
#players .dead .pt b { text-decoration: line-through; }
#players .dead .st { color: var(--bad); }

/* Bottom panel: centred, ornate 9-slice with gold corners. */
#bottom {
  position: absolute; left: 50%; bottom: 0; transform: translateX(-50%); width: var(--bw); height: var(--hud-h);
  display: flex; gap: 12px; align-items: stretch; padding: 14px 24px 6px;
  background: var(--wood); border: 12px solid transparent; border-bottom: 0; border-radius: 20px 20px 0 0;
  border-image-source: var(--panel-img); border-image-slice: 36 fill; border-image-width: 36px 36px 0 36px; border-image-repeat: round;
  box-shadow: 0 -3px 0 rgba(0, 0, 0, .25);
}
#minimap-wrap { flex: none; align-self: center; width: calc(var(--mm) + 10px); height: calc(var(--mm) + 10px); background: var(--deep); border: 3px solid var(--ink); border-radius: 10px; padding: 2px; box-shadow: 0 4px 0 rgba(0, 0, 0, .3), inset 0 0 0 2px var(--wood-light); display: grid; place-items: center; overflow: hidden; }
#minimap { width: var(--mm); height: var(--mm); image-rendering: pixelated; cursor: pointer; }
#info { flex: 1; min-width: 0; display: flex; gap: 12px; align-items: stretch; padding: 6px 8px; background: rgba(43, 26, 14, .35); border-radius: 12px; overflow: hidden; }
#card { flex: none; display: grid; grid-template-columns: repeat(4, var(--slot)); grid-template-rows: repeat(3, var(--slot)); gap: 5px; align-self: center; padding: 6px; background: rgba(43, 26, 14, .45); border-radius: 12px; }

/* Framed square slots (steel rim, dark inside). */
.slot {
  position: relative; border: 3px solid var(--ink); border-radius: 10px; background: var(--slab); border-image: var(--slot-img) 8 fill / 8px; box-shadow: 0 3px 0 rgba(0, 0, 0, .3);
}
.cbtn { cursor: pointer; padding: 5px; display: grid; place-items: center; overflow: hidden; color: var(--parch); font-family: var(--font); }
.cbtn:hover:not(:disabled) { filter: brightness(1.15); }
.cbtn.on { outline: 3px solid var(--gold); outline-offset: -1px; box-shadow: 0 0 0 3px var(--gold), 0 3px 0 rgba(0, 0, 0, .3); }
.cbtn.off canvas, .cbtn.off .sym { filter: grayscale(.8) brightness(.65); }
.cbtn.blank { cursor: default; opacity: .75; }
/* Thumbnails take their size from the slot, never from the canvas: thumbCanvas sizes the
   backing store to the shown size in device pixels. */
.cbtn canvas { image-rendering: pixelated; width: 100%; height: 100%; object-fit: contain; }
.cbtn .sym { font-size: 26px; font-weight: 700; color: var(--parch); text-shadow: 0 2px 0 var(--ink); line-height: 1; }
.cbtn .hk { position: absolute; left: -3px; top: -3px; z-index: 1; min-width: 22px; height: 22px; display: grid; place-items: center; background: var(--gold); border: 2px solid var(--ink); border-radius: 6px; padding: 0 4px; box-sizing: border-box; box-shadow: 0 2px 0 rgba(0, 0, 0, .35); }
.cbtn .hk canvas { display: block; width: auto; height: auto; max-width: none; image-rendering: pixelated; }
.cbtn .lvl { position: absolute; right: 2px; bottom: 0; font: var(--tiny); color: var(--parch); text-shadow: 1px 0 0 var(--ink), -1px 0 0 var(--ink), 0 1px 0 var(--ink), 0 -1px 0 var(--ink); }

/* Selection info: portrait frame, details, chips, framed production/selection slots. */
#info.empty { background: rgba(43, 26, 14, .2); }
.portrait { flex: none; width: 112px; align-self: center; height: 112px; background: radial-gradient(circle at 50% 40%, var(--wood-light), var(--wood-dark)); border: 3px solid var(--ink); border-radius: 14px; box-shadow: 0 4px 0 rgba(0, 0, 0, .3), inset 0 0 0 2px var(--gold); display: grid; place-items: center; overflow: hidden; }
.portrait canvas { image-rendering: pixelated; width: 100%; height: 100%; max-width: 100px; max-height: 100px; object-fit: contain; }
.details { flex: 1; display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.details h3 { margin: 0; color: var(--gold); text-shadow: 0 2px 0 var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.details .sub { color: var(--muted); line-height: 1; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 3px 6px; margin-top: 2px; }
.stats span { display: flex; justify-content: space-between; align-items: baseline; gap: 4px; min-width: 0; padding: 0 6px; background: rgba(43, 26, 14, .45); border-radius: 8px; color: var(--parch); white-space: nowrap; }
.stats span.wide { grid-column: 1 / -1; }
.stats i { font-style: normal; color: var(--muted); overflow: hidden; text-overflow: ellipsis; }
.bar { height: 20px; background: #2a1708; border: 3px solid var(--ink); border-radius: 10px; position: relative; overflow: hidden; box-shadow: 0 2px 0 rgba(0, 0, 0, .25); flex: none; }
.bar i { position: absolute; inset: 0 auto 0 0; border-radius: 7px; box-shadow: inset 0 2px 0 rgba(255, 255, 255, .35), inset 0 -2px 0 rgba(0, 0, 0, .25); }
.bar i.hi, .mini i.hi { background: linear-gradient(#8be873, #3aa82c); }
.bar i.mid, .mini i.mid { background: linear-gradient(#ffe06a, #d9a01a); }
.bar i.lo, .mini i.lo { background: linear-gradient(#ff7a60, #d42a1c); }
.bar.prog i, .mini.prog i { background: linear-gradient(#ffe06a, #d9a01a); }
.bar span { position: absolute; inset: 0; text-align: center; line-height: 15px; color: #fff6dc; text-shadow: 1px 0 0 var(--ink), -1px 0 0 var(--ink), 0 1px 0 var(--ink), 0 -1px 0 var(--ink); }
.slots { flex: none; display: grid; grid-template-columns: repeat(5, 46px); grid-auto-rows: 46px; gap: 5px; align-content: center; padding: 6px; background: rgba(43, 26, 14, .45); border-radius: 12px; }
.slots.long { grid-template-columns: repeat(4, 46px); }
.slots.multi { flex: 1; grid-template-columns: repeat(auto-fill, 46px); align-content: start; justify-content: start; overflow: hidden; }
.slots .slot { cursor: pointer; padding: 5px; display: grid; place-items: center; overflow: hidden; }
.slots .slot.blank { cursor: default; opacity: .6; }
.slots .slot:not(.blank):hover { filter: brightness(1.15); }
.slots canvas { image-rendering: pixelated; width: 100%; height: 100%; object-fit: contain; }
.mini { position: absolute; left: 4px; right: 4px; bottom: 3px; height: 6px; background: #2a1708; border: 1px solid var(--ink); border-radius: 3px; overflow: hidden; }
.mini i { position: absolute; inset: 0 auto 0 0; }
#info.many .details { flex: 0 0 150px; }

/* Idle worker button: sits on the top left of the bottom panel, outside it so the panel never rebuilds for it. */
#idle-btn { position: absolute; left: calc((100% - var(--bw)) / 2 + 22px); bottom: calc(var(--hud-h) + 6px); width: var(--slot); height: var(--slot); }
#idle-btn .cnt { position: absolute; right: 3px; bottom: -2px; font-size: 28px; line-height: 1; color: var(--gold); font-family: var(--font); text-shadow: 1px 0 0 var(--ink), -1px 0 0 var(--ink), 0 1px 0 var(--ink), 0 -1px 0 var(--ink), 0 2px 0 var(--ink); }
#tooltip { position: absolute; right: max(12px, calc((100% - var(--bw)) / 2 + 12px)); bottom: calc(var(--hud-h) + 8px); width: 340px; background: var(--shade); border: 3px solid var(--ink); border-radius: 10px; padding: 8px 10px; pointer-events: none; }
#tooltip.left { right: auto; left: calc((100% - var(--bw)) / 2 + 22px + var(--slot) + 10px); width: auto; max-width: 340px; }
#tooltip b { color: var(--gold); }
#tooltip .cost { color: var(--parch); display: flex; gap: 12px; margin: 2px 0; }
#tooltip .cost .no { color: var(--bad); }
#tooltip p { margin: 4px 0 0; line-height: 1.1; color: var(--text); }

#result { position: fixed; inset: 0; display: grid; place-items: center; background: rgba(0, 0, 0, .55); z-index: 30; }
.result-panel { width: min(980px, 96vw); max-height: 94vh; overflow-y: auto; text-align: center; }
#result-title { color: var(--gold); font-size: var(--px2); margin: 4px 0 0; text-shadow: 0 3px 0 var(--ink); }
#result-time { color: var(--muted); margin: 0 0 10px; }
#result-rank { margin: 0 0 10px; }
#result-rank[hidden], #result-record[hidden], #result-record-form[hidden] { display: none; }
/* E-04: a top-ten match asks for the name on the result screen; nothing is entered without it. */
#result-record { margin: 0 0 12px; }
#result-record p { margin: 0; }
#result-record input { width: 12em; }
#result-record-hint { color: var(--muted); }
#result-record-hint.err { color: #ffb08a; }
#result-stats { width: 100%; margin-bottom: 14px; border-collapse: collapse; font-variant-numeric: tabular-nums; }
#result-stats th, #result-stats td { padding: 2px 8px; text-align: right; line-height: 1.15; white-space: nowrap; }
#result-stats th { color: var(--muted); }
#result-stats .grp th { color: var(--gold); text-align: center; text-shadow: 0 2px 0 var(--ink); padding-bottom: 0; }
#result-stats .sub th { border-bottom: 3px solid var(--ink); }
#result-stats .gs { border-left: 3px solid rgba(43, 26, 14, .6); }
#result-stats .pl { text-align: left; max-width: 220px; overflow: hidden; text-overflow: ellipsis; }
#result-stats tbody tr:nth-child(even) { background: rgba(43, 26, 14, .25); }
#result-stats tr.me td { color: var(--gold); }
#result-stats tr.lost td { opacity: .8; }
#result-stats .mark { display: inline-block; width: 1.1em; height: 1.1em; vertical-align: -0.15em; background: center / contain no-repeat; image-rendering: pixelated; }
#result-stats .mark.star { background-image: url(../assets/herpderp/mark_star.png); }
#result-stats .mark.cross { background-image: url(../assets/herpderp/mark_cross.png); }
.lock-mark { display: inline-block; width: 1em; height: 1em; vertical-align: -0.12em; margin-right: 0.25em; background: url(../assets/ui/tb_lock.png) center / contain no-repeat; image-rendering: pixelated; }
#result-stats tr.won .mark { color: var(--gold); }
#result-stats .sw { display: inline-block; width: 14px; height: 14px; margin-right: 6px; border: 2px solid var(--ink); vertical-align: -1px; }
.btn.plaque { background: linear-gradient(#fff5d0, #efd48f); }

@media (max-width: 1180px) {
  #hud { --slot: 52px; --mm: 156px; }
  .stats { grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); }
  .slots { grid-template-columns: repeat(5, 40px); grid-auto-rows: 40px; }
  .slots.long { grid-template-columns: repeat(4, 40px); }
  .slots.multi { grid-template-columns: repeat(auto-fill, 40px); }
  #bottom { gap: 8px; padding: 14px 18px 6px; }
  .portrait { width: 96px; height: 96px; }
}
@media (max-width: 1400px) { #msgs { top: 56px; } }
@media (max-width: 1060px) {
  #msgs { width: min(300px, 30vw); }
  #right-col { width: 190px; }
  #info.many .details { flex-basis: 120px; }
}
@media (max-width: 900px) {
  .portrait { display: none; }
}

/* Puddlehold chips (same look as the DE/EN buttons on puddlehold.com): parchment, ink rim, gold when active. */
.home-link, .lang button, .mute-btn {
  display: inline-flex; align-items: center; justify-content: center; height: 30px; min-width: 40px; padding: 0 10px; line-height: 1;
  background: #ead6a4; color: #5a4120; border: 3px solid var(--ink); border-radius: 10px; box-shadow: 0 3px 0 var(--ink);
  font-family: var(--font); text-decoration: none; cursor: pointer; transition: transform .1s ease, filter .1s ease;
}
.home-link:hover, .lang button:hover, .mute-btn:hover { filter: brightness(1.08); transform: translateY(-1px); }
.home-link:active, .lang button:active, .mute-btn:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--ink); }
.mute-btn { position: absolute; left: 4px; top: 2px; padding: 0 6px; font-size: 16px; }
.mute-btn.off { opacity: .6; }
.home-link { position: absolute; left: 54px; top: 2px; }
/* Meadow with walking figures along the bottom edge, as on puddlehold.com. */

/* Faction themes: same HerpDerp slabs and gold ornaments, faction colours underneath. */
body[data-fac="sultanate"] {
  --wood: #1f6b68; --wood-dark: #0f3a39; --wood-light: #2c8f88; --slab: #18504e; --slab-hover: #237571;
  --deep: #08201f; --shade: rgba(10, 40, 39, .9); --gold: #ffd43a; --muted: #cfe8d8;
  --panel-img: url(../assets/ui/panel_sultanate.png); --slot-img: url(../assets/ui/slot_sultanate.png);
}
body[data-fac="shogunate"] {
  --wood: #8a281e; --wood-dark: #2a1414; --wood-light: #b23a2a; --slab: #3a1c1a; --slab-hover: #5a2a24;
  --deep: #140a0a; --shade: rgba(32, 14, 14, .92); --gold: #ffd43a; --muted: #f3d6c4;
  --panel-img: url(../assets/ui/panel_shogunate.png); --slot-img: url(../assets/ui/slot_shogunate.png);
}

/* Menu = the Puddlehold lobby (client/vendor/puddlehold-lobby, draft C, 04.11.2026). */
#menu { place-items: start center; }
.menu-wrap { width: min(1060px, 96vw); display: flex; flex-direction: column; gap: 8px; margin: auto 0; padding: 12px 0; }
.menu-msg { margin: 0; text-align: center; color: var(--gold); text-shadow: 0 2px 0 var(--ink); }
.menu-foot { display: flex; flex-wrap: wrap; gap: 4px 24px; justify-content: center; align-items: flex-start; }
.menu-foot .howto { margin-top: 0; color: var(--gold); }
.menu-foot details { position: relative; }
/* Opened texts float above the lobby, so the menu never grows a scroll bar. */
.menu-foot .howto-text { position: absolute; left: 50%; transform: translateX(-50%); bottom: calc(100% + 6px); z-index: 5; width: min(620px, 86vw); max-height: min(60vh, 420px); background: var(--deep); box-shadow: 0 6px 0 rgba(0, 0, 0, .35); }
.phl .name-hint { display: block; margin: 0 auto; }
.phl .facpick { margin-top: 8px; }
.phl .facpick > span { display: block; color: var(--gold); text-shadow: 0 2px 0 var(--ink); }
.phl .facs { gap: 8px; margin: 2px 0 0; }
.phl .fac { padding: 2px 4px 4px; border-radius: 10px; }
.phl .fac > img { width: 56px; height: 56px; image-rendering: pixelated; }
.phl .fac b { font-size: 16px; gap: 4px; }
.phl .fac b img { width: 18px; height: 18px; image-rendering: pixelated; }

/* Game name in the top bar: a click copies the invite link. */
.room-tag { max-width: 16em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 0 10px; color: var(--parch); background: var(--wood-dark); border: 2px solid var(--ink); border-radius: 8px; font-family: var(--font); cursor: pointer; }
.room-tag:hover { filter: brightness(1.2); }
.chat-log div.note { color: var(--gold); }

/* Lobby */
.lobby-panel { width: min(1000px, 96vw); }
.lobby-cols { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 14px; }
.lobby-opts label { display: flex; gap: 6px; align-items: center; }
#lobby-players .emblem { width: 28px; height: 28px; image-rendering: pixelated; vertical-align: middle; }
#lobby-players .ready { color: var(--muted); }
#lobby-players .ready.on { color: var(--good); }
#btn-ready.on { background: linear-gradient(#c9f5b8, #8fd46d); }
.lobby-chat { display: flex; flex-direction: column; gap: 6px; min-height: 240px; }
.chat-log { flex: 1; min-height: 180px; max-height: 300px; overflow-y: auto; background: var(--deep); border: 3px solid var(--ink); border-radius: 8px; padding: 6px 8px; user-select: text; }
.chat-log div, #chat-feed div { overflow-wrap: anywhere; line-height: 1.15; }
.chat-log div.sys { color: var(--gold); font-size: calc(var(--px) * 1.4); text-align: center; text-shadow: 0 2px 0 var(--ink); }
.chat-form { display: flex; gap: 6px; }
.chat-form input { flex: 1; min-width: 0; }
@media (max-width: 760px) {
  .lobby-cols { grid-template-columns: minmax(0, 1fr); }
  .lobby-main, .lobby-chat { min-width: 0; }
  #lobby-players tr { display: flex; flex-wrap: wrap; align-items: center; }
  #lobby-players td { padding: 3px; }
}

/* In-game chat */
#chat-feed { position: absolute; left: 12px; bottom: calc(var(--hud-h) + var(--slot) + 18px); display: flex; flex-direction: column; gap: 3px; max-width: min(520px, 60vw); pointer-events: none; }
#chat-feed div { background: var(--shade); border: 2px solid var(--ink); border-radius: 8px; padding: 1px 10px; color: var(--parch); transition: opacity .6s; }
#game-chat { width: min(520px, 60vw); position: absolute; left: 12px; bottom: calc(var(--hud-h) + var(--slot) + 18px); display: flex; flex-wrap: wrap; gap: 6px; align-items: center; background: var(--shade); border: 2px solid var(--ink); border-radius: 8px; padding: 4px 8px; }
#game-chat span { color: var(--gold); }
#game-chat input { flex: 1; min-width: 0; }

#chat-hist { flex: 0 0 100%; width: 100%; max-height: 190px; overflow-y: auto; padding: 2px 4px; user-select: text; }
#chat-hist div { overflow-wrap: anywhere; line-height: 1.15; color: var(--parch); }
#chat-hist .empty { color: var(--muted); }
#game-chat-to, #game-chat input { align-self: center; }


/* Drawn cursor while the mouse is locked to the window (pointer lock hides the real one). */
#vcursor { position: fixed; left: 0; top: 0; width: 32px; height: 32px; margin: -2px 0 0 -2px; z-index: 1000; pointer-events: none; will-change: transform; image-rendering: pixelated; background: no-repeat url(../assets/ui/cursor_move.png); }
#vcursor[data-cur=attack] { background-image: url(../assets/ui/cursor_attack.png); }
#vcursor[data-cur=aim] { margin: -14px 0 0 -14px; background-image: url(../assets/ui/cursor_aim.png); }
#vcursor[data-cur=axe], #vcursor[data-cur=pick], #vcursor[data-cur=build] { width: 32px; height: 32px; margin: -16px 0 0 -16px; image-rendering: pixelated; }
#vcursor[data-cur=axe] { background-image: url(../assets/ui/cursor_axe.png); }
#vcursor[data-cur=pick] { background-image: url(../assets/ui/cursor_pick.png); }
#vcursor[data-cur=build] { background-image: url(../assets/ui/cursor_build.png); }
#vcursor.hidden { display: none; }

/* Large desktops: scale menus and HUD up as a whole so text and buttons keep their on-screen size. */
@media (min-width: 1800px) and (min-height: 980px) {
  #hud, .screen > .panel { zoom: 1.25; }
}
@media (min-width: 2300px) and (min-height: 1300px) {
  #hud, .screen > .panel { zoom: 1.5; }
}

/* Shared menu: its key caps font stack ends in an invalid `inherit`, so the font is set here. */

/* Phones and small windows. Only max-width/max-height queries: 1280x720 and larger stay untouched.
   Grid: system buttons (chat, menu) own the top right corner, the status bar sits top left,
   messages below it, players under the system buttons, selection/command card/minimap at the bottom. */
@media (max-width: 760px), (max-height: 520px) {
  #hud { --slot: 38px; --mm: 112px; }
  #topbar {
    left: 0; transform: none; flex-wrap: wrap; gap: 4px 6px; padding: 3px 14px 4px 8px; max-width: calc(100vw - 108px);
    border-left: 0; border-radius: 0 0 18px 0;
  }
  #topbar::before, #topbar::after { display: none; }
  .res { gap: 3px; min-width: 0; }
  .res b, #r-supply { min-width: 0; }
  .ico { width: 22px; height: 22px; }
  #clock { min-width: 0; padding: 0 5px; }
  .tb-btns { margin-left: 0; gap: 5px; }
  .rbtn { width: 34px; height: 34px; }
  .rbtn.sm { width: 32px; height: 32px; }
  #btn-room { order: 5; flex: 0 1 100%; max-width: none; height: 26px; }
  #hud:has(#btn-room:not(.hidden)) #msgs { top: 76px; }
  #msgs { left: 6px; top: 46px; width: min(230px, calc(100vw - 168px)); }
  #msgs div:nth-last-child(n+3) { display: none; }
  #right-col { right: 6px; top: 56px; width: 150px; gap: 4px; max-height: calc(100vh - var(--hud-h) - 62px); }
  #players, #tips { padding: 2px 8px 4px; }
  #players .ph, #tips .ph { min-height: 30px; }
  #players-list { max-height: calc(100vh - var(--hud-h) - 140px); overflow-y: auto; }
  #players .pt small { display: none; }
  #players .pl { gap: 6px; padding: 1px 6px; }
  #players .sw { width: 24px; height: 24px; }
  #players .sw canvas { width: 18px; height: 18px; }
  #tip-now { min-height: 0; }
  #idle-btn { left: 8px; }
  #chat-feed, #game-chat { left: 6px; max-width: calc(100vw - 12px); }
  #chat-feed div:nth-last-child(n+4) { display: none; }
  #game-chat { width: calc(100vw - 12px); }
  #chat-hist { max-height: 90px; }
  #tooltip, #tooltip.left { right: 6px; left: auto; width: min(300px, calc(100vw - 12px)); }
  #help { padding-top: 4px; }
  .help-panel #help-close { right: auto; left: 14px; }
  .help-panel { width: calc(100vw - 8px); max-height: calc(100vh - 8px); overflow-y: auto; }
  .sc-grid { columns: 2; }
  .result-panel { overflow-x: auto; }
  .portrait { display: none; }
  .details .sub { -webkit-line-clamp: 1; }
  .details > div:not(.sub):not(.bar) { display: none; }
  .slots { grid-template-columns: repeat(5, 36px); grid-auto-rows: 36px; gap: 3px; padding: 4px; }
  .slots.long { grid-template-columns: repeat(6, 36px); }
  .slots.multi { grid-template-columns: repeat(auto-fill, 36px); }
  #info { gap: 6px; padding: 4px 6px; }
  #info.many .details { flex-basis: 96px; }
  #card { gap: 4px; padding: 5px; grid-template-rows: repeat(3, var(--slot)); }
  #minimap-wrap { width: calc(var(--mm) + 10px); height: calc(var(--mm) + 10px); }
  .cbtn { padding: 3px; }
  .cbtn .hk { display: none; }
}

/* Portrait: selection on top, command card and minimap below it. */
@media (max-width: 760px) {
  #hud { --hud-h: 238px; --slot: 40px; --mm: 124px; }
  #bottom {
    display: grid; grid-template-columns: auto 1fr; grid-template-rows: 64px auto; gap: 8px; align-content: start;
    padding: 12px 6px 4px; border-width: 8px 6px 0;
  }
  #info { grid-column: 1 / -1; }
  #card { align-self: start; }
  #minimap-wrap { align-self: start; justify-self: end; margin-right: 4px; }
  .details .sub { display: none; }
  .stats { display: none; }
  #chat-feed { bottom: calc(var(--hud-h) + var(--slot) + 14px); }
  .sc-grid { columns: 1; }
  .sc-sec li { grid-template-columns: minmax(96px, 42%) 1fr; }
}

/* Landscape phones: one row, short panel so the field keeps about 60% of the height. */
@media (max-height: 520px) {
  #hud { --hud-h: 148px; --slot: 36px; --mm: 100px; }
  #bottom { padding: 10px 8px 4px; border-width: 8px 6px 0; gap: 8px; }
  #card { align-self: center; }
  #minimap-wrap { align-self: center; }
  #info { align-self: stretch; }
  .details > .stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); }
  .sc-grid { columns: 2; }
}

/* LOR-29: landscape phones keep more of the field: a flatter bottom bar. */
@media (max-height: 430px) {
  #hud { --hud-h: 118px; --slot: 31px; --mm: 84px; }
  #bottom { padding: 6px 8px 2px; }
  #card { gap: 3px; padding: 4px; }
}
/* E-05: hint for touch-only devices in the menu. LOR-30: menu links and summaries big enough to tap. */
.touch-note { margin: 0 0 8px; padding: 6px 12px; background: rgba(43, 26, 14, .82); border: 3px solid var(--ink); border-radius: 12px; }
@media (pointer: coarse) {
  .menu-legal-bar a, .howto summary { min-height: 44px; display: inline-flex; align-items: center; }
}

/* Touch has no mouse lock; below 380 px the shortcut overview (also in the menu) makes room for the numbers. */
@media (pointer: coarse) { #btn-lock { display: none; } }
@media (max-width: 380px) { #btn-help { display: none; } }

/* Imprint, privacy policy and chat rules stay on screen at the bottom of the menu (11.11.2026);
   the texts live once on puddlehold.com instead of a copy per game. */
.menu-legal-bar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; display: flex; flex-wrap: wrap; justify-content: center; gap: 0 18px;
  padding: 0 12px env(safe-area-inset-bottom); background: rgba(30, 18, 8, .86); border-top: 2px solid #2b1a0e; }
.menu-legal-bar a { display: inline-flex; align-items: center; min-height: 36px; padding: 0 6px; color: #ffd43a; text-decoration: underline; text-shadow: 1px 1px 0 #2b1a0e; }
#menu { padding-bottom: calc(44px + env(safe-area-inset-bottom)); }
