:root {
  --bg: #05040f;
  --glass: rgba(22, 20, 44, 0.72);
  --glass-strong: rgba(28, 26, 54, 0.92);
  --panel: rgba(16, 15, 32, 0.94);
  --line: rgba(255, 255, 255, 0.12);
  --line-strong: rgba(255, 255, 255, 0.22);
  --text: #f2f1ff;
  --muted: rgba(235, 233, 255, 0.62);
  --accent: #8f7bff;
  --accent-2: #3fd0ff;
  --danger: #ff5c7a;
  --radius: 26px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", system-ui, sans-serif;
  color: var(--text);
  -webkit-text-size-adjust: 100%;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  overscroll-behavior: none;
}
body {
  position: fixed;
  inset: 0;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
}

button { font: inherit; color: inherit; }
input, textarea { font: inherit; }

/* ---------- Background ---------- */
#passthrough, #sky {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
}
#passthrough { object-fit: cover; display: none; }
body.bg-camera #passthrough { display: block; }
#sky { touch-action: none; cursor: grab; }
#sky.dragging { cursor: grabbing; }

/* ---------- 3D space ---------- */
#viewport {
  position: fixed;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  /* perspective is set from JS */
}
#world, #rig {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 0;
  height: 0;
  transform-style: preserve-3d;
}

.win {
  position: absolute;
  left: 0;
  top: 0;
  transform-style: preserve-3d;
  pointer-events: none;
  will-change: transform;
}
.win.hidden { visibility: hidden; }
.win.hidden * { pointer-events: none !important; }

.win-frame {
  position: absolute;
  inset: 0;
  border-radius: var(--radius);
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.55), 0 0 0 1px rgba(143, 123, 255, 0.06);
  overflow: hidden;
  pointer-events: auto;
  display: flex;
  flex-direction: column;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.win.focused .win-frame {
  border-color: rgba(143, 123, 255, 0.55);
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.55), 0 0 40px rgba(143, 123, 255, 0.18);
}
.win-title {
  position: absolute;
  left: 50%;
  bottom: 100%;
  transform: translate(-50%, -10px);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 14px;
  border-radius: 999px;
  background: var(--glass);
  border: 1px solid var(--line);
  font-size: 15px;
  font-weight: 600;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0.9;
}
.win-title .app-dot { width: 14px; height: 14px; border-radius: 5px; }

