:root {
  color-scheme: light;
  --border: #e5e7eb;
  --bg: #fafafa;
  --surface: #fff;
  --ink: #18181b;
  --muted: #71717a;
  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --radius: 8px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  font-family: -apple-system, "Segoe UI", Inter, Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.5;
}

h1 { font-size: 1.4rem; margin: 0.4rem 0 1rem; }
h2 { font-size: 1.1rem; margin: 1.5rem 0 0.6rem; }
h3 { font-size: 1rem; margin: 1.2rem 0 0.4rem; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

button, .search-form button, .zoom-controls button {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 0.4rem 0.8rem;
  font: inherit;
  font-size: 0.85rem;
  cursor: pointer;
}
button:hover { background: var(--accent-hover); }

input, select, textarea {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.45rem 0.6rem;
  font: inherit;
  background: var(--surface);
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1.5rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar .brand { font-weight: 600; font-size: 1.05rem; color: var(--ink); }
.topbar nav { display: flex; gap: 1.25rem; align-items: center; font-size: 0.9rem; }
.topbar .who { color: var(--muted); }
.linklike {
  background: none; border: none; padding: 0; margin: 0;
  color: var(--muted); text-decoration: none; cursor: pointer;
  font: inherit; font-size: 0.9rem;
}
.linklike:hover { color: var(--accent); }

main { flex: 1; width: 100%; max-width: 1400px; margin: 0 auto; padding: 1.5rem; }

.sitefooter {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1.25rem;
  padding: 0.75rem 1.5rem;
  border-top: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  font-size: 0.82rem;
}
.sitefooter-brand { font-weight: 600; color: var(--muted); }
.sitefooter-links { display: flex; gap: 1.25rem; }
.sitefooter a { color: var(--muted); }
.sitefooter a:hover { color: var(--accent); }

form.auth {
  max-width: 360px;
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
}
form.auth label { font-size: 0.85rem; color: var(--muted); display: flex; flex-direction: column; gap: 0.25rem; }
form.auth button { margin-top: 0.3rem; align-self: flex-start; }
.error { color: #dc2626; font-size: 0.9rem; }

.hero {
  text-align: center;
  padding: 3.5rem 1.5rem 3rem;
  margin: -1.5rem -1.5rem 2.5rem;
  background: linear-gradient(180deg, #eef2ff 0%, var(--bg) 100%);
  border-bottom: 1px solid var(--border);
}
.hero .eyebrow {
  margin: 0 0 0.6rem;
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--accent);
}
.hero h1 { font-size: 2rem; margin: 0 0 0.7rem; }
.hero .subtitle {
  max-width: 44ch;
  margin: 0 auto 1.8rem;
  color: var(--muted);
  font-size: 1.05rem;
}

.doc-cta { display: flex; justify-content: center; flex-wrap: wrap; gap: 0.75rem; }
.doc-cta-button {
  display: inline-block;
  background: var(--accent);
  color: #fff;
  border-radius: var(--radius);
  padding: 0.9rem 1.8rem;
  font-size: 1.1rem;
  font-weight: 600;
  box-shadow: 0 4px 14px rgb(79 70 229 / 0.25);
  transition: background 0.12s, box-shadow 0.12s, transform 0.12s;
}
.doc-cta-button:hover {
  background: var(--accent-hover);
  text-decoration: none;
  box-shadow: 0 6px 18px rgb(79 70 229 / 0.3);
  transform: translateY(-1px);
}

.status-overview {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 1rem;
  max-width: 76ch;
  margin: 0 auto 2.5rem;
}
.status-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 1rem 1.1rem;
}
.status-card h3 { margin: 0 0 0.5rem; }
.progress-bar {
  display: flex;
  height: 0.6rem;
  border-radius: 999px;
  background: var(--bg);
  overflow: hidden;
  margin-bottom: 0.5rem;
}
.progress-seg { height: 100%; }
.seg-approved { background: #22c55e; }
.seg-pending { background: #f59e0b; }
.seg-untouched { background: #d4d4d8; }
.status-total { margin: 0; font-size: 0.85rem; color: var(--muted); }

.contributors { max-width: 76ch; margin: 0 auto 2.5rem; text-align: center; }
.contributors h3 { margin: 0 0 0.25rem; }
.contributors-intro { margin: 0 0 1rem; font-size: 0.85rem; color: var(--muted); }
.contributor-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.6rem;
}
.contributor-row {
  display: flex;
  align-items: baseline;
  gap: 0.4rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  padding: 0.35rem 0.8rem;
  font-size: 0.85rem;
}
.contributor-name { font-weight: 600; }
.contributor-count { color: var(--muted); font-size: 0.78rem; }
.contributor-row-me {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 10%, var(--surface));
}

.contributor-prompt {
  max-width: 76ch;
  margin: 0 auto 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 0.8rem 1rem;
}
.contributor-prompt p { margin: 0 0 0.5rem; font-size: 0.9rem; }
.contributor-prompt-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.contributor-prompt-actions input[type="text"] { flex: 1 1 14rem; }

.contributor-me {
  max-width: 76ch;
  margin: 0 auto 2.5rem;
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--accent) 6%, var(--surface));
  padding: 0.8rem 1rem;
  text-align: center;
}
.contributor-me p { margin: 0 0 0.6rem; font-size: 0.9rem; }
.contributor-me form { display: flex; gap: 0.5rem; justify-content: center; flex-wrap: wrap; }
.contributor-me input[type="text"] { flex: 1 1 14rem; }

.about { max-width: 76ch; margin: 0 auto; }
.about-row {
  display: grid;
  grid-template-columns: 150px 1fr;
  gap: 1.5rem;
  padding: 1.15rem 0;
  border-top: 1px solid var(--border);
}
.about-row:first-child { border-top: none; padding-top: 0; }
.about-label {
  margin: 0;
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}
.about-text p { margin: 0; font-size: 0.95rem; }
.about-text a { font-weight: 500; }
@media (max-width: 640px) {
  .about-row { grid-template-columns: 1fr; gap: 0.35rem; }
}

.page-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 0.6rem;
}
.page-tile {
  display: block;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.6rem;
  text-align: center;
  color: var(--ink);
  background: var(--surface);
  transition: box-shadow 0.12s, border-color 0.12s;
}
.page-tile:hover {
  text-decoration: none;
  border-color: var(--accent);
  box-shadow: 0 2px 8px rgb(0 0 0 / 0.06);
}
.page-tile .no { font-weight: 600; }
.page-tile .cov { font-size: 0.78rem; color: var(--muted); margin-top: 0.15rem; }

