/* Components. Every value comes from tokens.css. */

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

html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font-sans);
  font-size: var(--text-body);
  line-height: var(--leading-body);
  letter-spacing: var(--tracking-body);
  font-optical-sizing: auto;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

h1, h2, h3, p, ul, ol, figure { margin: 0; }
img { max-width: 100%; display: block; }
[hidden] { display: none !important; } /* components set display; hidden must still win */
a { color: var(--color-accent); text-decoration: none; }
a:hover { text-decoration: underline; }
:focus-visible { outline: none; box-shadow: var(--focus-ring); border-radius: var(--radius-sm); }

.visually-hidden {
  position: absolute; width: var(--hairline); height: var(--hairline); overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}
.skip-link { position: absolute; left: var(--space-4); top: calc(-1 * var(--space-12)); z-index: var(--z-tab-bar); }
.skip-link:focus { top: var(--space-2); }

.icon {
  width: var(--icon-size); height: var(--icon-size); flex: none;
  fill: none; stroke: currentColor; stroke-width: var(--icon-stroke);
  stroke-linecap: round; stroke-linejoin: round;
}
.icon--small { width: var(--icon-size-small); height: var(--icon-size-small); }

/* ── Type roles ─────────────────────────────────────────── */
.large-title {
  font-family: var(--font-display);
  font-size: var(--text-large); line-height: var(--leading-large);
  letter-spacing: var(--tracking-large); font-weight: var(--weight-bold);
}
.title2 { font-size: var(--text-title2); line-height: var(--leading-title2); letter-spacing: var(--tracking-title2); font-weight: var(--weight-bold); }
.title3 { font-size: var(--text-title3); line-height: var(--leading-title3); letter-spacing: var(--tracking-title3); font-weight: var(--weight-semibold); }
.headline { font-size: var(--text-headline); line-height: var(--leading-headline); letter-spacing: var(--tracking-headline); font-weight: var(--weight-semibold); }
.subhead { font-size: var(--text-subhead); line-height: var(--leading-subhead); color: var(--color-text-muted); }
.footnote { font-size: var(--text-footnote); line-height: var(--leading-footnote); letter-spacing: var(--tracking-footnote); color: var(--color-text-muted); }
.section-label {
  font-size: var(--text-footnote); letter-spacing: var(--tracking-footnote);
  color: var(--color-text-muted); text-transform: uppercase; padding: 0 var(--space-4) var(--space-2);
}

/* ── Layout ─────────────────────────────────────────────── */
.page {
  width: 100%; max-width: var(--content-max); margin: 0 auto;
  padding: var(--space-4) var(--space-4) calc(var(--tab-bar-height) + var(--space-10) + env(safe-area-inset-bottom));
  display: grid; gap: var(--space-6); align-content: start;
}
.page--wide { max-width: var(--content-wide); }
.page--auth { min-height: 100dvh; align-content: center; padding-bottom: var(--space-10); max-width: 26rem; }
.page-head { display: grid; gap: var(--space-2); padding-top: var(--space-2); }
.stack { display: grid; gap: var(--space-4); }
.stack--tight { display: grid; gap: var(--space-2); }
.cluster { display: flex; flex-wrap: wrap; gap: var(--space-3); align-items: center; }
.cluster--end { justify-content: flex-end; }
.inline-form { display: inline; }

/* ── Header: translucent material, content scrolls under it ── */
.app-header {
  position: sticky; top: 0; z-index: var(--z-header);
  background: var(--material-bar);
  -webkit-backdrop-filter: var(--material-blur); backdrop-filter: var(--material-blur);
  padding-top: env(safe-area-inset-top);
}
/* Soft scroll-edge instead of a hard divider line */
.app-header::after {
  content: ''; position: absolute; left: 0; right: 0; bottom: calc(-1 * var(--space-3)); height: var(--space-3);
  background: linear-gradient(var(--color-separator), transparent); opacity: 0.35; pointer-events: none;
}
.app-header__inner {
  max-width: var(--content-wide); margin: 0 auto; min-height: var(--tap-min);
  padding: var(--space-2) var(--space-4); display: flex; align-items: center; justify-content: space-between; gap: var(--space-3);
}
.brand { font-family: var(--font-display); font-weight: var(--weight-bold); font-size: var(--text-headline); color: var(--color-text); letter-spacing: var(--tracking-headline); }
.brand:hover { text-decoration: none; }
.brand__year { color: var(--color-accent); }

