:root {
  --rose: #e3597a;
  --rose-soft: rgba(227, 89, 122, 0.12);
  --bg: #f2f2f7;
  --card: #ffffff;
  --text: #000000;
  --secondary: rgba(60, 60, 67, 0.6);
  --separator: rgba(60, 60, 67, 0.18);
  --fill: rgba(118, 118, 128, 0.12);
  --material: rgba(249, 249, 249, 0.82);
  --danger: #ff3b30;
  --shadow: 0 4px 18px rgba(0, 0, 0, 0.08);
  --safe-top: env(safe-area-inset-top);
  --safe-bottom: env(safe-area-inset-bottom);
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --rose: #ff6f8f;
    --rose-soft: rgba(255, 111, 143, 0.16);
    --bg: #000000;
    --card: #1c1c1e;
    --text: #ffffff;
    --secondary: rgba(235, 235, 245, 0.6);
    --separator: rgba(84, 84, 88, 0.6);
    --fill: rgba(118, 118, 128, 0.24);
    --material: rgba(30, 30, 30, 0.82);
    --shadow: none;
  }
  .segmented .on, .segmented input:checked + span { background: #636366; }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 17px/1.35 -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
button, input, textarea { font: inherit; color: inherit; }
button { background: none; border: 0; padding: 0; cursor: pointer; }
a { color: inherit; text-decoration: none; }
[hidden] { display: none !important; }

/* ---------- layout */
.view {
  max-width: 720px;
  margin: 0 auto;
  padding: calc(var(--safe-top) + 8px) 16px calc(var(--safe-bottom) + 96px);
}
.topbar {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
}
.topbar .spacer { flex: 1; }
.large-title {
  font-size: 34px;
  font-weight: 700;
  letter-spacing: 0.01em;
  margin: 4px 0 14px;
}
.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--card);
  color: var(--rose);
  box-shadow: var(--shadow);
}
.icon-btn svg { width: 22px; height: 22px; }
.heart { width: 46px; height: 46px; -webkit-touch-callout: none; user-select: none; -webkit-user-select: none; }
.heart img { width: 41px; height: auto; pointer-events: none; }
.heart.beat img { animation: beat 0.45s ease; }
@keyframes beat { 30% { transform: scale(1.35); } 60% { transform: scale(0.9); } }
.back {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  color: var(--rose);
  font-size: 17px;
  height: 44px;
  margin-left: -6px;
}
.back svg { width: 22px; height: 22px; }

/* ---------- tab bar */
.tabbar {
  position: fixed;
  left: 50%;
  bottom: calc(var(--safe-bottom) + 10px);
  transform: translateX(-50%);
  display: flex;
  gap: 4px;
  padding: 5px;
  border-radius: 999px;
  background: var(--material);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.12);
  z-index: 10;
}
.tabbar a {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-width: 92px;
  padding: 7px 16px 6px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text);
}
.tabbar a svg { width: 24px; height: 24px; }
.tabbar a.active { color: var(--rose); background: var(--fill); }

/* ---------- controls */
.segmented {
  display: flex;
  padding: 2px;
  border-radius: 10px;
  background: var(--fill);
  margin-bottom: 18px;
}
.segmented button, .segmented label {
  flex: 1;
  text-align: center;
  padding: 6px 0;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
}
.segmented .on, .segmented input:checked + span {
  background: var(--card);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.12);
}
.segmented label { padding: 0; }
.segmented label span { display: block; padding: 6px 0; border-radius: 8px; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }

.banner {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 12px;
  border-radius: 12px;
  margin-bottom: 14px;
  background: rgba(255, 149, 0, 0.16);
  font-size: 14px;
}

.empty {
  text-align: center;
  color: var(--secondary);
  padding: 70px 20px;
}
.empty svg { width: 54px; height: 54px; opacity: 0.6; }
.empty h3 { color: var(--text); font-size: 20px; margin: 12px 0 4px; }
.empty p { margin: 0; }

