/* ==========================================================================
   gihanmunasinghe.lk: shared system ("paperback series")
   Every page is a volume in one series. A page picks its series colour with
   a body class (series-blue | series-orange | series-green | series-red);
   everything else is shared ink, paper and type.
   ========================================================================== */

/* ---------- fonts (self-hosted, variable) ---------- */
@font-face {
  font-family: "Archivo";
  font-style: normal;
  font-weight: 100 900;
  font-stretch: 62% 125%;
  font-display: swap;
  src: url("/assets/fonts/archivo-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Archivo";
  font-style: normal;
  font-weight: 100 900;
  font-stretch: 62% 125%;
  font-display: swap;
  src: url("/assets/fonts/archivo-latin-ext.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C4, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: "Literata";
  font-style: normal;
  font-weight: 200 900;
  font-display: swap;
  src: url("/assets/fonts/literata-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Literata";
  font-style: normal;
  font-weight: 200 900;
  font-display: swap;
  src: url("/assets/fonts/literata-latin-ext.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C4, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: "Literata";
  font-style: italic;
  font-weight: 200 900;
  font-display: swap;
  src: url("/assets/fonts/literata-italic-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

/* ---------- tokens: light (default) ---------- */
:root {
  color-scheme: light;

  /* neutrals: cool paper, blue-black ink */
  --paper: #f3f5f7;
  --paper-2: #e5e8ed;
  --paper-3: #d6dbe2;
  --ink: #14161b;
  --ink-2: #474c56;
  --ink-3: #5c626d;
  --rule: rgba(20, 22, 27, 0.16);
  --rule-strong: rgba(20, 22, 27, 0.72);
  --plank: #14161b; /* the shelf books stand on */
  --shade: 18, 26, 54; /* rgb triplet for tinted shadows */

  /* the series: flat print colours */
  --blue: #2346a6;
  --blue-text: #2346a6;
  --orange: #ee6a1f;
  --orange-text: #b04a10;
  --green: #0f6b47;
  --green-text: #0f6b47;
  --red: #c41f45;
  --red-text: #c41f45;
  --on-dark-band: #f3f5f7; /* type on blue, green, red */
  --on-light-band: #14161b; /* type on orange */

  /* state */
  --ok: #0f6b47;
  --danger: #b3261e;

  /* type */
  --font-sans: "Archivo", "Helvetica Neue", Arial, system-ui, sans-serif;
  --font-serif: "Literata", "Iowan Old Style", Georgia, "Noto Serif", serif;
  --font-mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;

  /* rhythm */
  --wrap: 1240px;
  --gutter: clamp(16px, 4vw, 40px);
  --nav-h: 64px;
  --section: clamp(4.5rem, 9vw, 8rem);
  --r: 2px;
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);

  /* default series = blue; pages override with a body class */
  --series: var(--blue);
  --series-text: var(--blue-text);
  --on-series: var(--on-dark-band);
}

/* ---------- tokens: dark ---------- */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --paper: #111318;
    --paper-2: #191c22;
    --paper-3: #23272f;
    --ink: #eceef2;
    --ink-2: #b4b8c0;
    --ink-3: #959ba6;
    --rule: rgba(236, 238, 242, 0.15);
    --rule-strong: rgba(236, 238, 242, 0.7);
    --plank: #2c313a;
    --shade: 0, 0, 0;
    --blue: #2a4fb5;
    --blue-text: #8eaaff;
    --orange-text: #ff9b5e;
    --green-text: #5fd3a0;
    --red-text: #ff7d97;
    --on-dark-band: #eef1f5;
    --on-light-band: #111318;
    --ok: #5fd3a0;
    --danger: #ff8a80;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --paper: #111318;
  --paper-2: #191c22;
  --paper-3: #23272f;
  --ink: #eceef2;
  --ink-2: #b4b8c0;
  --ink-3: #959ba6;
  --rule: rgba(236, 238, 242, 0.15);
  --rule-strong: rgba(236, 238, 242, 0.7);
  --plank: #2c313a;
  --shade: 0, 0, 0;
  --blue: #2a4fb5;
  --blue-text: #8eaaff;
  --orange-text: #ff9b5e;
  --green-text: #5fd3a0;
  --red-text: #ff7d97;
  --on-dark-band: #eef1f5;
  --on-light-band: #111318;
  --ok: #5fd3a0;
  --danger: #ff8a80;
}

.series-blue   { --series: var(--blue);   --series-text: var(--blue-text);   --on-series: var(--on-dark-band); }
.series-orange { --series: var(--orange); --series-text: var(--orange-text); --on-series: var(--on-light-band); }
.series-green  { --series: var(--green);  --series-text: var(--green-text);  --on-series: var(--on-dark-band); }
.series-red    { --series: var(--red);    --series-text: var(--red-text);    --on-series: var(--on-dark-band); }
/* hover moves away from the type colour: darker under paper type, lighter under ink type (orange) */
:root, .series-blue, .series-green, .series-red { --series-hover: color-mix(in oklab, var(--series) 84%, #000); }
.series-orange { --series-hover: color-mix(in oklab, var(--series) 82%, #fff); }

/* ---------- base ---------- */
*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; padding: 0; }
html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-padding-top: calc(var(--nav-h) + 16px);
  background: var(--paper);
  scrollbar-color: var(--rule-strong) var(--paper-2);
}
@media (prefers-reduced-motion: no-preference) {
  html { scroll-behavior: smooth; }
  @view-transition { navigation: auto; }
}
body {
  min-height: 100dvh;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 1rem;
  line-height: 1.55;
  font-kerning: normal;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  overflow-x: clip;
}
img, svg, video { display: block; max-width: 100%; }
img { height: auto; }
a { color: inherit; text-underline-offset: 0.18em; text-decoration-thickness: 1px; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; }
::selection { background: var(--series); color: var(--on-series); }
:focus-visible { outline: 2px solid var(--series-text); outline-offset: 3px; }
.band :focus-visible, .masthead :focus-visible { outline-color: var(--on-series); }

.wrap { width: 100%; max-width: calc(var(--wrap) + 2 * var(--gutter)); margin-inline: auto; padding-inline: var(--gutter); }
[hidden] { display: none !important; }
.visually-hidden {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.skip {
  position: absolute; left: var(--gutter); top: -100px; z-index: 100;
  background: var(--ink); color: var(--paper); padding: 0.7rem 1rem; font-weight: 650; text-decoration: none;
  border-radius: var(--r);
}
.skip:focus { top: 12px; }

.icon { width: 1.15em; height: 1.15em; flex: none; fill: currentColor; }

/* ---------- type ---------- */
.display, h1, h2, h3, h4 { font-family: var(--font-sans); color: inherit; text-wrap: balance; }
h1 { font-weight: 800; font-stretch: 108%; letter-spacing: -0.025em; line-height: 0.98; }
h2 { font-size: clamp(2rem, 4.2vw, 3.25rem); font-weight: 780; font-stretch: 104%; letter-spacing: -0.02em; line-height: 1.02; }
h3 { font-size: clamp(1.2rem, 1.8vw, 1.45rem); font-weight: 680; letter-spacing: -0.01em; line-height: 1.2; }
h4 { font-size: 1.05rem; font-weight: 680; line-height: 1.3; }

.prose, .lede, .serif { font-family: var(--font-serif); font-optical-sizing: auto; }
.lede { font-size: clamp(1.08rem, 1.4vw, 1.22rem); line-height: 1.6; color: var(--ink-2); max-width: 60ch; text-wrap: pretty; }
.prose { font-size: 1.0625rem; line-height: 1.72; color: var(--ink-2); text-wrap: pretty; }
.prose p + p { margin-top: 1em; }
.prose strong { color: var(--ink); font-weight: 650; }
.meta { font-size: 0.875rem; color: var(--ink-3); font-variant-numeric: tabular-nums; }
.num { font-variant-numeric: tabular-nums lining-nums; }

/* ---------- the publisher's mark ---------- */
.roundel {
  display: inline-grid; place-items: center;
  min-width: 4.6em; height: 2.3em; padding: 0 0.85em;
  border: 1.5px solid currentColor; border-radius: 50%;
  font-family: var(--font-sans); font-weight: 800; font-stretch: 100%;
  letter-spacing: -0.01em; line-height: 1; text-decoration: none; white-space: nowrap;
}

/* ---------- bands (flat series colour fields) ---------- */
.band { background: var(--series); color: var(--on-series); }
.band .lede, .band .prose, .band .meta { color: inherit; }
.band .lede, .band .prose { opacity: 0.92; }

/* ---------- masthead (sticky series band carrying the nav) ---------- */
.masthead {
  position: sticky; top: 0; z-index: 50;
  background: var(--series); color: var(--on-series);
}
.masthead-in { display: flex; align-items: center; gap: 1.25rem; height: var(--nav-h); }
.masthead .roundel { font-size: 0.95rem; }
.nav { display: flex; align-items: center; gap: clamp(0.9rem, 1.6vw, 1.6rem); margin-left: auto; }
.nav a {
  font-size: 0.95rem; font-weight: 560; text-decoration: none; padding: 0.35rem 0;
  border-bottom: 1.5px solid transparent; transition: border-color 0.2s;
}
.nav a:hover, .nav a[aria-current="page"] { border-bottom-color: currentColor; }
.masthead-actions { display: flex; align-items: center; gap: 0.6rem; }
.nav + .masthead-actions { margin-left: clamp(0.4rem, 1.2vw, 1.2rem); }
.icon-btn {
  display: inline-grid; place-items: center; width: 40px; height: 40px;
  border: 1.5px solid transparent; border-radius: var(--r); color: inherit;
  transition: border-color 0.2s, background-color 0.2s;
}
.icon-btn:hover { border-color: currentColor; }
.icon-btn .icon { width: 20px; height: 20px; }
.menu-btn { display: none; }
.menu-panel { display: none; }

@media (max-width: 960px) {
  :root { --nav-h: 58px; }
  .masthead-in { gap: 0.75rem; }
  .nav { display: none; }
  .masthead-actions, .nav + .masthead-actions { margin-left: auto; }
  .masthead-actions .btn-cta { display: none; }
  .menu-btn { display: inline-flex; gap: 0.45rem; width: auto; padding: 0 0.7rem; font-weight: 600; font-size: 0.95rem; }
  .menu-panel {
    position: absolute; left: 0; right: 0; top: 100%;
    background: var(--series); color: var(--on-series);
    border-top: 1px solid color-mix(in srgb, var(--on-series) 25%, transparent);
    box-shadow: 0 24px 40px -24px rgba(var(--shade), 0.5);
    padding: 0.5rem var(--gutter) 1.4rem;
  }
  .menu-panel.open { display: block; }
  .menu-panel a {
    display: flex; align-items: center; justify-content: space-between;
    font-size: 1.35rem; font-weight: 700; font-stretch: 104%; letter-spacing: -0.01em;
    text-decoration: none; padding: 0.85rem 0;
    border-bottom: 1px solid color-mix(in srgb, var(--on-series) 22%, transparent);
  }
  .menu-panel a:last-child { border-bottom: 0; }
}

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.55rem;
  min-height: 48px; padding: 0.75rem 1.3rem;
  font-family: var(--font-sans); font-size: 0.98rem; font-weight: 650; line-height: 1.1; white-space: nowrap;
  text-decoration: none; border-radius: var(--r); border: 1.5px solid transparent;
  transition: background-color 0.2s, color 0.2s, border-color 0.2s, transform 0.15s var(--ease-out), box-shadow 0.2s;
}
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.5; cursor: not-allowed; }
.btn .icon { width: 1.15em; height: 1.15em; }
.btn-primary { background: var(--series); color: var(--on-series); border-color: var(--series); }
.btn-primary:hover:not(:disabled) { background: var(--series-hover); border-color: var(--series-hover); }
.btn-ghost { background: transparent; color: var(--ink); border-color: var(--rule-strong); }
.btn-ghost:hover:not(:disabled) { background: var(--paper-2); border-color: var(--ink); }
.btn-sm { min-height: 40px; padding: 0.5rem 0.95rem; font-size: 0.9rem; }
/* buttons sitting on a series band */
.btn-paper { background: var(--on-series); color: var(--series); border-color: var(--on-series); }
.btn-paper:hover:not(:disabled) { background: color-mix(in oklab, var(--on-series) 86%, var(--series)); }
.btn-outline-band { background: transparent; color: var(--on-series); border-color: color-mix(in srgb, var(--on-series) 70%, transparent); }
.btn-outline-band:hover:not(:disabled) { border-color: var(--on-series); background: color-mix(in srgb, var(--on-series) 10%, transparent); }
.btn-cta { min-height: 40px; padding: 0.5rem 1rem; font-size: 0.92rem; }

.text-link {
  display: inline-flex; align-items: center; gap: 0.4rem;
  color: var(--series-text); font-weight: 650; text-decoration: none;
  border-bottom: 1.5px solid currentColor; padding-bottom: 0.1rem;
}
.text-link .icon { transition: transform 0.25s var(--ease-out); }
.text-link:hover .icon { transform: translateX(3px); }

/* ---------- sections ---------- */
.section { padding-block: var(--section); }
.section-head { margin-bottom: clamp(2rem, 4vw, 3.25rem); max-width: 46rem; }
.section-head h2 + .lede { margin-top: 1rem; }

/* ---------- tabs / filters ---------- */
.tabs { display: flex; flex-wrap: wrap; gap: 0.25rem 1.4rem; border-bottom: 1px solid var(--rule); }
.tab {
  position: relative; padding: 0.7rem 0; font-size: 0.95rem; font-weight: 600; color: var(--ink-3);
  border-bottom: 3px solid transparent; margin-bottom: -1px; transition: color 0.2s, border-color 0.2s;
}
.tab:hover { color: var(--ink); }
.tab[aria-pressed="true"], .tab.on, .tab.active { color: var(--ink); border-bottom-color: var(--series); }

/* ---------- forms ---------- */
.field { display: grid; gap: 0.4rem; }
.field label, .field .field-label { font-size: 0.875rem; font-weight: 650; color: var(--ink); }
.field .hint { font-size: 0.8125rem; color: var(--ink-3); }
.input, .field input, .field select, .field textarea {
  width: 100%; min-height: 48px; padding: 0.7rem 0.9rem;
  font-family: var(--font-sans); font-size: 1rem; color: var(--ink);
  background: var(--paper); border: 1.5px solid var(--rule-strong); border-radius: var(--r);
  transition: border-color 0.2s, box-shadow 0.2s;
}
.field textarea { min-height: 120px; resize: vertical; line-height: 1.5; }
.field select { appearance: none; -webkit-appearance: none; padding-right: 2.4rem;
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%), linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: calc(100% - 18px) 52%, calc(100% - 13px) 52%; background-size: 5px 5px; background-repeat: no-repeat; }
.input::placeholder, .field input::placeholder, .field textarea::placeholder { color: var(--ink-3); opacity: 1; }
.input:focus, .field input:focus, .field select:focus, .field textarea:focus {
  outline: none; border-color: var(--series-text); box-shadow: 0 0 0 3px color-mix(in srgb, var(--series) 28%, transparent);
}
.field [aria-invalid="true"], .field [aria-invalid="true"]:focus { border-color: var(--danger); }
.field [aria-invalid="true"]:focus { box-shadow: 0 0 0 3px color-mix(in srgb, var(--danger) 24%, transparent); }
.field .error { font-size: 0.8125rem; color: var(--danger); font-weight: 600; }
.hp { position: absolute !important; left: -9999px !important; width: 1px; height: 1px; overflow: hidden; }

/* ---------- sheet (dialog panel) ---------- */
.scrim {
  position: fixed; inset: 0; z-index: 70; display: none; overflow-y: auto;
  background: rgba(10, 12, 18, 0.62); padding: clamp(0px, 3vw, 2rem);
}
.scrim.open { display: block; }
.sheet {
  position: relative; max-width: 880px; margin: 0 auto; background: var(--paper); color: var(--ink);
  border-radius: var(--r); box-shadow: 0 40px 80px -30px rgba(var(--shade), 0.6);
}
.sheet-band { height: 14px; background: var(--series); border-radius: var(--r) var(--r) 0 0; }
.sheet-body { padding: clamp(1.25rem, 4vw, 2.5rem); }
.sheet-close { position: absolute; top: 26px; right: 14px; color: var(--ink); }
.sheet-close:hover { border-color: var(--rule-strong); }
@media (prefers-reduced-motion: no-preference) {
  .scrim.open .sheet { animation: sheet-in 0.45s var(--ease-out) both; }
}
@keyframes sheet-in { from { transform: translateY(18px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 1.25rem; z-index: 90; transform: translateX(-50%);
  width: max-content; max-width: min(92vw, 440px); display: none; align-items: center; gap: 0.6rem;
  pointer-events: none;
  background: var(--ink); color: var(--paper); padding: 0.85rem 1.15rem; border-radius: var(--r);
  font-size: 0.95rem; font-weight: 550; box-shadow: 0 18px 40px -18px rgba(var(--shade), 0.6);
}
.toast.show { display: flex; }
.toast.err { background: var(--danger); color: #fff; }
:root[data-theme="dark"] .toast.err { color: #111318; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .toast.err { color: #111318; } }

/* ---------- empty / loading notes ---------- */
.note-box {
  padding: 2.5rem 1.5rem; text-align: center; color: var(--ink-2);
  border: 1.5px dashed var(--rule-strong); border-radius: var(--r); font-family: var(--font-serif);
}

/* ---------- colophon (footer) ---------- */
.colophon { background: var(--paper-2); color: var(--ink-2); border-top: 10px solid var(--series); }
.colophon-in {
  display: grid; gap: 2rem; padding-block: clamp(2.5rem, 5vw, 3.5rem);
  grid-template-columns: 1.2fr 1fr 1fr; align-items: start;
}
.colophon .roundel { color: var(--ink); font-size: 1rem; }
.colophon p { font-size: 0.9rem; margin-top: 0.9rem; }
.colophon h2 { font-size: 0.875rem; font-weight: 700; letter-spacing: 0; color: var(--ink); margin-bottom: 0.7rem; }
.colophon ul { list-style: none; display: grid; gap: 0.45rem; }
.colophon a { text-decoration: none; font-size: 0.95rem; }
.colophon a:hover { color: var(--ink); text-decoration: underline; }
.social { display: flex; flex-wrap: wrap; gap: 0.35rem; }
.social a {
  display: inline-grid; place-items: center; width: 42px; height: 42px; color: var(--ink);
  border: 1.5px solid var(--rule); border-radius: var(--r); transition: border-color 0.2s, background-color 0.2s;
}
.social a:hover { border-color: var(--ink); background: var(--paper); }
.social .icon { width: 20px; height: 20px; }
.colophon-base {
  display: flex; flex-wrap: wrap; justify-content: space-between; gap: 0.5rem 1.5rem;
  border-top: 1px solid var(--rule); padding-block: 1.1rem 1.6rem; font-size: 0.85rem; color: var(--ink-3);
}
@media (max-width: 820px) { .colophon-in { grid-template-columns: 1fr 1fr; } .colophon-in > :first-child { grid-column: 1 / -1; } }

/* ---------- motion safety ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}
