/* stainkit frontend — medical journal aesthetic */

:root {
  color-scheme: light dark;

  /* Light theme: paper-like cream, deep ink, crimson accent */
  --paper:        #fbf8f1;     /* aged paper */
  --paper-deep:   #f3eee2;     /* margin tint */
  --ink:          #14202e;     /* deep navy text */
  --ink-soft:     #3d4a5c;     /* secondary text */
  --rule:         #c9bfa7;     /* warm gray rule */
  --rule-soft:    #e3dcc9;     /* lighter rule */
  --crimson:      #8b1a1a;     /* NEJM-like accent */
  --crimson-soft: #f4e7e7;
  --shadow:       0 1px 0 rgba(20, 32, 46, 0.06);
  --serif:        "Source Serif 4", "Charter", "Iowan Old Style", "Georgia", "Times New Roman", serif;
  --sans:         "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  --mono:         "JetBrains Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper:      #0e1318;
    --paper-deep: #161b22;
    --ink:        #e8e0d0;
    --ink-soft:   #a8987c;
    --rule:       #303740;
    --rule-soft:  #1f262d;
    --crimson:    #d97a7a;
    --crimson-soft:#3a1e1e;
    --shadow:     0 1px 0 rgba(255, 255, 255, .04);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }

body {
  font-family: var(--serif);
  font-size: 17px;
  line-height: 1.62;
  color: var(--ink);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

a { color: var(--crimson); text-decoration: none; border-bottom: 1px solid currentColor; padding-bottom: 1px; }
a:hover { color: var(--ink); }

/* ---------- Page frame ---------- */
.page {
  max-width: 760px;
  margin: 0 auto;
  padding: 64px 32px 80px;
}

/* Subtle paper texture */
.page::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(ellipse at top left, var(--crimson-soft), transparent 50%),
    radial-gradient(ellipse at bottom right, var(--paper-deep), transparent 50%);
  opacity: 0.4;
  z-index: -1;
}

/* ---------- Masthead ---------- */
.masthead {
  text-align: center;
  padding-bottom: 36px;
  border-bottom: 3px double var(--ink);
  margin-bottom: 48px;
}
.vol {
  font-family: var(--sans);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink-soft);
  margin-bottom: 18px;
}
.vol .num { color: var(--crimson); }
.masthead-row {
  display: flex;
  align-items: center;
  gap: 22px;
  margin: 0 0 12px;
}
.masthead-mark {
  display: block;
  width: 84px;
  height: 84px;
  flex: 0 0 auto;
}
.wordmark {
  font-family: var(--serif);
  font-size: 76px;
  font-weight: 700;
  letter-spacing: -0.04em;
  line-height: 1;
  margin: 0;
  color: var(--ink);
}
.kicker {
  font-family: var(--sans);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-soft);
  margin: 0;
}

/* ---------- Article ---------- */
article > section {
  margin: 0 0 56px;
}

section h2 {
  font-family: var(--serif);
  font-size: 26px;
  font-weight: 600;
  letter-spacing: -0.01em;
  line-height: 1.2;
  margin: 0 0 4px;
  color: var(--ink);
}
section h2 + .caption {
  margin: 0 0 20px;
}

.caption {
  font-family: var(--sans);
  font-size: 13px;
  font-style: italic;
  color: var(--ink-soft);
  line-height: 1.5;
}

/* ---------- Lede ---------- */
.lede h2 {
  font-family: var(--serif);
  font-style: italic;
  font-weight: 500;
  font-size: 19px;
  display: inline;
  color: var(--ink);
  margin-right: 6px;
}
.lede p {
  margin: 0;
  text-align: justify;
  hyphens: auto;
}

/* ---------- Sample gallery ---------- */
.gallery {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin-top: 20px;
}
@media (max-width: 640px) { .gallery { grid-template-columns: repeat(2, 1fr); } }
.sample {
  position: relative;
  cursor: pointer;
  margin: 0;
  border: 1px solid var(--rule);
  background: #fff;
  transition: border-color 0.15s ease, transform 0.15s ease;
}
.sample:hover {
  border-color: var(--ink);
  transform: translateY(-2px);
}
.sample:focus-visible {
  outline: 2px solid var(--crimson);
  outline-offset: 2px;
}
.sample img {
  display: block;
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  background: #fff;
}
.sample figcaption {
  padding: 8px 10px;
  border-top: 1px solid var(--rule-soft);
  background: var(--paper-deep);
  font-family: var(--sans);
  font-size: 12px;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
}
.sample figcaption strong { font-weight: 600; color: var(--ink); }
.sample figcaption small { color: var(--ink-soft); font-size: 11px; }
.sample .badge {
  position: absolute;
  top: 8px;
  right: 8px;
  background: var(--ink);
  color: var(--paper);
  font-family: var(--sans);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 3px 8px;
  border-radius: 2px;
  opacity: 0;
  transition: opacity 0.15s ease;
}
.sample:hover .badge { opacity: 1; }