.spinner {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 3px solid var(--fill);
  border-top-color: var(--rose);
  animation: spin 0.8s linear infinite;
  margin: 0 auto;
}
.spinner.small { width: 18px; height: 18px; border-width: 2px; margin: 0; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading { padding: 80px 0; }

/* ---------- memories */
.year { font-size: 22px; font-weight: 700; margin: 22px 0 10px; }
.album-card {
  display: block;
  background: var(--card);
  border-radius: 20px;
  overflow: hidden;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
  transition: transform 0.15s ease;
}
.album-card:active { transform: scale(0.98); }
.cover {
  position: relative;
  height: 210px;
  background: var(--rose-soft);
  display: grid;
  place-items: center;
  color: var(--rose);
}
.cover img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.cover > svg { width: 40px; height: 40px; opacity: 0.5; }
.badge {
  position: absolute;
  top: 10px;
  left: 10px;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  background: var(--material);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}
.badge svg { width: 13px; height: 13px; fill: currentColor; }
.badge.inline { position: static; background: var(--card); }
.album-info { padding: 14px; }
.album-info h3 { margin: 0 0 3px; font-size: 20px; font-weight: 600; }
.meta { display: flex; flex-wrap: wrap; gap: 4px 12px; color: var(--secondary); font-size: 15px; }
.meta .place { display: inline-flex; align-items: center; gap: 3px; }
.meta svg { width: 14px; height: 14px; fill: currentColor; }

.album-head { display: flex; flex-direction: column; gap: 10px; margin-bottom: 16px; }
.album-head .row { display: flex; align-items: center; gap: 10px; color: var(--secondary); }
.note {
  background: var(--card);
  border-radius: 14px;
  padding: 14px;
  white-space: pre-wrap;
}
.status { display: flex; align-items: center; gap: 10px; color: var(--secondary); margin-bottom: 12px; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(105px, 1fr));
  gap: 4px;
  margin: 0 -12px;
}
.grid button {
  aspect-ratio: 1;
  border-radius: 6px;
  overflow: hidden;
  background: var(--rose-soft);
  -webkit-touch-callout: none;
  user-select: none;
  -webkit-user-select: none;
}
.grid img { width: 100%; height: 100%; object-fit: cover; display: block; pointer-events: none; }

/* ---------- photo viewer */
.viewer {
  position: fixed;
  inset: 0;
  background: #000;
  z-index: 50;
  animation: fade 0.2s ease;
}
@keyframes fade { from { opacity: 0; } }
.viewer .strip {
  display: flex;
  height: 100%;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  scrollbar-width: none;
}
.viewer .strip::-webkit-scrollbar { display: none; }
.viewer .slide {
  flex: 0 0 100%;
  height: 100%;
  scroll-snap-align: center;
  display: grid;
  place-items: center;
}
.viewer .slide img { max-width: 100%; max-height: 100%; object-fit: contain; }
.viewer .close {
  position: absolute;
  top: calc(var(--safe-top) + 10px);
  right: 14px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.2);
  color: #fff;
  display: grid;
  place-items: center;
}
.viewer .close svg { width: 18px; height: 18px; }
.viewer .caption {
  position: absolute;
  left: 0;
  right: 0;
  bottom: calc(var(--safe-bottom) + 14px);
  text-align: center;
  color: rgba(255, 255, 255, 0.8);
  font-size: 13px;
}

