/* ===========================================================
   The Great Deluge & The Coming ARkStorm — Essay Stylesheet
   Full-bleed 3D point cloud, centered frosted-glass reading cards,
   live atmospheric telemetry HUD, interactive climate simulator,
   and switchable palettes.
   =========================================================== */

/* ---------- Palettes ---------- */
:root,
html[data-theme="tempest"] {
  --bg: #0c141f;
  --bg-deep: #070d16;
  --ink: #e2edf7;
  --ink-soft: #a8c1d6;
  --ink-strong: #ffffff;
  --muted: #648aa5;
  --faint: #344c61;
  --accent: #38bdf8;          /* atmospheric cyan */
  --accent-2: #f59e0b;        /* storm gold */
  --accent-soft: rgba(56, 189, 248, 0.16);
  --accent-hover: rgba(56, 189, 248, 0.32);
  --accent-2-soft: rgba(245, 158, 11, 0.18);
  --accent-2-hover: rgba(245, 158, 11, 0.32);
  --rule: rgba(226, 237, 247, 0.14);
  --card-bg: linear-gradient(135deg, rgba(14, 27, 43, 0.72), rgba(10, 18, 30, 0.65));
  --card-bg-solid: #0d1a29;
  --card-border: rgba(56, 189, 248, 0.22);
  --card-shadow: 0 16px 36px rgba(0, 0, 0, 0.45), 0 0 20px rgba(56, 189, 248, 0.08);
  --note-bg: rgba(11, 22, 35, 0.96);
  --note-border: rgba(56, 189, 248, 0.40);
  --note-shadow: 0 18px 48px rgba(0, 0, 0, 0.7), 0 0 28px rgba(56, 189, 248, 0.15);
  --hud-bg: rgba(11, 23, 36, 0.88);
  --hud-border: rgba(56, 189, 248, 0.28);
  --hud-ink: #e2edf7;
  --hud-accent: #38bdf8;
  --hud-warning: #f59e0b;
  --hud-danger: #ef4444;
  --selection: rgba(56, 189, 248, 0.35);
  /* point cloud */
  --pc-bg: #0c141f;
  --pc-ink: #e2edf7;
  --pc-float-a: #3a6888;
  --pc-float-b: #284c66;
  --pc-light: 0;
}

html[data-theme="field"] {
  --bg: #f4eee1;
  --bg-deep: #e7ddca;
  --ink: #2b221a;
  --ink-soft: #4e4034;
  --ink-strong: #1a140f;
  --muted: #827263;
  --faint: #b3a496;
  --accent: #1e5f8a;          /* Pacific deep blue */
  --accent-2: #b8621b;        /* historic copper/silt */
  --accent-soft: rgba(30, 95, 138, 0.14);
  --accent-hover: rgba(30, 95, 138, 0.28);
  --accent-2-soft: rgba(184, 98, 27, 0.15);
  --accent-2-hover: rgba(184, 98, 27, 0.30);
  --rule: rgba(43, 34, 26, 0.14);
  --card-bg: linear-gradient(135deg, rgba(255, 252, 246, 0.75), rgba(247, 238, 222, 0.70));
  --card-bg-solid: #faf5eb;
  --card-border: rgba(184, 98, 27, 0.22);
  --card-shadow: 0 10px 24px rgba(78, 55, 34, 0.12), 0 1px 4px rgba(78, 55, 34, 0.08);
  --note-bg: rgba(255, 253, 248, 0.97);
  --note-border: rgba(30, 95, 138, 0.35);
  --note-shadow: 0 16px 44px rgba(60, 42, 22, 0.22);
  --hud-bg: rgba(253, 249, 241, 0.90);
  --hud-border: rgba(184, 98, 27, 0.25);
  --hud-ink: #2b221a;
  --hud-accent: #1e5f8a;
  --hud-warning: #b8621b;
  --hud-danger: #a82020;
  --selection: rgba(30, 95, 138, 0.22);
  /* point cloud */
  --pc-bg: #f4eee1;
  --pc-ink: #2b221a;
  --pc-float-a: #827263;
  --pc-float-b: #b8621b;
  --pc-light: 1;
}

