* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: #0d111a;
  color: #eef;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
}

/* ----- Host ----- */
.host { position: fixed; inset: 0; display: flex; flex-direction: column; }
.lobby {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
  padding: 32px;
}
.lobby .left {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
}
.lobby h1 { font-size: 4rem; margin: 0 0 0.5rem; letter-spacing: -0.02em; }
.lobby .subtitle { color: #93a; margin-bottom: 1rem; color: #9aa5c2; }
.lobby .code {
  font-family: "SF Mono", ui-monospace, monospace;
  font-size: 9rem;
  font-weight: 800;
  letter-spacing: 0.5rem;
  background: linear-gradient(135deg, #f97316, #ef4444);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  line-height: 1;
  margin: 0.5rem 0 1rem;
}
.lobby .join { font-size: 1.5rem; color: #cbd5e1; }
.lobby .url { font-family: "SF Mono", ui-monospace, monospace; color: #fb923c; text-decoration: none; }
.lobby .url:hover { text-decoration: underline; }
.lobby .copy {
  margin-left: 10px;
  padding: 4px 10px;
  font-size: 0.85rem;
  font-weight: 700;
  color: #cbd5e1;
  background: #1a2030;
  border: 1px solid #334155;
  border-radius: 8px;
  cursor: pointer;
  vertical-align: middle;
}
.lobby .copy:hover { background: #253046; }
.lobby .copy.done { color: #86efac; border-color: #22c55e; }
.lobby .right h2 { font-size: 2rem; margin: 0 0 1rem; }
.lobby .right ul { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 0.5rem; }
.lobby .right li {
  display: flex; align-items: center; gap: 14px;
  padding: 14px 18px;
  background: #1a2030;
  border-radius: 12px;
  font-size: 1.4rem;
}
.lobby .right .swatch { width: 24px; height: 24px; border-radius: 50%; box-shadow: inset 0 0 0 2px rgba(255,255,255,0.2); }
.lobby .win-settings {
  margin-top: 28px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 16px 24px;
  background: #1a2030;
  border-radius: 12px;
  min-width: 360px;
}
.lobby .win-settings label { font-size: 1.1rem; color: #cbd5e1; }
.lobby .win-settings strong { color: #fbbf24; font-size: 1.3rem; }
.lobby .win-settings input[type="range"] {
  width: 100%;
  accent-color: #f97316;
}

.lobby .mode-settings {
  margin-top: 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 14px 24px;
  background: #1a2030;
  border-radius: 12px;
  min-width: 360px;
  max-width: 420px;
}
.lobby .mode-toggle {
  display: inline-flex;
  padding: 4px;
  background: #0d111a;
  border-radius: 10px;
  gap: 4px;
}
.lobby .mode-toggle button {
  padding: 8px 20px;
  font-size: 1.05rem;
  font-weight: 700;
  color: #94a3b8;
  background: transparent;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
}
.lobby .mode-toggle button.active { background: #f97316; color: #0d111a; }
.lobby .mode-desc { font-size: 0.95rem; color: #cbd5e1; text-align: center; }
.lobby .host-name { display: flex; align-items: center; gap: 10px; margin-top: 6px; font-size: 1rem; color: #cbd5e1; }
.lobby .host-name input {
  width: 180px; padding: 8px 12px; font-size: 1.05rem;
  background: #0d111a; color: #eef;
  border: 2px solid #1f2937; border-radius: 8px;
}
.lobby .host-name input:focus { outline: none; border-color: #fb923c; }
.lobby .right li .you {
  font-size: 0.7em; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em;
  color: #0d111a; background: #fff; padding: 2px 6px; border-radius: 4px; margin-left: 6px;
}

.lobby .start {
  margin-top: 24px;
  padding: 18px 36px;
  font-size: 1.6rem;
  font-weight: 700;
  background: #22c55e;
  color: #052e16;
  border: 0;
  border-radius: 14px;
  cursor: pointer;
}
.lobby .start:disabled { background: #334155; color: #94a3b8; cursor: not-allowed; }

.game {
  flex: 1;
  position: relative;
  background: #0d111a;
}
.game canvas {
  width: 100%;
  height: 100%;
  display: block;
}
.hud {
  position: absolute;
  top: 16px;
  left: 16px;
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}
.hud .card {
  background: rgba(0,0,0,0.55);
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 1rem;
  display: flex;
  align-items: center;
  gap: 10px;
}
.hud .swatch { width: 14px; height: 14px; border-radius: 50%; }
.hud .bar {
  width: 140px; height: 8px;
  background: #1f2937; border-radius: 4px; overflow: hidden;
}
.hud .bar > div { height: 100%; background: #fbbf24; }
.hud .card.mine { outline: 2px solid rgba(255,255,255,0.7); }
.hud .you {
  font-size: 0.7em; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.08em; color: #0d111a; background: #fff;
  padding: 1px 5px; border-radius: 4px; margin-left: 4px; vertical-align: middle;
}
.key-hint {
  position: absolute; left: 16px; bottom: 16px;
  padding: 8px 12px; border-radius: 10px;
  background: rgba(0,0,0,0.55); color: #cbd5e1; font-size: 0.9rem;
}
.key-hint kbd {
  display: inline-block; min-width: 1.5em; padding: 2px 5px; margin-right: 2px;
  font-family: "SF Mono", ui-monospace, monospace; font-size: 0.8rem;
  background: rgba(255,255,255,0.12); border: 1px solid rgba(255,255,255,0.25);
  border-bottom-width: 3px; border-radius: 5px; text-align: center;
}
.end-game {
  position: absolute;
  top: 16px;
  right: 16px;
  padding: 10px 16px;
  font-size: 1rem;
  font-weight: 700;
  color: #fca5a5;
  background: rgba(0,0,0,0.55);
  border: 1px solid rgba(252,165,165,0.35);
  border-radius: 10px;
  cursor: pointer;
}
.end-game:hover { background: rgba(127,29,29,0.7); color: #fee2e2; }

.banner {
  position: absolute;
  inset: 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  background: rgba(0,0,0,0.7);
  font-size: 4rem;
  text-align: center;
  z-index: 50;
}
.banner .sub { font-size: 1.5rem; color: #cbd5e1; margin-top: 1rem; }
.banner .btn {
  margin-top: 2rem;
  padding: 14px 28px;
  font-size: 1.2rem;
  font-weight: 700;
  background: #f97316;
  color: #0d111a;
  border: 0;
  border-radius: 12px;
  cursor: pointer;
}

/* ----- Phone controller ----- */
.play {
  position: fixed; inset: 0;
  display: flex; flex-direction: column;
}
.play .form {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 24px; gap: 16px;
}
.play .form h1 { margin: 0 0 8px; font-size: 2.2rem; }
.play .form input {
  width: 100%; max-width: 320px;
  font-size: 1.6rem; padding: 14px 16px;
  background: #1a2030; color: #eef;
  border: 2px solid #1f2937; border-radius: 12px;
  text-align: center;
  -webkit-appearance: none;
}
.play .form input:focus { outline: none; border-color: #fb923c; }
.play .form button {
  width: 100%; max-width: 320px;
  font-size: 1.4rem; padding: 16px;
  background: #f97316; color: #0d111a;
  font-weight: 700;
  border: 0; border-radius: 12px;
  cursor: pointer;
}
.play .form .err { color: #fca5a5; min-height: 1.2em; }

.play .pad {
  flex: 1; display: grid; grid-template-columns: 1fr 1fr;
  position: relative;
  /* Two fingers on the pad must never become a pinch-zoom / scroll gesture —
     that would pointercancel the joystick the moment a button is touched. */
  touch-action: none;
  -webkit-touch-callout: none;
}
.play .stick {
  position: relative;
  background: #11161f;
  display: flex; align-items: center; justify-content: center;
  touch-action: none;
}
.play .stick .knob {
  position: absolute;
  width: 88px; height: 88px;
  background: #475569; border: 4px solid #1f2937;
  border-radius: 50%;
  transition: background 0.1s;
}
.play .stick .knob.active { background: #f97316; }
.play .stick .ring {
  width: 220px; height: 220px;
  border: 4px dashed #1f2937;
  border-radius: 50%;
}
.play .buttons {
  display: grid; grid-template-rows: 1fr 1fr; gap: 4px;
}
.play .btn {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  font-size: 1.4rem; font-weight: 700;
  background: #1a2030;
  color: #eef;
  border: 0;
  cursor: pointer;
  text-align: center;
  padding: 12px;
  touch-action: none;
  transition: background 0.1s;
}
.play .btn .icon { font-size: 3rem; line-height: 1; }
.play .btn .label { font-size: 0.95rem; opacity: 0.85; margin-top: 6px; }
.play .btn.pressed:not(:disabled) { background: #2a3347; }
.play .btn.hype.active { background: #f97316; color: #0d111a; }
.play .btn.hype.active.pressed { background: #fb923c; }
.play .btn.castle:disabled { color: #475569; }
.play .btn.castle:disabled .icon { filter: grayscale(1) opacity(0.5); }

/* Keyboard key badges — only shown on hover-capable devices (desktops) */
.kbd {
  display: none;
  margin-left: 6px;
  padding: 1px 6px;
  font-family: "SF Mono", ui-monospace, monospace;
  font-size: 0.75rem;
  background: rgba(255,255,255,0.12);
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 4px;
  vertical-align: middle;
}
.kbd-hint {
  display: none;
  position: absolute;
  bottom: 12px;
  font-family: "SF Mono", ui-monospace, monospace;
  font-size: 0.85rem;
  color: #6b7280;
  letter-spacing: 0.15em;
}
@media (hover: hover) and (pointer: fine) {
  .kbd, .kbd-hint { display: inline-block; }
}

/* Remote mode: the player page becomes a spectator view + keyboard */
.play .remote {
  flex: 1;
  position: relative;
  min-height: 0;
}
.play .remote canvas { width: 100%; height: 100%; display: block; }
.play .remote-overlay {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 20px;
  background: rgba(13,17,26,0.85);
  text-align: center; padding: 32px;
}
.play .remote-overlay .big { font-size: 1.6rem; font-weight: 700; }
.play .remote-overlay .keys { display: flex; flex-wrap: wrap; justify-content: center; gap: 18px; color: #cbd5e1; }
.play .remote-overlay kbd {
  display: inline-block; min-width: 1.6em; padding: 3px 6px; margin-right: 3px;
  font-family: "SF Mono", ui-monospace, monospace; font-size: 0.9rem;
  background: rgba(255,255,255,0.12); border: 1px solid rgba(255,255,255,0.25);
  border-bottom-width: 3px; border-radius: 5px; text-align: center;
}

.play .topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 14px;
  background: #11161f;
  border-bottom: 1px solid #1f2937;
  font-size: 0.95rem;
}
.play .topbar .name { display: flex; align-items: center; gap: 8px; font-weight: 700; }
.play .topbar .swatch { width: 14px; height: 14px; border-radius: 50%; }
.play .topbar .stats { display: flex; gap: 14px; color: #cbd5e1; }
.play .endbanner {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,0.85);
  font-size: 1.5rem; text-align: center; padding: 32px;
  z-index: 30;
}
