:root {
  --ground: #EDEEF0;
  --paper: #FFFFFF;
  --paper-2: #F6F7F8;
  --ink: #0F1319;
  --ink-muted: #5C6472;
  --ink-faint: #8A93A3;
  --line: #DCE0E6;
  --line-strong: #C6CBD3;
  --accent: #0E7C86;
  --accent-hover: #0B646C;
  --accent-soft: #DBEDEF;
  --accent-ink: #063D42;
  --tag-bg: #E5E8ED;
  --tag-fg: #3C4552;
  --danger: #B4402D;
  --shadow-sm: 0 1px 2px rgba(15, 19, 25, 0.05);
  --shadow-md: 0 8px 24px -8px rgba(15, 19, 25, 0.15);
  --shadow-lg: 0 24px 48px -12px rgba(15, 19, 25, 0.25);
  --radius: 10px;
  --radius-sm: 6px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --ground: #0F1114;
    --paper: #181A1F;
    --paper-2: #1F2229;
    --ink: #E4E8EE;
    --ink-muted: #8A93A3;
    --ink-faint: #5C6472;
    --line: #262932;
    --line-strong: #363A46;
    --accent: #2CB3BF;
    --accent-hover: #4DD1DD;
    --accent-soft: #0F2A2D;
    --accent-ink: #A7E6EC;
    --tag-bg: #23262E;
    --tag-fg: #C7CCD6;
    --danger: #E86B54;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.4);
    --shadow-md: 0 8px 24px -8px rgba(0,0,0,0.6);
    --shadow-lg: 0 24px 48px -12px rgba(0,0,0,0.8);
  }
}
:root[data-theme="dark"] {
  --ground: #0F1114;
  --paper: #181A1F;
  --paper-2: #1F2229;
  --ink: #E4E8EE;
  --ink-muted: #8A93A3;
  --ink-faint: #5C6472;
  --line: #262932;
  --line-strong: #363A46;
  --accent: #2CB3BF;
  --accent-hover: #4DD1DD;
  --accent-soft: #0F2A2D;
  --accent-ink: #A7E6EC;
  --tag-bg: #23262E;
  --tag-fg: #C7CCD6;
  --danger: #E86B54;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.4);
  --shadow-md: 0 8px 24px -8px rgba(0,0,0,0.6);
  --shadow-lg: 0 24px 48px -12px rgba(0,0,0,0.8);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--ground);
  color: var(--ink);
  font-family: "Inter", -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  min-height: 100vh;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
img { max-width: 100%; }
[hidden] { display: none !important; }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; border: none; background: none; }
a { color: var(--accent); text-decoration: none; }
code { font-family: ui-monospace, "SF Mono", Menlo, monospace; background: var(--paper-2); padding: 1px 6px; border-radius: 4px; font-size: 12px; }
.num { font-family: "Fraunces", "Inter", serif; font-variant-numeric: tabular-nums; font-weight: 500; }

