:root {
  --bg: #000;
  --fg: #f5f5f7;
  --muted: rgba(235, 235, 245, 0.6);
  --faint: rgba(235, 235, 245, 0.3);
  --glass: rgba(44, 44, 46, 0.62);
  --hair: rgba(255, 255, 255, 0.09);
  --green: #30d158;
  --red: #ff453a;
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
  --spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --sa-top: env(safe-area-inset-top, 0px);
  --sa-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--fg); overflow: hidden; overscroll-behavior: none; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", "Helvetica Neue", Inter, system-ui, sans-serif;
  -webkit-font-smoothing: antialiased; touch-action: none; user-select: none; -webkit-user-select: none;
}
button { font: inherit; color: inherit; }

/* ---- the backdrop: a soft glow of the group you're in ---- */
#backdrop {
  position: fixed; inset: -20%; pointer-events: none; opacity: 0; transition: opacity 0.7s var(--ease);
  background: radial-gradient(60% 45% at 50% 45%, var(--tint, #222) 0%, transparent 70%);
  filter: saturate(1.2);
}
#backdrop.on { opacity: 0.22; }

/* ---- header ---- */
#top {
  position: fixed; z-index: 5; left: 0; right: 0; top: 0; display: flex; align-items: center; gap: 12px;
  padding: calc(var(--sa-top) + 14px) 20px 10px; pointer-events: none;
}
#top > * { pointer-events: auto; }
#titles { flex: 1; min-width: 0; }
#eyebrow { margin: 0; font-size: 13px; font-weight: 600; letter-spacing: 0.02em; color: var(--muted); text-transform: uppercase; transition: opacity 0.4s var(--ease); }
#title { margin: 0; font-size: 34px; font-weight: 700; letter-spacing: -0.02em; line-height: 1.1; }
#title.swap { animation: title-in 0.55s var(--ease); }
@keyframes title-in { from { opacity: 0; transform: translateY(8px); filter: blur(6px); } to { opacity: 1; transform: none; filter: none; } }
#clock { font-variant-numeric: tabular-nums; font-size: 17px; font-weight: 600; color: var(--muted); }
.glass-btn {
  width: 40px; height: 40px; border-radius: 50%; border: 0; display: grid; place-items: center; cursor: pointer;
  background: var(--glass); -webkit-backdrop-filter: blur(20px) saturate(1.6); backdrop-filter: blur(20px) saturate(1.6);
  box-shadow: inset 0 0 0 0.5px var(--hair); transition: transform 0.25s var(--spring);
}
.glass-btn:active { transform: scale(0.88); }
.glass-btn svg { width: 22px; height: 22px; stroke: #fff; fill: none; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
#back { animation: pop-in 0.45s var(--spring); }
@keyframes pop-in { from { transform: scale(0.4); opacity: 0; } }

/* ---- the field of bubbles ---- */
#stage { position: fixed; inset: 0; cursor: grab; }
#stage.dragging { cursor: grabbing; }
#field { position: absolute; left: 50%; top: 52%; width: 0; height: 0; transform-origin: 0 0; }

.bubble {
  position: absolute; left: 0; top: 0; width: var(--d); height: var(--d); margin: calc(var(--d) / -2) 0 0 calc(var(--d) / -2);
  border: 0; padding: 0; border-radius: 50%; cursor: pointer; will-change: transform, opacity;
  /* flat colour, like the watch: a whisper of a gradient, no gloss, no glow */
  background: linear-gradient(180deg, var(--c1) 0%, color-mix(in srgb, var(--c1) 70%, var(--c2)) 100%);
  display: grid; place-items: center;
}
.bubble svg { width: 44%; height: 44%; stroke: #fff; fill: none; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; pointer-events: none; }
.bubble .label {
  position: absolute; top: calc(100% + 7px); left: 50%; transform: translateX(-50%); white-space: nowrap;
  font-size: 12.5px; font-weight: 600; letter-spacing: -0.005em; color: var(--fg); pointer-events: none;
}
.bubble .dot {
  position: absolute; right: 4%; bottom: 4%; width: 22%; height: 22%; min-width: 12px; min-height: 12px; border-radius: 50%;
  background: var(--green); box-shadow: 0 0 0 3px #000; transform: scale(0); transition: transform 0.45s var(--spring), background 0.3s;
}
.bubble .dot.on { transform: scale(1); }
.bubble .dot.down { background: var(--red); animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 3px #000, 0 0 0 7px rgba(255, 69, 58, 0.35); } }
.bubble .badge {
  position: absolute; right: -2%; top: -2%; min-width: 24px; height: 24px; padding: 0 7px; border-radius: 12px;
  background: var(--red); color: #fff; font-size: 13px; font-weight: 700; display: grid; place-items: center; box-shadow: 0 0 0 3px #000;
}
.bubble .home { position: absolute; left: 6%; bottom: 6%; width: 20%; height: 20%; min-width: 11px; min-height: 11px; border-radius: 50%;
  background: rgba(0,0,0,0.45); display: grid; place-items: center; }
.bubble .home svg { width: 66%; height: 66%; stroke-width: 2.6; }
.bubble.pressed { filter: brightness(0.82); }

/* the centre of the first screen: everything's health in one ring */
.bubble.health { background: #1c1c1e; }
.bubble svg.health-ring { position: absolute; inset: 5%; width: 90%; height: 90%; transform: rotate(-90deg); filter: none; stroke: none; }
.health-ring circle { fill: none; stroke-width: 6; stroke-linecap: round; }
.health-ring .track { stroke: rgba(255,255,255,0.08); }
.health-ring .val { stroke: var(--green); transition: stroke-dashoffset 1.2s var(--ease), stroke 0.4s; }
.health-text { position: relative; text-align: center; line-height: 1; pointer-events: none; }
.health-text b { display: block; font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.health-text span { font-size: 11px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }

/* ---- going into a group: its ball grows over everything ---- */
#portal {
  position: fixed; left: 0; top: 0; width: 100px; height: 100px; border-radius: 50%; pointer-events: none; z-index: 3; opacity: 0;
  background: linear-gradient(180deg, var(--c1) 0%, color-mix(in srgb, var(--c1) 70%, var(--c2)) 100%);
}

/* ---- opening an app: like iOS, its ball fills the screen ---- */
#launch {
  position: fixed; inset: 0; z-index: 20; display: grid; place-content: center; justify-items: center; gap: 14px; pointer-events: none; opacity: 0;
  background: linear-gradient(180deg, var(--c1) 0%, color-mix(in srgb, var(--c1) 70%, var(--c2)) 100%);
}
#launch-icon svg { width: 84px; height: 84px; stroke: #fff; fill: none; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
#launch-name { margin: 0; font-size: 22px; font-weight: 700; letter-spacing: -0.01em; }

/* ---- status pill ---- */
#pill {
  position: fixed; z-index: 6; left: 50%; bottom: calc(var(--sa-bottom) + 22px); transform: translate(-50%, 0);
  padding: 10px 16px; border-radius: 999px; font-size: 14px; font-weight: 600; white-space: nowrap;
  background: var(--glass); -webkit-backdrop-filter: blur(24px) saturate(1.6); backdrop-filter: blur(24px) saturate(1.6);
  box-shadow: inset 0 0 0 0.5px var(--hair), 0 10px 30px rgba(0,0,0,0.4); display: flex; align-items: center; gap: 8px;
  transition: transform 0.5s var(--spring), opacity 0.4s; opacity: 0;
}
#pill.show { opacity: 1; }
#pill.toast { transform: translate(-50%, -6px) scale(1.04); }
#pill i { width: 8px; height: 8px; border-radius: 50%; background: var(--green); display: inline-block; }
#pill i.down { background: var(--red); }

/* ---- sheets ---- */
#sheet-wrap, #login {
  position: fixed; inset: 0; z-index: 30; display: grid; align-items: end; justify-items: center;
  background: rgba(0, 0, 0, 0.35); -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px); animation: fade-in 0.3s var(--ease);
}
#login { align-items: center; background: rgba(0,0,0,0.6); -webkit-backdrop-filter: blur(30px) saturate(1.4); backdrop-filter: blur(30px) saturate(1.4); }
[hidden] { display: none !important; }
@keyframes fade-in { from { opacity: 0; } }
#sheet {
  width: min(520px, 100%); margin: 0 auto; padding: 10px 24px calc(var(--sa-bottom) + 24px); border-radius: 28px 28px 0 0; text-align: center;
  background: rgba(28, 28, 30, 0.92); box-shadow: inset 0 0.5px 0 var(--hair); animation: sheet-up 0.5s var(--spring);
}
@keyframes sheet-up { from { transform: translateY(100%); } }
.grip { width: 38px; height: 5px; border-radius: 3px; background: rgba(255,255,255,0.22); margin: 0 auto 18px; }
#sheet-icon { width: 76px; height: 76px; margin: 0 auto 12px; border-radius: 50%; display: grid; place-items: center;
  background: linear-gradient(180deg, var(--c1) 0%, color-mix(in srgb, var(--c1) 70%, var(--c2)) 100%); }
