/* ============================================================
   Two New Sciences — Galileo  |  style.css
   ============================================================ */

/* ── Reset & base ─────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --sidebar-width: 260px;
  --topbar-height: 52px;

  --color-bg:          #faf8f4;
  --color-bg-sidebar:  #1a1a2e;
  --color-bg-topbar:   #ffffff;
  --color-bg-modern:   #f0f4ff;
  --color-bg-theorem:  #fff9e6;
  --color-bg-proof:    #f7f7f7;
  --color-bg-def:      #eef7ee;
  --color-bg-corollary:#fdf0ff;

  --color-text:        #2c2c2c;
  --color-text-light:  #666;
  --color-text-sidebar:#e8e8f0;
  --color-accent:      #c0392b;
  --color-accent-blue: #2563eb;
  --color-border:      #ddd;
  --color-border-dark: #444;

  --font-body: Georgia, 'Times New Roman', serif;
  --font-ui:   system-ui, -apple-system, sans-serif;
  --font-mono: 'Fira Code', 'Courier New', monospace;

  --transition: 200ms ease;
}

html { font-size: 16px; scroll-behavior: smooth; }

body {
  display: flex;
  height: 100vh;
  overflow: hidden;
  font-family: var(--font-body);
  color: var(--color-text);
  background: var(--color-bg);
}

/* ── Accessibility ────────────────────────────────────────── */
.sr-only {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}

/* ── Sidebar ──────────────────────────────────────────────── */
#sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  background: var(--color-bg-sidebar);
  color: var(--color-text-sidebar);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: width var(--transition), transform var(--transition);
  z-index: 100;
}

body.sidebar-collapsed #sidebar {
  width: 0;
  overflow: hidden;
}

#sidebar-header {
  padding: 20px 16px 12px;
  border-bottom: 1px solid var(--color-border-dark);
}

#sidebar-header h1 {
  font-size: 1.1rem;
  font-weight: 700;
  color: #fff;
  line-height: 1.3;
}

.subtitle {
  font-size: 0.75rem;
  color: #aab;
  margin-top: 4px;
  font-family: var(--font-ui);
}

.subtitle-note {
  font-size: 0.68rem;
  color: #778;
  margin-top: 2px;
  font-family: var(--font-ui);
  font-style: italic;
}

/* Day tabs */
#day-tabs {
  display: flex;
  border-bottom: 1px solid var(--color-border-dark);
  flex-shrink: 0;
}

.day-tab {
  flex: 1;
  padding: 10px 4px;
  background: transparent;
  border: none;
  color: #99a;
  font-family: var(--font-ui);
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  transition: color var(--transition), background var(--transition);
  border-bottom: 3px solid transparent;
}

.day-tab:hover { color: #dde; background: rgba(255,255,255,.05); }
.day-tab.active { color: #fff; border-bottom-color: var(--color-accent); }

/* TOC */
#toc {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
  scrollbar-width: thin;
  scrollbar-color: #444 transparent;
}

#toc::-webkit-scrollbar { width: 4px; }
#toc::-webkit-scrollbar-track { background: transparent; }
#toc::-webkit-scrollbar-thumb { background: #444; border-radius: 2px; }

.toc-loading {
  padding: 16px;
  font-size: 0.8rem;
  color: #778;
  font-family: var(--font-ui);
}

.toc-section-link {
  display: block;
  padding: 7px 16px;
  color: #aab;
  text-decoration: none;
  font-family: var(--font-ui);
  font-size: 0.78rem;
  line-height: 1.35;
  transition: color var(--transition), background var(--transition);
  border-left: 3px solid transparent;
}

.toc-section-link:hover {
  color: #dde;
  background: rgba(255,255,255,.06);
}

.toc-section-link.active {
  color: #fff;
  border-left-color: var(--color-accent);
  background: rgba(192,57,43,.12);
}

.toc-passage-link {
  display: flex;
  align-items: baseline;
  gap: 5px;
  padding: 4px 16px 4px 28px;
  color: #889;
  text-decoration: none;
  font-family: var(--font-ui);
  font-size: 0.72rem;
  line-height: 1.3;
  border-left: 3px solid transparent;
  transition: color var(--transition), background var(--transition);
}

.toc-passage-link:hover {
  color: #ccd;
  background: rgba(255,255,255,.05);
}

.toc-passage-icon {
  flex-shrink: 0;
  font-size: 0.75rem;
  color: var(--color-accent);
  opacity: 0.8;
  font-style: normal;
}

/* ── Layout shell ─────────────────────────────────────────── */
#layout {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

/* ── Top bar ──────────────────────────────────────────────── */
#topbar {
  height: var(--topbar-height);
  background: var(--color-bg-topbar);
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  flex-shrink: 0;
  z-index: 50;
}

