html:has(.join-body) {
  height: 100%;
  overflow: hidden;
}

.join-body {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-height: 100dvh;
  overflow: hidden;
  background: transparent;
  font-family: var(--font-sans, "Google Sans", system-ui, sans-serif);
  color: var(--ink);
}

.join-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  padding: 12px 20px;
  gap: 12px;
}

.join-brand-wrap .join-brand.font-brand {
  color: var(--memyellow);
}

.join-back {
  color: var(--ink);
  font-weight: 800;
  text-decoration: none;
  padding: 8px 14px;
  background: var(--white);
  border: 3px solid var(--ink);
  border-radius: 999px;
  box-shadow: var(--shadow-sticker);
}

.join-brand.font-brand {
  color: var(--memyellow);
}

.join-main {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
  padding: 16px 20px;
  overflow: hidden;
}

.join-main.hidden {
  display: none !important;
}

.join-body:has(#studentRoom:not(.hidden)) .site-footer-mini {
  display: none;
}

.join-body:has(#studentRoom:not(.hidden)) .join-header {
  display: none;
}

.join-body:has(#studentRoom:not(.hidden)) {
  padding: 0;
}

.join-card,
.join-room-card {
  width: 100%;
  max-width: 420px;
  background: var(--white);
  border: 4px solid var(--ink);
  border-radius: 24px;
  padding: 32px 24px;
  box-shadow: var(--shadow-sticker);
  text-align: center;
}

.join-card h1 {
  margin: 0 0 8px;
  font-size: 28px;
}

.join-lead {
  color: #555;
  font-weight: 700;
  margin: 0 0 24px;
  line-height: 1.5;
}

.join-qr-hint {
  margin: -12px 0 20px;
  padding: 10px 14px;
  font-size: 14px;
  font-weight: 800;
  color: #1a5c2e;
  background: rgba(107, 191, 138, 0.28);
  border: 2px solid rgba(26, 10, 46, 0.15);
  border-radius: 12px;
  line-height: 1.45;
}

.join-qr-hint.hidden {
  display: none !important;
}

.join-form label {
  display: block;
  text-align: right;
  margin-bottom: 16px;
  font-weight: 800;
}

.join-form input {
  width: 100%;
  margin-top: 6px;
  padding: 16px;
  font-size: 20px;
  font-weight: 800;
  font-family: inherit;
  border: 3px solid #1a0a2e;
  border-radius: 14px;
  background: var(--white);
  color: var(--ink);
  text-align: center;
  box-sizing: border-box;
}

.join-error {
  color: #c0392b;
  font-weight: 800;
  margin: 0 0 12px;
}

.join-submit {
  width: 100%;
  padding: 18px;
  font-size: 20px;
  font-weight: 900;
  font-family: inherit;
  background: #ffe135;
  border: 4px solid #1a0a2e;
  border-radius: 16px;
  cursor: pointer;
  box-shadow: 0 6px 0 #1a0a2e;
}

.join-room-badge {
  display: inline-block;
  background: #6bbf8a;
  color: #1a0a2e;
  font-weight: 900;
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 14px;
  margin-bottom: 10px;
}

.join-room-code {
  font-weight: 700;
  color: #666;
}

.join-waiting {
  padding: 32px 0;
}

.join-pulse {
  width: 64px;
  height: 64px;
  margin: 0 auto 16px;
  border-radius: 50%;
  background: var(--electric);
  animation: join-pulse 1.4s ease infinite;
}

@keyframes join-pulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.15); opacity: 0.7; }
}

.join-wait-hint {
  font-size: 14px;
  color: #888;
  font-weight: 700;
}

.join-leave {
  margin-top: 20px;
  width: 100%;
  padding: 14px;
  font-weight: 800;
  font-family: inherit;
  background: transparent;
  border: 3px solid #1a0a2e;
  border-radius: 12px;
  cursor: pointer;
}

.join-chat {
  margin-top: 20px;
  padding-top: 16px;
  border-top: 3px dashed rgba(26, 10, 46, 0.2);
}

.join-chat h3 {
  margin: 0 0 10px;
  font-size: 16px;
  font-weight: 900;
}

.join-suspended {
  margin: 16px 0;
  padding: 16px;
  text-align: center;
  font-weight: 900;
  border: 3px solid #1a0a2e;
  border-radius: 12px;
  background: #ffe135;
}

.join-suspended.hidden {
  display: none;
}

#studentGameContent {
  min-height: 280px;
}

.join-game {
  text-align: right;
  margin-top: 16px;
}

/* Guest room — game + participants only */
.guest-room {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
  padding: 6px 10px 8px;
  max-width: 720px;
  margin: 0 auto;
  width: 100%;
  box-sizing: border-box;
}

.guest-room.hidden {
  display: none !important;
}

.guest-room-top {
  flex-shrink: 0;
  margin-bottom: 0;
}

