/* ==========================================================================
   Pulathisi, personal landing page
   Plain CSS, no build step. Sections: tokens, base, layout, sections,
   handshake diagram, responsive, reduced motion.
   ========================================================================== */

/* --- 1. Tokens ------------------------------------------------------------
   Light palette is the default. The dark block below only swaps colors. */
:root {
  --paper: #ecebe3;   /* page background: warm paper, not white */
  --paper-2: #e4e2d8; /* filled areas such as the diagram check box and code blocks */
  --ink: #181a1e;     /* main text */
  --muted: #474c54;   /* secondary text, labels */
  --rule: #c9c6bb;    /* section dividers, lane lines */
  --accent: #1d5a55;  /* links, encrypted messages, active caption */

  --font-body: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;

  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #121416;
    --paper-2: #1b1e21;
    --ink: #e4e2dc;
    --muted: #a3a8af;
    --rule: #2c3035;
    --accent: #7cc2b8;
    color-scheme: dark;
  }
}

/* --- 2. Base --------------------------------------------------------------- */
*,
*::before,
*::after {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 1rem;
  line-height: 1.6;
}

img {
  max-width: 100%;
  display: block;
}

a {
  color: var(--accent);
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}

a:hover {
  text-decoration-thickness: 2px;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
  border-radius: 2px;
}

.skip-link {
  position: absolute;
  left: 16px;
  top: -100px;
  background: var(--ink);
  color: var(--paper);
  padding: 8px 12px;
  z-index: 10;
}

.skip-link:focus {
  top: 16px;
}

h1,
h2,
h3 {
  line-height: 1.15;
  margin: 0;
  font-weight: 650;
}

p {
  margin: 0 0 1em;
}

/* --- 3. Page layout -------------------------------------------------------- */
/* Side padding is 24px at every width, which keeps the gutter above 16px. */
.page {
  max-width: 1040px;
  margin: 0 auto;
  padding: 56px 24px 32px;
}

/* Header: text on the left, portrait on the right, aligned to the bottom. */
.intro {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 200px);
  gap: 48px;
  align-items: end;
  padding-bottom: 56px;
}

.role,
.meta,
.stack,
.updated,
.link-key,
.msg-label,
.lane-label,
.check-label,
.work-num {
  font-family: var(--font-mono);
  font-size: 0.875rem;
  letter-spacing: 0.01em;
}

.role {
  color: var(--accent);
  margin-bottom: 0.25em;
}

.meta {
  color: var(--muted);
  margin-bottom: 1.5rem;
}

h1 {
  font-size: clamp(3rem, 9vw, 6.5rem);
  font-weight: 700;
  letter-spacing: -0.035em;
  line-height: 0.95;
  margin-bottom: 0.4em;
}

.lede {
  font-size: clamp(1.15rem, 2.2vw, 1.35rem);
  line-height: 1.5;
  max-width: 36ch;
  margin-bottom: 1.75rem;
}

.open-to {
  font-weight: 600;
  font-size: 1rem;
  line-height: 1.5;
  max-width: 40ch;
  margin-bottom: 0.75rem;
}

.cv-link a {
  font-weight: 600;
}

.cv-link {
  color: var(--muted);
}

/* Portrait: fixed square box. Any photo fills it with object-fit: cover. */
.portrait {
  margin: 0;
}

/* Circular crop. The photo's dark background reads as an avatar, not a hard-edged box. */
.frame {
  aspect-ratio: 1 / 1;
  width: 100%;
  overflow: hidden;
  border-radius: 50%;
  background: none;
}

.frame img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* Sections: a left label column and a content column. */
main {
  display: block;
}

.row {
  display: grid;
  grid-template-columns: 170px minmax(0, 1fr);
  gap: 40px;
  border-top: 1px solid var(--rule);
  padding: 36px 0;
}

.label {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: 0.02em;
  position: sticky;
  top: 24px;
  align-self: start;
}

.label .num {
  font-family: var(--font-mono);
  color: var(--accent);
  margin-right: 0.5em;
}

.body {
  max-width: 65ch;
}

.body > p:last-child {
  margin-bottom: 0;
}

.body a {
  text-underline-offset: 3px;
}

.stack {
  color: var(--muted);
  margin-top: 1.25rem;
}

.education {
  color: var(--muted);
  font-size: 0.9375rem;
  margin-top: 0.5rem;
}

/* --- 3b. Writing (plain list, no numbers) --------------------------------- */
.plain-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.plain-list li {
  padding: 16px 0;
  border-top: 1px solid var(--rule);
}

.plain-list li:first-child {
  border-top: 0;
  padding-top: 0;
}

.plain-list h3 {
  font-size: 1.125rem;
  margin-bottom: 0.3em;
}