/* ── Tab bar: bottom on phones (thumb reach), a row of pills on wider screens ── */
.tab-bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: var(--z-tab-bar);
  background: var(--material-bar);
  -webkit-backdrop-filter: var(--material-blur); backdrop-filter: var(--material-blur);
  border-top: var(--hairline) solid var(--material-edge);
  padding-bottom: env(safe-area-inset-bottom);
}
.tab-bar__list { list-style: none; padding: 0; margin: 0 auto; max-width: var(--content-wide); display: flex; }
.tab-bar__item { flex: 1; }
.tab-bar__link {
  min-height: var(--tab-bar-height); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: var(--space-1);
  font-size: var(--text-caption); letter-spacing: var(--tracking-caption); font-weight: var(--weight-medium);
  color: var(--color-text-muted);
  transition: transform var(--duration-press) var(--ease-out), color var(--duration-fast) var(--ease-standard);
}
.tab-bar__link:hover { text-decoration: none; }
.tab-bar__link:active { transform: scale(var(--press-scale)); }
.tab-bar__link[aria-current='page'] { color: var(--color-accent); }

@media (min-width: 48rem) {
  .tab-bar { position: static; background: none; backdrop-filter: none; -webkit-backdrop-filter: none; border: 0; padding: var(--space-3) var(--space-4) 0; }
  .tab-bar__list { justify-content: center; gap: var(--space-2); }
  .tab-bar__item { flex: none; }
  .tab-bar__link {
    flex-direction: row; min-height: var(--tap-min); padding: 0 var(--space-4); border-radius: var(--radius-pill);
    font-size: var(--text-subhead);
  }
  .tab-bar__link[aria-current='page'] { background: var(--color-accent-tint); }
  .page { padding-bottom: var(--space-12); }
}

/* ── Buttons: feedback on press, instantly ─────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  min-height: var(--tap-min); padding: 0 var(--space-5);
  border: 0; border-radius: var(--radius-pill); cursor: pointer;
  font: inherit; font-size: var(--text-body); font-weight: var(--weight-semibold); letter-spacing: var(--tracking-headline);
  text-decoration: none; white-space: nowrap;
  transition: transform var(--duration-press) var(--ease-out), background-color var(--duration-fast) var(--ease-standard), opacity var(--duration-fast) var(--ease-standard);
}
.btn:hover { text-decoration: none; }
.btn:active { transform: scale(var(--press-scale)); }
.btn[disabled], .btn[aria-busy='true'] { opacity: var(--dimmed); cursor: default; }
.btn--primary { background: var(--color-accent-fill); color: var(--color-on-accent); }
.btn--secondary { background: var(--color-accent-tint); color: var(--color-accent); }
.btn--destructive { background: var(--color-danger-tint); color: var(--color-danger); }
.btn--plain { background: none; color: var(--color-accent); padding: 0 var(--space-3); }
.btn--small { min-height: calc(var(--tap-min) - var(--space-2)); padding: 0 var(--space-4); font-size: var(--text-subhead); }
.btn--block { width: 100%; }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center; flex: none;
  width: var(--tap-min); height: var(--tap-min); border-radius: var(--radius-pill); color: var(--color-accent);
  border: 0; background: none; padding: 0; cursor: pointer;
  transition: transform var(--duration-press) var(--ease-out), background-color var(--duration-fast) var(--ease-standard);
}
.icon-btn:hover { background: var(--color-fill); text-decoration: none; }
.icon-btn:active { transform: scale(var(--press-scale)); }

/* ── Cards and grouped lists ───────────────────────────── */
.card {
  background: var(--color-surface); border-radius: var(--radius-lg); box-shadow: var(--shadow-md);
  padding: var(--space-5); display: grid; gap: var(--space-4);
}
.group { display: grid; gap: var(--space-1); }
.list {
  list-style: none; padding: 0; margin: 0;
  background: var(--color-surface); border-radius: var(--radius-lg); box-shadow: var(--shadow-md); overflow: hidden;
}
.list > li + li { border-top: var(--hairline) solid var(--color-separator); }
.list-row { display: flex; gap: var(--space-3); align-items: center; padding: var(--space-3) var(--space-4); min-height: var(--tap-min); }
.list-row__main { flex: 1; min-width: 0; display: grid; gap: var(--space-1); }