/* Top bar */
.topbar {
  position: sticky;
  top: env(safe-area-inset-top, 0px);
  z-index: 10;
  background: color-mix(in oklab, var(--ground) 92%, transparent);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
}
.topbar-inner {
  max-width: 1400px;
  margin: 0 auto;
  padding-block: 14px;
  padding-inline: 24px;
  display: flex;
  align-items: center;
  gap: 16px;
}
.wordmark {
  display: flex; align-items: baseline; gap: 6px;
  white-space: nowrap;
}
.wordmark.large { justify-content: center; }
.wordmark .mark {
  font-family: "Fraunces", serif;
  font-style: italic;
  font-weight: 300;
  font-size: 22px;
  letter-spacing: -0.01em;
}
.wordmark.large .mark { font-size: 44px; }
.wordmark .dot { color: var(--accent); font-size: 22px; line-height: 1; }
.wordmark.large .dot { font-size: 44px; }
.wordmark .sub {
  margin-left: 8px;
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-faint);
}
.search-wrap {
  flex: 1;
  max-width: 640px;
  display: flex;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.search-wrap:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.search-wrap input { flex: 1; padding: 10px 14px; background: transparent; border: none; outline: none; }
.search-wrap select {
  background: var(--paper-2);
  border: none;
  border-left: 1px solid var(--line);
  padding: 0 10px;
  outline: none;
  color: var(--ink-muted);
  font-size: 12px;
}
.btn {
  padding: 9px 16px;
  border-radius: var(--radius);
  font-weight: 500;
  font-size: 13px;
  transition: all 120ms ease;
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid transparent;
}
.btn-primary { background: var(--accent); color: white; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-lg { padding: 12px 22px; font-size: 14px; }
.btn-ghost { color: var(--ink-muted); }
.btn-ghost:hover { color: var(--ink); background: var(--paper-2); }
.btn-danger { color: var(--danger); }
.btn-danger:hover { background: color-mix(in oklab, var(--danger) 12%, transparent); }
.toolbar-right { display: flex; align-items: center; gap: 8px; }
#accountBtn { padding: 4px 10px; font-size: 12px; }
.linkish { color: var(--accent); text-decoration: underline; font-size: 13px; margin-top: 10px; }

/* Layout */
.layout {
  max-width: 1400px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 240px 1fr;
  gap: 32px;
  padding-inline: 24px;
  padding-block: 28px;
}
aside .section { margin-bottom: 28px; }
aside h3 {
  font-family: "Fraunces", serif;
  font-weight: 400;
  font-size: 11px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin: 0 0 10px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--line);
}
.sidebar-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.sidebar-item {
  display: flex; justify-content: space-between; align-items: center;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  color: var(--ink-muted);
  font-size: 13px;
  cursor: pointer;
  transition: background 100ms;
  text-align: left;
}
.sidebar-item:hover { background: var(--paper-2); color: var(--ink); }
.sidebar-item.active { background: var(--accent-soft); color: var(--accent-ink); font-weight: 500; }
.sidebar-item.active .count { color: var(--accent); }
.sidebar-item .count { font-size: 12px; color: var(--ink-faint); font-variant-numeric: tabular-nums; }
.tag-cloud { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 4px;
  background: var(--tag-bg); color: var(--tag-fg);
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 12px;
  cursor: pointer;
  transition: all 100ms;
}
.chip:hover { background: var(--line-strong); }
.chip.active { background: var(--accent); color: white; }
.chip.active .chip-count { color: rgba(255,255,255,0.8); }
.chip-count { font-size: 10px; color: var(--ink-faint); }
.empty-hint { font-size: 12px; color: var(--ink-faint); font-style: italic; }
.sidebar-reset {
  margin-top: 12px;
  font-size: 12px;
  color: var(--ink-faint);
  padding: 4px 8px;
}
.sidebar-reset:hover { color: var(--accent); }
.storage-hint {
  margin-top: 12px;
  padding: 10px 12px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  font-size: 11px;
  color: var(--ink-faint);
  line-height: 1.55;
}

/* Main */
.filter-bar {
  display: flex; justify-content: space-between; align-items: baseline;
  margin-bottom: 20px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}
.filter-bar .status { font-size: 13px; color: var(--ink-muted); }
.filter-bar .status strong { color: var(--ink); font-weight: 500; }
.filter-bar .count-total {
  font-family: "Fraunces", serif;
  font-size: 24px;
  font-weight: 400;
  color: var(--ink);
}
.filter-bar .count-total .u {
  font-size: 12px;
  color: var(--ink-faint);
  margin-left: 4px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  font-family: "Inter";
}

.gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 16px;
}
.card {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  transition: transform 160ms ease, box-shadow 160ms ease, border-color 160ms ease;
  position: relative;
  cursor: pointer;
}
.card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
  border-color: var(--line-strong);
}
.card:hover .card-actions { opacity: 1; transform: translateY(0); }
.card-thumb {
  aspect-ratio: 1;
  background: var(--paper-2);
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
  position: relative;
}
.card-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.card-thumb.loading::after {
  content: '';
  position: absolute;
  width: 20px; height: 20px;
  border: 2px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 800ms linear infinite;
}
.card-index {
  position: absolute; top: 8px; left: 8px;
  font-family: "Fraunces", serif;
  font-size: 10px;
  color: white;
  background: rgba(15, 19, 25, 0.6);
  padding: 2px 6px;
  border-radius: 3px;
  letter-spacing: 0.05em;
}
.card-actions {
  position: absolute; top: 8px; right: 8px;
  display: flex; gap: 4px;
  opacity: 0;
  transform: translateY(-4px);
  transition: opacity 160ms, transform 160ms;
}
.icon-btn {
  background: rgba(255,255,255,0.92);
  color: #0F1319;
  width: 28px; height: 28px;
  border-radius: 6px;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 13px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.15);
}
.icon-btn:hover { background: white; transform: scale(1.05); }
.icon-btn.danger:hover { background: var(--danger); color: white; }

