/* Design tokens (SPEC 5.1) */
:root {
  --bg: #0f1115;
  --surface: #181b21;
  --border: #262a33;
  --text: #e8eaee;
  --muted: #8b91a0;
  --accent: #f5b942;
  --danger: #e5484d;
  --radius: 12px;

  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: dark;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

/* Elements with display set in CSS must still honour the hidden attribute. */
[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px; /* >= 16px prevents iOS zoom on input focus */
  line-height: 1.4;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  /* App-like feel: no double-tap zoom, no text selection or long-press callout. */
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

/* Form fields must stay editable/selectable. */
input,
select,
textarea {
  -webkit-user-select: text;
  user-select: text;
}

.app {
  max-width: 480px;
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0 auto;
  padding: env(safe-area-inset-top) calc(16px + env(safe-area-inset-right)) env(safe-area-inset-bottom)
    calc(16px + env(safe-area-inset-left));
}

.muted {
  color: var(--muted);
}

.error {
  color: #ff8a8d; /* light red for inline error text */
}

.center-screen {
  min-height: 60vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  text-align: center;
}

h1 {
  font-size: 22px;
  margin: 0;
}

button {
  font: inherit;
  min-height: 44px;
  padding: 0 16px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  cursor: pointer;
}

button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #15120a;
  font-weight: 600;
}

button:disabled {
  opacity: 0.5;
  cursor: default;
}

/* ---- Forms ---- */
.form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field label {
  font-size: 14px;
  color: var(--muted);
}

.field small {
  font-size: 13px;
}

input,
select,
textarea {
  font: inherit;
  font-size: 16px;
  width: 100%;
  min-height: 48px;
  padding: 0 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--muted);
}

.form button[type='submit'] {
  min-height: 48px;
  margin-top: 8px;
  font-weight: 700;
}

.form-error:empty {
  display: none;
}

.form-error {
  margin: 0;
  font-size: 14px;
}

/* ---- Tabs ---- */
.tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
}

.tab {
  flex: 1;
  border: 0;
  border-radius: 0;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  color: var(--muted);
}

.tab.active {
  border-bottom-color: var(--accent);
  color: var(--text);
  font-weight: 600;
}

/* ---- Login ---- */
.login {
  min-height: 100vh;
  min-height: 100dvh;
  padding: 32px 8px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 32px;
}

.login-head {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.login-head h1 {
  font-size: 28px;
  font-weight: 700;
}

.login-head p {
  margin: 0;
}

/* ---- Top bar ---- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 56px;
}

/* ---- Layout helpers ---- */
.page {
  padding: 16px 4px 32px;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.stack-lg {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.grow {
  flex: 1;
  min-width: 0;
}

.small {
  font-size: 13px;
}

.center {
  text-align: center;
}

.strong {
  font-weight: 600;
}

.mono {
  font-family: var(--mono);
}

h2 {
  font-size: 18px;
  margin: 0;
}

.section-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
}

.label {
  font-size: 14px;
  color: var(--muted);
}

.notice {
  margin: 0;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  text-align: center;
}

textarea {
  padding: 12px 14px;
  min-height: 84px;
  resize: none;
}

/* ---- Top bar ---- */
.topbar.bordered {
  gap: 4px;
  margin: 0 -16px;
  padding: 8px 8px;
  border-bottom: 1px solid var(--border);
  justify-content: flex-start;
}

.topbar-title {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.topbar-title h1 {
  font-size: 18px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.icon-btn {
  width: 44px;
  min-width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text);
}

.dot-anchor {
  position: relative;
}

.dot {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--accent);
}

.dot.static {
  position: static;
  display: inline-block;
}

/* ---- Buttons ---- */
button.full {
  width: 100%;
  min-height: 48px;
  font-weight: 700;
}

button.danger {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
  font-weight: 600;
}

button.danger-outline {
  border-color: var(--danger);
  color: #ff8a8d;
}

.small-btn {
  min-height: 40px;
  padding: 0 12px;
  font-size: 14px;
  white-space: nowrap;
}

.pill-btn {
  border-radius: 999px;
  padding: 0 20px;
  color: var(--muted);
  background: var(--bg);
  font-size: 14px;
}

button svg {
  vertical-align: middle;
}

/* ---- Chips (create form) ---- */
.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  min-width: 52px;
  background: var(--surface);
  font-size: 15px;
}

.chip.selected {
  background: var(--accent);
  border-color: var(--accent);
  color: #15120a;
  font-weight: 700;
}

.chips.two .chip {
  flex: 1;
}

/* ---- Cards & lists ---- */
.card {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-align: left;
}

.card.row {
  flex-direction: row;
  align-items: center;
}

.card.faded {
  opacity: 0.6;
}

.card-btn {
  width: 100%;
  height: auto;
}

.invite {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 2px;
}

.list-row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 52px;
  padding: 4px 0;
  border-bottom: 1px solid var(--border);
}