.plain-list h3 a {
  color: var(--ink);
  text-decoration-color: var(--accent);
}

.plain-list p {
  margin: 0;
  color: var(--muted);
}

/* --- 4. Featured work ------------------------------------------------------ */
.work-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.work-item {
  display: grid;
  grid-template-columns: 40px minmax(0, 1fr);
  gap: 12px;
  padding: 18px 0;
  border-top: 1px solid var(--rule);
}

.work-item:first-child {
  border-top: 0;
  padding-top: 0;
}

.work-num {
  color: var(--muted);
  padding-top: 0.2em;
}

.work-item h3 {
  font-size: 1.125rem;
  margin-bottom: 0.3em;
}

.work-item h3 a {
  color: var(--ink);
  text-decoration-color: var(--accent);
}

.work-item p {
  margin: 0;
  color: var(--muted);
}

.work-item .work-status {
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  margin-top: 0.4em;
  color: var(--muted);
}

.work-item .work-status-active {
  color: var(--accent);
}

/* --- 5. Handshake diagram -------------------------------------------------- */
.intro-note {
  color: var(--muted);
  margin-bottom: 1.25rem;
}

/* The diagram needs more width than body text, so this section drops the 65ch cap.
   The captions keep their own measure. */
#handshake .body {
  max-width: none;
}

.handshake {
  max-width: 100%;
}

.intro-note,
.steps {
  max-width: 65ch;
}

.handshake-stage {
  overflow-x: auto;
  border: 1px solid var(--rule);
  border-radius: 2px;
  padding: 12px;
}

.handshake-svg {
  display: block;
  width: 100%;
  min-width: 480px;
  height: auto;
}

.lane {
  stroke: var(--rule);
  stroke-width: 1.5;
  stroke-dasharray: 4 6;
}

.lane-label {
  fill: var(--ink);
  font-weight: 600;
}

.msg {
  fill: none;
  stroke: var(--ink);
  stroke-width: 1.75;
}

.msg-enc {
  stroke: var(--accent);
}

.msg-data {
  stroke: var(--muted);
  stroke-dasharray: 2 5;
}

.msg-label {
  fill: var(--muted);
}

.head {
  fill: var(--ink);
}

/* Arrowheads that follow an encrypted line take the accent color. */
.msg-enc ~ .head {
  fill: var(--accent);
}

.check {
  fill: var(--paper-2);
  stroke: var(--accent);
  stroke-width: 1;
}

.check-label {
  fill: var(--ink);
}

.handshake-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 12px;
  margin: 12px 0 4px;
}

.replay {
  font-family: var(--font-mono);
  font-size: 0.875rem;
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--ink);
  border-radius: 2px;
  padding: 0.3em 0.9em;
  cursor: pointer;
}

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

.view-toggle {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.view-btn {
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--rule);
  border-radius: 2px;
  padding: 0.3em 0.8em;
  cursor: pointer;
}

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

.view-btn[aria-pressed="true"] {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--paper);
}

/* Eavesdropper labels: hidden by default, shown when the diagram has .is-eve. */
.eve-label {
  display: none;
  font-family: var(--font-mono);
  font-size: 12px;
  fill: var(--ink);
}

.eve-cipher {
  fill: var(--accent);
}

.handshake.is-eve .msg-label {
  display: none;
}

.handshake.is-eve .eve-label {
  display: inline;
}

.eve-note {
  display: none;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 0.875rem;
  margin: 0 0 8px;
}

.handshake.is-eve .eve-note {
  display: block;
}

/* The client-side check is invisible to an observer, so it is dimmed in this view. */
.handshake.is-eve .step[data-step="4"] {
  opacity: 0.35;
}

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

.steps li {
  padding: 0.55em 0 0.55em 0.9em;
  border-left: 2px solid transparent;
  color: var(--ink);
}

.steps li + li {
  border-top: 1px solid var(--rule);
}

.steps strong {
  font-weight: 600;
}

/* Timing: each data-step value sets --d. Steps and captions share the same delay. */
[data-step="1"] { --d: 0s; }
[data-step="2"] { --d: 1.4s; }
[data-step="3"] { --d: 2.8s; }
[data-step="4"] { --d: 4.2s; }
[data-step="5"] { --d: 5.6s; }
[data-step="6"] { --d: 6.8s; }

/* Animations only run after main.js adds .is-playing.
   Without it, the diagram and captions are in their final state. */
.handshake.is-playing .msg {
  stroke-dasharray: 1;
  stroke-dashoffset: 1;
  animation: draw 0.7s ease-out var(--d) both;
}

.handshake.is-playing .msg-data {
  stroke-dasharray: 1;
}