/* ---------- voice */
.intro { color: var(--secondary); margin: -6px 0 16px; }
.clip {
  display: flex;
  gap: 14px;
  align-items: flex-start;
  background: var(--card);
  border-radius: 20px;
  padding: 14px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
  -webkit-touch-callout: none;
  user-select: none;
  -webkit-user-select: none;
}
.play {
  flex: none;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: #fff;
  background: linear-gradient(160deg, #f07592, var(--rose));
  box-shadow: 0 4px 12px rgba(227, 89, 122, 0.35);
  transition: transform 0.12s ease;
}
.play:active { transform: scale(0.94); }
.play svg { width: 24px; height: 24px; fill: currentColor; }
.clip-body { flex: 1; min-width: 0; padding-top: 2px; }
.clip-body h3 { margin: 0; font-size: 17px; font-weight: 600; }
.clip-body p { margin: 2px 0 0; color: var(--secondary); font-size: 15px; white-space: pre-wrap; }
.clip-body .sub { font-size: 13px; color: var(--secondary); margin-top: 4px; }
.scrub { margin-top: 8px; }
.scrub input { width: 100%; accent-color: var(--rose); margin: 0; }
.scrub .times { display: flex; justify-content: space-between; font-size: 12px; color: var(--secondary); font-variant-numeric: tabular-nums; }

/* ---------- sheets */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(0, 0, 0, 0);
  transition: background 0.25s ease;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.sheet-backdrop.open { background: rgba(0, 0, 0, 0.35); }
.sheet {
  position: relative;
  width: 100%;
  max-width: 560px;
  max-height: 92vh;
  overflow-y: auto;
  background: var(--bg);
  border-radius: 14px 14px 0 0;
  padding: 0 16px calc(var(--safe-bottom) + 20px);
  transform: translateY(100%);
  transition: transform 0.3s cubic-bezier(0.2, 0.9, 0.3, 1);
}
.sheet-backdrop.open .sheet { transform: none; }
.sheet-head {
  position: sticky;
  top: 0;
  z-index: 1;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  background: var(--bg);
  padding: 14px 0 10px;
  margin-bottom: 6px;
}
.sheet-head h2 { margin: 0; font-size: 17px; font-weight: 600; }
.sheet-head .link:last-child { justify-self: end; }
.link { color: var(--rose); font-size: 17px; }
.link.strong { font-weight: 600; }
.link:disabled { opacity: 0.35; }

.group {
  background: var(--card);
  border-radius: 12px;
  margin-bottom: 22px;
  overflow: hidden;
}
.group-label { font-size: 13px; color: var(--secondary); text-transform: uppercase; margin: 0 16px 6px; }
.group-foot { font-size: 13px; color: var(--secondary); margin: -16px 16px 22px; }
.field {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 46px;
  padding: 0 16px;
  border-bottom: 0.5px solid var(--separator);
}
.field:last-child { border-bottom: 0; }
.field > span { flex: none; width: 64px; }
.field input, .field textarea {
  flex: 1;
  min-width: 0;
  border: 0;
  outline: 0;
  background: none;
  padding: 12px 0;
  font-size: 17px;
}
.field textarea { resize: none; }
.field:has(textarea) { align-items: flex-start; }
.field:has(textarea) > span { padding-top: 12px; }
.field.stack { display: block; padding: 0 16px; }
.field .segmented { margin: 0; flex: 1; }
.picker {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 13px 16px;
  color: var(--rose);
  cursor: pointer;
}
.picker svg { width: 22px; height: 22px; fill: currentColor; }
.error { color: var(--danger); font-size: 15px; margin: 0 16px 16px; }

.busy {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: color-mix(in srgb, var(--bg) 70%, transparent);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  font-size: 15px;
  z-index: 2;
}

.recorder {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 22px 16px;
}
.timer { font-size: 48px; font-weight: 300; font-variant-numeric: tabular-nums; letter-spacing: 0.02em; }
.rec-btn {
  width: 84px;
  height: 84px;
  border-radius: 50%;
  border: 4px solid var(--rose-soft);
  display: grid;
  place-items: center;
}
.rec-btn span {
  width: 66px;
  height: 66px;
  border-radius: 33px;
  background: var(--rose);
  transition: all 0.25s ease;
}
.rec-btn.on span { width: 32px; height: 32px; border-radius: 8px; }
.hint { color: var(--secondary); font-size: 14px; margin: 0; }
.pills { display: flex; gap: 12px; }
.pill {
  padding: 8px 16px;
  border-radius: 999px;
  background: var(--fill);
  color: var(--rose);
  font-weight: 500;
  font-size: 15px;
}
.pill.danger { color: var(--danger); }
.file-link { color: var(--rose); font-size: 14px; cursor: pointer; }

.actions { padding-top: 12px; }
.action-title { text-align: center; color: var(--secondary); font-size: 13px; padding: 12px 0; }
.action {
  display: block;
  width: 100%;
  padding: 16px;
  font-size: 18px;
  color: var(--rose);
  background: var(--card);
  border-bottom: 0.5px solid var(--separator);
}
.action:first-of-type { border-radius: 12px 12px 0 0; }
.action:nth-last-child(2) { border-radius: 0 0 12px 12px; border-bottom: 0; }
.action:only-of-type { border-radius: 12px; }
.action.destructive { color: var(--danger); }
.action.cancel { margin-top: 8px; border-radius: 12px; font-weight: 600; }

.toast {
  position: fixed;
  left: 50%;
  top: calc(var(--safe-top) + 12px);
  transform: translateX(-50%);
  max-width: calc(100% - 32px);
  padding: 10px 16px;
  border-radius: 14px;
  background: var(--material);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.15);
  font-size: 15px;
  z-index: 60;
  animation: fade 0.2s ease;
}

/* ---------- sign in / setup */
.center-screen {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  text-align: center;
}
.center-screen .logo { width: 84px; height: 84px; border-radius: 20px; box-shadow: var(--shadow); }
.center-screen h1 { font-size: 28px; margin: 16px 0 6px; }
.center-screen p { color: var(--secondary); margin: 0 0 22px; max-width: 360px; }
.center-screen form { width: 100%; max-width: 340px; text-align: left; }
.center-screen .group { margin-bottom: 16px; }
.btn {
  display: block;
  width: 100%;
  padding: 14px;
  border-radius: 14px;
  background: var(--rose);
  color: #fff;
  font-weight: 600;
  text-align: center;
}
.btn:disabled { opacity: 0.5; }
.center-screen .error { margin: 0 0 12px; text-align: center; }
.center-screen code { background: var(--fill); padding: 2px 6px; border-radius: 6px; font-size: 14px; }
