/* ==========================================================================
   Portal pages — shared "scientific editorial" layer
   Loaded by index.html, syllabus.html, guide.html and slides.html.

   Every roadmap stage is an "element family" with its own colour (--s1…--s6
   in style.css); .pt-sN sets --s so a module keeps one colour everywhere:
   periodic-table tile, timeline node, card accent, slide tile.
   ========================================================================== */

/* ---------- Stage colour hook ---------- */
.pt-s0 { --s: var(--text-muted); }
.pt-s1 { --s: var(--s1); }
.pt-s2 { --s: var(--s2); }
.pt-s3 { --s: var(--s3); }
.pt-s4 { --s: var(--s4); }
.pt-s5 { --s: var(--s5); }
.pt-s6 { --s: var(--s6); }

kbd {
  display: inline-block;
  padding: 0.02rem 0.4rem;
  font-family: var(--font-mono);
  font-size: 0.78em;
  line-height: 1.4;
  color: var(--text-primary);
  background: var(--bg-surface);
  border: 1px solid var(--border-strong);
  border-bottom-width: 2px;
  border-radius: 5px;
}

/* ==========================================================================
   Page sections
   ========================================================================== */

.home {
  max-width: 1240px;
  margin: 0 auto;
  padding: 0 1.5rem 5.5rem;
}

.sec {
  padding-top: clamp(3.5rem, 2.5rem + 3vw, 5.5rem);
  scroll-margin-top: 40px;
}

.sec-head {
  max-width: 46rem;
  margin-bottom: 2.2rem;
}

.sec-head-row {
  max-width: none;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1rem 1.5rem;
}

.sec-kicker {
  margin: 0 0 0.6rem;
  font-family: var(--font-mono);
  font-size: 0.74rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent-crimson);
}

.home .sec-title {
  margin: 0;
  padding: 0;
  border: 0;
  font-family: var(--font-serif);
  font-size: clamp(1.6rem, 1.15rem + 1.3vw, 2.35rem);
  line-height: 1.2;
  letter-spacing: -0.01em;
  color: var(--ink);
}

.sec-lead {
  margin: 0.85rem 0 0;
  font-size: 1rem;
  line-height: 1.8;
  color: var(--text-secondary);
}

.home .search-input {
  border-radius: 999px;
  padding: 0.55rem 1rem;
  min-width: 260px;
  border-color: var(--border-color);
}

.home .search-input:focus {
  outline: none;
  border-color: var(--ink);
  box-shadow: 0 0 0 4px rgba(20, 26, 36, 0.08);
}

/* ---------- § 2 Syllabus ---------- */

.progress-strip {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 0.35rem 1.25rem;
  margin: 0 0 0.5rem;
  padding: 0.95rem 1.25rem;
  border-left-width: 1px;
  box-shadow: none;
}

.progress-strip-label {
  display: flex;
  align-items: baseline;
  gap: 0.75rem;
  font-size: 0.9rem;
  color: var(--ink);
}

.progress-strip .hint-inline {
  grid-column: 1 / -1;
  margin: 0;
  font-size: 0.74rem;
}

.part-head {
  display: flex;
  align-items: center;
  gap: 1.3rem;
  margin: 3.2rem 0 1.5rem;
  padding-bottom: 1.1rem;
  border-bottom: 1px solid var(--border-color);
}

.part-no {
  flex: none;
  font-family: var(--font-serif);
  font-size: clamp(2rem, 1.5rem + 1.5vw, 2.8rem);
  font-weight: 700;
  line-height: 1;
  letter-spacing: -0.02em;
  color: var(--text-muted);
  color: transparent;
  -webkit-text-stroke: 1.2px var(--text-muted);
}

.home .part-title {
  margin: 0;
  font-family: var(--font-serif);
  font-size: 1.15rem;
  color: var(--ink);
}

.part-desc {
  margin: 0.15rem 0 0;
  font-size: 0.86rem;
  color: var(--text-muted);
}

.module-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1.25rem;
}

/* A semester with exactly four modules fills one row of four instead of
   leaving an orphan card under a 3-column grid. */
