:root {
  --bg: #0b0b0f;
  --ink: #f5f5f7;
  --ink-2: rgba(235, 235, 245, 0.62);
  --ink-3: rgba(235, 235, 245, 0.38);
  --teal: 64, 224, 208;
  --magenta: 236, 64, 160;
  --gold: #e9c46a;
  --radius: 38px;
  --inset: 9px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", "PingFang SC", "Hiragino Sans GB", "Noto Sans CJK SC", "Source Han Sans SC", "Microsoft YaHei", "Helvetica Neue", sans-serif;
  --mono: ui-monospace, "SF Mono", "SFMono-Regular", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  overflow: hidden;
  overscroll-behavior: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

/* ───────── backdrop ───────── */
.backdrop {
  position: fixed;
  inset: 0;
  background: var(--bg);
  overflow: hidden;
}
.backdrop .glow {
  position: absolute;
  inset: -20%;
  background:
    radial-gradient(42% 34% at 24% 30%, rgba(var(--teal), 0.16), transparent 70%),
    radial-gradient(38% 30% at 78% 64%, rgba(var(--magenta), 0.12), transparent 70%),
    radial-gradient(60% 40% at 50% 110%, rgba(var(--teal), 0.06), transparent 70%);
  filter: blur(36px);
  transform: translateZ(0);
}
.backdrop .grain {
  position: absolute;
  inset: 0;
  background: radial-gradient(120% 90% at 50% 40%, transparent 40%, rgba(0, 0, 0, 0.55) 100%);
}

@keyframes breathe {
  from { opacity: 0.85; transform: scale(1) translateZ(0); }
  to   { opacity: 1;    transform: scale(1.06) translateZ(0); }
}

/* ───────── loader ───────── */
.loader {
  position: fixed;
  left: 50%;
  top: 50%;
  width: 34px;
  height: 34px;
  margin: -17px 0 0 -17px;
  opacity: 0;
  transform: scale(0.8);
  transition: opacity 0.35s ease, transform 0.35s ease;
  pointer-events: none;
}
.loader.show { opacity: 1; transform: none; }
.loader svg { display: block; transform: rotate(-90deg); }
.loader circle { fill: none; stroke-width: 3; stroke-linecap: round; }
.loader .track { stroke: rgba(255, 255, 255, 0.1); }
.loader .bar {
  stroke: rgba(255, 255, 255, 0.75);
  stroke-dasharray: 100;
  stroke-dashoffset: 92;
  transition: stroke-dashoffset 0.25s ease;
}
.loader.indeterminate svg { animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(270deg); } }

/* ───────── sheet ───────── */
.stage {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: var(--inset);
  padding-bottom: max(var(--inset), calc(env(safe-area-inset-bottom) - 14px));
  pointer-events: none;
}
.sheet {
  position: relative;
  width: 100%;
  max-width: 460px;
  border-radius: var(--radius);
  padding: 0 0 22px;
  background: linear-gradient(180deg, #1e1e24 0%, #17171c 100%);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.09),
    inset 0 0 0 0.5px rgba(255, 255, 255, 0.07),
    0 30px 80px rgba(0, 0, 0, 0.55),
    0 2px 10px rgba(0, 0, 0, 0.3);
  visibility: hidden;
  pointer-events: auto;
  will-change: transform;
  transform: translate3d(0, 120vh, 0);
  overflow: hidden;
}
.sheet.live { visibility: visible; }
/* faint sheen across the glass */
.sheet::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background:
    radial-gradient(90% 55% at 50% 0%, rgba(255, 255, 255, 0.06), transparent 70%);
  pointer-events: none;
}

