:root {
  --bg: #0b0e16;
  --panel: #141a26;
  --panel2: #121826;
  --border: #2a3346;
  --p1: #ff7a18;
  --p1g: #ffb56b;
  --p2: #38bdf8;
  --p2g: #7dd3fc;
  --text: #c7d0e0;
  --muted: #6b7689;
}
* { box-sizing: border-box; }
html, body {
  margin: 0;
  min-height: 100%;
  background: radial-gradient(1200px 800px at 50% -10%, #131a28, var(--bg));
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  user-select: none;
}
.window {
  width: min(96vw, 1140px);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 24px 70px rgba(0,0,0,.6);
  overflow: hidden;
}
.titlebar {
  display: flex; align-items: center; gap: 8px;
  padding: 9px 12px; font-size: 13px;
  background: linear-gradient(#1b2333, #151c2a);
  border-bottom: 1px solid var(--border);
}
.titlebar .logo { font-size: 15px; }
.titlebar .title { flex: 1; text-align: center; letter-spacing: .3px; color: #dfe6f2; }
.titlebar .tag {
  font-size: 10px; text-transform: uppercase; letter-spacing: 1px;
  color: var(--p2g); border: 1px solid #244b63; border-radius: 4px;
  padding: 1px 5px; margin-left: 4px;
}
.titlebar .conn { font-size: 11px; color: var(--muted); min-width: 86px; text-align: right; }
.titlebar .conn.on { color: #4ade80; }
.titlebar .conn.off { color: #ff6b6b; }
.dots { display: flex; gap: 6px; }
.dots i { width: 11px; height: 11px; border-radius: 50%; display: inline-block; }
.dots .r { background: #ff5f57; } .dots .y { background: #febc2e; } .dots .g { background: #28c840; }
.menubar {
  display: flex; gap: 6px; padding: 5px 10px;
  font-size: 13px; color: var(--muted);
  border-bottom: 1px solid var(--border); background: var(--panel2);
  position: relative; z-index: 60;
}
.menu { position: relative; }
.menu-label { display: inline-block; cursor: pointer; padding: 3px 9px; border-radius: 5px; }
.menu-label:hover, .menu.open .menu-label { background: #222c3f; color: #dfe6f2; }
.menu-pop {
  position: absolute; top: 100%; left: 0; margin-top: 6px;
  min-width: 180px; background: #1b2333; border: 1px solid var(--border);
  border-radius: 8px; box-shadow: 0 14px 34px rgba(0,0,0,.55);
  padding: 6px; display: none; z-index: 1000;
}
.menu.open .menu-pop { display: block; }
.menu-pop button {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  width: 100%; text-align: left; background: transparent; border: none;
  color: var(--text); font-size: 13px; padding: 8px 10px; border-radius: 6px; cursor: pointer;
}
.menu-pop button:hover { background: #27324a; }
.menu-pop button.checked::after { content: '✓'; color: #4ade80; font-weight: 700; }
.menu-title {
  font-size: 11px; color: var(--muted); padding: 6px 10px 3px;
  text-transform: uppercase; letter-spacing: .6px;
}
.menu-sep { height: 1px; background: var(--border); margin: 5px 6px; }

.modal {
  position: fixed; inset: 0; z-index: 2000;
  display: flex; align-items: center; justify-content: center;
  background: rgba(4,7,12,.6); backdrop-filter: blur(2px);
}
.modal.hidden { display: none; }
.modal-box {
  width: min(92vw, 430px); background: var(--panel);
  border: 1px solid var(--border); border-radius: 10px; padding: 22px;
  box-shadow: 0 24px 60px rgba(0,0,0,.6);
}
.modal-box h2 { margin: 0 0 12px; font-size: 18px; color: #eef2f8; }
.modal-box .mb { color: var(--text); font-size: 13.5px; line-height: 1.6; }
.modal-box .mb p { margin: 0 0 10px; }
.modal-box .mb b { color: #dfe6f2; }
.modal-box kbd {
  background: #0e1623; border: 1px solid var(--border); border-bottom-width: 2px;
  border-radius: 4px; padding: 1px 6px; font-family: inherit; font-size: 12px; color: #dfe6f2;
}
.modal-box .btn { margin-top: 14px; }

.body { display: flex; align-items: stretch; }
.stage { position: relative; background: #070a11; flex: 1 1 auto; min-width: 0; }
canvas { display: block; width: 100%; height: auto; image-rendering: pixelated; }

.overlay {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: rgba(7,10,17,.86); backdrop-filter: blur(2px);
}
.overlay.gone { display: none; }
.screen {
  display: flex; flex-direction: column; align-items: center;
  gap: 12px; text-align: center; padding: 24px; width: 100%; max-width: 380px;
}
.screen.hidden { display: none; }
.screen.light { background: transparent; }
.overlay:has(.light:not(.hidden)) { background: rgba(7,10,17,.45); }
.screen h1 { margin: 0; font-size: 30px; letter-spacing: 1px; }
.screen .sub { margin: 0; color: var(--muted); font-size: 13.5px; line-height: 1.5; }

.field {
  display: flex; flex-direction: column; gap: 5px;
  font-size: 12px; color: var(--muted); width: 100%; text-align: left;
}
input, select {
  background: #1b2333; color: var(--text);
  border: 1px solid var(--border); border-radius: 6px;
  padding: 9px 11px; font-size: 14px; width: 100%;
}
input::placeholder { color: #4a5468; }
input:focus, select:focus { outline: none; border-color: #3b4d6b; }

.actions { display: flex; flex-direction: column; gap: 8px; width: 100%; }
.joinrow { display: flex; gap: 8px; width: 100%; }
.joinrow input { text-transform: uppercase; letter-spacing: 3px; text-align: center; font-weight: 700; }
.joinrow .btn { white-space: nowrap; }

.btn {
  padding: 10px 18px; font-size: 14px; font-weight: 600;
  color: #dfe6f2; background: #222c3f;
  border: 1px solid var(--border); border-radius: 6px;
  cursor: pointer; transition: filter .12s, background .12s;
}
.btn:hover { filter: brightness(1.12); }
.btn:disabled { opacity: .5; cursor: default; filter: none; }
.btn.primary {
  color: #0b0e16; border: none;
  background: linear-gradient(#ffb56b, #ff7a18);
  box-shadow: 0 4px 14px rgba(255,122,24,.35);
}
.btn.ghost { background: transparent; }
.btn.small { padding: 9px 14px; }

.err { color: #ff8080; font-size: 12.5px; min-height: 16px; margin: 0; }
.hint { color: var(--muted); font-size: 12px; min-height: 16px; margin: 0; }

.codebox {
  font-size: 38px; font-weight: 800; letter-spacing: 8px;
  color: var(--p2g); background: #0e1623; border: 1px dashed #2c4a63;
  border-radius: 8px; padding: 10px 18px; cursor: pointer;
}
.playerlist { list-style: none; padding: 0; margin: 4px 0; width: 100%; }
.playerlist li {
  display: flex; align-items: center; gap: 8px; justify-content: space-between;
  padding: 7px 11px; font-size: 14px;
  background: #0e1623; border: 1px solid var(--border);
  border-radius: 6px; margin-bottom: 6px;
}
.playerlist .who { display: flex; align-items: center; gap: 8px; }
.playerlist .pin { width: 10px; height: 10px; border-radius: 2px; }
.playerlist .pin.i0 { background: var(--p1); box-shadow: 0 0 7px var(--p1); }
.playerlist .pin.i1 { background: var(--p2); box-shadow: 0 0 7px var(--p2); }
.playerlist .st { font-size: 11px; color: var(--muted); }
.playerlist .st.ready { color: #4ade80; }

.count { font-size: 120px; font-weight: 800; color: #fff; text-shadow: 0 0 30px rgba(125,211,252,.7); }

/* chat */
.chat {
  width: 280px; flex: 0 0 280px;
  display: flex; flex-direction: column;
  background: var(--panel2); border-left: 1px solid var(--border);
}
.chat-head {
  padding: 10px 14px; font-size: 13px; color: var(--muted);
  border-bottom: 1px solid var(--border); letter-spacing: .5px;
}
.chat-log {
  flex: 1 1 auto; overflow-y: auto; padding: 10px 12px;
  display: flex; flex-direction: column; gap: 6px;
  font-size: 13px; line-height: 1.45; min-height: 0;
}
.chat-log .msg .nm { font-weight: 700; }
.chat-log .msg .nm.i0 { color: var(--p1g); }
.chat-log .msg .nm.i1 { color: var(--p2g); }
.chat-log .msg.sys { color: var(--muted); font-style: italic; }
.chat-form { display: flex; gap: 6px; padding: 10px; border-top: 1px solid var(--border); }
.chat-form input { flex: 1; }

.statusbar {
  display: flex; align-items: center; gap: 16px;
  padding: 9px 16px; font-size: 13px;
  border-top: 1px solid var(--border); background: var(--panel2);
}
.score { display: flex; align-items: center; gap: 7px; }
.score .swatch { width: 11px; height: 11px; border-radius: 2px; }
.score.p1 .swatch { background: var(--p1); box-shadow: 0 0 8px var(--p1); }
.score.p2 .swatch { background: var(--p2); box-shadow: 0 0 8px var(--p2); }
.score b { color: #eef2f8; min-width: 14px; text-align: center; }
.spacer { flex: 1; }
.hud { color: var(--muted); }

@media (max-width: 760px) {
  .body { flex-direction: column; }
  .chat { width: auto; flex: none; border-left: none; border-top: 1px solid var(--border); height: 200px; }
}