/* ---------- Upload form ---------- */
#upload {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: stretch;
  margin-top: 4px;
}
.file-pick {
  position: relative;
  display: flex;
  align-items: center;
  flex: 1 1 280px;
  min-width: 220px;
  padding: 14px 18px;
  border: 1px dashed var(--rule);
  background: var(--paper-deep);
  color: var(--ink-soft);
  cursor: pointer;
  font-family: var(--sans);
  font-size: 14px;
  transition: border-color 0.15s ease, color 0.15s ease, background-color 0.15s ease;
}
.file-pick:hover {
  border-color: var(--ink);
  color: var(--ink);
}
.file-pick.has-file {
  border-style: solid;
  border-color: var(--crimson);
  color: var(--ink);
  background: var(--crimson-soft);
}
.file-pick input[type=file] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

button {
  font-family: var(--sans);
  font-weight: 500;
  font-size: 14px;
  padding: 14px 22px;
  border: 1px solid var(--ink);
  background: var(--ink);
  color: var(--paper);
  cursor: pointer;
  letter-spacing: 0.02em;
  transition: background-color 0.15s ease, color 0.15s ease;
}
button:hover:not(:disabled) {
  background: var(--crimson);
  border-color: var(--crimson);
}
button:focus-visible { outline: 2px solid var(--crimson); outline-offset: 2px; }
button:disabled { opacity: 0.55; cursor: wait; }

.status {
  font-family: var(--sans);
  font-size: 13px;
  color: var(--ink-soft);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 18px;
  margin-left: 4px;
  padding: 0 6px;
  font-style: italic;
}
.status.busy::before {
  content: "";
  display: inline-block;
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--crimson);
  animation: pulse 1s infinite;
}
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.3; } }

/* ---------- Results ---------- */
img.panel {
  display: block;
  width: 100%;
  height: auto;
  margin: 0;
  border: 1px solid var(--rule);
}
.fig { margin: 0; }
.fig-full { margin: 24px 0 12px; }
.fig-full figcaption,
.fig figcaption {
  font-family: var(--sans);
  font-size: 12.5px;
  color: var(--ink-soft);
  line-height: 1.45;
  text-align: justify;
  padding: 8px 0 0;
  margin: 0;
}
.fig-full figcaption strong {
  font-family: var(--serif);
  font-weight: 600;
  font-style: normal;
  font-size: 13.5px;
  color: var(--ink);
}

.row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
  margin-top: 8px;
}
@media (max-width: 640px) { .row { grid-template-columns: 1fr; } }

details {
  margin-top: 28px;
  border-top: 1px solid var(--rule);
  padding-top: 12px;
}
details summary {
  cursor: pointer;
  font-family: var(--sans);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink-soft);
  list-style: none;
}
details summary::-webkit-details-marker { display: none; }
pre {
  margin: 12px 0 0;
  padding: 12px 14px;
  background: var(--paper-deep);
  border: 1px solid var(--rule-soft);
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.55;
  color: var(--ink-soft);
  max-height: 240px;
  overflow: auto;
  white-space: pre-wrap;
}

/* ---------- Errors ---------- */
#error-section pre {
  background: var(--paper-deep);
  color: var(--crimson);
  border-color: var(--crimson);
  font-size: 12.5px;
}
#error-section button {
  margin-top: 16px;
  border: 1px solid var(--crimson);
  background: transparent;
  color: var(--crimson);
}
#error-section button:hover { background: var(--crimson); color: var(--paper); }

/* ---------- References ---------- */
.refs {
  list-style: none;
  margin: 16px 0 0;
  padding: 0;
  counter-reset: ref;
}
.refs li {
  position: relative;
  padding: 8px 0 8px 36px;
  border-top: 1px solid var(--rule-soft);
  font-size: 14.5px;
  line-height: 1.5;
  text-indent: -12px;
  margin-left: 12px;
}
.refs li::before {
  counter-increment: ref;
  content: counter(ref);
  position: absolute;
  left: 0;
  top: 8px;
  width: 24px;
  font-family: var(--serif);
  font-weight: 600;
  color: var(--crimson);
  text-align: right;
  text-indent: 0;
}
.refs em { font-style: italic; }
.refs a { color: var(--crimson); }

/* ---------- Footer ---------- */
footer {
  border-top: 3px double var(--ink);
  margin-top: 64px;
  padding-top: 24px;
  text-align: center;
  font-family: var(--sans);
  font-size: 12px;
  color: var(--ink-soft);
}
footer a {
  color: var(--ink);
  border-bottom-color: var(--ink);
}
footer a:hover { color: var(--crimson); border-bottom-color: var(--crimson); }
footer .imprint { font-style: italic; }