/* LogLoss — poster palette */
:root {
  --ground: #EAE6DC;
  --ink: #1A1A18;
  --mute: #6E6A62;
  --rule: #D2553F;
  --tint: #E8A08F;
  --card: #F4F1EA;
  --line: #D6D1C5;
  --radius: 5px;
}

*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--ground);
  color: var(--ink);
  line-height: 1.55;
  -webkit-text-size-adjust: 100%;
}

/* ===== Top bar ===== */
.top-bar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: .75rem;
  padding: .6rem 1rem;
  background: var(--card);
  border-bottom: 1px solid var(--line);
}
.logo { font-weight: 700; font-size: 1.05rem; margin-right: auto; }
#progress { font-size: .85rem; color: var(--mute); }

/* ===== Badge ===== */
.badge {
  font-size: .75rem;
  padding: .15rem .5rem;
  border-radius: 999px;
  background: var(--rule);
  color: #fff;
}

/* ===== Buttons ===== */
button, .btn, .chip { touch-action: manipulation; }

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  padding: .5rem 1.1rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
  color: var(--ink);
  font: inherit; font-size: .9rem;
  cursor: pointer;
  transition: background .12s, border-color .12s;
}
.btn:hover { border-color: var(--mute); }
.btn:active { transition-duration: 0s; }
.btn-primary { background: var(--ink); color: var(--card); border-color: var(--ink); }
.btn-primary:hover { background: #333; }
.btn-submit {
  background: var(--rule); color: #fff; border-color: var(--rule);
  font-weight: 600; padding: .65rem 2rem;
}
.btn-submit:disabled {
  background: var(--line); border-color: var(--line);
  color: var(--mute); cursor: not-allowed;
}
.btn-icon {
  background: none; border: 1px solid var(--line); border-radius: var(--radius);
  padding: .35rem .7rem; font: inherit; font-size: .85rem;
  cursor: pointer; color: var(--mute);
}
.btn-icon:hover { border-color: var(--mute); color: var(--ink); }

/* ===== Chips (toggle buttons) ===== */
.chip {
  display: inline-flex; align-items: center; justify-content: center;
  padding: .4rem .8rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
  color: var(--ink);
  font: inherit; font-size: .85rem;
  cursor: pointer;
  transition: background .1s, border-color .1s, color .1s;
  min-width: 2.8rem;
}
.chip:hover { border-color: var(--mute); }
.chip:active { transition-duration: 0s; }
.chip.active {
  background: var(--rule); color: #fff; border-color: var(--rule);
}
.chip:disabled { opacity: .35; cursor: not-allowed; }

/* ===== FR button code tag ===== */
.fr-code {
  font-size: .72em;
  color: var(--mute);
  background: var(--ground);
  padding: .1rem .35rem;
  border-radius: 3px;
  margin-left: .35rem;
  font-weight: 400;
}
.chip.active .fr-code {
  color: rgba(255,255,255,.7);
  background: rgba(255,255,255,.15);
}

/* ===== Framing card row ===== */
.fr-card-row {
  display: flex; flex-wrap: wrap; gap: .4rem;
  align-items: flex-start;
}
.fr-card {
  display: flex; flex-wrap: wrap; align-items: center; gap: 2px;
}
.fr-def-toggle {
  display: inline-flex; align-items: center; justify-content: center;
  padding: .2rem .4rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
  font-size: .68rem; color: var(--mute);
  cursor: pointer; font-family: inherit;
  text-transform: lowercase;
  line-height: 1;
}
.fr-def-toggle:hover { border-color: var(--rule); color: var(--rule); }

/* ===== Inline framing detail ===== */
.fr-detail {
  flex-basis: 100%;
  margin-top: .35rem;
  padding: .6rem .75rem;
  background: var(--ground);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font-size: .83rem;
}
.fr-detail p { margin: 0 0 .3rem; }
.fr-detail p:last-child { margin-bottom: 0; }

/* ===== Main layout ===== */
#main {
  max-width: 48rem;
  margin: 0 auto;
  padding: 1rem;
}

/* ===== Passage card ===== */
.passage-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 1.25rem;
}
.passage-meta {
  display: flex; flex-wrap: wrap; gap: .5rem;
  margin-bottom: .75rem;
  font-size: .8rem; color: var(--mute);
}
.section-tag {
  background: var(--ground); padding: .15rem .5rem;
  border-radius: var(--radius);
}
.caption-tag {
  background: var(--tint); color: var(--ink); padding: .15rem .5rem;
  border-radius: var(--radius); font-weight: 600;
}

/* ===== Passage text ===== */
.passage-raw {
  margin: 0;
  white-space: pre-wrap;
  overflow-wrap: break-word;
  font-family: "SFMono-Regular", "Cascadia Code", "Consolas", monospace;
  font-size: .82rem;
  line-height: 1.55;
}
mark.target {
  background: var(--tint);
  color: var(--ink);
  padding: .1rem .15rem;
  border-radius: 2px;
}

/* ===== View toggle ===== */
.view-toggle {
  display: flex; gap: .35rem;
  margin-top: .75rem;
  padding-top: .6rem;
  border-top: 1px solid var(--line);
}