.role-tag {
  font-size: 12px;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--muted);
  white-space: nowrap;
}

.role-tag.owner,
.role-tag.admin {
  border-color: var(--accent);
  color: var(--accent);
}

.avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--surface);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  flex: none;
}

/* ---- Bottom sheet ---- */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 10;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.28s ease;
}

.sheet-backdrop.open {
  opacity: 1;
}

.sheet-backdrop.closing {
  pointer-events: none;
}

.sheet {
  transform: translateY(100%);
  transition: transform 0.28s cubic-bezier(0.2, 0.8, 0.2, 1);
  will-change: transform;
  width: 100%;
  max-width: 480px;
  max-height: 92vh;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-bottom: 0;
  border-radius: 16px 16px 0 0;
  padding: 8px 20px calc(20px + env(safe-area-inset-bottom));
}

.sheet-handle {
  width: 36px;
  height: 4px;
  border-radius: 2px;
  background: var(--border);
  margin: 0 auto 16px;
}

.sheet input,
.sheet textarea,
.sheet .avatar {
  background: var(--bg);
}

/* Open: slide up. Closing uses a faster ease-in so it feels snappy. */
.sheet-backdrop.open .sheet {
  transform: none;
}

.sheet-backdrop.closing .sheet {
  transition-timing-function: cubic-bezier(0.4, 0, 1, 1);
}

@media (prefers-reduced-motion: reduce) {
  .sheet-backdrop,
  .sheet {
    transition: none;
  }
}

/* ---- Screen transitions (router.js animates #app) ---- */
/* The incoming screen slides in from the side; don't let it widen the page meanwhile. */
body {
  overflow-x: clip;
}

/* ---- Timeline (space screen) ---- */
.timeline {
  position: relative;
  padding-top: 8px;
}

.timeline-line {
  position: absolute;
  left: 50%;
  top: 0;
  bottom: 0;
  width: 2px;
  margin-left: -1px;
  background: var(--border);
}