.module-grid:has(> .module-card:nth-child(4):last-child) {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.module-card {
  position: relative;
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  transition: transform 0.28s var(--ease-out), box-shadow 0.28s ease, border-color 0.2s ease;
}

/* Stage-coloured rule that draws itself across the top on hover. */
.module-card::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 1;
  height: 3px;
  background: var(--s);
  transform: scaleX(0);
  transform-origin: left;
  transition: transform 0.4s var(--ease-out);
}

.module-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-md);
  border-color: color-mix(in srgb, var(--s) 35%, var(--border-color));
}

.module-card:hover::before { transform: scaleX(1); }

.module-thumb {
  display: block;
  padding: 1rem 1rem 0.45rem;
  overflow: hidden;
  border-bottom: 1px solid var(--border-color);
  background: var(--bg-subtle);
  background: radial-gradient(120% 100% at 50% 0%,
    color-mix(in srgb, var(--s) 10%, var(--bg-surface)), var(--bg-surface) 72%);
}

.module-thumb-svg {
  display: block;
  width: 100%;
  height: auto;
  transition: transform 0.4s var(--ease-out);
}

.module-card:hover .module-thumb-svg { transform: scale(1.04); }

.module-card-todo .module-thumb-svg {
  opacity: 0.5;
  filter: saturate(0.45);
}

.module-card-body {
  flex: 1;
  padding: 1.1rem 1.25rem 0;
}

.module-card-top {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  margin-bottom: 0.65rem;
}

.module-el {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.75rem;
  height: 1.75rem;
  border-radius: 6px;
  border: 1px solid color-mix(in srgb, var(--s) 28%, transparent);
  background: var(--bg-subtle);
  background: color-mix(in srgb, var(--s) 11%, var(--bg-surface));
  color: var(--s);
  font-family: var(--font-serif);
  font-size: 0.8rem;
  font-weight: 700;
}

.module-card .module-num {
  padding: 0;
  background: none;
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.module-card .status-badge { margin-left: auto; }

.home .module-title {
  margin: 0 0 0.5rem;
  font-family: var(--font-serif);
  font-size: 1.12rem;
  line-height: 1.4;
  color: var(--ink);
}

.module-title a { color: inherit; }

.module-title a:hover {
  color: var(--s);
  text-decoration: none;
}

.module-desc {
  margin: 0 0 1rem;
  font-size: 0.85rem;
  line-height: 1.75;
  color: var(--text-secondary);
}

.module-notebooks {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.12rem;
  margin: 0 0 1rem;
  padding: 0.75rem 0 0;
  border-top: 1px dashed var(--border-color);
}

.module-notebooks li {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  min-width: 0;
  font-size: 0.8rem;
}

.module-notebooks li::before {
  content: "";
  flex: none;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--s);
  opacity: 0.6;
}

.module-notebooks li.nb-ex::before {
  border-radius: 1px;
  background: var(--accent-gold);
  opacity: 1;
  transform: rotate(45deg);
}

.module-notebooks a {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--text-secondary);
}

.module-notebooks a:hover {
  color: var(--s);
  text-decoration: none;
}

.module-nb-planned::before { display: none; }

.nb-tag {
  flex: none;
  padding: 0 0.35rem;
  border-radius: 3px;
  background: rgba(180, 83, 9, 0.1);
  color: var(--accent-gold);
  font-size: 0.64rem;
  font-weight: 600;
}

.module-card-foot {
  padding: 0 1.25rem 1rem;
}

.module-card .progress-fill { background: var(--s); }

.module-card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border-color);
  font-size: 0.78rem;
}

.module-meta { color: var(--text-muted); }

.module-go {
  white-space: nowrap;
  font-weight: 600;
  color: var(--ink);
}

.module-go span {
  display: inline-block;
  transition: transform 0.2s var(--ease-out);
}

.module-card:hover .module-go span { transform: translateX(3px); }

.module-go:hover {
  color: var(--s);
  text-decoration: none;
}

/* ---------- § 3 Learning rhythm ---------- */

.rhythm {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  overflow: hidden;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  counter-reset: step;
}

.rhythm li {
  position: relative;
  padding: 1.4rem 1.2rem 1.5rem;
  border-left: 1px solid var(--border-color);
  counter-increment: step;
  transition: background-color 0.2s ease;
}

.rhythm li:first-child { border-left: 0; }
.rhythm li:hover { background: var(--bg-subtle); }

