@font-face { font-family: "Selawik"; font-weight: 300; font-style: normal; font-display: swap; src: url("../fonts/Selawik-Light.woff2") format("woff2"); }
@font-face { font-family: "Selawik"; font-weight: 400; font-style: normal; font-display: swap; src: url("../fonts/Selawik-Regular.woff2") format("woff2"); }
@font-face { font-family: "Selawik"; font-weight: 600; font-style: normal; font-display: swap; src: url("../fonts/Selawik-Bold.woff2") format("woff2"); }
@font-face { font-family: "Selawik"; font-weight: 700; font-style: normal; font-display: swap; src: url("../fonts/Selawik-Bold.woff2") format("woff2"); }

:root {
  --ink: #1b2130;
  --paper: #f3f4f7;
  --surface: #ffffff;
  --rule: #d6dae3;
  --rule-soft: #e6e9ef;
  --muted: #566074;
  --wine: #7a1f3d;
  --wine-dark: #5c1630;
  --wine-wash: #f6e9ee;
  --ok: #1d6b4c;
  --warn: #8a6410;
  --err: #a32020;
  --blue: #34508a;
  --font: "Segoe UI", "Selawik", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  --measure: 68ch;
  --wrap: 1080px;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 1rem;
  line-height: 1.6;
  color: var(--ink);
  background: var(--paper);
}
img, iframe, audio { max-width: 100%; }
a { color: var(--wine); text-underline-offset: 2px; }
a:hover { color: var(--wine-dark); }
:focus-visible { outline: 3px solid #c9577d; outline-offset: 2px; border-radius: 2px; }

.wrap { width: min(var(--wrap), 100% - 2.5rem); margin-inline: auto; }
.skip { position: absolute; left: -999px; top: 0; background: var(--ink); color: #fff; padding: .6rem 1rem; z-index: 99; }
.skip:focus { left: 0; }

/* Header */
.site-head { background: var(--surface); border-bottom: 1px solid var(--rule); }
.site-head .wrap { display: flex; align-items: center; justify-content: space-between; gap: 1rem; min-height: 64px; flex-wrap: wrap; }
.brand { display: flex; align-items: baseline; gap: .6rem; text-decoration: none; color: var(--ink); }
.brand strong { font-size: 1.35rem; font-weight: 700; letter-spacing: .01em; color: var(--wine); }
.brand span { font-weight: 300; font-size: 1.05rem; color: var(--muted); }
.site-head .nav-toggle { display: none; }
.nav { display: flex; align-items: center; gap: .25rem; flex-wrap: wrap; }
.nav a, .nav button.linklike { color: var(--ink); text-decoration: none; padding: .5rem .8rem; border-radius: 4px; font-size: .97rem; }
.nav a:hover, .nav button.linklike:hover { background: var(--wine-wash); color: var(--wine-dark); }
.nav a[aria-current="page"] { font-weight: 600; box-shadow: inset 0 -2px 0 var(--wine); border-radius: 0; }
.nav .who { color: var(--muted); font-size: .9rem; padding: 0 .6rem; }
.nav form { margin: 0; }

@media (max-width: 720px) {
  .site-head .nav-toggle { display: inline-flex; }
  .nav { display: none; width: 100%; flex-direction: column; align-items: stretch; padding-bottom: .75rem; }
  .nav.open { display: flex; }
  .nav a, .nav button.linklike { padding: .75rem .5rem; text-align: left; }
}

/* Layout */
main { padding: 2rem 0 4rem; min-height: 60vh; }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .6rem; font-weight: 600; }
h1 { font-size: 1.9rem; font-weight: 300; letter-spacing: -.01em; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.05rem; }
p { margin: 0 0 1rem; }
.muted { color: var(--muted); }
.small { font-size: .88rem; }
.measure { max-width: var(--measure); }
.stack > * + * { margin-top: 1.25rem; }
.row { display: flex; gap: .75rem; flex-wrap: wrap; align-items: center; }
.row.between { justify-content: space-between; }

/* Flash */
.flash { margin: 0 0 1.25rem; padding: .75rem 1rem; border-left: 4px solid var(--ok); background: #eaf4ef; }
.flash.warn { border-color: var(--warn); background: #faf3e0; }
.flash.err { border-color: var(--err); background: #fbeaea; }

/* Buttons and forms */
.btn, button.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  min-height: 44px; padding: .55rem 1.1rem; border-radius: 4px; border: 1px solid var(--wine);
  background: var(--wine); color: #fff; font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
}
.btn:hover { background: var(--wine-dark); border-color: var(--wine-dark); color: #fff; }
.btn.ghost { background: transparent; color: var(--wine); }
.btn.ghost:hover { background: var(--wine-wash); color: var(--wine-dark); }
.btn.small { min-height: 36px; padding: .3rem .8rem; font-size: .9rem; }
.btn.danger { background: transparent; border-color: var(--err); color: var(--err); }
.btn.danger:hover { background: #fbeaea; color: var(--err); }
button.linklike { background: none; border: 0; font: inherit; color: var(--wine); cursor: pointer; padding: 0; text-decoration: underline; text-underline-offset: 2px; }

label { display: block; font-weight: 600; margin-bottom: .3rem; font-size: .95rem; }
.hint { display: block; font-weight: 400; color: var(--muted); font-size: .85rem; margin-top: .25rem; }
input[type=text], input[type=email], input[type=password], input[type=search], input[type=date], input[type=number], select, textarea {
  width: 100%; min-height: 44px; padding: .55rem .75rem; font: inherit; color: var(--ink);
  background: var(--surface); border: 1px solid #aeb4c2; border-radius: 4px;
}
textarea { min-height: 120px; resize: vertical; line-height: 1.5; }
input[type=file] { width: 100%; padding: .6rem; border: 1px dashed #aeb4c2; border-radius: 4px; background: var(--surface); font: inherit; }
.field + .field { margin-top: 1.1rem; }
.grid2 { display: grid; gap: 1.1rem; grid-template-columns: 1fr 1fr; }
.grid3 { display: grid; gap: 1.1rem; grid-template-columns: repeat(3, 1fr); }
@media (max-width: 720px) { .grid2, .grid3 { grid-template-columns: 1fr; } }
.hp { position: absolute; left: -5000px; height: 0; overflow: hidden; }

.panel { background: var(--surface); border: 1px solid var(--rule); padding: 1.5rem; }
.panel.narrow { max-width: 460px; }
.panel h1 { font-size: 1.6rem; }

/* Home hero */
.hero { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr); gap: 2.5rem; align-items: start; padding-bottom: 2rem; border-bottom: 1px solid var(--rule); }
@media (max-width: 860px) { .hero { grid-template-columns: 1fr; gap: 1.5rem; } }
.hero-ref { font-size: clamp(2.2rem, 6vw, 3.6rem); font-weight: 300; line-height: 1.05; letter-spacing: -.02em; color: var(--wine); margin: .25rem 0 .75rem; }
.hero-title { font-size: 1.35rem; font-weight: 600; margin-bottom: .4rem; }
.hero-meta { color: var(--muted); margin-bottom: 1rem; }
.hero-find h2 { font-weight: 300; font-size: 1.5rem; }
.searchbar { display: flex; gap: .5rem; }
.searchbar input { flex: 1; }
.quicklinks { margin-top: 1rem; padding: 0; list-style: none; display: grid; gap: .35rem; }
.fact { margin-top: 1.25rem; color: var(--muted); font-size: .92rem; }

/* Study list as ruled rows */
.rows { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--ink); }
.srow { display: grid; grid-template-columns: 6.5rem minmax(0, 1fr) minmax(8rem, auto); gap: 1.25rem; padding: 1rem 0; border-bottom: 1px solid var(--rule); align-items: baseline; }
.srow .when { color: var(--muted); font-size: .92rem; }
.srow .name { font-weight: 600; font-size: 1.08rem; text-decoration: none; color: var(--ink); }
.srow .name:hover { color: var(--wine); text-decoration: underline; }
.srow .ref { text-align: right; color: var(--wine); font-weight: 600; }
.srow .sub { color: var(--muted); font-size: .9rem; margin-top: .15rem; }
.srow .snippet { color: var(--muted); font-size: .92rem; margin-top: .35rem; max-width: var(--measure); }
@media (max-width: 720px) {
  .srow { grid-template-columns: 1fr; gap: .15rem; }
  .srow .ref { text-align: left; order: -1; }
}

.tag { display: inline-block; font-size: .8rem; padding: .1rem .55rem; border: 1px solid var(--rule); border-radius: 99px; color: var(--muted); text-decoration: none; background: var(--surface); margin: .15rem .25rem .15rem 0; }
a.tag:hover { border-color: var(--wine); color: var(--wine); }
.status { font-size: .78rem; font-weight: 600; padding: .05rem .5rem; border-radius: 3px; margin-left: .4rem; vertical-align: middle; }
.status.draft { background: #faf3e0; color: var(--warn); }
.status.public { background: #e3f2ea; color: var(--ok); }
.status.members { background: #e8edf8; color: var(--blue); }

/* Filters */
.filters { background: var(--surface); border: 1px solid var(--rule); padding: 1rem; display: grid; gap: .75rem; grid-template-columns: 2fr repeat(4, 1fr) auto; align-items: end; margin-bottom: 1.5rem; }
.filters label { font-size: .82rem; margin-bottom: .2rem; }
@media (max-width: 960px) { .filters { grid-template-columns: 1fr 1fr; } .filters .wide { grid-column: 1 / -1; } }
.pager { display: flex; gap: .4rem; align-items: center; margin-top: 1.5rem; flex-wrap: wrap; }
.pager a, .pager span { padding: .35rem .75rem; border: 1px solid var(--rule); background: var(--surface); text-decoration: none; border-radius: 4px; }
.pager .cur { background: var(--wine); color: #fff; border-color: var(--wine); }

/* Browse */
.book-grid { list-style: none; margin: 0 0 2rem; padding: 0; display: grid; gap: 0 1.5rem; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); }
.book-grid li { border-bottom: 1px solid var(--rule-soft); }
.book-grid a, .book-grid span.empty { display: flex; justify-content: space-between; padding: .5rem 0; text-decoration: none; color: var(--ink); }
.book-grid a:hover { color: var(--wine); }
.book-grid .n { color: var(--wine); font-weight: 600; }
.book-grid .empty { color: #9aa1b0; }

/* Study page */
.study-head { border-bottom: 1px solid var(--rule); padding-bottom: 1.25rem; margin-bottom: 1.5rem; }
.study-ref { font-size: clamp(1.8rem, 5vw, 2.8rem); font-weight: 300; color: var(--wine); line-height: 1.1; letter-spacing: -.015em; margin: 0 0 .4rem; }
.meta-line { margin: 0; display: flex; flex-wrap: wrap; gap: .15rem 1.25rem; }
.study-title { font-size: 1.5rem; font-weight: 600; margin: 0 0 .5rem; }
.study-layout { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 2.5rem; align-items: start; }
@media (max-width: 900px) { .study-layout { grid-template-columns: 1fr; } .study-layout .side { order: -1; } }
.notes { max-width: var(--measure); }
.notes p { margin-bottom: 1.1rem; }
.viewer { width: 100%; height: 78vh; min-height: 420px; border: 1px solid var(--rule); background: #fff; margin-bottom: .5rem; }
.files { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--rule); }
.files li { padding: .7rem 0; border-bottom: 1px solid var(--rule); }
.files .fname { font-weight: 600; word-break: break-word; }
.files .fmeta { color: var(--muted); font-size: .85rem; }
.side h2 { font-size: 1.05rem; }
.side .related { list-style: none; padding: 0; margin: 0; }
.side .related li { padding: .55rem 0; border-bottom: 1px solid var(--rule-soft); }
.side .related a { text-decoration: none; font-weight: 600; color: var(--ink); }
.side .related a:hover { color: var(--wine); }

/* Comments */
.comments { margin-top: 2.5rem; max-width: var(--measure); }
.comment { padding: 1rem 0; border-bottom: 1px solid var(--rule); }
.comment .who { font-weight: 600; }
.comment .when { color: var(--muted); font-size: .85rem; margin-left: .5rem; }
.comment .body { margin: .35rem 0 .5rem; white-space: pre-wrap; word-break: break-word; }
.comment .acts { display: flex; gap: 1rem; font-size: .88rem; }
.comment.hidden-c { opacity: .6; }
.replies { margin: .5rem 0 0 1.25rem; padding-left: 1rem; border-left: 2px solid var(--rule); }
.replies .comment { border-bottom: 0; padding: .6rem 0; }
.reply-form { margin-top: .6rem; display: none; }
.reply-form.open { display: block; }
.badge-admin { font-size: .75rem; color: var(--wine); border: 1px solid var(--wine); border-radius: 3px; padding: 0 .35rem; margin-left: .35rem; }

/* Tables */
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--rule); }
table { border-collapse: collapse; width: 100%; font-size: .93rem; }
th, td { text-align: left; padding: .65rem .8rem; border-bottom: 1px solid var(--rule-soft); vertical-align: middle; }
th { font-weight: 600; background: #fafbfc; white-space: nowrap; }
td form { display: inline; margin: 0; }
.statgrid { display: flex; gap: 2.5rem; flex-wrap: wrap; margin: 1rem 0 1.5rem; }
.statgrid div strong { display: block; font-size: 1.8rem; font-weight: 300; color: var(--wine); line-height: 1.1; }

.foot { border-top: 1px solid var(--rule); padding: 1.25rem 0 2rem; color: var(--muted); font-size: .88rem; }

@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; scroll-behavior: auto !important; } }
@media print {
  .site-head, .foot, .comments, .nav, .side .btn, .viewer { display: none !important; }
  body { background: #fff; }
}
