/* =========================================================
   Ketovore Living — Refined HTML Presentation
   Addresses Dr. Marsh's feedback: TOC with hyperlinks,
   working navigation, separate End Show, image citations,
   progressive bullet reveal with grey-out, student-created
   overlays, advanced organizers, 6x6 rule.
   ========================================================= */

:root {
  --bg: #fdfcfa;
  --bg-alt: #f5f1ea;
  --text: #1a202c;
  --text-dim: #475569;
  --text-muted: #64748b;
  --accent: #8b3a1f;
  --accent-soft: rgba(139,58,31,0.1);
  --gold: #c9a227;
  --gold-soft: rgba(201,162,39,0.12);
  --forest: #2f4f3e;
  --border: #e5e0d5;
  --shadow-sm: 0 2px 8px rgba(0,0,0,0.04);
  --shadow-md: 0 8px 28px rgba(0,0,0,0.08);
  --toc-width: 260px;
  --topbar-h: 56px;
  --font-display: 'DM Serif Display', Georgia, serif;
  --font-body: 'IBM Plex Sans', -apple-system, sans-serif;
}

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

body {
  font-family: var(--font-body);
  font-size: 17px;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg-alt);
  min-height: 100vh;
}

/* Accessibility */
.skip-link {
  position: absolute; left: -9999px; top: 0;
  background: #000; color: #fff; padding: 8px 16px;
  text-decoration: none; z-index: 9999;
}
.skip-link:focus { left: 0; }

/* ---- Top control bar ---- */
.topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--topbar-h);
  background: #ffffff;
  border-bottom: 1px solid var(--border);
  z-index: 100;
  box-shadow: 0 1px 4px rgba(0,0,0,0.04);
}
.topbar-inner {
  height: 100%;
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 1.25rem;
  display: flex;
  align-items: center;
  gap: 1rem;
}
.back-link {
  font-size: 0.82rem;
  color: var(--text-dim);
  text-decoration: none;
  font-weight: 500;
  white-space: nowrap;
}
.back-link:hover { color: var(--accent); }
.back-link .arrow { margin-right: 0.25rem; }

.presentation-title {
  flex: 1;
  text-align: center;
  font-family: var(--font-display);
  font-size: 1.05rem;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.refined-label {
  display: inline-block;
  font-family: var(--font-body);
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  background: var(--gold-soft);
  color: #8a7832;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  vertical-align: middle;
  margin-left: 0.4rem;
}

.controls {
  display: flex;
  gap: 0.4rem;
}
.ctrl-btn {
  font-family: var(--font-body);
  font-size: 0.82rem;
  font-weight: 500;
  padding: 0.45rem 0.8rem;
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  cursor: pointer;
  transition: all 0.15s ease;
}
.ctrl-btn:hover {
  background: var(--gold-soft);
  border-color: var(--gold);
}
.ctrl-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
.ctrl-btn:disabled:hover {
  background: #ffffff;
  border-color: var(--border);
}

/* ---- TOC sidebar ---- */
.toc {
  position: fixed;
  top: var(--topbar-h);
  left: 0;
  bottom: 0;
  width: var(--toc-width);
  background: #ffffff;
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 1.25rem 0.75rem;
  transition: transform 0.3s ease;
  z-index: 50;
}
.toc-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 0.5rem 0.75rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 0.75rem;
}
.toc-title {
  font-family: var(--font-display);
  font-size: 1rem;
  color: var(--text);
}
.toc-toggle {
  display: none;
  background: none;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.2rem 0.5rem;
  cursor: pointer;
  font-size: 0.85rem;
  color: var(--text-dim);
}

.toc-list {
  list-style: none;
  counter-reset: toc-counter;
}
.toc-list li {
  counter-increment: toc-counter;
  margin-bottom: 0.2rem;
}
.toc-list a {
  display: flex;
  align-items: baseline;
  gap: 0.6rem;
  padding: 0.55rem 0.75rem;
  color: var(--text-dim);
  text-decoration: none;
  font-size: 0.88rem;
  line-height: 1.35;
  border-radius: 6px;
  transition: all 0.15s ease;
  border-left: 3px solid transparent;
}
.toc-list a::before {
  content: counter(toc-counter, decimal-leading-zero);
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--text-muted);
  flex-shrink: 0;
  letter-spacing: 0.03em;
}
.toc-list a:hover {
  background: var(--gold-soft);
  color: var(--text);
}
.toc-list a.active {
  background: var(--accent-soft);
  color: var(--accent);
  border-left-color: var(--accent);
  font-weight: 600;
}
.toc-list a.active::before {
  color: var(--accent);
}