.rhythm li::before {
  content: counter(step, decimal-leading-zero);
  position: absolute;
  top: 1.15rem;
  right: 1.1rem;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--text-muted);
}

.rhythm-mark {
  display: block;
  margin-bottom: 0.9rem;
  font-size: 1.45rem;
  line-height: 1;
}

.rhythm strong {
  display: block;
  margin-bottom: 0.35rem;
  font-family: var(--font-serif);
  font-size: 1rem;
  color: var(--ink);
}

.rhythm p {
  margin: 0;
  font-size: 0.82rem;
  line-height: 1.7;
  color: var(--text-secondary);
}

/* ==========================================================================
   Sub-pages (syllabus / guide / slides)
   ========================================================================== */

.page-hero {
  position: relative;
  overflow: hidden;
  border-bottom: 1px solid var(--border-color);
}

.page-hero::before {
  content: "";
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(var(--grid-line) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-line) 1px, transparent 1px);
  background-size: 28px 28px;
  -webkit-mask-image: linear-gradient(100deg, transparent 35%, #000 100%);
  mask-image: linear-gradient(100deg, transparent 35%, #000 100%);
  pointer-events: none;
}

.page-hero-inner {
  position: relative;
  max-width: 1240px;
  margin: 0 auto;
  padding: clamp(2.2rem, 1.5rem + 3vw, 4rem) 1.5rem clamp(2rem, 1.5rem + 2vw, 3.2rem);
}

.crumbs {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 1.6rem;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.crumbs a { color: var(--text-secondary); }
.crumbs a:hover { color: var(--accent-crimson); }

.page-hero .page-title {
  margin: 0;
  font-family: var(--font-serif);
  font-size: clamp(2.2rem, 1.4rem + 2.6vw, 3.6rem);
  font-weight: 700;
  line-height: 1.1;
  letter-spacing: -0.02em;
  color: var(--ink);
}

.page-lead {
  max-width: 44rem;
  margin: 1rem 0 0;
  font-size: 1.02rem;
  line-height: 1.85;
  color: var(--text-secondary);
}

.sec-first { padding-top: clamp(2rem, 1.5rem + 2vw, 3rem); }
ol.sec-first { margin-top: clamp(2rem, 1.5rem + 2vw, 3rem); padding-top: 0; }

/* Syllabus: progress strip and filter share one toolbar row. */
.syllabus-bar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 1rem;
  padding-top: 2rem;
}

.syllabus-bar .progress-strip { margin: 0; }

/* Guide */
.note-card {
  display: flex;
  gap: 1rem;
  align-items: flex-start;
  margin-top: 1.25rem;
  padding: 1.2rem 1.4rem;
  border: 1px solid var(--border-color);
  border-left: 3px solid var(--accent-gold);
  border-radius: var(--radius-md);
  background: var(--bg-surface);
}

.note-mark {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.8rem;
  height: 1.8rem;
  border-radius: 50%;
  background: rgba(180, 83, 9, 0.12);
  color: var(--accent-gold);
  font-weight: 700;
}

.note-card strong {
  display: block;
  margin-bottom: 0.25rem;
  font-family: var(--font-serif);
  color: var(--ink);
}

.note-card p {
  margin: 0;
  font-size: 0.88rem;
  line-height: 1.75;
  color: var(--text-secondary);
}

.setup-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1.25rem;
}

.bento-card {
  min-width: 0;
  padding: 1.6rem 1.7rem;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
}

.home .bento-title {
  margin: 0.6rem 0 0.5rem;
  font-family: var(--font-serif);
  font-size: 1.3rem;
  color: var(--ink);
}

.setup-card p {
  margin: 0;
  font-size: 0.88rem;
  line-height: 1.75;
  color: var(--text-secondary);
}

.check-list {
  list-style: none;
  margin: 1rem 0 0;
  padding: 0;
  font-size: 0.86rem;
  color: var(--text-secondary);
}

.check-list li {
  position: relative;
  padding: 0.4rem 0 0.4rem 1.6rem;
  border-top: 1px dashed var(--border-color);
}

.check-list li::before {
  content: "✓";
  position: absolute;
  left: 0.2rem;
  color: var(--accent-teal);
  font-weight: 700;
}