.viewer {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.25rem;
  align-items: start;
}
@media (max-width: 900px) { .viewer { grid-template-columns: 1fr; } }

.image-pane {
  position: sticky;
  top: 4.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  overflow: hidden;
  height: 85vh;
  display: flex;
  flex-direction: column;
}
.image-pane .viewport {
  width: 100%;
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  cursor: grab;
  background: #f4f4f5;
}
.image-pane .scalable { position: relative; display: inline-block; transform-origin: 0 0; }
.image-pane img { display: block; max-width: none; }
.zoom-controls {
  height: 2.4rem;
  display: flex;
  gap: 0.3rem;
  align-items: center;
  padding: 0.4rem 0.6rem;
  border-bottom: 1px solid var(--border);
}
.zoom-controls button { background: var(--bg); color: var(--ink); border: 1px solid var(--border); }
.zoom-controls button:hover { background: var(--border); }

#line-overlay {
  position: absolute;
  top: 0;
  left: 0;
  pointer-events: none;
}
#line-overlay polygon {
  fill: rgba(79, 70, 229, 0);
  stroke: transparent;
  stroke-width: 4;
  pointer-events: auto;
  cursor: pointer;
  transition: fill 0.15s, stroke 0.15s;
}
#line-overlay polygon:hover {
  fill: rgba(79, 70, 229, 0.12);
}
#line-overlay polygon.highlighted {
  fill: rgba(79, 70, 229, 0.22);
  stroke: var(--accent);
}

.text-pane { padding-bottom: 2rem; }
.zone-block { margin-bottom: 1rem; }
.line-row {
  display: flex;
  align-items: baseline;
  gap: 0.6rem;
  padding: 0.3rem 0.5rem;
  border-radius: 6px;
  cursor: pointer;
}
.line-row:hover { background: var(--bg); }
.line-row.highlighted { background: #eef2ff; outline: 1px solid var(--accent); }
.line-text { flex: 1; }
.translation-row { font-size: 0.92rem; color: var(--muted); border-left: 2px solid var(--border); margin-left: 0.3rem; padding-left: 0.5rem; }
.translation-row .line-text { color: var(--ink); }
.history-panel:empty { display: none; }
.history-panel-inner {
  margin: 0.2rem 0 0.6rem 0.3rem;
  padding: 0.7rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}
.history-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 0.5rem; font-size: 0.9rem; }
.history-toggle { background: none; color: var(--muted); border: none; padding: 0; font-size: 0.8rem; }
.history-toggle:hover { color: var(--accent); background: none; }
.timeline { list-style: none; margin: 0; padding: 0 0 0 0.6rem; border-left: 2px solid var(--border); }
.timeline li { position: relative; padding: 0 0 0.9rem 1rem; display: flex; gap: 0.6rem; }
.timeline li:last-child { padding-bottom: 0; }
.timeline-dot { margin-top: 0.3rem; margin-left: -1.35rem; box-shadow: 0 0 0 2px var(--surface); }
.timeline-card { flex: 1; font-size: 0.85rem; }
.timeline-top { display: flex; gap: 0.5rem; align-items: baseline; flex-wrap: wrap; color: var(--muted); }
.timeline-top .action { color: var(--ink); font-weight: 500; }
.timeline-top time { font-size: 0.75rem; }
.field-tag {
  font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.03em;
  padding: 0.1rem 0.4rem; border-radius: 4px; background: var(--bg); color: var(--muted);
}
.field-tag.field-translation { background: #eef2ff; color: var(--accent); }
.timeline-text { margin-top: 0.15rem; }
.timeline-note { margin-top: 0.15rem; font-size: 0.8rem; color: var(--muted); font-style: italic; }

.notes-toggle { background: none; color: var(--muted); border: none; padding: 0; font-size: 0.8rem; }
.notes-toggle:hover { color: var(--accent); background: none; }
.notes-toggle.has-notes { color: var(--accent); font-weight: 500; }
.note-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.1rem;
  height: 1.1rem;
  padding: 0 0.3rem;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 0.68rem;
  font-weight: 600;
}
.notes-panel:empty { display: none; }
.notes-panel-inner {
  margin: 0.2rem 0 0.6rem 0.3rem;
  padding: 0.7rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}