.win-bar {
  position: absolute;
  left: 50%;
  top: 100%;
  transform: translate(-50%, 14px);
  display: flex;
  align-items: center;
  gap: 12px;
  pointer-events: auto;
}
.win-close {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--glass);
  display: grid;
  place-items: center;
  cursor: pointer;
}
.win-close svg { width: 14px; height: 14px; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; }
.win-grab {
  width: 140px;
  height: 34px;
  display: grid;
  place-items: center;
  cursor: grab;
  touch-action: none;
}
.win-grab::before {
  content: "";
  width: 120px;
  height: 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.55);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.4);
  transition: background 0.15s, transform 0.15s;
}
.win-grab.active::before { background: #fff; transform: scaleX(1.08); }

.app {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  position: relative;
}

/* ---------- Shared app UI ---------- */
.toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.03);
}
.toolbar input[type="text"], .toolbar input[type="url"] {
  flex: 1;
  min-width: 0;
  height: 36px;
  padding: 0 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.35);
  color: var(--text);
  outline: none;
  font-size: 16px; /* 16px keeps iOS from zooming on focus */
  -webkit-user-select: text;
  user-select: text;
}
.toolbar input:focus { border-color: var(--accent); }
.icon-btn {
  flex: none;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.06);
  display: grid;
  place-items: center;
  cursor: pointer;
}
.icon-btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.btn {
  height: 38px;
  padding: 0 18px;
  border-radius: 999px;
  border: 1px solid var(--line-strong);
  background: rgba(255, 255, 255, 0.08);
  cursor: pointer;
  font-weight: 600;
  font-size: 15px;
}
.btn.primary { background: linear-gradient(135deg, var(--accent), #6a5cff); border-color: transparent; }
.scroll { flex: 1; min-height: 0; overflow: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; scrollbar-width: none; }
.scroll::-webkit-scrollbar { display: none; }
.empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 24px;
  text-align: center;
  color: var(--muted);
}
.empty h4 { margin: 0; font-size: 20px; color: var(--text); }
.empty p { margin: 0; max-width: 34em; line-height: 1.45; }
.hint {
  font-size: 13px;
  color: var(--muted);
  padding: 6px 14px;
  border-top: 1px solid var(--line);
  display: flex;
  align-items: center;
  gap: 10px;
}
.hint a { color: var(--accent-2); }

/* Home / launcher */
.home { padding: 18px 20px 16px; gap: 14px; }
.home-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.home-time { font-size: 32px; font-weight: 300; letter-spacing: -0.02em; }
.home-date { color: var(--muted); font-size: 14px; }
.app-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(72px, 1fr));
  gap: 14px 6px;
}
.app-tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
  font-size: 13px;
  color: var(--text);
}
.app-icon {
  width: 54px;
  height: 54px;
  border-radius: 16px;
  display: grid;
  place-items: center;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.25), 0 8px 22px rgba(0, 0, 0, 0.35);
  transition: transform 0.15s;
}
.app-tile:active .app-icon { transform: scale(0.92); }
.app-icon svg { width: 28px; height: 28px; fill: none; stroke: #fff; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.section-label { font-size: 13px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); margin: 6px 0 -6px; }
.running { display: flex; gap: 10px; flex-wrap: wrap; }
.running button {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 14px; border-radius: 999px;
  border: 1px solid var(--line); background: rgba(255, 255, 255, 0.05);
  cursor: pointer; font-size: 14px;
}
.running button.on { border-color: var(--accent); background: rgba(143, 123, 255, 0.18); }

/* Browser */
.browser iframe { flex: 1; width: 100%; border: 0; background: #fff; }
.start-page { padding: 22px; display: flex; flex-direction: column; gap: 16px; }
.start-page h4 { margin: 0; font-size: 22px; }
.quick { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.quick button {
  text-align: left; padding: 14px; border-radius: 16px;
  border: 1px solid var(--line); background: rgba(255, 255, 255, 0.05);
  cursor: pointer;
}
.quick b { display: block; font-size: 15px; }
.quick small { color: var(--muted); }

/* Cinema */
.cinema video, .cinema iframe { flex: 1; width: 100%; min-height: 0; background: #000; border: 0; }
.cinema .stage { flex: 1; display: flex; min-height: 0; background: #000; }

/* Photos */
.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 4px; padding: 4px; }
.photo-grid img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 6px; cursor: pointer; }
.photo-view { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; background: #000; position: relative; }
.photo-view img { max-width: 100%; max-height: 100%; object-fit: contain; }
.photo-view .nav { position: absolute; top: 50%; transform: translateY(-50%); }
.photo-view .nav.prev { left: 12px; }
.photo-view .nav.next { right: 12px; }

/* Notes */
.notes textarea {
  flex: 1; min-height: 0; resize: none; border: 0; outline: none;
  padding: 20px 22px; background: transparent; color: var(--text);
  font-size: 17px; line-height: 1.55;
  -webkit-user-select: text; user-select: text;
}
.notes .meta { margin-left: auto; color: var(--muted); font-size: 13px; }

/* Clock */
.clock { container-type: inline-size; align-items: center; justify-content: center; gap: 3cqw; padding: 4cqw; overflow: hidden; }
.clock .big { font-size: min(110px, 17cqw); font-weight: 200; letter-spacing: -0.03em; font-variant-numeric: tabular-nums; line-height: 1; }
.clock .sub { color: var(--muted); font-size: min(20px, 4cqw); }
.zones { display: grid; grid-template-columns: repeat(4, 1fr); gap: 2cqw; width: 100%; max-width: 760px; }
.zones div { padding: 2cqw 1cqw; border-radius: 12px; background: rgba(255, 255, 255, 0.05); border: 1px solid var(--line); text-align: center; }
.zones b { display: block; font-size: min(24px, 4.2cqw); font-weight: 500; font-variant-numeric: tabular-nums; white-space: nowrap; }
.zones span { color: var(--muted); font-size: min(13px, 2.8cqw); white-space: nowrap; }

/* ---------- HUD ---------- */
#dim {
  position: fixed;
  inset: 0;
  background: #000;
  opacity: 0;
  pointer-events: none;
}

.hud-fade { transition: opacity 0.3s, transform 0.3s; }
body.hud-hidden .hud-fade { opacity: 0; pointer-events: none; }
body.hud-hidden #dock { transform: translate(-50%, 20px); }

#status {
  position: fixed;
  top: calc(var(--safe-t) + 10px);
  left: calc(var(--safe-l) + 12px);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--glass);
  border: 1px solid var(--line);
  font-size: 12px;
  color: var(--muted);
  -webkit-backdrop-filter: blur(16px);
  backdrop-filter: blur(16px);
  cursor: pointer;
}
#status .dot { width: 7px; height: 7px; border-radius: 50%; background: #ffb347; }
#status.live .dot { background: #4ce38a; box-shadow: 0 0 8px #4ce38a; }

#dock {
  position: fixed;
  left: 50%;
  bottom: calc(var(--safe-b) + 12px);
  transform: translateX(-50%);
  display: flex;
  gap: 2px;
  padding: 6px;
  border-radius: 24px;
  background: var(--glass);
  border: 1px solid var(--line);
  -webkit-backdrop-filter: blur(22px) saturate(1.4);
  backdrop-filter: blur(22px) saturate(1.4);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
  max-width: calc(100vw - 24px);
}
#dock button {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  min-width: 60px;
  padding: 7px 6px 5px;
  border: 0;
  border-radius: 18px;
  background: none;
  cursor: pointer;
  font-size: 10.5px;
  color: var(--muted);
}
#dock button:active { background: rgba(255, 255, 255, 0.1); }
#dock svg { width: 22px; height: 22px; fill: currentColor; color: var(--text); }
#dock svg[fill="none"] { fill: none; }