.setup-tag {
  display: inline-block;
  padding: 0.08rem 0.55rem;
  border-radius: 999px;
  background: var(--bg-subtle);
  color: var(--text-secondary);
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.05em;
}

.setup-code {
  margin: 1rem 0 0;
  padding: 1rem 1.1rem;
  border: 0;
  border-radius: 10px;
  background: #141a24;
  color: #e4e9f0;
  font-size: 0.8rem;
  line-height: 1.75;
}

.setup-code code {
  background: none;
  color: inherit;
  padding: 0;
}

/* Slides */
.deck-grid {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
}

.deck-card {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 1.2rem;
  height: 100%;
  padding: 1rem 1.3rem 1rem 1rem;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  color: var(--text-primary);
  text-decoration: none;
  transition: transform 0.28s var(--ease-out), box-shadow 0.28s ease, border-color 0.2s ease;
}

.deck-card:hover {
  transform: translateY(-3px);
  border-color: color-mix(in srgb, var(--s) 45%, var(--border-color));
  box-shadow: var(--shadow-md);
  color: var(--text-primary);
  text-decoration: none;
}

.deck-tile {
  position: relative;
  display: flex;
  align-items: flex-end;
  width: 4.4rem;
  height: 4.4rem;
  padding: 0.4rem 0.5rem;
  border-radius: 10px;
  border: 1px solid color-mix(in srgb, var(--s) 28%, var(--border-color));
  background: color-mix(in srgb, var(--s) 9%, var(--bg-surface));
}

.deck-tile-num {
  position: absolute;
  top: 0.35rem;
  left: 0.5rem;
  font-family: var(--font-mono);
  font-size: 0.66rem;
  font-weight: 600;
  color: var(--s);
}

.deck-tile-sym {
  font-family: var(--font-serif);
  font-size: 1.7rem;
  font-weight: 700;
  line-height: 1;
  color: var(--ink);
}

.deck-body {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  min-width: 0;
}

.deck-module {
  font-size: 0.76rem;
  font-weight: 600;
  color: var(--s);
}

.deck-name {
  font-family: var(--font-serif);
  font-size: 1rem;
  font-weight: 600;
  line-height: 1.45;
  color: var(--ink);
}

.deck-open {
  font-size: 0.8rem;
  font-weight: 600;
  white-space: nowrap;
  color: var(--text-muted);
  transition: color 0.2s ease;
}

.deck-open span {
  display: inline-block;
  transition: transform 0.25s var(--ease-out);
}

.deck-card:hover .deck-open { color: var(--ink); }
.deck-card:hover .deck-open span { transform: translate(2px, -2px); }

[data-theme="dark"] .setup-code { background: #0b0f15; }
[data-theme="dark"] .nb-tag { background: rgba(226, 176, 100, 0.14); }

/* ---------- Responsive ---------- */

@media (max-width: 1100px) {
  .module-grid,
  .module-grid:has(> .module-card:nth-child(4):last-child) {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .rhythm { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .rhythm li:nth-child(3n + 1) { border-left: 0; }
  .rhythm li:nth-child(n + 4) { border-top: 1px solid var(--border-color); }
}

@media (max-width: 900px) {
  .setup-grid,
  .deck-grid,
  .syllabus-bar { grid-template-columns: 1fr; }
}

@media (max-width: 640px) {
  .module-grid,
  .module-grid:has(> .module-card:nth-child(4):last-child) { grid-template-columns: 1fr; }
  .rhythm { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .rhythm li:nth-child(3n + 1) { border-left: 1px solid var(--border-color); }
  .rhythm li:nth-child(2n + 1) { border-left: 0; }
  .rhythm li:nth-child(n + 3) { border-top: 1px solid var(--border-color); }
  .progress-strip { grid-template-columns: 1fr auto; }
  .progress-strip .progress-track { grid-column: 1 / -1; grid-row: 2; }
  .home .search-input { min-width: 0; width: 100%; }
  .filter-bar { width: 100%; }
  .deck-card { grid-template-columns: auto minmax(0, 1fr); }
  .deck-open { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .module-card,
  .module-thumb-svg,
  .deck-card { transition: none; }
  .module-card:hover,
  .deck-card:hover,
  .module-card:hover .module-thumb-svg { transform: none; }
}