.sheet-head {
  position: relative;
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.caption {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.14em;
  color: var(--ink-3);
  padding-top: 6px;
}
.close {
  position: absolute;
  right: 16px;
  top: 16px;
  width: 30px;
  height: 30px;
  border: 0;
  border-radius: 50%;
  padding: 0;
  display: grid;
  place-items: center;
  color: rgba(235, 235, 245, 0.6);
  background: rgba(118, 118, 128, 0.24);
  cursor: pointer;
  transition: transform 0.2s ease, background 0.2s ease;
}
.close:active { transform: scale(0.88); background: rgba(118, 118, 128, 0.36); }

.viewport {
  position: relative;
  width: 100%;
  aspect-ratio: 10 / 7;
  max-height: max(170px, calc(100svh - 290px));
  margin-top: -10px;
  touch-action: none;
  cursor: grab;
  perspective: 900px;
}
.viewport.dragging { cursor: grabbing; }
.viewport canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  outline: none;
}
.viewport .fallback {
  position: absolute;
  left: 11%;
  top: 50%;
  width: 78%;
  height: auto;
  margin-top: -19.8%; /* half of image height (78% * 588/1160 / 2) */
  border-radius: 3.1% / 6.1%;
  box-shadow: 0 24px 40px -18px rgba(0, 0, 0, 0.7);
  will-change: transform;
  backface-visibility: visible;
  pointer-events: none;
}

