/* Base elements and reusable components */

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--f-body);
  font-size: var(--fs-base);
  line-height: var(--lh-body);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
:lang(am) body, body:lang(am) { line-height: var(--lh-ethi); }
img { max-width: 100%; display: block; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; text-underline-offset: .18em; text-decoration-thickness: 1px; }
[hidden] { display: none !important; }

h1, h2, h3, h4 {
  font-family: var(--f-display);
  font-weight: 500;
  line-height: var(--lh-tight);
  letter-spacing: -.01em;
  text-wrap: balance;
  margin: 0;
}
:lang(am) h1, :lang(am) h2, :lang(am) h3, :lang(am) h4 {
  font-family: var(--f-ethi-display);
  letter-spacing: 0;
  line-height: 1.35;
  font-weight: 600;
}
p { margin: 0; }
p + p { margin-top: .8em; }

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
  border-radius: 4px;
}

.skip-link {
  position: fixed; left: max(16px, env(safe-area-inset-left, 0px)); top: calc(env(safe-area-inset-top, 0px) + 8px);
  z-index: 100; padding: var(--s2) var(--s4);
  background: var(--primary); color: var(--on-primary); border-radius: var(--r-sm);
  transform: translateY(-160%); transition: transform .2s var(--ease);
}
.skip-link:focus { transform: none; }

.visually-hidden {
  position: absolute !important; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; margin: -1px; padding: 0; border: 0;
}

.icon { width: 20px; height: 20px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.icon-sm { width: 16px; height: 16px; }
.icon-lg { width: 28px; height: 28px; }

.eyebrow {
  font-size: var(--fs-xs);
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--gold-ink);
  font-weight: 600;
}
:lang(am) .eyebrow { letter-spacing: .04em; font-size: var(--fs-sm); }
.muted { color: var(--ink-2); }
.small { font-size: var(--fs-sm); }
.tabular { font-variant-numeric: tabular-nums; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s2);
  min-height: var(--tap); padding: 0 var(--s5);
  border-radius: var(--r-pill);
  border: 1px solid transparent;
  font-weight: 600; font-size: var(--fs-sm); letter-spacing: .01em;
  text-decoration: none; cursor: pointer;
  transition: background-color .18s var(--ease), border-color .18s var(--ease), color .18s var(--ease), transform .18s var(--ease);
  white-space: nowrap;
}
:lang(am) .btn { font-size: .92rem; }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--primary); color: var(--on-primary); }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: transparent; color: var(--ink); border-color: var(--line-2); }
.btn-secondary:hover { border-color: var(--ink-2); background: var(--card); }
.btn-ghost { background: transparent; color: var(--ink); padding: 0 var(--s3); }
.btn-ghost:hover { background: var(--sunk); }
.btn-danger { background: var(--danger); color: var(--card); }
.btn-danger:hover { filter: brightness(1.08); }
.btn-quiet-danger { background: transparent; color: var(--danger); padding: 0 var(--s3); }
.btn-quiet-danger:hover { background: var(--danger-bg); }
.btn-sm { min-height: 36px; padding: 0 var(--s4); font-size: var(--fs-xs); }
:lang(am) .btn-sm { font-size: .84rem; }
.btn-icon { width: var(--tap); padding: 0; border-radius: 50%; }
.btn[disabled], .btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; transform: none; }
.btn-row { display: flex; flex-wrap: wrap; gap: var(--s3); align-items: center; }

/* ---------- Form controls ---------- */
.field { display: grid; gap: var(--s2); min-width: 0; }
.field > label, .field > .label, legend.label {
  font-size: var(--fs-sm); font-weight: 600; color: var(--ink);
}
.field .hint { font-size: var(--fs-xs); color: var(--ink-2); }
:lang(am) .field .hint { font-size: .82rem; }
.input, .select, .textarea {
  width: 100%; min-height: var(--tap);
  padding: 10px 14px;
  background: var(--card);
  border: 1px solid var(--line-2);
  border-radius: var(--r-sm);
  transition: border-color .15s var(--ease), box-shadow .15s var(--ease);
}
.input:hover, .select:hover, .textarea:hover { border-color: var(--ink-2); }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--focus); box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 22%, transparent); }
.textarea { min-height: 180px; resize: vertical; line-height: 1.7; }
.input[aria-invalid="true"], .textarea[aria-invalid="true"] { border-color: var(--danger); }
.field-error { color: var(--danger); font-size: var(--fs-sm); display: flex; gap: var(--s2); align-items: center; }
fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }

/* Switch (checkbox) */
.switch { display: flex; align-items: center; gap: var(--s3); cursor: pointer; min-height: var(--tap); }
.switch input { appearance: none; -webkit-appearance: none; margin: 0; width: 42px; height: 24px; flex: none;
  border-radius: var(--r-pill); background: var(--line-2); position: relative; cursor: pointer; transition: background .18s var(--ease); }
