/* Fonts loaded via <link> in HTML head for reliability */

:root {
  --bg: #f4f1ea;
  --bg-warm: #ede9df;
  --panel: #faf8f4;
  --panel-2: #f0ede6;
  --text: #1a1916;
  --text-2: #2e2c28;
  --muted: #7a7469;
  --muted-2: #a09990;
  --accent: #2a3d2a;
  --accent-light: #4a6741;
  --line: #ddd8ce;
  --line-light: #e8e3d8;
  --max: 1020px;
  --max-text: 680px;
}

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

html { scroll-behavior: smooth; }

/* ── Reading progress bar ── */
.progress-bar {
  position: fixed;
  top: 0;
  left: 0;
  height: 2px;
  width: 0%;
  background: var(--accent);
  z-index: 100;
  transition: width 0.08s linear;
  pointer-events: none;
}

html.dark .progress-bar { background: var(--accent); }

@media print { .progress-bar { display: none; } }

/* ── Action buttons (print / copy) ── */
.action-row {
  display: flex;
  gap: 10px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}

.action-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: none;
  border: 1px solid var(--line);
  color: var(--muted);
  cursor: pointer;
  padding: 8px 14px;
  font-size: 11px;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  font-family: 'DM Sans', sans-serif;
  font-weight: 500;
  transition: color 0.18s, border-color 0.18s, background 0.18s;
  white-space: nowrap;
}

.action-btn:hover {
  color: var(--text);
  border-color: var(--muted);
  background: rgba(255,255,255,0.4);
}

.action-btn.success {
  color: var(--accent-light);
  border-color: var(--accent-light);
}

html.dark .action-btn:hover { background: rgba(255,255,255,0.05); }
html.dark .action-btn.success { color: var(--accent); border-color: var(--accent); }

@media print { .action-row { display: none !important; } }

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'DM Sans', sans-serif;
  font-size: 17px;
  line-height: 1.75;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1, h2, h3, h4, .quote, .lead {
  font-family: 'Playfair Display', Georgia, serif;
}

a { color: inherit; text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 3px; }
img { max-width: 100%; display: block; }

/* ── Layout ── */
.container {
  width: 100%;
  max-width: calc(var(--max) + 64px);
  margin: 0 auto;
  padding: 0 32px;
}

/* ── Topbar ── */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(244, 241, 234, 0.94);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
}

.topbar .inner {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 24px;
  padding-top: 16px;
  padding-bottom: 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  min-width: max-content;
}

.brand-mark {
  width: 28px;
  height: 28px;
  flex-shrink: 0;
  color: var(--text);
  transition: opacity 0.2s;
}

.brand:hover .brand-mark { opacity: 0.75; }

.brand span {
  font-family: 'DM Sans', sans-serif;
  font-size: 10.5px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 500;
}

.nav {
  display: flex;
  gap: 20px;
  flex-wrap: wrap;
  justify-content: flex-end;
  align-items: center;
}

.nav a {
  font-size: 10.5px;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 500;
  transition: color 0.18s;
}

.nav a:hover {
  color: var(--text);
  text-decoration: none;
}

/* ── Smallcaps label ── */
.smallcaps {
  font-size: 10.5px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--muted-2);
  font-weight: 500;
  margin-bottom: 12px;
  display: block;
}

/* ── Cover ── */
.cover {
  min-height: 100vh;
  display: flex;
  align-items: center;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(160deg, var(--panel) 0%, var(--bg) 60%);
}

.cover-grid {
  width: 100%;
  display: grid;
  grid-template-columns: 1fr 0.85fr;
  gap: 80px;
  align-items: center;
  padding: 72px 0;
}

h1 {
  font-size: clamp(46px, 6.5vw, 82px);
  line-height: 1.04;
  font-weight: 500;
  letter-spacing: -0.03em;
  margin: 0 0 22px;
  color: var(--text);
}

h2 {
  font-size: clamp(32px, 4vw, 52px);
  line-height: 1.09;
  font-weight: 500;
  letter-spacing: -0.025em;
  margin: 0 0 20px;
  color: var(--text);
}

h3 {
  font-family: 'Playfair Display', serif;
  font-size: 21px;
  line-height: 1.28;
  font-weight: 500;
  margin: 0 0 10px;
  letter-spacing: -0.01em;
}

.lead {
  font-size: 21px;
  line-height: 1.55;
  max-width: 44rem;
  color: var(--text-2);
  margin: 0 0 20px;
  font-weight: 400;
  font-style: italic;
}

p {
  font-size: 17px;
  line-height: 1.78;
  color: var(--text-2);
}