/* Eavesdropper labels are excluded, so switching views is instant even mid-autoplay. */
.handshake.is-playing .step > :not(.msg):not(.eve-label) {
  animation: fade 0.4s ease calc(var(--d) + 0.6s) both;
}

.handshake.is-playing .steps li {
  animation: note 1.2s ease var(--d) both;
}

/* Hovering the diagram or its captions pauses the sequence.
   Focus is not used here: clicking Replay focuses that button, and a focus-based pause would freeze the replay at once. */
.handshake.is-playing .handshake-stage:hover *,
.handshake.is-playing .steps:hover * {
  animation-play-state: paused !important;
}

@keyframes draw {
  from { stroke-dashoffset: 1; }
  to   { stroke-dashoffset: 0; }
}

@keyframes fade {
  from { opacity: 0; }
  to   { opacity: 1; }
}

@keyframes note {
  0%   { color: var(--muted); border-left-color: transparent; }
  12%  { color: var(--ink);   border-left-color: var(--accent); }
  100% { color: var(--ink);   border-left-color: transparent; }
}

/* --- 6. Now, links, footer ------------------------------------------------- */
.now {
  font-size: 1.25rem;
  line-height: 1.45;
  margin-bottom: 0.5em;
}

.updated {
  color: var(--muted);
}

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

.link-list li {
  display: grid;
  grid-template-columns: 90px minmax(0, 1fr);
  gap: 16px;
  padding: 8px 0;
  border-top: 1px solid var(--rule);
}

.link-list li:first-child {
  border-top: 0;
  padding-top: 0;
}

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

.link-key {
  color: var(--muted);
  padding-top: 0.15em;
}

.fingerprint {
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  color: var(--muted);
  margin: 0.25em 0 0;
  overflow-wrap: anywhere;
}

.link-list a {
  overflow-wrap: anywhere;
}

.site-footer {
  border-top: 1px solid var(--rule);
  padding-top: 24px;
  font-family: var(--font-mono);
  font-size: 0.875rem;
  color: var(--muted);
}

.site-footer p {
  margin: 0;
}


/* --- 7. Responsive -------------------------------------------------------- */
@media (max-width: 820px) {
  .intro {
    grid-template-columns: minmax(0, 1fr);
    gap: 32px;
    padding-bottom: 40px;
  }

  .portrait {
    max-width: 200px;
  }

  .row {
    grid-template-columns: minmax(0, 1fr);
    gap: 16px;
    padding: 28px 0;
  }

  .label {
    position: static;
  }
}

@media (max-width: 480px) {
  .page {
    padding-top: 40px;
  }

  .handshake-stage {
    padding: 8px;
  }
}

/* --- 7b. Small tool page (tools/jwt.html) --------------------------------- */
.tool-page {
  max-width: 760px;
}

.tool-back {
  font-family: var(--font-mono);
  font-size: 0.875rem;
  margin-bottom: 40px;
}

.tool-head {
  padding-bottom: 32px;
  border-bottom: 1px solid var(--rule);
  margin-bottom: 32px;
}

.tool-head h1 {
  font-size: clamp(2.25rem, 7vw, 3.5rem);
  margin-bottom: 0.4em;
}

.tool-warning {
  color: var(--muted);
  font-size: 0.9375rem;
  margin-top: 1rem;
}

.tool-label {
  display: block;
  font-family: var(--font-mono);
  font-size: 0.875rem;
  color: var(--muted);
  margin-bottom: 8px;
}

.tool-input {
  display: block;
  width: 100%;
  font-family: var(--font-mono);
  font-size: 0.875rem;
  line-height: 1.5;
  color: var(--ink);
  background: var(--paper-2);
  border: 1px solid var(--rule);
  border-radius: 2px;
  padding: 12px;
  resize: vertical;
  overflow-wrap: anywhere;
}

.tool-error {
  color: var(--ink);
  font-weight: 600;
  min-height: 1.5em;
  margin: 12px 0;
}

.tool-result {
  margin-top: 16px;
}

.tool-subhead {
  font-size: 0.9375rem;
  color: var(--muted);
  margin: 24px 0 8px;
}

.tool-out {
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  line-height: 1.5;
  background: var(--paper-2);
  border: 1px solid var(--rule);
  border-radius: 2px;
  padding: 12px;
  margin: 0;
  overflow-x: auto;
}

.tool-notes {
  padding-left: 1.25em;
  margin: 0;
  color: var(--muted);
}

.tool-notes li {
  margin-bottom: 0.4em;
}

/* --- 8. Reduced motion ---------------------------------------------------- */
/* main.js never adds .is-playing in this case. This block is a second safety net,
   so any animation that does run finishes at once, in its final state. */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-delay: 0ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