.toc-footer {
  margin-top: 1rem;
  padding: 0 0.75rem;
}
.toc-note {
  font-size: 0.72rem;
  color: var(--text-muted);
  font-style: italic;
  line-height: 1.5;
}

/* ---- Main slide stage ---- */
.stage {
  position: fixed;
  top: var(--topbar-h);
  left: var(--toc-width);
  right: 0;
  bottom: 0;
  overflow-y: auto;
  scroll-behavior: smooth;
  scroll-snap-type: y mandatory;
  background: var(--bg-alt);
}

.slide {
  scroll-snap-align: start;
  min-height: calc(100vh - var(--topbar-h));
  padding: 2.5rem 3rem 5rem;
  display: flex;
  flex-direction: column;
  position: relative;
}

.slide-inner {
  max-width: 820px;
  width: 100%;
  margin: 0 auto;
  background: #ffffff;
  border-radius: 12px;
  padding: 3rem 3.5rem;
  box-shadow: var(--shadow-md);
  flex: 1;
  border: 1px solid var(--border);
}

.slide-head {
  margin-bottom: 2rem;
  padding-bottom: 1.25rem;
  border-bottom: 2px solid var(--gold-soft);
}
.slide-label {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 0.3rem 0.7rem;
  border-radius: 999px;
  margin-bottom: 0.85rem;
}
.slide-head h2 {
  font-family: var(--font-display);
  font-size: 2.4rem;
  font-weight: 400;
  color: var(--text);
  line-height: 1.1;
  margin-bottom: 0.5rem;
  letter-spacing: -0.01em;
}
.slide-deck {
  font-size: 1.1rem;
  color: var(--text-dim);
  line-height: 1.5;
}

/* ---- Slide footer with advanced organizer ---- */
.slide-footer {
  position: absolute;
  bottom: 1.25rem;
  left: 3rem;
  right: 3rem;
  max-width: 820px;
  margin: 0 auto;
  padding: 0.85rem 1.25rem;
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow-sm);
  text-align: center;
}
.organizer {
  font-size: 0.82rem;
  color: var(--text-muted);
}
.organizer strong {
  color: var(--accent);
  font-weight: 600;
}

/* ---- Slide 1: Title ---- */
.slide-title .title-card {
  text-align: center;
  padding: 1rem 0;
}
.hero-image {
  margin: 0 auto 1.5rem;
  max-width: 480px;
}
.hero-image img {
  width: 100%;
  height: auto;
  border-radius: 10px;
  box-shadow: var(--shadow-md);
  border: 1px solid var(--border);
}
.image-citation {
  display: block;
  margin-top: 0.5rem;
  font-size: 0.75rem;
  color: var(--text-muted);
  font-style: italic;
  text-align: left;
  padding: 0.4rem 0.6rem;
  background: var(--bg-alt);
  border-left: 3px solid var(--gold);
  border-radius: 0 4px 4px 0;
}
.title-card h1 {
  font-family: var(--font-display);
  font-size: 3.2rem;
  color: var(--accent);
  line-height: 1.05;
  margin-bottom: 0.5rem;
  font-weight: 400;
  letter-spacing: -0.02em;
}
.subtitle {
  font-family: var(--font-display);
  font-size: 1.3rem;
  color: var(--text);
  font-style: italic;
  margin-bottom: 1rem;
}
.pillars {
  font-size: 0.95rem;
  color: var(--forest);
  letter-spacing: 0.04em;
  margin-bottom: 1.5rem;
}
.pillars strong { color: var(--accent); }

.byline {
  font-size: 0.88rem;
  color: var(--text-dim);
  margin-bottom: 1.5rem;
  line-height: 1.7;
}
.byline a { color: var(--accent); font-weight: 600; }

.why-box {
  text-align: left;
  background: var(--gold-soft);
  border-left: 4px solid var(--gold);
  padding: 1rem 1.25rem;
  border-radius: 0 8px 8px 0;
  margin-top: 1rem;
}
.why-label {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: #8a7832;
  margin-bottom: 0.3rem;
}
.why-box p {
  font-size: 0.95rem;
  color: var(--text);
  line-height: 1.6;
}

