/* Chrome estilo iOS. O canvas ocupa a viewport inteira; a UI da página é
   uma camada fina com vidro fosco que some no toque. */

* { box-sizing: border-box; }
html, body {
  width: 100vw; height: 100vh; margin: 0; overflow: hidden;
  background: #050609;
}
body {
  color: #fff;
  font: 14px/1.35 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  touch-action: none;
  user-select: none; -webkit-user-select: none;
  -webkit-touch-callout: none;
}
canvas#gl {
  position: fixed; inset: 0; display: block;
  width: 100vw; height: 100vh;
}

/* ─── Top-level frosted chrome ─── */
.chrome {
  position: fixed; inset: 0;
  pointer-events: none;
  padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(18px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}

.actions {
  position: absolute; left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 12px; width: max-content; max-width: calc(100% - 24px);
  pointer-events: auto;
  transition: opacity .25s, visibility .25s;
}
.actions.hidden { opacity: 0; visibility: hidden; pointer-events: none; }

/* ─── Buttons + chips ─── */
button, .pick, .credit {
  border: 1px solid rgba(255,255,255,.16);
  background: rgba(19,22,28,.68);
  color: #fff;
  box-shadow: 0 8px 32px rgba(0,0,0,.28);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
}
button, .pick {
  min-height: 38px; border-radius: 999px;
  padding: 8px 14px; font: inherit; font-weight: 600; cursor: pointer;
}
button:active, .pick:active, .credit:active { transform: scale(.97); }

.pick { position: relative; }
.pick input {
  position: absolute; width: 1px; height: 1px; opacity: 0;
}
.pick:focus-within { outline: 2px solid #fff; outline-offset: 3px; }

.credit {
  display: inline-flex; align-items: center; gap: 4px;
  min-height: 44px; padding: 8px 14px;
  border-radius: 999px;
  color: rgba(255,255,255,.85);
  text-decoration: none; white-space: nowrap; cursor: pointer;
  font-size: 13px;
  transition: background .15s, transform .15s;
}
.credit strong { color: #fff; font-weight: 600; }
.credit svg { width: 14px; height: 14px; margin-left: 4px; }
.credit:hover { background: rgba(52,57,66,.9); }
.credit:focus-visible { outline: 2px solid #fff; outline-offset: 3px; }
.credit[hidden] { display: none; }

/* ─── Hint at bottom ─── */
.hint {
  position: absolute; left: 50%; bottom: max(24px, env(safe-area-inset-bottom));
  width: min(88vw, 430px);
  transform: translateX(-50%);
  text-align: center;
  color: rgba(255,255,255,.8);
  text-shadow: 0 1px 12px #000;
  transition: opacity .5s;
}
.hint.hidden { opacity: 0; }

/* ─── Error banner ─── */
.error {
  position: fixed; inset: auto 16px 16px; z-index: 5;
  display: none; padding: 14px;
  border-radius: 12px; background: #802828;
  pointer-events: none;
}

/* Hide the live canvas while waiting for first sensor reading. */
.waiting-for-gravity .chrome, .waiting-for-gravity canvas,
.no-gravity canvas { visibility: hidden; }
body:has(#motion-permission[open]):not(.no-gravity) canvas { visibility: visible; }

/* ─── Unavailable device panel ─── */
.unavailable {
  position: fixed; inset: 0;
  display: flex; flex-direction: column; align-items: center;
  padding: max(28px, env(safe-area-inset-top)) max(20px, env(safe-area-inset-right))
           max(28px, env(safe-area-inset-bottom)) max(20px, env(safe-area-inset-left));
  background: #101318;
  overflow-y: auto; overscroll-behavior: contain; touch-action: pan-y;
}
.unavailable[hidden] { display: none; }
.unavailable-content { width: min(100%, 560px); margin-block: auto; }
.instruction { width: 100%; margin-bottom: 24px; }
.instruction h1 {
  margin: 0 0 12px; font-size: 28px; line-height: 1.15;
  letter-spacing: -.025em;
}
.instruction p { margin: 0 0 8px; color: #c6c9d0; font-size: 16px; line-height: 1.55; }
.instruction .motion-status { margin-top: 12px; font-size: 14px; }
.motion-retry { margin-top: 16px; }

.demo-embed {
  width: 100%; padding: 24px;
  border: 1px solid rgba(255,255,255,.15);
  border-radius: 20px; color: #dfe3e9; line-height: 1.5;
  font-size: 15px;
}
.demo-embed a { color: #a9d5ff; }

/* ─── Permission dialog (iOS-style modal) ─── */
dialog {
  width: min(400px, calc(100vw - 24px));
  max-width: none; max-height: calc(100dvh - 32px); margin: auto;
  padding: 28px 24px 24px;
  border: 1px solid rgba(255,255,255,.14);
  border-radius: 32px;
  background: linear-gradient(155deg, rgba(255,255,255,.05), transparent 60%), rgba(25,28,34,.93);
  color: #fff;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.06), 0 24px 80px rgba(0,0,0,.35);
  backdrop-filter: blur(32px) saturate(130%);
  -webkit-backdrop-filter: blur(32px) saturate(130%);
  outline: none; overflow: auto; overscroll-behavior: contain; touch-action: pan-y;
  opacity: 0; transform: translateY(18px) scale(.98);
  transition: opacity .22s, transform .3s cubic-bezier(.2,.8,.2,1),
              display .3s allow-discrete, overlay .3s allow-discrete;
}
dialog[open] { opacity: 1; transform: none; }
dialog::backdrop { background: rgba(6,9,13,.5); }

.dialog-icon {
  display: grid; place-items: center;
  width: 60px; height: 60px; margin-bottom: 22px;
  border: 1px solid rgba(255,255,255,.09);
  border-radius: 20px;
  background: linear-gradient(145deg, rgba(255,255,255,.09), rgba(255,255,255,.02));
  color: #f1f5fa;
}
.dialog-icon svg { width: 34px; height: 34px; }
.permission-heading {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 12px; margin-bottom: 22px;
}
.permission-heading .dialog-icon { flex-shrink: 0; margin-bottom: 0; }
.permission-heading .credit { margin-top: 8px; }

dialog h2 {
  margin: 0 0 10px; font-size: 27px; font-weight: 650;
  line-height: 1.15; letter-spacing: -.025em;
}
dialog p {
  margin: 0 0 26px; color: #c6c9d0;
  font-size: 16px; line-height: 1.5; text-wrap: pretty;
}
dialog button {
  width: 100%; min-height: 56px; padding: 15px 20px;
  border: 0; background: #f4f5f7; color: #17191e;
  box-shadow: 0 2px 8px rgba(0,0,0,.13);
  font-size: 17px; font-weight: 600; letter-spacing: -.015em;
  transition: transform .15s, background .15s;
}
dialog button:active { transform: scale(.985); background: #dfe2e8; }
dialog button:focus-visible { outline: 3px solid #90c8ff; outline-offset: 4px; }
dialog button:disabled { opacity: .6; cursor: wait; }

.setup-steps { display: grid; gap: 16px; margin: 0 0 24px; padding: 0; list-style: none; counter-reset: step; }
.setup-steps li {
  display: flex; align-items: center; gap: 12px;
  color: #e2e4e9; font-size: 15px; line-height: 1.45;
  counter-increment: step;
}
.setup-steps li::before {
  content: counter(step);
  display: grid; place-items: center; flex: 0 0 28px; height: 28px;
  border-radius: 50%; background: rgba(255,255,255,.05);
  color: #c6c9d0; font-size: 13px; font-weight: 600;
}
dialog .footnote { margin-bottom: 24px; font-size: 13px; color: #a5aab5; }

@starting-style { dialog[open] { opacity: 0; transform: translateY(18px) scale(.98); } }
@media (prefers-reduced-motion: reduce) {
  .actions, .credit, .hint, dialog, dialog button { transition: none; }
  dialog { transform: none; }
}
@media (prefers-reduced-transparency: reduce) {
  dialog { background: #1b1e24; backdrop-filter: none; -webkit-backdrop-filter: none; }
}
@media (max-width: 600px) {
  dialog { margin: auto auto max(12px, env(safe-area-inset-bottom)); }
}

/* ─── Tuning mode (/?tuning) ─── */
.tuning-panel {
  display: none;
  position: fixed; right: 16px; top: 16px;
  width: min(320px, calc(100vw - 32px));
  padding: 16px;
  border-radius: 18px;
  background: rgba(20,22,28,.92);
  border: 1px solid rgba(255,255,255,.1);
  color: #fff;
  font-size: 12px;
  pointer-events: auto;
  z-index: 6;
  max-height: calc(100vh - 32px); overflow: auto;
}
body.tuning .tuning-panel { display: block; }
.tuning-panel h3 {
  margin: 0 0 10px; font-size: 12px;
  color: rgba(255,255,255,.6); text-transform: uppercase; letter-spacing: .08em;
}
.tuning-row {
  display: grid; grid-template-columns: 1fr 48px; gap: 8px; align-items: center;
  margin-bottom: 6px;
}
.tuning-row input[type=range] { width: 100%; }
.tuning-row output { text-align: right; color: rgba(255,255,255,.7); font-variant-numeric: tabular-nums; }
.tuning-divider { height: 1px; background: rgba(255,255,255,.1); margin: 12px 0; }
