:root {
  --paper: #F6F3EC;
  --surface: #FFFDF8;
  --sunken: #EDE9DF;
  --ink: #1F2A26;
  --muted: #66716B;
  --line: #E0DBCE;
  --accent: #1F5C4A;
  --accent-press: #174637;
  --on-accent: #FBF8F1;
  --accent-soft: #DDE9E2;
  --danger: #A8452A;
  --danger-soft: #F6E3DB;
  --shadow: 0 1px 2px rgba(31, 42, 38, .06), 0 8px 24px rgba(31, 42, 38, .08);
  --shadow-lift: 0 2px 4px rgba(31, 42, 38, .08), 0 14px 32px rgba(31, 42, 38, .14);
  --ease-out: cubic-bezier(.2, .8, .2, 1);
  --spring: cubic-bezier(.34, 1.56, .64, 1);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #131816;
    --surface: #1B211E;
    --sunken: #232B27;
    --ink: #E9EDE6;
    --muted: #97A29C;
    --line: #2E3733;
    --accent: #7CC4A9;
    --accent-press: #66AE93;
    --on-accent: #10211A;
    --accent-soft: #24372F;
    --danger: #E8947A;
    --danger-soft: #3A2219;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .3);
    --shadow-lift: 0 2px 4px rgba(0, 0, 0, .35), 0 14px 32px rgba(0, 0, 0, .45);
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 15px/1.55 "DM Sans", "Segoe UI", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}
main { max-width: 1120px; margin: 0 auto; padding: 36px 24px 72px; }
h1, h2 { font-family: Fraunces, Georgia, "Times New Roman", serif; font-weight: 600; letter-spacing: -.01em; margin: 0; }
h1 { font-size: 34px; line-height: 1.15; }
h2 { font-size: 22px; line-height: 1.25; overflow-wrap: anywhere; }
p { margin: 0; }
hr { border: 0; border-top: 1px solid var(--line); margin: 18px 0; }
.muted { color: var(--muted); }
.small-text { font-size: 13px; }
.label { font-weight: 500; margin-bottom: 8px; }

/* ---------- Buttons: press in, spring back, ripple from the click point ---------- */
button, .button {
  position: relative;
  overflow: hidden;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 9px 16px;
  border: 1px solid var(--accent);
  border-radius: 10px;
  background: var(--accent);
  color: var(--on-accent);
  font: inherit;
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
  user-select: none;
  transition: transform .28s var(--spring), background-color .15s, border-color .15s, color .15s, box-shadow .15s;
}
button:hover, .button:hover { background: var(--accent-press); border-color: var(--accent-press); }
button:active, .button:active { transform: scale(.94); transition: transform .07s ease-out; }
button:focus-visible, .button:focus-visible, input:focus-visible, select:focus-visible, .button:has(input:focus-visible) {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
button:disabled { opacity: .6; cursor: default; transform: none; }
button.ghost, .button.ghost { background: transparent; color: var(--accent); border-color: var(--line); }
button.ghost:hover, .button.ghost:hover { background: var(--accent-soft); border-color: var(--accent); }
button.danger { background: transparent; color: var(--danger); border-color: var(--line); }
button.danger:hover { background: var(--danger-soft); border-color: var(--danger); }
button.danger.armed { background: var(--danger); border-color: var(--danger); color: var(--surface); }
button.small { padding: 6px 12px; font-size: 14px; }
button.large { padding: 13px 26px; font-size: 16px; }
button.icon { padding: 8px; border-color: transparent; background: transparent; color: var(--muted); border-radius: 50%; }
button.icon:hover { background: var(--sunken); color: var(--ink); border-color: transparent; }

.ripple {
  position: absolute;
  border-radius: 50%;
  background: currentColor;
  opacity: .28;
  transform: scale(0);
  pointer-events: none;
  animation: ripple .55s var(--ease-out) forwards;
}
@keyframes ripple { to { transform: scale(1); opacity: 0; } }

button.confirmed { animation: confirm .4s var(--spring); }
@keyframes confirm { 40% { transform: scale(1.06); } }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 12px 24px;
  background: var(--paper);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; font: 600 19px Fraunces, Georgia, serif; }
