:root {
  --bg: #f3f2ee;
  --surface: #ffffff;
  --surface-2: #ebeae4;
  --text: #1b1f1d;
  --muted: #59615c;
  --line: #dbdad3;
  --line-strong: #c3c2ba;
  --accent: #16725a;
  --accent-hover: #10604b;
  --accent-soft: #dbece5;
  --on-accent: #ffffff;
  --danger: #a3392b;
  --j-key: #1b1f1d;
  --j-str: #8a4f0e;
  --j-num: #2a58a8;
  --j-lit: #9b2f63;
  --shadow: 0 1px 2px rgb(20 24 22 / 0.05), 0 8px 24px -8px rgb(20 24 22 / 0.12);
  --radius: 14px;
  --font: "IBM Plex Sans", -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #131615;
    --surface: #1b1f1d;
    --surface-2: #242927;
    --text: #e9ece8;
    --muted: #a0a9a3;
    --line: #2f3532;
    --line-strong: #434a46;
    --accent: #5fcfa9;
    --accent-hover: #7cdbb9;
    --accent-soft: #1a382e;
    --on-accent: #0c1f18;
    --danger: #f0907f;
    --j-key: #e9ece8;
    --j-str: #e6b679;
    --j-num: #8fb6f2;
    --j-lit: #eb9cc4;
    --shadow: 0 1px 2px rgb(0 0 0 / 0.3), 0 10px 28px -10px rgb(0 0 0 / 0.55);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #131615;
  --surface: #1b1f1d;
  --surface-2: #242927;
  --text: #e9ece8;
  --muted: #a0a9a3;
  --line: #2f3532;
  --line-strong: #434a46;
  --accent: #5fcfa9;
  --accent-hover: #7cdbb9;
  --accent-soft: #1a382e;
  --on-accent: #0c1f18;
  --danger: #f0907f;
  --j-key: #e9ece8;
  --j-str: #e6b679;
  --j-num: #8fb6f2;
  --j-lit: #eb9cc4;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.3), 0 10px 28px -10px rgb(0 0 0 / 0.55);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 var(--font);
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
body.viewing { overflow: hidden; }
a { color: var(--accent); }
code, kbd { font-family: var(--mono); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
svg { flex: none; }

.wrap { width: 100%; max-width: 1200px; margin: 0 auto; padding-left: max(16px, env(safe-area-inset-left)); padding-right: max(16px, env(safe-area-inset-right)); }
@media (min-width: 720px) { .wrap { padding-left: 28px; padding-right: 28px; } }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  height: 36px; padding: 0 13px;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface); color: var(--text);
  font: 500 14px/1 var(--font); text-decoration: none; white-space: nowrap;
  cursor: pointer; transition: background-color .15s, border-color .15s, color .15s;
}
.btn:hover { border-color: var(--line-strong); background: var(--surface-2); }
.btn svg { width: 17px; height: 17px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.icon { width: 36px; padding: 0; }

/* ---------- site header ---------- */
.site-header {
  position: sticky; top: 0; z-index: 10;
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  -webkit-backdrop-filter: saturate(1.4) blur(12px);
  backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid var(--line);
  padding-top: env(safe-area-inset-top);
}
.site-header .wrap { display: flex; align-items: center; gap: 12px; height: 58px; }
.brand { display: inline-flex; align-items: center; gap: 10px; color: var(--text); text-decoration: none; font-weight: 600; font-size: 16px; letter-spacing: -0.01em; }
.brand svg { width: 26px; height: 26px; color: var(--accent); }
.header-actions { margin-left: auto; display: flex; align-items: center; gap: 4px; }
.header-actions .label { font: 13px/1 var(--mono); color: var(--muted); }
.header-actions .btn:hover .label { color: var(--text); }
@media (max-width: 560px) { .header-actions .label { display: none; } .header-actions .btn { width: 36px; padding: 0; } }

/* ---------- gallery ---------- */
#gallery { flex: 1; }
.intro { padding: 44px 0 22px; max-width: 760px; }
.intro h1 { margin: 0; font-size: clamp(30px, 5vw, 44px); line-height: 1.08; letter-spacing: -0.025em; font-weight: 600; }
.intro p { margin: 12px 0 0; color: var(--muted); font-size: 16px; max-width: 60ch; }

.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; padding-bottom: 20px; }
.search {
  position: relative; flex: 1 1 260px; max-width: 380px;
  display: flex; align-items: center;
}
.search svg { position: absolute; left: 12px; width: 18px; height: 18px; color: var(--muted); pointer-events: none; }
.search input {
  width: 100%; height: 40px; padding: 0 38px 0 38px;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface); color: var(--text);
  font: 15px var(--font);
}
.search input::placeholder { color: var(--muted); opacity: .85; }
.search input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.search input::-webkit-search-cancel-button { cursor: pointer; }
.search kbd {
  position: absolute; right: 10px;
  font-size: 12px; line-height: 1; color: var(--muted);
  border: 1px solid var(--line); border-radius: 5px; padding: 3px 6px; background: var(--surface-2);
  pointer-events: none;
}
.search input:focus ~ kbd, .search input:not(:placeholder-shown) ~ kbd { display: none; }
@media (hover: none) { .search kbd { display: none; } }
.sort select {
  height: 40px; padding: 0 34px 0 12px;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3E%3Cpath d='M6 8l4 4 4-4' fill='none' stroke='%23888' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") no-repeat right 10px center / 16px;
  color: var(--text); font: 14px var(--font);
  -webkit-appearance: none; appearance: none; cursor: pointer;
}
.sort select:focus-visible { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.count { margin: 0 0 0 auto; color: var(--muted); font-size: 13.5px; }

.grid {
  list-style: none; margin: 0; padding: 0 0 56px;
  display: grid; gap: 20px;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 310px), 1fr));
}

