/* The world page: a canvas and the least possible chrome around it. */

:root {
  --wc-gutter: 16px;
  --wc-ink: #f4f6f8;
  --wc-glass: rgba(18, 21, 26, 0.62);
  --wc-glass-border: rgba(255, 255, 255, 0.16);
  --wc-blue: #2f6bff;
  --wc-font: 'Figtree', system-ui, -apple-system, 'Segoe UI', sans-serif;
}

html, body.wc {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #0f1216;
  color: var(--wc-ink);
  font-family: var(--wc-font);
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
}

#stage {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none; /* the browser must never scroll or zoom under a finger */
  outline: none;
  cursor: grab;
}
#stage:active { cursor: grabbing; }

/* Top left, the way Spatial does it: a round back arrow and the world's name. */
.wc-top {
  position: fixed;
  z-index: 30; /* above loading and error: the way out is always there */
  top: max(var(--wc-gutter), env(safe-area-inset-top));
  left: max(var(--wc-gutter), env(safe-area-inset-left));
  right: max(var(--wc-gutter), env(safe-area-inset-right));
  display: flex;
  align-items: center;
  gap: 10px;
  pointer-events: none;
}
.wc-back {
  pointer-events: auto;
  flex: none;
  min-width: 44px;
  height: 44px;
  box-sizing: border-box;
  padding: 0 16px 0 12px;
  gap: 4px;
  border-radius: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 15px;
  color: var(--wc-ink);
  background: var(--wc-glass);
  border: 1px solid var(--wc-glass-border);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  text-decoration: none;
  transition: background 0.15s;
}
.wc-back:hover, .wc-back:focus-visible { background: rgba(47, 107, 255, 0.85); outline: none; }
.wc-name {
  min-width: 0;
  max-width: 60vw;
  padding: 0 16px;
  height: 44px;
  line-height: 44px;
  border-radius: 22px;
  font-weight: 700;
  font-size: 15px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  background: var(--wc-glass);
  border: 1px solid var(--wc-glass-border);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
}

/* Loading: a real bar, and the name of the thing being waited for. */
.wc-loading {
  position: fixed;
  z-index: 10;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: var(--wc-gutter);
  background: radial-gradient(120% 90% at 50% 20%, #1b2433 0%, #0f1216 70%);
  transition: opacity 0.4s ease;
}
.wc-loading[data-done] { opacity: 0; pointer-events: none; }
.wc-loading-title { margin: 0; font-size: clamp(22px, 5vw, 34px); font-weight: 800; text-align: center; }
.wc-bar {
  width: min(360px, 100% - 2 * var(--wc-gutter));
  height: 6px;
  border-radius: 3px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.14);
}
.wc-bar > span {
  display: block;
  height: 100%;
  width: 0;
  border-radius: 3px;
  background: var(--wc-blue);
  transition: width 0.18s ease-out;
}
.wc-loading-note { margin: 0; font-size: 13px; opacity: 0.7; text-align: center; }

/* Failure: plain, and unmistakable. Never a plausible empty room. */
.wc-error {
  position: fixed;
  z-index: 20;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: calc(var(--wc-gutter) + 56px) var(--wc-gutter) var(--wc-gutter);
  text-align: center;
  background: #0f1216;
}
.wc-error[hidden], .wc-banner[hidden], .wc-hint[hidden], .wc-loading[hidden] { display: none; }
.wc-error-title { margin: 0; font-size: 22px; font-weight: 800; }
.wc-error-detail { margin: 0; max-width: 560px; font-size: 14px; line-height: 1.5; opacity: 0.8; word-break: break-word; }
.wc-error-actions { display: flex; gap: 10px; margin: 8px 0 0; }
.wc-pill {
  display: inline-block;
  padding: 11px 20px;
  border-radius: 999px;
  background: var(--wc-blue);
  color: #fff;
  font-weight: 700;
  font-size: 14px;
  text-decoration: none;
}
.wc-pill-ghost { background: transparent; border: 1px solid var(--wc-glass-border); }