.card-body { padding: 10px 12px 12px; }
.card-title {
  font-size: 13px;
  font-weight: 500;
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-bottom: 2px;
}
.card-meta {
  font-size: 11px;
  color: var(--ink-faint);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.card-meta .cat { color: var(--accent); font-weight: 500; }
.card-meta .score { font-family: "Fraunces", serif; font-variant-numeric: tabular-nums; }
.card-meta .when { color: var(--ink-faint); font-size: 10px; white-space: nowrap; }
.card-tags { display: flex; flex-wrap: wrap; gap: 3px; margin-top: 6px; }
.card-tags .chip { font-size: 10px; padding: 1px 6px; cursor: default; }

/* Empty state */
.empty-state {
  text-align: center;
  padding: 80px 20px;
  color: var(--ink-muted);
  grid-column: 1 / -1;
}
.empty-state .glyph {
  font-family: "Fraunces", serif;
  font-style: italic;
  font-size: 56px;
  color: var(--accent);
  opacity: 0.35;
  margin-bottom: 12px;
  line-height: 1;
}
.empty-state h2 {
  font-family: "Fraunces", serif;
  font-weight: 400;
  font-size: 22px;
  margin: 0 0 6px;
  color: var(--ink);
}
.empty-state p { margin: 0 0 16px; font-size: 13px; }
.kbd {
  display: inline-block;
  padding: 1px 6px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 4px;
  font-size: 11px;
  font-family: ui-monospace, monospace;
}

/* Modal */
.modal-scrim {
  position: fixed; inset: 0;
  background: rgba(15, 19, 25, 0.55);
  z-index: 30;
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  animation: fade 140ms ease-out;
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.modal {
  background: var(--paper);
  border-radius: 14px;
  box-shadow: var(--shadow-lg);
  max-width: 900px;
  width: 100%;
  max-height: calc(100vh - 40px);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.modal-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
}
.modal-head h2 { font-family: "Fraunces", serif; font-weight: 400; font-size: 18px; margin: 0; }
.modal-close { padding: 4px 10px; color: var(--ink-muted); font-size: 20px; line-height: 1; }
.modal-body { padding: 20px; overflow: auto; }

/* Fields */
.field { margin-bottom: 14px; }
.field label {
  display: block;
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-muted);
  margin-bottom: 5px;
  font-weight: 500;
}
.field input, .field textarea {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--paper-2);
  outline: none;
  transition: border 120ms, box-shadow 120ms;
}
.field input:focus, .field textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
  background: var(--paper);
}
.field textarea { resize: vertical; min-height: 60px; }
.field-hint { font-size: 11px; color: var(--ink-faint); margin-top: 4px; }
.actions-row { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; flex-wrap: wrap; }
.pill { display: inline-block; padding: 5px 10px; background: var(--paper-2); border-radius: var(--radius-sm); font-size: 12px; color: var(--ink); font-family: ui-monospace, monospace; word-break: break-all; }

.share-block {
  background: var(--paper-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
}
.share-head {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 4px;
}
.share-head h3 {
  margin: 0; font-family: "Fraunces", serif; font-weight: 400; font-size: 15px;
}
.share-badge {
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--tag-bg);
  color: var(--ink-muted);
}
.share-badge.on {
  background: var(--accent-soft);
  color: var(--accent-ink);
}
.detail-info .field label { margin-bottom: 3px; }
.detail-info .detail-meta { margin-top: 0; }

.drop-zone {
  border: 2px dashed var(--line-strong);
  border-radius: var(--radius);
  background: var(--paper-2);
  padding: 24px;
  text-align: center;
  color: var(--ink-muted);
  margin-bottom: 14px;
  transition: all 140ms;
  cursor: pointer;
  display: block;
}
.drop-zone:hover, .drop-zone.dragover {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent-ink);
}
.drop-zone .big { font-family: "Fraunces", serif; font-style: italic; font-size: 20px; margin-bottom: 4px; }
.drop-zone input { display: none; }

