/* ============ Design tokens ============ */
:root {
  --bg: #EDE9FE;
  --bg-alt: #E4DEFB;
  --surface: #EDE9FE;
  --surface-raised: #F3F0FD;
  --ink: #3D3466;
  --ink-soft: #6C63A0;
  --ink-faint: #9891C4;
  --accent: #7C60D8;
  --accent-strong: #6547C9;
  --accent-soft: #C4B5FD;
  --success: #34B27B;
  --danger: #E0637A;

  --clay-light: rgba(255, 255, 255, 0.85);
  --clay-dark: rgba(148, 130, 210, 0.45);

  --radius-lg: 28px;
  --radius-md: 20px;
  --radius-sm: 14px;
  --radius-round: 999px;

  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
  --ease-in-out: cubic-bezier(0.77, 0, 0.175, 1);
  --ease-drawer: cubic-bezier(0.32, 0.72, 0, 1);

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: linear-gradient(160deg, #F1EDFC 0%, #E4DEFB 55%, #DCD3F8 100%);
  color: var(--ink);
  font-family: var(--font);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}

body {
  min-height: 100dvh;
  display: flex;
  justify-content: center;
}

#app {
  width: 100%;
  max-width: 560px;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  position: relative;
  padding-bottom: env(safe-area-inset-bottom);
}

button {
  font-family: inherit;
  border: none;
  background: none;
  cursor: pointer;
  color: inherit;
}

img { display: block; }

/* ============ Clay utility ============ */
.clay {
  background: var(--surface-raised);
  border-radius: var(--radius-md);
  box-shadow:
    8px 8px 16px var(--clay-dark),
    -8px -8px 16px var(--clay-light);
}

.clay-inset {
  background: var(--bg);
  border-radius: var(--radius-md);
  box-shadow:
    inset 5px 5px 10px var(--clay-dark),
    inset -5px -5px 10px var(--clay-light);
}

.clay-press {
  transition: transform 150ms var(--ease-out), box-shadow 150ms var(--ease-out);
}
.clay-press:active {
  transform: scale(0.97);
  box-shadow:
    4px 4px 10px var(--clay-dark),
    -4px -4px 10px var(--clay-light);
}

/* ============ Header ============ */
.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  padding: 20px 20px 14px;
  backdrop-filter: blur(14px);
  background: rgba(237, 233, 250, 0.82);
}

.app-header__row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.app-title {
  display: flex;
  align-items: center;
  gap: 10px;
}

.app-title__mark {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(145deg, #B8A6F5, #8F79E8);
  box-shadow: 4px 4px 10px var(--clay-dark), -4px -4px 10px var(--clay-light);
  color: white;
}
.app-title__mark svg { width: 20px; height: 20px; }

.app-title h1 {
  font-size: 17px;
  font-weight: 700;
  margin: 0;
  letter-spacing: -0.01em;
}
.app-title p {
  margin: 0;
  font-size: 12px;
  color: var(--ink-soft);
}

.icon-btn {
  width: 42px;
  height: 42px;
  border-radius: var(--radius-round);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--ink-soft);
}
.icon-btn svg { width: 20px; height: 20px; }

