:root {
  --bg: #070d18;
  --panel: #121a28;
  --panel2: #1a2436;
  --line: #3a4a63;
  --gold: #c9a24a;
  --gold2: #8a6a2a;
  --text: #e8eef6;
  --muted: #95a6bd;
  --accent: #f2c95c;
  --good: #7fe08a;
  --bad: #ff6b5e;
  --ice: #9fd8ff;
}
* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; color: var(--text);
  font: 14px/1.4 "Trebuchet MS", system-ui, sans-serif;
  background: radial-gradient(ellipse at 50% 0%, #1b2f4f 0%, #0b1424 55%, var(--bg) 100%) fixed;
}
h1, h2, h3, .stat .lbl, .btns .nm, #selName { font-family: "Cinzel", "Trajan Pro", Georgia, serif; }
button {
  font: inherit; color: var(--text); cursor: pointer; padding: 7px 12px;
  background: linear-gradient(#26324a, #161f30); border: 1px solid var(--gold2); border-radius: 4px;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.08), 0 1px 2px rgba(0,0,0,.5);
}
button:hover:not(:disabled) { border-color: var(--gold); box-shadow: inset 0 1px 0 rgba(255,255,255,.12), 0 0 8px rgba(201,162,74,.35); }
button:disabled { opacity: .45; cursor: not-allowed; }
button.primary {
  background: linear-gradient(#e7c66a, #a77c2c); color: #1d1405; border-color: #f3dc94; font-weight: 700;
  font-family: "Cinzel", Georgia, serif; letter-spacing: .5px; text-shadow: 0 1px 0 rgba(255,255,255,.3);
}
input { font: inherit; color: var(--text); background: #0a111d; border: 1px solid var(--gold2); border-radius: 4px; padding: 7px 10px; box-shadow: inset 0 1px 3px rgba(0,0,0,.6); }
input:focus { outline: none; border-color: var(--gold); }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.row { display: flex; gap: 8px; }
.row > * { flex: 1; }
kbd { background: #0a111d; border: 1px solid var(--gold2); border-radius: 3px; padding: 0 4px; font-size: 12px; color: var(--accent); }
code { background: #0a111d; padding: 1px 5px; border-radius: 4px; color: var(--ice); }
/* Ornate frame used by the lobby card, side panel and game-over card */
.frame {
  background:
    linear-gradient(rgba(159,216,255,.05), transparent 40%),
    linear-gradient(160deg, #18233a, #0e1522);
  border: 2px solid var(--gold2);
  box-shadow: inset 0 0 0 1px #000, inset 0 0 0 3px rgba(201,162,74,.35), 0 10px 40px rgba(0,0,0,.6);
}
.g { color: var(--good); } .r { color: var(--bad); }

/* Lobby */
#lobby { min-height: 100%; display: flex; align-items: center; justify-content: center; padding: 24px 16px; }
.lobby-card { width: 100%; max-width: 480px; border-radius: 8px; padding: 28px; }
h1 { margin: 0; font-size: 32px; letter-spacing: 1px; color: #f4f8ff; text-shadow: 0 0 18px rgba(159,216,255,.55), 0 2px 0 #000; }
h1 span { color: var(--accent); text-shadow: 0 0 14px rgba(242,201,92,.5), 0 2px 0 #000; }
.tag { color: var(--muted); margin: 6px 0 20px; }
#joinForm { display: flex; gap: 8px; margin-bottom: 16px; }
#joinForm input { flex: 1; }
#slots { list-style: none; padding: 0; margin: 0 0 12px; display: grid; gap: 6px; }
#slots li { display: flex; align-items: center; gap: 10px; background: #0a111d; border: 1px solid rgba(201,162,74,.35); border-radius: 4px; padding: 9px 12px; }
#slots li.empty { color: var(--muted); border-style: dashed; background: transparent; }
#slots .sw { width: 12px; height: 12px; border-radius: 3px; flex: none; }
#slots .nm { flex: 1; }
#slots .tagb { font-size: 11px; color: var(--muted); border: 1px solid var(--line); border-radius: 4px; padding: 0 5px; }
#slots .x { padding: 0 8px; line-height: 20px; }
#hostCtl { margin-bottom: 12px; }
#watchBtn { width: 100%; margin-bottom: 12px; }
.howto { margin-top: 16px; border-top: 1px solid rgba(201,162,74,.3); padding-top: 12px; }
.howto summary { cursor: pointer; font-weight: 600; color: var(--accent); font-family: Cinzel, Georgia, serif; }
.howto ul { padding-left: 18px; color: #c4cad6; }
.howto li { margin: 6px 0; }

/* Game */
#game { display: flex; height: 100vh; }
#board { background: #0b1424; }
#board { flex: 1; min-width: 0; position: relative; }
#cv { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#panel { width: 300px; flex: none; border-width: 0 0 0 2px; padding: 12px; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; }
#panel section { border-top: 1px solid rgba(201,162,74,.3); padding-top: 10px; }
#panel h3 { margin: 0 0 8px; font-size: 13px; text-transform: uppercase; letter-spacing: 1px; color: var(--accent); }
#panel h3 small { text-transform: none; letter-spacing: 0; color: var(--muted); font-weight: 400; float: right; }
#stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.stat { background: #0a111d; border: 1px solid rgba(201,162,74,.35); border-radius: 4px; padding: 6px 8px; }
.stat .lbl { display: block; font-size: 11px; color: var(--muted); }
.stat .val { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
.val.gold { color: var(--accent); } .val.inc { color: var(--good); } .val.lives { color: #ff8a80; }
#incBar { position: relative; height: 18px; background: #0a111d; border: 1px solid rgba(201,162,74,.35); border-radius: 4px; overflow: hidden; }
#incFill { position: absolute; inset: 0 auto 0 0; background: linear-gradient(90deg, #2a6fa8, var(--ice)); width: 0; }
#incTxt { position: relative; display: block; text-align: center; font-size: 11px; line-height: 16px; text-shadow: 0 1px 2px #000; }
.btns { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.btns button { text-align: left; padding: 6px 8px; display: grid; grid-template-columns: 14px 1fr auto; gap: 2px 6px; align-items: center; }
.btns button .sw { width: 12px; height: 12px; border-radius: 3px; }
.btns button .nm { font-weight: 600; }
.btns button .hk { font-size: 11px; color: var(--muted); }
.btns button .sub { grid-column: 2 / 4; font-size: 11px; color: var(--muted); }
.btns button .sub b { color: var(--accent); font-weight: 600; }
.btns button .sub i { color: var(--good); font-style: normal; }
.btns button.active { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent), 0 0 10px rgba(242,201,92,.4); }
.btns button.poor { opacity: .45; }
#phaseNote { background: #2a2414; border: 1px solid #5a4a20; color: var(--accent); border-radius: 8px; padding: 6px 8px; margin-bottom: 8px; font-size: 12px; font-weight: 600; text-align: center; }
#selInfo { margin-top: 8px; background: #0a111d; border: 1px solid rgba(201,162,74,.35); border-radius: 4px; padding: 8px; }
#selName { font-weight: 600; margin-bottom: 2px; }
#selActions { margin-top: 8px; }
#plist { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
#plist li { display: grid; grid-template-columns: 12px 1fr auto; gap: 8px; align-items: center; font-size: 13px; padding: 4px 6px; border-radius: 6px; }
#plist li.me { background: rgba(159,216,255,.08); }
#plist li.dead { opacity: .4; text-decoration: line-through; }
#plist .sw { width: 10px; height: 10px; border-radius: 2px; }
#plist .num { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
#feedSec { flex: 1; display: flex; flex-direction: column; min-height: 140px; }
#feed { flex: 1; overflow-y: auto; font-size: 12px; color: var(--muted); margin-bottom: 6px; display: flex; flex-direction: column; gap: 2px; }
#feed .chat { color: var(--text); }
#feed .chat b { color: var(--accent); }
#chatIn { width: 100%; }

#overlay { position: fixed; inset: 0; background: rgba(5, 7, 10, .7); display: flex; align-items: center; justify-content: center; z-index: 10; }
.over-card { border-radius: 8px; padding: 28px 36px; text-align: center; }
.over-card h2 { margin: 0 0 18px; font-size: 28px; text-shadow: 0 2px 0 #000; }
#toast { position: fixed; top: 14px; left: 50%; transform: translateX(-50%); background: #3a1f1f; border: 1px solid #6b2f2f; color: #ffd5d0; padding: 8px 14px; border-radius: 8px; opacity: 0; transition: opacity .2s; pointer-events: none; z-index: 20; }
#toast.show { opacity: 1; }

@media (max-width: 800px) {
  #game { flex-direction: column; height: auto; }
  #board { height: 70vh; }
  #panel { width: 100%; border-left: 0; border-top: 1px solid var(--line); }
}
.subtitle { margin: 2px 0 0; font-family: Cinzel, Georgia, serif; color: var(--ice); letter-spacing: 3px; font-size: 12px; text-transform: uppercase; }
#snow { position: fixed; inset: 0; pointer-events: none; z-index: 0; }
#lobby { position: relative; z-index: 1; }

/* 3D board overlays */
#board { overflow: hidden; }
#board canvas.gl { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.labels3d { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.lbl3d { position: absolute; left: 0; top: 0; white-space: nowrap; font: 600 13px Cinzel, Georgia, serif; color: #f4f8ff;
  background: linear-gradient(#1d2940ee, #0e1626ee); border: 1px solid var(--gold2); border-radius: 4px; padding: 3px 9px;
  box-shadow: 0 2px 8px rgba(0,0,0,.5); display: flex; align-items: center; gap: 6px; }
.lbl3d.me { border-color: var(--gold); font-size: 14px; }
.lbl3d .sw, .pip-lbl .sw { width: 10px; height: 10px; border-radius: 2px; display: inline-block; }
.lbl3d b, .pip-lbl b { color: #ff8a80; font-family: system-ui, sans-serif; }
.lbl3d small { font: 10px system-ui; color: var(--muted); border: 1px solid var(--line); border-radius: 3px; padding: 0 3px; }
.lbl3d i { font-style: normal; color: var(--accent); font-size: 11px; }
.lbl3d em, .pip-lbl em { font-style: normal; color: var(--bad); }
.pip-lbl { position: absolute; font: 600 11px Cinzel, Georgia, serif; color: #f4f8ff; text-shadow: 0 1px 3px #000;
  display: flex; align-items: center; gap: 5px; overflow: hidden; white-space: nowrap; }
.pip-lbl.target { color: var(--accent); }
.pip-lbl.target::after { content: '◀ target'; font-size: 9px; letter-spacing: .5px; }
#phaseBanner { position: absolute; left: 50%; bottom: 28px; transform: translateX(-50%); z-index: 2; pointer-events: none;
  font: 700 18px Cinzel, Georgia, serif; color: var(--accent); padding: 10px 22px; white-space: nowrap;
  background: linear-gradient(#1d2940f0, #0e1626f0); border: 2px solid var(--gold); border-radius: 4px; box-shadow: 0 6px 24px rgba(0,0,0,.5); }
#camHint { position: absolute; left: 12px; bottom: 8px; z-index: 2; pointer-events: none; font-size: 11px; color: rgba(230,240,255,.75); text-shadow: 0 1px 2px #000; }
.ladder { display: grid; gap: 2px; margin-top: 6px; }
.ladder span { display: flex; align-items: center; gap: 6px; font-size: 11px; color: var(--muted); padding: 1px 4px; border-radius: 3px; }
.ladder span i { width: 8px; height: 8px; border-radius: 2px; opacity: .5; }
.ladder span.done { color: #c4cad6; }
.ladder span.done i { opacity: 1; }
.ladder span.cur { color: var(--accent); background: rgba(242,201,92,.1); font-weight: 600; }
.ladder span.cur i { opacity: 1; }
.btns button .pt { width: 34px; height: 34px; grid-row: 1 / 3; border-radius: 4px; background: radial-gradient(#2a3a55, #0a111d); object-fit: cover; }
.btns button.has-pt { grid-template-columns: 34px 1fr auto; }
#selInfo .portrait { float: right; width: 56px; height: 56px; margin: 0 0 4px 8px; border-radius: 4px; border: 1px solid var(--gold2); background: radial-gradient(#2a3a55, #0a111d); }
.tierHead { grid-column: 1 / -1; font: 600 11px Cinzel, Georgia, serif; color: var(--accent); letter-spacing: 1px; text-transform: uppercase; margin-top: 4px; }
.tierHead.locked { color: var(--muted); }
.btns button.locked { opacity: .35; filter: grayscale(.8); }
#creepUpBtn { width: 100%; margin-top: 8px; text-align: left; line-height: 1.3; background: linear-gradient(#3a2d12, #1d160a); border-color: var(--gold); }
#creepUpBtn b { color: var(--accent); }
#creepUpBtn small { display: block; font-size: 11px; color: var(--muted); }
#creepUpBtn.done { background: linear-gradient(#18301f, #0d1a11); border-color: #3d7a45; }
#slots { grid-template-columns: 1fr 1fr; }
#selPortrait[src=""] { display: none; }
#selInfo::after { content: ''; display: block; clear: both; }
.lbl3d small.up { color: var(--accent); border-color: var(--gold2); }
#gallery { display: grid; gap: 6px; margin-top: 8px; }
.grow { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.gcard { background: #0a111d; border: 1px solid rgba(201,162,74,.3); border-radius: 4px; padding: 4px; text-align: center; }
.gcard img { width: 100%; aspect-ratio: 1; display: block; background: radial-gradient(#2a3a55, #0a111d); border-radius: 3px; }
.gcard b { display: block; font: 600 10px Cinzel, Georgia, serif; color: #e8eef6; margin-top: 3px; line-height: 1.15; }
.gcard small { font-size: 9px; color: var(--muted); }
.lobby-card { max-width: 560px; }
#botLevel { font: inherit; color: var(--text); background: #0a111d; border: 1px solid var(--gold2); border-radius: 4px; padding: 6px 8px; flex: 0 0 auto; }
#slots .tagb.lvl-easy { color: var(--good); }
#slots .tagb.lvl-hard { color: var(--bad); border-color: #6b2f2f; }
#plist li { cursor: pointer; }
#plist li:hover { background: rgba(242,201,92,.08); }
.invite { margin: 4px 0 12px; padding: 10px; background: #0a111d; border: 1px solid rgba(201,162,74,.35); border-radius: 6px; display: grid; gap: 8px; }
.invite-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.invite-head b { color: var(--accent); font-family: Cinzel, Georgia, serif; letter-spacing: 2px; font-size: 16px; }
.invite-head small { color: var(--muted); font-size: 11px; }
.invite .row > input { flex: 1; min-width: 0; }
.invite .row > button { flex: 0 0 auto; }
#slots .tagb.away { color: var(--bad); }
