/* ==========================================================================
   Saptarishi Dhanuka — personal site
   Layout borrowed from dsconnelly.github.io (two-column, Karla + Palatino).
   Page structure and content rhythm borrowed from huyenchip.com.
   ========================================================================== */

/* --- palette -------------------------------------------------------------- */

:root {
  --bg: #faf9f6;
  --fg: #1a1a1a;
  --muted: #7f7979;
  --accent: #5d92ca;
  --rule: #dcd8d0;
  --mark: #efede6;

  --sans: "Karla", -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  --serif: "Palatino", "Palatino Linotype", "Book Antiqua", "URW Palladio L", Georgia, serif;

  /* theme switch — circuit closed, lamp burning */
  --ts-trace: #c2913f;
  --ts-blade: 0deg;
  --ts-spark: 1;
  --ts-sun-fill: #eaa93f;
  --ts-sun-stroke: #cf8f2a;
  --ts-sun-glow: 0.55;
  --ts-moon-fill: none;
  --ts-moon-stroke: #b3ada1;
  --ts-moon-glow: 0;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15161a;
    --fg: #e6e4df;
    --muted: #9b968d;
    --accent: #82b1e8;
    --rule: #2e3037;
    --mark: #22242a;

    /* theme switch — contact broken, lamp out, moon up */
    --ts-trace: #4a4d55;
    --ts-blade: -30deg;
    --ts-spark: 0;
    --ts-sun-fill: none;
    --ts-sun-stroke: #5e626b;
    --ts-sun-glow: 0;
    --ts-moon-fill: #ccd8ea;
    --ts-moon-stroke: #ccd8ea;
    --ts-moon-glow: 0.5;
  }
}

:root[data-theme="dark"] {
  --bg: #15161a;
  --fg: #e6e4df;
  --muted: #9b968d;
  --accent: #82b1e8;
  --rule: #2e3037;
  --mark: #22242a;

  /* theme switch — contact broken, lamp out, moon up */
  --ts-trace: #4a4d55;
  --ts-blade: -30deg;
  --ts-spark: 0;
  --ts-sun-fill: none;
  --ts-sun-stroke: #5e626b;
  --ts-sun-glow: 0;
  --ts-moon-fill: #ccd8ea;
  --ts-moon-stroke: #ccd8ea;
  --ts-moon-glow: 0.5;
}

/* --- base ----------------------------------------------------------------- */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background-color: var(--bg);
  color: var(--fg);
  font-family: var(--serif);
  font-size: 17.5px;
  line-height: 1.6;
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

hr {
  border: 0;
  border-top: 1px solid var(--rule);
  margin: 2.2rem 0;
}

code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.86em;
  background: var(--mark);
  padding: 0.1em 0.35em;
  border-radius: 3px;
}

/* --- shell ---------------------------------------------------------------- */

.page {
  max-width: 980px;
  margin: 0 auto;
  padding: 4.2rem 24px 4rem;
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  gap: 48px;
  align-items: start;
}

/* --- left rail ------------------------------------------------------------ */

.rail {
  position: sticky;
  top: 4.2rem;
  font-family: var(--sans);
  text-align: right;
}

.rail__portrait {
  display: block;
  font-size: 0;
  line-height: 0;
}

.rail__portrait img {
  width: 100%;
  height: auto;
  border-radius: 2px;
  border: 1px solid var(--rule);
  filter: saturate(0.92);
}

.rail__name {
  font-family: var(--sans);
  font-size: 1.55rem;
  font-weight: 400;
  line-height: 1.2;
  margin: 0.85rem 0 0;
  letter-spacing: -0.01em;
}

.rail__role,
.rail__where,
.rail__email {
  font-size: 0.86rem;
  color: var(--muted);
  margin: 0.3rem 0 0;
}

.rail__email {
  word-break: break-word;
}

/* --- theme switch: a circuit that closes onto a lamp ---------------------- */

