:root {
  --ink: #15181e;
  --muted: #5e6573;
  --line: #e2e5ea;
  --bg: #f5f6f8;
  --card: #ffffff;
  --accent: #1f5ad1;
  --accent-ink: #ffffff;
  --danger: #c4302b;
  --warn-bg: #fff6e0;
  --warn-ink: #7a5300;
  color-scheme: light;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 400 16px/1.5 Inter, system-ui, sans-serif;
}

.top {
  background: var(--card);
  border-bottom: 1px solid var(--line);
  padding: 14px max(16px, calc((100% - 720px) / 2 + 16px));
  padding-top: max(14px, env(safe-area-inset-top));
}
.brand { color: var(--ink); font-weight: 700; font-size: 17px; text-decoration: none; }

main {
  max-width: 720px;
  margin: 0 auto;
  padding: 20px 16px 40px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
main > .btn.ghost { align-self: flex-start; margin-left: -10px; }

h1 { font-size: 24px; line-height: 30px; font-weight: 700; margin: 0; }
.count { color: var(--muted); font-weight: 500; }
.hint, .note, .none { color: var(--muted); margin: 0; font-size: 15px; }
.note { font-size: 14px; }

.row { display: flex; gap: 8px; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }

/* Buttons: icon and label always side by side. */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 16px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--card);
  color: var(--ink);
  font: 600 15px/1 Inter, system-ui, sans-serif;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
}
.btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.danger-text { color: var(--danger); }
.btn.ghost { border-color: transparent; background: none; padding: 0 10px; }
.btn.small { min-height: 32px; padding: 0 10px; font-size: 13px; gap: 4px; }
.btn.small svg { width: 14px; height: 14px; }
.btn:disabled { opacity: .5; cursor: default; }
.btn:focus-visible, .search:focus-visible, .field input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Empty library. */
.empty { text-align: center; padding: 48px 8px; display: flex; flex-direction: column; align-items: center; gap: 12px; }
.empty p { color: var(--muted); margin: 0 0 8px; }

/* Library list. */
.search {
  width: 100%;
  height: 44px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--card);
  font: inherit;
  color: inherit;
}
.list { list-style: none; margin: 0; padding: 0; background: var(--card); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.list li + li { border-top: 1px solid var(--line); }
.list a { display: flex; flex-direction: column; padding: 12px 16px; color: inherit; text-decoration: none; }
.list a:hover { background: var(--bg); }
.name { font-weight: 600; overflow-wrap: anywhere; }
.desc { color: var(--muted); font-size: 14px; }

/* Photos, numbered in reading order. */
.photos { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; }
.photos li { position: relative; display: flex; flex-direction: column; gap: 6px; }
.thumb { padding: 0; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: var(--card); cursor: zoom-in; aspect-ratio: 4 / 3; }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.num { position: absolute; top: 6px; left: 6px; min-width: 24px; height: 24px; border-radius: 12px; background: var(--ink); color: #fff; font-size: 13px; font-weight: 600; display: grid; place-items: center; }

.status { display: flex; align-items: center; gap: 10px; margin: 0; color: var(--muted); }
.spin { width: 18px; height: 18px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.error { margin: 0; color: var(--danger); font-weight: 500; }
.warn { margin: 0; padding: 10px 14px; border-radius: 10px; background: var(--warn-bg); color: var(--warn-ink); font-size: 15px; }

/* Phrase. */
.field { display: flex; flex-direction: column; gap: 6px; }
.field span { font-size: 13px; font-weight: 600; color: var(--muted); }
.field input {
  height: 44px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--card);
  font: inherit;
  color: inherit;
}
#name { font-weight: 600; }

.editor {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 16px;
  font-size: 15px;
  line-height: 1.5;
  overflow-wrap: anywhere;
  outline: none;
}
.editor:focus { border-color: var(--accent); }
.editor p { margin: 0; min-height: 1.5em; }
.editor ol, .editor ul { margin: 0; padding-left: 28px; }

.actions {
  position: sticky;
  bottom: 0;
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin: 0 -16px -40px;
  padding: 12px 16px;
  padding-bottom: max(12px, env(safe-area-inset-bottom));
  background: var(--card);
  border-top: 1px solid var(--line);
}
.actions .primary { flex: 0 1 220px; }

/* Dialogs and toast. */
dialog { border: 0; border-radius: 14px; padding: 20px; max-width: min(420px, calc(100vw - 32px)); box-shadow: 0 12px 40px rgba(0, 0, 0, .2); }
dialog::backdrop { background: rgba(20, 24, 30, .45); }
dialog p { margin: 0 0 20px; }
#confirm-name { margin-bottom: 4px; font-weight: 600; overflow-wrap: anywhere; }
#viewer { max-width: calc(100vw - 32px); max-height: calc(100vh - 32px); padding: 12px; }
#viewer img { display: block; max-width: 100%; max-height: calc(100vh - 120px); margin-bottom: 12px; border-radius: 8px; }

#toast {
  position: fixed;
  left: 50%;
  bottom: 88px;
  transform: translate(-50%, 12px);
  background: var(--ink);
  color: #fff;
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 15px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
  max-width: calc(100vw - 32px);
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* Sign in. */
.signin { display: flex; flex-direction: column; gap: 12px; padding-top: 24px; }
.signin form { display: flex; flex-direction: column; gap: 12px; margin-top: 8px; }
.signin form p { margin: 0; }
.signin .row { margin-left: -10px; }
.account { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; color: var(--muted); font-size: 14px; overflow-wrap: anywhere; }
.account .btn { margin-right: -10px; }
.signin form { max-width: 420px; }
.offer { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 16px; display: flex; flex-direction: column; gap: 4px; }
.offer p { margin: 0; }
.offer p + p { color: var(--muted); font-size: 15px; }
.offer .row { margin-top: 10px; }
.or { margin: 4px 0 0; color: var(--muted); font-size: 15px; }
.signin > .btn { max-width: 420px; }
#read { align-self: flex-start; }

/* In-app camera: many photos in one go. */
.camera { position: fixed; inset: 0; z-index: 50; background: #000; display: flex; flex-direction: column; }
.camera video { flex: 1; min-height: 0; width: 100%; object-fit: contain; transition: opacity .12s; }
.camera.flash video { opacity: .25; }
.cam-hint { position: absolute; top: max(16px, env(safe-area-inset-top)); left: 16px; right: 16px; margin: 0; color: #fff; text-align: center; font-size: 15px; text-shadow: 0 1px 3px rgba(0, 0, 0, .7); }
.cam-bar { display: flex; align-items: center; gap: 12px; padding: 16px; padding-bottom: max(16px, env(safe-area-inset-bottom)); background: #000; }
.cam-last { width: 56px; height: 56px; flex-shrink: 0; object-fit: cover; border-radius: 8px; border: 2px solid #fff; visibility: hidden; }
.cam-last.on { visibility: visible; }
.cam-shoot { flex: 1; min-height: 56px; font-size: 17px; }
.cam-done { min-height: 56px; min-width: 120px; }
