:root {
  --ink: #1d1814;
  --muted: #6a5d52;
  --line: rgba(29, 24, 20, 0.12);
  --accent: #7a3f24;
  --accent-deep: #5d2e18;
  --danger: #7a2e2e;
  --good: #2f5d46;
  --serif: "Literata", "Iowan Old Style", Palatino, "Palatino Linotype", serif;
  --sans: "Source Sans 3", "Segoe UI", sans-serif;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  color: var(--ink);
  font-family: var(--sans);
  background: #2a1c12;
}

.bg {
  position: fixed;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  pointer-events: none;
}

.bg-photo {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center 45%;
  transform: scale(1.02);
  filter: saturate(1.05) contrast(1.02);
}

.bg-scrim {
  position: absolute;
  inset: 0;
  background:
    linear-gradient(180deg, rgba(28, 18, 10, 0.38) 0%, rgba(28, 18, 10, 0.18) 28%, rgba(28, 18, 10, 0.34) 100%),
    radial-gradient(1200px 700px at 70% 20%, rgba(255, 196, 110, 0.12), transparent 60%);
}

.shell {
  position: relative;
  z-index: 1;
  width: min(1180px, 100%);
  margin: 0 auto;
  padding: 1rem 0.9rem calc(1.4rem + var(--safe-bottom));
}

.top {
  display: flex;
  justify-content: space-between;
  gap: 0.85rem;
  align-items: start;
  margin-bottom: 0.9rem;
  padding: 0.85rem 1rem;
  border-radius: 18px;
  background: rgba(255, 248, 238, 0.78);
  border: 1px solid rgba(255, 255, 255, 0.35);
  box-shadow: 0 18px 40px rgba(20, 12, 6, 0.18);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

button, .btn {
  font: inherit;
  border-radius: 999px;
  padding: 0.7rem 1.05rem;
  background: rgba(255, 250, 242, 0.85);
  color: var(--ink);
  border: 1px solid var(--line);
  cursor: pointer;
}

.btn.primary {
  background: var(--accent);
  color: #fff8f1;
  border-color: transparent;
}

.btn.danger {
  background: transparent;
  color: var(--danger);
  border-color: rgba(122, 46, 46, 0.35);
}

.site-brand {
  margin: 0 0 0.35rem;
  font-family: var(--serif);
  font-size: clamp(2rem, 6vw, 3rem);
  line-height: 1.05;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--accent-deep);
}

.top h1 {
  margin: 0;
  font-family: var(--serif);
  font-size: clamp(1.15rem, 3.2vw, 1.55rem);
  line-height: 1.15;
  font-weight: 600;
  color: var(--ink);
}

.eyebrow {
  margin: 0 0 0.3rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.7rem;
  color: var(--muted);
  font-weight: 600;
}

.byline { margin: 0.4rem 0 0; color: var(--muted); }

.top-actions {
  display: flex;
  gap: 0.45rem;
  align-items: center;
  flex-wrap: wrap;
}

.status-pill {
  padding: 0.5rem 0.8rem;
  border-radius: 999px;
  background: rgba(255, 250, 242, 0.9);
  border: 1px solid var(--line);
  font-size: 0.82rem;
  color: var(--muted);
}

.gate, .admin, .reader, .advisory {
  background: rgba(255, 248, 238, 0.82);
  border: 1px solid rgba(255, 255, 255, 0.38);
  border-radius: 20px;
  box-shadow: 0 18px 44px rgba(20, 12, 6, 0.2);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.gate, .admin, .advisory {
  padding: 1.25rem 1.15rem 1.4rem;
  margin-bottom: 0.9rem;
  max-width: 560px;
}

.gate h2, .admin h2, .advisory h2 {
  margin: 0 0 0.4rem;
  font-family: var(--serif);
  font-size: 1.45rem;
}

.advisory { max-width: 640px; }

.advisory-list {
  margin: 0 0 1.1rem;
  padding-left: 1.15rem;
  color: var(--muted);
  line-height: 1.55;
}

.admin-subhead {
  margin: 1.4rem 0 0.35rem;
  font-family: var(--serif);
  font-size: 1.25rem;
}

.submission-list {
  display: grid;
  gap: 0.55rem;
  margin-top: 0.75rem;
}

.submission-detail {
  margin-top: 1rem;
  padding: 1rem;
  border-radius: 14px;
  background: rgba(255, 250, 242, 0.9);
  border: 1px solid var(--line);
}

.submission-detail h3,
.submission-detail h4 {
  font-family: var(--serif);
  margin: 0.8rem 0 0.35rem;
}

.submission-detail h3 { margin-top: 0; }

.submission-detail ul {
  margin: 0.25rem 0 0.6rem;
  padding-left: 1.1rem;
  color: var(--muted);
}

.lede {
  margin: 0 0 1rem;
  color: var(--muted);
  line-height: 1.5;
}

label {
  display: grid;
  gap: 0.35rem;
  margin-bottom: 0.75rem;
  color: var(--muted);
  font-size: 0.92rem;
}

input {
  width: 100%;
  font: inherit;
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.75rem 0.85rem;
  background: rgba(255, 252, 247, 0.95);
}

.or {
  margin: 0.2rem 0 0.7rem;
  color: var(--muted);
  text-align: center;
  font-size: 0.85rem;
}

.gate-actions, .admin-form {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
  align-items: end;
}

.hint {
  margin: 0.7rem 0 0;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.4;
}

.hint.error { color: var(--danger); }
.hint.ok { color: var(--good); }

.invite-list {
  display: grid;
  gap: 0.55rem;
  margin-top: 0.9rem;
}

.invite-card {
  display: grid;
  gap: 0.25rem;
  padding: 0.8rem 0.9rem;
  border-radius: 14px;
  background: rgba(255, 250, 242, 0.88);
  border: 1px solid var(--line);
}

.invite-card strong { font-size: 0.98rem; }
.invite-card .mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.86rem;
}
.invite-card .meta { color: var(--muted); font-size: 0.8rem; }
.invite-card.revoked { opacity: 0.55; }

