  @import url('https://fonts.googleapis.com/css2?family=Google+Sans:wght@400;500;700&display=swap');

  * { box-sizing: border-box; margin: 0; padding: 0; }

  :root {
    --accent: #6c63ff;
    --accent2: #43e8a0;
    --accent3: #ff6584;
    --bg: #0a0a0f;
    --surface: rgba(17,17,24,0.92);
    --border: rgba(42,42,58,0.8);
    --text: #e8e8f0;
    --text-muted: #6a6a8a;
  }

  html, body {
    width: 100%; height: 100%;
    overflow: hidden;
    background: #000;
    font-family: 'Google Sans', 'Google Sans Text', 'Segoe UI', Arial, sans-serif;
    color: var(--text);
  }

  /* ---- LOADING SCREEN ---- */
  #loadScreen {
    position: fixed; inset: 0;
    background: var(--bg);
    z-index: 1000;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 24px;
    padding: 32px;
    transition: opacity 0.5s;
  }
  #loadScreen.hidden { opacity: 0; pointer-events: none; }

  .load-logo {
    font-family: 'Google Sans', 'Google Sans Text', 'Segoe UI', Arial, sans-serif;
    font-weight: 800;
    font-size: 28px;
    letter-spacing: -1px;
    background: linear-gradient(135deg, var(--accent2) 0%, var(--accent) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    text-align: center;
  }
  .load-sub { font-size: 11px; color: var(--text-muted); letter-spacing: 2px; text-transform: uppercase; }

  .load-card {
    background: rgba(255,255,255,0.03);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 24px;
    width: 100%;
    max-width: 320px;
    text-align: center;
  }
  .load-card-title { font-size: 12px; color: var(--text-muted); margin-bottom: 16px; letter-spacing: 1px; text-transform: uppercase; }

  .drop-zone {
    border: 2px dashed var(--border);
    border-radius: 12px;
    padding: 24px 16px;
    cursor: pointer;
    transition: all 0.2s;
    margin-bottom: 12px;
  }
  .drop-zone:hover, .drop-zone.dragover {
    border-color: var(--accent);
    background: rgba(108,99,255,0.05);
  }
  .drop-zone .dz-icon { font-size: 32px; display: block; margin-bottom: 8px; }
  .drop-zone .dz-text { font-size: 12px; color: var(--text-muted); line-height: 1.5; }

  .load-btn {
    width: 100%;
    background: var(--accent);
    border: none;
    border-radius: 10px;
    color: #fff;
    font-family: 'Google Sans', 'Google Sans Text', 'Segoe UI', Arial, sans-serif;
    font-size: 13px;
    font-weight: 700;
    padding: 12px;
    cursor: pointer;
    letter-spacing: 0.5px;
    transition: opacity 0.15s;
  }
  .load-btn:hover { opacity: 0.9; }
  .load-btn:disabled { opacity: 0.4; cursor: default; }

  .load-note {
    font-size: 10px;
    color: var(--text-muted);
    line-height: 1.6;
    text-align: center;
    max-width: 280px;
  }

  /* ---- LOAD SPINNER ---- */
  #loadSpinner {
    flex-direction: column;
    align-items: center;
    gap: 20px;
  }
  .spinner-ring {
    width: 52px; height: 52px;
    border: 3px solid rgba(108,99,255,0.18);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.75s linear infinite;
  }
  @keyframes spin { to { transform: rotate(360deg); } }
  .spinner-label {
    font-size: 13px;
    color: var(--text-muted);
    text-align: center;
    letter-spacing: 0.3px;
  }

  input[type="file"] { display: none; }

  /* ---- AR CANVAS LAYER ---- */
  #arContainer {
    position: fixed; inset: 0;
    display: none;
  }
  #arContainer.active { display: block; }

  #videoEl {
    position: absolute; inset: 0;
    width: 100%; height: 100%;
    object-fit: cover;
  }

  #threeCanvas {
    position: absolute; inset: 0;
    width: 100% !important;
    height: 100% !important;
    pointer-events: none;
  }

  /* ---- HUD ---- */
  #hud {
    position: absolute; inset: 0;
    pointer-events: none;
    z-index: 10;
  }

  .hud-top {
    position: absolute;
    top: 0; left: 0; right: 0;
    padding: 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: linear-gradient(to bottom, rgba(0,0,0,0.6) 0%, transparent 100%);
    pointer-events: all;
  }

  .hud-logo {
    font-family: 'Google Sans', 'Google Sans Text', 'Segoe UI', Arial, sans-serif;
    font-size: 14px;
    font-weight: 800;
    background: linear-gradient(135deg, var(--accent2) 0%, var(--accent) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
  }

  .hud-btn {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font-family: 'Google Sans', 'Google Sans Text', 'Segoe UI', Arial, sans-serif;
    font-size: 11px;
    padding: 6px 12px;
    cursor: pointer;
    backdrop-filter: blur(8px);
    transition: all 0.15s;
  }
  .hud-btn:hover { border-color: var(--accent); color: var(--accent); }

  .hud-bottom {
    position: absolute;
    bottom: 0; left: 0; right: 0;
    padding: 16px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    background: linear-gradient(to top, rgba(0,0,0,0.5) 0%, transparent 100%);
  }

  .tracking-status {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 6px 14px;
    font-size: 11px;
    backdrop-filter: blur(8px);
  }
  .status-indicator {
    width: 8px; height: 8px;
    border-radius: 50%;
    background: var(--accent3);
    animation: pulse 1.5s infinite;
  }
  .status-indicator.tracking { background: var(--accent2); animation: none; }
  .status-indicator.lost { background: var(--accent3); }

  @keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.3; }
  }

  .tap-hint {
    font-size: 10px;
    color: rgba(255,255,255,0.4);
    letter-spacing: 1px;
  }

  /* ---- AR LOADING PROGRESS OVERLAY ---- */
  #arLoadingOverlay {
    position: absolute; inset: 0;
    display: none;
    align-items: flex-end;
    justify-content: center;
    padding-bottom: 120px;
    z-index: 50;
    pointer-events: none;
  }
  .ar-lp-inner {
    width: min(320px, 80vw);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 14px 18px;
    backdrop-filter: blur(12px);
  }
  .ar-lp-label {
    font-size: 11px;
    color: var(--text-muted);
    margin-bottom: 8px;
    letter-spacing: 0.5px;
  }
  .ar-lp-track {
    height: 4px;
    background: rgba(255,255,255,0.08);
    border-radius: 4px;
    overflow: hidden;
  }
  .ar-lp-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(to right, var(--accent), var(--accent2));
    border-radius: 4px;
    transition: width 0.3s ease;
  }

  /* ---- SCANNING OVERLAY ---- */
  #scanOverlay {
    position: absolute; inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
  }

  .scan-frame {
    width: 240px;
    height: 300px;
    position: relative;
  }

  .scan-corner {
    position: absolute;
    width: 24px; height: 24px;
    border-color: var(--accent2);
    border-style: solid;
    opacity: 0.8;
  }
  .sc-tl { top: 0; left: 0; border-width: 2px 0 0 2px; border-radius: 4px 0 0 0; }
  .sc-tr { top: 0; right: 0; border-width: 2px 2px 0 0; border-radius: 0 4px 0 0; }
  .sc-bl { bottom: 0; left: 0; border-width: 0 0 2px 2px; border-radius: 0 0 0 4px; }
  .sc-br { bottom: 0; right: 0; border-width: 0 2px 2px 0; border-radius: 0 0 4px 0; }

  .scan-line {
    position: absolute;
    left: 0; right: 0;
    height: 2px;
    background: linear-gradient(to right, transparent, var(--accent2), transparent);
    animation: scanline 2s ease-in-out infinite;
  }

  @keyframes scanline {
    0% { top: 0; opacity: 0; }
    10% { opacity: 1; }
    90% { opacity: 1; }
    100% { top: 100%; opacity: 0; }
  }

  .scan-label {
    position: absolute;
    bottom: -28px; left: 50%;
    transform: translateX(-50%);
    font-size: 11px;
    color: var(--accent2);
    white-space: nowrap;
    letter-spacing: 1px;
  }

  /* ---- TOAST ---- */
  #toast {
    position: fixed;
    bottom: 80px; left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 10px 18px;
    font-size: 12px;
    color: var(--text);
    backdrop-filter: blur(12px);
    z-index: 500;
    opacity: 0;
    transition: all 0.3s;
    white-space: nowrap;
  }
  #toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

  /* ---- DEBUG PANEL ---- */
  #debugPanel {
    position: fixed;
    top: 60px; left: 0; right: 0;
    padding: 8px 16px;
    background: rgba(0,0,0,0.7);
    font-size: 10px;
    color: var(--accent2);
    display: none;
    line-height: 1.6;
    backdrop-filter: blur(4px);
    z-index: 20;
  }
  #debugPanel.visible { display: block; }

  /* ---- NO CAMERA fallback ---- */
  #noCameraMsg {
    position: fixed; inset: 0;
    background: var(--bg);
    display: none;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 16px;
    text-align: center;
    padding: 32px;
    font-size: 13px;
    color: var(--text-muted);
    z-index: 900;
  }
  #noCameraMsg.visible { display: flex; }
  #noCameraMsg .nc-icon { font-size: 48px; }
  #noCameraMsg h2 { font-size: 18px; color: var(--text); font-family: 'Google Sans', 'Google Sans Text', 'Segoe UI', Arial, sans-serif; }

  /* ================================================================
     LAUNCHER — mode picker cards (ar-launcher.html)
  ================================================================ */
  .mode-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
    width: 100%;
    max-width: 360px;
  }
  @media (max-width: 380px) { .mode-grid { grid-template-columns: 1fr; } }

  .mode-card {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    padding: 24px 16px 20px;
    background: rgba(255,255,255,0.03);
    border: 1px solid var(--border);
    border-radius: 16px;
    text-decoration: none;
    color: var(--text);
    transition: border-color 0.2s, background 0.2s;
    cursor: pointer;
    text-align: center;
  }
  .mode-card:hover {
    border-color: var(--accent);
    background: rgba(108,99,255,0.07);
  }
  .mode-icon  { font-size: 32px; line-height: 1; }
  .mode-title { font-size: 13px; font-weight: 700; letter-spacing: 0.3px; }
  .mode-desc  { font-size: 11px; color: var(--text-muted); line-height: 1.5; }
  .mode-badge {
    position: absolute;
    top: 8px; right: 8px;
    font-size: 8px;
    font-weight: 700;
    letter-spacing: 0.5px;
    color: var(--accent2);
    border: 1px solid var(--accent2);
    border-radius: 4px;
    padding: 1px 5px;
    opacity: 0.8;
  }
  .mode-card.disabled { opacity: 0.35; pointer-events: none; }

  /* ================================================================
     SURFACE AR — enter-AR panel + placement overlay (ar-surface.html)
  ================================================================ */

  /* xrOverlay: direct body child, position:fixed — required by WebXR dom-overlay spec.
     Uses visibility:hidden (NOT display:none) so the element is always RENDERED and
     in the layout tree — WebXR dom-overlay requires the root to be visible at
     requestSession time. Switched to visibility:visible when XR session starts. */
  #xrOverlay {
    position: fixed; inset: 0;
    opacity: 0;
    pointer-events: none;
    z-index: 200;
  }
  #xrOverlay.xr-active {
    opacity: 1;
    pointer-events: auto;
  }
  #enterARPanel, #enterCameraARPanel {
    display: none;
    flex-direction: column;
    align-items: center;
    gap: 14px;
    width: 100%;
    max-width: 320px;
    text-align: center;
  }
  .enter-ar-hint {
    font-size: 10px;
    color: var(--text-muted);
    line-height: 1.6;
    max-width: 260px;
  }

  /* Crosshair — screen-centre aim indicator, visible after scene placement */
  #crosshair {
    display: none;
    position: fixed;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    width: 24px; height: 24px;
    pointer-events: none;
    z-index: 300;
  }
  #crosshair.visible { display: block; }
  .ch-h { width: 100%; height: 2px; top: 50%; transform: translateY(-50%);
    background: linear-gradient(to right,
      rgba(255,255,255,0.85) calc(50% - 3px),
      transparent calc(50% - 3px),
      transparent calc(50% + 3px),
      rgba(255,255,255,0.85) calc(50% + 3px));
  }
  .ch-v { height: 100%; width: 2px; left: 50%; transform: translateX(-50%);
    background: linear-gradient(to bottom,
      rgba(255,255,255,0.85) calc(50% - 3px),
      transparent calc(50% - 3px),
      transparent calc(50% + 3px),
      rgba(255,255,255,0.85) calc(50% + 3px));
  }
  .ch-h, .ch-v {
    position: absolute;
    filter: drop-shadow(0 0 3.5px rgba(0,0,0,0.95)) drop-shadow(0 0 2px rgba(0,0,0,0.85));
  }

  #surfaceScanOverlay {
    position: fixed; inset: 0;
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 24px;
    pointer-events: none;
  }
  .sp-ring {
    width: 80px; height: 80px;
    border-radius: 50%;
    border: 2px solid var(--accent);
    box-shadow: 0 0 0 8px rgba(108,99,255,0.12), inset 0 0 0 8px rgba(108,99,255,0.12);
    animation: spPulse 2s ease-in-out infinite;
  }
  @keyframes spPulse {
    0%, 100% { transform: scale(1);    opacity: 0.9; }
    50%       { transform: scale(1.12); opacity: 0.5; }
  }
  .sp-label {
    font-size: 11px;
    color: var(--accent2);
    letter-spacing: 1px;
    text-align: center;
    padding: 6px 16px;
    background: rgba(0,0,0,0.4);
    border-radius: 20px;
    backdrop-filter: blur(6px);
  }

  /* Tap-to-place hint — shown once a flat surface is detected */
  #tapToPlaceHint {
    display: none;
    position: fixed;
    bottom: 100px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 13px;
    font-weight: 600;
    letter-spacing: 1.5px;
    color: #fff;
    padding: 8px 22px;
    background: rgba(0,0,0,0.5);
    border: 1.5px solid rgba(255,255,255,0.35);
    border-radius: 24px;
    backdrop-filter: blur(8px);
    pointer-events: none;
    animation: tapHintPulse 1.4s ease-in-out infinite;
  }
  @keyframes tapHintPulse {
    0%, 100% { opacity: 1; }
    50%       { opacity: 0.55; }
  }

  #noXRMsg {
    display: none;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    padding: 20px;
    background: rgba(255,100,100,0.08);
    border: 1px solid rgba(255,100,100,0.3);
    border-radius: 14px;
    max-width: 300px;
    text-align: center;
    font-size: 12px;
    color: var(--text-muted);
  }