.guest-room-panel {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  min-height: 0;
  border: 4px solid var(--ink, #1a0a2e);
  border-radius: 16px;
  box-shadow: 0 6px 0 var(--ink, #1a0a2e);
  overflow: hidden;
  background-color: var(--game-stage-bg-color, #b8c0cc);
}

.guest-top-strip {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 10px 12px;
  width: 100%;
  padding: 12px 16px;
  background: var(--memyellow, #ffe135);
  border: none;
  border-bottom: 4px solid var(--ink, #1a0a2e);
  border-radius: 0;
}

.guest-top-strip-info {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 12px;
  flex: 1;
  min-width: 0;
}

.guest-stat-pill {
  display: inline-flex;
  align-items: center;
  padding: 8px 14px;
  font-size: 14px;
  font-weight: 800;
  color: var(--ink, #1a0a2e);
  background: var(--white, #fff);
  border: 3px solid var(--ink, #1a0a2e);
  border-radius: 999px;
  box-shadow: 4px 4px 0 var(--ink, #1a0a2e);
  white-space: nowrap;
}

.guest-stat-pill strong {
  font-size: 1.05rem;
  color: var(--ink, #1a0a2e);
  letter-spacing: 0.06em;
}

.guest-stat-pill--name {
  font-size: 15px;
  font-weight: 900;
}

.guest-leave-btn {
  flex-shrink: 0;
  font-family: inherit;
  cursor: pointer;
  background: #e03030;
  color: #fff;
  border-color: var(--ink, #1a0a2e);
  transition: transform 0.1s ease, background 0.12s ease;
}

.guest-leave-btn:hover {
  background: #c62828;
  transform: translate(-1px, -1px);
}

.guest-game-stage {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: transparent;
  border: none;
  border-radius: 0;
  box-shadow: none;
  overflow: hidden;
}

.guest-waiting {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 0;
  padding: 20px 16px;
  text-align: center;
  font-weight: 800;
}

.guest-wait-hint {
  font-size: 14px;
  color: #888;
  font-weight: 700;
  margin-top: 8px;
}

.guest-suspended {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  text-align: center;
  font-weight: 900;
  background: #ffe135;
}

.guest-suspended.hidden {
  display: none !important;
}

.guest-game {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
  padding: 8px 10px;
  text-align: right;
  color: var(--ink, #1a0a2e);
  background: transparent;
}

.guest-game.hidden {
  display: none !important;
}

#studentGameContent {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.guest-room:has(#studentGame:not(.hidden)) .guest-participants-wrap {
  max-height: 13vh;
  margin-top: 6px;
  padding: 6px 10px;
}

.guest-participants-wrap {
  flex-shrink: 0;
  margin-top: 10px;
  padding: 10px 12px;
  max-height: 22vh;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.12);
  border: 3px solid rgba(255, 255, 255, 0.35);
  border-radius: 16px;
}

.guest-participants-wrap.hidden {
  display: none !important;
}

.guest-participants-title {
  margin: 0 0 10px;
  font-size: 13px;
  font-weight: 900;
  color: #fff;
  text-align: right;
}

.guest-participants-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-start;
  max-height: calc(13vh - 28px);
  overflow: hidden;
  overscroll-behavior: contain;
}

.guest-participant {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  min-width: 72px;
  padding: 8px 10px;
  background: #fff;
  border: 3px solid #1a0a2e;
  border-radius: 12px;
  box-shadow: 3px 3px 0 #1a0a2e;
}

.guest-participant--me {
  outline: 3px solid #ffe135;
}

.guest-participant--suspended {
  opacity: 0.55;
}

.guest-participant-avatar {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 900;
  font-size: 16px;
  border-radius: 50%;
  border: 2px solid #1a0a2e;
  background: #6bbf8a;
}

.guest-participant--teal .guest-participant-avatar { background: #5ec4c4; }
.guest-participant--pink .guest-participant-avatar { background: #ff9ecd; }
.guest-participant--yellow .guest-participant-avatar { background: #ffe135; }
.guest-participant--orange .guest-participant-avatar { background: #ff9f43; }
.guest-participant--lime .guest-participant-avatar { background: #c8f020; }
.guest-participant--blue .guest-participant-avatar { background: #6eb5ff; }
.guest-participant--purple .guest-participant-avatar { background: #c084fc; }

.guest-participant--me .guest-participant-avatar { background: #ff9ecd; }

.guest-participant-name {
  font-size: 11px;
  font-weight: 900;
  text-align: center;
  max-width: 80px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.guest-participant-badge {
  font-size: 10px;
  font-weight: 800;
  color: #c0392b;
}

.guest-chat-wrap {
  flex-shrink: 0;
  margin-top: 10px;
  padding: 10px 12px;
  max-height: 24vh;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.12);
  border: 3px solid rgba(255, 255, 255, 0.35);
  border-radius: 16px;
}

.guest-chat-wrap.hidden {
  display: none !important;
}

.guest-chat-log {
  max-height: 10vh;
  overflow-y: auto;
  overscroll-behavior: contain;
  margin-bottom: 8px;
  text-align: right;
}

.join-body .site-footer-mini {
  flex-shrink: 0;
  padding: 12px 16px calc(16px + env(safe-area-inset-bottom, 0px));
}

/* ── Mobile / student phones ── */
@media (max-width: 640px) {
  html:has(.join-body:not(:has(#studentRoom:not(.hidden)))) {
    height: auto;
    overflow: auto;
  }

  .join-body:not(:has(#studentRoom:not(.hidden))) {
    height: auto;
    min-height: 100dvh;
    max-height: none;
    overflow: auto;
  }

  .join-header {
    padding: calc(10px + env(safe-area-inset-top, 0px)) 14px 10px;
  }

  .join-main {
    align-items: flex-start;
    padding: 12px 14px calc(20px + env(safe-area-inset-bottom, 0px));
    overflow: visible;
  }

  .join-card,
  .join-room-card {
    padding: 24px 18px;
    border-radius: 20px;
    box-shadow: 0 10px 0 #1a0a2e;
  }

  .join-card h1 {
    font-size: 24px;
  }

  .join-lead {
    font-size: 15px;
    margin-bottom: 18px;
  }

  .join-form input {
    font-size: 16px;
    padding: 14px;
    min-height: 48px;
  }

  .join-submit,
  .join-leave {
    min-height: 48px;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
  }

  .guest-room {
    padding: calc(4px + env(safe-area-inset-top, 0px)) 6px calc(6px + env(safe-area-inset-bottom, 0px));
    max-width: none;
  }

  .guest-top-strip {
    padding: 10px 12px;
    gap: 8px;
  }

  .guest-top-strip-info {
    gap: 6px 8px;
    flex: 1 1 100%;
  }

  .guest-stat-pill {
    padding: 6px 10px;
    font-size: 12px;
    box-shadow: 3px 3px 0 var(--ink, #1a0a2e);
  }

  .guest-stat-pill--name {
    max-width: min(140px, 42vw);
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .guest-leave-btn {
    margin-right: auto;
    min-height: 40px;
  }

  .guest-participants-wrap {
    max-height: 18vh;
    margin-top: 6px;
    padding: 8px 10px;
  }

  .guest-room:has(#studentGame:not(.hidden)) .guest-participants-wrap {
    max-height: 11vh;
  }

  .guest-participants-strip {
    gap: 6px;
    max-height: calc(11vh - 24px);
  }

  .guest-participant {
    min-width: 60px;
    padding: 6px 8px;
  }

  .guest-participant-avatar {
    width: 30px;
    height: 30px;
    font-size: 14px;
  }

  .guest-participant-name {
    font-size: 10px;
    max-width: 64px;
  }

  .guest-game {
    padding: 6px 8px;
  }

  .guest-chat-wrap {
    max-height: 20vh;
  }

  .guest-chat-log {
    max-height: 9vh;
  }
}

@media (max-width: 380px) {
  .guest-top-strip-info .guest-stat-pill:first-child {
    display: none;
  }

  .join-back {
    padding: 8px 12px;
    font-size: 14px;
  }
}

@media (max-height: 520px) and (orientation: landscape) {
  .join-main {
    align-items: flex-start;
    padding-top: 8px;
  }

  .join-card {
    padding: 16px 18px;
  }

  .join-card h1 {
    font-size: 22px;
    margin-bottom: 4px;
  }

  .join-lead {
    margin-bottom: 12px;
    font-size: 14px;
  }

  .join-form label {
    margin-bottom: 10px;
  }

  .guest-participants-wrap,
  .guest-chat-wrap {
    display: none;
  }
}

/* Touch-friendly game controls inside guest room */
.guest-game .quiz-option,
.guest-game .letter-btn,
.guest-game .memory-card,
.guest-game .runner-lane-btn,
.guest-game .candy-tile,
.guest-game .scramble-chip,
.guest-game .spot-cell,
.guest-game .shop-item,
.join-submit,
.guest-leave-btn {
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

@media (max-width: 640px) {
  .guest-game .quiz-options {
    gap: 10px;
  }

  .guest-game .quiz-option {
    padding: 14px 16px;
    font-size: 16px;
    min-height: 48px;
  }

  .guest-game .hangman-letters {
    gap: 6px;
  }

  .guest-game .letter-btn {
    min-width: 36px;
    min-height: 40px;
    padding: 8px 10px;
    font-size: 15px;
  }

  .guest-game .game-question {
    font-size: clamp(22px, 6vw, 32px);
    margin: 12px 0;
  }

  .guest-game .runner-lane-btn {
    min-height: 44px;
    padding: 12px 18px;
  }

  .guest-game .game-actions .btn {
    min-height: 44px;
  }
}
