:root {
  --bg: #0d0a14;
  --ink: #15101c;
  --panel: #241b36;
  --card: #2e2445;
  --field: #120d1c;
  --text: #f6f0ff;
  --muted: #b3a6cf;
  --red: #ff5a4e;
  --blue: #4aa3ff;
  --gold: #ffd23f;
  --green: #7fdb55;
  --bar-h: 38px;
  --font-fun: 'Lilita One', 'Arial Rounded MT Bold', system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.4 system-ui, -apple-system, 'Segoe UI', sans-serif;
  overflow: hidden;
}

#stage {
  position: fixed;
  inset: 0 0 var(--bar-h) 0;
  display: grid;
  place-items: center;
}
body.no-bar #stage { inset: 0; }

canvas { display: block; }

#bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: var(--bar-h);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 10px;
  background: linear-gradient(#2a2140, #1b152b);
  border-top: 3px solid var(--ink);
  font-size: 12px;
  color: var(--muted);
}
#room { display: flex; align-items: center; gap: 8px; white-space: nowrap; font-family: var(--font-fun); }
#room b { color: var(--gold); font-size: 17px; letter-spacing: 2px; font-weight: 400; }
#net { flex: 1; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-btns { display: flex; gap: 6px; }

.hidden { display: none !important; }

.overlay {
  animation: fade-in 0.16s ease-out;
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 16px;
  background: radial-gradient(circle at 50% 40%, rgba(30, 20, 50, 0.25), rgba(8, 6, 14, 0.7));
  backdrop-filter: blur(2px);
  overflow: auto;
  z-index: 10;
}
#pause { background: rgba(8, 6, 14, 0.6); }

.panel {
  width: min(560px, 100%);
  background: var(--panel);
  border: 4px solid var(--ink);
  border-radius: 20px;
  padding: 22px;
  box-shadow: 0 8px 0 var(--ink), 0 24px 60px rgba(0, 0, 0, 0.45);
}
.panel.narrow { width: min(400px, 100%); }
.overlay > .panel { animation: pop-in 0.22s cubic-bezier(0.2, 1.4, 0.4, 1); }
@keyframes fade-in { from { opacity: 0; } }
@keyframes pop-in { from { opacity: 0; transform: translateY(14px) scale(0.96); } }
@media (prefers-reduced-motion: reduce) {
  .overlay, .overlay > .panel { animation: none; }
}

h1 {
  margin: -4px 0 0;
  font: 400 60px/1 var(--font-fun);
  letter-spacing: 1px;
  text-align: center;
  color: var(--gold);
  -webkit-text-stroke: 8px var(--ink);
  paint-order: stroke fill;
  text-shadow: 0 6px 0 var(--ink);
  transform: rotate(-2deg);
}
h1 span:first-child { color: var(--red); }
h1 span:last-child { color: var(--blue); }
h2 {
  margin: 0 0 10px;
  font: 400 15px var(--font-fun);
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--text);
}
.sub { text-align: center; color: var(--muted); margin: 12px 0 18px; }
.hint { color: var(--muted); margin: -4px 0 12px; font-size: 12px; }

.card {
  background: var(--card);
  border: 3px solid var(--ink);
  border-radius: 14px;
  padding: 14px;
  margin-top: 12px;
}

label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); flex: 1; font-weight: 600; }
label.check { flex-direction: row; align-items: center; gap: 8px; margin-top: 10px; font-size: 13px; color: var(--text); cursor: pointer; }
.field-row { display: flex; gap: 10px; }

input, select {
  font: inherit;
  font-weight: 600;
  color: var(--text);
  background: var(--field);
  border: 3px solid var(--ink);
  border-radius: 10px;
  padding: 8px 10px;
  min-width: 0;
}
input:focus, select:focus { outline: 3px solid var(--gold); outline-offset: 0; }
input[type=checkbox] { width: 18px; height: 18px; accent-color: var(--gold); }