/* A world that loaded, but not all of it. */
.wc-banner {
  position: fixed;
  z-index: 6;
  top: calc(max(var(--wc-gutter), env(safe-area-inset-top)) + 54px);
  left: 50%;
  transform: translateX(-50%);
  width: min(560px, 100% - 2 * var(--wc-gutter));
  box-sizing: border-box;
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 13px;
  line-height: 1.4;
  background: rgba(120, 70, 8, 0.88);
  border: 1px solid rgba(255, 196, 120, 0.5);
}
.wc-banner button {
  float: right;
  margin-left: 10px;
  background: none;
  border: 0;
  color: inherit;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

.wc-hint {
  position: fixed;
  z-index: 4;
  left: 50%;
  bottom: max(var(--wc-gutter), env(safe-area-inset-bottom));
  transform: translateX(-50%);
  padding: 9px 16px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  background: var(--wc-glass);
  border: 1px solid var(--wc-glass-border);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  pointer-events: none;
  transition: opacity 0.6s;
}
.wc-hint[data-fading] { opacity: 0; }

/* Touch controls. */
.wc-stick {
  position: fixed;
  z-index: 4;
  left: max(var(--wc-gutter), env(safe-area-inset-left));
  bottom: max(var(--wc-gutter), env(safe-area-inset-bottom));
  width: 128px;
  height: 128px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.1);
  border: 2px solid rgba(255, 255, 255, 0.28);
  touch-action: none;
}
.wc-stick-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 54px;
  height: 54px;
  margin: -27px 0 0 -27px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.5);
  pointer-events: none;
}
.wc-jump {
  position: fixed;
  z-index: 4;
  right: max(var(--wc-gutter), env(safe-area-inset-right));
  bottom: max(var(--wc-gutter), env(safe-area-inset-bottom));
  width: 76px;
  height: 76px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.4);
  background: rgba(47, 107, 255, 0.55);
  color: #fff;
  font: 700 14px var(--wc-font);
  touch-action: none;
}
.wc-jump:active { background: rgba(47, 107, 255, 0.9); }

/* On a phone the bottom corners belong to the thumbs: the hint goes up under the bar. */
@media (pointer: coarse) {
  .wc-hint {
    bottom: auto;
    top: calc(max(var(--wc-gutter), env(safe-area-inset-top)) + 58px);
    max-width: calc(100vw - 2 * var(--wc-gutter));
    box-sizing: border-box;
    white-space: normal;
    text-align: center;
  }
  .wc-banner { top: calc(max(var(--wc-gutter), env(safe-area-inset-top)) + 104px); }
}

@media (max-width: 520px) {
  .wc-name { max-width: calc(100vw - 2 * var(--wc-gutter) - 54px); }
}

/* Avatar picker: a round thumbnail button at the right of the top bar, and a
   small panel of cards under it, the way Spatial does it. */
.wc-avatar-btn {
  pointer-events: auto;
  flex: none;
  margin-left: auto;
  width: 44px;
  height: 44px;
  padding: 0;
  border-radius: 50%;
  overflow: hidden;
  cursor: pointer;
  background: var(--wc-glass);
  border: 2px solid var(--wc-glass-border);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  transition: border-color 0.15s;
}
.wc-avatar-btn[hidden] { display: none; }
.wc-avatar-btn:hover, .wc-avatar-btn:focus-visible, .wc-avatar-btn[aria-expanded='true'] { border-color: var(--wc-blue); outline: none; }
.wc-avatar-btn img { display: block; width: 100%; height: 100%; object-fit: cover; }

