:root {
  --bg: #f6f1ea;
  --surface: #fffdf9;
  --surface-2: #efe7dc;
  --text: #2d241e;
  --muted: #7a6b5f;
  --chevron: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%237a6b5f' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  --chevron-on-dark: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23f6f1ea' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  --border: #e2d6c7;
  --accent: #a4552f;
  --accent-ink: #ffffff;
  --accent-soft: #f3e0d3;
  --danger: #b3261e;
  --stage-greenware: #7c8b5a;
  --stage-bisque: #c48a5a;
  --stage-glazed: #3f7a8c;
  --stage-done: #6b4b8a;
  --stage-archived: #7a7570;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(60, 40, 20, .06), 0 4px 14px rgba(60, 40, 20, .06);
  --topbar-h: 56px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1714;
    --surface: #25201c;
    --surface-2: #302923;
    --text: #f1e9e0;
    --muted: #a99a8c;
    --chevron: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23a99a8c' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
    --chevron-on-dark: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%231b1714' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
    --border: #3b332c;
    --accent: #d7774a;
    --accent-ink: #1b1714;
    --accent-soft: #3d2a20;
    --danger: #f2867d;
    --stage-greenware: #a4b47c;
    --stage-bisque: #dca57a;
    --stage-glazed: #6fb0c4;
    --stage-done: #b195cf;
    --stage-archived: #a8a29c;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 14px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html, body { margin: 0; }
/* No pinch or double-tap zoom (see the viewport tag and the gesture guard in app.js). */
html { touch-action: pan-x pan-y; -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
  -webkit-tap-highlight-color: transparent;
  min-height: 100vh;
}

button, input, select, textarea { font: inherit; color: inherit; }
/* One drop-down arrow everywhere, with the same room on the right in every browser
   (the native arrow sits hard against the edge in desktop Chrome). */
select {
  -webkit-appearance: none; appearance: none;
  background-image: var(--chevron); background-repeat: no-repeat;
  background-position: right 12px center; background-size: 16px 16px;
  padding-right: 38px !important;
  text-overflow: ellipsis;
}
select::-ms-expand { display: none; }

svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

[hidden] { display: none !important; }

/* Top bar */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 4px;
  height: calc(var(--topbar-h) + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) 8px 0;
  background: var(--accent);
  color: var(--accent-ink);
}
.topbar h1 {
  flex: 1; margin: 0 8px; font-size: 1.2rem; font-weight: 650;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.icon-btn {
  display: grid; place-items: center;
  width: 44px; height: 44px; border: 0; border-radius: 50%;
  background: transparent; color: inherit; cursor: pointer;
}
.icon-btn:active { background: rgba(255, 255, 255, .18); }

main {
  max-width: 760px; margin: 0 auto;
  padding: 12px 16px calc(96px + env(safe-area-inset-bottom));
  outline: none;
}

/* FAB */
.fab {
  position: fixed; right: 20px; bottom: calc(20px + env(safe-area-inset-bottom)); z-index: 20;
  width: 60px; height: 60px; border-radius: 18px; border: 0;
  background: var(--accent); color: var(--accent-ink);
  box-shadow: 0 6px 18px rgba(120, 50, 20, .35);
  display: grid; place-items: center; cursor: pointer;
}
.fab svg { width: 28px; height: 28px; stroke-width: 2.5; }
.fab:active { transform: scale(.96); }
/* Edit form: + (and the camera on Android, above it) at the right of the Photos section */
.photo-section { display: flex; gap: 12px; align-items: flex-start; }
.photo-main { flex: 1; min-width: 0; display: grid; gap: 6px; }
.photo-main .muted { margin: 0; align-self: center; min-height: 48px; display: flex; align-items: center; }
.photo-fabs { flex: none; display: flex; flex-direction: column; align-items: center; gap: 10px; }
.photo-fab {
  width: 48px; height: 48px; border-radius: 14px; display: grid; place-items: center; cursor: pointer;
  background: var(--accent); color: var(--accent-ink); box-shadow: 0 3px 10px rgba(120, 50, 20, .25);
  -webkit-tap-highlight-color: transparent;
}
.photo-fab[hidden] { display: none; }
.photo-fab:active { transform: scale(.95); }
.photo-fab svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.photo-fab.camera-only svg { stroke-width: 2; }
.photo-fab:focus-visible { outline: 3px solid var(--text); outline-offset: 2px; }

/* Toast */
.toast {
  position: fixed; left: 50%; bottom: calc(96px + env(safe-area-inset-bottom)); z-index: 30;
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  max-width: calc(100vw - 32px);
  background: var(--text); color: var(--bg);
  padding: 10px 16px; border-radius: 10px; font-size: .95rem;
  transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast { display: flex; align-items: center; gap: 14px; }
.toast.show.has-action { pointer-events: auto; }
.toast-action { background: none; border: 0; padding: 6px 4px; margin: -6px -4px -6px 0; color: var(--accent-soft); font: inherit; font-weight: 700; cursor: pointer; text-transform: uppercase; letter-spacing: .04em; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 46px; padding: 0 18px; border-radius: 12px;
  border: 1px solid transparent; font-weight: 600; cursor: pointer;
  text-decoration: none;
}
.btn:disabled { opacity: .55; cursor: default; }
.btn-small { min-height: 38px; padding: 0 14px; font-size: .92rem; }
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-secondary { background: var(--accent-soft); color: var(--accent); }
.btn-ghost { background: transparent; color: var(--muted); border-color: var(--border); }
.btn-danger-ghost { background: transparent; color: var(--danger); border-color: var(--border); }
.btn-google { background: #fff; color: #3c4043; border-color: #dadce0; width: 100%; }
.btn-google svg { width: 20px; height: 20px; stroke: none; }

/* List */
.search-row input {
  width: 100%; height: 46px; padding: 0 14px;
  border: 1px solid var(--border); border-radius: 12px;
  background: var(--surface);
}
.chips {
  display: flex; gap: 8px; overflow-x: auto; padding: 12px 0 4px;
  scrollbar-width: none; margin: 0 -16px; padding-left: 16px; padding-right: 16px;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; height: 36px; padding: 0 14px; border-radius: 18px;
  border: 1px solid var(--border); background: var(--surface); cursor: pointer;
  font-size: .92rem; white-space: nowrap;
}
.chip[aria-selected="true"] { background: var(--text); color: var(--bg); border-color: var(--text); }
.chip .n { opacity: .6; margin-left: 4px; }
.count { color: var(--muted); font-size: .88rem; margin: 8px 2px; }

.cards { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.card {
  background: var(--surface); border-radius: var(--radius); overflow: hidden;
  box-shadow: var(--shadow); cursor: pointer; display: flex; flex-direction: column;
  border: 0; padding: 0; text-align: left; width: 100%;
}
.card .thumb {
  aspect-ratio: 1; background: var(--surface-2); display: grid; place-items: center;
  color: var(--muted); overflow: hidden;
}
.card .thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.card .thumb svg { width: 40px; height: 40px; opacity: .5; stroke-width: 1.5; }
.card .meta { padding: 10px 12px 12px; display: grid; gap: 6px; }
.card .title { font-weight: 600; line-height: 1.25; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.card .sub { color: var(--muted); font-size: .82rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.stage-pill {
  display: inline-flex; align-items: center; gap: 6px; justify-self: start;
  font-size: .78rem; font-weight: 600; padding: 3px 9px; border-radius: 999px;
  background: color-mix(in srgb, var(--c) 16%, transparent); color: var(--c);
}
.stage-pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--c); }
.st-greenware { --c: var(--stage-greenware); }
.st-bisque { --c: var(--stage-bisque); }
.st-glazed { --c: var(--stage-glazed); }
.st-done { --c: var(--stage-done); }
.st-archived { --c: var(--stage-archived); }

.empty { text-align: center; padding: 48px 16px; color: var(--muted); }
.empty h2 { color: var(--text); margin: 12px 0 4px; }
.empty-pot svg { width: 72px; height: 72px; stroke: var(--accent); stroke-width: 2.5; }

/* Detail */
.detail-view { margin: -12px -16px 0; }
.gallery {
  display: flex; overflow-x: auto; scroll-snap-type: x mandatory; background: var(--surface-2);
  scrollbar-width: none;
}
.gallery::-webkit-scrollbar { display: none; }
.gallery img { flex: none; width: 100%; max-height: 62vh; aspect-ratio: 4 / 3; object-fit: cover; scroll-snap-align: center; cursor: zoom-in; }
.gallery.single img { aspect-ratio: auto; object-fit: contain; max-height: 62vh; }
.gallery .no-photo { width: 100%; height: 160px; display: grid; place-items: center; color: var(--muted); }
.gallery-wrap { position: relative; }
.gallery-nav { position: absolute; top: 50%; transform: translateY(-50%); width: 40px; height: 40px; border-radius: 50%; border: 0; display: grid; place-items: center; background: rgba(0, 0, 0, .45); color: #fff; cursor: pointer; padding: 0; }
.gallery-nav:hover { background: rgba(0, 0, 0, .65); }
.gallery-nav:disabled { opacity: 0; pointer-events: none; }
.gallery-nav svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.gallery-nav.prev { left: 10px; }
.gallery-nav.next { right: 10px; }
.gallery-add { display: flex; justify-content: center; flex-wrap: wrap; gap: 8px; padding: 10px 16px 0; }
.gallery-dots { display: flex; justify-content: center; gap: 6px; padding: 8px 0 0; }
.gallery-dots span { width: 6px; height: 6px; border-radius: 50%; background: var(--border); }
.gallery-dots span.on { background: var(--accent); }
.detail-body { padding: 12px 16px; }
.detail-head { display: flex; align-items: flex-start; gap: 12px; justify-content: space-between; }
.detail-head h2 { margin: 4px 0 0; font-size: 1.45rem; line-height: 1.2; }
.detail-head .stage-pill { margin-top: 8px; flex: none; }

.stage-track { list-style: none; display: grid; grid-template-columns: repeat(5, 1fr); gap: 4px; padding: 0; margin: 18px 0 12px; }
.stage-track li { text-align: center; font-size: .75rem; color: var(--muted); }
.stage-track li::before { content: ""; display: block; height: 6px; border-radius: 3px; background: var(--border); margin-bottom: 6px; }
.stage-track li.reached::before { background: var(--accent); }
.stage-track li.current { color: var(--text); font-weight: 600; }

.facts { display: grid; grid-template-columns: auto 1fr; gap: 10px 16px; margin: 20px 0; background: var(--surface); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.facts dt { color: var(--muted); font-size: .9rem; }
.facts dd { margin: 0; overflow-wrap: anywhere; }
.facts .glaze-list { display: flex; flex-wrap: wrap; gap: 6px; }
.facts .glaze-list span { background: var(--surface-2); border-radius: 8px; padding: 1px 8px; font-size: .9rem; }
.notes { white-space: pre-wrap; background: var(--surface); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); margin-top: 0; overflow-wrap: anywhere; }
.detail-body h3 { font-size: .95rem; color: var(--muted); margin: 20px 0 8px; font-weight: 600; }
.detail-actions { display: flex; gap: 10px; margin-top: 24px; }
.detail-actions .btn-primary { flex: 1; }
/* Edit: a round pencil pinned just under the top bar (and under the Reconnect or offline bar
   when one shows), at the right edge of the content, so it never needs a scroll. It sits over
   the photo's top corner, clear of the back button and the carousel arrows (centred vertically). */
.edit-float {
  position: fixed; z-index: 20;
  top: calc(var(--topbar-h) + env(safe-area-inset-top) + var(--bars-h, 0px) + 12px);
  right: calc(env(safe-area-inset-right) + 12px);
  width: 52px; height: 52px; border-radius: 50%; border: 0; padding: 0;
  background: var(--accent); color: var(--accent-ink);
  box-shadow: 0 4px 14px rgba(120, 50, 20, .35);
  display: grid; place-items: center; cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.edit-float[hidden] { display: none; }
.edit-float svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.edit-float:active { transform: scale(.94); }
.edit-float:focus-visible { outline: 3px solid var(--text); outline-offset: 2px; }

/* Lightbox */
.lightbox { position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.92); display: grid; place-items: center; }
.lightbox img { max-width: 100vw; max-height: 100vh; object-fit: contain; }
.lightbox button { position: absolute; top: calc(8px + env(safe-area-inset-top)); right: 8px; color: #fff; }

/* Edit form */
.edit-view { display: grid; grid-template-columns: minmax(0, 1fr); gap: 18px; }
.field { display: grid; gap: 6px; border: 0; padding: 0; margin: 0; min-width: 0; }
.field > span, .field > legend { font-size: .9rem; font-weight: 600; color: var(--muted); padding: 0; margin-bottom: 6px; }
fieldset.field > legend { margin-bottom: 6px; }
.field input:not([type=radio]):not([type=file]), .field select, .field textarea, .tag-input-row input {
  width: 100%; min-height: 46px; padding: 10px 12px;
  border: 1px solid var(--border); border-radius: 12px; background-color: var(--surface);
}
.field textarea { resize: vertical; min-height: 110px; }
.field input:focus, .field select:focus, .field textarea:focus, .tag-input-row input:focus, .search-row input:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.field-row { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); gap: 12px; }
.field select { max-width: 100%; min-width: 0; text-overflow: ellipsis; }
.tag { max-width: 100%; overflow-wrap: anywhere; }

.segmented { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; background: var(--surface-2); padding: 4px; border-radius: 12px; gap: 4px; }
.segmented label { position: relative; }
.segmented input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.segmented span { display: grid; place-items: center; min-height: 40px; border-radius: 9px; font-size: .92rem; font-weight: 500; color: var(--muted); padding: 0 4px; text-align: center; }
.segmented input:checked + span { background: var(--surface); color: var(--text); font-weight: 650; box-shadow: var(--shadow); }
.segmented input:focus-visible + span { outline: 2px solid var(--accent); }

.dates-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 12px; }
.dates-grid label { display: grid; gap: 4px; font-size: .85rem; color: var(--muted); min-width: 0; }
.dates-grid input { width: 100%; min-height: 44px; padding: 8px 10px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); min-width: 0; }

.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(88px, 1fr)); gap: 8px; }
.photo-grid:empty { display: none; }
.photo-item { position: relative; aspect-ratio: 1; border-radius: 10px; overflow: hidden; background: var(--surface-2); }
.photo-item img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo-item .remove {
  position: absolute; top: 4px; right: 4px; width: 30px; height: 30px; border-radius: 50%;
  border: 0; background: rgba(0,0,0,.6); color: #fff; display: grid; place-items: center; cursor: pointer;
}
.photo-item .remove svg { width: 16px; height: 16px; }
.photo-item .cover { position: absolute; left: 4px; bottom: 4px; font-size: .7rem; background: rgba(0,0,0,.6); color: #fff; padding: 1px 6px; border-radius: 6px; }
.photo-item.pending { display: grid; place-items: center; color: var(--muted); font-size: .8rem; }
.photo-add { justify-self: start; display: flex; flex-wrap: wrap; gap: 8px; }
.photo-add .btn { cursor: pointer; }

.tags { display: flex; flex-wrap: wrap; gap: 6px; }
.tags:empty { display: none; }
.tag { display: inline-flex; align-items: center; gap: 4px; background: var(--accent-soft); color: var(--accent); border-radius: 999px; padding: 4px 4px 4px 12px; font-size: .92rem; font-weight: 500; }
.tag button { width: 26px; height: 26px; border-radius: 50%; border: 0; background: transparent; color: inherit; display: grid; place-items: center; cursor: pointer; }
.tag button svg { width: 14px; height: 14px; }
.tag-input-row { display: flex; gap: 8px; }
.tag-input-row input { flex: 1; min-width: 0; }

.form-actions { display: flex; gap: 10px; position: sticky; bottom: 0; padding: 12px 0 calc(12px + env(safe-area-inset-bottom)); background: linear-gradient(transparent, var(--bg) 30%); }
.form-actions .btn { flex: 1; }

/* Save in the top bar (edit screens) */
.header-save { flex: none; margin-right: 4px; background: var(--accent-ink); color: var(--accent); font-weight: 650; }
.header-save:disabled { opacity: .6; }

/* Purpose and Type side by side */
.field-row-even { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.field-row-even .pick-row { flex-wrap: wrap; }
.slot { display: contents; }

/* Stage sections: fold open and shut */
.form-section.stage-section { display: block; min-width: 0; padding: 0; border-left: 4px solid var(--c); }
.stage-section > summary {
  display: flex; align-items: baseline; gap: 10px; padding: 14px; cursor: pointer; list-style: none;
  font-weight: 650; min-height: 48px; user-select: none;
}
.stage-section > summary::-webkit-details-marker { display: none; }
.stage-section > summary::after {
  content: ""; flex: none; width: 18px; height: 18px; margin-left: auto; align-self: center;
  background: var(--chevron) center / 18px no-repeat; transition: transform .15s;
}
.stage-section[open] > summary::after { transform: rotate(180deg); }
.stage-section > summary:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; border-radius: 14px; }
.sec-title { flex: none; }
.stage-section > summary { min-width: 0; }
.sec-sum { color: var(--muted); font-weight: 400; font-size: .88rem; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stage-section[open] .sec-sum { display: none; }
.sec-body { display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; padding: 0 14px 14px; }
.date-field input { max-width: 14em; }

/* Backup */
.switch-row { display: flex; align-items: center; gap: 12px; margin: 12px 0; cursor: pointer; position: relative; }
.switch-row input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch { flex: none; width: 44px; height: 26px; border-radius: 13px; background: var(--border); position: relative; transition: background .15s; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: transform .15s; }
.switch-row input:checked + .switch { background: var(--accent); }
.switch-row input:checked + .switch::after { transform: translateX(18px); }
.switch-row input:focus-visible + .switch { outline: 2px solid var(--accent); outline-offset: 2px; }
#backupNavBtn { position: relative; }
#backupNavBtn.dirty::after { content: ""; position: absolute; top: 9px; right: 9px; width: 9px; height: 9px; border-radius: 50%; background: #f6d36b; box-shadow: 0 0 0 2px var(--accent); }
#backupNavBtn.syncing svg { animation: spin 2s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { 50% { opacity: .35; } }
@media (prefers-reduced-motion: reduce) { #backupNavBtn.syncing svg { animation: none; opacity: .6; } }
.folder-box { margin: 14px 0 10px; padding: 12px; border: 1px solid var(--border); border-radius: 12px; display: grid; gap: 10px; }
.folder-row { display: flex; align-items: center; gap: 10px; min-width: 0; }
.folder-row svg { flex: none; color: var(--accent); }
.folder-text { display: grid; min-width: 0; }
.folder-text strong { overflow-wrap: anywhere; }
.folder-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.new-folder { display: grid; gap: 8px; padding-top: 10px; border-top: 1px solid var(--border); }
.new-folder p { margin: 0; }
.backup-view { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; }
.panel { background: var(--surface); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.panel h2 { margin: 0 0 6px; font-size: 1.15rem; }
.muted { color: var(--muted); }
.small { font-size: .88rem; }
.center { text-align: center; }
.center a { color: inherit; }
.list-view > .support-line { margin: 28px 0 8px; }
.warn { background: var(--accent-soft); color: var(--accent); padding: 10px 12px; border-radius: 10px; }
.warn code { font-size: .9em; }
.account { font-weight: 600; margin: 12px 0 2px; overflow-wrap: anywhere; }
.btn-col { display: grid; gap: 10px; margin-top: 14px; }
.progress { position: relative; height: 28px; border-radius: 8px; background: var(--surface-2); overflow: hidden; margin-top: 12px; }
.progress-bar { position: absolute; inset: 0 auto 0 0; width: 0; background: var(--accent-soft); transition: width .2s; }
.progress span { position: relative; display: block; line-height: 28px; padding: 0 10px; font-size: .85rem; }

@media (min-width: 640px) {
  .cards { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
  .detail-view { margin: 0; }
  .gallery { border-radius: var(--radius); }
  .edit-float { right: max(28px, calc((100vw - 760px) / 2 + 28px)); }
}

@media (max-width: 360px) {
  .field-row:not(.field-row-even), .dates-grid { grid-template-columns: minmax(0, 1fr); }
  .segmented-5 span { font-size: .8rem; padding: 0 2px; }
}

/* "Add to home screen" tip on phones */
.install-tip { display: flex; gap: 12px; align-items: flex-start; background: var(--accent-soft); color: var(--text); border-radius: var(--radius); padding: 12px 8px 12px 14px; margin-bottom: 12px; }
.install-tip img { width: 40px; height: 40px; border-radius: 10px; flex: none; }
.install-tip .tip-body { flex: 1; min-width: 0; }
.install-tip .tip-title { display: block; margin-bottom: 2px; }
.install-tip p { margin: 0; font-size: .92rem; color: var(--muted); }
.install-tip .tip-glyph { display: inline-block; vertical-align: -3px; width: 16px; height: 16px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.install-tip .btn { margin-top: 8px; }
.install-tip.tip-warn { background: var(--surface); border: 1px solid var(--danger); box-shadow: inset 4px 0 0 var(--danger); }
.install-tip.tip-warn .tip-title { color: var(--danger); }
.install-tip.tip-warn p + p { margin-top: 6px; }
.install-tip .icon-btn { flex: none; margin: -6px 0 0; color: var(--muted); }

/* Field filters on the home screen */
.search-row { display: flex; gap: 8px; align-items: center; }
.search-row input { flex: 1; min-width: 0; }
.filter-btn { position: relative; flex: none; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 12px; }
.filter-btn .badge { position: absolute; top: -4px; right: -4px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--accent); color: var(--accent-ink); font-size: .72rem; font-weight: 700; display: grid; place-items: center; }
.field-filters { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 10px; scrollbar-width: none; }
.field-filters::-webkit-scrollbar { display: none; }
.field-filters select { flex: none; max-width: 70vw; min-height: 36px; padding: 0 28px 0 12px; border-radius: 18px; border: 1px solid var(--border); background-color: var(--surface); color: var(--text); font: inherit; font-size: .9rem; }
.field-filters select.active { background-color: var(--text); color: var(--bg); border-color: var(--text); background-image: var(--chevron-on-dark); }
.field-filters .clear { flex: none; min-height: 36px; padding: 0 12px; border-radius: 18px; border: 0; background: transparent; color: var(--accent); font: inherit; font-size: .9rem; font-weight: 600; cursor: pointer; }

/* Pop-up sheet */
dialog.sheet { border: 0; border-radius: 18px; padding: 20px; width: min(440px, calc(100vw - 32px)); max-height: calc(100vh - 64px); background: var(--surface); color: var(--text); box-shadow: 0 10px 40px rgba(0, 0, 0, .25); }
dialog.sheet::backdrop { background: rgba(20, 14, 10, .45); }
dialog.sheet h2 { margin: 0 0 4px; font-size: 1.15rem; }
dialog.ask .ask-text { margin: 8px 0; line-height: 1.45; }
dialog.ask .ask-list { margin: 8px 0; padding-left: 20px; line-height: 1.5; }
dialog.ask .ask-actions { position: static; padding-bottom: 0; background: none; margin-top: 14px; }
.btn-danger { background: var(--danger); color: var(--bg); }
.check-list { display: grid; gap: 2px; margin: 12px 0; }
.check-list label { display: flex; align-items: center; gap: 12px; min-height: 44px; padding: 0 4px; border-radius: 10px; cursor: pointer; }
.check-list input { width: 20px; height: 20px; accent-color: var(--accent); }
.check-list .type { margin-left: auto; color: var(--muted); font-size: .85rem; }
.check-list h3 { margin: 10px 4px 2px; font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }

/* Custom fields: settings list and edit form */
.cf-list { list-style: none; margin: 12px 0; padding: 0; display: grid; grid-template-columns: minmax(0, 1fr); gap: 6px; }
.cf-list li { display: flex; align-items: center; gap: 10px; padding: 8px 4px 8px 12px; border: 1px solid var(--border); border-radius: 12px; }
#cfList li { padding-left: 2px; gap: 6px; background: var(--surface); }
.drag-handle { flex: none; width: 32px; height: 38px; display: grid; place-items: center; border: 0; background: none; color: var(--muted); cursor: grab; touch-action: none; padding: 0; border-radius: 8px; }
.drag-handle svg { width: 18px; height: 18px; fill: currentColor; stroke: none; }
.drag-handle:focus-visible { outline: 2px solid var(--accent); }
#cfList li.dragging { box-shadow: 0 6px 18px rgba(0, 0, 0, .18); border-color: var(--accent); position: relative; z-index: 2; }
#cfList li.dragging .drag-handle { cursor: grabbing; }
.cf-list .cf-name { font-weight: 600; }
.cf-list .cf-meta { color: var(--muted); font-size: .88rem; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cf-list .icon-btn { flex: none; width: 38px; height: 38px; color: var(--muted); }
.cf-list .icon-btn svg { width: 18px; height: 18px; }
.cf-add { display: grid; gap: 12px; }
.cf-list li.editing { display: block; padding: 12px; }
.cf-edit { display: grid; gap: 12px; }
.cf-edit textarea { min-height: 96px; }
.cf-edit-actions { display: flex; gap: 8px; }
.cf-add .yesno, .cf-edit .yesno { display: flex; align-items: center; gap: 10px; min-height: 36px; }
.cf-add .yesno b, .cf-edit .yesno b { font-weight: 500; }
.cf-add .btn { justify-self: start; }
.custom-fields { display: grid; gap: 18px; }
.custom-fields:empty { display: none; }
.custom-fields .yesno, .edit-view .yesno { display: flex; align-items: center; gap: 10px; min-height: 44px; }
.field .yesno input[type=checkbox] { width: 22px; height: 22px; min-height: 0; padding: 0; margin: 0; flex: none; accent-color: var(--accent); }
.custom-fields .yesno b, .edit-view .yesno b { font-weight: 500; }

/* "Google Drive got disconnected" bar under the top bar */
.conn-bar { position: sticky; top: calc(var(--topbar-h) + env(safe-area-inset-top)); z-index: 9; display: flex; align-items: center; gap: 12px; padding: 10px 16px; background: #f6d36b; color: #3a2a10; font-size: .92rem; }
.conn-bar span { flex: 1; min-width: 0; }
.offline-note { position: sticky; top: calc(var(--topbar-h) + env(safe-area-inset-top)); z-index: 9; display: flex; align-items: center; gap: 8px; padding: 7px 16px; background: var(--surface); border-bottom: 1px solid var(--border); color: var(--muted); font-size: .86rem; }
.offline-note svg { flex: none; width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.conn-bar .btn { flex: none; background: #3a2a10; color: #fff; border: 0; }

/* Glaze and clay pickers (edit form) and list editors (settings) */
.tag-picker { display: grid; gap: 8px; }
.tag-picker .tags:empty { display: none; }
.pick-row { display: flex; gap: 8px; }
.pick-row > * { min-width: 0; }
.pick-row select, .pick-row input { flex: 1; }
.pick-row .btn { flex: none; }
.list-head { margin: 18px 0 4px; font-size: .95rem; }
.list-add { display: flex; gap: 8px; }
.list-add input { flex: 1; min-width: 0; width: 0; height: 44px; padding: 0 12px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); color: var(--text); font: inherit; }
.list-add select, .cf-list select { height: 44px; padding: 0 8px; border: 1px solid var(--border); border-radius: 12px; background-color: var(--surface); color: var(--text); font: inherit; flex: none; width: 7.5em; }
.cf-list select { height: 36px; }

/* Bisque and glaze sections of the edit form */
.form-section { display: grid; gap: 14px; padding: 14px; border: 1px solid var(--border); border-radius: 16px; }
.form-section > h3 { margin: 0; font-size: 1rem; }

/* Picking the thumbnail photo in Edit */
.photo-item .pick-thumb { display: block; width: 100%; height: 100%; padding: 0; border: 0; background: none; cursor: pointer; }
.photo-item.is-cover { outline: 3px solid var(--accent); outline-offset: -3px; }

/* Photo storage limit in Settings */
.storage-limit select { max-width: 220px; }
.meter { height: 8px; border-radius: 999px; background: var(--surface-2); overflow: hidden; margin: 10px 0 6px; }
.meter > div { height: 100%; width: 0; background: var(--accent); border-radius: inherit; transition: width .3s; }
.meter.full > div { background: var(--danger); }

/* Square */
.btn-square { display: flex; width: 100%; margin: 12px 0 4px; background: #1a1a1a; color: #fff; }
.btn-square:active { background: #333; }
.fact-link { color: var(--accent); font-weight: 600; }
.icon-btn-space { flex: none; width: 38px; }
.square-toggle { display: flex; align-items: center; gap: 10px; min-height: 44px; margin: 4px 0; }
.square-toggle input { width: 20px; height: 20px; accent-color: var(--accent); }
.square-toggle b { font-weight: 600; }
#squarePanel code { overflow-wrap: anywhere; }
.square-note { position: fixed; left: 16px; right: 16px; bottom: 16px; z-index: 50; max-width: 520px; margin: 0 auto; padding: 14px 16px; border-radius: 14px; background: var(--surface); color: var(--text); border: 1px solid var(--border); box-shadow: 0 10px 40px rgba(0, 0, 0, .25); }
.square-note p { margin: 0 0 10px; }
.money-row { display: flex; gap: 8px; }
.money-row input { flex: 1; min-width: 0; }
.money-row select { flex: none; width: 7.5em; }

/* Glaze glazingProcesses */
.optional { font-style: normal; font-weight: 400; opacity: .8; }
.process-box { display: grid; gap: 10px; }
.process-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.process-actions p { margin: 0; }
.process-card { display: flex; gap: 12px; align-items: flex-start; padding: 10px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); text-align: left; width: 100%; color: inherit; font: inherit; }
button.process-card { cursor: pointer; }
button.process-card:hover, button.process-card:focus-visible { border-color: var(--accent); }
button.process-card.match { box-shadow: inset 4px 0 0 var(--accent); }
.process-meta { display: grid; gap: 2px; min-width: 0; flex: 1; }
.process-meta strong { overflow-wrap: anywhere; }
.process-meta .sub { color: var(--muted); font-size: .86rem; }
.process-notes { white-space: pre-wrap; margin: 4px 0 0; color: var(--muted); font-size: .88rem; overflow-wrap: anywhere; }
.process-thumb { flex: none; width: 60px; height: 60px; border-radius: 10px; overflow: hidden; background: var(--surface-2); display: grid; place-items: center; color: var(--muted); }
.process-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.process-thumb svg { width: 30px; height: 30px; opacity: .5; stroke-width: 1.5; }
.process-thumb.big { width: 88px; height: 88px; }
.process-list .process-thumb { width: 44px; height: 44px; }
.process-list li { padding-left: 6px; }
.process-list .cf-meta { white-space: normal; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.process-list .cf-text { display: grid; flex: 1; min-width: 0; }
.tag.locked { padding-right: 12px; }
.process-sheet .process-choices { display: grid; gap: 8px; margin: 12px 0; max-height: 58vh; overflow: auto; }
.process-sheet .field { margin-top: 12px; }
.process-thumb-row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.photo-pick { max-height: 60vh; overflow: auto; margin: 10px 0; display: grid; gap: 6px; }
.photo-pick h3 { margin: 10px 0 4px; font-size: .9rem; }
.photo-pick .photo-item button { display: block; width: 100%; height: 100%; padding: 0; border: 0; background: none; cursor: pointer; }
.photo-pick .photo-item.chosen { outline: 3px solid var(--accent); outline-offset: -3px; }
.photo-pick .default-pick { justify-self: start; }
.photo-pick .default-pick[aria-pressed="true"] { outline: 2px solid var(--accent); }
.process-fact { display: flex; gap: 10px; align-items: flex-start; }
.photo-pick p:empty { display: none; }

/* Selecting several pieces */
.count-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.select-links { display: flex; gap: 16px; }
.link-btn { background: none; border: 0; padding: 8px 2px; color: var(--accent); font: inherit; font-size: .9rem; font-weight: 600; cursor: pointer; }
.card { position: relative; -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; }
.card .check {
  position: absolute; top: 8px; left: 8px; width: 26px; height: 26px; border-radius: 50%;
  border: 2px solid #fff; background: rgba(0, 0, 0, .25); box-shadow: 0 1px 4px rgba(0, 0, 0, .3);
  display: none; place-items: center; color: #fff;
}
.card .check svg { width: 16px; height: 16px; stroke-width: 3; opacity: 0; }
.selecting .card .check { display: grid; }
.card.selected { outline: 3px solid var(--accent); outline-offset: -3px; }
.card.selected .check { background: var(--accent); border-color: var(--accent); }
.card.selected .check svg { opacity: 1; }
.card.selected .thumb { opacity: .85; }
.selecting main, main:has(.selecting) { padding-bottom: calc(110px + env(safe-area-inset-bottom)); }
.select-bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 25;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: var(--surface); border-top: 1px solid var(--border); box-shadow: 0 -4px 14px rgba(60, 40, 20, .08);
}
.select-bar[hidden] { display: none; }
.select-count { flex: 1; min-width: 0; font-weight: 600; font-size: .95rem; }
.select-exit { flex: none; width: 40px; height: 40px; margin: -4px 0 -4px -8px; color: var(--muted); }
.select-exit svg { width: 22px; height: 22px; }
.select-exit:active { background: var(--border); }
.select-actions { display: flex; gap: 8px; }
.select-actions .btn-square { width: auto; margin: 0; }
.selecting ~ .toast, body:has(.select-bar:not([hidden])) .toast { bottom: calc(84px + env(safe-area-inset-bottom)); }

/* Editing several pieces */
.conflict { color: var(--danger); font-size: .85rem; margin: 2px 0 0; }
.conflict[hidden] { display: none; }
.sale-list { list-style: none; margin: 8px 0; padding: 0; max-height: 40vh; overflow: auto; }
.sale-list li { display: flex; justify-content: space-between; gap: 12px; padding: 6px 0; border-bottom: 1px solid var(--border); }
.sale-list .sale-total { font-weight: 700; border-bottom: 0; }
