:root {
  --bg: #0d1016;
  --panel: rgba(18, 22, 30, 0.88);
  --line: rgba(255, 255, 255, 0.09);
  --text: #e9e4d8;
  --muted: #9a9486;
  --gold: #f2c14e;
  --red: #e05a4f;
  --blue: #4f86e0;
  --t1: #8a7f72; --t2: #5fae6a; --t3: #4f9be0; --t4: #a466e0; --t5: #f2c14e;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--text);
  font: 14px/1.4 Inter, system-ui, sans-serif; user-select: none; }
canvas#world { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
button, input { font: inherit; color: var(--text); }
button { background: #232a36; border: 1px solid var(--line); border-radius: 8px; padding: 9px 14px; cursor: pointer; }
button:hover:not(:disabled) { background: #2c3544; }
button:disabled { opacity: 0.4; cursor: default; }
button.primary { background: linear-gradient(#d9a53a, #b9831f); color: #1b1408; border-color: #e8bd5c; font-weight: 700; }
button.primary:hover:not(:disabled) { background: linear-gradient(#e6b44a, #c8912a); }
input { background: #151a23; border: 1px solid var(--line); border-radius: 8px; padding: 9px 12px; outline: none; }
input:focus { border-color: #6b5a2e; }

/* Screens */
.screen { position: fixed; inset: 0; display: grid; place-items: center; padding: 16px;
  background: radial-gradient(ellipse at 50% 30%, rgba(60, 50, 110, 0.35), transparent 60%), rgba(8, 10, 14, 0.75); z-index: 10; }
.card { width: min(380px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 16px;
  padding: 28px; display: flex; flex-direction: column; gap: 12px; box-shadow: 0 20px 60px rgba(0,0,0,.5); }
.card.wide { width: min(620px, 100%); }
h1 { font: 800 44px/1 Cinzel, serif; margin: 0; letter-spacing: 2px;
  background: linear-gradient(90deg, var(--t3), var(--t4), var(--t5)); -webkit-background-clip: text; background-clip: text; color: transparent; }
h2 { font: 600 24px Cinzel, serif; margin: 0; }
h3 { margin: 0 0 8px; }
.tag { margin: 0 0 6px; color: var(--muted); }
label { display: flex; flex-direction: column; gap: 6px; color: var(--muted); }
.row { display: flex; gap: 8px; }
.row > * { flex: 1; }
#code { text-transform: uppercase; letter-spacing: 4px; text-align: center; }
.roomhead { display: flex; justify-content: space-between; align-items: baseline; }
#roomcode { color: var(--gold); letter-spacing: 4px; }
.teams { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.team { border: 1px solid var(--line); border-radius: 12px; padding: 12px; display: flex; flex-direction: column; min-height: 200px; }
.team.red h3 { color: var(--red); } .team.blue h3 { color: var(--blue); }
.team ul { list-style: none; margin: 0 0 10px; padding: 0; flex: 1; }
.team li { padding: 4px 0; border-bottom: 1px solid var(--line); }
.team li.me { font-weight: 700; }
.team li .host { color: var(--gold); font-size: 11px; margin-left: 6px; }
.bigscore { font: 800 36px Cinzel, serif; margin: 0; text-align: center; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 6px 8px; text-align: left; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; }
td.red { color: var(--red); } td.blue { color: var(--blue); }

/* HUD */
#hud > * { position: fixed; z-index: 5; }
#topbar { top: 12px; left: 50%; transform: translateX(-50%); display: flex; align-items: center; gap: 14px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 6px 16px; }
#timer { font: 700 20px Inter; min-width: 64px; text-align: center; font-variant-numeric: tabular-nums; }
.score { font: 800 22px Cinzel, serif; min-width: 52px; text-align: center; font-variant-numeric: tabular-nums; }
.score.red { color: var(--red); } .score.blue { color: var(--blue); }
#minimap { top: 12px; right: 12px; background: #0a0d12; border: 1px solid var(--line); border-radius: 10px; image-rendering: pixelated; }
#returnbase { top: 190px; right: 12px; width: 168px; }
#helpbtn { top: 234px; right: 12px; width: 36px; height: 36px; padding: 0; border-radius: 50%; font-weight: 700; }
#help { top: 50%; left: 50%; transform: translate(-50%, -50%); width: min(520px, calc(100% - 32px));
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 20px 22px; }
#help ul { margin: 0; padding-left: 18px; display: flex; flex-direction: column; gap: 8px; }
#help code { background: #222936; padding: 1px 5px; border-radius: 4px; }

#log { left: 12px; bottom: 52px; width: min(380px, calc(100% - 24px)); max-height: 34vh; overflow: hidden;
  display: flex; flex-direction: column; justify-content: flex-end; gap: 2px; pointer-events: none; }
#log div { background: rgba(10, 12, 18, 0.6); padding: 3px 8px; border-radius: 6px; width: fit-content; max-width: 100%;
  text-shadow: 0 1px 2px #000; animation: fade 12s forwards; }
#log .red { color: var(--red); } #log .blue { color: var(--blue); } #log .gold { color: var(--gold); }
@keyframes fade { 0%, 80% { opacity: 1; } 100% { opacity: 0.15; } }
#chat { left: 12px; bottom: 12px; width: min(380px, calc(100% - 24px)); }

#panel { right: 12px; bottom: 12px; width: 300px; max-height: 50vh; max-height: 50dvh;
  overflow-y: auto; overscroll-behavior: contain; background: var(--panel); border: 1px solid var(--line);
  border-radius: 12px; padding: 12px; display: flex; flex-direction: column; gap: 10px; }
.hp { position: relative; height: 18px; background: #3a1d1d; border-radius: 6px; overflow: hidden; }
#hpbar { height: 100%; background: linear-gradient(#5fd06d, #36a046); width: 100%; transition: width .15s; }
#hptext { position: absolute; inset: 0; text-align: center; font-size: 12px; font-weight: 700; line-height: 18px; text-shadow: 0 1px 2px #000; }
#pack { font-size: 11px; text-align: right; }
.inventory-heading { display: flex; justify-content: space-between; align-items: baseline; }
.inventory-heading button { padding: 3px 7px; font-size: 11px; }
#inventory { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 4px; }
.inventory-slot { position: relative; min-width: 0; aspect-ratio: 1; padding: 2px; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 1px; border-radius: 4px; background: #151a23; border-color: #353d4b; }
.inventory-slot.empty { background: #11151d; border-color: #262d39; }
.inventory-slot.equipped { box-shadow: inset 0 0 0 2px var(--gold); }
.inventory-slot.dragging { opacity: .4; }
.inventory-item-icon { display: block; width: 40px; height: 40px; }
.inventory-item-icon svg { display: block; width: 100%; height: 100%; overflow: visible; }
.inventory-item-icon svg path { stroke: #22212a; stroke-width: 1.3; stroke-linecap: round; stroke-linejoin: round; }
.inventory-item-icon .gem-body,
.inventory-item-icon .metal-body,
.inventory-item-icon .fish-body,
.inventory-item-icon .armor-body,
.inventory-item-icon .blade-body,
.inventory-item-icon .staff-orb { fill: currentColor; }
.inventory-item-icon .gem-facet,
.inventory-item-icon .metal-edge,
.inventory-item-icon .armor-plate,
.inventory-item-icon .blade-edge { fill: #f3e4bf; }
.inventory-item-icon .gem-line,
.inventory-item-icon .metal-line,
.inventory-item-icon .armor-line,
.inventory-item-icon .fish-eye { fill: none; stroke: #443b4a; stroke-width: 1; }
.inventory-item-icon .wood-body { fill: #9b6842; }
.inventory-item-icon .wood-end { fill: #d1a16b; }
.inventory-item-icon .wood-line { fill: none; stroke: #563922; stroke-width: 1; }
.inventory-item-icon .fish-fin { fill: #f2c14e; }
.inventory-item-icon .food-mark { fill: #f08b35; stroke: #f4d0a4; stroke-width: .8; }
.inventory-item-icon .wood-handle { fill: #98633f; stroke: #432f26; stroke-width: 2; }
.inventory-item-icon .metal-body,
.inventory-item-icon .metal-edge { stroke: #453b47; stroke-width: 1.4; }
.inventory-item-icon .armor-plate { fill-opacity: .75; }
.inventory-item-icon .blade-hilt,
.inventory-item-icon .blade-guard { fill: #c89046; }
.inventory-item-icon .bow-body { fill: #a66d3f; }
.inventory-item-icon .bow-string,
.inventory-item-icon .bow-arrow { fill: none; stroke: #e7d6b2; stroke-width: 1.4; }
.inventory-item-icon .staff-glow { fill: #fff1a6; stroke: #6951a2; stroke-width: .7; }
.inventory-slot small { max-width: 100%; overflow: hidden; color: var(--muted); font-size: 8px; line-height: 1; }
#panel.collapsed .hp,
#panel.collapsed #inventory,
#panel.collapsed #gear { display: none; }
#panel.collapsed { gap: 0; }
#gear { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 4px; font-size: 11px; }
#gear div { min-width: 0; background: #151a23; border-radius: 6px; padding: 5px 2px; text-align: center; }
#gear span { display: block; color: var(--muted); font-size: 9px; text-transform: uppercase; letter-spacing: .5px; }

#bench { left: 50%; bottom: 12px; transform: translateX(-50%); background: var(--panel); border: 1px solid #6b5a2e;
  border-radius: 12px; padding: 12px; width: min(520px, calc(100% - 24px)); }
#stove { left: 50%; bottom: 12px; transform: translateX(-50%); background: var(--panel); border: 1px solid #8b6039;
  border-radius: 12px; padding: 12px; width: min(420px, calc(100% - 24px)); }
.benchhead { display: flex; justify-content: space-between; margin-bottom: 8px; font-size: 12px; }
#benchgrid { display: grid; grid-template-columns: 72px repeat(5, 1fr); gap: 4px; align-items: center; font-size: 12px; }
#benchgrid button { padding: 6px 0; font-size: 12px; border-width: 2px; }
#stovegrid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 5px; }
#stovegrid button { padding: 7px 3px; font-size: 11px; border-width: 2px; }

#gatherbar { left: 50%; top: calc(50% + 30px); transform: translateX(-50%); width: 60px; height: 6px;
  background: rgba(0,0,0,.6); border-radius: 3px; overflow: hidden; }
#gatherbar div { height: 100%; background: var(--gold); width: 0; }
#tooltip { pointer-events: none; background: rgba(10,12,18,.92); border: 1px solid var(--line); border-radius: 6px;
  padding: 4px 8px; font-size: 12px; white-space: nowrap; }
#dead { top: 38%; left: 50%; transform: translate(-50%, -50%); text-align: center; display: flex; flex-direction: column;
  gap: 4px; font: 600 26px Cinzel, serif; text-shadow: 0 2px 8px #000; }
#dead span { font: 16px Inter; color: var(--muted); }

#toast { position: fixed; top: 20px; left: 50%; transform: translateX(-50%); z-index: 20; background: #4a2020;
  border: 1px solid var(--red); padding: 8px 14px; border-radius: 8px; }

@media (max-width: 700px) {
  #minimap { width: 112px; height: 112px; }
  #returnbase { top: 132px; width: 112px; padding: 8px 4px; font-size: 12px; }
  #helpbtn { top: 176px; }
  #panel { width: 228px; padding: 8px; gap: 7px; }
  .inventory-item-icon { width: 32px; height: 32px; }
  #gear { gap: 3px; font-size: 10px; }
  #gear div { padding: 4px 1px; }
  #gear span { font-size: 8px; letter-spacing: 0; }
  #log { max-height: 22vh; bottom: 52px; width: calc(100% - 226px); }
}
