/* ==========================================================================
   sahildevani.com
   ========================================================================== */

/* ---- Fonts (self-hosted) ------------------------------------------------ */

@font-face {
  font-family: 'Inter';
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url('fonts/inter-latin-wght-normal.woff2') format('woff2');
}
@font-face {
  font-family: 'JetBrains Mono';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('fonts/jetbrains-mono-latin-400-normal.woff2') format('woff2');
}
/* Local fallbacks tuned to the web fonts' metrics, so the swap doesn't move text. */
@font-face {
  font-family: 'Inter Fallback';
  src: local('Arial'), local('ArialMT');
  size-adjust: 105.1%;
  ascent-override: 92.17%;
  descent-override: 22.95%;
  line-gap-override: 0%;
}
@font-face {
  font-family: 'JetBrains Mono Fallback';
  src: local('Courier New'), local('CourierNewPSMT');
  size-adjust: 100%;
  ascent-override: 102%;
  descent-override: 30%;
  line-gap-override: 0%;
}

/* ---- Tokens ------------------------------------------------------------- */

:root {
  --bg: #090909;
  --fg: #ededea;
  --mid: #a2a29c;
  --dim: #6b6b66;
  --line: #232321;
  --cellline: #30302d;
  --star: #ffffff;

  --sans: 'Inter', 'Inter Fallback', system-ui, sans-serif;
  --mono: 'JetBrains Mono', 'JetBrains Mono Fallback', 'DejaVu Sans Mono', ui-monospace, monospace;
  --ease-out: cubic-bezier(.22, .61, .36, 1);

  /* One design pixel. Sizes below are written as calc(N * var(--px)), so the
     whole layout is drawn at 90% on laptops and desktops; phones reset it to
     1px further down. main.js reads it too, to scale the star field. */
  --px: .9px;

  color-scheme: dark;
}
:root.light {
  --bg: #f7f6f2;
  --fg: #1c1c1a;
  --mid: #5f5e58;
  --dim: #98978f;
  --line: #e2e0d8;
  --cellline: #d6d4cb;
  --star: #1c1c1a;

  color-scheme: light;
}

/* ---- Base --------------------------------------------------------------- */

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

html {
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  color: var(--fg);
  font-family: var(--sans);
  font-size: calc(17 * var(--px));
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  min-height: 100vh;
}

button {
  font: inherit;
  color: inherit;
  letter-spacing: inherit;
  background: none;
  border: 0;
  cursor: pointer;
}

a, button { -webkit-tap-highlight-color: transparent; }

:focus-visible {
  outline: 1px solid var(--mid);
  outline-offset: calc(3 * var(--px));
  border-radius: calc(2 * var(--px));
}
[tabindex="-1"]:focus { outline: none; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.mono { font-family: var(--mono); letter-spacing: -.02em; }

/* ---- Star field --------------------------------------------------------- */

#stars {
  position: fixed;
  left: 0;
  top: 0;
  width: 100%;
  height: 100vh;
  height: 100lvh; /* stays put while mobile toolbars collapse */
  pointer-events: none;
  z-index: 0;
}

/* ---- Layout ------------------------------------------------------------- */

.wrap {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: calc(640 * var(--px));
  margin: 0 auto;
  padding: calc(96 * var(--px)) 0 calc(90 * var(--px));
}

/* ---- Top bar ------------------------------------------------------------ */

.top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}

.clock { font-size: calc(13 * var(--px)); color: var(--mid); line-height: 1.45; }
.clock-time,
.clock-zone { display: block; min-height: 1.45em; } /* reserves space before the first tick */
.clock-zone { color: var(--dim); font-size: calc(10.5 * var(--px)); letter-spacing: .04em; }

.toggle {
  color: var(--mid);
  width: calc(36 * var(--px));
  height: calc(36 * var(--px));
  border: 1px solid var(--line);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color .2s ease;
}
.toggle:focus-visible { border-radius: 50%; }
.toggle svg { width: calc(18 * var(--px)); height: calc(18 * var(--px)); }
.toggle .icon-moon,
.light .toggle .icon-sun { display: none; }
.light .toggle .icon-moon { display: block; }

