:root {
  --bg: #fafafa; --panel: #ffffff; --ink: #0b0b0b; --muted: #636363;
  --faint: #767676; --line: #e4e4e4; --stripe: rgba(11,11,11,0.07);
  --danger: #b3261e;
}
[data-theme="dark"] {
  --bg: #0c0c0c; --panel: #141414; --ink: #f1f1f1; --muted: #9a9a9a;
  --faint: #8a8a8a; --line: #232323; --stripe: rgba(241,241,241,0.07);
  --danger: #ff6b60;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg); color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  transition: background 180ms linear, color 180ms linear;
  min-height: 100vh;
}
a { text-decoration: none; color: inherit; }
input, textarea, button, select { font-family: inherit; color: inherit; }
button { font-family: inherit; }

.brand { font-family: Archivo, sans-serif; font-weight: 700; letter-spacing: -0.035em; line-height: 0.92; }

/* ---- Login ---- */
.lock-screen { min-height: 100vh; display: grid; place-items: center; padding: 40px; }
.lock-box { width: 100%; max-width: 300px; display: flex; flex-direction: column; gap: 56px; }
.lock-box .brand { font-size: 30px; }
.lock-fields { display: flex; flex-direction: column; gap: 14px; }
.eyebrow { font-size: 12px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--muted); }
.text-input {
  width: 100%; background: transparent; border: none; border-bottom: 1px solid var(--line);
  padding: 10px 0; font-size: 17px; letter-spacing: 0.02em; color: var(--ink);
}
.text-input:focus { outline: none; border-bottom-color: var(--ink); }
.lock-row { display: flex; align-items: center; justify-content: space-between; margin-top: 10px; gap: 12px;}
.error-text { font-size: 13px; color: var(--danger); }

.btn {
  border: 1px solid var(--line); background: transparent; border-radius: 2px;
  padding: 10px 18px; font-size: 14px; cursor: pointer; color: var(--ink);
}
.btn:hover { border-color: var(--ink); }
.btn-primary { background: var(--ink); color: var(--bg); border: none; }
.btn-primary:hover { opacity: 0.85; }
.btn-sm { padding: 7px 14px; font-size: 13px; }
.icon-btn {
  background: transparent; border: 1px solid var(--line); border-radius: 999px;
  width: 30px; height: 30px; display: grid; place-items: center; cursor: pointer; font-size: 13px; color: var(--muted);
  flex: none;
}

/* ---- Shell (desktop-first: wide well, generous side gutters) ---- */
.shell { max-width: 1440px; margin: 0 auto; padding: 36px 56px 120px; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 32px; margin-bottom: 56px; flex-wrap: wrap; padding-bottom: 20px; border-bottom: 1px solid var(--line); }
.topbar-left { display: flex; align-items: center; gap: 48px; flex-wrap: wrap; }
.topbar .brand { font-size: 19px; }
.nav { display: flex; gap: 26px; flex-wrap: wrap; }
.nav a { font-size: 15px; letter-spacing: -0.005em; color: var(--muted); white-space: nowrap; }
.nav a.active { color: var(--ink); }
.top-actions { display: flex; align-items: center; gap: 14px; }

/* ---- Consistent page template used by every screen ---- */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; flex-wrap: wrap; margin-bottom: 28px; }
.page-head-left { display: flex; flex-direction: column; gap: 4px; }
.page-title { font-size: 22px; font-weight: 600; letter-spacing: -0.01em; }
.page-sub { font-size: 15px; color: var(--muted); }
.page-lede { font-size: 16px; line-height: 1.7; margin: -12px 0 30px; max-width: 620px; color: var(--muted); }
.page-search { border-bottom: 1px solid var(--line); margin-bottom: 24px; display: flex; align-items: center; gap: 12px; }
.page-search .label { font-size: 14px; color: var(--faint); white-space: nowrap; }
.page-search input { flex: 1; min-width: 0; background: transparent; border: none; padding: 10px 0; font-size: 16px; color: var(--ink); }
.page-search input:focus { outline: none; }
.search-clear { background: transparent; border: none; cursor: pointer; font-size: 13px; color: var(--muted); padding: 4px; }
.page-filters { display: flex; gap: 18px; flex-wrap: wrap; align-items: center; margin-bottom: 32px; }
.page-filters a, .page-filters button { font-size: 14px; letter-spacing: 0.02em; color: var(--muted); border-bottom: 1px solid transparent; padding-bottom: 3px; background: none; border-top: none; border-left: none; border-right: none; cursor: pointer; }
.page-filters a.active, .page-filters button.active { color: var(--ink); border-bottom-color: var(--ink); }
.page-filters .new-cat-input { background: transparent; border: none; border-bottom: 1px solid var(--ink); padding: 2px 0 3px; font-size: 14px; width: 180px; }
.page-body { }