html[data-theme="pacific"] {
  --bg: #071724;
  --bg-deep: #040d16;
  --ink: #e0f2f1;
  --ink-soft: #80cbc4;
  --ink-strong: #ffffff;
  --muted: #4db6ac;
  --faint: #004d40;
  --accent: #26a69a;
  --accent-2: #80deea;
  --accent-soft: rgba(38, 166, 154, 0.18);
  --accent-hover: rgba(38, 166, 154, 0.35);
  --accent-2-soft: rgba(128, 222, 234, 0.18);
  --accent-2-hover: rgba(128, 222, 234, 0.32);
  --rule: rgba(224, 242, 241, 0.16);
  --card-bg: linear-gradient(135deg, rgba(8, 30, 47, 0.72), rgba(5, 20, 32, 0.65));
  --card-bg-solid: #092235;
  --card-border: rgba(77, 182, 172, 0.28);
  --card-shadow: 0 16px 38px rgba(0, 0, 0, 0.5), 0 0 22px rgba(38, 166, 154, 0.12);
  --note-bg: rgba(6, 24, 38, 0.96);
  --note-border: rgba(38, 166, 154, 0.45);
  --note-shadow: 0 18px 48px rgba(0, 0, 0, 0.75);
  --hud-bg: rgba(6, 25, 40, 0.90);
  --hud-border: rgba(38, 166, 154, 0.32);
  --hud-ink: #e0f2f1;
  --hud-accent: #80deea;
  --hud-warning: #ffd54f;
  --hud-danger: #ef5350;
  --selection: rgba(38, 166, 154, 0.35);
  /* point cloud */
  --pc-bg: #071724;
  --pc-ink: #e0f2f1;
  --pc-float-a: #26a69a;
  --pc-float-b: #80deea;
  --pc-light: 0;
}

html[data-theme="observatory"] {
  --bg: #08080a;
  --bg-deep: #000000;
  --ink: #e6e8eb;
  --ink-soft: #a1a7b0;
  --ink-strong: #ffffff;
  --muted: #5e6673;
  --faint: #2d3138;
  --accent: #f59e0b;          /* radar telemetry amber */
  --accent-2: #10b981;        /* radar green */
  --accent-soft: rgba(245, 158, 11, 0.16);
  --accent-hover: rgba(245, 158, 11, 0.32);
  --accent-2-soft: rgba(16, 185, 129, 0.16);
  --accent-2-hover: rgba(16, 185, 129, 0.30);
  --rule: rgba(230, 232, 235, 0.15);
  --card-bg: linear-gradient(135deg, rgba(16, 17, 21, 0.76), rgba(10, 10, 14, 0.70));
  --card-bg-solid: #121317;
  --card-border: rgba(245, 158, 11, 0.25);
  --card-shadow: 0 16px 40px rgba(0, 0, 0, 0.65), 0 0 24px rgba(245, 158, 11, 0.08);
  --note-bg: rgba(14, 15, 19, 0.97);
  --note-border: rgba(245, 158, 11, 0.45);
  --note-shadow: 0 20px 50px rgba(0, 0, 0, 0.85);
  --hud-bg: rgba(14, 15, 18, 0.92);
  --hud-border: rgba(245, 158, 11, 0.30);
  --hud-ink: #f59e0b;
  --hud-accent: #f59e0b;
  --hud-warning: #f97316;
  --hud-danger: #ef4444;
  --selection: rgba(245, 158, 11, 0.32);
  /* point cloud */
  --pc-bg: #08080a;
  --pc-ink: #f59e0b;
  --pc-float-a: #fbbf24;
  --pc-float-b: #10b981;
  --pc-light: 0;
}

/* ---------- Typography & Base ---------- */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 18px;
  background-color: var(--bg);
  color: var(--ink);
  scroll-behavior: smooth;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

body {
  font-family: 'Lora', 'Georgia', serif;
  line-height: 1.72;
  background-color: var(--bg);
  color: var(--ink);
  overflow-x: hidden;
  position: relative;
  transition: background-color 0.5s ease, color 0.5s ease;
}

::selection {
  background: var(--selection);
}

/* Typography styles based on data-type */
html[data-type="fraunces"] body {
  font-family: 'Lora', 'Georgia', serif;
}
html[data-type="fraunces"] h1,
html[data-type="fraunces"] h2,
html[data-type="fraunces"] h3,
html[data-type="fraunces"] .main-title,
html[data-type="fraunces"] .section-title {
  font-family: 'Fraunces', serif;
}