#sidebar-toggle {
  background: none;
  border: none;
  font-size: 1.25rem;
  cursor: pointer;
  color: var(--color-text-light);
  padding: 4px 6px;
  border-radius: 4px;
  transition: background var(--transition);
  flex-shrink: 0;
}
#sidebar-toggle:hover { background: #f0f0f0; }

/* Search */
#search-container {
  position: relative;
  flex: 1;
  max-width: 420px;
}

#search-input {
  width: 100%;
  padding: 7px 12px;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  font-family: var(--font-ui);
  font-size: 0.875rem;
  background: #fafafa;
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}

#search-input:focus {
  border-color: var(--color-accent-blue);
  box-shadow: 0 0 0 3px rgba(37,99,235,.15);
}

#search-results {
  position: absolute;
  top: calc(100% + 4px);
  left: 0; right: 0;
  background: #fff;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0,0,0,.12);
  max-height: 420px;
  overflow-y: auto;
  z-index: 200;
}

#search-results[hidden] { display: none; }

.search-result-item {
  display: block;
  padding: 10px 14px;
  cursor: pointer;
  border-bottom: 1px solid #f0f0f0;
  text-decoration: none;
  color: var(--color-text);
  transition: background var(--transition);
}

.search-result-item:last-child { border-bottom: none; }
.search-result-item:hover { background: #f5f7ff; }

.search-result-context {
  font-family: var(--font-ui);
  font-size: 0.7rem;
  color: var(--color-text-light);
  margin-bottom: 3px;
  text-transform: uppercase;
  letter-spacing: .04em;
}

.search-result-snippet {
  font-size: 0.85rem;
  line-height: 1.4;
}

.search-result-snippet mark {
  background: #fef08a;
  color: inherit;
  border-radius: 2px;
}

.search-no-results {
  padding: 14px;
  font-family: var(--font-ui);
  font-size: 0.85rem;
  color: var(--color-text-light);
  text-align: center;
}

/* Column labels */
#column-labels {
  display: flex;
  margin-left: auto;
  gap: 0;
}

#column-labels span {
  font-family: var(--font-ui);
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: .05em;
  text-transform: uppercase;
  color: var(--color-text-light);
  padding: 0 12px;
}

#column-labels .label-modern { color: #4361a0; }

/* ── Reader ───────────────────────────────────────────────── */
#reader {
  flex: 1;
  overflow-y: auto;
  padding: 32px 24px;
  scrollbar-width: thin;
  scrollbar-color: #ccc transparent;
}

#reader::-webkit-scrollbar { width: 6px; }
#reader::-webkit-scrollbar-track { background: transparent; }
#reader::-webkit-scrollbar-thumb { background: #ccc; border-radius: 3px; }

.loading-state {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 60px;
  font-family: var(--font-ui);
  color: var(--color-text-light);
}

/* ── Section headings ─────────────────────────────────────── */
.section-heading {
  margin: 40px 0 20px;
  padding-bottom: 8px;
  border-bottom: 2px solid var(--color-border);
  font-size: 1.1rem;
  font-family: var(--font-ui);
  font-weight: 700;
  color: #333;
  scroll-margin-top: calc(var(--topbar-height) + 16px);
}

.section-heading:first-child { margin-top: 0; }

/* ── Passage rows (two-column grid) ───────────────────────── */
.passage-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 24px;
  margin-bottom: 16px;
  scroll-margin-top: calc(var(--topbar-height) + 16px);
}

.passage-row.highlight-passage {
  animation: highlight-flash 1.5s ease-out;
}

@keyframes highlight-flash {
  0%   { background: #fef9c3; }
  100% { background: transparent; }
}

/* Left column: Galileo's text */
.passage-original {
  padding: 14px 16px;
  border-radius: 6px;
  line-height: 1.75;
  font-size: 0.9375rem;
}

/* Right column: modern annotation */
.passage-modern {
  padding: 14px 16px;
  border-radius: 6px;
  background: var(--color-bg-modern);
  font-size: 0.875rem;
  line-height: 1.65;
}

.passage-modern:empty,
.passage-modern.no-annotation { background: transparent; }

/* ── Passage type variants ────────────────────────────────── */

/* Dialogue */
.passage-row.type-dialogue .passage-original {
  background: transparent;
}

.speaker-name {
  display: block;
  font-family: var(--font-ui);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--color-accent);
  margin-bottom: 6px;
}

