/* Bobhata Annotate: reading-first, mobile-first. No build step. */
:root {
  --bg: #faf7f0;
  --paper: #ffffff;
  --ink: #1f1b16;
  --muted: #6b6257;
  --line: #e4ddd0;
  --soft: #f3eee4;
  --accent: #9a3f0e;
  --accent-ink: #ffffff;
  --accent-soft: #fbe9dc;
  --ok: #1f7a4a;
  --ok-soft: #e1f3e8;
  --warn: #8a5a00;
  --warn-soft: #fff3cd;
  --bad: #b42318;
  --bad-soft: #fde4e1;
  --ins: #dcfae6; --ins-ink: #067647;
  --del: #fde2e1; --del-ink: #b42318;
  --focus: #2563eb;
  --read-font: "Noto Serif Devanagari", "Tiro Devanagari Marathi", "Kohinoor Devanagari", "Mangal", "Nirmala UI", Georgia, serif;
  --ui-font: "Noto Sans Devanagari", system-ui, -apple-system, "Segoe UI", "Kohinoor Devanagari", "Nirmala UI", sans-serif;
  --read-size: 20px;
  --radius: 12px;
  --gutter: 16px;
  --tabs-h: 56px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #17140f; --paper: #211d17; --ink: #ece6dc; --muted: #b3a998; --line: #3a342b; --soft: #2a251e;
    --accent: #f0a060; --accent-ink: #1b1209; --accent-soft: #3d2a1a;
    --ok: #6fd39b; --ok-soft: #173826; --warn: #f3c969; --warn-soft: #3b3014; --bad: #ff9b8f; --bad-soft: #4a1d18;
    --ins: #153d26; --ins-ink: #a6f4c5; --del: #5a1f1c; --del-ink: #ffb4ab; --focus: #8ab4ff;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #17140f; --paper: #211d17; --ink: #ece6dc; --muted: #b3a998; --line: #3a342b; --soft: #2a251e;
  --accent: #f0a060; --accent-ink: #1b1209; --accent-soft: #3d2a1a;
  --ok: #6fd39b; --ok-soft: #173826; --warn: #f3c969; --warn-soft: #3b3014; --bad: #ff9b8f; --bad-soft: #4a1d18;
  --ins: #153d26; --ins-ink: #a6f4c5; --del: #5a1f1c; --del-ink: #ffb4ab; --focus: #8ab4ff;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 17px/1.55 var(--ui-font); overflow-x: hidden; }
a { color: var(--accent); }
h1, h2, h3 { line-height: 1.35; margin: 0 0 .4em; }
h1 { font-size: 1.45rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1.05rem; }
p { margin: 0 0 .8em; }
.muted { color: var(--muted); }
.small { font-size: .88rem; }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 6px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.page { max-width: 46rem; margin: 0 auto; padding: 12px var(--gutter) 96px; }
.page.narrow { max-width: 36rem; padding-top: 48px; }
body.admin .page { max-width: 72rem; }

/* ---------- buttons ---------- */
button, .btn {
  font: inherit; font-size: 1rem; min-height: 44px; padding: 8px 16px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--paper); color: var(--ink); cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; text-decoration: none; line-height: 1.2;
  -webkit-tap-highlight-color: transparent; touch-action: manipulation;
}
button:hover, .btn:hover { border-color: var(--muted); }
button:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn-primary:hover { filter: brightness(1.05); border-color: var(--accent); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: var(--soft); border-color: transparent; }
.btn-danger { color: var(--bad); }
.btn-big { min-height: 52px; font-size: 1.1rem; padding: 10px 22px; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.btn-row.spread { justify-content: space-between; }
.icon-btn { min-width: 44px; padding: 6px 10px; }

/* ---------- top bar ---------- */
.topbar {
  display: flex; align-items: center; gap: 6px; padding: 6px 0; min-height: 52px; flex-wrap: nowrap;
}
.topbar .grow { flex: 1; min-width: 0; }
.topbar .where { font-size: .92rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.save-state { flex: 0 0 auto; font-size: .85rem; color: var(--muted); white-space: nowrap; display: inline-flex; align-items: center; gap: 4px; }
.save-state.ok { color: var(--ok); }
.save-state.err { color: var(--bad); }
.save-state.busy::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--warn); display: inline-block; }
.fontctl { display: inline-flex; gap: 2px; }
.fontctl button { min-width: 44px; padding: 4px 8px; font-weight: 600; }
@media (max-width: 400px) { .theme-btn { display: none !important; } .topbar { gap: 2px; } .topbar .icon-btn { padding: 6px 6px; } }