html[data-type="zilla"] body {
  font-family: 'Jost', sans-serif;
}
html[data-type="zilla"] h1,
html[data-type="zilla"] h2,
html[data-type="zilla"] h3,
html[data-type="zilla"] .main-title,
html[data-type="zilla"] .section-title {
  font-family: 'Zilla Slab', serif;
}

/* ---------- Full-bleed Canvas ---------- */
#point-cloud-canvas {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  z-index: 1;
  pointer-events: none;
  display: block;
}

/* ---------- Minimalist Floating Theme Switcher ---------- */
.theme-switch-btn {
  position: fixed;
  top: 1.2rem;
  left: 2rem;
  z-index: 50;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: var(--surface);
  border: 1px solid var(--rule);
  color: var(--muted);
  padding: 0.32rem 0.8rem;
  border-radius: 20px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.72rem;
  font-weight: 500;
  cursor: pointer;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
  transition: all 0.2s ease;
}

.theme-switch-btn:hover {
  color: var(--ink-strong);
  border-color: var(--accent);
  background: var(--accent-soft);
  transform: translateY(-1px);
}

/* ---------- Text Column & Sections: Docked to Left Rail ---------- */
.text-column {
  position: relative;
  z-index: 10;
  width: 100%;
  max-width: 1600px;
  margin: 0;
  padding: 0 clamp(1.5rem, 5vw, 6rem);
  pointer-events: none;
}

.essay-section {
  position: relative;
  width: 100%;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: flex-start; /* Aligns cards to the left side */
  pointer-events: none;
}

/* Card Styling: Narrower, elegant card docked to the left */
.card {
  position: sticky;
  top: 14vh;
  width: 100%;
  max-width: 440px; /* Narrower to prevent obscuring the 3D illustrations */
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 18px;
  padding: 1.8rem 2.0rem;
  box-shadow: var(--card-shadow);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  pointer-events: auto;
  transition: transform 0.3s ease, border-color 0.3s ease, box-shadow 0.3s ease;
}

.card-sim {
  max-width: 480px; /* Slightly wider for the two sliders & 6 stat cards */
}

.card:hover {
  border-color: var(--accent);
}

/* ---------- Section 6 Historic Photo Layout & Scroll ---------- */
.essay-section.has-historic-photo {
  flex-direction: row;
  justify-content: flex-start;
  align-items: center;
  gap: clamp(2rem, 5vw, 5rem);
}

.historic-photo-panel {
  position: relative;
  z-index: 10;
  flex: 1;
  max-width: 760px;
  pointer-events: auto;
}

.historic-photo-card {
  margin: 0;
  padding: 1.2rem 1.3rem;
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 18px;
  box-shadow: var(--card-shadow);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  transition: transform 0.3s ease, border-color 0.3s ease, box-shadow 0.3s ease;
}

.historic-photo-card:hover {
  border-color: var(--accent);
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.35);
}

.historic-photo-img-wrap {
  width: 100%;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.30);
  background: #000;
}

.historic-photo-img {
  width: 100%;
  height: auto;
  max-height: 52vh;
  object-fit: contain;
  display: block;
  transition: transform 0.4s ease;
}

.historic-photo-card:hover .historic-photo-img {
  transform: scale(1.015);
}

.historic-photo-caption {
  margin-top: 0.9rem;
  padding: 0 0.2rem;
}

.historic-photo-caption .photo-title {
  display: block;
  font-family: 'Fraunces', 'Playfair Display', Georgia, serif;
  font-size: 1.08rem;
  font-weight: 600;
  color: var(--ink-strong);
  letter-spacing: 0.01em;
}

.historic-photo-caption .photo-meta {
  display: block;
  font-family: 'Inter', sans-serif;
  font-size: 0.78rem;
  line-height: 1.45;
  color: var(--muted);
  margin-top: 0.3rem;
}

@media (max-width: 1100px) {
  .essay-section.has-historic-photo {
    flex-direction: column;
    align-items: flex-start;
    gap: 2rem;
    padding-top: 6vh;
    padding-bottom: 6vh;
  }
  .historic-photo-panel {
    width: 100%;
    max-width: 480px;
  }
}

/* ---------- Typography in Cards ---------- */
.main-title {
  font-size: 2.35rem;
  line-height: 1.15;
  font-weight: 500;
  letter-spacing: -0.02em;
  color: var(--ink-strong);
  margin-bottom: 0.6rem;
  text-wrap: balance;
}