/* ── Entry (one memory): shared by My Year, Review and the phone view of the sheet ── */
.entry { display: flex; gap: var(--space-3); align-items: flex-start; padding: var(--space-4); }
.entry__photo { flex: none; border-radius: var(--radius-md); overflow: hidden; }
.entry__photo img { width: var(--thumb-size); height: var(--thumb-size); object-fit: cover; background: var(--color-fill); }
.entry__photo, .sheet__cover { position: relative; display: inline-block; }
.entry__more { position: absolute; right: var(--space-1); bottom: var(--space-1); background: var(--color-surface); box-shadow: var(--shadow-sm); }

/* ── Memory page: every photo at reading size ── */
.memory-grid { margin-block: var(--space-5); display: grid; gap: var(--space-2); }
.memory-grid__tools { display: flex; align-items: center; justify-content: center; gap: var(--space-3); color: var(--color-text-muted); font-size: var(--text-footnote); }
.memory-grid__tools .icon-btn[aria-disabled='true'] { opacity: var(--dimmed); cursor: default; background: none; }
/* The transition overlay must not take hit-testing, or a continuing pinch lands on <html> and zooms the page. */
::view-transition { pointer-events: none; }
.memory-grid__list { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--memory-grid-gap); grid-template-columns: repeat(var(--grid-cols, 3), 1fr); touch-action: pan-y; }
.memory-grid__tile { display: block; }
.memory-grid__img { display: block; width: 100%; height: auto; background: var(--color-fill); }
[data-grid]:not([data-cols="1"]) .memory-grid__img { aspect-ratio: 1; object-fit: cover; }
.pswp.pswp { --pswp-bg: var(--color-viewer-bg); }
.memory__text { white-space: pre-line; overflow-wrap: anywhere; }
.entry__body { flex: 1; min-width: 0; display: grid; gap: var(--space-1); }
.entry__meta { font-size: var(--text-footnote); letter-spacing: var(--tracking-footnote); color: var(--color-text-muted); }
.entry__text { white-space: pre-line; overflow-wrap: anywhere; }
.entry__edit { margin: calc(-1 * var(--space-2)) calc(-1 * var(--space-2)) 0 0; }

.empty {
  text-align: center; padding: var(--space-10) var(--space-6); display: grid; gap: var(--space-3); justify-items: center;
  background: var(--color-surface); border-radius: var(--radius-lg); box-shadow: var(--shadow-md); color: var(--color-text-muted);
}
.empty .icon { width: calc(var(--icon-size) * 2); height: calc(var(--icon-size) * 2); color: var(--color-accent); }

/* ── Forms ──────────────────────────────────────────────── */
.form { display: grid; gap: var(--space-5); }
.field { display: grid; gap: var(--space-2); }
.field__label { font-size: var(--text-subhead); font-weight: var(--weight-semibold); }
.field__hint { font-size: var(--text-footnote); line-height: var(--leading-footnote); color: var(--color-text-muted); }
.field__input {
  width: 100%; min-height: var(--tap-min); padding: var(--space-3) var(--space-4);
  font: inherit; color: var(--color-text); background: var(--color-fill);
  border: var(--hairline) solid transparent; border-radius: var(--radius-md);
  transition: box-shadow var(--duration-fast) var(--ease-standard), background-color var(--duration-fast) var(--ease-standard);
  -webkit-appearance: none; appearance: none;
}
.field__input:focus { outline: none; background: var(--color-surface); box-shadow: var(--focus-ring); }
textarea.field__input { min-height: calc(var(--tap-min) * 3); resize: vertical; line-height: var(--leading-body); }
select.field__input { padding-right: var(--space-8); }
.field__input[type='file'] { padding: var(--space-3); }
.field__input[type='file']::file-selector-button {
  font: inherit; font-weight: var(--weight-semibold); color: var(--color-accent); background: var(--color-accent-tint);
  border: 0; border-radius: var(--radius-pill); padding: var(--space-2) var(--space-4); margin-right: var(--space-3); cursor: pointer;
}
.field__row { display: flex; gap: var(--space-2); align-items: center; }
.field__row .field__input { flex: 1; min-width: 0; }
.field__input:user-invalid { border-color: var(--color-danger); }
.check { display: flex; gap: var(--space-3); align-items: center; min-height: var(--tap-min); }
.check input { width: var(--icon-size); height: var(--icon-size); accent-color: var(--color-accent-fill); }

