/* ============================================================
   ANTON JOHANSSON — index-sheet portfolio
   Paper white. No color at rest. Color only on interaction.
   ============================================================ */

:root {
  --paper: #f6f4ee;
  --ink: #191813;
  --body: #4b4940;
  --muted: #6a675a;
  --faint: #878477;
  --line: #dcd9cb;

  /* hover pops */
  --c1: #2431f0; /* ultramarine */
  --c2: #c84000; /* vermilion   */
  --c3: #007a46; /* emerald     */
  --c4: #7526e8; /* violet      */
  --c5: #d10c6a; /* magenta     */
  --c6: #007790; /* teal        */
  --c7: #9e5a00; /* amber       */

  /* profile categories */
  --experience: #2431f0; /* blue   */
  --leadership: #007a46; /* green  */
  --education: #9e5a00; /* orange  */
  --research: #7526e8; /* purple   */

  --edge: clamp(12px, 4vw, 52px);
  --pad: calc(var(--edge) + clamp(18px, 4vw, 56px));
  --mono: "IBM Plex Mono", ui-monospace, "Cascadia Mono", Consolas, monospace;

  color-scheme: light;
}

/* dark: follows the system unless the toggle picked light; the token
   block is repeated for the explicit data-theme="dark" choice */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #131310;
    --ink: #ece9df;
    --body: #bdb9ab;
    --muted: #a19d8e;
    --faint: #858174;
    --line: #2e2d27;

    --c1: #7c84ff;
    --c2: #ff6a3d;
    --c3: #2ec27e;
    --c4: #a57bff;
    --c5: #ff4f9d;
    --c6: #2bb8d6;
    --c7: #f0a030;

    --experience: #7c84ff;
    --leadership: #2ec27e;
    --education: #f0a030;
    --research: #a57bff;

    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #131310;
  --ink: #ece9df;
  --body: #bdb9ab;
  --muted: #a19d8e;
  --faint: #858174;
  --line: #2e2d27;

  --c1: #7c84ff;
  --c2: #ff6a3d;
  --c3: #2ec27e;
  --c4: #a57bff;
  --c5: #ff4f9d;
  --c6: #2bb8d6;
  --c7: #f0a030;

  --experience: #7c84ff;
  --leadership: #2ec27e;
  --education: #f0a030;
  --research: #a57bff;

  color-scheme: dark;
}

* { box-sizing: border-box; }

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--mono);
  font-size: 0.8125rem;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

::selection {
  background: var(--ink);
  color: var(--paper);
}

a {
  color: inherit;
  text-decoration: none;
}

/* ---------- atmosphere ---------- */

.grain {
  position: fixed;
  inset: 0;
  z-index: 60;
  pointer-events: none;
  opacity: 0.045;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2'/%3E%3C/filter%3E%3Crect width='160' height='160' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* vertical frame lines that the row rules cross */
.frame::before,
.frame::after {
  content: "";
  position: fixed;
  top: 0;
  bottom: 0;
  width: 1px;
  background: var(--line);
  z-index: 0;
  transform: scaleY(0);
  transform-origin: top;
  transition: transform 1.1s cubic-bezier(0.22, 1, 0.36, 1) 0.15s;
}
.frame::before { left: var(--edge); }
.frame::after { right: var(--edge); }
.ready .frame::before,
.ready .frame::after { transform: scaleY(1); }

/* ---------- primitives ---------- */

.wrap {
  padding-inline: var(--pad);
}

.micro {
  margin: 0;
  font-size: 0.75rem;
  font-weight: 500;
  letter-spacing: 0.09em;
  text-transform: uppercase;
}

.ico {
  width: 0.85em;
  height: 0.85em;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.3;
  stroke-linecap: square;
}

.dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  margin-right: 0.6em;
  background: var(--c3);
  animation: pulse 2.2s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.25; }
}

/* ---------- reveal on scroll ---------- */

[data-reveal] {
  opacity: 0;
  transform: translateY(10px);
  transition:
    opacity 0.65s cubic-bezier(0.22, 1, 0.36, 1),
    transform 0.65s cubic-bezier(0.22, 1, 0.36, 1);
}
[data-reveal].in {
  opacity: 1;
  transform: none;
}

