* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #0b0d10;
  color: #e8d6a8;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

#canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

button {
  background: transparent;
  color: inherit;
  border: none;
  font-family: inherit;
  cursor: pointer;
}

/* ── Overlay shell (top bar + main + drawer; drawer lives outside) ─────── */
.overlay {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  background: rgba(11, 13, 16, 0.78);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  z-index: 10;
  transition: opacity 0.18s ease;
}
.overlay.hidden { opacity: 0; pointer-events: none; }


/* ── Top bar ───────────────────────────────────────────────────────────── */
.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: max(14px, env(safe-area-inset-top)) 22px 12px;
  border-bottom: 1px solid rgba(232, 214, 168, 0.10);
  flex-shrink: 0;
}
.brand {
  margin: 0;
  font-size: 20px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: #e8d6a8;
}
.top-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}
.top-button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 8px;
  background: rgba(232, 214, 168, 0.10);
  color: #e8d6a8;
  font-size: 13px;
  font-weight: 500;
  border: 1px solid rgba(232, 214, 168, 0.18);
  transition: background 0.12s ease;
}
.top-button:hover { background: rgba(232, 214, 168, 0.18); }
.top-button:active { transform: scale(0.97); }
.top-button-glyph {
  font-size: 16px;
  line-height: 1;
  font-weight: 400;
}