.tswitch {
  position: fixed;
  top: 16px;
  right: 18px;
  z-index: 20;
  display: block;
  padding: 3px 8px;
  line-height: 0;
  background: var(--bg);
  border: 1px solid var(--rule);
  border-radius: 999px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.tswitch[hidden] {
  display: none;
}

.tswitch:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.tswitch__art {
  display: block;
  width: 132px;
  height: 40px;
}

/* traces */

.tsw-trace {
  fill: none;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.tsw-trace {
  stroke: var(--ts-trace);
  transition: stroke 0.3s ease;
}

.tsw-pad {
  fill: var(--ts-trace);
  transition: fill 0.3s ease;
}

/* the switch itself: two terminals and a blade hinged on the left one */

.tsw-term {
  fill: var(--bg);
  stroke: var(--ts-trace);
  stroke-width: 1.5;
  transition:
    fill 0.3s ease,
    stroke 0.3s ease;
}

.tsw-pivot {
  fill: var(--ts-trace);
  transition: fill 0.3s ease;
}

.tsw-blade {
  transform: rotate(var(--ts-blade));
  transform-box: view-box;
  transform-origin: 58px 26px;
  transition: transform 0.42s cubic-bezier(0.34, 1.34, 0.64, 1);
}

.tsw-blade-body {
  fill: none;
  stroke-width: 2.2;
  stroke-linecap: round;
}

.tsw-blade-body {
  stroke: var(--ts-trace);
  transition: stroke 0.3s ease;
}

/* the contact arcing over when the switch closes */

.tsw-spark {
  fill: #f6cf85;
  opacity: var(--ts-spark);
  transition: opacity 0.3s ease;
}

/* the lamp */

.tsw-sun-body {
  fill: var(--ts-sun-fill);
  stroke: var(--ts-sun-stroke);
  stroke-width: 1.4;
  transition:
    fill 0.3s ease,
    stroke 0.3s ease;
}

.tsw-sun-rays {
  fill: none;
  stroke: var(--ts-sun-stroke);
  stroke-width: 1.5;
  stroke-linecap: round;
  transition: stroke 0.3s ease;
}

.tsw-sun-glow {
  fill: #eaa93f;
  opacity: var(--ts-sun-glow);
  transition: opacity 0.35s ease;
}

/* the moon, which only gets a turn once the lamp is out */

.tsw-moon-body {
  fill: var(--ts-moon-fill);
  stroke: var(--ts-moon-stroke);
  /* the path carries a 0.75 transform, so this lands at ~1.35 user units */
  stroke-width: 1.8;
  stroke-linejoin: round;
  transition:
    fill 0.3s ease,
    stroke 0.3s ease;
}

.tsw-moon-glow {
  fill: #cfdcf0;
  opacity: var(--ts-moon-glow);
  transition: opacity 0.35s ease;
}

@media (prefers-reduced-motion: reduce) {
  .tsw-blade,
  .tsw-blade-body,
  .tsw-trace,
  .tsw-pad,
  .tsw-term,
  .tsw-pivot,
  .tsw-spark,
  .tsw-sun-body,
  .tsw-sun-rays,
  .tsw-sun-glow,
  .tsw-moon-body,
  .tsw-moon-glow {
    transition: none;
  }
}

/* --- right column / nav --------------------------------------------------- */

.main {
  min-width: 0;
}

.nav {
  display: flex;
  flex-wrap: wrap;
  gap: 1.4rem;
  font-family: var(--sans);
  font-size: 1.05rem;
  padding-bottom: 0.55rem;
  border-bottom: 1px solid var(--fg);
  margin-bottom: 2.1rem;
}

.nav a {
  color: var(--accent);
}

.nav a[aria-current="page"] {
  color: var(--fg);
  text-decoration: none;
  cursor: default;
}

.nav a[aria-current="page"]:hover {
  text-decoration: none;
}

/* --- content -------------------------------------------------------------- */

.main h1,
.main h2,
.main h3 {
  font-family: var(--sans);
  font-weight: 400;
  line-height: 1.25;
}

.main h1 {
  font-size: 1.6rem;
  margin: 0 0 1.2rem;
}

.main h2 {
  font-size: 1.22rem;
  margin: 2.4rem 0 0.8rem;
}

.main h3 {
  font-size: 1.02rem;
  margin: 1.6rem 0 0.4rem;
}

.main p {
  margin: 0 0 1.05rem;
}

.prose p,
.prose li {
  text-align: justify;
  hyphens: auto;
}

.prose ul,
.prose ol {
  padding-left: 1.2rem;
}

.prose li {
  margin-bottom: 0.4rem;
}

.lede {
  color: var(--muted);
  font-family: var(--sans);
  font-size: 0.95rem;
  text-align: left;
  margin-bottom: 2rem;
}

blockquote {
  margin: 1.4rem 0;
  padding-left: 1rem;
  border-left: 2px solid var(--rule);
  color: var(--muted);
}

blockquote p {
  margin: 0;
}

/* --- listings (papers) --------------------------------------------- */

.list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.list > li {
  padding: 1.1rem 0;
  border-bottom: 1px solid var(--rule);
}

.list > li:first-child,
.list > li.is-first {
  padding-top: 0;
}

.list > li[hidden] {
  display: none;
}

/* --- tag filter (blog) ---------------------------------------------------- */

.tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin: 0 0 1.9rem;
}

.tags[hidden] {
  display: none;
}

.tags__chip {
  font-family: var(--sans);
  font-size: 0.78rem;
  letter-spacing: 0.03em;
  color: var(--muted);
  background: none;
  border: 1px solid var(--rule);
  border-radius: 999px;
  padding: 0.25em 0.72em;
  cursor: pointer;
  transition:
    color 0.2s ease,
    background-color 0.2s ease,
    border-color 0.2s ease;
}

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

.tags__chip:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.tags__chip[aria-pressed="true"] {
  color: var(--bg);
  background: var(--fg);
  border-color: var(--fg);
}

.tags__n {
  margin-left: 0.4em;
  opacity: 0.55;
  font-variant-numeric: tabular-nums;
}

@media (prefers-reduced-motion: reduce) {
  .tags__chip {
    transition: none;
  }
}

/* --- cv ------------------------------------------------------------------- */

.cv-item {
  margin-bottom: 1.5rem;
}

.cv-item__head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1rem;
  font-family: var(--sans);
}