/* ===== Rendered passage ===== */
.passage-rendered {
  font-size: .88rem;
  line-height: 1.65;
  overflow-wrap: break-word;
}
.passage-rendered .katex-display {
  margin: .6rem 0;
  overflow-x: auto;
  overflow-y: hidden;
  overscroll-behavior-x: contain;
}
.passage-rendered .katex-error { color: var(--mute); }
.passage-rendered mark.target {
  background: var(--tint);
  color: var(--ink);
  padding: .1rem .15rem;
  border-radius: 2px;
}
.passage-rendered mark.target-display {
  display: block;
  background: none;
  border: 2px solid var(--rule);
  border-radius: var(--radius);
  padding: .4rem .6rem;
}
.passage-rendered mark.target .katex {
  color: inherit;
}

/* ===== Jump-to-target button ===== */
.jump-row {
  text-align: right;
  margin-top: .4rem;
  margin-bottom: 1rem;
}

/* ===== Form sections ===== */
.form-section {
  margin-bottom: 1rem;
}
.section-label {
  font-weight: 600;
  margin-bottom: .5rem;
}
.btn-row {
  display: flex; flex-wrap: wrap; gap: .4rem;
  align-items: center;
}

.field-group {
  border: none; padding: 0;
  margin: 0 0 1rem;
}
.field-group legend {
  font-size: .85rem;
  font-weight: 600;
  color: var(--mute);
  margin-bottom: .35rem;
  padding: 0;
}
.field-input {
  display: block;
  width: 100%;
  padding: .45rem .6rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  font: inherit; font-size: 16px;
  color: var(--ink);
  resize: vertical;
}
.field-input:focus {
  outline: none;
  border-color: var(--rule);
  box-shadow: 0 0 0 2px var(--tint);
}

.checkbox-label {
  display: flex; align-items: center; gap: .4rem;
  font-size: .9rem;
  margin-bottom: .5rem;
}
.text-label {
  display: block;
  font-size: .85rem;
  color: var(--mute);
  margin-bottom: .5rem;
}
.text-label .field-input { margin-top: .2rem; }

.submit-row {
  margin-top: 1.25rem;
}
.submit-hint {
  font-size: .8rem;
  color: var(--mute);
  margin-bottom: .35rem;
}

/* ===== Message card (fatigue / done) ===== */
.message-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 2rem;
  text-align: center;
  margin-top: 2rem;
}
.message-card h2 { margin-bottom: .75rem; }
.message-card p { color: var(--mute); margin-bottom: .75rem; }
.message-card .btn { margin-top: .75rem; }
/* ===== Resume link ===== */
.resume-box {
  margin-top: 1.25rem;
  text-align: left;
}
.resume-box p {
  font-size: .85rem;
  color: var(--mute);
  margin: 0 0 .4rem;
}
.resume-link-row {
  display: flex; gap: .4rem;
}
.resume-url {
  flex: 1;
  padding: .35rem .5rem;
}

/* ===== Site footer ===== */
.site-footer {
  text-align: center;
  font-size: .78rem;
  color: var(--mute);
  padding: 1.5rem 1rem 1rem;
}
.site-footer a { color: var(--mute); }

/* ===== Codebook panel ===== */
.overlay {
  display: none;
  position: fixed; inset: 0; z-index: 30;
  background: rgba(0,0,0,.25);
  cursor: pointer;               /* iOS Safari needs this for tap events */
}
.overlay.open { display: block; }
#cb-panel {
  display: none;
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 31;
  width: min(26rem, 100vw);
  background: var(--card);
  border-left: 1px solid var(--line);
  flex-direction: column;
  box-shadow: -4px 0 16px rgba(0,0,0,.08);
}
#cb-panel.open { display: flex; }
.panel-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: .75rem 1rem;
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}
.panel-head h2 { font-size: 1rem; margin: 0; }
#cb-body {
  overflow-y: auto; flex: 1;
  padding: 1rem;
}

/* Codebook content */
.cb-section {
  margin-bottom: 1.5rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--line);
}
.cb-section:last-child { border-bottom: none; }
.cb-section h3 {
  font-size: .95rem;
  margin-bottom: .5rem;
  color: var(--rule);
}
.cb-def, .cb-rules {
  font-size: .85rem;
  margin-bottom: .5rem;
}
.cb-example {
  font-size: .83rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: .5rem .65rem;
  margin-bottom: .4rem;
  background: #fff;
}
.cb-ex-label {
  font-weight: 600;
  font-size: .78rem;
  text-transform: uppercase;
  color: var(--mute);
}
.cb-boundary {
  font-size: .83rem;
  margin-bottom: .35rem;
}

/* ===== Visitor flow: background, consent, stop ===== */
.screen-heading {
  margin: 0 0 1.25rem;
  font-size: 1.15rem;
}
.bg-form {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.25rem;
}
.hint {
  font-size: .78rem;
  color: var(--mute);
  margin: .3rem 0 0;
}
.consent-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.25rem;
}
.consent-card h2 { margin: 0 0 .75rem; }
.consent-text {
  font-size: .88rem;
  line-height: 1.6;
  margin-bottom: 1rem;
}
.consent-id {
  font-size: .8rem;
  color: var(--mute);
  margin-bottom: 1rem;
  word-break: break-all;
}
.consent-id code {
  background: var(--ground);
  padding: .15rem .4rem;
  border-radius: 3px;
  font-size: .78rem;
}
.stop-row {
  margin-top: 1rem;
  text-align: center;
}

/* ===== Responsive ===== */
@media (max-width: 600px) {
  #main { padding: .75rem; }
  .passage-raw { font-size: .76rem; }
  .chip { padding: .35rem .6rem; font-size: .8rem; min-width: 2.4rem; }
  #cb-panel { width: 100vw; }
}