.reader {
  display: grid;
  grid-template-columns: 220px 1fr;
  min-height: 70vh;
  overflow: hidden;
}

.toc {
  padding: 1rem 0.75rem 1.2rem;
  border-right: 1px solid var(--line);
  background: rgba(239, 228, 212, 0.55);
  overflow: auto;
  max-height: 78vh;
}

.toc h2 {
  margin: 0 0 0.7rem;
  font-family: var(--serif);
  font-size: 1.05rem;
  padding: 0 0.3rem;
}

.toc-item {
  width: 100%;
  text-align: left;
  border-radius: 12px;
  background: transparent;
  margin-bottom: 0.28rem;
  padding: 0.6rem 0.65rem;
}

.toc-item.active,
.toc-item:hover { background: rgba(255, 250, 242, 0.92); }

.toc-item .meta {
  display: block;
  margin-top: 0.15rem;
  color: var(--muted);
  font-size: 0.75rem;
}

.page {
  display: grid;
  grid-template-rows: auto auto 1fr;
  min-width: 0;
}

.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.55rem;
  padding: 0.8rem 0.85rem 0.35rem;
}

.progress {
  color: var(--muted);
  font-size: 0.88rem;
  text-align: center;
}

.spread {
  overflow: auto;
  padding: 0.4rem 1.1rem 1rem;
  -webkit-overflow-scrolling: touch;
}

.chapter-title {
  margin: 0.35rem 0 1rem;
  font-family: var(--serif);
  font-size: 1.45rem;
}

.para-wrap {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.35rem;
  align-items: start;
  margin: 0 0 0.85rem;
}

.para {
  margin: 0;
  font-family: var(--serif);
  font-size: 1.08rem;
  line-height: 1.7;
  cursor: pointer;
  border-radius: 8px;
  padding: 0.15rem 0.3rem;
}

.para:hover { background: rgba(122, 63, 36, 0.08); }
.para.active {
  background: rgba(122, 63, 36, 0.14);
  box-shadow: inset 3px 0 0 var(--accent);
}
.para.marked {
  background: rgba(122, 63, 36, 0.07);
}
.para.ready::after {
  content: " ●";
  color: var(--good);
  font-size: 0.7rem;
}

.para-tools {
  padding-top: 0.2rem;
}

.mark-btn {
  border-radius: 999px;
  padding: 0.35rem 0.65rem;
  font-size: 0.78rem;
  background: rgba(255, 250, 242, 0.95);
  border: 1px solid var(--line);
  color: var(--accent-deep);
  white-space: nowrap;
}

.mark-btn:hover {
  border-color: rgba(122, 63, 36, 0.35);
}

.listen-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.45rem;
  padding: 0.55rem 0.85rem 0.75rem;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 248, 238, 0.72);
}

#player { display: none; }

.submit-panel {
  padding: 1rem 1.1rem calc(1.2rem + var(--safe-bottom));
  border-top: 1px solid var(--line);
  background: rgba(239, 228, 212, 0.55);
}

.submit-panel h2 {
  margin: 0 0 0.35rem;
  font-family: var(--serif);
  font-size: 1.25rem;
}

.checkpoint-panel {
  margin: 1.5rem 0 1rem;
  padding: 1.1rem 1rem 1.2rem;
  border-radius: 16px;
  border: 1px solid rgba(122, 63, 36, 0.22);
  background: rgba(255, 248, 238, 0.88);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.checkpoint-panel h2 {
  margin: 0 0 0.35rem;
  font-family: var(--serif);
  font-size: 1.3rem;
}

.checkpoint-panel.final-panel {
  margin-top: 0.75rem;
  border-color: rgba(47, 93, 70, 0.28);
  background: rgba(245, 250, 246, 0.95);
}

.chapter-marks {
  display: grid;
  gap: 0.35rem;
  margin: 0.55rem 0 0.85rem;
}

.chapter-mark-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 0.55rem;
  align-items: baseline;
  font-size: 0.88rem;
  padding: 0.4rem 0.55rem;
  border-radius: 10px;
  background: rgba(255, 252, 247, 0.9);
  border: 1px solid var(--line);
}