.section-lede { font-size: 17px; line-height: 1.7; margin: 0 0 40px; max-width: 460px; }

/* ---- Library hub (category tiles) ---- */
.hub-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 20px; }
.hub-tile { border: 1px solid var(--line); padding: 22px 20px; display: flex; flex-direction: column; gap: 10px; cursor: pointer; background: var(--panel); }
.hub-tile:hover { border-color: var(--ink); }
.hub-tile .name { font-size: 16px; font-weight: 600; }
.hub-tile .count { font-size: 13px; color: var(--muted); }

/* ---- Grid view (books, magazines, albums, series, movies, animes, mangas, comics, artists) ---- */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 36px 24px; }
.grid-item { display: flex; flex-direction: column; gap: 10px; cursor: pointer; }
.thumb { aspect-ratio: 3/4; background-color: var(--panel); background-image: repeating-linear-gradient(135deg, var(--stripe) 0 1px, transparent 1px 7px); border: 1px solid var(--line); display: grid; place-items: end start; padding: 10px; overflow: hidden; }
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.thumb-label { font-family: ui-monospace, monospace; font-size: 10px; letter-spacing: 0.06em; color: var(--faint); }
.item-title-sm { font-size: 15px; line-height: 1.35; letter-spacing: -0.005em; }
.item-meta-sm { font-size: 13px; color: var(--muted); margin-top: 1px; }

/* ---- Mosaic view (images): real aspect ratio via CSS columns, lazy-loaded ---- */
.mosaic { column-width: 220px; column-gap: 16px; }
.mosaic-item { break-inside: avoid; margin-bottom: 16px; display: block; border: 1px solid var(--line); overflow: hidden; cursor: pointer; }
.mosaic-item img { width: 100%; display: block; }

/* ---- List view (videos, web articles, papers, finds) ---- */
.list-rows { display: flex; flex-direction: column; }
.list-row { display: flex; align-items: center; gap: 16px; padding: 14px 0; border-top: 1px solid var(--line); cursor: pointer; }
.list-rows .list-row:last-child { border-bottom: 1px solid var(--line); }
.list-thumb { width: 56px; height: 56px; flex: none; background-color: var(--panel); background-image: repeating-linear-gradient(135deg, var(--stripe) 0 1px, transparent 1px 7px); border: 1px solid var(--line); display: grid; place-items: center; overflow: hidden; }
.list-thumb img { width: 100%; height: 100%; object-fit: cover; }
.list-thumb .thumb-label { font-size: 8px; }
.list-main { flex: 1; min-width: 0; }
.list-title { font-size: 15px; line-height: 1.3; }
.list-sub { font-size: 13px; color: var(--muted); margin-top: 2px; }
.list-tags { display: flex; gap: 6px; flex-wrap: wrap; flex: none; }
.list-actions { display: flex; gap: 10px; flex: none; }

.empty-note { font-size: 16px; color: var(--muted); margin: 0 0 40px; }

.panel-box { border: 1px solid var(--line); background: var(--panel); padding: 30px 28px; margin-bottom: 46px; max-width: 620px; }
.field-stack { display: flex; flex-direction: column; gap: 22px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 22px; }
.field { display: flex; flex-direction: column; gap: 8px; }
.field .label { font-size: 12px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted); }
.field input, .field textarea, .field select {
  width: 100%; background: transparent; border: none; border-bottom: 1px solid var(--line);
  padding: 6px 0; font-size: 16px; color: var(--ink); font-family: inherit;
}
.field input:focus, .field textarea:focus, .field select:focus { outline: none; border-bottom-color: var(--ink); }