.cv-item__title {
  font-size: 1.02rem;
  margin: 0;
  font-weight: 400;
}

.cv-item__dates {
  font-size: 0.8rem;
  color: var(--muted);
  white-space: nowrap;
}

.cv-item__sub {
  font-family: var(--sans);
  font-size: 0.86rem;
  color: var(--muted);
  margin: 0.1rem 0 0.45rem;
}

.cv-item ul {
  margin: 0;
  padding-left: 1.1rem;
  font-size: 0.95rem;
}

.cv-item li {
  margin-bottom: 0.25rem;
  text-align: left;
}

.kv {
  font-size: 0.95rem;
  margin-bottom: 0.5rem;
}

.kv strong {
  font-family: var(--sans);
  font-weight: 400;
  font-size: 0.86rem;
  color: var(--muted);
  display: block;
}

/* --- footer --------------------------------------------------------------- */

.foot {
  margin-top: 3.5rem;
  padding-top: 1.1rem;
  border-top: 1px solid var(--rule);
  font-family: var(--sans);
  font-size: 0.83rem;
  color: var(--muted);
  display: flex;
  flex-wrap: wrap;
  gap: 1.1rem;
  align-items: baseline;
}

.foot .spacer {
  margin-left: auto;
}

.foot a {
  cursor: pointer;
}

/* --- responsive ----------------------------------------------------------- */

@media (max-width: 760px) {
  .page {
    grid-template-columns: minmax(0, 1fr);
    gap: 2rem;
    padding-top: 4rem;
  }

  .rail {
    position: static;
    text-align: left;
    display: grid;
    grid-template-columns: 96px minmax(0, 1fr);
    gap: 1rem;
    align-items: center;
  }

  .rail__portrait {
    grid-row: span 5;
  }

  .rail__portrait img {
    border-radius: 999px;
    aspect-ratio: 1;
    object-fit: cover;
  }

  .rail__name {
    margin-top: 0;
    font-size: 1.35rem;
  }

  .prose p,
  .prose li,
  details p {
    text-align: left;
    hyphens: manual;
  }

  .nav {
    gap: 1.1rem;
    font-size: 1rem;
  }

  .tswitch {
    top: 10px;
    right: 12px;
    padding: 2px 6px;
  }

  .tswitch__art {
    width: 104px;
    height: 32px;
  }

  .cv-item__head {
    display: block;
  }

  .cv-item__dates {
    display: block;
  }
}