li {
  font-size: 17px;
  line-height: 1.78;
  color: var(--text-2);
}

ul {
  padding-left: 1.2em;
}

.meta {
  margin-top: 32px;
  font-size: 11px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted-2);
}

/* ── Logo panel ── */
/* Light mode: dark panel, white dots (col4=brightest) */
.logo-panel {
  --hm-bg:  #0f0e0c;
  --hm-d1:  rgba(255,255,255,0.38);
  --hm-d2:  rgba(255,255,255,0.58);
  --hm-d3:  rgba(255,255,255,0.78);
  --hm-d4:  rgba(255,255,255,0.97);
  --hm-dot: #ffffff;
  min-height: 460px;
  border: 1px solid #1a1916;
  background: #0f0e0c;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 48px;
  position: relative;
  overflow: hidden;
}

.hero-mark {
  width: min(100%, 320px);
  height: auto;
  position: relative;
  display: block;
}

/* ── Sections ── */
.section {
  padding: 88px 0;
  border-bottom: 1px solid var(--line);
}

.section.noborder { border-bottom: 0; }

.section-intro {
  max-width: var(--max-text);
  color: var(--text-2);
  margin-bottom: 36px;
  font-size: 18px;
  line-height: 1.72;
}

/* ── Quote ── */
.quote {
  margin: 36px 0 0;
  padding: 28px 0 0;
  border-top: 1px solid var(--line);
  font-size: 26px;
  line-height: 1.4;
  font-style: italic;
  font-weight: 400;
  color: var(--text-2);
  max-width: 42rem;
}

/* ── Cards ── */
.card-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 20px;
  margin-top: 36px;
}

.card {
  border: 1px solid var(--line);
  background: rgba(255,255,255,0.45);
  padding: 32px;
  transition: background 0.2s;
}

.card:hover {
  background: rgba(255,255,255,0.65);
}

.card h3 { margin-top: 0; }

.card p {
  margin-top: 8px;
  color: var(--muted);
}

/* ── Rules ── */
.rule {
  border-top: 1px solid var(--line-light);
  padding-top: 22px;
  margin-top: 22px;
}

.rule:first-child { border-top: 0; padding-top: 0; margin-top: 0; }

.rule h3 {
  color: var(--text);
  margin-bottom: 6px;
}

/* ── Diagram ── */
.diagram {
  border: 1px solid var(--line);
  background: var(--panel);
  padding: 32px 28px;
  margin: 36px 0 40px;
}

.diagram svg { width: 100%; height: auto; display: block; }

/* ── Divider sections ── */
.divider {
  min-height: 66vh;
  display: flex;
  align-items: center;
  border-bottom: 1px solid var(--line);
  background: var(--bg-warm);
}

.divider h2 {
  font-size: clamp(48px, 7vw, 90px);
  line-height: 1.03;
  margin: 0;
  letter-spacing: -0.035em;
}

.divider p {
  margin: 0 0 16px;
  font-size: 10.5px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--muted-2);
  font-weight: 500;
}

/* ── Two-col ── */
.twocol {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 52px;
  align-items: start;
}

/* ── Callout ── */
.callout {
  border-left: 2px solid var(--accent);
  padding-left: 20px;
  margin: 32px 0;
}

.callout p {
  font-size: 16px;
  color: var(--muted);
}

/* ── Table ── */
.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  margin-top: 28px;
  border-radius: 0;
}

table {
  width: 100%;
  border-collapse: collapse;
  background: var(--panel);
}

th, td {
  text-align: left;
  vertical-align: top;
  padding: 18px 22px;
  border-bottom: 1px solid var(--line);
  font-size: 16px;
}

th {
  font-family: 'DM Sans', sans-serif;
  font-size: 10.5px;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 500;
  background: var(--panel-2);
}

td { color: var(--text-2); line-height: 1.65; }

tr:last-child td { border-bottom: 0; }

/* ── Rule card ── */
.rule-card {
  border: 1px solid var(--text);
  background: #fff;
  padding: 36px 32px;
  margin-top: 8px;
}

.rule-card p {
  font-family: 'Playfair Display', serif;
  font-size: 21px;
  line-height: 1.5;
  margin: 0;
  padding: 12px 0;
  border-bottom: 1px solid var(--line-light);
  color: var(--text);
}

.rule-card p:first-child { padding-top: 0; }
.rule-card p:last-child { border-bottom: 0; padding-bottom: 0; }

/* ── Contents ── */
.contents {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0 32px;
  margin-top: 28px;
}

.contents a {
  display: block;
  border-top: 1px solid var(--line);
  padding: 16px 0;
  font-size: 16px;
  color: var(--text-2);
  transition: color 0.15s;
}