/* Streak stat strip */
.stat-strip {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.stat-card {
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.stat-card__icon {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-round);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.stat-card__icon svg { width: 18px; height: 18px; }
.stat-card--streak .stat-card__icon { background: #FDE7C8; color: #C9822B; }
.stat-card--total .stat-card__icon { background: #D6EFE1; color: #2F9D6A; }

.stat-card__value {
  font-size: 19px;
  font-weight: 800;
  line-height: 1.1;
}
.stat-card__label {
  font-size: 11px;
  color: var(--ink-soft);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

/* ============ Timeline ============ */
.timeline {
  flex: 1;
  padding: 4px 20px 120px;
}

.day-group {
  margin-top: 26px;
  opacity: 0;
  transform: translateY(8px);
  animation: fadeIn 320ms var(--ease-out) forwards;
}

@keyframes fadeIn {
  to { opacity: 1; transform: translateY(0); }
}

.day-group__header {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 10px;
  padding-left: 2px;
}

.day-group__title {
  font-size: 14px;
  font-weight: 700;
  color: var(--ink);
}

.day-group__date {
  font-size: 12px;
  color: var(--ink-faint);
}

.day-group__streak-flag {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  font-weight: 700;
  color: #C9822B;
  background: #FDE7C8;
  padding: 3px 8px;
  border-radius: var(--radius-round);
}
.day-group__streak-flag svg { width: 12px; height: 12px; }

.photo-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.photo-tile {
  position: relative;
  aspect-ratio: 3 / 4;
  border-radius: var(--radius-sm);
  overflow: hidden;
  box-shadow: 5px 5px 12px var(--clay-dark), -5px -5px 12px var(--clay-light);
  transition: transform 160ms var(--ease-out);
}
.photo-tile:active { transform: scale(0.96); }

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

.photo-tile__note-dot {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 18px;
  height: 18px;
  border-radius: var(--radius-round);
  background: rgba(61, 52, 102, 0.55);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
}
.photo-tile__note-dot svg { width: 10px; height: 10px; color: white; }

/* Empty state */
.empty-state {
  margin-top: 60px;
  text-align: center;
  padding: 0 30px;
}
.empty-state__icon {
  width: 84px;
  height: 84px;
  margin: 0 auto 18px;
  border-radius: var(--radius-round);
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-raised);
  box-shadow: 8px 8px 16px var(--clay-dark), -8px -8px 16px var(--clay-light);
  color: var(--accent);
}
.empty-state__icon svg { width: 36px; height: 36px; }
.empty-state h2 {
  font-size: 16px;
  margin: 0 0 6px;
}
.empty-state p {
  font-size: 13px;
  color: var(--ink-soft);
  margin: 0;
  line-height: 1.5;
}

/* ============ FAB ============ */
.fab {
  position: fixed;
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%);
  width: 64px;
  height: 64px;
  border-radius: var(--radius-round);
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(150deg, #9E86F3, #7C60D8);
  color: white;
  box-shadow: 0 10px 24px rgba(101, 71, 201, 0.45), 6px 6px 14px var(--clay-dark);
  z-index: 30;
  transition: transform 150ms var(--ease-out), box-shadow 150ms var(--ease-out);
}
.fab svg { width: 26px; height: 26px; }
.fab:active {
  transform: translateX(-50%) scale(0.93);
  box-shadow: 0 6px 14px rgba(101, 71, 201, 0.4), 3px 3px 8px var(--clay-dark);
}

/* Material ripple */
.ripple-wrap { position: relative; overflow: hidden; }
.ripple {
  position: absolute;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.55);
  transform: scale(0);
  animation: rippleAnim 500ms var(--ease-out);
  pointer-events: none;
}
@keyframes rippleAnim {
  to { transform: scale(3); opacity: 0; }
}

/* ============ Sheets / overlays ============ */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: none;
}
.overlay.is-open { display: block; }

.overlay__scrim {
  position: absolute;
  inset: 0;
  background: rgba(43, 35, 77, 0.45);
  opacity: 0;
  transition: opacity 220ms var(--ease-out);
}
.overlay.is-open .overlay__scrim { opacity: 1; }

.sheet {
  position: absolute;
  left: 50%;
  bottom: 0;
  transform: translate(-50%, 100%);
  width: 100%;
  max-width: 560px;
  max-height: 88dvh;
  background: var(--bg);
  border-radius: 28px 28px 0 0;
  box-shadow: 0 -10px 30px rgba(60, 45, 120, 0.25);
  transition: transform 320ms var(--ease-drawer);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.overlay.is-open .sheet { transform: translate(-50%, 0); }

.sheet__handle {
  width: 40px;
  height: 5px;
  border-radius: var(--radius-round);
  background: var(--accent-soft);
  margin: 12px auto 4px;
  flex-shrink: 0;
}

.sheet__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 20px 4px;
  flex-shrink: 0;
}
.sheet__title {
  font-size: 15px;
  font-weight: 700;
}

.sheet__body {
  padding: 12px 20px 28px;
  overflow-y: auto;
}

/* Camera view */
.camera-stage {
  position: relative;
  width: 100%;
  aspect-ratio: 3 / 4;
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: #1E1B33;
  box-shadow: 6px 6px 16px var(--clay-dark), -6px -6px 16px var(--clay-light);
}
.camera-stage video,
.camera-stage img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.camera-stage.is-mirrored video { transform: scaleX(-1); }

.camera-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 26px;
  margin-top: 20px;
}

.shutter-btn {
  width: 72px;
  height: 72px;
  border-radius: var(--radius-round);
  background: white;
  box-shadow: 0 0 0 4px var(--accent-soft), 4px 4px 12px var(--clay-dark);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 120ms var(--ease-out);
}
.shutter-btn:active { transform: scale(0.9); }
.shutter-btn__core {
  width: 58px;
  height: 58px;
  border-radius: var(--radius-round);
  background: linear-gradient(150deg, #9E86F3, #7C60D8);
}

.camera-side-btn {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-round);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--ink-soft);
}
.camera-side-btn svg { width: 20px; height: 20px; }