.notes-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 0.5rem; font-size: 0.9rem; }
.notes-list { list-style: none; margin: 0 0 0.6rem; padding: 0; display: flex; flex-direction: column; gap: 0.55rem; }
.note-item { border-left: 2px solid var(--accent); padding-left: 0.6rem; }
.note-top { display: flex; gap: 0.5rem; font-size: 0.78rem; color: var(--muted); }
.note-top time { font-size: 0.72rem; }
.note-body { font-size: 0.85rem; margin-top: 0.1rem; white-space: pre-wrap; }
.note-form { display: flex; gap: 0.4rem; align-items: flex-end; }
.note-form textarea { flex: 1; font: inherit; }

.review-list { display: flex; flex-direction: column; gap: 0.6rem; }
.review-row {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 0.6rem;
}
.thumb {
  flex: none;
  align-self: center;
  width: 660px;
  height: 180px;
  max-width: 100%;
  border-radius: 6px;
  border: 1px solid var(--border);
  background-color: #f4f4f5;
}
.review-row-body { flex: 1; min-width: 0; }
.review-row-top { display: flex; align-items: baseline; gap: 0.5rem; }
.review-row .meta { font-size: 0.8rem; color: var(--muted); margin: 0.15rem 0 0.4rem; }
.diff-caption { font-size: 0.72rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.02em; margin-bottom: 0.1rem; }
.diff-add { background: #dcfce7; color: #166534; border-radius: 3px; padding: 0 0.05rem; }
.diff-del { background: #fef2f2; color: #b91c1c; text-decoration: line-through; border-radius: 3px; padding: 0 0.05rem; }
.review-row-ref {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  font-size: 0.85rem;
  color: var(--muted);
  padding-top: 0.4rem;
  border-top: 1px dashed var(--border);
}
.review-row-ref .ref-label { flex: none; font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.02em; }
.status-dot {
  display: inline-block;
  width: 0.55rem;
  height: 0.55rem;
  border-radius: 50%;
  flex: none;
}
.status-unreviewed { background: #a1a1aa; }
.status-pending_review { background: #f59e0b; }
.status-approved { background: #22c55e; }
.status-needs_recheck { background: #f97316; }
.status-orphaned { background: #ef4444; }
.status-not_transcribed { background: transparent; border: 1px dashed var(--muted); }

.legend { display: flex; gap: 1rem; flex-wrap: wrap; font-size: 0.8rem; color: var(--muted); margin-bottom: 1rem; }
.legend .status-dot { margin-right: 0.3rem; }

.line-actions { display: flex; gap: 0.3rem; align-items: center; }
.line-actions button { font-size: 0.75rem; padding: 0.2rem 0.5rem; background: var(--bg); color: var(--ink); border: 1px solid var(--border); }
.line-actions button:hover { background: var(--border); }
.line-actions a { color: var(--muted); font-size: 0.8rem; }

textarea.edit-box { width: 100%; font: inherit; }

table.history { border-collapse: collapse; width: 100%; font-size: 0.9rem; }
table.history th, table.history td { border-bottom: 1px solid var(--border); padding: 0.5rem 0.6rem; text-align: left; }
table.history th { color: var(--muted); font-weight: 500; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.02em; }

.flash { padding: 0.6rem 0.9rem; margin-bottom: 1rem; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--border); }
.flash.ok { border-color: #22c55e; background: #f0fdf4; }
.flash.err { border-color: #ef4444; background: #fef2f2; color: #b91c1c; }

.not-transcribed { color: var(--muted); font-style: italic; }
.source-attribution { color: var(--muted); font-size: 0.8rem; padding: 0.4rem 0.6rem; margin: 0; flex-shrink: 0; border-top: 1px solid var(--border); }

.search-form { display: flex; gap: 0.5rem; max-width: 480px; margin: 0.8rem 0; }
.search-form input { flex: 1; }
.search-results { list-style: none; padding: 0; }
.search-results li { padding: 0.6rem 0; border-bottom: 1px solid var(--border); }
.search-results mark { background: #fef08a; color: inherit; padding: 0 0.1em; border-radius: 2px; }