.card {
  display: flex; flex-direction: column; min-width: 0;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  overflow: hidden;
  transition: border-color .15s, box-shadow .2s;
}
.card:hover { border-color: var(--line-strong); box-shadow: var(--shadow); }
.card-media {
  display: block; position: relative; aspect-ratio: 16 / 10; overflow: hidden;
  background: var(--surface-2); border-bottom: 1px solid var(--line);
}
.card-media img { display: block; width: 100%; height: 100%; object-fit: cover; object-position: top center; transition: transform .45s ease; }
.card:hover .card-media img { transform: scale(1.025); }
.card-body { display: flex; flex-direction: column; gap: 10px; flex: 1; padding: 16px 18px 18px; min-width: 0; }
.card-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 0; color: var(--muted); font-size: 13px; }
.badge {
  font: 600 11px/1 var(--font); letter-spacing: .06em; text-transform: uppercase;
  color: var(--accent); background: var(--accent-soft); padding: 4px 7px; border-radius: 6px;
}
.card-title { margin: 0; font-size: 18px; line-height: 1.3; font-weight: 600; letter-spacing: -0.01em; }
.card-title a { color: inherit; text-decoration: none; }
.card-title a:hover { text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 3px; }
.card-summary {
  margin: 0; color: var(--muted);
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}
.files { display: flex; flex-wrap: wrap; gap: 6px; margin: 2px 0 0; padding: 0; list-style: none; }
.files a {
  display: inline-block; padding: 5px 8px; border-radius: 7px;
  background: var(--surface-2); border: 1px solid transparent;
  color: var(--text); text-decoration: none; font: 12.5px/1.2 var(--mono);
}
.files a:hover { border-color: var(--line-strong); }
.card-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: auto; padding-top: 6px; }

.placeholder {
  position: absolute; inset: 0; display: grid; place-content: center; justify-items: center; gap: 10px;
  background-color: var(--surface-2);
  background-image:
    linear-gradient(var(--line) 1px, transparent 1px),
    linear-gradient(90deg, var(--line) 1px, transparent 1px);
  background-size: 22px 22px;
  background-position: center;
}
.placeholder .mark {
  width: 60px; height: 60px; border-radius: 15px; display: grid; place-items: center;
  background: var(--accent); color: var(--on-accent); font: 600 28px/1 var(--font);
}
.placeholder .name { font: 12.5px/1 var(--mono); color: var(--muted); background: var(--surface); padding: 5px 8px; border-radius: 6px; border: 1px solid var(--line); }

