:root {
  --bg: #fffaf3;
  --card: #ffffff;
  --ink: #1f1a17;
  --muted: #6b625c;
  --line: #eadfd3;
  --accent: #c2410c;
  --danger: #b91c1c;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--bg);
}

* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; padding-bottom: 96px; }

.bar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 8px;
  padding: 12px 16px; padding-top: max(12px, env(safe-area-inset-top));
  background: var(--accent); color: #fff;
}
.bar h1 { flex: 1; margin: 0; font-size: 1.2rem; font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn, .text-btn {
  background: transparent; border: 0; color: inherit; font: inherit; cursor: pointer;
  padding: 6px 10px; border-radius: 8px;
}
.icon-btn { font-size: 1.3rem; }
.text-btn { border: 1px solid rgba(255,255,255,.6); }

main { max-width: 720px; margin: 0 auto; padding: 16px; }

#search {
  width: 100%; padding: 12px 14px; font: inherit;
  border: 1px solid var(--line); border-radius: 12px; background: var(--card);
}

.grid { list-style: none; padding: 0; margin: 16px 0 0;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: 14px;
  overflow: hidden; cursor: pointer; display: flex; flex-direction: column;
}
.card img, .card .placeholder {
  width: 100%; aspect-ratio: 3 / 4; object-fit: cover; object-position: top;
  background: #f3ebe2; display: block;
}
.card .placeholder { display: grid; place-items: center; font-size: 2.5rem; }
.card span { padding: 10px 12px; font-weight: 500; line-height: 1.3; }
.card span.untitled { color: var(--muted); font-style: italic; font-weight: 400; }

.empty { text-align: center; color: var(--muted); margin-top: 48px; }

#edit-view { display: flex; flex-direction: column; gap: 14px; }
#edit-view[hidden] { display: none; }
#edit-image { width: 100%; border-radius: 14px; border: 1px solid var(--line); }
.extract-bar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 10px 12px; border-radius: 10px; background: #fdeee4; color: var(--ink); font-size: .9rem; }
.extract-bar[hidden] { display: none; }
.extract-bar span { flex: 1; }
.extract-bar.busy span::after { content: ' ⏳'; }
.passcode-form { display: flex; gap: 8px; width: 100%; }
.passcode-form[hidden] { display: none; }
.passcode-form input { flex: 1; min-width: 0; font: inherit; padding: 8px 10px;
  border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.passcode-form button { font: inherit; font-weight: 600; padding: 8px 14px; border: 0; border-radius: 8px; cursor: pointer; }
.text-link { background: none; border: 0; padding: 0; font: inherit; font-weight: 600;
  color: var(--accent); cursor: pointer; text-decoration: underline; }
.text-link:disabled { opacity: .5; cursor: default; }
label { display: flex; flex-direction: column; gap: 6px; font-weight: 600; font-size: .9rem; }
input[type=text], textarea {
  font: inherit; font-weight: 400; padding: 10px 12px;
  border: 1px solid var(--line); border-radius: 10px; background: var(--card); resize: vertical;
}
.actions { display: flex; gap: 10px; }
.actions button { flex: 1; padding: 12px; font: inherit; font-weight: 600;
  border-radius: 12px; border: 0; cursor: pointer; }
.primary { background: var(--accent); color: #fff; }
.danger { background: transparent; color: var(--danger); border: 1px solid var(--danger) !important; }

.fab-wrap { position: fixed; left: 0; right: 0; bottom: 0; display: flex; justify-content: center;
  padding: 16px; padding-bottom: max(16px, env(safe-area-inset-bottom)); pointer-events: none; }
.fab-wrap[hidden] { display: none; }
.fab {
  pointer-events: auto; background: var(--accent); color: #fff; font-weight: 600;
  padding: 14px 22px; border-radius: 999px; box-shadow: 0 6px 20px rgba(194,65,12,.35); cursor: pointer;
}