#sheet-icon svg { width: 46%; height: 46%; stroke: #fff; fill: none; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
#sheet h2 { margin: 0; font-size: 24px; font-weight: 700; letter-spacing: -0.01em; }
#sheet-sub { margin: 4px 0 0; color: var(--muted); font-size: 15px; }
#sheet-status { margin: 16px 0 0; font-size: 15px; font-weight: 600; }
#sheet-url { margin: 4px 0 20px; font-size: 13px; color: var(--faint); word-break: break-all; }
.sheet-actions { display: flex; gap: 10px; }
.sheet-actions .btn { flex: 1; }
.btn {
  border: 0; border-radius: 14px; padding: 14px 16px; font-size: 16px; font-weight: 600; cursor: pointer;
  background: rgba(118, 118, 128, 0.24); transition: transform 0.25s var(--spring), filter 0.2s;
}
.btn:active { transform: scale(0.96); filter: brightness(0.9); }
.btn.primary { background: #0a84ff; color: #fff; }

#login-form { width: min(340px, calc(100% - 48px)); text-align: center; animation: sheet-up 0.6s var(--spring); }
#login-form.shake { animation: shake 0.45s; }
@keyframes shake { 20%, 60% { transform: translateX(-10px); } 40%, 80% { transform: translateX(10px); } }
#lock { width: 76px; height: 76px; margin: 0 auto 16px; border-radius: 50%; display: grid; place-items: center;
  background: #5e5ce6; }
#lock svg { width: 34px; height: 34px; stroke: #fff; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
#login h2 { margin: 0; font-size: 28px; font-weight: 700; }
#login p { color: var(--muted); margin: 6px 0 20px; font-size: 15px; }
#pw {
  width: 100%; border: 0; outline: 0; border-radius: 14px; padding: 15px 16px; font-size: 17px; color: var(--fg); margin-bottom: 10px;
  background: rgba(118, 118, 128, 0.24); box-shadow: inset 0 0 0 0.5px var(--hair); user-select: text; -webkit-user-select: text;
}
#pw:focus { box-shadow: inset 0 0 0 2px #0a84ff; }
#login .btn { width: 100%; }
#login-err { color: var(--red) !important; min-height: 20px; margin-top: 12px !important; font-size: 14px !important; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