.wc-avatars {
  position: fixed;
  z-index: 31;
  top: calc(max(var(--wc-gutter), env(safe-area-inset-top)) + 52px);
  right: max(var(--wc-gutter), env(safe-area-inset-right));
  width: min(320px, 100vw - 2 * var(--wc-gutter));
  box-sizing: border-box;
  padding: 14px;
  border-radius: 20px;
  background: rgba(18, 21, 26, 0.86);
  border: 1px solid var(--wc-glass-border);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.4);
}
.wc-avatars[hidden] { display: none; }
.wc-av-title { margin: 0 0 10px; font-size: 14px; font-weight: 700; opacity: 0.85; }
.wc-av-list { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 10px; align-items: start; }
.wc-av-item { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.wc-av-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 8px 8px 10px;
  border-radius: 14px;
  color: var(--wc-ink);
  font: inherit;
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
  background: rgba(255, 255, 255, 0.07);
  border: 2px solid transparent;
}
.wc-av-card:hover:not(:disabled), .wc-av-card:focus-visible { background: rgba(255, 255, 255, 0.13); outline: none; }
.wc-av-card[aria-pressed='true'] { border-color: var(--wc-blue); background: rgba(47, 107, 255, 0.18); }
.wc-av-card:disabled { cursor: progress; opacity: 0.6; }
.wc-av-card[data-busy] { opacity: 1; animation: wc-av-pulse 1s ease-in-out infinite; }
@keyframes wc-av-pulse { 50% { opacity: 0.55; } }
.wc-av-thumb { width: 100%; max-width: 96px; height: auto; aspect-ratio: 1; border-radius: 10px; object-fit: cover; background: rgba(255, 255, 255, 0.06); }
.wc-av-name { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.wc-av-credit { font-size: 11px; line-height: 1.3; text-align: center; opacity: 0.7; overflow-wrap: anywhere; }
.wc-av-status { margin: 10px 0 0; min-height: 0; font-size: 12px; line-height: 1.4; opacity: 0.85; }
.wc-av-status:empty { display: none; }

/* "<- Spaces" is a pill with a word; below 480px it is the arrow alone, still a 44px target. */
@media (max-width: 479px) {
  .wc-back { width: 44px; padding: 0; }
  .wc-back-label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
}

/* The menu button, top right beside the avatar. */
.wc-menu-btn {
  pointer-events: auto;
  flex: none;
  margin-left: auto;
  width: 44px;
  height: 44px;
  padding: 0;
  display: grid;
  place-items: center;
  border-radius: 50%;
  cursor: pointer;
  color: var(--wc-ink);
  background: var(--wc-glass);
  border: 1px solid var(--wc-glass-border);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  transition: background 0.15s;
}
.wc-menu-btn[hidden] { display: none; }
.wc-menu-btn:hover, .wc-menu-btn:focus-visible, .wc-menu-btn[aria-expanded='true'] { background: rgba(47, 107, 255, 0.85); outline: none; }
.wc-avatar-btn:not([hidden]) ~ .wc-menu-btn { margin-left: 0; }

/* The Esc menu: a centred card over a dimmed world. Beneath the top bar (30)
   so the way out and the menu button stay reachable while it is open. */
.wc-menu {
  position: fixed;
  z-index: 29;
  inset: 0;
  display: grid;
  place-items: center;
  padding: calc(var(--wc-gutter) + 56px) var(--wc-gutter) var(--wc-gutter);
  box-sizing: border-box;
  background: rgba(8, 10, 14, 0.55);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  -webkit-user-select: none;
  user-select: none;
}
.wc-menu[hidden], .wc-menu-view[hidden] { display: none; }
.wc-menu-card {
  width: min(380px, 100%);
  max-height: 100%;
  overflow-y: auto;
  box-sizing: border-box;
  padding: 24px;
  border-radius: 24px;
  background: rgba(24, 28, 35, 0.96);
  border: 1px solid var(--wc-glass-border);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}
.wc-menu-view { display: flex; flex-direction: column; gap: 10px; }
.wc-menu-kicker { margin: 0; font-size: 12px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; opacity: 0.6; text-align: center; }
.wc-menu-title { margin: 0 0 8px; font-size: 24px; font-weight: 800; text-align: center; overflow-wrap: anywhere; }
.wc-menu-btn-primary, .wc-menu-btn-plain {
  display: block;
  box-sizing: border-box;
  width: 100%;
  min-height: 48px;
  padding: 12px 18px;
  border-radius: 999px;
  font: 700 16px var(--wc-font);
  text-align: center;
  text-decoration: none;
  cursor: pointer;
  color: #fff;
  border: 1px solid transparent;
}
.wc-menu-btn-primary { background: var(--wc-blue); }
.wc-menu-btn-plain { background: rgba(255, 255, 255, 0.09); border-color: var(--wc-glass-border); }
.wc-menu-btn-primary:hover, .wc-menu-btn-primary:focus-visible { background: #4a7fff; outline: none; }
.wc-menu-btn-plain:hover, .wc-menu-btn-plain:focus-visible { background: rgba(255, 255, 255, 0.17); outline: none; }
.wc-menu-btn-plain[hidden] { display: none; }
.wc-menu-leave { color: #ffb4b4; }
.wc-menu-tip { margin: 6px 0 0; font-size: 12px; opacity: 0.6; text-align: center; }

/* World settings (owners). */
.wc-settings { gap: 16px; }
.wc-settings-head { display: flex; align-items: center; gap: 10px; }
.wc-settings-title { margin: 0; font-size: 20px; font-weight: 800; }
.wc-menu-back { background: none; border: 0; color: var(--wc-ink); font: 700 15px var(--wc-font); cursor: pointer; padding: 10px 8px; min-height: 44px; margin-left: -8px; }
.wc-field { display: flex; flex-direction: column; gap: 6px; }
.wc-field label, .wc-field-label { font-size: 13px; font-weight: 700; opacity: 0.85; }
.wc-field-row { display: flex; gap: 8px; }
.wc-field input {
  flex: 1;
  min-width: 0;
  min-height: 44px;
  box-sizing: border-box;
  padding: 0 14px;
  border-radius: 12px;
  font: 500 15px var(--wc-font);
  color: var(--wc-ink);
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--wc-glass-border);
  -webkit-user-select: text;
  user-select: text;
}
.wc-field input:focus-visible { outline: 2px solid var(--wc-blue); outline-offset: 1px; }
.wc-menu-btn-small {
  flex: none;
  min-height: 44px;
  padding: 0 16px;
  border-radius: 12px;
  font: 700 14px var(--wc-font);
  color: #fff;
  cursor: pointer;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid var(--wc-glass-border);
}
.wc-menu-btn-small:hover:not(:disabled), .wc-menu-btn-small:focus-visible { background: rgba(255, 255, 255, 0.18); outline: none; }
.wc-menu-btn-small:disabled, .wc-seg-btn:disabled { opacity: 0.55; cursor: progress; }
.wc-menu-btn-small[hidden] { display: none; }
.wc-menu-btn-accent { background: var(--wc-blue); border-color: transparent; }
.wc-menu-btn-accent:hover:not(:disabled), .wc-menu-btn-accent:focus-visible { background: #4a7fff; }
.wc-field-note { margin: 0; font-size: 12px; line-height: 1.4; opacity: 0.7; }
.wc-seg { display: flex; gap: 6px; }
.wc-seg-btn {
  flex: 1;
  min-height: 44px;
  padding: 0 10px;
  border-radius: 12px;
  font: 700 14px var(--wc-font);
  color: #fff;
  cursor: pointer;
  background: rgba(255, 255, 255, 0.07);
  border: 2px solid transparent;
}
.wc-seg-btn[aria-pressed='true'] { border-color: var(--wc-blue); background: rgba(47, 107, 255, 0.2); }
.wc-settings-status { margin: 0; min-height: 1.4em; font-size: 13px; line-height: 1.4; }
.wc-settings-status[data-kind='ok'] { color: #8be3a7; }
.wc-settings-status[data-kind='bad'] { color: #ffb4b4; }
.wc-settings-status[data-kind='working'] { opacity: 0.8; }