/* ---------- top bar ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  background: var(--paper);
  border-bottom: 1px solid var(--line);
}

.topbar-in {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding-block: 0.9rem;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.65em;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.09em;
  text-transform: uppercase;
}
.brand::before {
  content: "";
  width: 8px;
  height: 8px;
  background: currentColor;
  transition: transform 0.4s cubic-bezier(0.22, 1, 0.36, 1);
}
.brand:hover::before { transform: rotate(135deg); }

.nav {
  display: flex;
  gap: clamp(1rem, 3vw, 2.25rem);
}
.nav a {
  font-size: 0.75rem;
  font-weight: 500;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--muted);
  transition: color 0.2s;
}
.nav a:hover,
.nav a:focus-visible {
  color: var(--pop);
}

.topbar-end {
  display: flex;
  align-items: center;
  gap: clamp(1rem, 3vw, 2.25rem);
}

/* theme toggle: a half-filled square, echoing the brand mark */
.theme-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.6em;
  padding: 0;
  border: 0;
  background: none;
  font: inherit;
  font-size: 0.75rem;
  font-weight: 500;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--muted);
  cursor: pointer;
  transition: color 0.2s;
}
.theme-toggle::before {
  content: "";
  width: 8px;
  height: 8px;
  border: 1px solid currentColor;
  background: linear-gradient(135deg, currentColor 50%, transparent 50%);
  transition: transform 0.4s cubic-bezier(0.22, 1, 0.36, 1);
}
.theme-toggle:hover,
.theme-toggle:focus-visible { color: var(--ink); }
.theme-toggle:hover::before { transform: rotate(180deg); }

/* ---------- hero ---------- */

.hero {
  padding-top: clamp(5rem, 15vh, 9.5rem);
  padding-bottom: clamp(4rem, 11vh, 7.5rem);
}

.hero-kicker {
  color: var(--muted);
  margin-bottom: clamp(1.5rem, 4vh, 2.75rem);
}

.hero-name {
  margin: 0 0 clamp(1.75rem, 5vh, 3rem);
  font-size: clamp(2.4rem, 8.5vw, 6rem);
  font-weight: 500;
  line-height: 1.02;
  letter-spacing: -0.015em;
  text-transform: uppercase;
}
.hero-line {
  display: block;
  min-height: 1.02em; /* keep height while scrambling */
}

.lede {
  margin: 0;
  max-width: 44ch;
  font-size: 0.9375rem;
  line-height: 1.75;
  color: var(--body);
}

.status {
  display: flex;
  align-items: center;
  margin: 2.1rem 0 0;
  font-size: 0.75rem;
  font-weight: 500;
  letter-spacing: 0.09em;
  text-transform: uppercase;
}

.hero-meta {
  margin-top: 0.85rem;
  color: var(--muted);
}

/* ---------- section index ---------- */

.index {
  margin-top: clamp(4rem, 10vh, 7.5rem);
}

.index-head {
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  background: var(--paper);
}
.index-head-in {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  padding-block: 0.7rem;
}
.s-num { color: var(--muted); font-weight: 400; }
.s-count { color: var(--muted); }
.status-inline { display: inline-flex; align-items: center; color: var(--ink); }

section[id] { scroll-margin-top: 4.5rem; }

/* ---------- entry rows ---------- */

.entry {
  border-bottom: 1px solid var(--line);
}

.entry-head {
  display: grid;
  grid-template-columns: 1.9ch minmax(0, 34ch) 1fr max-content 2ch;
  column-gap: clamp(0.9rem, 2.5vw, 1.75rem);
  align-items: baseline;
  width: 100%;
  padding-block: 1rem;
  margin: 0;
  border: 0;
  background: none;
  font: inherit;
  color: inherit;
  text-align: left;
  cursor: pointer;
  transition: background-color 0.25s;
}

.entry-head .ico { align-self: center; color: var(--faint); transition: color 0.2s, transform 0.3s; }