/* Detail modal */
.detail-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(280px, 1fr);
  gap: 24px;
}
.detail-preview {
  background: var(--paper-2);
  border-radius: var(--radius);
  overflow: hidden;
  aspect-ratio: 1;
  display: flex; align-items: center; justify-content: center;
}
.detail-preview img { max-width: 100%; max-height: 100%; object-fit: contain; }
.detail-meta { font-size: 12px; margin-top: 12px; }
.detail-meta dl { margin: 0; display: grid; grid-template-columns: max-content 1fr; gap: 4px 12px; }
.detail-meta dt {
  color: var(--ink-faint); text-transform: uppercase;
  font-size: 10px; letter-spacing: 0.1em; padding-top: 3px;
}
.detail-meta dd { margin: 0; color: var(--ink); word-break: break-word; }

/* Sign-in gate */
.gate {
  min-height: 80vh;
  display: flex; align-items: center; justify-content: center;
  padding: 40px 20px;
}
.gate-inner {
  max-width: 560px;
  text-align: center;
  width: 100%;
}
.gate-inner .lede {
  color: var(--ink-muted);
  font-size: 15px;
  margin: 20px auto 32px;
  max-width: 40ch;
  text-wrap: balance;
}
.gate-inner .fine {
  color: var(--ink-faint);
  font-size: 12px;
  margin-top: 12px;
  max-width: 44ch;
  margin-inline: auto;
}
.setup-card {
  text-align: left;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px 24px;
  margin-top: 20px;
  box-shadow: var(--shadow-sm);
}
.setup-card h3 {
  font-family: "Fraunces", serif;
  font-weight: 400;
  font-size: 18px;
  margin: 0 0 12px;
}
.setup-card ol {
  padding-left: 20px;
  color: var(--ink-muted);
  font-size: 13px;
  line-height: 1.7;
  margin-bottom: 16px;
}
.setup-card ol code { font-size: 12px; }

/* Drop overlay */
.drop-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: color-mix(in oklab, var(--accent) 12%, transparent);
  backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
  pointer-events: none;
  opacity: 0;
  transition: opacity 120ms;
}
.drop-overlay.active { opacity: 1; }
.drop-overlay .msg {
  background: var(--paper);
  border: 2px dashed var(--accent);
  border-radius: 16px;
  padding: 40px 60px;
  box-shadow: var(--shadow-lg);
  text-align: center;
}
.drop-overlay .msg .big {
  font-family: "Fraunces", serif;
  font-style: italic;
  font-weight: 400;
  font-size: 32px;
  color: var(--accent);
  margin-bottom: 6px;
}

/* Toast */
.toast {
  position: fixed;
  bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  right: 20px;
  background: var(--ink);
  color: var(--ground);
  padding: 10px 16px;
  border-radius: var(--radius);
  font-size: 13px;
  box-shadow: var(--shadow-lg);
  z-index: 40;
  display: flex; align-items: center; gap: 10px;
  max-width: 360px;
}
.spinner {
  width: 14px; height: 14px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 800ms linear infinite;
  flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Responsive */
@media (max-width: 780px) {
  .layout { grid-template-columns: 1fr; gap: 20px; padding-inline: 16px; }
  aside { order: 2; display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
  aside .section { margin-bottom: 0; }
  .storage-hint { grid-column: 1 / -1; }
  .topbar-inner { flex-wrap: wrap; padding-inline: 16px; gap: 10px; }
  .search-wrap { order: 3; max-width: none; width: 100%; }
  .wordmark { flex: 1; }
  .detail-grid { grid-template-columns: 1fr; }
  .filter-bar { flex-direction: column; align-items: flex-start; gap: 4px; }
}
@media (max-width: 480px) {
  aside { grid-template-columns: 1fr; }
  .gallery { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
  .wordmark.large .mark { font-size: 32px; }
  .wordmark.large .dot { font-size: 32px; }
}

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: 6px; }
::-webkit-scrollbar-thumb:hover { background: var(--ink-faint); }