.day {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.day + .day {
  margin-top: 40px;
}

.day-head {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.day-date,
.day-code,
.checked-in {
  background: var(--bg);
  padding: 0 8px;
}

/* The date is the headline of each day (no pill); today is a yellow pill. */
.day-date {
  font-size: 26px;
  font-weight: 700;
  line-height: 1.2;
}

.timeline .day-date {
  background: none;
  border-radius: 0;
  padding: 0 8px;
  color: var(--muted);
  text-shadow: 0 0 8px var(--bg), 0 0 4px var(--bg);
}

.timeline .day-date.today {
  font-size: 30px;
  background: var(--accent);
  color: #15120a;
  border-radius: 999px;
  padding: 4px 18px;
  text-shadow: none;
}

.day-code {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.code {
  font-family: var(--mono);
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 3px;
  color: var(--muted);
}

.code.big {
  font-size: 18px;
  letter-spacing: 4px;
  color: var(--text);
}

.checked-in {
  margin: 0;
  color: var(--accent);
  font-weight: 600;
}

.day-chips {
  width: 100%;
  display: flex;
  gap: 28px;
}

.day-chips .col {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.day-chips .left {
  align-items: flex-end;
}

.day-chips .right {
  align-items: flex-start;
}

.chip-name {
  max-width: 100%;
  min-height: 40px;
  border-radius: 999px;
  padding: 0 12px;
  background: var(--surface);
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 15px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chip-name.mine {
  border-color: var(--accent);
  font-weight: 600;
}

/* Past days and own chips are plain labels, not buttons. */
.chip-name.static {
  cursor: default;
}

.chip-wrap {
  position: relative;
  display: inline-flex;
  max-width: 100%;
}

/* Shield that pops up above a chip of today; tap it to verify. */
.shield-bubble {
  position: absolute;
  left: 50%;
  bottom: calc(100% + 8px);
  z-index: 5;
  width: 52px;
  height: 52px;
  margin-left: -26px;
  border-radius: 50%;
  background: none;
  border: none;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  filter: drop-shadow(0 6px 10px rgba(0, 0, 0, 0.55));
  animation: shield-pop 0.32s cubic-bezier(0.34, 1.56, 0.64, 1) both, shield-float 1.6s ease-in-out 0.32s infinite;
}

/* While a badge is open, everything else on the timeline steps back. */
.timeline .day,
.timeline .chip-wrap {
  transition: opacity 0.2s ease;
}

.timeline.verifying .day:not(.active-day),
.timeline.verifying .active-day > :not(.day-chips),
.timeline.verifying .chip-wrap:not(.active) {
  opacity: 0.3;
}

.chip-wrap.active {
  z-index: 4;
}

.chip-wrap.active .chip-name {
  box-shadow: 0 0 0 2px var(--accent);
}

/* Pulsing gold glow behind the badge. */
.shield-glow {
  position: absolute;
  inset: -14px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(245, 185, 66, 0.55) 0%, rgba(245, 185, 66, 0) 70%);
  animation: shield-glow 1.4s ease-in-out infinite;
  pointer-events: none;
  z-index: -1;
}

.shield-bubble .verify-icon {
  position: relative;
}

.shield-hint {
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  white-space: nowrap;
  font-size: 12px;
  font-weight: 600;
  color: #15120a;
  background: var(--accent);
  border-radius: 999px;
  padding: 3px 10px;
}

.plus-one {
  position: absolute;
  right: 6px;
  bottom: 100%;
  font-weight: 800;
  font-size: 18px;
  color: var(--accent);
  pointer-events: none;
  animation: plus-one 0.9s ease-out forwards;
}

@keyframes shield-glow {
  0%, 100% { transform: scale(0.85); opacity: 0.6; }
  50% { transform: scale(1.15); opacity: 1; }
}

@keyframes plus-one {
  from { opacity: 1; transform: translateY(0) scale(0.8); }
  to { opacity: 0; transform: translateY(-36px) scale(1.2); }
}

.shield-bubble.done {
  opacity: 0.55;
  animation: shield-pop 0.32s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

.shield-bubble.note {
  width: max-content;
  max-width: 220px;
  height: auto;
  margin-left: 0;
  transform: translateX(-50%);
  padding: 8px 12px;
  border-radius: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: 13px;
  color: var(--muted);
  white-space: normal;
  text-align: center;
  animation: none;
}

.shield-bubble.burst {
  animation: shield-burst 0.4s ease-out forwards;
}

@keyframes shield-pop {
  from { opacity: 0; transform: translateY(14px) scale(0.3); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes shield-float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-4px); }
}

@keyframes shield-burst {
  0% { transform: scale(1); opacity: 1; }
  40% { transform: scale(1.35); opacity: 1; background: var(--accent); }
  100% { transform: translateY(-16px) scale(0.6); opacity: 0; }
}

.shield-count {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  color: var(--accent);
  font-size: 13px;
  font-weight: 700;
}
.shield-count.off {
  color: var(--muted);
}

/* Past day: collapsed to a dot on the line with the date beside it; tap to expand. */
.day.past {
  gap: 0;
}

.day-toggle {
  position: relative;
  width: 100%;
  min-height: 32px;
  padding: 0;
  border: none;
  border-radius: 0;
  background: none;
}

.day-dot {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 14px;
  height: 14px;
  margin: -10px 0 0 -10px;
  border: 3px solid var(--bg);
  border-radius: 50%;
  box-sizing: content-box;
  background: var(--muted);
  transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.day-dot.on {
  background: var(--accent);
}

.day-label {
  position: absolute;
  left: calc(50% + 18px);
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  font-size: 16px;
  font-weight: 600;
  white-space: nowrap;
  background: rgba(15, 17, 21, 0.85);
  border-radius: 8px;
  padding: 2px 8px;
  transition: color 0.2s ease;
}

.day.past.open .day-dot {
  transform: scale(1.3);
}

.day.past.open .day-label {
  color: var(--text);
}

/* Height animates via grid rows 0fr -> 1fr (no JS measuring). */
.day-detail {
  display: grid;
  grid-template-rows: 0fr;
  width: 100%;
  transition: grid-template-rows 0.32s ease;
}

.day.past.open .day-detail {
  grid-template-rows: 1fr;
}

.day-detail-inner {
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.day-detail-inner > .day-code {
  margin-top: 10px;
}

.day-detail .day-code {
  opacity: 0;
  transform: translateY(-6px);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.day.past.open .day-detail .day-code {
  opacity: 1;
  transform: none;
  transition-delay: 0.08s;
}

/* Chips slide out from the line, one after another. */
.day-detail .chip-wrap {
  opacity: 0;
  transition: opacity 0.15s ease, transform 0.15s ease;
}

.day-detail .left .chip-wrap {
  transform: translateX(14px) scale(0.9);
}

.day-detail .right .chip-wrap {
  transform: translateX(-14px) scale(0.9);
}

.day.past.open .day-detail .chip-wrap {
  opacity: 1;
  transform: none;
  transition: opacity 0.25s ease, transform 0.3s cubic-bezier(0.34, 1.4, 0.64, 1);
  transition-delay: calc(0.1s + var(--i, 0) * 35ms);
}

@media (prefers-reduced-motion: reduce) {
  .day-dot,
  .day-label,
  .day-detail,
  .day-detail .day-code,
  .day-detail .chip-wrap {
    transition: none !important;
  }
}

.timeline-more {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-top: 32px;
}

.error:empty {
  display: none;
}

.stack > p,
.day > p {
  margin: 0;
}

.card p,
.card h2 {
  margin: 0;
}

.stack-sm {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.tiny {
  font-size: 12px;
}

.accent {
  color: var(--accent);
}

.link-btn {
  border: 0;
  background: none;
  color: var(--muted);
  text-decoration: underline;
  font-size: 15px;
}

/* ---- Home ---- */
/* Home fits one screen: no vertical scroll or bounce (the carousel scrolls sideways). */
html:has(.home),
html:has(.home) body {
  overflow: hidden;
  overscroll-behavior: none;
}

.home {
  height: 100vh;
  height: calc(100dvh - env(safe-area-inset-top) - env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
}

.home-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-top: 20px;
}

.home-head h1 {
  font-size: 24px;
}

.profile-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  padding: 4px 4px 4px 14px;
  border-radius: 999px;
  background: var(--surface);
  font-size: 15px;
}

.profile-name {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 160px;
}

.avatar.sm {
  width: 36px;
  height: 36px;
  font-size: 15px;
  background: var(--border);
  border: 0;
}

.avatar.lg {
  width: 72px;
  height: 72px;
  font-size: 28px;
  background: var(--border);
  border: 0;
}

.home-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.home-carousel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  padding-bottom: 24px;
}

.carousel {
  align-self: stretch;
  margin: 0 -16px;
  display: flex;
  gap: 12px;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  /* Side padding lets the first/last card sit in the centre. */
  padding: 16px calc(50% - 120px);
  scrollbar-width: none;
  outline: none;
}

.carousel::-webkit-scrollbar {
  display: none;
}

.hcard {
  flex: none;
  width: 240px;
  /* Shrinks on short screens so Home never needs a vertical scroll. */
  height: min(380px, calc(100dvh - 230px - env(safe-area-inset-top) - env(safe-area-inset-bottom)));
  min-height: 240px;
  scroll-snap-align: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  cursor: pointer;
  transform-origin: center;
}

.hcard.pending {
  justify-content: center;
  gap: 8px;
  cursor: default;
  border-style: dashed;
}

.hcard.new {
  background: transparent;
  border-style: dashed;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.hcard .plus {
  font-size: 32px;
  line-height: 1;
}

.hcard-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 28px;
}

/* Small round role badge, top right (crown = owner, shield = admin, lock = solo). */
.hcard-badge {
  width: 28px;
  height: 28px;
  margin-left: auto;
  flex: none;
  border-radius: 50%;
  border: 1px solid var(--accent);
  color: var(--accent);
  background: rgba(15, 17, 21, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
}

.hcard-badge.muted {
  border-color: var(--border);
  color: var(--muted);
}

.pending-note {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
}

.hcard-name {
  margin-top: 8px;
  font-size: 22px;
  font-weight: 700;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

/* Footer: "X/Y" + today's sticker on one row, progress bar below. */
.hcard-foot {
  position: relative; /* above the cover layer */
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.hcard-foot-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 30px;
}

.hcard-count {
  font-size: 15px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.progress {
  height: 4px;
  border-radius: 2px;
  background: var(--border);
}

.progress-bar {
  height: 4px;
  border-radius: 2px;
  background: var(--accent);
}

/* Today's sticker: outline (not yet), white (checked in), gold (verified). */
.hcard-sticker {
  width: 30px;
  height: 30px;
  display: block;
  flex: none;
}

.dots {
  display: flex;
  gap: 8px;
}

.dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--border);
}

.dots span.on {
  background: var(--accent);
}

/* ---- Home: honeycomb layout (Profile → Home layout) ---- */
.home-hive {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding-bottom: 24px;
}

/* Own pan (finger / mouse / trackpad) instead of native scroll: free 2D, momentum. */
.hive-vp {
  position: relative;
  align-self: stretch;
  flex: 1;
  min-height: 240px;
  margin: 0 -16px;
  overflow: hidden;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  cursor: grab;
}

.hive-vp.dragging {
  cursor: grabbing;
}

.hive-plane {
  position: absolute;
  left: 0;
  top: 0;
  will-change: transform;
}

.hive-bubble {
  position: absolute;
  width: 96px;
  height: 96px;
  margin: -48px 0 0 -48px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: none;
  color: var(--text);
  will-change: transform;
  -webkit-tap-highlight-color: transparent;
}

.hive-bubble.pending {
  filter: opacity(0.45);
}

.hive-ring {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
}

.hive-ring .track {
  stroke: var(--border);
}

.hive-ring .bar {
  stroke: var(--accent);
}

/* Cover photo centred and cropped to the circle; no cover → the initial. */
.hive-face {
  position: absolute;
  inset: 7px;
  border-radius: 50%;
  overflow: hidden;
  background: var(--surface);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 30px;
  font-weight: 700;
  color: var(--muted);
}

.hive-face img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
  display: block;
}

.hive-bubble.new .hive-face {
  border: 1.5px dashed var(--muted);
  font-size: 36px;
  font-weight: 400;
}

/* Today's state: a dot on the arc tip (limited) or top right (unlimited). */
.hive-dot {
  position: absolute;
  right: 4px;
  top: 4px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 2px solid var(--bg);
}

.hive-dot[style*='left'] {
  right: auto;
}

.hive-dot.todo {
  background: var(--bg);
  box-shadow: inset 0 0 0 2px var(--muted);
}

.hive-dot.done {
  background: var(--text);
}

.hive-dot.verified {
  background: var(--accent);
}

/* Unlimited: no arc; the day (or week) number sits on the bottom of the ring. */
.hive-count {
  position: absolute;
  left: 50%;
  bottom: -4px;
  transform: translateX(-50%);
  min-width: 28px;
  height: 20px;
  padding: 0 7px;
  border-radius: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: 12px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  display: flex;
  align-items: center;
  justify-content: center;
}

.hive-caption {
  min-height: 44px;
  text-align: center;
  padding: 0 16px;
}

.hive-cap-name {
  font-size: 17px;
  font-weight: 700;
}

.hive-cap-meta {
  margin-top: 2px;
}

/* Profile: Home layout picker (two tiles with a tiny picture each). */
.layout-opts {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.layout-opt {
  min-height: 88px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 14px;
}

.layout-opt.selected {
  border-color: var(--accent);
  color: var(--accent);
}

.layout-mini {
  height: 36px;
  display: flex;
  align-items: center;
  gap: 3px;
}

.layout-mini i {
  background: var(--border);
}

.layout-mini.cards i {
  width: 16px;
  height: 28px;
  border-radius: 4px;
}

.layout-mini.cards i:nth-child(2) {
  width: 22px;
  height: 36px;
  background: currentColor;
  opacity: 0.8;
}

.layout-mini.hive {
  display: grid;
  grid-template-columns: repeat(3, 11px);
  justify-content: center;
}

.layout-mini.hive i {
  width: 11px;
  height: 11px;
  border-radius: 50%;
}

/* 7 dots: rows of 2 / 3 / 2, the middle one highlighted. */
.layout-mini.hive i:nth-child(1),
.layout-mini.hive i:nth-child(6) {
  grid-column: 1;
  transform: translateX(7px);
}

.layout-mini.hive i:nth-child(3) {
  grid-column: 1;
}

.layout-mini.hive i:nth-child(2),
.layout-mini.hive i:nth-child(7) {
  transform: translateX(7px);
}

.layout-mini.hive i:nth-child(4) {
  background: currentColor;
  opacity: 0.8;
}

/* ---- Loading skeleton (space screen) ---- */
.skel {
  display: block;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--surface) 0%, #222630 50%, var(--surface) 100%);
  background-size: 200% 100%;
  animation: skel-shine 1.4s ease-in-out infinite;
}

@keyframes skel-shine {
  from {
    background-position: 100% 0;
  }
  to {
    background-position: -100% 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .skel {
    animation: none;
  }
}

.skel-title {
  display: inline-block;
  width: 140px;
  height: 20px;
  vertical-align: middle;
}

.skel-center {
  position: relative;
  display: flex;
  justify-content: center;
  margin-bottom: 16px;
}

.skel-streak {
  width: 150px;
  height: 36px;
}

.skel-date {
  width: 200px;
  height: 46px;
  background: rgba(245, 185, 66, 0.25);
  animation: none;
}

.skel-label {
  width: 190px;
  height: 14px;
}

.skel-label.short {
  width: 120px;
}

.skel-code {
  width: 130px;
  height: 22px;
}

.skel-chip {
  width: 96px;
  height: 40px;
}

/* Past days: a dot on the line + the date to its right. */
.skel-past {
  position: relative;
  height: 30px;
  margin-top: 34px;
}

.skel-dot {
  position: absolute;
  left: 50%;
  top: 9px;
  width: 12px;
  height: 12px;
  margin-left: -6px;
}

.skel-day {
  position: absolute;
  left: calc(50% + 16px);
  top: 5px;
  width: 80px;
  height: 20px;
}

/* ---- Circle transition layer (router reveal / conceal) ---- */
.screen-layer {
  position: fixed;
  inset: 0;
  z-index: 40;
  overflow: hidden;
  background:
    linear-gradient(rgba(15, 17, 21, 0.35), rgba(15, 17, 21, 0.35)),
    url('/img/bg.webp') center / cover no-repeat,
    var(--bg);
}

/* ---- Profile sheet ---- */
.sheet.tall {
  min-height: calc(100vh - 56px);
  min-height: calc(100dvh - 56px);
  border-radius: 20px 20px 0 0;
}

.sheet-close-row {
  display: flex;
  justify-content: flex-end;
  margin-top: -8px;
}

.sheet-close-row .link-btn {
  text-decoration: none;
}

.profile-display {
  font-size: 20px;
  font-weight: 700;
}

.stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.stat {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.stat-value {
  font-size: 22px;
  font-weight: 700;
}

.space-row {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 64px;
  height: auto;
  padding: 10px 14px;
  background: var(--bg);
  text-align: left;
}

.streaks {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
  font-size: 13px;
  white-space: nowrap;
}

.streaks b {
  color: var(--text);
}

.streaks b.accent {
  color: var(--accent);
}

.chips.three .chip {
  flex: 1;
  padding: 0 8px;
}

.logout-btn {
  min-height: 48px;
  color: var(--danger);
}

.hcard.is-center:not(.new):not(.pending) {
  border-color: var(--accent);
}

/* ---- Space cover image ---- */
.cover-layer {
  position: absolute;
  inset: 0;
  overflow: hidden;
  border-radius: inherit;
  pointer-events: none;
}

.cover-layer img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* Dark overlay keeps text readable on any photo. */
.cover-layer::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(15, 17, 21, 0.55) 0%, rgba(15, 17, 21, 0.75) 60%, rgba(15, 17, 21, 0.9) 100%);
}

.hcard {
  position: relative;
}

.hcard > .stack-sm {
  position: relative; /* above the cover layer */
}

.space-screen {
  position: relative;
}

.space-screen > * {
  position: relative;
  z-index: 1;
}

.cover-preview {
  /* Same shape as the Home card (240x380), so the crop matches what the card shows. */
  position: relative;
  width: 160px;
  aspect-ratio: 240 / 380;
  margin: 0 auto;
  border-radius: 16px;
  border: 1px dashed var(--border);
  background: var(--surface);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

.cover-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* Labels sit on the timeline line (and maybe a cover photo): rounded translucent pills. */
.day-date,
.day-code,
.checked-in {
  background: rgba(15, 17, 21, 0.85);
  border-radius: 8px;
  padding: 2px 10px;
}

/* Streak button + heatmap above today (my check-ins in this space). */
.streak-block {
  position: relative;
  margin-bottom: 16px;
}

.streak-row {
  display: flex;
  justify-content: center;
}

.streak-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 36px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
}

.streak-btn[aria-expanded='true'] {
  border-color: var(--accent);
}

.streak-flame {
  display: inline-flex;
  color: var(--accent);
}

.streak-chev {
  display: inline-flex;
  color: var(--muted);
  transition: transform 0.2s;
}

.streak-btn[aria-expanded='true'] .streak-chev {
  transform: rotate(180deg);
}

/* Height animates via grid rows 0fr -> 1fr, like .day-detail. */
.heatmap-wrap {
  display: grid;
  grid-template-rows: 0fr;
  transition: grid-template-rows 0.28s ease;
}

.heatmap-wrap.open {
  grid-template-rows: 1fr;
}

.heatmap-clip {
  overflow: hidden;
  min-height: 0;
}

.heatmap {
  margin-top: 12px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.heatmap-stats {
  display: flex;
  margin-bottom: 14px;
}

.heatmap-stat {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.heatmap-stat b {
  font-size: 20px;
}

.heatmap-stat span {
  font-size: 11px;
  color: var(--muted);
}

.heatmap-grid {
  display: flex;
  justify-content: center;
  gap: 6px;
}

.heatmap-dow,
.heatmap-col {
  display: grid;
  grid-template-rows: 14px repeat(7, 16px);
  gap: 3px;
  flex: none;
}

.heatmap-dow {
  font-size: 9px;
  line-height: 16px;
  color: var(--muted);
}

.heatmap-cols {
  display: flex;
  gap: 3px;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: none;
  padding: 0 3px 3px; /* room for today's outline */
}

.heatmap-month {
  width: 16px;
  font-size: 9px;
  color: var(--muted);
  white-space: nowrap;
}

.heat-cell {
  width: 16px;
  height: 16px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg);
  opacity: 0;
  transform: scale(0.6);
}

.heatmap-wrap.open .heat-cell {
  animation: heat-pop 0.25s ease forwards;
  animation-delay: calc(var(--i, 0) * 6ms);
}

@keyframes heat-pop {
  to {
    opacity: 1;
    transform: none;
  }
}

.heat-cell.empty {
  visibility: hidden;
}

.heat-cell.future {
  border-style: dashed;
  background: transparent;
}

.heat-cell.l1 {
  border-color: transparent;
  background: rgba(245, 185, 66, 0.45);
}

.heat-cell.l2 {
  border-color: transparent;
  background: var(--accent);
}

.heat-cell.today {
  outline: 2px solid var(--text);
  outline-offset: 1px;
}

@media (prefers-reduced-motion: reduce) {
  .heatmap-wrap,
  .streak-chev {
    transition: none;
  }

  .heatmap-wrap.open .heat-cell {
    animation: none;
    opacity: 1;
    transform: none;
  }
}

/* ---- Solo + weekly challenges (SPEC 16) ---- */
.with-icon {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

/* Create: group / solo picker */
.pick {
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-height: calc(100dvh - 120px);
}

.pick-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 24px;
  border-radius: 16px;
  background: var(--surface);
  text-align: center;
}

.pick-btn:hover,
.pick-btn:focus-visible {
  border-color: var(--accent);
}

.pick-icon {
  display: inline-flex;
  color: var(--accent);
}

.pick-btn b {
  font-size: 24px;
}

.pick-btn .muted {
  max-width: 260px;
  line-height: 1.5;
}

/* Create: chips with a second line, chips sharing one row */
.chip.tall {
  min-height: 60px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
}

.chip.tall small {
  font-size: 12px;
  font-weight: 400;
  opacity: 0.75;
}

.chips.fill {
  flex-wrap: nowrap;
}

.chips.fill .chip {
  flex: 1;
  min-width: 0;
  padding: 0;
}

/* Weekly: session count on a timeline chip ("2/4") */
.week-count {
  color: var(--muted);
  font-size: 12px;
  font-weight: 400;
}

/* Weekly: "this week" card above today */
.week-card {
  position: relative;
  width: 260px;
  margin: 0 auto 18px;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.week-card-line {
  font-size: 13px;
  color: var(--muted);
  text-align: center;
}

.week-card-line b {
  color: var(--text);
  font-size: 15px;
}

.week-card-line b.accent {
  color: var(--accent);
}

.week-days {
  display: flex;
  gap: 6px;
}

.week-day-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  font-size: 10px;
  color: var(--muted);
}

.week-day {
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--bg);
  font-size: 12px;
}

.week-day.done {
  border-color: var(--accent);
  background: var(--accent);
  color: #15120a;
  font-weight: 700;
}

.week-day.future {
  border-style: dashed;
  background: transparent;
}

.week-day.today {
  outline: 2px solid var(--text);
  outline-offset: 1px;
}

.week-segs {
  width: 100%;
  display: flex;
  gap: 4px;
}

.week-segs span {
  flex: 1;
  height: 4px;
  border-radius: 2px;
  background: var(--border);
}

.week-segs span.on {
  background: var(--accent);
}

/* Weekly: week label on the timeline line between past weeks */
.week-sep {
  position: relative;
  display: flex;
  justify-content: center;
  margin-top: 40px;
}

.week-sep + .day {
  margin-top: 16px;
}

.week-sep span {
  padding: 3px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg);
  color: var(--muted);
  font-size: 12px;
}

.week-sep span.met {
  border-color: var(--accent);
  color: var(--accent);
}

/* Weekly heatmap: extra row for the met / missed bar above each column */
.heatmap-grid.weekly .heatmap-dow,
.heatmap-grid.weekly .heatmap-col {
  grid-template-rows: 14px 6px repeat(7, 16px);
}

.heat-week {
  width: 16px;
  height: 4px;
  align-self: center;
  border-radius: 2px;
}

.heat-week.ok {
  background: var(--accent);
}

.heat-week.miss {
  background: var(--border);
}

/* Create: custom start date / week picker */
input[type='date'] {
  -webkit-appearance: none;
  appearance: none;
  display: flex;
  align-items: center;
  color-scheme: dark;
}

select {
  color-scheme: dark;
}

.cover-preview + .row {
  justify-content: center;
}

/* ---- App background + fixed navigation ---- */
/* Background photo, fixed behind every screen (a fixed layer, since iOS ignores
   background-attachment: fixed). Dimmed so text and cards stay readable. */
body {
  background: transparent;
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background:
    linear-gradient(rgba(15, 17, 21, 0.35), rgba(15, 17, 21, 0.35)),
    url('/img/bg.webp') center / cover no-repeat,
    var(--bg);
}

/* Headers stay put while the page scrolls; they also cover the notch area. */
.topbar.bordered,
.home-head {
  position: sticky;
  top: 0;
  z-index: 5;
  margin-top: calc(-1 * env(safe-area-inset-top));
  background: rgba(15, 17, 21, 0.82);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
}

.topbar.bordered {
  padding-top: calc(8px + env(safe-area-inset-top));
}

.home-head {
  margin-left: -16px;
  margin-right: -16px;
  padding: calc(20px + env(safe-area-inset-top)) 16px 12px;
}

/* Space screen: the header sits in a wrapper, so the wrapper is what sticks. */
.space-screen > .space-head {
  position: sticky;
  top: 0;
  z-index: 5;
}

.space-head .topbar.bordered {
  position: static;
}

/* Checkbox + label on one line (edit space: minimum verifies). */
.check-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.check-row input[type='checkbox'] {
  width: 18px;
  height: 18px;
  margin: 0;
  flex: none;
  accent-color: var(--accent);
}

/* Profile: verified email line (long addresses wrap) */
.email-line {
  min-width: 0;
  gap: 6px;
}
.email-line .strong {
  overflow-wrap: anywhere;
}

/* 6-digit email code */
.code-input {
  font-size: 22px;
  letter-spacing: 6px;
  text-align: center;
}
.code-links {
  justify-content: space-between;
}