@media (min-width: 860px) {
  .card.featured { grid-column: 1 / -1; display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr); }
  .card.featured .card-media { aspect-ratio: auto; min-height: 360px; border-bottom: 0; border-right: 1px solid var(--line); }
  .card.featured .card-body { padding: 30px 32px; gap: 14px; justify-content: center; }
  .card.featured .card-title { font-size: 26px; line-height: 1.2; letter-spacing: -0.02em; }
  .card.featured .card-summary { -webkit-line-clamp: 7; font-size: 15.5px; }
  .card.featured .card-actions { margin-top: 6px; }
}

/* loading skeleton */
.skeleton .card-media, .skeleton .sk {
  background: linear-gradient(90deg, var(--surface-2) 25%, var(--line) 50%, var(--surface-2) 75%) 0 0 / 200% 100%;
  animation: shimmer 1.3s linear infinite;
}
.skeleton .sk { height: 12px; border-radius: 6px; }
.skeleton .sk.title { height: 18px; width: 60%; }
.skeleton .sk.short { width: 40%; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* empty, error and not-found states */
.state {
  grid-column: 1 / -1;
  padding: 56px 20px; text-align: center;
  border: 1px dashed var(--line-strong); border-radius: var(--radius);
  color: var(--muted);
}
.state h2 { margin: 0 0 6px; color: var(--text); font-size: 18px; font-weight: 600; }
.state p { margin: 0 auto 16px; max-width: 56ch; }
.state code { font-size: .92em; background: var(--surface-2); padding: 1px 5px; border-radius: 5px; color: var(--text); }
.state .actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }
.state.error h2 { color: var(--danger); }
.vbody .state { margin: 32px auto; max-width: 640px; width: calc(100% - 32px); background: var(--surface); }

.site-footer { padding-bottom: max(32px, env(safe-area-inset-bottom)); color: var(--muted); font-size: 13.5px; }
.site-footer p { margin: 0; padding-top: 20px; border-top: 1px solid var(--line); }
.site-footer code { font-size: .92em; }