#toast {
  position: fixed;
  left: 50%;
  top: calc(var(--safe-t) + 14px);
  transform: translate(-50%, -16px);
  padding: 9px 18px;
  border-radius: 999px;
  background: var(--glass-strong);
  border: 1px solid var(--line);
  font-size: 14px;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s, transform 0.25s;
  -webkit-backdrop-filter: blur(16px);
  backdrop-filter: blur(16px);
  white-space: nowrap;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Settings sheet ---------- */
#sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
}
#sheet {
  position: fixed;
  left: 50%;
  bottom: 0;
  width: min(560px, 100%);
  max-height: min(86vh, 860px);
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  border-radius: 26px 26px 0 0;
  background: var(--glass-strong);
  border: 1px solid var(--line);
  border-bottom: 0;
  -webkit-backdrop-filter: blur(30px) saturate(1.4);
  backdrop-filter: blur(30px) saturate(1.4);
  box-shadow: 0 -20px 60px rgba(0, 0, 0, 0.5);
  animation: sheet-in 0.28s cubic-bezier(.2, .9, .3, 1);
}
@keyframes sheet-in { from { transform: translate(-50%, 40px); opacity: 0; } }
#sheet[hidden], #sheet-backdrop[hidden], #intro[hidden] { display: none; }
.sheet-grab { width: 40px; height: 5px; border-radius: 3px; background: rgba(255, 255, 255, 0.3); margin: 8px auto 0; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 10px 20px 6px; }
.sheet-head h2 { margin: 0; font-size: 22px; }
.sheet-body {
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 0 16px calc(var(--safe-b) + 24px);
}
.sheet-body h3 { margin: 18px 6px 8px; font-size: 13px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); font-weight: 600; }
.group { border-radius: 16px; background: rgba(255, 255, 255, 0.05); border: 1px solid var(--line); padding: 4px 14px; }
.row { display: flex; align-items: center; gap: 12px; min-height: 48px; border-bottom: 1px solid var(--line); }
.row:last-child { border-bottom: 0; }
.row[hidden] { display: none; }
.row label { flex: 1; font-size: 15px; }
.row input[type="range"] { flex: 1.3; accent-color: var(--accent); }
.row output { width: 46px; text-align: right; color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.note { color: var(--muted); font-size: 13px; line-height: 1.45; margin: 10px 0; }
.note strong { color: var(--text); }
.seg { display: flex; padding: 2px; border-radius: 10px; background: rgba(0, 0, 0, 0.35); }
.seg button {
  border: 0; background: none; padding: 6px 10px; border-radius: 8px; font-size: 13px; cursor: pointer; color: var(--muted);
}
.seg button.on { background: rgba(255, 255, 255, 0.16); color: var(--text); font-weight: 600; }
.pill {
  border: 1px solid var(--line-strong);
  background: rgba(255, 255, 255, 0.08);
  border-radius: 999px;
  padding: 7px 16px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.pill.danger { color: var(--danger); }
.pill:disabled { opacity: 0.5; }

/* ---------- Intro ---------- */
#intro {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  overflow-y: auto;
  padding: calc(var(--safe-t) + 20px) calc(var(--safe-r) + 20px) calc(var(--safe-b) + 20px) calc(var(--safe-l) + 20px);
  background: radial-gradient(ellipse at 30% 20%, rgba(123, 92, 255, 0.28), transparent 60%),
              radial-gradient(ellipse at 80% 90%, rgba(63, 208, 255, 0.18), transparent 60%),
              rgba(5, 4, 15, 0.82);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
}
.intro-card { width: min(380px, 100%); text-align: center; display: flex; flex-direction: column; align-items: center; gap: 12px; }
.intro-logo { width: 96px; height: 96px; border-radius: 24px; box-shadow: 0 16px 50px rgba(123, 92, 255, 0.45); }
.intro-card h1 { margin: 6px 0 0; font-size: 34px; letter-spacing: -0.02em; }
.intro-sub { margin: 0 0 14px; color: var(--muted); line-height: 1.45; }
.cta, .ghost {
  width: 100%;
  height: 52px;
  border-radius: 16px;
  font-size: 17px;
  font-weight: 600;
  cursor: pointer;
}
.cta { border: 0; background: linear-gradient(135deg, var(--accent), #5b6cff); box-shadow: 0 10px 30px rgba(123, 92, 255, 0.4); }
.ghost { border: 1px solid var(--line-strong); background: rgba(255, 255, 255, 0.06); }
.intro-install { font-size: 14px; color: var(--text); background: rgba(255, 255, 255, 0.07); border-radius: 12px; padding: 10px 14px; margin: 8px 0 0; line-height: 1.4; }
.intro-fine { font-size: 12px; color: var(--muted); margin: 6px 0 0; }

/* Phone held sideways: tighten the intro so it fits without scrolling. */
@media (max-height: 500px) {
  .intro-card { gap: 8px; width: min(440px, 100%); }
  .intro-logo { width: 56px; height: 56px; border-radius: 14px; }
  .intro-card h1 { font-size: 24px; margin: 0; }
  .intro-sub { margin: 0 0 4px; font-size: 14px; }
  .cta, .ghost { height: 44px; font-size: 16px; }
  .intro-install { font-size: 13px; padding: 8px 12px; margin: 2px 0 0; }
  #dock button { min-width: 54px; padding: 5px 4px 4px; }
  #dock svg { width: 20px; height: 20px; }
}

@media (prefers-reduced-motion: reduce) {
  #sheet { animation: none; }
  .hud-fade, #toast { transition: none; }
}
