:root {
  --bg: #1a120c;
  --panel: rgba(30, 18, 10, 0.82);
  --panel-border: rgba(255, 196, 120, 0.22);
  --ink: #f6e9d3;
  --muted: #c2a882;
  --gold: #ffcc4d;
  --red: #e2483a;
  --blue: #3b82e6;
  --green: #5bd16a;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); font: 14px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif; overflow: hidden; }
#view { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
.hidden { display: none !important; }
.screen { position: fixed; inset: 0; pointer-events: none; }
.screen > * { pointer-events: auto; }

.panel { background: var(--panel); border: 1px solid var(--panel-border); border-radius: 14px; padding: 14px 16px; backdrop-filter: blur(6px); box-shadow: 0 10px 30px rgba(0,0,0,.35); }
.panel h2 { margin: 0 0 10px; font-size: 18px; letter-spacing: .04em; text-transform: uppercase; color: var(--gold); }
.panel h2 small { color: var(--muted); font-weight: 400; text-transform: none; font-size: 12px; margin-left: 6px; }
.panel h3 { margin: 0 0 6px; font-size: 12px; letter-spacing: .08em; text-transform: uppercase; color: var(--gold); }
.panel.small { padding: 10px 12px; font-size: 13px; }

.btn { background: linear-gradient(#ffcf5a, #e6a325); color: #2a1606; border: 0; border-radius: 9px; padding: 8px 12px; font-weight: 700; cursor: pointer; white-space: nowrap; font-size: 13px; }
.btn:hover { filter: brightness(1.08); }
.btn:active { transform: translateY(1px); }
.btn.ghost { background: rgba(255,255,255,.08); color: var(--ink); border: 1px solid var(--panel-border); }
.btn.red { background: linear-gradient(#f0675a, #c33326); color: #fff; }
.btn.blue { background: linear-gradient(#5b9cf5, #2d68c9); color: #fff; }
.btn.tiny { padding: 4px 8px; font-size: 12px; margin-top: 6px; }
.btn kbd, kbd { display: inline-block; font: 600 11px ui-monospace, monospace; padding: 1px 5px; border-radius: 4px; background: rgba(0,0,0,.35); border: 1px solid rgba(255,255,255,.2); color: inherit; }

input, select { background: rgba(0,0,0,.35); color: var(--ink); border: 1px solid var(--panel-border); border-radius: 8px; padding: 7px 9px; font: inherit; min-width: 0; }
input[type=color] { padding: 0; width: 100%; height: 28px; border-radius: 6px; cursor: pointer; }
input[type=range] { flex: 1; accent-color: var(--gold); }
.row { display: flex; align-items: center; gap: 8px; margin: 6px 0; }
.row > input:not([type=color]):not([type=range]), .row > select { flex: 1; }
.gap3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.gap3 label { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--muted); }

/* ---------- lobby ---------- */
#lobby { overflow-y: auto; padding: 20px 16px 30px; background: linear-gradient(90deg, rgba(20,12,6,.0) 0%, rgba(20,12,6,.0) 30%, rgba(20,12,6,.55) 60%); }
.brand { text-align: left; margin: 0 0 12px 6px; text-shadow: 0 4px 20px rgba(0,0,0,.6); }
.brand h1 { margin: 0; font-size: clamp(30px, 5vw, 56px); letter-spacing: .06em; font-weight: 900; color: var(--ink); }
.brand h1 span { color: var(--gold); }
.brand p { margin: 2px 0 0; color: var(--muted); }
.lobby-grid { display: grid; grid-template-columns: minmax(280px, 380px) 1fr minmax(320px, 440px); gap: 16px; align-items: start; }
.lobby-grid .builder { grid-column: 1; }
.lobby-grid .rooms { grid-column: 3; }
.colors { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 10px 0; }
.colors label { font-size: 12px; color: var(--muted); display: flex; flex-direction: column; gap: 3px; }
.slider { display: flex; align-items: center; gap: 8px; margin: 10px 0 4px; font-size: 13px; }
.slider .hint { font-size: 11px; color: var(--muted); }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; font-size: 12px; margin-bottom: 8px; }
.stats div { background: rgba(0,0,0,.25); border-radius: 8px; padding: 5px 7px; }
.stats b { display: block; font-size: 15px; color: var(--gold); }

#room-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 10px; max-height: 300px; overflow-y: auto; }
.room { background: rgba(0,0,0,.28); border: 1px solid var(--panel-border); border-radius: 10px; padding: 10px; display: grid; grid-template-columns: 1fr auto; gap: 6px; }
.room .title { font-weight: 800; font-size: 15px; }
.room .meta { color: var(--muted); font-size: 12px; }
.room .phase { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; padding: 2px 6px; border-radius: 6px; background: rgba(255,255,255,.08); }
.room .phase.fighting { background: var(--red); color: #fff; }
.room .actions { grid-column: 1 / -1; display: flex; gap: 8px; }
.room .actions .btn { flex: 1; }
.room .price s { opacity: .6; font-weight: 400; margin-left: 4px; }
.room .price em { font-style: normal; color: #135c1b; background: #b9f5bf; border-radius: 4px; padding: 0 4px; margin-left: 4px; font-size: 11px; }
.btn.ghost .price em { color: #b9f5bf; background: rgba(91,209,106,.2); }
.tickets { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--muted); border-top: 1px dashed var(--panel-border); padding-top: 8px; margin-top: 6px; }
.tickets em { font-style: normal; color: var(--green); font-weight: 700; }
.howto ul { margin: 4px 0 0; padding-left: 18px; color: var(--muted); font-size: 12.5px; }
.howto li { margin: 3px 0; }
.howto h3 { margin-top: 12px; }

/* ---------- HUD ---------- */
#hud .top { position: absolute; top: 12px; left: 12px; right: 12px; display: grid; grid-template-columns: 1fr auto 1fr; gap: 16px; align-items: start; pointer-events: none; }
.fighter-bar .name { display: flex; justify-content: space-between; align-items: center; font-weight: 900; font-size: 18px; text-shadow: 0 2px 6px #000; margin-bottom: 4px; }
.fighter-bar.blue .name { flex-direction: row; }
.fighter-bar .pips { display: flex; gap: 4px; }
.fighter-bar .pips i { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--gold); display: inline-block; }
.fighter-bar .pips i.on { background: var(--gold); }
.fighter-bar .hp { height: 22px; background: rgba(0,0,0,.6); border: 2px solid rgba(255,255,255,.35); border-radius: 6px; overflow: hidden; position: relative; }
.fighter-bar .hp .fill, .fighter-bar .hp .ghost { position: absolute; top: 0; bottom: 0; width: 100%; transition: width .08s linear; }
.fighter-bar .hp .ghost { background: #fff6; transition: width .6s ease .25s; }
.fighter-bar .hp .fill { z-index: 2; }
.fighter-bar.red .hp .fill { background: linear-gradient(#ff7a6b, var(--red)); }
.fighter-bar.blue .hp .fill { background: linear-gradient(#7fb5ff, var(--blue)); }
.fighter-bar.blue .hp .fill, .fighter-bar.blue .hp .ghost, .fighter-bar.blue .st .fill, .fighter-bar.blue .hype .fill { right: 0; }
.fighter-bar.red .hp .fill, .fighter-bar.red .hp .ghost, .fighter-bar.red .st .fill, .fighter-bar.red .hype .fill { left: 0; }
.fighter-bar .st, .fighter-bar .hype { height: 7px; margin-top: 4px; background: rgba(0,0,0,.5); border-radius: 4px; position: relative; overflow: hidden; }
.fighter-bar .st .fill { position: absolute; top: 0; bottom: 0; background: var(--green); }
.fighter-bar .hype { height: 12px; }
.fighter-bar .hype .fill { position: absolute; top: 0; bottom: 0; background: linear-gradient(90deg, #ff9d2e, #ffe14d); }
.fighter-bar .hype span { position: absolute; inset: 0; font-size: 9px; font-weight: 800; letter-spacing: .15em; text-align: center; line-height: 12px; color: rgba(255,255,255,.8); }
.fighter-bar.blue .name .nm { order: 2; }
.center { text-align: center; text-shadow: 0 2px 8px #000; }
#timer { font-size: 40px; font-weight: 900; font-variant-numeric: tabular-nums; line-height: 1; }
#round-lbl { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .1em; }

#banner { position: absolute; top: 34%; left: 0; right: 0; text-align: center; font-size: clamp(36px, 8vw, 90px); font-weight: 900; letter-spacing: .04em; color: var(--gold); text-shadow: 0 6px 0 #6b3a0b, 0 10px 30px rgba(0,0,0,.7); pointer-events: none; opacity: 0; transition: opacity .2s, transform .2s; transform: scale(.8); }
#banner.show { opacity: 1; transform: scale(1); }
#sub-banner { position: absolute; top: calc(34% + clamp(48px, 9vw, 110px)); left: 0; right: 0; text-align: center; font-size: 20px; font-weight: 700; color: var(--ink); text-shadow: 0 2px 8px #000; pointer-events: none; }
#crosshair { position: absolute; left: 50%; top: 50%; width: 6px; height: 6px; margin: -3px; border-radius: 50%; background: rgba(255,255,255,.6); pointer-events: none; }
#lock-hint { position: absolute; left: 50%; top: 62%; transform: translateX(-50%); background: var(--panel); padding: 8px 14px; border-radius: 10px; border: 1px solid var(--panel-border); pointer-events: none; }

.side-left { position: absolute; left: 12px; top: 120px; width: 230px; display: flex; flex-direction: column; gap: 10px; pointer-events: none; }
.side-right { position: absolute; right: 12px; top: 120px; width: 240px; display: flex; flex-direction: column; gap: 10px; }
.side-left .panel { pointer-events: auto; }
ol { margin: 0; padding-left: 20px; }
ol li { margin: 2px 0; }
ol li .pts { float: right; color: var(--gold); font-variant-numeric: tabular-nums; }
ol li.me { color: var(--gold); font-weight: 700; }
.tag { font-size: 10px; padding: 0 4px; border-radius: 4px; background: rgba(255,255,255,.12); margin-left: 4px; }
.tag.red { background: var(--red); } .tag.blue { background: var(--blue); }
#controls-mini { font-size: 12px; color: var(--muted); }
#controls-mini div { margin: 2px 0; }
#me-panel b { color: var(--gold); }

.bottom { position: absolute; left: 12px; right: 12px; bottom: 12px; display: flex; flex-direction: column; gap: 6px; pointer-events: none; }
.bottom > * { pointer-events: auto; }
.bottom .row { flex-wrap: wrap; }
#log { max-width: 520px; max-height: 150px; overflow: hidden; display: flex; flex-direction: column; justify-content: flex-end; font-size: 13px; text-shadow: 0 1px 3px #000; pointer-events: none; }
#log div { opacity: .92; }
#log .sys { color: var(--muted); font-style: italic; }
#log .chat b { color: var(--gold); }
#chat { max-width: 360px; }

#toast { position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%); background: var(--panel); border: 1px solid var(--panel-border); border-radius: 10px; padding: 8px 14px; opacity: 0; transition: opacity .3s; pointer-events: none; }
#toast.show { opacity: 1; }

@media (max-width: 1100px) {
  .lobby-grid { grid-template-columns: 1fr 1fr; }
  .lobby-grid .rooms { grid-column: 2; }
  #lobby { background: rgba(20,12,6,.45); }
}
@media (max-width: 720px) {
  .lobby-grid { grid-template-columns: 1fr; }
  .lobby-grid .rooms, .lobby-grid .builder { grid-column: 1; }
  .side-left, .side-right { display: none; }
  #timer { font-size: 28px; }
  .fighter-bar .name { font-size: 13px; }
}

/* ---------- walkable barn ---------- */
.top-walk { position: absolute; top: 12px; left: 0; right: 0; text-align: center; pointer-events: none; }
.barn-name { display: inline-block; font-weight: 900; font-size: 20px; letter-spacing: .08em; color: var(--gold); text-shadow: 0 2px 8px #000; }
#cage-lbl { color: var(--gold); font-weight: 800; font-size: 12px; letter-spacing: .12em; }
#prompt { position: absolute; left: 50%; bottom: 120px; transform: translateX(-50%); background: var(--panel); border: 1px solid var(--gold); border-radius: 12px; padding: 10px 16px; text-align: center; font-size: 15px; pointer-events: none; box-shadow: 0 10px 30px rgba(0,0,0,.4); }
#prompt b { color: var(--gold); }
#prompt .opts { margin-top: 6px; display: flex; gap: 14px; justify-content: center; }
#prompt em { font-style: normal; color: var(--green); font-weight: 700; }
#prompt s { opacity: .6; }
#cage-dir ol { padding-left: 18px; }
#cage-dir li { margin: 3px 0; }
#cage-dir li.live { color: #ffb0a6; }
#cage-dir li.here { color: var(--gold); font-weight: 700; }
#cage-dir .dist { float: right; color: var(--muted); font-variant-numeric: tabular-nums; }

#voice-panel ul { list-style: none; margin: 6px 0 0; padding: 0; max-height: 180px; overflow-y: auto; }
#voice-panel li { display: flex; align-items: center; gap: 6px; padding: 3px 0; border-top: 1px solid rgba(255,255,255,.06); }
#voice-panel li .who { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#voice-panel li .spk { width: 10px; height: 10px; border-radius: 50%; background: rgba(255,255,255,.15); flex: none; }
#voice-panel li .spk.on { background: var(--green); box-shadow: 0 0 8px var(--green); }
#voice-panel li .mode { font-size: 10px; color: var(--muted); }
#voice-panel li button { background: none; border: 0; cursor: pointer; font-size: 13px; padding: 0 2px; opacity: .7; }
#voice-panel li button:hover { opacity: 1; }
#voice-panel li.blocked .who { text-decoration: line-through; opacity: .5; }
.meter { flex: 1; height: 8px; background: rgba(0,0,0,.4); border-radius: 4px; overflow: hidden; }
#mic-meter { height: 100%; width: 0; background: var(--green); transition: width .06s; }
.row.vol input { flex: 1; }
.voice-pick select { flex: 1; }
.hint { color: var(--muted); font-size: 11.5px; }

#global-mute { position: fixed; top: 12px; right: 12px; z-index: 50; font-size: 18px; padding: 6px 10px; background: var(--panel); }
#global-mute.muted { border-color: var(--red); }
#hud .side-right { top: 60px; }