@media (hover: hover) {
  .toggle:hover { color: var(--fg); }
}

/* ---- Name and bio ------------------------------------------------------- */

h1 { font-size: calc(23 * var(--px)); font-weight: 500; letter-spacing: -.015em; margin-top: calc(34 * var(--px)); }
.role { color: var(--mid); margin-top: calc(2 * var(--px)); }

.bio { margin-top: calc(30 * var(--px)); }
.bio p { color: var(--mid); margin-bottom: calc(17 * var(--px)); }
.bio p:first-child { color: var(--fg); }
/* Links and the organisation names in the bio share the thin dim underline,
   which brightens on hover. The names are plain text, not links. */
a,
.co {
  color: var(--fg);
  text-decoration: underline;
  text-decoration-color: var(--dim);
  text-underline-offset: calc(3.5 * var(--px));
  text-decoration-thickness: 1px;
  transition: text-decoration-color .2s ease;
}

@media (hover: hover) {
  a:hover,
  .co:hover { text-decoration-color: var(--fg); }
}
a:focus-visible { text-decoration-color: var(--fg); }

/* ---- Shared hover underline ----------------------------------------------
   A 1px line in the text colour that draws in left to right and retracts the
   same way. Drawn as a background so it follows the text across line breaks. */

.u {
  background-image: linear-gradient(var(--fg), var(--fg));
  background-repeat: no-repeat;
  background-position: 0 100%;
  background-size: 0% 1px;
  padding-bottom: calc(2 * var(--px));
  transition: background-size .2s ease;
}

@media (hover: hover) {
  .exp:hover .n,
  .plink:hover .n { background-size: 100% 1px; }
}
.exp:focus-visible .n,
.exp[aria-expanded="true"] .n,
.plink:focus-visible .n { background-size: 100% 1px; }

/* ---- Test run divider ---------------------------------------------------- */

.run {
  display: flex;
  justify-content: center;
  align-items: center;
  margin: calc(52 * var(--px)) 0 calc(50 * var(--px));
}
.run-cells { display: flex; gap: calc(7 * var(--px)); }
.run-cell {
  width: calc(8 * var(--px));
  height: calc(8 * var(--px));
  border: 1px solid var(--cellline);      /* waiting */
  border-radius: calc(1.5 * var(--px));
}
.run-cell.is-running { border-color: var(--fg); }
.run-cell.is-passed { border-color: var(--fg); background: var(--fg); }

.run-count {
  margin-left: calc(16 * var(--px));
  font-size: calc(12 * var(--px));
  color: var(--dim);
  white-space: nowrap;
}
/* Reserve the width of the final "12/12 passed" from the start, so the row is
   centred on its resting state and nothing shifts as the counter grows. */
.run-count::after {
  content: attr(data-final);
  display: block;
  height: 0;
  overflow: hidden;
  visibility: hidden;
}

/* ---- Sections ----------------------------------------------------------- */

.label {
  font-size: max(10.5px, calc(11 * var(--px))); /* never below 10.5px */
  font-weight: 400;
  letter-spacing: .09em;
  text-transform: uppercase;
  color: var(--dim);
  margin-bottom: calc(14 * var(--px));
}

.list { list-style: none; }

#projects { scroll-margin-top: calc(40 * var(--px)); }

.row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: calc(14 * var(--px));
  padding: calc(9 * var(--px)) 0;
}
.row .n { font-weight: 500; }
.row .d { display: block; color: var(--mid); font-size: calc(15 * var(--px)); line-height: 1.45; margin-top: calc(1 * var(--px)); }
.row .r { font-size: calc(12.5 * var(--px)); color: var(--dim); white-space: nowrap; }

hr { border: 0; border-top: 1px solid var(--line); margin: calc(30 * var(--px)) 0 calc(28 * var(--px)); }

/* ---- Experience --------------------------------------------------------- */

.exp {
  width: 100%;
  text-align: left;
}

/* Collapsible panel: animates grid rows 0fr -> 1fr so the height eases to
   the content's natural size without measuring it in JS. */
