:root {
  --paper: #f7f7f8;
  --card: #ffffff;
  --ink: #23212a;
  --muted: #6f6b75;
  --line: #e4e2e8;
  --accent: #3d3a45;
  --danger: #a3263a;
  --ok: #2f6b4f;
  --warn: #8a5a00;
  --display: 'Bodoni Moda', Georgia, serif;
  --ui: 'Figtree', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --ease: cubic-bezier(0.2, 0.7, 0.2, 1);
  --head-h: 0px;
  --gutter: clamp(16px, 4vw, 40px);
  color-scheme: light;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--paper); color: var(--ink); font: 400 15px/1.5 var(--ui); -webkit-text-size-adjust: 100%; }
[hidden] { display: none !important; }
img { max-width: 100%; }
h1 { font: 400 34px/1.1 var(--display); letter-spacing: -0.01em; margin: 0; }
h2 { font: 600 15px/1.3 var(--ui); margin: 0 0 14px; }
h3 { font: 600 15px/1.3 var(--ui); margin: 0 0 8px; }
a { color: inherit; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.block { display: block; margin-top: 8px; }

/* ---- Top bar ---- */
.topbar {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: calc(10px + env(safe-area-inset-top, 0px)) var(--gutter) 10px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
}
.brand { font: 400 20px/1 var(--display); color: var(--ink); text-decoration: none; margin-right: auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.brand img { display: block; max-height: 32px; max-width: 160px; width: auto; }
.topnav { display: flex; gap: 4px; }
.topnav a {
  padding: 9px 14px;
  border-radius: 999px;
  text-decoration: none;
  font-weight: 500;
  font-size: 14px;
  color: var(--muted);
}
.topnav a:hover { color: var(--ink); background: #f1f0f4; }
.topnav a[aria-current='page'] { color: var(--ink); background: #ecebf0; }

.link { background: none; border: 0; padding: 0; font: inherit; color: var(--ink); text-decoration: underline; cursor: pointer; }
.page { padding: 28px var(--gutter) 80px; max-width: 1280px; margin: 0 auto; }
.page-title { margin-bottom: 22px; }

/* ---- Buttons and forms ---- */
.btn {
  font: 500 14px/1 var(--ui);
  border-radius: 8px;
  padding: 11px 16px;
  min-height: 40px;
  cursor: pointer;
  border: 1px solid transparent;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  white-space: nowrap;
}
.btn-solid { background: var(--accent); color: #fff; }
.btn-solid:hover { filter: brightness(1.15); }
.btn-quiet { background: var(--card); color: var(--ink); border-color: var(--line); }
.btn-quiet:hover { border-color: var(--ink); }
.btn-danger { background: none; color: var(--danger); border-color: #e9c9cf; }
.btn-danger.armed, .chip-danger.armed { background: var(--danger); color: #fff; border-color: var(--danger); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

input, textarea {
  width: 100%;
  font: 400 15px/1.3 var(--ui);
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
}
input[type='color'] { width: 56px; height: 42px; padding: 4px; flex: none; }
input[type='radio'], input[type='checkbox'] { width: auto; margin: 3px 0 0; accent-color: var(--accent); }
textarea { resize: vertical; }
label { display: grid; gap: 6px; font-size: 14px; font-weight: 500; }
label small { font-weight: 400; }
fieldset { border: 0; padding: 0; margin: 0; display: grid; gap: 14px; align-content: start; min-width: 0; }
legend { font-weight: 600; font-size: 15px; padding: 0; margin: 0 0 2px; float: left; width: 100%; }
legend + * { clear: both; }
.choice, .check { display: flex; gap: 10px; align-items: flex-start; font-weight: 400; }
.choice span { display: grid; gap: 2px; }
.stack { display: grid; gap: 16px; }
.select { font: 400 14px/1.2 var(--ui); padding: 9px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--ink); max-width: 100%; }
.form-error { color: var(--danger); margin: 0; font-size: 14px; }
.form-ok { color: var(--ok); margin: 0; font-size: 14px; }
.form-warn { color: var(--warn); margin: 0; font-size: 14px; }
.color-row { display: flex; align-items: center; gap: 12px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 22px; }

.auth-card { max-width: 420px; margin: 8vh auto 0; background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 32px; }
.auth-card h1 { margin-bottom: 8px; }
.auth-card form { margin-top: 22px; }

.pill { font-size: 12px; font-weight: 600; padding: 4px 10px; border-radius: 999px; white-space: nowrap; }
.pill-on { background: #e3f1e9; color: var(--ok); }
.pill-draft { background: #ecebf0; color: var(--muted); }
.pill-off { background: #f6e3e6; color: var(--danger); }
.empty-note { color: var(--muted); padding: 24px 0; }

/* ---- Dashboard ---- */
.dash { max-width: 960px; margin: 0 auto; }
.dash-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px 20px; flex-wrap: wrap; margin-bottom: 20px; }
.usage-link { font-size: 14px; color: var(--muted); text-decoration: none; border-bottom: 1px solid var(--line); }
.usage-link:hover { color: var(--ink); border-color: var(--ink); }
.new-gallery { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 20px; }
.new-gallery input[name='title'] { flex: 1 1 260px; }
.new-gallery input[type='date'] { flex: 0 1 170px; }
.gallery-list { list-style: none; padding: 0; margin: 0; background: var(--card); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.gallery-list li + li { border-top: 1px solid var(--line); }
.gallery-row {
  display: grid;
  grid-template-columns: 64px minmax(0, 1fr) auto;
  gap: 16px;
  align-items: center;
  padding: 12px 18px 12px 12px;
  color: inherit;
  text-decoration: none;
}
.gallery-row:hover { background: #fafafb; }
.row-thumb { width: 64px; height: 64px; border-radius: 8px; background: #ecebf0; overflow: hidden; }
.row-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.row-main { display: grid; gap: 2px; min-width: 0; }
.row-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-meta, .row-stats { color: var(--muted); font-size: 13px; }

/* ---- Settings ---- */
.settings { display: grid; grid-template-columns: 200px minmax(0, 680px); gap: 32px; align-items: start; }
.settings-nav { display: grid; gap: 2px; position: sticky; top: 20px; }
.settings-nav a { padding: 9px 12px; border-radius: 8px; text-decoration: none; color: var(--muted); font-weight: 500; font-size: 14px; }
.settings-nav a:hover { color: var(--ink); background: #efeef2; }
.settings-nav a[aria-current='page'] { color: var(--ink); background: #e7e5eb; }
.settings-body { display: grid; gap: 16px; }
.section-title { font: 400 24px/1.2 var(--display); margin: 0; }
.logo-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-top: 14px; }
.logo-preview { display: grid; place-items: center; min-width: 140px; height: 72px; padding: 10px 16px; border: 1px dashed var(--line); border-radius: 10px; background: #fafafb; }
.logo-preview img { max-height: 52px; max-width: 200px; width: auto; display: block; }
.logo-form label { display: inline-flex; }
.costs { margin: 8px 0 12px; display: grid; gap: 8px; }
.costs div { display: flex; justify-content: space-between; }
.costs dt { color: var(--muted); }
.costs dd { margin: 0; font-variant-numeric: tabular-nums; }
.costs .total { border-top: 1px solid var(--line); padding-top: 8px; font-weight: 600; }
.costs .total dt { color: var(--ink); }
.usage-list { list-style: none; margin: 8px 0 0; padding: 0; }
.usage-list li { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-top: 1px solid var(--line); font-size: 14px; }
.usage-list li:first-child { border-top: 0; }
.account-line { margin: 0 0 14px; }

/* ---- Gallery editor: header ---- */
.back { display: inline-flex; align-items: center; gap: 4px; margin: 0 0 6px -6px; padding: 6px 8px; min-height: 36px; border-radius: 8px; color: var(--muted); text-decoration: none; font-size: 14px; font-weight: 500; }
.back svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.back:hover { color: var(--ink); background: #efeef2; }
.edit-head {
  position: sticky;
  top: 0;
  z-index: 6;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 12px 20px;
  flex-wrap: wrap;
  margin: -12px calc(-1 * var(--gutter)) 14px;
  padding: 12px var(--gutter);
  background: var(--paper);
}
.title-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.edit-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.dirty-note { font-size: 13px; color: var(--warn); }
.btn-solid.is-dirty { box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent); }
.notice { background: #fff6e0; border: 1px solid #f1dfb0; color: #6b4a00; padding: 10px 14px; border-radius: 8px; margin: 0 0 18px; font-size: 14px; }

.share { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin: 0 0 18px; }
.share-url { flex: 1 1 260px; max-width: 420px; color: var(--muted); background: var(--card); }
.share-buttons { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.share-buttons form { display: contents; }
.share-note { margin: 0; flex-basis: 100%; }

/* ---- Gallery editor: tabs ---- */
.edit-tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 22px; }
.edit-tabs a {
  padding: 12px 16px;
  margin-bottom: -1px;
  border-bottom: 2px solid transparent;
  text-decoration: none;
  color: var(--muted);
  font-weight: 600;
  font-size: 15px;
}
.edit-tabs a:hover { color: var(--ink); }
.edit-tabs a[aria-selected='true'] { color: var(--ink); border-bottom-color: var(--ink); }
.tab-count { font-weight: 400; color: var(--muted); margin-left: 4px; }

/* ---- Photos tab: collections ---- */
.col-bar { display: flex; align-items: flex-start; gap: 10px; margin-bottom: 14px; }
.col-tabs { display: flex; gap: 4px; flex-wrap: wrap; align-items: center; flex: 1; min-width: 0; }
.col-tab { padding: 8px 14px; border-radius: 999px; color: var(--ink); text-decoration: none; font-weight: 500; font-size: 14px; white-space: nowrap; }
.col-tab:hover { background: #ecebf0; }
.col-tab[aria-current='page'] { background: var(--ink); color: #fff; }
.col-tab[aria-current='page'] .muted { color: #c9c6cf; }
.col-menu { position: relative; flex: none; }
.col-menu summary { list-style: none; }
.col-menu summary::-webkit-details-marker { display: none; }
.col-menu[open] summary { border-color: var(--ink); }
.col-menu-body {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  z-index: 7;
  width: min(340px, calc(100vw - 32px));
  display: grid;
  gap: 14px;
  padding: 16px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 16px 40px rgba(20, 19, 23, 0.14);
}
.inline-form { display: flex; gap: 6px; }
.inline-form input { min-width: 0; }

/* ---- Uploader ---- */
.dropzone {
  border: 1.5px dashed #c9c6cf;
  border-radius: 12px;
  padding: 24px;
  text-align: center;
  background: var(--card);
  margin-bottom: 18px;
}
.dropzone.over { border-color: var(--accent); background: #f3f2f6; }
.dropzone p { margin: 0 0 4px; }
.dz-buttons { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin: 12px 0 10px !important; }
.dz-buttons label { display: inline-flex; font-weight: 500; }
.upload-status { margin-top: 16px; text-align: left; }
.progress { height: 6px; background: #ecebf0; border-radius: 999px; overflow: hidden; }
.progress-bar { height: 100%; width: 0; background: var(--accent); transition: width 0.2s; }
/* Mouse and touch get different instructions. */
.hint-touch { display: none; }
@media (hover: none) {
  .hint-mouse, .hint-mouse-inline { display: none; }
  .hint-touch { display: inline; }
}

/* ---- Photo grid ---- */
.grid-tools { display: flex; gap: 14px; align-items: baseline; margin: 0 0 10px; flex-wrap: wrap; }
.photo-grid { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.photo-grid li { position: relative; aspect-ratio: 1; background: #ecebf0; border-radius: 8px; overflow: hidden; cursor: pointer; }
.photo-grid img { width: 100%; height: 100%; object-fit: cover; display: block; transition: transform 0.25s var(--ease), border-radius 0.25s; }
.photo-grid li.is-cover::before {
  content: 'Cover';
  position: absolute;
  z-index: 1;
  top: 8px;
  left: 8px;
  background: var(--accent);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 999px;
}
.photo-actions {
  position: absolute;
  inset: auto 0 0 0;
  display: flex;
  justify-content: space-between;
  gap: 4px;
  padding: 8px;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.55), transparent);
  opacity: 0;
  transform: translateY(4px);
  transition: opacity 0.2s, transform 0.3s var(--ease);
}
.chip { font: 600 12px/1 var(--ui); padding: 6px 10px; border-radius: 999px; border: 0; background: rgba(255, 255, 255, 0.92); color: var(--ink); cursor: pointer; }
.chip-select { appearance: none; max-width: 92px; }
@media (hover: hover) {
  .photo-grid li:hover img { transform: scale(1.04); }
  .photo-grid li:hover .photo-actions, .photo-grid li:focus-within .photo-actions { opacity: 1; transform: none; }
}
/* On touch screens, tap selects; the selection bar holds the actions. */
@media (hover: none) {
  .photo-actions { display: none; }
}
.select-box {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 1.5px solid rgba(255, 255, 255, 0.9);
  background: rgba(20, 19, 23, 0.25);
  display: grid;
  place-items: center;
  padding: 0;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.2s, background-color 0.2s, transform 0.15s;
}
.select-box svg { width: 16px; height: 16px; fill: none; stroke: #fff; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; opacity: 0; }
.photo-grid li:hover .select-box, .photo-grid.selecting .select-box, .select-box:focus-visible { opacity: 1; }
.photo-grid li.is-selected .select-box { background: var(--accent); border-color: var(--accent); transform: scale(1.05); }
.photo-grid li.is-selected .select-box svg { opacity: 1; }
.photo-grid li.is-selected img { transform: scale(0.9); border-radius: 6px; }
.photo-grid li.is-selected { background: #dcdae2; }
.select-bar {
  position: sticky;
  top: calc(var(--head-h) + 8px);
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 10px 14px;
  margin-bottom: 12px;
  background: var(--ink);
  color: #fff;
  border-radius: 10px;
  box-shadow: 0 12px 30px rgba(20, 19, 23, 0.18);
}
.select-bar > span { margin-right: auto; }
.select-bar .btn { padding: 8px 12px; min-height: 36px; }
.select-bar .btn-quiet { background: transparent; color: #fff; border-color: rgba(255, 255, 255, 0.3); }
.select-bar .btn-danger { color: #ffb4c0; border-color: rgba(255, 180, 192, 0.4); }

.favs-panel { margin-top: 28px; }
.fav-list { list-style: none; margin: 0 0 12px; padding: 0; }
.fav-list li { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); flex-wrap: wrap; }
.fav-list li:first-child { border-top: 0; }

/* ---- Design tab ---- */
.design-panel { display: grid; gap: 16px; max-width: 880px; }
.design-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 16px; }
.swatches { display: flex; flex-wrap: wrap; gap: 14px; margin-top: 6px; }
.swatch { display: grid; justify-items: center; gap: 6px; cursor: pointer; font-weight: 400; }
.swatch input { position: absolute; opacity: 0; pointer-events: none; }
.swatch-chip {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font: 400 18px/1 var(--display);
  box-shadow: inset 0 0 0 1px rgba(20, 19, 23, 0.12);
  transition: box-shadow 0.2s, transform 0.2s var(--ease);
}
.swatch:hover .swatch-chip { transform: translateY(-2px); }
.swatch input:checked + .swatch-chip { box-shadow: inset 0 0 0 1px rgba(20, 19, 23, 0.12), 0 0 0 3px var(--paper), 0 0 0 5px var(--ink); }
.swatch input:focus-visible + .swatch-chip { outline: 2px solid var(--accent); outline-offset: 6px; }
.swatch-name { font-size: 12px; color: var(--muted); }
.swatch input:checked ~ .swatch-name { color: var(--ink); font-weight: 600; }

/* ---- Settings tab ---- */
.settings-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 16px; align-items: start; }
.danger-zone { margin-top: 24px; }

/* ---- Motion ---- */
.btn, .chip, .col-tab, .topnav a, .edit-tabs a { transition: background-color 0.2s, border-color 0.2s, color 0.2s, filter 0.2s, transform 0.12s; }
.btn:active, .chip:active { transform: scale(0.97); }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}

/* ---- Tablets ---- */
@media (max-width: 900px) {
  .settings { grid-template-columns: 1fr; gap: 18px; }
  .settings-nav { position: static; display: flex; overflow-x: auto; gap: 4px; margin: 0 calc(-1 * var(--gutter)); padding: 0 var(--gutter) 4px; scrollbar-width: none; }
  .settings-nav a { white-space: nowrap; }
}

/* ---- Phones ---- */
@media (max-width: 640px) {
  h1 { font-size: 28px; }
  .page { padding-top: 18px; padding-bottom: 120px; }
  .topbar { gap: 12px; }
  .topnav a { padding: 8px 12px; }
  /* 16px keeps iPhones from zooming into a field when it's tapped. */
  input, textarea, .select { font-size: 16px; }

  .new-gallery input[name='title'] { flex-basis: 100%; }
  .new-gallery input[type='date'] { flex: 1 1 0; }
  .gallery-row { grid-template-columns: 52px minmax(0, 1fr) auto; gap: 12px; padding: 10px 12px 10px 10px; }
  .row-thumb { width: 52px; height: 52px; }
  .row-stats { display: none; }

  /* The editor header scrolls away; Save and Publish move to a bar at the bottom. */
  .edit-head { position: static; margin-bottom: 8px; }
  .edit-actions {
    position: fixed;
    z-index: 8;
    left: 0;
    right: 0;
    bottom: 0;
    padding: 10px 16px calc(10px + env(safe-area-inset-bottom, 0px));
    background: rgba(255, 255, 255, 0.96);
    backdrop-filter: blur(10px);
    border-top: 1px solid var(--line);
    flex-wrap: nowrap;
  }
  .edit-actions .btn { flex: 1; }
  .edit-actions .dirty-note, .edit-actions .saved-note { position: absolute; left: 16px; right: 16px; bottom: calc(100% + 8px); text-align: center; background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; box-shadow: 0 6px 20px rgba(20, 19, 23, 0.1); }
  .is-selecting .edit-actions { display: none; }

  .share-url { display: none; }
  .share-buttons .btn { padding: 10px 12px; }
  .edit-tabs { margin: 0 calc(-1 * var(--gutter)) 18px; padding: 0 var(--gutter); }
  .edit-tabs a { flex: 1; text-align: center; padding: 12px 8px; }

  .col-tabs { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
  .col-tabs::-webkit-scrollbar { display: none; }
  .dropzone { padding: 18px; }

  .photo-grid { grid-template-columns: repeat(3, 1fr); gap: 4px; }
  .photo-grid li { border-radius: 4px; }
  .select-box { opacity: 1; width: 24px; height: 24px; top: 6px; right: 6px; }
  .photo-grid li.is-cover::before { top: 6px; left: 6px; font-size: 10px; padding: 2px 6px; }
  .select-bar {
    position: fixed;
    left: 8px;
    right: 8px;
    top: auto;
    bottom: calc(8px + env(safe-area-inset-bottom, 0px));
    margin: 0;
    z-index: 9;
  }
  .select-bar .select { flex: 1 1 100%; order: 5; }

  .settings-grid { grid-template-columns: 1fr; }
  .card { padding: 18px; }
}