/* ── Photo grid in the memory form ─────────────────────── */
.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(var(--photo-tile-min), 1fr)); gap: var(--space-4) var(--space-3); }
.photo-grid:not(:has([data-photo-tile])) { display: none; }
.photo-tile { display: grid; gap: var(--space-1); align-content: start; }
.photo-tile__frame { position: relative; }
.photo-tile--lifted { transform: scale(var(--lift-scale)); box-shadow: var(--shadow-lg); }
/* After --lifted: in native drag the in-list tile gets both classes; the placeholder must win. */
.photo-tile--placeholder { transform: none; box-shadow: none; opacity: var(--dimmed); }
.photo-tile__img { -webkit-touch-callout: none; user-select: none; -webkit-user-select: none; width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: var(--radius-md); background: var(--color-fill); transition: opacity var(--duration-fast) var(--ease-standard); }
.photo-tile[data-state='waiting'] .photo-tile__img, .photo-tile[data-state='uploading'] .photo-tile__img { opacity: var(--dimmed); }
.photo-tile__cover { position: absolute; top: var(--space-2); left: var(--space-2); display: none; }
.photo-tile:first-child .photo-tile__cover { display: inline-flex; }
.photo-tile__state { font-size: var(--text-footnote); line-height: var(--leading-footnote); color: var(--color-text-muted); }
.photo-tile__state:empty { display: none; }
.photo-tile[data-state='failed'] .photo-tile__state { color: var(--color-danger); }
.photo-tile__actions { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; }
.photo-tile__actions .icon-btn[disabled] { opacity: var(--dimmed); cursor: default; background: none; }
.photo-tile__actions .btn { flex-basis: 100%; }
.photo-tile:first-child [data-cover] { display: none; }
.loc-status { display: flex; align-items: center; gap: var(--space-1); color: var(--color-text-muted); }
.loc-status--yes .icon:last-of-type { color: var(--color-success); stroke-width: calc(var(--icon-stroke) * 1.4); }
.loc-status--no .icon:last-of-type { color: var(--color-danger); stroke-width: calc(var(--icon-stroke) * 1.4); }
.icon--fill { fill: currentColor; stroke: none; }
.switch { display: flex; align-items: center; justify-content: space-between; gap: var(--space-2); min-height: var(--tap-min); font-size: var(--text-footnote); line-height: var(--leading-footnote); cursor: pointer; }
.switch input {
  appearance: none; position: relative; flex: none; margin: 0; cursor: pointer;
  width: var(--switch-width); height: var(--switch-height); border-radius: var(--radius-pill);
  background: var(--color-fill-strong); transition: background var(--duration-fast) var(--ease-standard);
}
.switch input::before {
  content: ''; position: absolute; top: var(--switch-inset); left: var(--switch-inset);
  width: calc(var(--switch-height) - 2 * var(--switch-inset)); aspect-ratio: 1; border-radius: var(--radius-pill);
  background: var(--color-switch-knob); box-shadow: var(--shadow-sm); transition: transform var(--duration-fast) var(--ease-out);
}
.switch input:checked { background: var(--color-success); }
.switch input:checked::before { transform: translateX(calc(var(--switch-width) - var(--switch-height))); }
.switch input:disabled { opacity: var(--dimmed); cursor: default; }
.switch input:focus-visible { border-radius: var(--radius-pill); }
.photo-offer { display: flex; flex-wrap: wrap; gap: var(--space-3); align-items: center; justify-content: space-between; }
.filters { display: flex; flex-wrap: wrap; gap: var(--space-3); align-items: end; }
.filters .field { flex: 1 1 10rem; }

/* ── Alerts and the 1 December banner ──────────────────── */
.alert { padding: var(--space-3) var(--space-4); border-radius: var(--radius-md); font-size: var(--text-subhead); }
.alert--info { background: var(--color-accent-tint); color: var(--color-text); }
.alert--success { background: var(--color-success-tint); color: var(--color-text); }
.alert--warning { background: var(--color-warning-tint); color: var(--color-text); }
.alert--danger { background: var(--color-danger-tint); color: var(--color-text); }
.alert strong { color: inherit; }

.banner {
  display: flex; gap: var(--space-4); align-items: center; flex-wrap: wrap;
  padding: var(--space-4) var(--space-5); border-radius: var(--radius-lg);
  background: var(--color-accent-tint);
  animation: arrive var(--duration-base) var(--ease-out) both;
}
.banner__icon { color: var(--color-accent); }
.banner__text { flex: 1 1 12rem; display: grid; gap: var(--space-1); }

@keyframes arrive {
  from { opacity: 0; transform: translateY(calc(-1 * var(--space-2))); }
  to { opacity: 1; transform: none; }
}