.contents a:hover {
  color: var(--accent-light);
  text-decoration: none;
}

/* ── Footer ── */
.footer {
  padding: 40px 0 48px;
  color: var(--muted);
  font-size: 13px;
  letter-spacing: 0.05em;
  border-top: 1px solid var(--line);
}

/* ── Utility ── */
hr.line {
  border: 0;
  border-top: 1px solid var(--line);
  margin: 36px 0;
}

strong { font-weight: 500; color: var(--text); }

/* ── Responsive ── */
@media (max-width: 960px) {
  .container { padding: 0 24px; }
  .cover { min-height: auto; }
  .cover-grid,
  .card-grid,
  .twocol,
  .contents { grid-template-columns: 1fr; }
  .cover-grid { gap: 48px; padding: 56px 0; }
  .logo-panel { min-height: 280px; padding: 36px; }
  .section { padding: 64px 0; }
  .divider { min-height: 44vh; }
}

@media (max-width: 600px) {
  .container { padding: 0 20px; }
  .nav { gap: 12px; }
  .section { padding: 52px 0; }
}

/* ── Scroll animations ── */
.reveal {
  opacity: 0;
  transform: translateY(28px);
  transition: opacity 0.65s cubic-bezier(0.22, 1, 0.36, 1),
              transform 0.65s cubic-bezier(0.22, 1, 0.36, 1);
}

.reveal.visible {
  opacity: 1;
  transform: translateY(0);
}

.reveal-delay-1 { transition-delay: 0.08s; }
.reveal-delay-2 { transition-delay: 0.16s; }
.reveal-delay-3 { transition-delay: 0.24s; }
.reveal-delay-4 { transition-delay: 0.32s; }

/* Stagger card children */
.card-grid .card,
.contents a {
  opacity: 0;
  transform: translateY(20px);
  transition: opacity 0.5s cubic-bezier(0.22, 1, 0.36, 1),
              transform 0.5s cubic-bezier(0.22, 1, 0.36, 1);
}

.card-grid.visible .card:nth-child(1),
.contents.visible a:nth-child(1) { opacity: 1; transform: none; transition-delay: 0.05s; }
.card-grid.visible .card:nth-child(2),
.contents.visible a:nth-child(2) { opacity: 1; transform: none; transition-delay: 0.12s; }
.card-grid.visible .card:nth-child(3),
.contents.visible a:nth-child(3) { opacity: 1; transform: none; transition-delay: 0.19s; }
.card-grid.visible .card:nth-child(4),
.contents.visible a:nth-child(4) { opacity: 1; transform: none; transition-delay: 0.26s; }
.card-grid.visible .card:nth-child(5),
.contents.visible a:nth-child(5) { opacity: 1; transform: none; transition-delay: 0.33s; }
.card-grid.visible .card:nth-child(6),
.contents.visible a:nth-child(6) { opacity: 1; transform: none; transition-delay: 0.40s; }
.card-grid.visible .card:nth-child(7),
.contents.visible a:nth-child(7) { opacity: 1; transform: none; transition-delay: 0.47s; }
.card-grid.visible .card:nth-child(8),
.contents.visible a:nth-child(8) { opacity: 1; transform: none; transition-delay: 0.54s; }
.card-grid.visible .card:nth-child(9),
.contents.visible a:nth-child(9) { opacity: 1; transform: none; transition-delay: 0.61s; }
.card-grid.visible .card:nth-child(10),
.contents.visible a:nth-child(10) { opacity: 1; transform: none; transition-delay: 0.68s; }

/* Divider h2 reveal — letters slide in */
.divider h2 {
  clip-path: inset(0 0 0 0);
}

/* Rule stagger */
.rules-list .rule {
  opacity: 0;
  transform: translateX(-14px);
  transition: opacity 0.5s ease, transform 0.5s ease;
}
.rules-list.visible .rule:nth-child(1) { opacity: 1; transform: none; transition-delay: 0.04s; }
.rules-list.visible .rule:nth-child(2) { opacity: 1; transform: none; transition-delay: 0.12s; }
.rules-list.visible .rule:nth-child(3) { opacity: 1; transform: none; transition-delay: 0.20s; }
.rules-list.visible .rule:nth-child(4) { opacity: 1; transform: none; transition-delay: 0.28s; }
.rules-list.visible .rule:nth-child(5) { opacity: 1; transform: none; transition-delay: 0.36s; }