/* --- writing & creative courses ------------------------------------------- */

.writing-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin: 1.5rem 0 2rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--rule);
}

.writing-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.filter-btn {
  font-family: var(--sans);
  font-size: 0.82rem;
  padding: 0.32rem 0.75rem;
  background: transparent;
  border: 1px solid var(--rule);
  border-radius: 999px;
  color: var(--muted);
  cursor: pointer;
  transition: all 0.2s ease;
}

.filter-btn:hover {
  border-color: var(--fg);
  color: var(--fg);
}

.filter-btn.is-active {
  background: var(--fg);
  color: var(--bg);
  border-color: var(--fg);
}

.filter-btn .count {
  font-size: 0.75rem;
  opacity: 0.75;
  margin-left: 0.25rem;
}

.spotlight-btn {
  font-family: var(--sans);
  font-size: 0.82rem;
  padding: 0.32rem 0.85rem;
  background: var(--mark);
  border: 1px solid var(--rule);
  border-radius: 999px;
  color: var(--fg);
  cursor: pointer;
  transition: all 0.2s ease;
}

.spotlight-btn:hover {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.writing-grid {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.writing-card {
  border: 1px solid var(--rule);
  border-radius: 4px;
  padding: 1.2rem 1.4rem;
  background: var(--bg);
  transition: border-color 0.2s ease, transform 0.2s ease, box-shadow 0.25s ease;
  position: relative;
}

.writing-card:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
}

.writing-card.is-spotlighted {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(93, 146, 202, 0.4);
  transform: translateY(-3px);
}

.writing-card.is-hidden {
  display: none;
}

.writing-card__header {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.5rem;
  margin-bottom: 0.45rem;
  font-family: var(--sans);
  font-size: 0.8rem;
}

.writing-card__badge {
  color: var(--accent);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-size: 0.76rem;
}

.writing-card__context {
  color: var(--muted);
}

.writing-card__title {
  margin: 0 0 0.4rem;
  font-size: 1.15rem;
  line-height: 1.3;
}

.writing-card__teaser {
  margin: 0 0 0.85rem;
  color: var(--fg);
  font-size: 0.95rem;
  line-height: 1.5;
}

.writing-card__drawer {
  border-top: 1px dashed var(--rule);
  padding-top: 0.65rem;
  margin-top: 0.5rem;
}

.writing-card__toggle {
  font-family: var(--sans);
  font-size: 0.84rem;
  color: var(--accent);
  cursor: pointer;
  outline: none;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  user-select: none;
}

.writing-card__toggle:hover {
  text-decoration: underline;
}

.writing-card__content {
  padding-top: 0.8rem;
  font-size: 0.94rem;
  color: var(--fg);
  line-height: 1.6;
}

.writing-card__content p {
  margin: 0 0 0.75rem;
}

.writing-card__meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  margin-top: 0.6rem;
}

.writing-tag {
  display: inline-block;
  font-family: var(--sans);
  font-size: 0.74rem;
  background: var(--mark);
  color: var(--muted);
  padding: 0.15rem 0.5rem;
  border-radius: 3px;
  border: 1px solid var(--rule);
}

.writing-tag--stub {
  color: var(--accent);
  border-color: var(--accent);
}

/* --- print (mostly for the cv) -------------------------------------------- */

@media print {
  .rail__portrait,
  .tswitch,
  .nav,
  .foot {
    display: none;
  }

  .page {
    display: block;
    max-width: none;
    padding: 0;
  }

  body {
    font-size: 10.5pt;
    color: #000;
    background: #fff;
  }

  a {
    color: #000;
  }
}