.subtitle {
  font-size: 1.05rem;
  font-weight: 400;
  color: var(--accent);
  margin-bottom: 0.9rem;
  letter-spacing: 0.01em;
  text-wrap: balance;
}

.title-byline {
  font-family: 'Inter', sans-serif;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  margin-top: 1.1rem;
  padding-top: 0.8rem;
  border-top: 1px solid var(--rule);
}

.section-title {
  font-size: 1.75rem;
  line-height: 1.25;
  font-weight: 500;
  letter-spacing: -0.015em;
  color: var(--ink-strong);
  margin-bottom: 0.45rem;
}

.section-sub {
  font-family: 'Inter', sans-serif;
  font-size: 0.82rem;
  font-weight: 500;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--accent-2);
  margin-bottom: 1.0rem;
}

.time-mark {
  font-family: 'JetBrains Mono', 'Menlo', monospace;
  font-size: 0.80rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 0.45rem;
}

.card p {
  margin-bottom: 0.95rem;
  color: var(--ink);
  font-size: 0.98rem;
  line-height: 1.55;
}

.card p:last-child {
  margin-bottom: 0;
}

.card strong {
  font-weight: 600;
  color: var(--ink-strong);
}

.card em {
  font-style: italic;
}

.deluge-callout {
  font-size: 1.4rem;
  font-weight: 400;
  font-style: italic;
  text-align: center;
  margin: 1.4rem 0 0.8rem;
  color: var(--ink-strong);
  line-height: 1.35;
  padding: 0.8rem 1rem;
  border-left: 3px solid var(--accent);
  border-right: 3px solid var(--accent);
  background: var(--accent-soft);
  border-radius: 8px;
}

/* ---------- Hot Interactive Hover Spans ---------- */
.hot {
  color: var(--ink-strong);
  border-bottom: 1.5px dotted var(--accent);
  cursor: pointer;
  padding-bottom: 1px;
  transition: color 0.15s, background-color 0.15s, border-color 0.15s;
  border-radius: 2px;
}

.hot:hover {
  color: var(--accent);
  background-color: var(--accent-soft);
  border-bottom: 1.5px solid var(--accent);
}

/* ---------- Note Card Tooltip ---------- */
.note-card {
  position: fixed;
  z-index: 1000;
  max-width: 360px;
  background: var(--note-bg);
  border: 1px solid var(--note-border);
  border-radius: 14px;
  padding: 1.1rem 1.3rem;
  box-shadow: var(--note-shadow);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  pointer-events: none;
  opacity: 0;
  transform: scale(0.96) translateY(6px);
  transition: opacity 0.22s cubic-bezier(0.16, 1, 0.3, 1), transform 0.22s cubic-bezier(0.16, 1, 0.3, 1);
  font-family: 'Lora', 'Georgia', serif;
  font-size: 0.88rem;
  line-height: 1.55;
  color: var(--ink);
}

.note-card.is-visible {
  opacity: 1;
  transform: scale(1) translateY(0);
}

.note-card strong {
  color: var(--ink-strong);
  display: block;
  font-size: 0.95rem;
  margin-bottom: 0.35rem;
  font-family: 'Fraunces', serif;
}

.note-card .src {
  font-family: 'Inter', sans-serif;
  font-size: 0.72rem;
  color: var(--muted);
  margin-top: 0.6rem;
  padding-top: 0.45rem;
  border-top: 1px solid var(--rule);
  letter-spacing: 0.02em;
}

/* ---------- Interactive Climate Simulator Widget ---------- */
.climate-simulator-box {
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid var(--rule);
  border-radius: 12px;
  padding: 1.25rem 1.4rem;
  margin: 1.2rem 0;
  font-family: 'Inter', sans-serif;
}

.sim-slider-container {
  margin-bottom: 1.3rem;
}

.sim-slider-label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.80rem;
  font-weight: 600;
  color: var(--ink-strong);
  margin-bottom: 0.4rem;
}

.sim-temp-display {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.92rem;
  color: var(--accent-2);
  font-weight: 700;
}

.sim-temp-display.hot {
  color: #fb923c;
}