/* ---------- viewer ---------- */
.viewer {
  position: fixed; inset: 0; z-index: 20;
  display: flex; flex-direction: column;
  background: var(--bg);
}
.vbar {
  flex: none;
  background: var(--surface); border-bottom: 1px solid var(--line);
  padding: env(safe-area-inset-top) max(10px, env(safe-area-inset-right)) 0 max(10px, env(safe-area-inset-left));
}
.vbar-row { display: flex; align-items: center; gap: 8px; min-height: 54px; }
.vtitle {
  flex: 1; min-width: 0; margin: 0;
  font-size: 16px; font-weight: 600; letter-spacing: -0.01em;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.vtitle:focus { outline: none; }
.vactions { display: flex; align-items: center; gap: 4px; }
.tabs-row { min-height: 0; align-items: flex-end; }
.vtabs {
  display: flex; gap: 2px; min-width: 0; flex: 1;
  overflow-x: auto; scrollbar-width: none;
}
.vtabs::-webkit-scrollbar { display: none; }
.vtabs a {
  flex: none; padding: 9px 12px 11px;
  color: var(--muted); text-decoration: none; font: 13px/1 var(--mono);
  border-bottom: 2px solid transparent; border-radius: 6px 6px 0 0;
}
.vtabs a:hover { color: var(--text); background: var(--surface-2); }
.vtabs a[aria-current="page"] { color: var(--text); border-bottom-color: var(--accent); font-weight: 500; }
.vmeta { margin: 0 4px 10px auto; color: var(--muted); font: 12px/1 var(--mono); white-space: nowrap; }
@media (max-width: 640px) {
  .vbar .label, .vmeta { display: none; }
  .vbar .btn { width: 36px; padding: 0; }
}

.vbody { position: relative; flex: 1; min-height: 0; overflow: auto; -webkit-overflow-scrolling: touch; }
.vbody iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; display: block; background: var(--bg); }
.loading {
  position: absolute; inset: 0; z-index: 1;
  display: flex; align-items: center; justify-content: center; gap: 10px;
  background: var(--bg); color: var(--muted); font-size: 14px;
  transition: opacity .25s;
}
.loading.done { opacity: 0; pointer-events: none; }
.spinner { width: 20px; height: 20px; border-radius: 50%; border: 2px solid var(--line-strong); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* rendered documents */
.doc-wrap { padding: 28px max(16px, env(safe-area-inset-right)) 72px max(16px, env(safe-area-inset-left)); }
.doc {
  max-width: 820px; margin: 0 auto;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 30px 36px 36px;
  overflow-wrap: break-word;
}
.doc.wide { max-width: 1000px; }
@media (max-width: 640px) { .doc { padding: 20px 18px 24px; } .doc-wrap { padding-top: 14px; } }
.doc > :first-child { margin-top: 0; }
.doc h1 { font-size: 28px; line-height: 1.2; letter-spacing: -0.02em; margin: 0 0 16px; font-weight: 600; }
.doc h2 { font-size: 20px; line-height: 1.3; letter-spacing: -0.01em; margin: 34px 0 10px; font-weight: 600; padding-top: 6px; }
.doc h3 { font-size: 16px; margin: 26px 0 8px; font-weight: 600; }
.doc p, .doc ul, .doc ol { margin: 0 0 14px; }
.doc ul, .doc ol { padding-left: 22px; }
.doc li { margin: 4px 0; }
.doc li::marker { color: var(--muted); }
.doc a { color: var(--accent); text-underline-offset: 2px; }
.doc code { font-size: .88em; background: var(--surface-2); padding: 1.5px 5px; border-radius: 5px; }
.doc a code { color: inherit; }
.doc pre { background: var(--surface-2); padding: 14px 16px; border-radius: 10px; overflow-x: auto; font-size: 13px; line-height: 1.55; }
.doc pre code { background: none; padding: 0; font-size: inherit; }
.doc blockquote { margin: 0 0 14px; padding: 2px 0 2px 16px; border-left: 3px solid var(--line-strong); color: var(--muted); }
.doc hr { border: 0; border-top: 1px solid var(--line); margin: 28px 0; }
.doc img { max-width: 100%; height: auto; border-radius: 8px; }
.table-scroll { overflow-x: auto; margin: 0 0 18px; border: 1px solid var(--line); border-radius: 10px; }
.doc table { border-collapse: collapse; width: 100%; font-size: 14px; font-variant-numeric: tabular-nums; }
.doc th, .doc td { text-align: left; padding: 8px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
.doc th { background: var(--surface-2); font-weight: 600; white-space: nowrap; }
.doc tr:last-child td { border-bottom: 0; }
@media (max-width: 640px) { .doc table { font-size: 13.5px; } .doc th, .doc td { padding: 7px 9px; } }

.doc pre.code-view { margin: 0; padding: 0; background: none; border-radius: 0; overflow: visible; font: 13px/1.6 var(--mono); white-space: pre-wrap; overflow-wrap: anywhere; color: var(--muted); }
/* JSON lines keep their indent when they wrap: --i is the line's indent in characters */
.code-view .ln { padding-left: calc((var(--i) + 2) * 1ch); text-indent: -2ch; }
.code-view .k { color: var(--j-key); font-weight: 500; }
.code-view .s { color: var(--j-str); }
.code-view .n { color: var(--j-num); }
.code-view .l { color: var(--j-lit); }
.image-view { display: grid; place-items: center; min-height: 100%; padding: 24px; }
.image-view img { max-width: 100%; max-height: calc(100vh - 160px); border-radius: 8px; box-shadow: var(--shadow); background: var(--surface); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0s !important; animation-iteration-count: 1 !important; transition: none !important; }
}