.panel {
  display: grid;
  grid-template-rows: 0fr;
  opacity: 0;
  visibility: hidden;
  transition:
    grid-template-rows .25s ease,
    opacity .25s ease,
    visibility 0s linear .25s;
}
.exp[aria-expanded="true"] + .panel {
  grid-template-rows: 1fr;
  opacity: 1;
  visibility: visible;
  transition:
    grid-template-rows .25s ease,
    opacity .25s ease,
    visibility 0s;
}
.panel-inner { overflow: hidden; min-height: 0; }
/* Without JS, show everything. */
html:not(.js) .panel { grid-template-rows: 1fr; opacity: 1; visibility: visible; }

.bullets { list-style: none; margin: calc(8 * var(--px)) 0 calc(14 * var(--px)); }
.bullets li {
  position: relative;
  padding-left: calc(18 * var(--px));
  font-size: calc(15.5 * var(--px));
  line-height: 1.5;
  margin-bottom: calc(9 * var(--px));
}
.bullets li::before {
  content: '';
  position: absolute;
  left: calc(2 * var(--px));
  top: calc(11 * var(--px));
  width: calc(3.5 * var(--px));
  height: calc(3.5 * var(--px));
  border-radius: 50%;
  background: var(--mid);
}

/* ---- Projects ----------------------------------------------------------- */

.plink { text-decoration: none; }
.plink:focus-visible { outline-offset: calc(4 * var(--px)); }

.arr {
  display: inline-block;
  width: calc(10 * var(--px));
  height: calc(10 * var(--px));
  margin-left: calc(4.5 * var(--px));
  vertical-align: calc(-0.5 * var(--px));
  color: var(--dim);
  fill: none;
  stroke: currentColor;
  stroke-width: 1.2;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: color .2s ease, transform .2s ease;
}
@media (hover: hover) {
  .plink:hover .arr { color: var(--fg); transform: translate(calc(1 * var(--px)), calc(-1 * var(--px))); }
}
.plink:focus-visible .arr { color: var(--fg); transform: translate(calc(1 * var(--px)), calc(-1 * var(--px))); }

/* ---- Footer ------------------------------------------------------------- */

.foot { color: var(--mid); }
.updated { margin-top: calc(20 * var(--px)); font-size: calc(12 * var(--px)); color: var(--dim); }

/* ---- Section reveal ----------------------------------------------------- */

.js .reveal {
  opacity: 0;
  transform: translateY(calc(8 * var(--px)));
  transition: opacity .7s var(--ease-out), transform .7s var(--ease-out);
}
.js .reveal.in { opacity: 1; transform: none; }

/* ---- Theme cross-fade ----------------------------------------------------
   Browsers with View Transitions cross-fade a snapshot of the whole page.
   Others fall back to colour transitions while .theme-fade is set. */

::view-transition-group(root),
::view-transition-old(root),
::view-transition-new(root) {
  animation-duration: .3s;
  animation-timing-function: ease;
}

.theme-fade,
.theme-fade *,
.theme-fade *::before,
.theme-fade *::after {
  transition:
    background-color .3s ease,
    color .3s ease,
    border-color .3s ease,
    text-decoration-color .3s ease !important;
}

/* ---- Phones ------------------------------------------------------------- */

@media (max-width: 700px) {
  :root { --px: 1px; } /* phones stay at full size */
  body { font-size: 15.5px; line-height: 1.62; }
  .wrap { padding: 56px 26px 52px; }
  h1 { font-size: 21px; }
  .clock { font-size: 12px; }
  .row .d { font-size: 14px; }
  .row .r { font-size: 11.5px; }
  .row.proj { flex-direction: column; gap: 3px; }
  .bullets li { padding-left: 16px; font-size: 14px; }
  .bullets li::before { top: 9px; }
}

/* ---- Reduced motion ----------------------------------------------------- */

/* Stars and the test run are handled in main.js; smooth scrolling is JS-driven too. */
@media (prefers-reduced-motion: reduce) {
  .js .reveal { opacity: 1; transform: none; transition: none; }
}