.file-fallback {
  margin-top: 14px;
  text-align: center;
}
.file-fallback label {
  font-size: 13px;
  color: var(--accent-strong);
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 3px;
}

/* Note field */
.field-label {
  font-size: 12px;
  font-weight: 700;
  color: var(--ink-soft);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  margin: 18px 0 8px;
}

textarea.clay-input {
  width: 100%;
  min-height: 72px;
  border: none;
  border-radius: var(--radius-sm);
  padding: 14px;
  font-family: inherit;
  font-size: 14px;
  color: var(--ink);
  resize: none;
  background: var(--bg);
  box-shadow: inset 4px 4px 8px var(--clay-dark), inset -4px -4px 8px var(--clay-light);
}
textarea.clay-input::placeholder { color: var(--ink-faint); }
textarea.clay-input:focus { outline: 2px solid var(--accent-soft); outline-offset: 1px; }

.sheet__actions {
  display: flex;
  gap: 12px;
  margin-top: 20px;
}

.btn {
  flex: 1;
  padding: 15px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 700;
  text-align: center;
  transition: transform 150ms var(--ease-out);
}
.btn:active { transform: scale(0.97); }

.btn--primary {
  background: linear-gradient(150deg, #9E86F3, #7C60D8);
  color: white;
  box-shadow: 4px 4px 10px var(--clay-dark), -2px -2px 8px var(--clay-light);
}
.btn--ghost {
  background: var(--surface-raised);
  color: var(--ink-soft);
  box-shadow: 4px 4px 10px var(--clay-dark), -4px -4px 10px var(--clay-light);
}
.btn--danger {
  background: var(--surface-raised);
  color: var(--danger);
  box-shadow: 4px 4px 10px var(--clay-dark), -4px -4px 10px var(--clay-light);
}

/* Photo detail sheet image */
.detail-image-wrap {
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: 6px 6px 16px var(--clay-dark), -6px -6px 16px var(--clay-light);
}
.detail-image-wrap img {
  width: 100%;
  max-height: 52dvh;
  object-fit: cover;
}
.detail-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 14px;
  color: var(--ink-soft);
  font-size: 12px;
}
.detail-meta svg { width: 14px; height: 14px; }

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: 112px;
  transform: translate(-50%, 12px);
  background: var(--ink);
  color: white;
  font-size: 13px;
  font-weight: 600;
  padding: 12px 20px;
  border-radius: var(--radius-round);
  box-shadow: 0 8px 20px rgba(43, 35, 77, 0.3);
  z-index: 60;
  opacity: 0;
  transition: opacity 200ms var(--ease-out), transform 200ms var(--ease-out);
  pointer-events: none;
  display: flex;
  align-items: center;
  gap: 8px;
}
.toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}
.toast svg { width: 16px; height: 16px; color: #B8A6F5; }

/* Install banner */
.install-banner {
  margin: 4px 20px 0;
  padding: 12px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  animation: fadeIn 320ms var(--ease-out) forwards;
}
.install-banner__icon {
  width: 34px; height: 34px;
  border-radius: var(--radius-sm);
  background: #E4DEFB;
  display: flex; align-items: center; justify-content: center;
  color: var(--accent);
  flex-shrink: 0;
}
.install-banner__icon svg { width: 17px; height: 17px; }
.install-banner__text { flex: 1; font-size: 12px; color: var(--ink-soft); line-height: 1.4; }
.install-banner__text strong { color: var(--ink); }
.install-banner__btn {
  font-size: 12px;
  font-weight: 700;
  color: var(--accent-strong);
  padding: 8px 12px;
  border-radius: var(--radius-round);
  background: white;
  flex-shrink: 0;
}
.install-banner__close {
  color: var(--ink-faint);
  flex-shrink: 0;
}
.install-banner__close svg { width: 16px; height: 16px; }

@media (hover: hover) and (pointer: fine) {
  .icon-btn:hover, .fab:hover, .photo-tile:hover { filter: brightness(1.03); }
}

@media (prefers-reduced-motion: reduce) {
  .day-group, .toast, .sheet, .overlay__scrim {
    animation-duration: 1ms !important;
    transition-duration: 1ms !important;
  }
}