/* Diagram fade */
.diagram {
  opacity: 0;
  transform: translateY(16px);
  transition: opacity 0.7s ease, transform 0.7s ease;
}
.diagram.visible {
  opacity: 1;
  transform: none;
}

/* Respect prefers-reduced-motion */
@media (prefers-reduced-motion: reduce) {
  .reveal, .card-grid .card, .contents a, .rules-list .rule, .diagram {
    opacity: 1 !important;
    transform: none !important;
    transition: none !important;
  }
}

/* ── Dark mode ── */
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141310;
    --bg-warm: #181612;
    --panel: #1c1a17;
    --panel-2: #201e1a;
    --text: #f0ece3;
    --text-2: #ccc6b8;
    --muted: #7a7468;
    --muted-2: #5c574f;
    --accent: #7da87a;
    --accent-light: #9dc49a;
    --line: #2a2720;
    --line-light: #232019;
  }

  body { color: var(--text); }

  .topbar {
    background: rgba(20, 19, 16, 0.94);
    border-bottom-color: var(--line);
  }

  .cover {
    background: linear-gradient(160deg, var(--panel) 0%, var(--bg) 60%);
  }

  .logo-panel {
    --hm-bg:  #f4f1ea;
    --hm-d1:  #9a9490;
    --hm-d2:  #6a6460;
    --hm-d3:  #3a3632;
    --hm-d4:  #1a1916;
    --hm-dot: #1a1916;
    background: #f4f1ea;
    border-color: #ddd8ce;
  }

  .card {
    background: rgba(255,255,255,0.03);
    border-color: var(--line);
  }

  .card:hover {
    background: rgba(255,255,255,0.055);
  }

  .diagram {
    background: var(--panel);
    border-color: var(--line);
  }

  /* Invert SVG diagram box/text colors for dark */
  .diagram svg .dbox,
  .diagram svg .dbox2  { fill: #1c1a17; stroke: #3a342a; }
  .diagram svg .dbox2h { fill: #1a2a1a; stroke: #4a6741; }
  .diagram svg .dlbl,
  .diagram svg .dlbl2,
  .diagram svg .dlbl3  { fill: #f0ece3; }
  .diagram svg .dnote  { fill: #6a6460; }
  .diagram svg .darr,
  .diagram svg .darr2  { stroke: #5a5248; }

  table {
    background: var(--panel);
  }

  th {
    background: var(--panel-2);
    color: var(--muted);
  }

  td {
    color: var(--text-2);
    border-bottom-color: var(--line);
  }

  .rule-card {
    background: var(--panel);
    border-color: var(--text-2);
  }

  .rule-card p {
    color: var(--text);
    border-bottom-color: var(--line);
  }

  .callout {
    border-left-color: var(--accent);
  }

  .divider {
    background: var(--bg-warm);
    border-bottom-color: var(--line);
  }

  strong { color: var(--text); }

  hr.line { border-top-color: var(--line); }
}

/* Manual dark mode toggle class (js-controlled) */
html.dark {
  --bg: #141310;
  --bg-warm: #181612;
  --panel: #1c1a17;
  --panel-2: #201e1a;
  --text: #f0ece3;
  --text-2: #ccc6b8;
  --muted: #7a7468;
  --muted-2: #5c574f;
  --accent: #7da87a;
  --accent-light: #9dc49a;
  --line: #2a2720;
  --line-light: #232019;
}

html.dark body { color: var(--text); background: var(--bg); }
html.dark .topbar { background: rgba(20, 19, 16, 0.94); border-bottom-color: var(--line); }
html.dark .cover { background: linear-gradient(160deg, var(--panel) 0%, var(--bg) 60%); }
html.dark .logo-panel {
  --hm-bg:  #f4f1ea;
  --hm-d1:  #9a9490;
  --hm-d2:  #6a6460;
  --hm-d3:  #3a3632;
  --hm-d4:  #1a1916;
  --hm-dot: #1a1916;
  background: #f4f1ea;
  border-color: #ddd8ce;
}
html.dark .card { background: rgba(255,255,255,0.03); border-color: var(--line); }
html.dark .card:hover { background: rgba(255,255,255,0.055); }
html.dark .diagram { background: var(--panel); border-color: var(--line); }
html.dark table { background: var(--panel); }
html.dark th { background: var(--panel-2); color: var(--muted); }
html.dark td { color: var(--text-2); border-bottom-color: var(--line); }
html.dark .rule-card { background: var(--panel); border-color: var(--text-2); }
html.dark .rule-card p { color: var(--text); border-bottom-color: var(--line); }
html.dark .callout { border-left-color: var(--accent); }
html.dark .divider { background: var(--bg-warm); border-bottom-color: var(--line); }
html.dark strong { color: var(--text); }
html.dark hr.line { border-top-color: var(--line); }

/* Dark mode SVG diagrams */
html.dark .diagram svg .dbox,
html.dark .diagram svg .dbox2  { fill: #1c1a17; stroke: #3a342a; }
html.dark .diagram svg .dbox2h { fill: #1a2a1a; stroke: #4a6741; }
html.dark .diagram svg .dlbl,
html.dark .diagram svg .dlbl2,
html.dark .diagram svg .dlbl3  { fill: #f0ece3; }
html.dark .diagram svg .dnote  { fill: #6a6460; }
html.dark .diagram svg .darr,
html.dark .diagram svg .darr2  { stroke: #5a5248; }

/* ── Dark mode toggle button ── */
.theme-toggle {
  background: none;
  border: 1px solid var(--line);
  color: var(--muted);
  cursor: pointer;
  padding: 5px 10px;
  font-size: 10.5px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  font-family: 'DM Sans', sans-serif;
  font-weight: 500;
  transition: color 0.18s, border-color 0.18s;
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

.theme-toggle:hover {
  color: var(--text);
  border-color: var(--muted);
}

/* ── Enhanced print styles ── */
@media print {
  /* Hide UI chrome */
  .topbar,
  .theme-toggle,
  .cover,
  .divider,
  #contents,
  #note,
  #loop,
  #response,
  #situations,
  #cases,
  #parents,
  #sources,
  .footer { display: none !important; }

  /* Show only student rule sheet */
  #students { display: block !important; }

  /* Reset body for print */
  html, body {
    margin: 0;
    padding: 0;
    background: #fff !important;
    color: #000 !important;
    font-family: Georgia, 'Times New Roman', serif;
    font-size: 11pt;
    line-height: 1.5;
  }

  #students {
    padding: 0 !important;
    border: none !important;
  }

  .container {
    width: 100% !important;
    max-width: 100% !important;
    margin: 0 !important;
    padding: 0.4in 0.5in !important;
  }

  .smallcaps {
    font-size: 7pt;
    letter-spacing: 0.2em;
    text-transform: uppercase;
    color: #999;
    display: block;
    margin-bottom: 6pt;
  }

  h2 {
    font-size: 22pt !important;
    letter-spacing: -0.02em;
    margin: 0 0 14pt !important;
    color: #000 !important;
  }

  /* Two-col layout for rule card + instructions */
  .twocol {
    display: grid !important;
    grid-template-columns: 1fr 1fr !important;
    gap: 32pt !important;
    margin-top: 14pt;
  }

  .section-intro {
    font-size: 9.5pt !important;
    color: #444 !important;
    margin-bottom: 14pt !important;
    max-width: none !important;
  }

  /* Rule card — main printable element */
  .rule-card {
    border: 1.5pt solid #000 !important;
    background: #fff !important;
    padding: 20pt 18pt !important;
    page-break-inside: avoid;
  }

  .rule-card p {
    font-family: Georgia, serif !important;
    font-size: 14pt !important;
    line-height: 1.6 !important;
    padding: 10pt 0 !important;
    border-bottom: 0.5pt solid #ddd !important;
    margin: 0 !important;
    color: #000 !important;
  }

  .rule-card p:first-child { padding-top: 0 !important; }
  .rule-card p:last-child { border-bottom: none !important; padding-bottom: 0 !important; }

  /* Right column */
  h3 {
    font-size: 11pt !important;
    margin: 0 0 6pt !important;
    color: #000 !important;
  }

  ul { padding-left: 1.2em; margin: 0 0 14pt; }
  li { font-size: 9.5pt !important; color: #333 !important; line-height: 1.6; }

  p { font-size: 9.5pt !important; color: #333 !important; }

  /* Page setup */
  @page {
    size: letter portrait;
    margin: 0.5in;
  }

  /* Print header with branding */
  #students::before {
    content: 'Praxis Minor — Student Rule Sheet';
    display: block;
    font-size: 7pt;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: #aaa;
    border-bottom: 0.5pt solid #ddd;
    padding-bottom: 6pt;
    margin-bottom: 18pt;
    font-family: 'DM Sans', Arial, sans-serif;
  }

  /* Footer for print */
  #students::after {
    content: 'praxisminor.com — Educational use only. Not a substitute for professional care.';
    display: block;
    font-size: 7pt;
    color: #bbb;
    border-top: 0.5pt solid #eee;
    padding-top: 8pt;
    margin-top: 24pt;
    letter-spacing: 0.06em;
    font-family: 'DM Sans', Arial, sans-serif;
  }
}