/* ---- Bullets with progressive reveal ---- */
.bullets {
  list-style: none;
  margin: 1rem 0;
}
.bullets li {
  position: relative;
  padding: 0.85rem 1rem 0.85rem 2.5rem;
  margin-bottom: 0.3rem;
  font-size: 1.08rem;
  line-height: 1.5;
  color: var(--text);
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.25s ease, color 0.3s ease, opacity 0.3s ease;
}
.bullets li::before {
  content: "●";
  position: absolute;
  left: 1rem;
  top: 0.85rem;
  color: var(--gold);
  font-size: 1.2rem;
  line-height: 1;
  transition: color 0.25s ease;
}
.bullets li.active {
  background: var(--accent-soft);
  color: var(--text);
  font-weight: 500;
}
.bullets li.active::before {
  color: var(--accent);
}
.bullets li.addressed {
  color: var(--text-muted);
  opacity: 0.55;
}
.bullets li.addressed::before {
  color: var(--text-muted);
}
.bullets li strong { color: var(--accent); }
.bullets li.addressed strong { color: var(--text-muted); }

.bullets-warning li::before { content: "⚠"; font-size: 1rem; }

.reveal-hint {
  margin-top: 1rem;
  padding: 0.6rem 0.9rem;
  background: var(--bg-alt);
  border-radius: 6px;
  font-size: 0.82rem;
  color: var(--text-muted);
  text-align: center;
  font-style: italic;
}
.reveal-hint kbd {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 1px 5px;
  font-size: 0.78rem;
  font-family: monospace;
  box-shadow: 0 1px 0 rgba(0,0,0,0.08);
}

/* ---- Reasons grid (slide 3) ---- */
.reasons-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1rem;
  margin: 1rem 0;
}
.reason-card {
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-left: 4px solid var(--gold);
  border-radius: 8px;
  padding: 1.1rem 1.25rem;
}
.reason-num {
  font-family: var(--font-display);
  font-size: 1.6rem;
  color: var(--gold);
  margin-bottom: 0.3rem;
  font-weight: 700;
}
.reason-card h3 {
  font-family: var(--font-display);
  font-size: 1.15rem;
  color: var(--text);
  margin-bottom: 0.3rem;
  font-weight: 400;
}
.reason-card p {
  font-size: 0.95rem;
  color: var(--text-dim);
  line-height: 1.5;
}

/* ---- Food table (slide 4) ---- */
.food-table {
  width: 100%;
  border-collapse: collapse;
  margin: 1rem 0;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}
.food-table th {
  padding: 0.9rem 1rem;
  text-align: left;
  color: #fff;
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 400;
  letter-spacing: 0.02em;
}
.food-table th.col-eat { background: var(--forest); }
.food-table th.col-mod { background: #8a7832; }
.food-table th.col-avoid { background: var(--accent); }
.food-table td {
  padding: 0.85rem 1rem;
  vertical-align: top;
  font-size: 0.92rem;
  line-height: 1.5;
  border: 1px solid var(--border);
  background: #fff;
  width: 33.33%;
}
.food-table tr:nth-child(even) td { background: var(--bg-alt); }

/* ---- Plate figure (slide 5) ---- */
.plate-figure {
  text-align: center;
  margin: 1rem 0 1.5rem;
}
.plate-figure svg {
  width: 100%;
  max-width: 520px;
  height: auto;
}
.plate-notes {
  list-style: none;
  max-width: 520px;
  margin: 0 auto;
}
.plate-notes li {
  font-size: 0.95rem;
  color: var(--text-dim);
  padding: 0.35rem 0 0.35rem 1.5rem;
  position: relative;
}
.plate-notes li::before {
  content: "▸";
  position: absolute;
  left: 0.5rem;
  color: var(--gold);
}

/* ---- Steps (slide 6) ---- */
.steps {
  list-style: none;
  margin: 1rem 0;
}
.steps li {
  display: flex;
  gap: 1rem;
  margin-bottom: 0.9rem;
  padding: 1rem 1.1rem;
  background: var(--bg-alt);
  border-radius: 8px;
  border-left: 4px solid var(--gold);
}
.step-n {
  flex-shrink: 0;
  width: 42px;
  height: 42px;
  background: var(--gold);
  color: #fff;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-size: 1.3rem;
  font-weight: 700;
}
.steps h3 {
  font-family: var(--font-display);
  font-size: 1.15rem;
  color: var(--text);
  margin-bottom: 0.2rem;
  font-weight: 400;
}
.steps p {
  font-size: 0.95rem;
  color: var(--text-dim);
  line-height: 1.5;
}

/* ---- Resources (slide 9) ---- */
.resources {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.9rem;
  margin: 1rem 0 1.5rem;
}
.resource-card {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  padding: 1rem 1.1rem;
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 8px;
  text-decoration: none;
  color: var(--text);
  transition: all 0.15s ease;
  box-shadow: var(--shadow-sm);
}
.resource-card:hover {
  border-color: var(--accent);
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}
.resource-head {
  font-family: var(--font-display);
  font-size: 1.1rem;
  color: var(--accent);
}
.resource-card p {
  font-size: 0.88rem;
  color: var(--text-dim);
  line-height: 1.5;
  flex: 1;
}
.resource-link {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--accent);
  letter-spacing: 0.03em;
}