.switch input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%;
  background: var(--card); box-shadow: var(--shadow-sm); transition: transform .18s var(--ease); }
.switch input:checked { background: var(--primary); }
.switch input:checked::after { transform: translateX(18px); background: var(--on-primary); }
.switch input:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.switch .switch-text { display: grid; }
.switch .switch-text small { color: var(--ink-2); font-size: var(--fs-xs); }
:lang(am) .switch .switch-text small { font-size: .82rem; }

/* Chips (mood, filters) */
.chips { display: flex; flex-wrap: wrap; gap: var(--s2); }
.chip {
  display: inline-flex; align-items: center; gap: 6px; min-height: 38px; padding: 0 14px;
  border-radius: var(--r-pill); border: 1px solid var(--line-2); background: var(--card);
  font-size: var(--fs-sm); cursor: pointer; transition: all .15s var(--ease);
}
.chip:hover { border-color: var(--ink-2); }
.chip[aria-pressed="true"], .chip.is-on { background: var(--lav); border-color: var(--info); color: var(--ink); }
.chip[aria-pressed="true"]::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--info); }

/* Tags and status pills */
.tag {
  display: inline-flex; align-items: center; gap: 5px; padding: 2px 10px; border-radius: var(--r-pill);
  font-size: var(--fs-xs); font-weight: 600; background: var(--sunk); color: var(--ink-2); white-space: nowrap;
}
:lang(am) .tag { font-size: .8rem; }
.tag-demo { background: var(--warn-bg); color: var(--warn); }
.tag-book { background: var(--rose); color: var(--ink); }
.tag-private { background: var(--sunk); color: var(--ink-2); }
.tag-soon { background: var(--info-bg); color: var(--info); }

.status {
  display: inline-flex; align-items: center; gap: var(--s2); font-size: var(--fs-sm); color: var(--ink-2); min-height: 28px;
}
.status:empty { display: none; }
.status::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--line-2); flex: none; }
.status[data-state="draft"]::before { background: var(--gold); }
.status[data-state="saving"]::before { background: var(--info); animation: pulse 1s infinite; }
.status[data-state="saved"] { color: var(--ok); }
.status[data-state="saved"]::before { background: var(--ok); }
.status[data-state="error"] { color: var(--danger); }
.status[data-state="error"]::before { background: var(--danger); }
@keyframes pulse { 50% { opacity: .35; } }

/* Notices / banners */
.notice {
  display: flex; gap: var(--s3); align-items: flex-start; padding: var(--s4);
  border-radius: var(--r-md); background: var(--info-bg); color: var(--ink); font-size: var(--fs-sm);
}
.notice .icon { margin-top: 2px; color: var(--info); }
.notice-warn { background: var(--warn-bg); } .notice-warn .icon { color: var(--warn); }
.notice-danger { background: var(--danger-bg); } .notice-danger .icon { color: var(--danger); }
.notice-ok { background: var(--ok-bg); } .notice-ok .icon { color: var(--ok); }
.notice > div { display: grid; gap: var(--s2); min-width: 0; }
.notice strong { font-weight: 600; }

/* Surfaces */
.panel {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--r-lg);
  padding: var(--s5); box-shadow: var(--shadow-sm);
}
.panel-quiet { background: transparent; border: 1px solid var(--line); border-radius: var(--r-lg); padding: var(--s5); }

/* Photo frame — album mat around a photo. Crop is non-destructive:
   aspect ratio on the frame, object-position + scale on the image. */
.frame {
  background: var(--card); padding: 8px; border-radius: 4px;
  box-shadow: var(--shadow); border: 1px solid var(--line);
  max-width: 100%;
}
.frame-inner { position: relative; overflow: hidden; border-radius: 2px; background: var(--sunk); aspect-ratio: var(--ar, 4 / 5); max-width: 100%; }
.frame-inner img { width: 100%; height: 100%; object-fit: cover; transform-origin: var(--ox, 50%) var(--oy, 50%); object-position: var(--ox, 50%) var(--oy, 50%); transform: scale(var(--zoom, 1)); }
.frame-caption { font-size: var(--fs-xs); color: var(--ink-2); padding: 8px 2px 0; }