.checkpoint-questions {
  display: grid;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.q-field {
  display: grid;
  gap: 0.4rem;
  margin-bottom: 0.65rem;
}

.q-prompt {
  color: var(--ink);
  font-size: 0.95rem;
  font-weight: 600;
}

.choice-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.choice-btn {
  border-radius: 999px;
  padding: 0.4rem 0.75rem;
  font-size: 0.84rem;
  background: rgba(255, 250, 242, 0.95);
}

.choice-btn.selected {
  background: var(--accent);
  color: #fff8f1;
  border-color: transparent;
}

.final-form {
  margin: 0.5rem 0 0.85rem;
}

.submit-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.65rem;
}

textarea {
  width: 100%;
  font: inherit;
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.75rem 0.85rem;
  background: rgba(255, 252, 247, 0.95);
  resize: vertical;
}

.questions {
  margin: 0.4rem 0 0.85rem;
  color: var(--muted);
}

.questions summary {
  cursor: pointer;
  margin-bottom: 0.65rem;
  font-weight: 600;
}

.breakdown-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin: 0.55rem 0 0.85rem;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
  padding: 0.28rem 0.55rem;
  border-radius: 999px;
  background: rgba(255, 250, 242, 0.95);
  border: 1px solid var(--line);
  font-size: 0.8rem;
  color: var(--ink);
}

.chip.muted { color: var(--muted); }

.mark-modal {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 1rem;
  background: rgba(29, 24, 20, 0.45);
}

.mark-modal[hidden] { display: none; }

.mark-card {
  width: min(440px, 100%);
  max-height: min(90vh, 720px);
  overflow: auto;
  padding: 1.1rem 1.05rem 1.2rem;
  border-radius: 18px;
  background: rgba(247, 241, 232, 0.94);
  border: 1px solid var(--line);
  box-shadow: 0 24px 50px rgba(20, 12, 6, 0.28);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.mark-card h3 {
  margin: 0 0 0.45rem;
  font-family: var(--serif);
  font-size: 1.25rem;
}

.mark-card .excerpt {
  margin: 0 0 0.85rem;
  color: var(--muted);
  font-family: var(--serif);
  font-size: 0.95rem;
  line-height: 1.45;
}

.reaction-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.4rem;
  margin-bottom: 0.75rem;
}

.reaction-btn {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  text-align: left;
  border-radius: 12px;
  padding: 0.55rem 0.65rem;
  font-size: 0.86rem;
  background: rgba(255, 250, 242, 0.95);
}

.reaction-btn .emoji { font-size: 1.1rem; }
.reaction-btn.selected {
  border-color: var(--accent);
  box-shadow: inset 0 0 0 1px var(--accent);
  background: rgba(122, 63, 36, 0.1);
}

.drawer-backdrop {
  position: fixed;
  inset: 0;
  z-index: 30;
  background: rgba(29, 24, 20, 0.35);
}

.drawer-backdrop[hidden] { display: none; }

.notes-drawer {
  position: fixed;
  top: 0;
  right: 0;
  z-index: 35;
  width: min(380px, 100%);
  height: 100%;
  padding: 1rem 0.9rem calc(1rem + var(--safe-bottom));
  background: rgba(244, 235, 224, 0.92);
  border-left: 1px solid var(--line);
  box-shadow: -16px 0 40px rgba(20, 12, 6, 0.18);
  overflow: auto;
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}

.notes-drawer[hidden] { display: none; }

.notes-drawer-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.notes-drawer-head h2 {
  margin: 0;
  font-family: var(--serif);
  font-size: 1.25rem;
}

.notes-list {
  display: grid;
  gap: 0.55rem;
}

.note-card {
  padding: 0.75rem 0.8rem;
  border-radius: 14px;
  background: rgba(255, 250, 242, 0.95);
  border: 1px solid var(--line);
}

.note-card-top {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.35rem 0.5rem;
}

.note-emoji { font-size: 1.05rem; }
.note-excerpt, .note-body {
  margin: 0.4rem 0 0;
  font-size: 0.88rem;
  line-height: 1.45;
  color: var(--muted);
}
.note-body { color: var(--ink); }
.note-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-top: 0.55rem;
}

.meta { color: var(--muted); font-size: 0.8rem; }

@media (max-width: 860px) {
  .reader { grid-template-columns: 1fr; }
  .toc {
    max-height: 150px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
  .top { flex-direction: column; }
  .gate, .admin, .advisory { max-width: none; }
  .submit-grid { grid-template-columns: 1fr; }
  .reaction-grid { grid-template-columns: 1fr; }
}