.citations-box {
  background: var(--bg-alt);
  border-left: 4px solid var(--forest);
  padding: 1rem 1.25rem;
  border-radius: 0 8px 8px 0;
  margin-top: 1rem;
}
.citations-box h3 {
  font-family: var(--font-display);
  font-size: 1.05rem;
  color: var(--forest);
  margin-bottom: 0.6rem;
  font-weight: 400;
}
.citations-box ul {
  list-style: none;
  padding: 0;
}
.citations-box li {
  font-size: 0.82rem;
  color: var(--text-dim);
  line-height: 1.6;
  padding: 0.2rem 0 0.2rem 1.2rem;
  position: relative;
}
.citations-box li::before {
  content: "†";
  position: absolute;
  left: 0.2rem;
  color: var(--forest);
}

/* ---- Slide 10: End Show ---- */
.slide-end {
  background: linear-gradient(135deg, #2f4f3e 0%, #1e3528 100%);
}
.slide-end::after {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at top left, rgba(201,162,39,0.15) 0%, transparent 50%);
  pointer-events: none;
}
.slide-end .slide-inner {
  background: transparent;
  border: none;
  box-shadow: none;
  display: flex;
  align-items: center;
  justify-content: center;
}
.slide-end .slide-footer { display: none; }

.end-card {
  text-align: center;
  color: #fff;
}
.end-mantra {
  margin-bottom: 2rem;
}
.end-mantra p {
  font-family: var(--font-display);
  font-size: 2rem;
  color: #fff;
  line-height: 1.25;
  margin-bottom: 0.3rem;
  font-weight: 400;
}
.end-mantra p:nth-child(2) { color: var(--gold); }
.end-mantra p:nth-child(3) { color: #f0d88a; }

.end-card h2 {
  font-family: var(--font-display);
  font-size: 2.4rem;
  color: #fff;
  margin-bottom: 1rem;
  font-weight: 400;
}
.end-sub {
  font-size: 0.92rem;
  color: rgba(255,255,255,0.75);
  line-height: 1.7;
  margin-bottom: 2rem;
}
.end-sub strong { color: var(--gold); }

.end-actions {
  display: flex;
  gap: 0.75rem;
  justify-content: center;
  flex-wrap: wrap;
}
.end-btn {
  display: inline-block;
  padding: 0.8rem 1.6rem;
  border-radius: 8px;
  text-decoration: none;
  font-weight: 600;
  font-size: 0.92rem;
  transition: all 0.2s ease;
}
.end-btn-primary {
  background: var(--gold);
  color: #1a202c;
}
.end-btn-primary:hover {
  background: #dbb42c;
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(201,162,39,0.35);
}
.end-btn-secondary {
  background: transparent;
  color: #fff;
  border: 1.5px solid rgba(255,255,255,0.35);
}
.end-btn-secondary:hover {
  background: rgba(255,255,255,0.1);
  border-color: #fff;
}

/* ---- Progress bar ---- */
.progress-bar {
  position: fixed;
  top: var(--topbar-h);
  left: var(--toc-width);
  right: 0;
  height: 3px;
  background: rgba(0,0,0,0.05);
  z-index: 99;
}
.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--gold) 0%, var(--accent) 100%);
  width: 10%;
  transition: width 0.3s ease;
}

/* ---- Responsive ---- */
@media (max-width: 900px) {
  :root { --toc-width: 0px; }
  .toc {
    transform: translateX(-100%);
    width: 260px;
  }
  .toc.open { transform: translateX(0); }
  .toc-toggle { display: inline-block; }
  .stage { left: 0; }
  .progress-bar { left: 0; }
  .slide { padding: 1.5rem 1rem 4rem; }
  .slide-inner { padding: 1.75rem 1.5rem; }
  .slide-head h2 { font-size: 1.85rem; }
  .title-card h1 { font-size: 2.2rem; }
  .slide-footer { left: 1rem; right: 1rem; }
  .reasons-grid, .resources { grid-template-columns: 1fr; }
  .food-table { font-size: 0.85rem; }
  .food-table th, .food-table td { padding: 0.6rem 0.7rem; }
  .presentation-title { font-size: 0.9rem; }
  .ctrl-btn { font-size: 0.75rem; padding: 0.4rem 0.6rem; }
  .topbar-inner { padding: 0 0.75rem; gap: 0.4rem; }
}