.sim-marker-pill {
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  color: #ea580c;
  background: rgba(249, 115, 22, 0.15);
  border: 1px solid rgba(249, 115, 22, 0.35);
  border-radius: 4px;
  padding: 2px 6px;
  display: inline-block;
  margin-bottom: 0.4rem;
}

.sim-slider-ticks {
  display: flex;
  justify-content: space-between;
  font-size: 0.66rem;
  color: var(--muted);
  margin-top: 0.35rem;
}

.tick-highlight {
  color: #fb923c;
  font-weight: 700;
}

.sim-slider {
  width: 100%;
  height: 6px;
  border-radius: 3px;
  background: var(--faint);
  outline: none;
  -webkit-appearance: none;
  cursor: pointer;
}

.sim-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--accent-2);
  box-shadow: 0 0 10px var(--accent-2);
  cursor: pointer;
  transition: transform 0.1s;
}

.sim-slider-elnino::-webkit-slider-thumb {
  background: #f97316;
  box-shadow: 0 0 12px #f97316;
}

.sim-slider::-webkit-slider-thumb:hover {
  transform: scale(1.2);
}

.sim-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.8rem;
}

.sim-stat-card {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--rule);
  border-radius: 8px;
  padding: 0.65rem 0.8rem;
}

.sim-stat-card.sim-stat-alert {
  background: rgba(239, 68, 68, 0.10);
  border-color: rgba(239, 68, 68, 0.35);
}

.sim-stat-value.alert {
  color: #f87171;
}

.sim-stat-name {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  margin-bottom: 0.25rem;
}

.sim-stat-value {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--ink-strong);
}

.sim-stat-note {
  font-size: 0.65rem;
  color: var(--accent);
  margin-top: 0.2rem;
}

/* ---------- Mathematical Typography ---------- */
.math-eq {
  font-family: 'Lora', 'Georgia', serif;
  font-style: normal;
  font-size: 0.96em;
  background: var(--accent-soft);
  border: 1px solid rgba(56, 189, 248, 0.28);
  padding: 1px 6px;
  border-radius: 4px;
  display: inline-block;
  white-space: nowrap;
  color: var(--ink-strong);
}

.math-eq em {
  font-style: italic;
  font-family: 'Lora', 'Georgia', serif;
}

.math-eq sub {
  font-size: 0.75em;
  vertical-align: -0.2em;
}

/* ---------- Preparedness Checklist ---------- */
.prep-checklist {
  list-style-type: none;
  margin: 1rem 0 1.2rem 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.prep-checklist li {
  position: relative;
  padding-left: 1.5rem;
  font-size: 0.92rem;
  line-height: 1.55;
  color: var(--ink);
}

.prep-checklist li::before {
  content: '▸';
  position: absolute;
  left: 0;
  top: 0;
  color: var(--accent);
  font-size: 1.05rem;
  font-weight: 700;
}

.prep-checklist li strong {
  color: var(--ink-strong);
}

/* ---------- Blockquotes & Interactive Quotations ---------- */
.quote-callout {
  margin: 1.3rem 0;
  padding: 1.1rem 1.4rem;
  background: rgba(255, 255, 255, 0.035);
  border-left: 3px solid var(--accent);
  border-radius: 0 8px 8px 0;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
  position: relative;
  transition: background 0.22s ease, border-left-color 0.22s ease;
}

.quote-callout p {
  font-family: 'Fraunces', 'Playfair Display', Georgia, serif;
  font-style: italic;
  font-size: 1.05rem;
  line-height: 1.55;
  color: var(--ink-strong);
  margin: 0;
}

/* Citation Meta in Popups */
.note-card .cite-meta-row {
  margin: 0.4rem 0;
  line-height: 1.45;
  font-size: 0.84rem;
  color: var(--ink);
}

.note-card .cite-meta-label {
  display: inline-block;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.70rem;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--accent);
  margin-right: 0.4rem;
}

/* ---------- Responsive Design ---------- */
@media (max-width: 900px) {
  .theme-switch-btn {
    top: 0.8rem;
    left: 1rem;
    padding: 0.25rem 0.6rem;
    font-size: 0.68rem;
  }
  .text-column {
    padding: 0 1rem;
  }
  .card {
    padding: 1.6rem 1.6rem;
  }
  .main-title {
    font-size: 2.2rem;
  }
  .section-title {
    font-size: 1.7rem;
  }
}