.dropzone {
  display: block; width: 100%;
  background-image: repeating-linear-gradient(135deg, var(--stripe) 0 1px, transparent 1px 7px);
  border: 1px solid var(--line); padding: 26px 22px; text-align: center; cursor: pointer;
}
.dropzone .main { font-size: 15px; margin-bottom: 6px; }
.dropzone .sub { font-family: ui-monospace, monospace; font-size: 11px; letter-spacing: 0.06em; color: var(--faint); }
.dropzone input[type="file"] { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.dropzone .filename { font-size: 13px; color: var(--ink); margin-top: 8px; }

.btn-row { display: flex; gap: 14px; flex-wrap: wrap; }

.tag-row { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.tag-pill { font-size: 12px; color: var(--muted); border: 1px solid var(--line); border-radius: 999px; padding: 3px 9px; }
.assign-link { font-size: 12px; color: var(--faint); background: none; border: none; cursor: pointer; padding: 0; }
.assign-options { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 9px; padding-top: 9px; border-top: 1px solid var(--line); }
.opt-pill { font-size: 12px; border: 1px solid var(--line); border-radius: 999px; padding: 3px 9px; background: transparent; color: var(--muted); cursor: pointer; }
.opt-pill.on { background: var(--ink); color: var(--bg); }

.word-group { display: grid; grid-template-columns: 54px minmax(0,1fr); gap: 20px; margin-bottom: 34px; align-items: start; }
.word-letter { font-family: Archivo, sans-serif; font-size: 15px; font-weight: 600; color: var(--faint); padding-top: 13px; }
.word-row { border-top: 1px solid var(--line); padding: 13px 0; }
.word-head { display: flex; align-items: baseline; justify-content: space-between; gap: 18px; background: none; border: none; width: 100%; text-align: left; cursor: pointer; color: inherit; padding: 0; }
.word-term { font-size: 19px; letter-spacing: -0.01em; }
.word-kind { font-size: 12px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--faint); }
.word-body { padding: 14px 0 8px; max-width: 480px; }
.word-def { font-size: 17px; line-height: 1.7; margin: 0 0 14px; }
.word-source { font-size: 14px; color: var(--muted); }
.new-word-toggle { font-size: 14px; color: var(--muted); background: none; border: none; cursor: pointer; padding: 0; margin-bottom: 30px; }

.phrase-card { border-top: 1px solid var(--line); padding: 20px 0; max-width: 640px; }
.phrase-text { font-size: 19px; line-height: 1.6; font-style: italic; margin: 0 0 10px; }
.phrase-source { font-size: 14px; color: var(--muted); display: flex; align-items: center; gap: 10px; }

.autocomplete { position: relative; }
.autocomplete-list { position: absolute; top: 100%; left: 0; right: 0; background: var(--panel); border: 1px solid var(--line); z-index: 20; max-height: 220px; overflow-y: auto; }
.autocomplete-item { padding: 8px 10px; font-size: 14px; cursor: pointer; }
.autocomplete-item:hover, .autocomplete-item.active { background: var(--stripe); }
.autocomplete-item .k { font-size: 11px; color: var(--faint); text-transform: uppercase; letter-spacing: 0.06em; margin-left: 6px; }

.back-link { font-size: 14px; color: var(--muted); background: none; border: none; cursor: pointer; padding: 0; }

/* ---- Modal ---- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 500;
  display: flex; align-items: flex-start; justify-content: center; padding: 5vh 20px; overflow-y: auto;
}
.modal-panel {
  background: var(--bg); border: 1px solid var(--line); max-width: 760px; width: 100%;
  padding: 40px 44px; position: relative; margin-bottom: 5vh;
}
.modal-close { position: absolute; top: 16px; right: 16px; background: transparent; border: none; font-size: 22px; cursor: pointer; color: var(--muted); line-height: 1; padding: 6px; }
.modal-close:hover { color: var(--ink); }

.item-modal-grid { display: grid; grid-template-columns: 1fr; gap: 24px; align-items: start; }
.item-modal-grid .thumb { aspect-ratio: auto; padding: 12px; }
.item-modal-grid .thumb img { width: auto; height: auto; max-width: 100%; max-height: 280px; object-fit: contain; }
.item-modal-grid .thumb.thumb-plain {
  background: none; background-image: none; border: none; padding: 0;
  display: flex; justify-content: center;
}
.item-modal-grid .thumb.thumb-plain img { max-height: 520px; }
.item-type-label { font-size: 12px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--faint); margin-bottom: 12px; }
.item-title-lg { font-size: 27px; font-weight: 600; letter-spacing: -0.02em; line-height: 1.15; margin: 0 0 6px; }
.item-subtitle { font-size: 16px; color: var(--muted); margin-bottom: 24px; }
.item-note { margin: 0 0 26px; }
.item-fields { display: flex; flex-direction: column; }
.item-field { display: grid; grid-template-columns: 110px minmax(0,1fr); gap: 16px; padding: 10px 0; border-top: 1px solid var(--line); font-size: 14px; }
.item-field .k { color: var(--muted); }
.item-field a { text-decoration: underline; }
.item-tags { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 22px; }
.item-actions { margin-top: 28px; display: flex; gap: 14px; }

.reader-body h2 { font-size: 24px; font-weight: 600; letter-spacing: -0.02em; margin: 26px 0 12px; }
.reader-body h3 { font-size: 19px; font-weight: 600; margin: 22px 0 10px; }
.reader-body p { font-size: 16px; line-height: 1.75; margin: 0 0 18px; }
.reader-body blockquote { font-size: 18px; font-style: italic; border-left: 2px solid var(--line); margin: 22px 0; padding-left: 18px; color: var(--muted); }
.reader-body ul { padding-left: 22px; margin: 0 0 18px; }
.reader-body li { font-size: 16px; line-height: 1.75; margin-bottom: 6px; }
.reader-body code { font-family: ui-monospace, monospace; background: var(--panel); border: 1px solid var(--line); padding: 1px 5px; border-radius: 3px; font-size: 0.9em; }

.compose-head { display: flex; align-items: baseline; justify-content: space-between; gap: 24px; flex-wrap: wrap; margin-bottom: 34px; }
.compose-head-actions { display: flex; gap: 14px; align-items: center; }
.word-count { font-size: 13px; color: var(--faint); }
.compose-title-input { width: 100%; background: transparent; border: none; border-bottom: 1px solid var(--line); padding: 0 0 14px; font-size: 30px; font-weight: 600; letter-spacing: -0.02em; color: var(--ink); }
.compose-title-input:focus { outline: none; }
.compose-grid { display: grid; gap: 44px; margin-top: 34px; align-items: start; }
.compose-editor { width: 100%; min-height: 460px; background: transparent; border: none; resize: vertical; font-family: ui-monospace, monospace; font-size: 14px; line-height: 1.85; color: var(--ink); }
.compose-editor:focus { outline: none; }
.compose-preview { border-left: 1px solid var(--line); padding-left: 40px; }
.compose-preview-label { font-size: 12px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--faint); margin-bottom: 22px; }
.compose-preview h2 { font-size: 24px; font-weight: 600; letter-spacing: -0.02em; line-height: 1.15; margin: 0 0 18px; }

.posts-list { margin-bottom: 44px; display: flex; flex-direction: column; }
.post-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 11px 0; border-top: 1px solid var(--line); }
.post-row .t { font-size: 15px; cursor: pointer; }
.post-row .badge { font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--faint); }

.images-row { display: flex; gap: 12px; flex-wrap: wrap; margin: 20px 0; }
.image-thumb { position: relative; width: 96px; height: 96px; border: 1px solid var(--line); overflow: hidden; }
.image-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.image-thumb button { position: absolute; top: 2px; right: 2px; background: rgba(0,0,0,0.6); color: #fff; border: none; width: 18px; height: 18px; font-size: 11px; cursor: pointer; border-radius: 2px; }
.image-hint { font-size: 12px; color: var(--faint); margin-top: -8px; margin-bottom: 20px; }

.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: var(--bg); padding: 10px 18px; border-radius: 3px; font-size: 14px;
  z-index: 999;
}

@media (max-width: 900px) {
  .shell { padding: 24px 24px 100px; }
  .item-modal-grid { grid-template-columns: 1fr; }
  .compose-grid { grid-template-columns: 1fr !important; }
  .compose-preview { border-left: none; padding-left: 0; border-top: 1px solid var(--line); padding-top: 24px; }
  .field-row { grid-template-columns: 1fr; }
  .modal-panel { padding: 32px 22px; }
}
