/* Palette taken from pastpapers.wiki: navy #0b2e4a (body text),
     sky #1fb9fb (theme-color), red #f70d28 (menu badges). */
  :root {
    --ground:      #EDF2F6;
    --surface:     #FFFFFF;
    --surface-alt: #F4F8FB;
    --line:        #D2DFE9;
    --line-soft:   #E3ECF3;
    --ink:         #0B2E4A;
    --ink-2:       #37566E;
    --muted:       #64798B;
    --accent:      #0B6FA8;
    --fill:        #0B2E4A;
    --fill-ink:    #FFFFFF;
    --accent-soft: #DCEFFB;
    --sky:         #1FB9FB;
    --pdf:         #C21024;
    --pdf-soft:    #FCE7EA;
    --live:        #F70D28;
    --shadow:      0 1px 2px rgba(11,46,74,.07), 0 8px 24px -12px rgba(11,46,74,.22);

    --step--1: .8125rem;
    --step-0:  1rem;
    --step-1:  1.15rem;
    --step-2:  1.45rem;
    --step-4:  2.5rem;

    --sans: "Noto Sans Sinhala", "Segoe UI", system-ui, sans-serif;
    --serif: "Noto Serif Sinhala", Georgia, serif;
    --mono: "IBM Plex Mono", ui-monospace, monospace;
  }

  @media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
      --ground:      #071620;
      --surface:     #0E202C;
      --surface-alt: #122836;
      --line:        #24404F;
      --line-soft:   #1A3342;
      --ink:         #E4EFF6;
      --ink-2:       #B4C9D6;
      --muted:       #8AA2B2;
      --accent:      #58C8FF;
      --fill:        #1FB9FB;
      --fill-ink:    #06222F;
      --accent-soft: #0E2E40;
      --sky:         #1FB9FB;
      --pdf:         #FF8A96;
      --pdf-soft:    #351720;
      --live:        #FF6B7C;
      --shadow:      0 1px 2px rgba(0,0,0,.45), 0 8px 24px -12px rgba(0,0,0,.75);
    }
  }

  :root[data-theme="dark"] {
    --ground:      #071620;
    --surface:     #0E202C;
    --surface-alt: #122836;
    --line:        #24404F;
    --line-soft:   #1A3342;
    --ink:         #E4EFF6;
    --ink-2:       #B4C9D6;
    --muted:       #8AA2B2;
    --accent:      #58C8FF;
    --fill:        #1FB9FB;
    --fill-ink:    #06222F;
    --accent-soft: #0E2E40;
    --sky:         #1FB9FB;
    --pdf:         #FF8A96;
    --pdf-soft:    #351720;
    --live:        #FF6B7C;
    --shadow:      0 1px 2px rgba(0,0,0,.45), 0 8px 24px -12px rgba(0,0,0,.75);
  }

  * { box-sizing: border-box; }

  body {
    margin: 0;
    background: var(--ground);
    color: var(--ink);
    font-family: var(--sans);
    font-size: var(--step-0);
    line-height: 1.65;
    -webkit-font-smoothing: antialiased;
  }

  a { color: var(--accent); text-underline-offset: .18em; }
  a:focus-visible, button:focus-visible, summary:focus-visible {
    outline: 2px solid var(--sky);
    outline-offset: 3px;
    border-radius: 3px;
  }

  .mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }

  /* Sinhala needs more leading than Latin at the same size */
  .si { font-family: var(--sans); line-height: 1.95; }
  .gloss { color: var(--muted); font-weight: 400; }


  /* ---------- masthead ---------- */
  .masthead { border-bottom: 3px solid var(--sky); background: var(--surface); }
  .masthead-in {
    max-width: 1140px; margin: 0 auto; padding: .9rem 1.25rem;
    display: flex; align-items: center; gap: 1rem; flex-wrap: wrap;
  }
  .wordmark {
    font-family: var(--serif); font-weight: 700; font-size: var(--step-1);
    letter-spacing: -.01em; color: var(--ink); text-decoration: none;
  }
  .wordmark em { color: var(--sky); font-style: normal; }
  .crumbs {
    margin-left: auto; font-size: var(--step--1); color: var(--muted);
    display: flex; gap: .45rem; flex-wrap: wrap;
  }
  .crumbs a { color: var(--muted); text-decoration: none; }
  .crumbs a:hover { color: var(--accent); text-decoration: underline; }

  /* ---------- shell ---------- */
  .shell { max-width: 1140px; margin: 0 auto; padding: 2rem 1.25rem 3.5rem; }
  .cols { display: grid; gap: 2rem; align-items: start; }
  @media (min-width: 940px) {
    .cols { grid-template-columns: minmax(0,1fr) 316px; gap: 2.5rem; }
  }

  /* ---------- title block ---------- */
  .eyebrow {
    display: flex; flex-wrap: wrap; gap: .5rem; align-items: center;
    font-size: .74rem; letter-spacing: .1em; text-transform: uppercase;
    color: var(--muted); font-weight: 700; margin-bottom: .85rem;
  }
  .eyebrow .dot { width: 3px; height: 3px; border-radius: 50%; background: var(--line); }
  .tag-grade {
    background: var(--fill); color: var(--fill-ink);
    padding: .22rem .55rem; border-radius: 3px; letter-spacing: .06em;
  }
  h1 {
    font-family: var(--serif); font-weight: 700;
    font-size: clamp(1.6rem, 1.1rem + 2.1vw, var(--step-4));
    line-height: 1.35; margin: 0 0 .5rem; text-wrap: balance;
  }
  h1 .gloss-line {
    display: block; font-family: var(--sans); font-size: .46em;
    font-weight: 400; color: var(--muted); margin-top: .5rem; line-height: 1.4;
  }
  .standfirst {
    color: var(--ink-2); font-size: var(--step-1); margin: 0 0 1.5rem; max-width: 62ch;
  }
  .standfirst .seqmark { font-family: var(--mono); font-size: .88em; color: var(--muted); }

  /* ---------- player ---------- */
  .player {
    background: var(--surface); border: 1px solid var(--line);
    border-top: 3px solid var(--sky);
    border-radius: 10px; box-shadow: var(--shadow); overflow: hidden;
  }
  .player-top { display: flex; gap: 1rem; align-items: center; padding: 1.15rem 1.25rem 1rem; }
  .play {
    flex: none; width: 58px; height: 58px; border-radius: 50%;
    border: none; background: var(--fill); color: var(--fill-ink);
    display: grid; place-items: center; cursor: pointer;
    transition: transform .15s ease, background .15s ease;
  }
  .play:hover { background: var(--sky); color: #06222F; transform: scale(1.04); }
  .play svg { width: 22px; height: 22px; margin-left: 2px; }
  .play[data-state="playing"] svg { margin-left: 0; }
  .play-meta { min-width: 0; }
  .play-label { font-weight: 700; font-size: var(--step-1); line-height: 1.3; margin-bottom: .15rem; }
  .play-sub { font-size: var(--step--1); color: var(--muted); }
  .play-sub .live-dot {
    display: inline-block; width: 6px; height: 6px; border-radius: 50%;
    background: var(--live); margin-right: .35rem; vertical-align: middle;
  }

  .scrub { padding: 0 1.25rem; }
  .track { position: relative; height: 6px; border-radius: 99px; background: var(--line-soft); cursor: pointer; }
  .track-fill { position: absolute; inset: 0 auto 0 0; width: 0%; background: var(--sky); border-radius: 99px; }
  .track-knob {
    position: absolute; top: 50%; left: 0%; width: 13px; height: 13px;
    border-radius: 50%; background: var(--fill); border: 2px solid var(--surface);
    transform: translate(-50%, -50%);
  }
  .times {
    display: flex; justify-content: space-between;
    font-family: var(--mono); font-size: .76rem; color: var(--muted); padding: .45rem 0 0;
  }

  .player-bar { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; padding: .85rem 1.25rem 1.1rem; }
  .ctl {
    border: 1px solid var(--line); background: var(--surface);
    color: var(--ink-2); border-radius: 6px; padding: .38rem .6rem;
    font-family: var(--sans); font-size: var(--step--1); cursor: pointer;
    display: inline-flex; align-items: center; gap: .35rem;
  }
  .ctl:hover { border-color: var(--sky); color: var(--accent); }
  .ctl .mono { font-size: .78rem; }
  .player-bar .spacer { margin-left: auto; }
  .dl-audio {
    background: var(--fill); border: 1px solid var(--fill);
    color: var(--fill-ink); border-radius: 6px; padding: .45rem .85rem;
    font-size: var(--step--1); font-weight: 500; text-decoration: none;
    display: inline-flex; gap: .5rem; align-items: center;
  }
  .dl-audio:hover { background: var(--sky); border-color: var(--sky); color: #06222F; }
  .dl-audio svg { width: 15px; height: 15px; }
  .dl-audio .sz { font-family: var(--mono); font-size: .76rem; opacity: .8; }

  .player-note {
    border-top: 1px dashed var(--line); padding: .7rem 1.25rem;
    font-size: var(--step--1); color: var(--muted); background: var(--surface-alt);
  }

  /* ---------- sections ---------- */
  section { margin-top: 2.5rem; }
  h2 { font-family: var(--serif); font-size: var(--step-2); font-weight: 600; margin: 0 0 .25rem; }
  h2 .gloss { font-size: .62em; font-family: var(--sans); margin-left: .5rem; }
  .sec-note { color: var(--muted); font-size: var(--step--1); margin: 0 0 1.1rem; }

  /* ---------- download cards ---------- */
  .sheets { display: grid; gap: .8rem; }
  @media (min-width: 640px) { .sheets { grid-template-columns: 1fr 1fr; } }

  .sheet {
    display: grid; grid-template-columns: auto 1fr auto;
    gap: 1rem; align-items: center;
    background: var(--surface); border: 1px solid var(--line);
    border-radius: 10px; padding: 1rem 1.1rem;
    text-decoration: none; color: inherit;
    transition: border-color .15s ease, box-shadow .15s ease, transform .15s ease;
  }
  .sheet:hover {
    border-color: var(--sky); box-shadow: var(--shadow); transform: translateY(-2px);
  }
  .sheet-icon {
    flex: none; width: 44px; height: 52px; border-radius: 4px;
    background: var(--pdf-soft); border: 1px solid var(--pdf);
    display: grid; place-items: center;
    font-family: var(--mono); font-size: .62rem; font-weight: 500;
    color: var(--pdf); letter-spacing: .06em;
  }
  .sheet-body { min-width: 0; }
  .sheet-name { font-weight: 600; font-size: var(--step-0); line-height: 1.4; overflow-wrap: anywhere; }
  .sheet-meta { font-family: var(--mono); font-size: .75rem; color: var(--muted); margin-top: .15rem; }
  .sheet-btn {
    flex: none; display: inline-flex; align-items: center; gap: .4rem;
    background: var(--fill); color: var(--fill-ink);
    border-radius: 6px; padding: .48rem .8rem;
    font-size: var(--step--1); font-weight: 600; white-space: nowrap;
    transition: background .15s ease;
  }
  .sheet:hover .sheet-btn { background: var(--sky); color: #06222F; }
  .sheet-btn svg { width: 15px; height: 15px; }

  /* ---------- parts list ---------- */
  .parts { display: flex; flex-direction: column; border-top: 1px solid var(--line-soft); }
  .part {
    display: grid; grid-template-columns: auto 1fr auto; gap: .9rem;
    align-items: center; padding: .8rem .5rem;
    border-bottom: 1px solid var(--line-soft);
    text-decoration: none; color: inherit;
  }
  .part:hover { background: var(--surface-alt); }
  .part[aria-current="true"] { background: var(--accent-soft); }
  .part-no {
    font-family: var(--mono); font-size: .8rem; font-weight: 500;
    width: 2.6rem; text-align: center; color: var(--muted);
    border: 1px solid var(--line); border-radius: 4px; padding: .15rem 0;
    background: var(--surface);
  }
  .part[aria-current="true"] .part-no { background: var(--fill); color: var(--fill-ink); border-color: var(--fill); }
  .part-main { min-width: 0; }
  .part-title { font-weight: 500; line-height: 1.4; }
  .part-title .gloss { display: block; font-size: .82rem; line-height: 1.9; }
  .part-sub { font-size: .78rem; color: var(--muted); font-family: var(--mono); }
  .part-dur { font-family: var(--mono); font-size: .78rem; color: var(--muted); }

  /* ---------- prose ---------- */
  .prose { max-width: 64ch; color: var(--ink-2); }
  .prose p { margin: 0 0 1.1rem; }

  /* ---------- credit ---------- */
  .credit {
    border-left: 3px solid var(--sky); background: var(--surface);
    padding: 1.1rem 1.25rem; border-radius: 0 8px 8px 0;
    border-top: 1px solid var(--line-soft);
    border-right: 1px solid var(--line-soft);
    border-bottom: 1px solid var(--line-soft);
  }
  .credit h3 { margin: 0 0 .4rem; font-size: var(--step-0); font-weight: 700; font-family: var(--sans); }
  .credit p { margin: 0 0 .5rem; font-size: var(--step--1); color: var(--ink-2); }
  .credit p:last-child { margin-bottom: 0; }

  /* ---------- pager ---------- */
  .pager { display: grid; gap: .7rem; margin-top: 2.5rem; }
  @media (min-width: 620px) { .pager { grid-template-columns: 1fr 1fr; } }
  .pager a {
    border: 1px solid var(--line); border-radius: 8px; padding: .9rem 1rem;
    text-decoration: none; color: inherit; background: var(--surface); display: block;
  }
  .pager a:hover { border-color: var(--sky); }
  .pager .dir { font-size: .72rem; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); font-weight: 700; }
  .pager .nm { font-weight: 500; line-height: 1.4; margin-top: .2rem; }
  .pager .nx { text-align: right; }

  /* ---------- sidebar ---------- */
  .aside { display: flex; flex-direction: column; gap: 1.25rem; }
  .panel { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 1.1rem 1.15rem; }
  .panel h3 {
    margin: 0 0 .9rem; font-size: .74rem; letter-spacing: .1em;
    text-transform: uppercase; color: var(--muted); font-weight: 700; font-family: var(--sans);
  }
  .facts { display: grid; grid-template-columns: auto 1fr; gap: .55rem .9rem; font-size: var(--step--1); }
  .facts dt { color: var(--muted); }
  .facts dd { margin: 0; font-family: var(--mono); font-variant-numeric: tabular-nums; }
  .facts dd.plain { font-family: var(--sans); }

  .onair {
    background: var(--fill); color: var(--fill-ink);
    border-radius: 8px; padding: .8rem .95rem; margin-bottom: 1rem;
  }
  .onair-time { font-family: var(--mono); font-size: var(--step-2); font-weight: 500; letter-spacing: -.02em; }
  .onair-lbl { font-size: .7rem; text-transform: uppercase; letter-spacing: .1em; opacity: .7; font-weight: 700; }
  .onair-date { font-size: var(--step--1); opacity: .85; }

  /* ---------- notes ---------- */
  .notes { margin-top: 3rem; border-top: 2px solid var(--line); padding-top: 1.5rem; }
  .notes summary { cursor: pointer; font-weight: 700; font-size: var(--step--1); letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
  .notes-grid { display: grid; gap: 1.25rem; margin-top: 1.25rem; }
  @media (min-width: 700px) { .notes-grid { grid-template-columns: 1fr 1fr; } }
  .note-block h4 { margin: 0 0 .4rem; font-size: var(--step--1); font-weight: 700; font-family: var(--mono); color: var(--accent); }
  .note-block ul { margin: 0; padding-left: 1.1rem; font-size: var(--step--1); color: var(--ink-2); }
  .note-block li { margin-bottom: .3rem; }

  @media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* ---------- index pages ---------- */
.intro { max-width: 68ch; margin-bottom: 2.5rem; }
.intro h1 {
  font-family: var(--serif); font-weight: 700;
  font-size: clamp(1.7rem, 1.2rem + 2.2vw, var(--step-4));
  line-height: 1.25; margin: 0 0 .6rem; text-wrap: balance;
}
.stat-line {
  margin: 1rem 0 0; font-size: var(--step--1); color: var(--muted);
  font-family: var(--mono);
}
.stat-line strong { color: var(--ink); font-weight: 500; }

.grade-block { margin-top: 2.75rem; }
.grade-head {
  display: flex; flex-wrap: wrap; align-items: baseline; gap: .25rem 1rem;
  border-bottom: 2px solid var(--sky); padding-bottom: .5rem; margin-bottom: 1.1rem;
}
.grade-head h2 { margin: 0; }
.grade-sum {
  margin: 0; font-size: var(--step--1); color: var(--muted);
  display: flex; flex-wrap: wrap; gap: .9rem; align-items: baseline;
}
.grade-all { margin-left: auto; white-space: nowrap; font-weight: 500; }

.subject-grid { display: grid; gap: .7rem; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); }
.subject-card {
  display: flex; flex-direction: column; gap: .3rem;
  background: var(--surface); border: 1px solid var(--line);
  border-left: 3px solid var(--line); border-radius: 8px;
  padding: .85rem 1rem; text-decoration: none; color: inherit;
  transition: border-color .15s ease, transform .15s ease;
}
.subject-card:hover { border-color: var(--line); border-left-color: var(--sky); transform: translateX(2px); }
.subject-name { font-weight: 600; line-height: 1.35; }
.subject-meta { font-size: .78rem; color: var(--muted); font-family: var(--mono); }
.subject-meta .count { color: var(--ink); font-weight: 500; }
.subject-meta .dates { display: block; margin-top: .15rem; }

/* ---------- lists ---------- */
.lesson-index { border-top: 1px solid var(--line-soft); }
.parts.flush { border-top: none; }
.part.two { grid-template-columns: auto 1fr; }
.pager-empty {
  border: 1px dashed var(--line); border-radius: 8px; padding: .9rem 1rem;
  color: var(--muted); background: transparent; display: block;
}
.pager-empty .dir { display: block; }
.panel-more { margin: .9rem 0 0; font-size: var(--step--1); }
.panel-links { margin: 0; font-size: var(--step--1); color: var(--ink-2); line-height: 2; }

/* ---------- footer ---------- */
.foot { border-top: 1px solid var(--line); background: var(--surface); margin-top: 3.5rem; }
.foot-in {
  max-width: 1140px; margin: 0 auto; padding: 1.6rem 1.25rem 2.2rem;
  font-size: var(--step--1); color: var(--muted);
}
.foot-in p { margin: 0 0 .5rem; max-width: 78ch; }
.foot-links { font-family: var(--sans); }

/* ---------- province ---------- */
.tag-prov {
  background: var(--accent-soft); color: var(--accent);
  padding: .2rem .5rem; border-radius: 3px; letter-spacing: .06em;
}
.province-bar { display: flex; flex-wrap: wrap; gap: .5rem; margin: 0 0 1.6rem; }
.prov-chip {
  border: 1px solid var(--line); border-radius: 99px;
  padding: .35rem .85rem; font-size: var(--step--1);
  text-decoration: none; color: var(--ink-2); background: var(--surface);
  display: inline-flex; gap: .4rem; align-items: baseline;
}
.prov-chip:hover { border-color: var(--sky); color: var(--accent); }
.prov-chip.on { background: var(--fill); border-color: var(--fill); color: var(--fill-ink); }
.prov-chip .n { font-family: var(--mono); font-size: .76rem; opacity: .75; }
.prov-head {
  margin: 2rem 0 .8rem; padding-bottom: .4rem;
  border-bottom: 1px solid var(--line);
}
.prov-head .gloss { font-family: var(--sans); font-size: .6em; margin-left: .5rem; }
.part-no.prov { font-size: .7rem; text-transform: uppercase; letter-spacing: .04em; }
.subject-si { font-size: .82rem; color: var(--muted); line-height: 1.8; }
h1 .gloss-line.si { line-height: 1.9; }

/* ---------- syllabus unit headings ---------- */
.unit-head {
  display: flex; align-items: baseline; gap: .55rem; flex-wrap: wrap;
  margin: 1.6rem 0 .5rem;
  font-family: var(--serif); font-size: var(--step-1); font-weight: 600;
  color: var(--ink); line-height: 1.75;
}
.unit-head .unit-no {
  flex: none;
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 1.7rem; height: 1.7rem; padding: 0 .35rem;
  border-radius: .45rem;
  background: var(--accent-soft); color: var(--accent);
  font-family: var(--sans); font-size: .78rem; font-weight: 700;
}
.unit-head .gloss {
  font-family: var(--sans); font-size: .72rem; font-weight: 400; color: var(--muted);
}
.unit-head.other { color: var(--muted); font-style: italic; }
.unit-head + .parts { margin-top: 0; }

/* ---------- back navigation ---------- */
.backlink {
  display: inline-flex; align-items: baseline; gap: .45rem;
  font-size: var(--step--1); color: var(--muted);
  text-decoration: none; margin-bottom: 1.1rem;
  padding: .3rem .7rem .3rem .55rem;
  border: 1px solid var(--line); border-radius: 99px;
  background: var(--surface);
}
.backlink:hover { border-color: var(--sky); color: var(--accent); }
.backlink .gloss { font-size: .92em; }

/* The header breadcrumb is supporting navigation, not the main way back. */
.crumbs { max-width: 100%; }
@media (max-width: 640px) {
  .crumbs { margin-left: 0; width: 100%; font-size: .78rem; }
}

/* ---------- links back into the wiki ---------- */
.wiki-links { display: flex; flex-direction: column; gap: .5rem; }
.wiki-links.row { flex-direction: row; flex-wrap: wrap; }
.wiki-link {
  display: flex; align-items: center; justify-content: space-between; gap: .75rem;
  border: 1px solid var(--line); border-radius: 8px;
  padding: .6rem .8rem; font-size: var(--step--1);
  text-decoration: none; color: var(--ink-2); background: var(--surface);
  transition: border-color .15s ease, background .15s ease;
}
.wiki-link:hover { border-color: var(--sky); color: var(--accent); }
.wiki-link .arrow { opacity: .5; }
.wiki-link:hover .arrow { opacity: 1; }
.wiki-link.primary {
  background: var(--fill); border-color: var(--fill); color: var(--fill-ink); font-weight: 600;
}
.wiki-link.primary:hover { background: var(--sky); border-color: var(--sky); color: #06222F; }
.wiki-cta { border-top: 1px solid var(--line); padding-top: 1.6rem; }