/* Illustrated placeholders (no stock photos, clearly labelled) */
.art { position: absolute; inset: 0; }
.art-1 { background: radial-gradient(circle at 68% 30%, #F7E7C9 0 13%, transparent 14%), linear-gradient(170deg, #F2DEE1 0%, #E9CFD3 48%, #CDB7C7 49%, #B9A3B9 100%); }
.art-2 { background: radial-gradient(ellipse at 30% 110%, #C9D3BF 0 40%, transparent 41%), radial-gradient(circle at 60% 35%, #FFF6E6 0 10%, transparent 11%), linear-gradient(180deg, #EAE4F3, #DCD2EA); }
.art-3 { background: radial-gradient(circle at 50% 46%, #EFD9B8 0 22%, transparent 23%), linear-gradient(200deg, #F3E7D8, #E3CFC0); }
.art-4 { background: linear-gradient(160deg, #E4E8DD 0 55%, #CBD4C1 56% 100%); }
.art-label {
  position: absolute; left: 8px; bottom: 8px; font-size: 10px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase;
  background: rgb(255 253 250 / .86); color: #5E5260; padding: 2px 7px; border-radius: 99px;
}

/* Dialog */
dialog.dlg {
  width: min(560px, calc(100vw - 32px)); max-height: calc(100dvh - 48px);
  border: 1px solid var(--line); border-radius: var(--r-lg); padding: 0;
  background: var(--card); color: var(--ink); box-shadow: var(--shadow-lg);
}
dialog.dlg-wide { width: min(860px, calc(100vw - 32px)); }
dialog.dlg::backdrop { background: var(--scrim); }
.dlg-head { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--s4); padding: var(--s5) var(--s5) 0; }
.dlg-head h2 { font-size: var(--fs-lg); }
.dlg-body { padding: var(--s4) var(--s5); display: grid; gap: var(--s4); }
.dlg-foot { padding: 0 var(--s5) var(--s5); display: flex; flex-wrap: wrap; gap: var(--s3); justify-content: flex-end; }
@media (max-width: 560px) {
  dialog.dlg { width: 100vw; max-width: 100vw; margin: auto 0 0; border-radius: var(--r-lg) var(--r-lg) 0 0; max-height: 92dvh; padding-bottom: env(safe-area-inset-bottom, 0px); }
}

/* Toasts */
.toasts { position: fixed; z-index: 90; left: 50%; transform: translateX(-50%);
  bottom: calc(env(safe-area-inset-bottom, 0px) + 88px); display: grid; gap: var(--s2); width: min(440px, calc(100vw - 32px)); pointer-events: none; }
.toast { pointer-events: auto; background: var(--primary); color: var(--on-primary); padding: 12px 16px; border-radius: var(--r-md);
  box-shadow: var(--shadow-lg); font-size: var(--fs-sm); display: flex; gap: var(--s3); align-items: center; animation: toast-in .25s var(--ease); }
.toast.is-error { background: var(--danger); color: var(--card); }
.toast-text { flex: 1 1 auto; min-width: 0; overflow-wrap: anywhere; }
.toast-close { flex: none; display: grid; place-items: center; width: 32px; height: 32px; margin: -6px -8px -6px 0; border: 0; border-radius: 50%; background: transparent; color: inherit; cursor: pointer; opacity: .8; }
.toast-close:hover, .toast-close:focus-visible { opacity: 1; background: rgb(255 255 255 / .14); }
.toast.is-bump { animation: toast-bump .3s var(--ease); }
@keyframes toast-bump { 50% { transform: scale(1.02); } }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }
@media (min-width: 900px) { .toasts { bottom: calc(env(safe-area-inset-bottom, 0px) + 24px); } }

/* Empty states */
.empty {
  display: grid; justify-items: center; text-align: center; gap: var(--s3);
  padding: var(--s7) var(--s5); border: 1px dashed var(--line-2); border-radius: var(--r-lg); background: transparent;
}
.empty h3 { font-size: var(--fs-lg); }
.empty p { color: var(--ink-2); max-width: 44ch; }
.empty .sprig { width: 56px; height: 56px; color: var(--gold); }

/* Skeleton loading */
.skeleton { background: linear-gradient(90deg, var(--sunk), var(--line), var(--sunk)); background-size: 200% 100%; animation: shimmer 1.4s infinite; border-radius: var(--r-sm); }
@keyframes shimmer { to { background-position: -200% 0; } }

/* Segmented control */
.seg { display: inline-flex; padding: 3px; border-radius: var(--r-pill); background: var(--sunk); border: 1px solid var(--line); }
.seg button { white-space: nowrap; border: 0; background: transparent; min-height: 34px; padding: 0 14px; border-radius: var(--r-pill); cursor: pointer; font-size: var(--fs-sm); color: var(--ink-2); font-weight: 500; }
.seg button[aria-pressed="true"] { background: var(--card); color: var(--ink); box-shadow: var(--shadow-sm); font-weight: 600; }

.lang-switch button { font-family: var(--f-body); }

/* Gold hairline rule */
.rule { height: 1px; background: linear-gradient(90deg, transparent, var(--gold), transparent); border: 0; margin: 0; opacity: .7; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; scroll-behavior: auto !important; }
}
