/* IMALL "walk the mall" verse overlays. The 3D canvas fills the viewport; every
   HUD element floats above it. Colours follow the dark IMALL theme. */

html, body { height: 100%; }
body[data-page="verse"] {
  margin: 0;
  overflow: hidden;
  background: #05070f;
  color: #eef2ff;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  touch-action: none;
}

.verse-scene { position: fixed; inset: 0; }
.verse-scene canvas { display: block; width: 100%; height: 100%; }

/* Loading / fallback overlay */
.verse-overlay {
  position: fixed; inset: 0; z-index: 40;
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(120% 120% at 50% 20%, #101a36 0%, #05070f 70%);
}
/* The boot sequence hides this overlay via the [hidden] attribute; the class
   rule above would otherwise keep display:flex and pin the loader on screen. */
.verse-overlay[hidden] { display: none; }
.verse-card {
  text-align: center; max-width: 380px; padding: 28px 26px;
  background: rgba(12, 18, 40, 0.85); border: 1px solid #24305a; border-radius: 16px;
}
.verse-card h2 { margin: 14px 0 6px; }
.verse-card p { color: #9fb0d8; margin: 0 0 16px; }
.verse-spinner {
  width: 42px; height: 42px; margin: 0 auto; border-radius: 50%;
  border: 4px solid #24305a; border-top-color: #5fa8d3; animation: verse-spin 0.9s linear infinite;
}
@keyframes verse-spin { to { transform: rotate(360deg); } }

/* Crosshair */
.verse-crosshair {
  position: fixed; left: 50%; top: 50%; transform: translate(-50%, -50%);
  z-index: 20; font-size: 22px; line-height: 1; color: rgba(255, 255, 255, 0.8);
  text-shadow: 0 0 4px rgba(0, 0, 0, 0.8); pointer-events: none;
}

/* Hands-free dwell ring (look-to-select). The arc offset is animated from JS. */
.verse-dwell {
  position: fixed; left: 50%; top: 50%; transform: translate(-50%, -50%);
  z-index: 21; width: 64px; height: 64px; pointer-events: none;
}
.verse-dwell-track { fill: none; stroke: rgba(255, 255, 255, 0.18); stroke-width: 4; }
.verse-dwell-arc {
  fill: none; stroke: #7fd0ff; stroke-width: 4; stroke-linecap: round;
  stroke-dasharray: 125.66; stroke-dashoffset: 125.66;
  transform: rotate(-90deg); transform-origin: 50% 50%;
  filter: drop-shadow(0 0 4px rgba(127, 208, 255, 0.8));
}
/* Hands-free toggle in its on state. */
.hud-chip[aria-pressed="true"] { background: #5fa8d3; color: #05070f; border-color: #7fd0ff; }

/* Top HUD */
.verse-hud {
  position: fixed; top: 0; left: 0; right: 0; z-index: 25;
  display: flex; justify-content: flex-start; padding: 12px;
  pointer-events: none;
}
.verse-hud .hud-left, .verse-hud .hud-right { display: flex; gap: 8px; pointer-events: auto; }
.hud-chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 12px; border-radius: 999px; cursor: pointer;
  background: rgba(12, 18, 40, 0.8); border: 1px solid #2a376a; color: #eef2ff;
  font-size: 14px; text-decoration: none;
}
.hud-chip:hover { border-color: #5fa8d3; }
#cartCount { background: #5fa8d3; color: #05070f; border-radius: 999px; padding: 0 7px; font-weight: 700; }
/* One clean Menu button + popover on every screen. The popover drops down from
   the top-right on desktop; the mobile query re-anchors it to the bottom bar. */
#btnMore { display: inline-flex; }
.hud-more-menu {
  display: none; flex-direction: column; align-items: stretch; gap: 6px;
  position: fixed; z-index: 31; min-width: 176px; padding: 8px;
  top: 58px; inset-inline-start: 12px;
  border-radius: 14px; background: rgba(9, 13, 30, 0.97);
  border: 1px solid #2a376a; box-shadow: 0 16px 40px rgba(0, 0, 0, 0.55);
}
body.more-open .hud-more-menu { display: flex; }
.hud-more-menu .hud-chip { justify-content: flex-start; width: 100%; }
/* The smart centre action button is mobile-only; desktop keeps the floating
   contextual action bar. */
.hud-primary { display: none; }
.hud-loc { cursor: default; background: rgba(95, 168, 211, 0.16); border-color: #3a4a86; }

/* Contextual prompt */
.verse-prompt {
  position: fixed; left: 50%; top: 62%; transform: translateX(-50%); z-index: 22;
  padding: 8px 16px; border-radius: 10px; pointer-events: none;
  background: rgba(12, 18, 40, 0.85); border: 1px solid #2a376a; font-size: 15px;
}
.verse-prompt b { color: #7fd0ff; }
.verse-bang {
  display: inline-block; min-width: 1.25em; height: 1.25em; line-height: 1.25em;
  text-align: center; border-radius: 999px; margin: 0 3px;
  background: #d69e2e; color: #0b1226; font-weight: 800;
}

/* Bottom action buttons - kept above the on-screen pad and assistant so the
   Enter / Leave / Inspect buttons are always tappable, never covered. */
.verse-actions {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%); z-index: 33;
  display: flex; gap: 10px;
}

/* Shared button */
.btn {
  appearance: none; cursor: pointer; font-size: 15px; font-weight: 600;
  padding: 11px 20px; border-radius: 12px; border: 1px solid transparent;
  background: #5fa8d3; color: #05070f;
}
.btn:hover { background: #7fbfe4; }
.btn.ghost { background: rgba(12, 18, 40, 0.85); color: #eef2ff; border-color: #2a376a; }
.btn.ghost:hover { border-color: #5fa8d3; }
.btn:disabled { opacity: 0.6; cursor: default; }

/* Movement joystick (touch) */
.verse-joystick {
  position: fixed; left: 22px; bottom: 22px; z-index: 24;
  width: 120px; height: 120px; border-radius: 50%;
  background: rgba(12, 18, 40, 0.55); border: 1px solid #2a376a; touch-action: none;
}
.verse-joystick span {
  position: absolute; left: 50%; top: 50%; width: 48px; height: 48px; margin: -24px 0 0 -24px;
  border-radius: 50%; background: rgba(95, 168, 211, 0.85);
}

/* On-screen control pad */
.verse-pad {
  position: fixed; right: 18px; bottom: 20px; z-index: 25;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  touch-action: none; user-select: none;
}
.verse-pad[hidden] { display: none; }
.pad-cross {
  display: grid; grid-template-columns: repeat(3, 52px); grid-template-rows: repeat(3, 52px);
  gap: 4px;
}
.pad-btn {
  appearance: none; cursor: pointer; font-size: 16px; font-weight: 700;
  border-radius: 12px; border: 1px solid #2a376a; color: #eef2ff;
  background: rgba(12, 18, 40, 0.72); touch-action: none; -webkit-user-select: none; user-select: none;
}
.pad-btn:active, .pad-btn.on { background: rgba(95, 168, 211, 0.9); color: #05070f; border-color: #7fbfe4; }
.pad-cross .pad-btn { width: 52px; height: 52px; }
.pad-fwd { grid-column: 2; grid-row: 1; }
.pad-left { grid-column: 1; grid-row: 2; }
.pad-stop { grid-column: 2; grid-row: 2; font-size: 20px; touch-action: none;
  background: rgba(95, 168, 211, 0.28); border-color: #3f6fa0; color: #dff0ff;
  transition: transform 0.05s ease-out; }
.pad-stop.on { background: rgba(95, 168, 211, 0.95); color: #05070f; border-color: #7fbfe4; }
.pad-right { grid-column: 3; grid-row: 2; }
.pad-back { grid-column: 2; grid-row: 3; }
/* Drag anywhere to look/turn (mouse or touch), so the on-screen look row is
   redundant everywhere - hidden to keep the pad clean. */
.pad-look { display: none; }
.pad-look .pad-btn { padding: 8px 12px; font-size: 13px; }
.pad-view { width: 100%; padding: 8px 12px; font-size: 13px; letter-spacing: 0.3px;
  background: rgba(95, 168, 211, 0.18); border-color: #3f6fa0; color: #dff0ff; }
.pad-view:hover { background: rgba(95, 168, 211, 0.34); }
.pad-tip { margin: 0; color: #9fb0d8; font-size: 11px; text-align: center; }

/* Small round toggle to hide/show the pad + chat (shown on small screens). */
.verse-controls-toggle {
  position: fixed; z-index: 27; display: none;
  align-items: center; justify-content: center;
  width: 42px; height: 42px; border-radius: 50%; font-size: 20px; cursor: pointer;
  border: 1px solid #2a376a; color: #eef2ff; background: rgba(12, 18, 40, 0.92);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4);
}
.verse-controls-toggle[aria-pressed="false"] { background: rgba(95, 168, 211, 0.9); color: #05070f; border-color: #7fbfe4; }

/* Cashier / voice assistant */
.asst-cashier { display: flex; align-items: center; gap: 10px; padding: 8px 14px;
  background: #0b1226; border-bottom: 1px solid #24305a; }
.asst-avatar { font-size: 26px; line-height: 1; }
.asst-queue { color: #ffcf7f; font-size: 12.5px; line-height: 1.4; }
.asst-mic { padding: 10px 12px; font-size: 16px; }
.asst-mic.listening { background: #ef476f; color: #fff; border-color: #ef476f; }

/* Slide-in panels */
.verse-panel {
  position: fixed; top: 0; right: 0; z-index: 34; width: min(400px, 92vw); height: 100%;
  overflow-y: auto; padding: 22px; box-sizing: border-box;
  background: rgba(9, 14, 32, 0.97); border-left: 1px solid #24305a;
  box-shadow: -12px 0 40px rgba(0, 0, 0, 0.5);
}
.verse-panel h2 { margin: 4px 0 14px; }
.panel-close {
  position: absolute; top: 12px; right: 14px; width: 34px; height: 34px;
  border-radius: 8px; border: 1px solid #2a376a; background: rgba(12, 18, 40, 0.9);
  color: #eef2ff; font-size: 20px; cursor: pointer;
}
.prod-meta { display: flex; gap: 14px; margin-bottom: 12px; color: #9fb0d8; }
.prod-meta #prodPrice { color: #7fd0ff; font-size: 20px; font-weight: 700; }
.prod-showroom { width: 100%; height: 240px; background: #0b1226; border-radius: 12px; overflow: hidden; }
.prod-showroom model-viewer { width: 100%; height: 100%; }
.prod-desc { color: #cdd7f2; line-height: 1.5; }
.panel-actions { display: flex; gap: 10px; flex-wrap: wrap; margin: 12px 0; }
.prod-agent { background: #0b1226; border: 1px solid #24305a; border-radius: 10px; padding: 12px; color: #cdd7f2; }

/* Cart */
.cart-lines { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.cart-row { display: flex; justify-content: space-between; gap: 10px; align-items: center;
  padding: 8px 10px; background: #0b1226; border: 1px solid #24305a; border-radius: 8px; }
.cart-row input { width: 56px; }
.cart-row button { background: none; border: none; color: #ff7a7a; cursor: pointer; font-size: 18px; }
/* A look-added item awaiting the customer's decision (auto-removed if ignored). */
.cart-row.is-tentative { border-style: dashed; border-color: #c9a227; opacity: 0.85; }
.cart-pending { color: #f0c419; font-size: 12px; }
.cart-keep { background: #c9a227 !important; color: #0b1226 !important; border: none;
  border-radius: 6px; font-size: 12px !important; padding: 2px 8px; cursor: pointer; }
.cart-total { font-size: 18px; margin: 10px 0; }
.cart-total b { color: #7fd0ff; }
.cart-buyer { display: flex; flex-direction: column; gap: 8px; margin: 12px 0; }
.cart-buyer input, .asst-form input {
  padding: 10px 12px; border-radius: 10px; border: 1px solid #2a376a;
  background: #0b1226; color: #eef2ff; font-size: 15px; width: 100%; box-sizing: border-box;
}
.cart-note { color: #7f8db3; font-size: 13px; }
#btnCheckout { width: 100%; }

/* Assistant dock - sits on the LEFT so it never overlaps the control pad
   (arrows) on the right; width is capped so it always leaves room for the
   bottom-right pad, and it can be minimised to just its header bar. */
.verse-assistant {
  position: fixed; left: 14px; bottom: 14px; z-index: 28; width: min(268px, calc(100vw - 210px));
  background: rgba(9, 14, 32, 0.97); border: 1px solid #24305a; border-radius: 13px; overflow: hidden;
}
.verse-assistant.min { width: auto; max-width: min(268px, calc(100vw - 210px)); }
.verse-assistant.min .asst-cashier,
.verse-assistant.min .asst-log,
.verse-assistant.min .asst-form { display: none; }
.verse-assistant.min .asst-head { border-bottom: none; }
.asst-head { display: flex; justify-content: space-between; align-items: center;
  padding: 7px 11px; font-size: 13px; background: #0b1226; border-bottom: 1px solid #24305a; }
.asst-head #asstName { cursor: pointer; font-weight: 600; }
.asst-head-btns { display: flex; gap: 6px; align-items: center; }
.verse-assistant .panel-close { position: static; width: 28px; height: 28px; font-size: 18px;
  display: inline-flex; align-items: center; justify-content: center; }
.asst-log { max-height: 150px; overflow-y: auto; padding: 9px 11px; display: flex; flex-direction: column; gap: 6px; }
.asst-msg { padding: 6px 9px; border-radius: 9px; font-size: 12.5px; line-height: 1.35; max-width: 90%; }
.asst-msg.me { align-self: flex-end; background: #244; color: #dff; }
.asst-msg.bot { align-self: flex-start; background: #12224a; color: #cdd7f2; }
.asst-form { display: flex; gap: 6px; padding: 8px 10px; border-top: 1px solid #24305a; }

.help-list { line-height: 1.7; color: #cdd7f2; padding-left: 18px; }
.help-list b { color: #7fd0ff; }

/* Shop directory */
.dir-hint { color: #9fb0d8; font-size: 13px; margin: 0 0 12px; line-height: 1.5; }
.dir-hint b { color: #7fd0ff; }
#dirSearch {
  width: 100%; box-sizing: border-box; margin-bottom: 12px;
  padding: 10px 12px; border-radius: 10px; border: 1px solid #2a376a;
  background: #0b1226; color: #eef2ff; font-size: 15px;
}
.dir-list { display: flex; flex-direction: column; gap: 7px; }
.dir-row {
  display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; cursor: pointer;
  padding: 10px 12px; border-radius: 10px; border: 1px solid #24305a;
  background: #0b1226; color: #eef2ff; font-size: 15px;
}
.dir-row:hover { border-color: #5fa8d3; background: #101c3a; }
.dir-dot { width: 12px; height: 12px; border-radius: 50%; flex: 0 0 auto; box-shadow: 0 0 6px rgba(255,255,255,0.25); }
.dir-name { flex: 1 1 auto; font-weight: 600; }
.dir-cat { color: #9fb0d8; font-size: 12px; text-transform: capitalize; }
.dir-empty { color: #7f8db3; }

/* Movement hint banner */
.verse-move-hint {
  position: fixed; left: 50%; top: 70px; transform: translateX(-50%); z-index: 26;
  max-width: min(680px, 94vw); padding: 10px 40px 10px 16px; border-radius: 12px;
  background: rgba(9, 14, 32, 0.92); border: 1px solid #2a376a; color: #dbe4ff;
  font-size: 14px; line-height: 1.5; box-shadow: 0 8px 30px rgba(0,0,0,0.4);
}
.verse-move-hint b { color: #7fd0ff; }
.verse-move-hint button {
  position: absolute; top: 6px; right: 8px; width: 26px; height: 26px; border-radius: 7px;
  border: 1px solid #2a376a; background: rgba(12,18,40,0.9); color: #eef2ff; cursor: pointer; font-size: 16px;
}

.toast {
  position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%) translateY(20px);
  z-index: 35; padding: 11px 18px; border-radius: 10px; opacity: 0; pointer-events: none;
  background: #12224a; border: 1px solid #2a376a; transition: opacity 0.2s, transform 0.2s;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.err { background: #4a1220; border-color: #6a2a3a; }

@media (max-width: 720px) {
  /* Mobile layout is split into non-overlapping horizontal bands so the HUD
     never piles up on itself the way a free-floating layout does on a phone:
        top       -> Exit + location (left), controls toggle (right)
        centre    -> 3D view + crosshair
        band 3    -> movement pad (right) / assistant (left, in-shop only)
        band 2    -> contextual action buttons (Enter shop, Inspect...)
        band 1    -> bottom nav bar (language / Shops / Controls / Cart)
     env(safe-area-inset-bottom) keeps everything clear of the phone's home bar. */

  /* --- Top bar --------------------------------------------------------- */
  .verse-hud { pointer-events: none; }
  .verse-hud .hud-left {
    position: fixed; top: 10px; left: 10px; right: auto; z-index: 27; gap: 6px;
  }
  .verse-hud .hud-left .hud-chip { font-size: 12.5px; padding: 6px 11px; }
  .verse-controls-toggle { display: inline-flex; top: 10px; right: 12px; }

  /* --- Band 1: bottom action bar (menu | centre action | shops) -------- */
  .verse-hud .hud-right {
    position: fixed; left: 0; right: 0; bottom: 0; top: auto; z-index: 30;
    display: grid; grid-template-columns: 1fr auto 1fr; align-items: center;
    gap: 8px; max-width: none;
    padding: 10px 16px calc(12px + env(safe-area-inset-bottom, 0px));
    background: linear-gradient(to top, rgba(5, 7, 15, 0.96), rgba(5, 7, 15, 0));
  }
  .verse-hud .hud-right .hud-chip {
    border-radius: 14px; padding: 10px 14px; font-size: 13px;
    background: rgba(12, 18, 40, 0.95); border-color: #34437c; white-space: nowrap;
  }
  #btnMore { display: inline-flex; justify-self: start; }
  #btnDirectory { justify-self: end; }
  /* Smart centre action: one prominent, contextual button (Enter / Inspect /
     Go up / Sit / Leave ...). Replaces the floating action bar on touch. */
  .hud-primary {
    display: inline-flex; align-items: center; justify-content: center;
    justify-self: center; min-width: 92px; padding: 15px 26px;
    border-radius: 999px; border: none; cursor: pointer;
    font-size: 15px; font-weight: 800; letter-spacing: 0.2px;
    color: #05070f; background: linear-gradient(135deg, #7fd0ff, #3d7fb0);
    box-shadow: 0 12px 28px rgba(0, 0, 0, 0.5), 0 0 0 5px rgba(95, 168, 211, 0.18);
    transform: translateY(-14px);
  }
  .hud-primary.is-idle, .hud-primary:disabled {
    background: rgba(12, 18, 40, 0.9); color: #7f8fbb; font-weight: 700;
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.4); transform: translateY(-8px); opacity: 0.85;
  }
  /* On mobile the menu popover rises from the bottom bar's start edge (which
     flips to the right under RTL/Arabic) instead of dropping from the top. */
  .hud-more-menu {
    top: auto; inset-inline-end: auto; inset-inline-start: 12px;
    bottom: calc(70px + env(safe-area-inset-bottom, 0px));
  }
  /* Fade the movement pad while the menu popover is open so it reads clearly. */
  body.more-open .verse-pad { opacity: 0.25; pointer-events: none; }

  /* --- Band 2: the floating action bar is replaced by the centre button - */
  .verse-actions { display: none; }

  /* --- Band 3: movement pad floats above the action row --------------- */
  .verse-pad {
    right: 10px; left: auto;
    bottom: calc(116px + env(safe-area-inset-bottom, 0px)); gap: 6px;
    background: transparent;
  }
  .pad-cross { grid-template-columns: repeat(3, 46px); grid-template-rows: repeat(3, 46px); gap: 5px; }
  .pad-cross .pad-btn { width: 46px; height: 46px; font-size: 15px; }
  .pad-btn { background: rgba(12, 18, 40, 0.6); }
  /* Drag anywhere on the screen to look/turn, so the on-screen look row is
     redundant on touch - hide it to cut four buttons. */
  .pad-look { display: none; }
  .pad-view { padding: 7px 10px; font-size: 12px; }
  .pad-tip { display: none; }

  /* --- Assistant (only visible inside a shop): narrow dock, bottom-left,
         width-capped so it never reaches the movement pad on the right. --- */
  .verse-assistant {
    left: 10px; bottom: calc(60px + env(safe-area-inset-bottom, 0px));
    width: min(210px, calc(100vw - 200px));
  }
  body.controls-collapsed #padControls,
  body.controls-collapsed .verse-assistant { display: none; }

  /* Keep the hint, prompt and toast clear of the top bar and control bands. */
  .verse-move-hint { top: 92px; font-size: 12.5px; padding: 9px 34px 9px 12px; }
  .verse-prompt { top: 52%; font-size: 14px; }
  .toast { bottom: 118px; }
}

/* Extra-tight phones (older / smaller handsets). */
@media (max-width: 400px) {
  .pad-cross { grid-template-columns: repeat(3, 42px); grid-template-rows: repeat(3, 42px); gap: 4px; }
  .pad-cross .pad-btn { width: 42px; height: 42px; font-size: 14px; }
  .verse-pad { bottom: calc(112px + env(safe-area-inset-bottom, 0px)); }
  .verse-hud .hud-left .hud-chip { font-size: 12px; padding: 5px 9px; }
  .verse-hud .hud-right .hud-chip { padding: 8px 11px; font-size: 12.5px; }
}

/* ---- Arabic / right-to-left ------------------------------------------- */
html[dir="rtl"] .verse-panel,
html[dir="rtl"] .verse-assistant,
html[dir="rtl"] .verse-move-hint,
html[dir="rtl"] .help-list,
html[dir="rtl"] .dir-row,
html[dir="rtl"] .asst-msg { direction: rtl; text-align: right; }
html[dir="rtl"] .asst-form input,
html[dir="rtl"] .dir-list input,
html[dir="rtl"] .cart-buyer input { text-align: right; }