button {
  font: 400 16px var(--font-fun);
  letter-spacing: 0.5px;
  color: var(--ink);
  background: var(--gold);
  border: 3px solid var(--ink);
  border-radius: 12px;
  padding: 9px 16px;
  cursor: pointer;
  box-shadow: 0 4px 0 var(--ink), inset 0 -4px 0 rgba(0, 0, 0, 0.15), inset 0 3px 0 rgba(255, 255, 255, 0.35);
  transition: transform 0.05s, box-shadow 0.05s;
}
button:hover { filter: brightness(1.08); transform: translateY(-1px); }
button:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink), inset 0 -2px 0 rgba(0, 0, 0, 0.15); }
button:disabled { opacity: 0.5; cursor: default; transform: none; }
button.ghost { background: #3a2e55; color: var(--text); }
button.danger { background: #c9364a; color: #fff; }
button.small { padding: 3px 10px; font-size: 13px; border-radius: 9px; box-shadow: 0 3px 0 var(--ink); }
button.team0 { background: var(--red); color: #fff; }
button.team1 { background: var(--blue); color: #fff; }

.btns { display: flex; gap: 10px; margin-top: 12px; }
.btns button { flex: 1; }
.stack { display: flex; flex-direction: column; gap: 10px; }

.adv summary { width: max-content; cursor: pointer; font: 400 14px var(--font-fun); letter-spacing: 0.5px; color: var(--muted); }
.adv summary:hover { color: var(--text); }
.adv > .stack { margin-top: 10px; }
.adv label.check { margin-top: 0; }
.pcol { flex: 1; min-width: 0; }
.hatpick { display: grid; grid-template-columns: auto 84px auto 1fr; align-items: center; gap: 6px; }
.hatpick canvas { width: 84px; height: 77px; background: var(--field); border: 3px solid var(--ink); border-radius: 12px; }
.hatpick span { font: 400 13px var(--font-fun); color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.help ul { margin: 10px 0 0; padding-left: 18px; color: var(--muted); font-size: 13px; line-height: 1.6; }
.help kbd { display: inline-block; min-width: 22px; padding: 0 6px; border-radius: 6px; background: var(--field); color: var(--text); box-shadow: 0 2px 0 var(--ink); font: 400 12px var(--font-fun); text-align: center; }

.join { display: flex; gap: 10px; }
.join input { flex: 1; text-transform: uppercase; letter-spacing: 6px; font: 400 22px var(--font-fun); text-align: center; }

#menuMsg { min-height: 20px; margin: 12px 0 0; text-align: center; color: var(--gold); font-weight: 600; }
#menuMsg.err { color: #ff8f7a; }


@media (max-width: 520px) {
  .field-row, .btns { flex-direction: column; }
  h1 { font-size: 44px; }
  #net { display: none; }
}

#settings { z-index: 12; }
label.range { flex-direction: row; align-items: center; gap: 12px; margin: 6px 0; color: var(--text); }
label.range input { flex: 1; accent-color: var(--gold); }
table.keys { width: 100%; border-collapse: collapse; margin: 6px 0 10px; }
table.keys th { text-align: left; font: 400 13px var(--font-fun); color: var(--muted); padding: 2px 4px; }
table.keys td { padding: 3px 4px; font-weight: 600; }
button.key { width: 100%; padding: 5px 8px; font-size: 14px; background: var(--field); color: var(--text); box-shadow: 0 3px 0 var(--ink); }
button.key.wait { background: var(--gold); color: var(--ink); }

#chat {
  position: fixed;
  left: 50%;
  bottom: calc(var(--bar-h) + 10px);
  transform: translateX(-50%);
  width: min(420px, calc(100% - 20px));
  display: flex;
  flex-direction: column;
  gap: 6px;
  z-index: 6;
}
#chatEmojis { display: flex; flex-wrap: wrap; gap: 4px; }
#chatEmojis button { padding: 2px 6px; font: 16px system-ui, sans-serif; background: rgba(46, 36, 69, 0.85); box-shadow: 0 2px 0 var(--ink); border-radius: 8px; }
#chatEmojis small { font: 400 10px var(--font-fun); color: var(--muted); margin-left: 2px; }
.chat-keys { margin: 10px 0 0; }

#touch {
  position: fixed;
  left: 0;
  right: 0;
  bottom: calc(var(--bar-h) + 10px);
  display: flex;
  justify-content: space-between;
  padding: 0 14px;
  pointer-events: none;
  z-index: 5;
  user-select: none;
  -webkit-user-select: none;
}
#touch .tpad { display: flex; gap: 12px; align-items: flex-end; pointer-events: auto; }
#touch button {
  width: 68px;
  height: 68px;
  border-radius: 50%;
  font-size: 26px;
  background: rgba(46, 36, 69, 0.75);
  color: #fff;
  touch-action: none;
}
#touch button.small-k { width: 54px; height: 54px; font-size: 22px; }
#touch button.down { background: var(--gold); color: var(--ink); transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }

.debug {
  position: fixed;
  top: 8px;
  left: 8px;
  width: 330px;
  max-height: calc(100vh - 60px);
  overflow: auto;
  z-index: 20;
  padding: 10px;
  background: rgba(12, 9, 20, 0.88);
  border: 3px solid var(--ink);
  border-radius: 12px;
  font: 11px/1.45 ui-monospace, Menlo, Consolas, monospace;
  color: #dcd3f0;
}
.debug-head { display: flex; justify-content: space-between; margin-bottom: 6px; }
.debug-head b { font: 400 15px var(--font-fun); color: var(--gold); letter-spacing: 1px; }
.debug-head span { color: var(--muted); }
.debug-text > div { display: flex; gap: 8px; }
.debug-text span { flex: 0 0 92px; color: var(--muted); }
.debug-text b { font-weight: 600; color: #fff; }
.debug-graph { display: block; width: 100%; height: 70px; margin: 8px 0 2px; background: rgba(255, 255, 255, 0.04); border-radius: 6px; }
.debug-legend { color: var(--muted); font-size: 10px; }
.debug-legend i { display: inline-block; width: 8px; height: 8px; margin: 0 3px 0 6px; border-radius: 2px; }
.debug-legend .lg-rb { background: #ffd23f; }
.debug-legend .lg-rtt { background: #4aa3ff; }
.debug-legend .lg-st { background: rgba(255, 80, 80, 0.6); }
.debug-sub { margin: 10px 0 4px; font: 400 13px var(--font-fun); color: var(--text); letter-spacing: 0.5px; }
.debug-muted { color: var(--muted); }
.debug table { width: 100%; border-collapse: collapse; }
.debug th { text-align: left; color: var(--muted); font-weight: 400; padding: 1px 3px; }
.debug td { padding: 1px 3px; }
.debug input[type=number] { width: 64px; padding: 2px 4px; border-width: 2px; border-radius: 6px; font: 11px ui-monospace, Menlo, monospace; }
.debug-clients { margin-top: 6px; }
.debug-toggles { display: flex; gap: 14px; margin-top: 8px; }
.debug-toggles label { flex-direction: row; align-items: center; gap: 4px; color: var(--text); flex: 0; white-space: nowrap; }
