/* The big screen. rem follows the window's height, so the same layout fills a laptop or a TV. */

html.host { font-size: clamp(9px, 1.55vh, 28px); }
/* a phone held upright: the layout follows the width instead, and stacks */
@media (orientation: portrait) { html.host { font-size: clamp(9px, 3.2vw, 28px); } }
html.host body { overflow: hidden; }
.host .screen { position: fixed; inset: 0; }

/* ---------- Lobby: the rule film on the left, joining on the right ---------- */

.lesson-stage { position: absolute; inset: 0; }
.lesson-stage canvas { display: block; }
.lesson-ui { position: absolute; inset: 0; pointer-events: none; }

.join {
  position: absolute;
  top: 0;
  bottom: 0;
  right: 0;
  width: clamp(17rem, 27vw, 34rem);
  padding: 4.2rem 2.4rem 3rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.1rem;
  background: linear-gradient(to left, rgba(6, 8, 11, 0.86) 55%, rgba(6, 8, 11, 0));
}
.join .wordmark { font-size: 1.35rem; margin-bottom: 1.4rem; }
/* a phone held upright: joining is a band across the top, the rule film plays below it */
@media (orientation: portrait) {
  .lesson-stage, .lesson-ui { top: 30vh; }
  .lesson-stage { -webkit-mask-image: linear-gradient(to bottom, transparent, #000 6rem); mask-image: linear-gradient(to bottom, transparent, #000 6rem); }
  .join { z-index: 1; left: 0; width: auto; bottom: auto; max-height: 62vh; padding: 2.4rem 1.6rem 2rem; background: linear-gradient(to bottom, rgba(6, 8, 11, 0.9) 75%, rgba(6, 8, 11, 0)); }
  .join .wordmark { margin-bottom: 0.4rem; }
  .join-qr img { width: min(15rem, 42vw); }
  .lobby-players { flex: 0 1 auto; overflow: hidden; margin-top: 0.4rem; grid-template-columns: 1fr 1fr; }
  .go { position: fixed; right: 1.6rem; bottom: 1.6rem; }
}
.join-qr {
  padding: 0.8rem;
  border-radius: 1.2rem;
  background: #fff;
  box-shadow: 0 0 3rem rgba(244, 239, 228, 0.22), 0 0 0 1px rgba(255, 255, 255, 0.4);
}
.join-qr img { display: block; width: min(15rem, 22vw); aspect-ratio: 1; image-rendering: pixelated; border-radius: 0.4rem; }
/* until the room's code is ready: no broken-image icon, just the card breathing with a faint shimmer, and the
   code fades in when it arrives */
.join-qr { position: relative; overflow: hidden; }
.join-qr img { opacity: 0; transition: opacity 0.6s ease; }
.join-qr.ready img { opacity: 1; }
.join-qr:not(.ready) { animation: join-wait 2.4s ease-in-out infinite; }
.join-qr:not(.ready)::after {
  content: "";
  position: absolute;
  inset: 0.8rem;
  border-radius: 0.4rem;
  background:
    linear-gradient(105deg, transparent 30%, rgba(255, 255, 255, 0.7) 50%, transparent 70%) 0 0 / 250% 100%,
    repeating-linear-gradient(0deg, rgba(11, 14, 19, 0.05) 0 0.55rem, transparent 0.55rem 1.1rem),
    repeating-linear-gradient(90deg, rgba(11, 14, 19, 0.05) 0 0.55rem, transparent 0.55rem 1.1rem);
  animation: join-shimmer 1.8s linear infinite;
}
@keyframes join-wait { 50% { box-shadow: 0 0 2rem rgba(244, 239, 228, 0.12), 0 0 0 1px rgba(255, 255, 255, 0.3); } }
@keyframes join-shimmer { from { background-position: 150% 0, 0 0, 0 0; } to { background-position: -100% 0, 0 0, 0 0; } }
/* only the QR shows; the address appears under it on hover, or when it's held down on a touch screen */
.join-scan { position: relative; z-index: 2; align-self: stretch; display: flex; flex-direction: column; align-items: center; }
.join-qr { -webkit-touch-callout: none; user-select: none; -webkit-user-select: none; }
.join-reveal {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  padding: 1.1rem 0 1.2rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.1rem;
  border-radius: 0 0 1rem 1rem;
  background: rgba(6, 8, 11, 0.92);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s, visibility 0s 0.2s;
}
.join-qr:hover + .join-reveal,
.join-reveal:hover,
.join-scan.reveal .join-reveal { opacity: 1; visibility: visible; transition: opacity 0.2s; }
/* QR — or — the address (which, on the website, already has the room code in it) */
.join-or {
  display: flex;
  align-items: center;
  gap: 1rem;
  width: 72%;
  font-size: 1rem;
  font-weight: 400;
  letter-spacing: 0.3em;
  text-indent: 0.3em;
  text-transform: uppercase;
  color: var(--faint);
}
.join-or::before,
.join-or::after { content: ""; flex: 1; height: 1px; background: linear-gradient(to right, transparent, var(--hair2)); }
.join-or::after { background: linear-gradient(to left, transparent, var(--hair2)); }
/* the same thin, tracked type as the wordmark; host.js sizes it to exactly the QR card's width */
.join-link { display: flex; flex-direction: column; align-items: center; width: 100%; text-decoration: none; cursor: pointer; font-size: 2.2rem; font-weight: 200; line-height: 1.22; letter-spacing: 0.06em; color: var(--light); text-align: center; }
.join-link span { display: block; width: max-content; padding-left: 0.06em; white-space: nowrap; } /* (balances the tracking after the last letter) */
.join-link b { font-weight: inherit; }
.join-link:hover { color: #fff; }
.join-local { display: flex; align-items: center; gap: 0.5rem; font-size: 1.1rem; color: var(--dim); letter-spacing: 0.04em; }
.join-local svg { width: 1.6rem; height: 1.6rem; color: var(--faint); }
.join-local b { font-weight: 400; }

.lobby-players {
  flex: 1;
  min-height: 0;
  width: 100%;
  margin-top: 1.2rem;
  display: grid;
  grid-template-columns: 1fr;
  align-content: start;
  gap: 0.5rem 1.2rem;
}
.lobby-players.two { grid-template-columns: 1fr 1fr; }
.lp {
  --c: #999;
  position: relative;
  display: flex;
  align-items: center;
  gap: 0.8rem;
  min-width: 0;
  height: 2.7rem;
  animation: lp-in 0.9s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.lp-bot { position: relative; flex: none; display: grid; }
.lp .lm-bot { width: 2.3rem; height: 2.3rem; flex: none; filter: drop-shadow(0 0 0.5rem color-mix(in srgb, var(--c) 60%, transparent)); }
/* the leader (starts the game from their phone): a small crown of light on their robot */
.lp-leader {
  position: absolute; top: -0.7rem; right: -0.75rem; width: 1.4rem; height: 1.4rem; color: var(--light);
  filter: drop-shadow(0 0 0.3rem rgba(244, 239, 228, 0.7)); transform: rotate(12deg);
}
.lp-leader svg { display: block; width: 100%; height: 100%; }
.lp-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 400;
  font-size: 1.15rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}
.lp.away { opacity: 0.35; }
.lp-link { display: grid; color: var(--faint); }
.lp-link svg { width: 1.3rem; height: 1.3rem; }
.lp-kick {
  margin-left: auto;
  appearance: none;
  border: 0;
  background: none;
  color: var(--faint);
  cursor: pointer;
  opacity: 0;
  font-size: 0.9rem;
  transition: opacity 0.2s;
}
.lp:hover .lp-kick { opacity: 1; }
@keyframes lp-in {
  0% { opacity: 0; transform: translateX(1.5rem); filter: blur(6px); }
  100% { opacity: 1; transform: none; filter: none; }
}
.lobby-empty { display: flex; gap: 0.5rem; justify-content: center; padding-top: 0.6rem; }
.lobby-empty i { width: 2.3rem; height: 2.3rem; border-radius: 50%; border: 1px dashed var(--hair2); animation: lm-breathe-slow 3s ease-in-out infinite; }
.lobby-empty i:nth-child(2) { animation-delay: 0.4s; }
.lobby-empty i:nth-child(3) { animation-delay: 0.8s; }
@keyframes lm-breathe-slow { 50% { opacity: 0.3; } }

.last-result {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  color: var(--dim);
  font-size: 0.95rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}
.last-result .lm-bot { width: 1.6rem; height: 1.6rem; }
.last-result .lm-g { width: 1.3rem; height: 1.3rem; color: var(--light); }

.go {
  flex: none;
  appearance: none;
  display: grid;
  place-items: center;
  width: 4.6rem;
  height: 4.6rem;
  border-radius: 50%;
  border: 1px solid var(--light);
  background: var(--light);
  color: var(--ink);
  cursor: pointer;
  box-shadow: 0 0 2.6rem rgba(244, 239, 228, 0.35);
  transition: all 0.6s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.go svg { width: 2.2rem; height: 2.2rem; margin-left: .35rem; }
.go:hover:not(:disabled) { transform: scale(1.06); }
.go:disabled { background: transparent; color: var(--faint); border-color: var(--hair2); box-shadow: none; cursor: default; }

.lobby-corner { position: absolute; left: 1.2rem; bottom: 1.2rem; display: flex; gap: 0.5rem; }
.corner-btn {
  appearance: none;
  width: 3.2rem;
  height: 3.2rem;
  display: grid;
  place-items: center;
  border-radius: 50%;
  border: 1px solid var(--hair2);
  background: rgba(12, 15, 20, 0.6);
  color: var(--dim);
  cursor: pointer;
}
.corner-btn svg { width: 1.9rem; height: 1.9rem; }
.corner-btn:hover { color: var(--light); border-color: rgba(244, 239, 228, 0.5); }
.corner-btn.warn { color: var(--energy); border-color: rgba(255, 197, 110, 0.4); animation: lm-breathe-slow 2.4s ease-in-out infinite; }

/* ---------- In a game ---------- */

.game-screen .stage { position: absolute; inset: 0; }
.game-screen .game-root { position: absolute; inset: 0; }
.game-menu {
  position: absolute;
  top: 1.2rem;
  left: 1.2rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  opacity: 0;
  transition: opacity 0.6s;
  z-index: 5;
}
body.pointer .game-menu { opacity: 1; }
@media (hover: none) { .game-menu { opacity: 0.85; } } /* a touch screen has no mouse to wake it */
.menu-btn {
  appearance: none;
  width: 3.2rem;
  height: 3.2rem;
  display: grid;
  place-items: center;
  border-radius: 50%;
  border: 1px solid var(--hair2);
  background: rgba(12, 15, 20, 0.6);
  color: var(--light);
  cursor: pointer;
}
.menu-btn svg { width: 1.8rem; height: 1.8rem; }
.menu-btn:hover { color: var(--light); border-color: rgba(244, 239, 228, 0.5); }

.denied { position: fixed; inset: 0; display: grid; place-content: center; justify-items: center; gap: 1.6rem; text-align: center; padding: 2rem; }
.denied p { max-width: 30rem; color: var(--dim); }

/* ---------- Your own controller on this screen: the phone page in a panel over the big screen ---------- */

.play-panel {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 20; width: min(100vw, 30rem);
  display: flex; flex-direction: column; background: var(--ink); box-shadow: -1rem 0 3rem rgba(0, 0, 0, 0.6);
  transform: translateX(105%); visibility: hidden; transition: transform 0.35s cubic-bezier(0.2, 0.8, 0.2, 1), visibility 0s 0.35s;
}
.play-panel.open { transform: none; visibility: visible; transition: transform 0.35s cubic-bezier(0.2, 0.8, 0.2, 1); }
@media (orientation: portrait) { .play-panel { width: 100vw; } }
.play-back {
  appearance: none; flex: none; display: flex; align-items: center; justify-content: center; gap: 0.6rem; height: 3.2rem;
  border: 0; border-bottom: 1px solid var(--hair2); background: rgba(12, 15, 20, 0.9); color: var(--light); font: inherit;
  font-size: 1.05rem; letter-spacing: 0.14em; text-transform: uppercase; cursor: pointer;
}
.play-back svg { width: 1.8rem; height: 1.8rem; }
.play-panel iframe { flex: 1; width: 100%; border: 0; background: var(--ink); }