.top-icon {
  position: relative;
  width: 38px;
  height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  background: transparent;
  color: rgba(232, 214, 168, 0.78);
  border: 1px solid rgba(232, 214, 168, 0.14);
  transition: background 0.12s ease;
}
.top-icon:hover { background: rgba(232, 214, 168, 0.10); color: #e8d6a8; }
.top-icon:active { transform: scale(0.96); }
.top-icon svg { width: 18px; height: 18px; }

/* Hamburger glyph (3 horizontal bars), built from spans so we don't need an SVG */
.menu-toggle { gap: 4px; flex-direction: column; }
.menu-toggle span:not(.menu-toggle-badge) {
  display: block;
  width: 16px;
  height: 1.5px;
  background: currentColor;
  border-radius: 1px;
}
.menu-toggle-badge {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #ff9a4a;
  border: 1.5px solid rgba(11, 13, 16, 0.9);
}
.menu-toggle-badge.hidden { display: none; }

/* ── Main scroll area (grid + error log + hints) ───────────────────────── */
.menu-main {
  flex: 1;
  overflow-y: auto;
  padding: 22px 22px 16px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

/* ── Persistent inline error log ───────────────────────────────────────── */
.error-log {
  padding: 10px 12px;
  border-radius: 8px;
  background: rgba(180, 60, 60, 0.14);
  border: 1px solid rgba(220, 100, 100, 0.35);
  font-size: 12px;
  color: #ffb3b3;
  max-height: 22vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.error-log.hidden { display: none; }
.error-log .error-entry {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  line-height: 1.35;
  word-break: break-word;
}
.error-log .error-entry .error-time {
  flex-shrink: 0;
  font-family: ui-monospace, monospace;
  color: rgba(255, 179, 179, 0.55);
  font-size: 10px;
  padding-top: 2px;
}
.error-log .error-dismiss {
  background: transparent;
  color: rgba(255, 179, 179, 0.75);
  font-size: 13px;
  padding: 0 6px;
}
.error-log .error-dismiss:hover { color: #fff; }

/* ── Worlds grid (responsive squares) ──────────────────────────────────── */
.worlds-grid {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 14px;
  flex: 1;
  align-content: start;
}
.worlds-grid:empty::after {
  content: "No worlds yet. Tap + to add one.";
  grid-column: 1 / -1;
  padding: 40px 0;
  text-align: center;
  color: rgba(232, 214, 168, 0.50);
  font-size: 13px;
}

.world-card {
  position: relative;
  aspect-ratio: 1 / 1;
  border-radius: 12px;
  overflow: hidden;
  cursor: pointer;
  background: linear-gradient(135deg, #2a2926 0%, #1a1a1a 100%);
  border: 1px solid rgba(232, 214, 168, 0.12);
  transition: transform 0.12s ease, border-color 0.12s ease, box-shadow 0.12s ease;
}
.world-card:hover {
  transform: translateY(-2px);
  border-color: rgba(232, 214, 168, 0.30);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.45);
}
.world-card:active { transform: translateY(-1px); }
.world-card.current {
  border-color: #e8d6a8;
  box-shadow: 0 0 0 2px rgba(232, 214, 168, 0.30);
}
.world-card.uncached { opacity: 0.78; }
.world-card.uncached:hover { opacity: 1; }

/* Background thumbnail or placeholder. Thumbnail is an <img> child; the
   linear-gradient on .world-card itself shows through when no thumbnail. */
.world-thumb {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* Top-left badge cluster (source: default / onedrive) */
.world-badges {
  position: absolute;
  top: 8px;
  left: 8px;
  display: flex;
  gap: 4px;
  z-index: 2;
}
.world-badge {
  padding: 2px 7px;
  font-size: 10px;
  border-radius: 4px;
  background: rgba(11, 13, 16, 0.65);
  color: rgba(232, 214, 168, 0.85);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}
/* Sync-state badges — semantic colors so user can tell at a glance. */
.world-badge-pending {
  background: rgba(80, 130, 200, 0.85);
  color: #fff;
}
.world-badge-deferred {
  background: rgba(11, 13, 16, 0.65);
  color: rgba(232, 214, 168, 0.55);
  font-style: italic;
}
.world-badge-ghost {
  background: rgba(200, 110, 90, 0.85);
  color: #fff;
}

/* Loading placeholder card (network-backed provider list in flight).
   Fade-in is delayed 200ms so a fast resolve never causes a visual flash. */
.world-loading-placeholder {
  cursor: default;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: rgba(232, 214, 168, 0.04);
  border: 1px dashed rgba(232, 214, 168, 0.18);
  color: rgba(232, 214, 168, 0.65);
  font-size: 12px;
  opacity: 0;
  animation: world-loading-fadein 0.3s ease 0.2s forwards;
}
.world-loading-placeholder:hover { background: rgba(232, 214, 168, 0.04); }
.world-loading-spinner {
  width: 26px;
  height: 26px;
  border: 2px solid rgba(232, 214, 168, 0.18);
  border-top-color: rgba(232, 214, 168, 0.85);
  border-radius: 50%;
  animation: world-loading-spin 0.9s linear infinite;
}
.world-loading-label {
  letter-spacing: 0.02em;
}
@keyframes world-loading-fadein {
  to { opacity: 1; }
}
@keyframes world-loading-spin {
  to { transform: rotate(360deg); }
}

/* Bottom info overlay — name + meta */
.world-info {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  padding: 22px 12px 10px;
  background: linear-gradient(to top, rgba(11, 13, 16, 0.92) 25%, rgba(11, 13, 16, 0) 100%);
  display: flex;
  flex-direction: column;
  gap: 2px;
  z-index: 2;
  pointer-events: none;
}
.world-name {
  font-size: 13px;
  color: #e8d6a8;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.world-meta {
  font-size: 10.5px;
  color: rgba(232, 214, 168, 0.55);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.world-card.uncached .world-meta { font-style: italic; }

/* Bottom-right action button cluster. Always visible on touch; on hover-
   capable devices we can hide them by default if needed. */
.world-actions {
  position: absolute;
  bottom: 8px;
  right: 8px;
  display: flex;
  gap: 4px;
  z-index: 3;
}
.world-action {
  width: 28px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  background: rgba(11, 13, 16, 0.72);
  color: rgba(232, 214, 168, 0.85);
  font-size: 14px;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  transition: background 0.12s ease;
}
.world-action:hover { background: rgba(232, 214, 168, 0.18); color: #e8d6a8; }
.world-action.danger:hover { background: rgba(220, 100, 100, 0.28); color: #ff9a9a; }
.world-action.danger-strong:hover { background: rgba(220, 100, 100, 0.42); color: #fff; }

/* Inline SVG icons (replaced the former emoji/glyph button labels). The
   dynamically-built icons (app.js makeIcon) carry inline width/height; the
   static index.html ones (close X, enter play) are sized here. */
.drawer-x { display: inline-flex; align-items: center; justify-content: center; }
.drawer-x svg { width: 16px; height: 16px; }
.enter-prompt-button-glyph { display: inline-flex; }
.enter-prompt-button-glyph svg { width: 14px; height: 14px; }
.world-badge { display: inline-flex; align-items: center; gap: 3px; }
.error-log .error-dismiss { display: inline-flex; align-items: center; }

/* ── Hints (footer of main area) ───────────────────────────────────────── */
.hints {
  margin: 0;
  text-align: center;
  font-size: 12px;
  color: rgba(232, 214, 168, 0.45);
  padding: 4px 0 max(8px, env(safe-area-inset-bottom));
}
.hints kbd {
  background: rgba(232, 214, 168, 0.08);
  border: 1px solid rgba(232, 214, 168, 0.15);
  border-radius: 4px;
  padding: 1px 6px;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 0.92em;
}

/* ── Drawer (slide-in from right) ──────────────────────────────────────── */
.menu-backdrop {
  position: fixed;
  inset: 0;
  z-index: 70;
  background: rgba(0, 0, 0, 0.55);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.22s ease-out;
}
.menu-backdrop.show {
  opacity: 1;
  pointer-events: auto;
}

.menu-drawer {
  position: fixed;
  top: 0;
  right: 0;
  height: 100dvh;
  width: 88%;
  max-width: 360px;
  z-index: 80;
  background: rgba(20, 22, 26, 0.98);
  border-left: 1px solid rgba(232, 214, 168, 0.14);
  transform: translateX(100%);
  transition: transform 0.25s ease-out;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  padding-bottom: env(safe-area-inset-bottom);
}
.menu-drawer.open { transform: translateX(0); }

.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: max(14px, env(safe-area-inset-top)) 18px 12px;
  border-bottom: 1px solid rgba(232, 214, 168, 0.10);
}
.drawer-head h2 {
  margin: 0;
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: rgba(232, 214, 168, 0.65);
}
.drawer-x {
  width: 32px;
  height: 32px;
  border-radius: 6px;
  border: 1px solid rgba(232, 214, 168, 0.14);
  color: rgba(232, 214, 168, 0.78);
  font-size: 14px;
}
.drawer-x:hover { background: rgba(232, 214, 168, 0.08); color: #e8d6a8; }

/* Settings toggles inside the drawer */
.setting-toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  font-size: 14px;
  color: rgba(232, 214, 168, 0.90);
}
.setting-toggle input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: #e8d6a8;
  cursor: pointer;
}
.setting-hint {
  margin: 8px 0 0;
  font-size: 12px;
  color: rgba(232, 214, 168, 0.50);
  line-height: 1.4;
}

.drawer-section {
  padding: 16px 18px;
  border-bottom: 1px solid rgba(232, 214, 168, 0.08);
}
.drawer-section h3 {
  margin: 0 0 10px;
  font-size: 10.5px;
  font-weight: 500;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: rgba(232, 214, 168, 0.55);
}
.drawer-foot { border-bottom: none; padding-top: 22px; }
.drawer-version {
  margin: 0;
  text-align: center;
  font-size: 11px;
  color: rgba(232, 214, 168, 0.35);
  letter-spacing: 0.04em;
}

.drawer-link {
  background: transparent;
  color: rgba(232, 214, 168, 0.65);
  font-size: 13px;
  text-decoration: underline;
  text-underline-offset: 3px;
  padding: 0;
}
.drawer-link:hover { color: rgba(255, 154, 154, 0.85); }

/* OneDrive sub-block inside the drawer */
.onedrive-bar {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  background: rgba(0, 120, 212, 0.08);
  border: 1px solid rgba(0, 120, 212, 0.30);
  font-size: 12px;
}
.onedrive-bar.hidden { display: none; }
.onedrive-status {
  color: rgba(232, 214, 168, 0.78);
  word-break: break-all;
  line-height: 1.4;
}
.onedrive-buttons { display: flex; gap: 8px; flex-wrap: wrap; }
.onedrive-button {
  background: rgba(0, 120, 212, 0.85);
  color: #fff;
  padding: 7px 12px;
  font-size: 12px;
  border-radius: 6px;
  font-weight: 500;
}
.onedrive-button:hover { background: rgba(0, 120, 212, 1); }
.onedrive-button.hidden { display: none; }

/* ── Enter-prompt overlay (shown when gesture expired during a slow load) ── */
.enter-prompt {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.92);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}
.enter-prompt.hidden { display: none; }
.enter-prompt-card {
  text-align: center;
  padding: 32px 40px;
  border-radius: 14px;
  background: rgba(20, 22, 26, 0.98);
  border: 1px solid rgba(232, 214, 168, 0.20);
  max-width: 420px;
}
.enter-prompt-title {
  margin: 0;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.20em;
  text-transform: uppercase;
  color: rgba(232, 214, 168, 0.50);
}
.enter-prompt-name {
  margin: 8px 0 24px;
  font-size: 19px;
  color: #e8d6a8;
  word-break: break-word;
}
.enter-prompt-button {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 14px 32px;
  background: #e8d6a8;
  color: #0b0d10;
  border-radius: 10px;
  font-size: 16px;
  font-weight: 600;
  transition: background 0.12s ease;
}
.enter-prompt-button:hover { background: #f0deb4; }
.enter-prompt-button:active { transform: scale(0.97); }
.enter-prompt-button-glyph {
  font-size: 14px;
  line-height: 1;
}
.enter-prompt-cancel {
  display: block;
  margin: 16px auto 0;
  background: transparent;
  color: rgba(232, 214, 168, 0.55);
  font-size: 12px;
  padding: 4px 10px;
  text-decoration: underline;
  text-underline-offset: 3px;
}
.enter-prompt-cancel:hover { color: rgba(255, 154, 154, 0.85); }

/* ── Pause overlay (flat mode) ─────────────────────────────────────────────
   Translucent on purpose: the world stays visible behind it so it reads as
   "paused, still standing here" rather than "left to the menu". Below the
   enter-prompt (200) and gl-error (500), above HUD + toasts. */
.pause-overlay {
  position: fixed;
  inset: 0;
  z-index: 190;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.42);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  cursor: pointer;            /* whole backdrop resumes on click */
}
.pause-overlay.hidden { display: none; }
.pause-card {
  text-align: center;
  padding: 28px 40px;
  border-radius: 14px;
  background: rgba(20, 22, 26, 0.96);
  border: 1px solid rgba(232, 214, 168, 0.20);
  cursor: default;
}
.pause-title {
  margin: 0 0 20px;
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.22em;
  color: rgba(232, 214, 168, 0.75);
}
.pause-hint {
  margin: 18px 0 0;
  font-size: 12px;
  color: rgba(232, 214, 168, 0.45);
}
.pause-hint kbd {
  background: rgba(232, 214, 168, 0.08);
  border: 1px solid rgba(232, 214, 168, 0.15);
  border-radius: 4px;
  padding: 1px 6px;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 0.92em;
}

/* ── WebGL context failure overlay (out-of-GPU-memory retry) ────────────── */
.gl-error {
  position: fixed;
  inset: 0;
  z-index: 500;          /* above everything — the app can't render behind it */
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.95);
}
.gl-error.hidden { display: none; }
.gl-error-card {
  text-align: center;
  padding: 32px 40px;
  border-radius: 14px;
  background: rgba(20, 22, 26, 0.98);
  border: 1px solid rgba(232, 214, 168, 0.20);
  max-width: 420px;
}
.gl-error-title {
  margin: 0 0 12px;
  font-size: 19px;
  color: #e8d6a8;
}
.gl-error-body {
  margin: 0 0 8px;
  font-size: 14px;
  line-height: 1.6;
  color: rgba(255, 255, 255, 0.75);
}
.gl-error-note {
  margin: 0 0 24px;
  font-size: 13px;
  line-height: 1.6;
  color: rgba(232, 214, 168, 0.65);
  min-height: 1.2em;
}
.gl-error-retry {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 14px 32px;
  background: #e8d6a8;
  color: #0b0d10;
  border-radius: 10px;
  font-size: 16px;
  font-weight: 600;
  transition: background 0.12s ease;
}
.gl-error-retry:hover { background: #f0deb4; }
.gl-error-retry:active { transform: scale(0.97); }

/* ── Drag-and-drop overlay (briefly shown on dragenter) ─────────────────── */
.drop-overlay {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: rgba(232, 214, 168, 0.12);
  border: 2px dashed rgba(232, 214, 168, 0.55);
  pointer-events: none;
  z-index: 90;
  font-size: 22px;
  color: #fff;
}
.drop-overlay.hidden { display: none; }

/* ── HUD (top-left status, in-world) ──────────────────────────────────── */
.hud {
  position: fixed;
  top: 12px; left: 14px;
  z-index: 5;
  font-size: 13px;
  color: rgba(232, 214, 168, 0.62);
  pointer-events: none;
  user-select: none;
}
.hud-name { font-weight: 600; color: rgba(232, 214, 168, 0.85); }
.hud-status { margin-left: 10px; }

/* ── Progress bar (download + cache) ───────────────────────────────────── */
.progress-bar {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 100;
  background: rgba(11, 13, 16, 0.95);
  padding: 8px 16px 10px;
  display: flex; flex-direction: column; gap: 6px;
  font-size: 12px;
  color: rgba(232, 214, 168, 0.85);
}
.progress-bar.hidden { display: none; }
.progress-label { text-align: center; }
.progress-track {
  height: 3px;
  background: rgba(232, 214, 168, 0.15);
  border-radius: 2px;
  overflow: hidden;
  position: relative;
}
.progress-fill {
  height: 100%;
  background: #e8d6a8;
  border-radius: 2px;
  transition: width 0.1s linear;
  width: 0;
}
.progress-fill.indeterminate {
  width: 30% !important;
  animation: progress-slide 1.2s ease-in-out infinite;
}
@keyframes progress-slide {
  0%   { margin-left: -30%; }
  100% { margin-left: 100%; }
}

/* ── Toasts ───────────────────────────────────────────────────────────── */
/* Two toast slots so they never visually collide:
   - PWA shell update lives at the bottom center (more impactful — full reload)
   - World-content update lives at the top center (informational only) */
.toast {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(20, 22, 26, 0.96);
  border: 1px solid rgba(232, 214, 168, 0.2);
  border-radius: 10px;
  padding: 10px 14px;
  display: flex; align-items: center; gap: 12px;
  z-index: 30;
  font-size: 14px;
  max-width: calc(100% - 32px);
}
#updateToast      { bottom: 16px; }
#worldUpdateToast { top: 70px; }
.toast.hidden { display: none; }
.toast button {
  background: #e8d6a8;
  color: #0b0d10;
  padding: 6px 12px;
  font-size: 13px;
  border-radius: 6px;
  font-weight: 600;
}