/* ---------- cards / home ---------- */
.card { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin: 12px 0; }
.card > :last-child { margin-bottom: 0; }
details.card > summary { cursor: pointer; font-weight: 600; min-height: 32px; display: flex; align-items: center; list-style: none; }
details.card > summary::-webkit-details-marker { display: none; }
details.card > summary::before { content: "▸"; margin-right: 8px; transition: transform .15s; }
details.card[open] > summary::before { transform: rotate(90deg); }
details.card[open] > summary { margin-bottom: 8px; }
.md h1, .md h2, .md h3 { margin-top: .6em; }
.md ul, .md ol { padding-left: 1.4em; margin: 0 0 .8em; }
.md li { margin: .25em 0; }
.md code { background: var(--soft); padding: 0 4px; border-radius: 4px; }

.progress { height: 10px; background: var(--soft); border-radius: 6px; overflow: hidden; border: 1px solid var(--line); }
.progress > i { display: block; height: 100%; background: var(--ok); border-radius: 6px; transition: width .3s; }
.progress-line { display: flex; justify-content: space-between; gap: 8px; font-size: .95rem; margin: 6px 0; }

.item-list { list-style: none; padding: 0; margin: 0; }
.item-list li + li { border-top: 1px solid var(--line); }
.item-link { display: flex; align-items: center; gap: 12px; padding: 12px 4px; min-height: 60px; color: var(--ink); text-decoration: none; }
.item-link:hover { background: var(--soft); }
.item-num { flex: 0 0 auto; width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; background: var(--soft); font-weight: 600; font-size: .95rem; }
.item-title { flex: 1; min-width: 0; }
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 2px 10px; border-radius: 999px; font-size: .82rem; border: 1px solid var(--line); white-space: nowrap; color: var(--muted); }
.chip.submitted { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.chip.draft { background: var(--warn-soft); color: var(--warn); border-color: transparent; }

/* ---------- banners ---------- */
.banner { border-radius: 10px; padding: 12px 14px; margin: 10px 0; border: 1px solid transparent; }
.banner.warn { background: var(--warn-soft); color: var(--ink); border-color: color-mix(in srgb, var(--warn) 35%, transparent); }
.banner.bad { background: var(--bad-soft); border-color: color-mix(in srgb, var(--bad) 35%, transparent); }
.banner.ok { background: var(--ok-soft); }
.banner .btn-row { margin-top: 8px; }

/* ---------- prompt ---------- */
.prompt-head h1 { font-size: 1.35rem; margin: 6px 0 4px; }
.prompt-text { font-family: var(--read-font); font-size: calc(var(--read-size) * .9); line-height: 1.7; white-space: pre-line; }

/* ---------- candidate tabs (sticky, small, never wraps the text) ---------- */
.cand-tabs {
  position: sticky; top: 0; z-index: 20; background: var(--bg);
  display: flex; gap: 6px; padding: 6px 0; margin: 8px 0 4px;
  border-bottom: 1px solid var(--line);
  overflow-x: auto; scrollbar-width: none;
}
.cand-tabs::-webkit-scrollbar { display: none; }
.cand-tab {
  flex: 1 0 44px; min-height: 44px; padding: 4px 8px; font-size: 1.1rem; font-weight: 600;
  border-radius: 10px; position: relative; background: var(--paper);
}
.cand-tab.final { flex: 1.6 0 auto; font-size: .95rem; font-weight: 600; }
.cand-tab[aria-selected="true"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.cand-tab .tick { font-size: .75rem; margin-left: 2px; color: var(--ok); }
.cand-tab[aria-selected="true"] .tick { color: inherit; }
.cand-tab.done:not([aria-selected="true"]) { background: var(--ok-soft); border-color: transparent; }

.cand-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; margin: 14px 0 6px; flex-wrap: wrap; }
.cand-head h2 { margin: 0; font-size: 1.25rem; }
.cand-title { font-family: var(--read-font); font-size: calc(var(--read-size) * 1.15); font-weight: 600; margin: 4px 0 10px; }

/* ---------- reading ---------- */
.reading {
  font-family: var(--read-font); font-size: var(--read-size); line-height: 1.78;
  max-width: 38em; overflow-wrap: break-word; word-break: normal; hyphens: manual;
  font-kerning: normal; text-rendering: optimizeLegibility;
}
.reading p { margin: 0 0 1em; white-space: pre-line; }
.reading.verse p { white-space: pre-wrap; margin-bottom: 1.3em; }
.reading-wrap { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 18px 8px; }
@media (max-width: 480px) { .reading-wrap { padding: 14px 14px 4px; border-radius: 10px; } }
.context { font-size: .92rem; color: var(--muted); margin: 6px 0 10px; white-space: pre-line; }
.read-end { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin: 12px 0; }
.read-toggle[aria-pressed="true"] { background: var(--ok-soft); color: var(--ok); border-color: transparent; font-weight: 600; }

/* image + diff */
.figure { background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 6px; overflow: auto; cursor: zoom-in; }
.figure img { display: block; max-width: 100%; height: auto; margin: 0 auto; }
.figure.zoom { cursor: zoom-out; }
.figure.zoom img { max-width: none; height: auto; width: 200%; }
.diffline { font-family: var(--read-font); font-size: calc(var(--read-size) * 1.15); line-height: 1.8; overflow-wrap: anywhere; }
.diffline del { background: var(--del); color: var(--del-ink); text-decoration: none; border-radius: 3px; }
.diffline ins { background: var(--ins); color: var(--ins-ink); text-decoration: none; border-radius: 3px; }
.kv-label { font-size: .85rem; color: var(--muted); margin-top: 10px; }

/* ---------- fields ---------- */
.fields { margin: 14px 0; }
.field { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin: 10px 0; }
.field.invalid { border-color: var(--bad); box-shadow: 0 0 0 2px color-mix(in srgb, var(--bad) 25%, transparent); }
.field-label { font-weight: 600; font-size: 1.05rem; display: block; margin-bottom: 2px; }
.field-label .req { color: var(--bad); margin-left: 3px; }
.field-help { color: var(--muted); font-size: .92rem; margin-bottom: 8px; }
.field-error { color: var(--bad); font-size: .9rem; margin-top: 6px; }

.likert { display: flex; gap: 6px; }
.likert button { flex: 1 1 0; min-width: 0; min-height: 48px; font-size: 1.15rem; font-weight: 600; padding: 4px; }
.likert button[aria-checked="true"], .opt[aria-checked="true"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.likert-ends { display: flex; justify-content: space-between; gap: 8px; font-size: .82rem; color: var(--muted); margin-top: 4px; }
.likert-ends span { flex: 1; }
.likert-ends span:nth-child(2) { text-align: center; }
.likert-ends span:last-child { text-align: right; }
.likert-point { font-size: .9rem; color: var(--muted); margin-top: 4px; min-height: 1.3em; }
.na-btn { margin-top: 8px; font-size: .92rem; min-height: 40px; }
.na-btn[aria-checked="true"] { background: var(--soft); border-color: var(--muted); font-weight: 600; }

.opts { display: flex; flex-direction: column; gap: 6px; }
.opt { justify-content: flex-start; text-align: left; width: 100%; padding: 10px 14px; }
.opt .mark { width: 22px; height: 22px; flex: 0 0 22px; border: 2px solid var(--muted); border-radius: 50%; display: inline-grid; place-items: center; font-size: .8rem; }
.opt.multi .mark { border-radius: 5px; }
.opt[aria-checked="true"] .mark { border-color: currentColor; }
.opt[aria-checked="true"] .mark::after { content: "✓"; }
.opt small { display: block; opacity: .8; font-weight: 400; }

textarea, input[type="text"], input[type="password"], input[type="number"], input:not([type]) {
  width: 100%; font: inherit; font-size: 1.05rem; line-height: 1.6; padding: 10px 12px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--bg); color: var(--ink); min-height: 48px;
}
textarea { resize: vertical; display: block; }
textarea.deva, .edit textarea { font-family: var(--read-font); font-size: calc(var(--read-size) * 1.05); }
.counter { font-size: .8rem; color: var(--muted); text-align: right; margin-top: 2px; }
.palette { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 8px; }
.palette button { min-width: 44px; padding: 4px 8px; font-family: var(--read-font); font-size: 1.15rem; }

/* rank */
.rank-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.rank-chip { min-width: 72px; min-height: 56px; flex: 1 1 72px; font-size: 1.25rem; font-weight: 600; flex-direction: column; gap: 0; padding: 4px 8px; }
.rank-chip .r { font-size: .8rem; font-weight: 400; color: var(--muted); }
.rank-chip.ranked { background: var(--accent-soft); border-color: var(--accent); }
.rank-chip.ranked .r { color: var(--accent); font-weight: 600; font-size: .9rem; }
.rank-order { list-style: none; padding: 0; margin: 12px 0 4px; display: flex; flex-direction: column; gap: 4px; }
.rank-order li { display: flex; gap: 10px; align-items: center; padding: 6px 10px; background: var(--soft); border-radius: 8px; }
.rank-order .n { font-weight: 700; color: var(--accent); min-width: 2.2em; }
.rank-order li.empty { color: var(--muted); background: transparent; border: 1px dashed var(--line); }

/* ---------- item footer ---------- */
.submit-box { margin: 18px 0; }
.errors { margin: 10px 0; padding-left: 0; list-style: none; }
.errors li { margin: 4px 0; }
.errors button { min-height: 36px; font-size: .95rem; padding: 4px 10px; color: var(--bad); border-color: color-mix(in srgb, var(--bad) 40%, transparent); background: var(--bad-soft); text-align: left; }
.item-nav { display: flex; justify-content: space-between; gap: 10px; margin-top: 22px; padding-top: 14px; border-top: 1px solid var(--line); }
.item-nav button { flex: 1; }
.panel-nav { display: flex; justify-content: space-between; gap: 10px; margin: 16px 0 6px; }
.panel-nav button { flex: 1; }

#toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 50; max-width: calc(100vw - 32px); }
#toast > div { background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 10px; margin-top: 6px; box-shadow: 0 4px 16px rgba(0,0,0,.2); }

/* ---------- admin ---------- */
.admin-grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
table { border-collapse: collapse; width: 100%; font-size: .92rem; }
th, td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
.table-wrap { overflow-x: auto; }
.matrix td.cell { width: 22px; min-width: 22px; padding: 0; text-align: center; font-size: .75rem; }
.matrix td.cell span { display: block; width: 20px; height: 20px; border-radius: 4px; margin: 2px auto; line-height: 20px; }
.cell-none span { background: var(--soft); }
.cell-draft span { background: var(--warn-soft); color: var(--warn); }
.cell-submitted span { background: var(--ok); color: #fff; }
.cell-na span { background: transparent; }
.link-box { display: flex; gap: 6px; align-items: center; }
.link-box input { font-family: ui-monospace, monospace; font-size: .8rem; min-height: 36px; padding: 4px 8px; }
.link-box button { min-height: 36px; padding: 4px 10px; font-size: .88rem; }
.pill { padding: 2px 8px; border-radius: 999px; font-size: .8rem; background: var(--soft); }
.pill.open { background: var(--ok-soft); color: var(--ok); }
.pill.closed { background: var(--bad-soft); color: var(--bad); }
pre.err { white-space: pre-wrap; color: var(--bad); font-size: .85rem; }