.title {
  font-size: 0.8125rem;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  transition: color 0.2s;
  overflow-wrap: break-word;
}

.role {
  color: var(--muted);
  font-size: 0.75rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.date {
  color: var(--muted);
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  white-space: nowrap;
}

.toggle {
  justify-self: end;
  color: var(--faint);
  transition: transform 0.35s cubic-bezier(0.22, 1, 0.36, 1), color 0.2s;
}

/* hover = the pop */
.entry-head:hover,
.entry-head:focus-visible {
  background: color-mix(in srgb, var(--pop) 5%, transparent);
}
.entry-head:hover .title,
.entry-head:focus-visible .title,
.entry.open .title { color: var(--pop); }
.entry-head:hover .ico,
.entry.open .ico { color: var(--pop); transform: translateX(3px); }
.entry-head:hover .toggle { color: var(--pop); }
.entry.open .toggle { transform: rotate(45deg); color: var(--pop); }

.entry-head:focus-visible {
  outline: 1px dashed var(--pop, var(--ink));
  outline-offset: -1px;
}

/* expandable body */
.entry-body {
  display: grid;
  grid-template-rows: 0fr;
  transition: grid-template-rows 0.45s cubic-bezier(0.22, 1, 0.36, 1);
}
.entry.open .entry-body {
  grid-template-rows: 1fr;
}
.entry-inner {
  min-height: 0;
  overflow: hidden;
  visibility: hidden;
  transition: visibility 0.45s;
  padding-inline: var(--pad);
}
.entry.open .entry-inner {
  visibility: visible;
}
.entry-inner p {
  margin: 0 0 1.1rem;
  max-width: 58ch;
  color: var(--body);
  line-height: 1.7;
}
.entry-inner p:first-child { padding-top: 0.2rem; }
.entry-inner .tags {
  color: var(--muted);
  margin-bottom: 1.4rem;
}
/* indent body to align with title column */
@media (min-width: 761px) {
  .entry-inner {
    padding-left: calc(var(--pad) + 1.9ch + clamp(0.9rem, 2.5vw, 1.75rem));
  }
}

/* ---------- profile map ---------- */

.map-wrap {
  padding-block: clamp(1.5rem, 4vh, 2.75rem) 0.25rem;
}

.map-fig {
  margin: 0;
  /* fits header + chart + caption in one laptop screen */
  max-width: min(100%, 780px);
}

.map-plot { position: relative; }

.map {
  display: block;
  width: 100%;
  height: auto;
  overflow: visible; /* labels may extend slightly past the plot edge */
}

.map .grid line {
  stroke: var(--line);
  stroke-width: 1;
  opacity: 0.55;
}

.map .axis {
  stroke: var(--ink);
  stroke-width: 1.2;
}

.map-axis {
  position: absolute;
  color: var(--ink);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  pointer-events: none;
}
.map-axis-y { top: 1%; left: calc(32 / 720 * 100% + 10px); }
.map-axis-x { bottom: calc((1 - 412 / 460) * 100% + 8px); right: calc((1 - 688 / 720) * 100%); }

.pt {
  cursor: pointer;
  outline: none;
}
.pt-hit { fill: transparent; }
.pt-sq {
  fill: var(--paper);
  stroke: var(--muted);
  stroke-width: 1.2;
  transform-box: fill-box;
  transform-origin: center;
  transition: fill 0.2s, stroke 0.2s, transform 0.3s cubic-bezier(0.22, 1, 0.36, 1);
}
.map-wrap.in .pt-sq {
  animation: ptin 0.55s cubic-bezier(0.22, 1, 0.36, 1) backwards;
  animation-delay: calc(var(--i) * 65ms + 0.3s);
}
@keyframes ptin {
  from { transform: scale(0); }
}
.pt:hover .pt-sq,
.pt:focus-visible .pt-sq,
.pt.on .pt-sq {
  fill: var(--pc);
  stroke: var(--pc);
  transform: scale(1.4);
}

.pt-label {
  fill: var(--muted);
  font-size: 11px;
  letter-spacing: 0.07em;
  pointer-events: none;
  transition: fill 0.2s;
}
.map-wrap.in .pt-label {
  animation: lblin 0.5s ease backwards;
  animation-delay: calc(var(--i) * 65ms + 0.5s);
}
@keyframes lblin {
  from { opacity: 0; }
}
.pt:hover .pt-label,
.pt:focus-visible .pt-label {
  fill: var(--pc);
}

.xhair line {
  stroke-width: 1;
  stroke-dasharray: 3 4;
  opacity: 0.7;
}
.xhair { transition: opacity 0.2s; }

.map-cap {
  display: flex;
  align-items: center;
  gap: 0.7em;
  margin: 0.9rem 0 0;
  min-height: 1.4em;
  color: var(--muted);
}
.map-swatch {
  flex: none;
  width: 8px;
  height: 8px;
  background: var(--sw, transparent);
  transition: background-color 0.2s;
}
.map-cap.live { color: var(--ink); }

/* row flash after jumping from the map */
.entry.flash > .entry-head {
  animation: rowflash 1.5s ease-out;
}
@keyframes rowflash {
  0%, 30% { background-color: color-mix(in srgb, var(--pop) 12%, transparent); }
  100% { background-color: transparent; }
}

/* ---------- about ---------- */

.about {
  display: grid;
  grid-template-columns: minmax(0, 1fr) clamp(220px, 26vw, 320px);
  gap: clamp(2rem, 6vw, 5.5rem);
  padding-block: clamp(2.5rem, 6vh, 4rem) 0.5rem;
}

.about-lede {
  margin: 0 0 1.2rem;
  max-width: 52ch;
  font-size: 0.875rem;
  line-height: 1.8;
  color: var(--body);
}

.about-label {
  margin: 2.4rem 0 1rem;
  color: var(--muted);
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin: 0;
  padding: 0;
  list-style: none;
}
.chip {
  padding: 0.42em 0.9em;
  border: 1px solid var(--line);
  border-radius: 2px;
  font-size: 0.75rem;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: default;
  transition: color 0.2s, border-color 0.2s, background-color 0.2s;
}
.chip:hover {
  color: var(--pop);
  border-color: var(--pop);
  background: color-mix(in srgb, var(--pop) 6%, transparent);
}

.langs {
  margin: 0;
  padding: 0;
  list-style: none;
  max-width: 24rem;
}
.langs li {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding-block: 0.55rem;
  border-bottom: 1px solid var(--line);
  font-size: 0.75rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.langs li:first-child { border-top: 1px solid var(--line); }
.lang-level { color: var(--muted); }

/* portrait: grayscale at rest, color on hover */
.portrait {
  margin: 0;
  position: relative;
}
.portrait img {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 5;
  object-fit: cover;
  border: 1px solid var(--line);
  filter: grayscale(1) contrast(1.04);
  transition: filter 0.5s ease;
}
.portrait:hover img { filter: none; }
.portrait-note { display: none; }
.portrait.missing img { display: none; }
.portrait.missing .portrait-note {
  display: grid;
  place-items: center;
  aspect-ratio: 4 / 5;
  border: 1px dashed var(--line);
  color: var(--faint);
  text-align: center;
  line-height: 2;
}
.portrait-cap {
  display: block;
  margin-top: 0.7rem;
  color: var(--muted);
}

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

.foot {
  margin-top: clamp(4rem, 10vh, 7.5rem);
  border-top: 1px solid var(--line);
}
.foot-in {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding-block: 1.1rem;
  color: var(--muted);
}
.foot a { transition: color 0.2s; }
.foot a:hover { color: var(--c1); }

.foot-keys {
  padding: 0;
  border: 0;
  background: none;
  font-family: inherit;
  color: inherit;
  cursor: pointer;
  transition: color 0.2s;
}
.foot-keys:hover,
.foot-keys:focus-visible { color: var(--ink); }
/* shortcuts only make sense with a keyboard */
@media (hover: none) {
  .foot-keys { display: none; }
}

/* ---------- keyboard shortcuts panel ---------- */

.keys {
  position: fixed;
  right: calc(var(--edge) + 12px);
  bottom: calc(var(--edge) + 12px);
  z-index: 50;
  width: min(19rem, calc(100vw - 2 * var(--edge) - 24px));
  padding: 0.9rem 1.1rem 1rem;
  background: var(--paper);
  border: 1px solid var(--ink);
  box-shadow: 4px 4px 0 var(--line);
  animation: keysin 0.25s cubic-bezier(0.22, 1, 0.36, 1);
}
.keys[hidden] { display: none; }
@keyframes keysin {
  from { opacity: 0; transform: translateY(6px); }
}
.keys-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 0.75rem;
  padding-bottom: 0.6rem;
  border-bottom: 1px solid var(--line);
}
.keys-x {
  padding: 0;
  border: 0;
  background: none;
  font: inherit;
  color: var(--muted);
  cursor: pointer;
}
.keys-x:hover { color: var(--ink); }
.keys-foot {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 0.75rem;
  padding-top: 0.7rem;
  border-top: 1px solid var(--line);
}
.keys-switch {
  min-width: 4.2em;
  padding: 0.25em 0.6em;
  border: 1px solid var(--ink);
  border-radius: 2px;
  background: var(--ink);
  font: inherit;
  color: var(--paper);
  cursor: pointer;
}
.keys-switch[aria-pressed="false"] {
  background: none;
  color: var(--ink);
}

/* headings that receive focus from the number shortcuts */
.index-head h2:focus { outline: none; }
.keys dl { margin: 0; }
.keys dl div {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding-block: 0.3rem;
}
.keys dt { white-space: nowrap; }
.keys dd {
  margin: 0;
  color: var(--body);
  font-size: 0.75rem;
  text-align: right;
}
kbd {
  display: inline-block;
  min-width: 1.7em;
  padding: 0.05em 0.4em;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 2px;
  font-family: inherit;
  font-size: 0.6875rem;
  text-align: center;
}

/* ---------- 404 ---------- */

.lost {
  min-height: 80vh;
  display: grid;
  align-content: center;
}
.lost h1 {
  margin: 0 0 1.5rem;
  font-size: clamp(2.4rem, 8.5vw, 6rem);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: -0.015em;
}
.lost a { text-decoration: underline; text-underline-offset: 4px; }
.lost a:hover { color: var(--c2); }

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

@media (max-width: 760px) {
  .nav-xtra { display: none; }

  /* the brand may wrap to two lines on the narrowest phones */
  .topbar-in { gap: 0.75rem; }
  .topbar-end,
  .nav { gap: clamp(0.6rem, 3.4vw, 1.25rem); }
  /* icon only on phones; the button keeps its aria-label */
  .theme-toggle { padding: 0.5rem; margin: -0.5rem; }
  .theme-toggle::before { width: 10px; height: 10px; }
  .js-theme-label {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }

  .entry-head {
    grid-template-columns: 1.9ch minmax(0, 1fr) 2ch;
    grid-template-areas:
      "a t g"
      ". r r"
      ". d d";
    row-gap: 0.25rem;
  }
  .entry-head .ico { grid-area: a; }
  .title { grid-area: t; }
  .role { grid-area: r; }
  .date { grid-area: d; }
  .toggle { grid-area: g; }

  .about {
    grid-template-columns: 1fr;
  }
  .portrait { max-width: 320px; }

  /* SVG text scales with the chart, so counter-scale the labels on phones
     and center them below each point where they stay collision-free */
  .pt-label {
    font-size: 19px;
    text-anchor: middle;
  }
  .pt-label.lbl-r { transform: translate(-11px, 20.5px); }
  .pt-label.lbl-l { transform: translate(11px, 20.5px); }
  .map-axis { font-size: 0.75rem; }
  /* bottom-right corner is occupied by the Research label on phones */
  .map-axis-x {
    right: auto;
    left: calc(32 / 720 * 100% + 8px);
  }

  .foot-clock { display: none; }
}

/* ---------- reduced motion ---------- */

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }
  [data-reveal] { opacity: 1; transform: none; }
  .frame::before,
  .frame::after { transform: none; }
}