.brand img { display: block; border-radius: 7px; }
.user { display: flex; align-items: center; gap: 14px; min-width: 0; }
.user-email { color: var(--muted); font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- Welcome ---------- */
.welcome { display: grid; grid-template-columns: 1.1fr .9fr; gap: 56px; align-items: center; padding: 48px 0; }
.welcome h1 { font-size: 50px; line-height: 1.08; margin-bottom: 18px; }
.eyebrow { color: var(--accent); font-weight: 600; font-size: 14px; margin-bottom: 14px; }
.lead { color: var(--muted); font-size: 18px; max-width: 34em; margin-bottom: 28px; }
.features { list-style: none; margin: 40px 0 0; padding: 22px 0 0; border-top: 1px solid var(--line); display: grid; gap: 10px; color: var(--muted); }
.features b { color: var(--ink); font-weight: 600; margin-right: 6px; }
.collage { position: relative; height: 420px; }
.tile { position: absolute; display: block; border-radius: 12px; box-shadow: var(--shadow-lift); border: 6px solid var(--surface); animation: settle .7s var(--ease-out) both; }
.tile-a { width: 74%; left: 0; top: 4%; --tilt: -4deg; }
.tile-b { width: 48%; right: 2%; top: 22%; --tilt: 5deg; animation-delay: .08s; }
.tile-c { width: 58%; left: 10%; bottom: 0; --tilt: 2deg; animation-delay: .16s; }
.tile { transform: rotate(var(--tilt)); }
@keyframes settle { from { opacity: 0; transform: translateY(16px) rotate(0); } to { opacity: 1; transform: rotate(var(--tilt)); } }

/* ---------- Vault header and filters ---------- */
.vault-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 22px; }
.upload input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.search { position: relative; margin-bottom: 14px; }
.search svg { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
input, select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  transition: border-color .15s;
}
input:hover, select:hover { border-color: var(--muted); }
.search input { padding-left: 38px; }
.pills { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 26px; }
.pill {
  padding: 5px 13px;
  border: 1px solid var(--line);
  border-radius: 99px;
  background: transparent;
  color: var(--muted);
  font-size: 14px;
  font-weight: 500;
}
.pill:hover { background: var(--sunken); border-color: var(--line); color: var(--ink); }
.pill.active, .pill.active:hover { background: var(--ink); border-color: var(--ink); color: var(--paper); }
.pill.tag-pill { border-style: dashed; color: var(--accent); border-color: var(--accent); }
.pill.tag-pill:hover { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }

/* ---------- File grid ---------- */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 24px 20px; }
.card {
  display: block;
  width: 100%;
  padding: 0;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: inherit;
  font-weight: 400;
  text-align: left;
  overflow: visible;
  animation: rise .4s var(--ease-out) both;
  animation-delay: calc(var(--i, 0) * 35ms);
}
.card:hover { background: transparent; }
.card:active { transform: scale(.97); }
@keyframes rise { from { opacity: 0; transform: translateY(10px); } }
.thumb {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  aspect-ratio: 4 / 3;
  overflow: hidden;
  border-radius: 12px;
  background: var(--sunken);
  color: var(--muted);
  box-shadow: 0 1px 2px rgba(31, 42, 38, .08);
  transition: box-shadow .2s, transform .25s var(--ease-out);
}
.card:hover .thumb { box-shadow: var(--shadow-lift); transform: translateY(-3px); }
.thumb img { display: block; width: 100%; height: 100%; object-fit: cover; }
.badge {
  position: absolute;
  left: 8px;
  top: 8px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 9px;
  border-radius: 99px;
  background: var(--surface);
  color: var(--ink);
  font-size: 12px;
  font-weight: 500;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .18);
}
.badge i { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); animation: pulse 1.1s ease-in-out infinite; }
.badge.warn { left: auto; right: 8px; background: var(--danger); color: var(--surface); }
@keyframes pulse { 50% { opacity: .25; } }
.card-name { display: block; margin-top: 10px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-meta { display: flex; align-items: center; gap: 6px; margin-top: 1px; color: var(--muted); font-size: 13px; }
.dot { flex: none; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.dot.Receipts { background: #C98A2B; }
.dot.Documents { background: #4A77A8; }
.dot.Travel { background: #2F8F72; }
.dot.People { background: #C4603F; }
.dot.Screenshots { background: #7B68A6; }

.skeleton { aspect-ratio: 4 / 3; border-radius: 12px; background: var(--sunken); animation: pulse 1.3s ease-in-out infinite; }
.empty { text-align: center; padding: 64px 16px; border: 1px dashed var(--line); border-radius: 14px; }
.empty h2 { margin-bottom: 6px; }
.drop-hint { margin-top: 32px; font-size: 13px; text-align: center; }

/* ---------- Drop overlay, upload tray, toast ---------- */
.drop-overlay {
  position: fixed;
  inset: 12px;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px dashed var(--accent);
  border-radius: 18px;
  background: var(--accent-soft);
  color: var(--accent);
  font: 600 26px Fraunces, Georgia, serif;
  pointer-events: none;
}
.tray { position: fixed; right: 20px; bottom: 20px; z-index: 15; display: grid; gap: 8px; width: min(320px, calc(100vw - 40px)); }
.tray-row {
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  box-shadow: var(--shadow);
  animation: rise .25s var(--ease-out);
}
.tray-name { display: flex; justify-content: space-between; gap: 10px; font-size: 13px; }
.tray-name span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.tray-name span:last-child { flex: none; color: var(--muted); }
.tray-bar { height: 4px; margin-top: 7px; border-radius: 99px; background: var(--sunken); overflow: hidden; }
.tray-bar i { display: block; height: 100%; width: 0; border-radius: 99px; background: var(--accent); transition: width .2s; }
.tray-row.error .tray-name span:last-child { color: var(--danger); }
.tray-row.error .tray-bar i { background: var(--danger); }
.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 30;
  max-width: calc(100vw - 40px);
  padding: 10px 16px;
  border-radius: 10px;
  background: var(--ink);
  color: var(--paper);
  font-size: 14px;
  box-shadow: var(--shadow-lift);
  transform: translateX(-50%);
  animation: toast .3s var(--spring);
}
.toast.error { background: var(--danger); color: var(--surface); }
@keyframes toast { from { opacity: 0; transform: translate(-50%, 12px); } }

/* ---------- Detail dialog ---------- */
dialog {
  width: min(960px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  padding: 0;
  border: 0;
  border-radius: 18px;
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-lift);
}
dialog[open] { animation: dialog .28s var(--ease-out); }
dialog::backdrop { background: rgba(15, 20, 18, .55); animation: fade .2s; }
@keyframes dialog { from { opacity: 0; transform: translateY(14px) scale(.98); } }
@keyframes fade { from { opacity: 0; } }
.close { position: absolute; right: 12px; top: 12px; z-index: 1; }
.close button { background: var(--surface); box-shadow: 0 1px 3px rgba(0, 0, 0, .2); }
.detail-body { display: grid; grid-template-columns: 1.1fr 1fr; }
.preview { display: flex; align-items: center; justify-content: center; min-height: 260px; padding: 20px; background: var(--sunken); }
.preview img { display: block; max-width: 100%; max-height: 72vh; border-radius: 8px; box-shadow: var(--shadow); }
.info { padding: 26px 26px 22px; min-width: 0; }
.info h2 { padding-right: 32px; outline: none; }
.caption { margin-top: 12px; font-size: 16px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.chip { padding: 2px 10px; border: 0; border-radius: 99px; background: var(--accent-soft); color: var(--accent); font-size: 13px; font-weight: 500; }
.chip:hover { background: var(--accent); color: var(--on-accent); }
.fields { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 12px; }
.fields label { display: grid; gap: 4px; align-content: start; font-weight: 500; font-size: 14px; }
.fields .muted { font-weight: 400; font-size: 12px; }
.flag { margin-top: 10px; padding: 8px 12px; border-radius: 10px; background: var(--danger-soft); color: var(--danger); font-size: 14px; }
.segmented { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.segmented button { padding: 8px 6px; }
.share-result { display: flex; gap: 8px; margin-top: 10px; animation: rise .25s var(--ease-out); }
.share-result input { font-size: 13px; }
.actions { display: flex; justify-content: space-between; gap: 10px; margin-top: 22px; }

/* ---------- Public share page ---------- */
.shared { max-width: 820px; text-align: center; }
.shared .caption { color: var(--muted); }
.shared .preview { margin: 24px 0 14px; border-radius: 14px; border: 1px solid var(--line); }

@media (max-width: 820px) {
  .welcome { grid-template-columns: 1fr; gap: 32px; padding: 12px 0; }
  .welcome h1 { font-size: 38px; }
  .collage { height: 300px; max-width: 420px; }
  .detail-body { grid-template-columns: 1fr; }
  .preview { min-height: 180px; }
  .preview img { max-height: 42vh; }
}
@media (max-width: 520px) {
  main { padding: 24px 16px 96px; }
  .topbar { padding: 10px 16px; }
  .user-email { display: none; }
  h1 { font-size: 28px; }
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px 12px; }
  .fields { grid-template-columns: 1fr; }
  .info { padding: 20px 16px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-delay: 0s !important; transition-duration: .01ms !important; }
  .ripple { display: none; }
}
