/* Shared chrome for every MiniGame: lobby, invite, join, loading, warnings, leave.
   Games set theme variables (--ink, --muted, --red / --accent, --card, --line, --teal). */

.all-games {
  width: min(420px, 100%);
  margin: 0 0 8px;
  text-align: left;
}
.all-games a {
  color: var(--ink, #111);
  font-size: 14px;
  font-weight: 700;
  text-decoration: none;
  display: inline-block;
  padding: 6px 0;
}
.all-games a:hover { text-decoration: underline; text-underline-offset: 3px; }
#screen-lobby > .all-games {
  width: min(1100px, 100%);
  flex-shrink: 0;
  align-self: stretch;
  margin: 0 0 4px;
  position: relative;
  z-index: 2;
}

.error {
  display: none;
  margin-top: 12px;
  background: #fde8ea;
  color: var(--red, #c41e3a);
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 14px;
}
.error.show { display: block; }

.net-warn {
  margin-top: 14px;
  background: #fff8e1;
  color: #7c4a03;
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 13px;
  line-height: 1.45;
  text-align: left;
}
.net-warn b { display: block; margin-bottom: 4px; }
body.dark .net-warn {
  background: #3d3419;
  color: #fde68a;
}
input.bad {
  border-color: var(--red, #c41e3a);
  background: #fff5f5;
}

.join-status {
  display: none;
  margin-top: 12px;
  border-radius: 12px;
  padding: 10px 12px;
  background: #f4f4f4;
}
.join-status.show { display: block; }
.join-status.connecting,
.join-status.joining { background: #e8f1ff; }
.join-status.ok { background: #e8f8ee; }
.join-status.fail { background: #fde8ea; }
.join-status-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  font-weight: 700;
}
.join-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--teal, #2e8b3a);
  flex-shrink: 0;
}
.join-status.connecting .join-dot,
.join-status.joining .join-dot { animation: mg-pulse-dot .8s ease infinite; }
.join-status.ok .join-dot { background: var(--teal, #2e8b3a); }
.join-status.fail .join-dot { background: var(--red, #c41e3a); }
.join-status.ok .join-status-row { color: #0d6b45; }
.join-status.fail .join-status-row { color: var(--red, #c41e3a); }
.join-bar {
  margin-top: 8px;
  height: 6px;
  border-radius: 99px;
  background: #dbeafe;
  overflow: hidden;
}
.join-status.ok .join-bar { background: #bbf7d0; }
.join-status.fail .join-bar { display: none; }
.join-bar i {
  display: block;
  height: 100%;
  width: 40%;
  border-radius: 99px;
  background: var(--teal, #2e8b3a);
  animation: mg-join-slide 1s ease infinite;
}
.join-status.ok .join-bar i {
  width: 100%;
  animation: none;
}
@keyframes mg-join-slide {
  0% { transform: translateX(-120%); }
  100% { transform: translateX(320%); }
}
@keyframes mg-pulse-dot {
  0%, 100% { opacity: 1; }
  50% { opacity: .35; }
}

.warmup {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 5000;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(12, 10, 10, .62);
}
.warmup.show { display: flex; }
.warmup-card {
  width: min(360px, 100%);
  background: var(--card, #fff);
  color: var(--ink, #111);
  border-radius: 20px;
  padding: 26px 22px;
  text-align: center;
  box-shadow: 0 16px 40px rgba(0, 0, 0, .28);
}
.warmup-spin {
  width: 42px;
  height: 42px;
  margin: 0 auto 14px;
  border: 4px solid #f3e8ea;
  border-top-color: var(--red, #c41e3a);
  border-radius: 50%;
  animation: mg-spin .8s linear infinite;
}
@keyframes mg-spin { to { transform: rotate(360deg); } }
.warmup-card b { display: block; font-size: 18px; margin-bottom: 8px; }
.warmup-card p { color: var(--muted, #6b7280); font-size: 14px; line-height: 1.4; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%) translateY(20px);
  background: var(--toast-bg, var(--ink, #111));
  color: var(--toast-fg, #fff);
  padding: 10px 16px;
  border-radius: 999px;
  font-weight: 700;
  opacity: 0;
  pointer-events: none;
  transition: .25s;
  z-index: 40;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.topbar {
  width: min(1100px, 100%);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}
.room-label {
  color: var(--muted, #6b7280);
  font-size: 12px;
  letter-spacing: .12em;
  text-transform: uppercase;
}
.code-pill {
  background: var(--card, #fff);
  border: 2px solid var(--line, #111);
  border-radius: 8px;
  padding: 8px 14px;
  font-weight: 700;
  letter-spacing: 0.2em;
}
.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  flex-shrink: 0;
}
.topbar-actions .btn.ghost,
#btn-lobby-leave,
#btn-game-leave {
  width: auto;
  margin-top: 0;
  padding: 10px 16px;
  border: 0;
  border-radius: 999px;
  background: #fff;
  color: var(--accent, var(--red, #c41e3a));
  font-weight: 800;
  box-shadow: 0 4px 0 #b01024;
}
.topbar-actions .btn.ghost:active:not(:disabled),
#btn-lobby-leave:active:not(:disabled),
#btn-game-leave:active:not(:disabled) {
  transform: translateY(2px);
  box-shadow: 0 2px 0 #b01024;
}
button.icon-btn {
  width: 42px;
  height: 42px;
  flex-shrink: 0;
  padding: 0;
  margin: 0;
  border: 0;
  border-radius: 999px;
  background: #fff;
  color: #111;
  font-size: 18px;
  line-height: 1;
  box-shadow: 0 3px 0 rgba(0, 0, 0, .18);
  cursor: pointer;
}
button.icon-btn:active:not(:disabled) {
  transform: translateY(2px);
  box-shadow: 0 1px 0 rgba(0, 0, 0, .18);
}

#screen-lobby.screen.active {
  overflow-x: hidden;
  overflow-y: auto;
  max-height: 100dvh;
  min-height: 0;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

.lobby-grid {
  width: min(720px, 100%);
  display: grid;
  grid-template-columns: 1.2fr .8fr;
  gap: 16px;
  margin-top: 12px;
  min-height: 0;
  flex: 1 1 auto;
}
.lobby-grid > .panel {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.qr {
  background: var(--card, #fff);
  border: 2px solid var(--line, #111);
  border-radius: 16px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  color: var(--ink, #111);
  gap: 8px;
  height: fit-content;
}
.qr img { width: min(160px, 42vw); height: auto; aspect-ratio: 1; }
.player-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 8px;
  min-height: 0;
  max-height: min(46vh, 380px);
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding-right: 4px;
}
.player-list::-webkit-scrollbar { width: 8px; }
.player-list::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, .28);
  border-radius: 99px;
}
.player-list .seat { min-width: 0; }
.seat {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--card, #fff);
  border: 2px solid var(--line, #111);
  border-radius: 8px;
  padding: 6px 10px 6px 6px;
}
.seat .dot {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: #fff;
  font-size: 12px;
  font-weight: 800;
  flex-shrink: 0;
}
.seat .meta { min-width: 0; }
.seat .meta b { display: block; }
.seat .meta span { font-size: 12px; color: var(--muted, #6b7280); }
.seat.you { box-shadow: 0 0 0 2px var(--accent, var(--red, #c41e3a)); }

.end-card { text-align: center; width: min(420px, 100%); }

.settings {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  align-items: start;
  margin-top: 10px;
}
.level-block { min-width: 0; }
.level-label {
  display: flex;
  align-items: center;
  gap: 8px;
}
.info-btn {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid currentColor;
  background: transparent;
  color: inherit;
  font: 800 12px/1 inherit;
  padding: 0;
  cursor: pointer;
  flex-shrink: 0;
}
.level-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.level-chip {
  border: 0;
  border-radius: 999px;
  padding: 8px 12px;
  font-weight: 800;
  font-size: 13px;
  background: var(--surface-muted, #eef2f7);
  color: var(--ink, #111);
  cursor: pointer;
}
.level-chip.on {
  background: var(--accent, var(--red, #c41e3a));
  color: #fff;
}
.level-chip:disabled { cursor: default; opacity: 0.9; }
.level-help {
  display: none;
  margin-top: 8px;
  font-size: 12px;
  line-height: 1.4;
  color: var(--muted, #6b7280);
  text-align: left;
  text-transform: none;
  letter-spacing: 0;
  font-weight: 600;
}
.level-help.show { display: block; }

#btn-debug {
  position: fixed;
  left: max(8px, env(safe-area-inset-left, 0px));
  bottom: max(8px, env(safe-area-inset-bottom, 0px));
  z-index: 40;
  margin: 0;
  padding: 0;
  width: 28px;
  height: 28px;
  min-width: 0;
  min-height: 0;
  background: transparent;
  border: 0;
  box-shadow: none;
  border-radius: 0;
  color: inherit;
  font-size: 18px;
  font-weight: 400;
  line-height: 1;
  letter-spacing: 0;
  text-transform: none;
  opacity: 0.5;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
#btn-debug:hover,
#btn-debug:focus-visible { opacity: 1; }

#card-atlas { z-index: 50; }
#card-atlas .panel {
  width: min(760px, 100%);
  max-height: 86dvh;
  overflow: auto;
  text-align: left;
}
.atlas-note { margin: 8px 0 12px; }
.atlas-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 12px;
  margin: 0 0 18px;
}
.atlas-pair {
  display: flex;
  align-items: center;
  gap: 6px;
}
.atlas-pair .ucard,
.atlas-grid .ucard { pointer-events: none; }
.atlas-arrow { color: var(--muted, #6b7280); font-weight: 800; font-size: 16px; }
.atlas-grid .card.atlas-mini {
  width: min(26vw, 120px);
  border-width: 4px;
  flex-shrink: 0;
}
.atlas-grid .card.atlas-mini .sym { pointer-events: none; }

#debug-pick { z-index: 42; }
#debug-pick .panel {
  width: min(420px, 100%);
  text-align: left;
}
#debug-log {
  margin-top: 10px;
  max-height: min(42vh, 280px);
  overflow: auto;
  background: #0b1220;
  color: #d1fae5;
  border-radius: 10px;
  padding: 10px;
  font: 11px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace;
  white-space: pre-wrap;
  word-break: break-word;
}
#debug-pick .hint { margin-top: 8px; }
#debug-pick label { margin-top: 10px; }
#debug-pick input { width: 100%; }

.debug-sheet {
  position: fixed;
  inset: 0;
  z-index: 42;
  display: none;
  place-items: center;
  padding: 20px;
  background: rgba(0, 0, 0, .55);
  pointer-events: auto;
}
.debug-sheet.show { display: grid; }
.debug-sheet .panel { width: min(420px, 100%); margin: 0; text-align: left; }

.zoom-bar {
  display: none;
  position: fixed;
  z-index: 35;
  right: max(10px, env(safe-area-inset-right, 0px));
  bottom: max(14px, env(safe-area-inset-bottom, 0px));
  flex-direction: column;
  align-items: center;
  gap: 4px;
  background: var(--card, var(--surface, #fff));
  color: var(--ink, #111);
  border: 2px solid var(--line, #111);
  border-radius: 999px;
  padding: 6px 4px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, .22);
}
body[data-phase="lobby"] .zoom-bar,
body[data-phase="game"] .zoom-bar,
body[data-phase="end"] .zoom-bar { display: flex; }
.zoom-bar button {
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 50%;
  background: var(--ink, #111);
  color: var(--card, var(--surface, #fff));
  font-size: 20px;
  font-weight: 800;
  line-height: 1;
  cursor: pointer;
}
.zoom-bar button:disabled { opacity: .35; cursor: not-allowed; }
.zoom-bar span {
  min-width: 0;
  text-align: center;
  font-size: 11px;
  font-weight: 800;
  color: var(--ink, #111);
}

#screen-lobby.screen.active,
#screen-game.screen.active,
#screen-end.screen.active {
  zoom: var(--mg-zoom, 1);
}
@supports not (zoom: 1) {
  #screen-lobby.screen.active,
  #screen-game.screen.active,
  #screen-end.screen.active {
    transform: scale(var(--mg-zoom, 1));
    transform-origin: top center;
  }
}

@media (max-width: 720px) {
  .lobby-grid { grid-template-columns: 1fr; }
  .qr img { width: 140px; height: 140px; }
}