.copy {
  position: relative;
  text-align: center;
  padding: 0 22px;
  margin-top: -2px;
}
.title {
  margin: 0;
  font-size: 27px;
  line-height: 1.2;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--ink);
}
.subtitle {
  margin: 7px 0 0;
  font-family: var(--mono);
  font-size: 12.5px;
  letter-spacing: 0.08em;
  color: var(--ink-2);
}
.subtitle s {
  text-decoration-thickness: 1px;
  color: var(--ink-3);
}
.actions {
  display: flex;
  gap: 10px;
  margin-top: 22px;
}
.btn {
  flex: 1 1 0;
  min-width: 0;
  height: 52px;
  border: 0;
  border-radius: 16px;
  font: 600 16px/1 var(--font);
  letter-spacing: 0.04em;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  text-decoration: none;
  cursor: pointer;
  transition: transform 0.18s ease, opacity 0.18s ease, background 0.2s ease;
}
.btn:active { transform: scale(0.965); opacity: 0.85; }
.btn.primary { background: rgba(255, 255, 255, 0.94); color: #111114; }
.btn.secondary { background: rgba(118, 118, 128, 0.26); color: var(--ink); }
.ar-icon { width: 18px; height: 18px; display: block; }

/* staggered text reveal */
.reveal {
  opacity: 0;
  transform: translate3d(0, 14px, 0);
  transition: opacity 0.5s cubic-bezier(0.2, 0.8, 0.2, 1), transform 0.62s cubic-bezier(0.2, 0.9, 0.25, 1);
}
.reveal.in { opacity: 1; transform: none; }
.reveal.out { transition-duration: 0.18s; transition-delay: 0s !important; }
.caption, .close { transition: opacity 0.4s ease; }
.sheet:not(.ready) .caption, .sheet:not(.ready) .close { opacity: 0; }

/* replay pill */
.replay {
  position: fixed;
  left: 50%;
  bottom: calc(28px + env(safe-area-inset-bottom));
  transform: translate3d(-50%, 20px, 0) scale(0.9);
  opacity: 0;
  height: 40px;
  padding: 0 18px 0 14px;
  border-radius: 20px;
  border: 0;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font: 600 14px/1 var(--font);
  letter-spacing: 0.04em;
  color: var(--ink);
  background: #2a2a31;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.1), 0 10px 30px rgba(0, 0, 0, 0.4);
  cursor: pointer;
  transition: opacity 0.35s ease, transform 0.5s cubic-bezier(0.2, 1.4, 0.4, 1);
}
.replay.show { opacity: 1; transform: translate3d(-50%, 0, 0) scale(1); }
.replay:active { transform: translate3d(-50%, 0, 0) scale(0.95); }

.noscript { position: fixed; inset: auto 0 40px; text-align: center; color: var(--ink-2); font-size: 14px; }

/* desktop / large screens: centred card */
@media (min-width: 700px) and (min-height: 620px) {
  .stage { align-items: center; padding: 24px; }
  .sheet { padding-bottom: 26px; }
}
/* short landscape phones: tighter */
@media (max-height: 480px) {
  .sheet-head { height: 40px; }
  .title { font-size: 22px; }
  .actions { margin-top: 12px; }
  .btn { height: 44px; }
}

@media (prefers-reduced-motion: reduce) {
  .reveal { transform: none; transition: opacity 0.4s ease; }
  body.sheet-open .backdrop .glow { animation: none; }
}

[hidden] { display: none !important; }
.actions:not(:has(> :not([hidden]))) { display: none; }

.serial {
  margin: 8px 0 0;
  font-family: var(--mono);
  font-size: 13px;
  letter-spacing: 0.12em;
  color: var(--ink-2);
}
.serial.invalid { color: var(--ink-3); letter-spacing: 0.04em; font-family: var(--font); }

.guide-link {
  margin: 14px auto 0;
  display: block;
  border: 0;
  background: none;
  padding: 6px 10px;
  font: 500 13px/1 var(--font);
  letter-spacing: 0.04em;
  color: var(--ink-3);
  text-decoration: underline;
  text-underline-offset: 3px;
  text-decoration-color: rgba(235, 235, 245, 0.2);
  cursor: pointer;
}
.guide {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: var(--bg);
  opacity: 0;
  transform: translate3d(0, 24px, 0);
  transition: opacity 0.3s ease, transform 0.3s cubic-bezier(0.2, 0.9, 0.25, 1);
}
.guide.open { opacity: 1; transform: none; }
.guide-scroll {
  position: absolute;
  inset: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: calc(env(safe-area-inset-top) + 56px) 24px calc(env(safe-area-inset-bottom) + 48px);
  max-width: 520px;
  margin: 0 auto;
  user-select: text;
  -webkit-user-select: text;
  font-size: 15px;
  line-height: 1.75;
  color: var(--ink-2);
}
.guide-close { position: fixed; top: calc(env(safe-area-inset-top) + 14px); right: 16px; }
.guide h2 { color: var(--ink); font-size: 22px; line-height: 1.4; margin: 0 0 12px; letter-spacing: 0.02em; }
.guide .g-no { display: block; font: 500 14px/1.6 var(--mono); letter-spacing: 0.12em; color: var(--ink-3); margin-top: 4px; }
.guide h3 { color: var(--ink); font-size: 16px; margin: 30px 0 8px; }
.guide p { margin: 0 0 10px; }
.guide b { color: var(--ink); font-weight: 600; }
.guide ul, .guide ol { margin: 0 0 10px; padding-left: 1.3em; }
.guide li { margin: 4px 0; }
.g-apps { display: grid; gap: 12px; }
.g-app { background: #18181d; border-radius: 16px; padding: 14px 14px 12px; }
.g-os { color: var(--ink); font-weight: 600; margin-bottom: 8px; }
.g-btn {
  display: block;
  width: 100%;
  text-align: center;
  border: 0;
  border-radius: 12px;
  padding: 11px 12px;
  font: 600 15px/1.2 var(--font);
  color: #111;
  background: var(--ink);
  text-decoration: none;
  cursor: pointer;
}
.g-btn.ghost { background: #2a2a31; color: var(--ink); }
.g-tip { font-size: 13px; line-height: 1.6; color: var(--ink-3); margin: 8px 0 !important; }
.g-langs { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 22px; }
.g-langs button { border: 0; border-radius: 999px; padding: 6px 11px; font: 500 12.5px/1 var(--font); color: var(--ink-3); background: #18181d; cursor: pointer; }
.g-langs button.on { color: #111; background: var(--ink); }
.g-copy { background: #18181d; border-radius: 16px; padding: 12px; }
.g-copy code { display: block; font: 12px/1.5 var(--mono); color: var(--ink-3); word-break: break-all; margin-bottom: 10px; user-select: all; -webkit-user-select: all; }
