:root {
  --bg: #0b0e14;
  --panel: #121826;
  --line: #1e2635;
  --text: #d8dee9;
  --dim: #7a8494;
  --accent: #c9a227;
  --danger: #b3564d;
  --ok: #5f9e6e;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

[hidden] { display: none !important; }

/* ---------- setup screen ---------- */

#setup {
  min-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  padding-top: max(24px, env(safe-area-inset-top));
}

.card {
  width: 100%;
  max-width: 420px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 28px;
}

.card h1 {
  margin: 0 0 4px;
  font-size: 22px;
  font-weight: 600;
  letter-spacing: 0.2px;
}

.card h1 .mark { color: var(--accent); }

.card p.sub {
  margin: 0 0 22px;
  color: var(--dim);
  font-size: 13px;
}

.field { margin-bottom: 16px; }

.field label {
  display: block;
  font-size: 12px;
  color: var(--dim);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
}

.field input {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  -webkit-user-select: text;
  user-select: text;
}

.field input:focus {
  outline: none;
  border-color: var(--accent);
}

#btnConnect {
  width: 100%;
  min-height: 48px;
  margin-top: 6px;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: #141003;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
}

#btnConnect:disabled { opacity: 0.55; }

#setupStatus {
  margin-top: 14px;
  min-height: 20px;
  font-size: 13px;
  color: var(--dim);
}

#setupStatus.error { color: var(--danger); }

/* ---------- game screen ---------- */

#stage {
  position: fixed;
  inset: 0;
  background: #000;
  overflow: hidden;
  touch-action: none;
}

#video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #000;
  pointer-events: none;
}

#touch {
  position: absolute;
  inset: 0;
  touch-action: none;
}

/* status chip, top right, out of the way of the notch */
#chip {
  position: absolute;
  top: max(8px, env(safe-area-inset-top));
  right: max(8px, env(safe-area-inset-right));
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 10px;
  border-radius: 20px;
  background: rgba(11, 14, 20, 0.72);
  border: 1px solid rgba(255, 255, 255, 0.08);
  font-size: 11px;
  color: var(--dim);
  pointer-events: none;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

#chip .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--dim);
}

#chip.ok .dot { background: var(--ok); }
#chip.bad .dot { background: var(--danger); }

/* key bar: right edge, collapsible */
#keybarToggle {
  position: absolute;
  right: max(6px, env(safe-area-inset-right));
  bottom: 50%;
  transform: translateY(50%);
  width: 34px;
  height: 56px;
  border-radius: 10px 0 0 10px;
  border: 1px solid var(--line);
  border-right: none;
  background: rgba(18, 24, 38, 0.85);
  color: var(--dim);
  font-size: 15px;
  z-index: 3;
}

#keybar {
  position: absolute;
  top: 50%;
  right: max(44px, calc(env(safe-area-inset-right) + 40px));
  transform: translateY(-50%);
  display: grid;
  grid-template-columns: repeat(3, 52px);
  gap: 6px;
  padding: 8px;
  border-radius: 12px;
  background: rgba(18, 24, 38, 0.88);
  border: 1px solid var(--line);
  z-index: 2;
}

#keybar button {
  min-width: 52px;
  min-height: 44px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
  touch-action: manipulation;
}

#keybar button:active { background: var(--line); }
#keybar button.latched {
  border-color: var(--accent);
  color: var(--accent);
}

#keybar .wide { grid-column: span 3; }

#btnDisconnect {
  position: absolute;
  top: max(8px, env(safe-area-inset-top));
  left: max(8px, env(safe-area-inset-left));
  min-height: 34px;
  padding: 4px 12px;
  border-radius: 17px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(11, 14, 20, 0.72);
  color: var(--dim);
  font-size: 12px;
  z-index: 3;
}

/* chat input: must be focusable to summon the keyboard, but invisible */
#chatInput {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 1px;
  height: 1px;
  opacity: 0.01;
  border: none;
  background: transparent;
  color: transparent;
}

/* reconnect banner */
#banner {
  position: absolute;
  left: 50%;
  bottom: max(14px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  padding: 8px 16px;
  border-radius: 20px;
  background: rgba(179, 86, 77, 0.16);
  border: 1px solid var(--danger);
  color: var(--text);
  font-size: 13px;
  z-index: 3;
}