/* Theorem */
.passage-row.type-theorem .passage-original {
  background: var(--color-bg-theorem);
  border-left: 4px solid #d4a017;
  font-style: italic;
}

.type-label {
  display: inline-block;
  font-family: var(--font-ui);
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  padding: 2px 7px;
  border-radius: 3px;
  margin-bottom: 8px;
}

.type-label.theorem  { background: #fde68a; color: #78350f; }
.type-label.proof    { background: #e5e7eb; color: #374151; }
.type-label.definition { background: #bbf7d0; color: #14532d; }
.type-label.corollary  { background: #e9d5ff; color: #581c87; }
.type-label.lemma      { background: #bfdbfe; color: #1e3a5f; }

/* Proof */
.passage-row.type-proof .passage-original {
  background: var(--color-bg-proof);
  border-left: 4px solid #9ca3af;
  font-size: 0.9rem;
}

/* Definition */
.passage-row.type-definition .passage-original {
  background: var(--color-bg-def);
  border-left: 4px solid #4caf50;
}

/* Corollary */
.passage-row.type-corollary .passage-original {
  background: var(--color-bg-corollary);
  border-left: 4px solid #9c27b0;
  font-style: italic;
}

/* Lemma */
.passage-row.type-lemma .passage-original {
  background: #dbeafe;
  border-left: 4px solid #3b82f6;
  font-style: italic;
}

/* ── Collapsible proofs ───────────────────────────────────── */
.proof-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  background: none;
  border: 1px solid var(--color-border);
  border-radius: 4px;
  padding: 5px 10px;
  font-family: var(--font-ui);
  font-size: 0.78rem;
  color: var(--color-text-light);
  cursor: pointer;
  margin-bottom: 8px;
  transition: background var(--transition), border-color var(--transition);
}

.proof-toggle:hover { background: #f5f5f5; border-color: #bbb; }

.proof-toggle .toggle-icon {
  display: inline-block;
  transition: transform var(--transition);
  font-size: 0.6rem;
}

.proof-toggle[aria-expanded="true"] .toggle-icon { transform: rotate(90deg); }

.proof-body { overflow: hidden; }
.proof-body.collapsed { display: none; }

/* ── Modern annotation panel content ─────────────────────── */
.annotation-notation {
  margin-bottom: 10px;
  padding: 8px 12px;
  background: rgba(255,255,255,.7);
  border-radius: 4px;
  font-size: 1rem;
  overflow-x: auto;
}

.annotation-explanation {
  font-size: 0.85rem;
  line-height: 1.65;
  color: #334;
  font-family: var(--font-ui);
}

/* ── Figures ──────────────────────────────────────────────── */
.passage-figure {
  margin: 8px 0 4px;
  text-align: center;
}

.passage-figure img {
  max-width: 100%;
  max-height: 280px;
  border: 1px solid var(--color-border);
  border-radius: 4px;
  background: #fff;
}

.figure-caption {
  font-family: var(--font-ui);
  font-size: 0.72rem;
  color: var(--color-text-light);
  margin-top: 4px;
  font-style: italic;
}

/* ── Day header ───────────────────────────────────────────── */
.day-header {
  margin-bottom: 32px;
  padding-bottom: 16px;
  border-bottom: 3px double var(--color-border);
}

.day-header h2 {
  font-size: 1.6rem;
  margin-bottom: 6px;
}

.day-header p {
  font-size: 0.9rem;
  color: var(--color-text-light);
  font-family: var(--font-ui);
}

/* ── KaTeX overrides ──────────────────────────────────────── */
.katex-display {
  overflow-x: auto;
  overflow-y: hidden;
  margin: 6px 0;
}

/* ── Responsive ───────────────────────────────────────────── */
@media (max-width: 900px) {
  :root { --sidebar-width: 220px; }

  .passage-row {
    grid-template-columns: 1fr;
  }

  .passage-modern {
    border-left: 4px solid #4361a0;
    margin-top: 0;
    border-radius: 0 0 6px 6px;
  }

  #column-labels { display: none; }
}

@media (max-width: 640px) {
  body.sidebar-open #sidebar {
    position: fixed;
    left: 0; top: 0; bottom: 0;
    width: var(--sidebar-width);
  }

  body:not(.sidebar-open) #sidebar {
    width: 0;
    overflow: hidden;
  }
}