/* ── Badges ─────────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center; padding: 0 var(--space-2); border-radius: var(--radius-pill);
  font-size: var(--text-caption); font-weight: var(--weight-semibold); letter-spacing: var(--tracking-caption);
  background: var(--color-fill); color: var(--color-text-muted); line-height: var(--leading-body);
}
.badge--accent { background: var(--color-accent-tint); color: var(--color-accent); }
.badge--success { background: var(--color-success-tint); color: var(--color-success); }
.badge--warning { background: var(--color-warning-tint); color: var(--color-warning); }

/* ── Family sheet: a table on wide screens, cards on phones ── */
.sheet { width: 100%; border-collapse: collapse; background: var(--color-surface); border-radius: var(--radius-lg); box-shadow: var(--shadow-md); overflow: hidden; }
.sheet th, .sheet td { text-align: left; vertical-align: top; padding: var(--space-3) var(--space-4); }
.sheet thead th { font-size: var(--text-footnote); color: var(--color-text-muted); font-weight: var(--weight-semibold); background: var(--color-fill); }
.sheet tbody tr + tr td { border-top: var(--hairline) solid var(--color-separator); }
.sheet td.sheet__nowrap { white-space: nowrap; }
.sheet__text { white-space: pre-line; overflow-wrap: anywhere; }
.sheet__thumb img { width: calc(var(--thumb-size) * 0.75); height: calc(var(--thumb-size) * 0.75); object-fit: cover; border-radius: var(--radius-sm); }

@media (max-width: 40rem) {
  .sheet, .sheet tbody, .sheet tr, .sheet td { display: block; width: 100%; }
  .sheet { background: none; box-shadow: none; }
  .sheet thead { display: none; }
  .sheet tr { background: var(--color-surface); border-radius: var(--radius-lg); box-shadow: var(--shadow-md); margin-bottom: var(--space-3); padding: var(--space-2) 0; position: relative; }
  .sheet tbody tr + tr td { border-top: 0; }
  .sheet td { padding: var(--space-1) var(--space-4); }
  .sheet td[data-label]::before { content: attr(data-label); display: block; font-size: var(--text-caption); color: var(--color-text-muted); }
  .sheet td.sheet__edit { position: absolute; top: var(--space-1); right: 0; width: auto; }
}

/* ── Photo book ─────────────────────────────────────────── */
.book { display: grid; gap: var(--space-6); }
.book-cover, .book-page {
  background: var(--color-surface); border-radius: var(--radius-xl); box-shadow: var(--shadow-lg); overflow: hidden;
}
.book-cover { padding: var(--space-12) var(--space-6); text-align: center; display: grid; gap: var(--space-3); }
.book-page figure { display: grid; }
.book-page img { width: 100%; max-height: 75vh; object-fit: contain; background: var(--color-fill); }
.book-page figcaption { padding: var(--space-5) var(--space-6) var(--space-6); display: grid; gap: var(--space-2); }

/* ── Backup codes / links ───────────────────────────────── */
.codes { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(12rem, 1fr)); gap: var(--space-2); }
.codes li { font-family: ui-monospace, 'SF Mono', Menlo, monospace; background: var(--color-fill); border-radius: var(--radius-sm); padding: var(--space-2) var(--space-3); text-align: center; }
.qr { width: 15rem; height: 15rem; border-radius: var(--radius-md); background: var(--color-print-bg); padding: var(--space-2); }
.recovery-key { font-family: ui-monospace, 'SF Mono', Menlo, monospace; font-size: var(--text-title3); line-height: var(--leading-title3); overflow-wrap: anywhere; }
.mono { font-family: ui-monospace, 'SF Mono', Menlo, monospace; overflow-wrap: anywhere; }

/* ── Motion preferences: gentle cross-fades only ───────── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 1ms !important; transition-duration: 1ms !important; }
  .btn:active, .icon-btn:active, .tab-bar__link:active { transform: none; }
}

/* ── Print: sheet as a clean table, book as one photo per page ── */
@media print {
  @page { margin: 12mm; }
  body { background: var(--color-print-bg); color: var(--color-print-text); }
  .app-header, .tab-bar, .no-print, .banner, .skip-link { display: none !important; }
  .page { max-width: none; padding: 0; }
  .sheet, .list, .card, .book-cover, .book-page { box-shadow: none; }
  .sheet { border: var(--hairline) solid var(--color-separator); }
  .sheet tr { break-inside: avoid; }
  .book { gap: 0; }
  .book-cover, .book-page { border-radius: 0; break-after: page; }
  .book-cover { min-height: 90vh; align-content: center; }
  .book-page img { max-height: 70vh; background: none; }
}
