/* ==========================================================================
   mats.mæland — portfolio
   Built from Figma "Lekeplass v.2". Desktop frame 1440, mobile frame 390.
   ========================================================================== */

:root {
  --light: #fff;
  --dark: #1c1c1c;
  --dark-txt: #111;
  --grey-txt: #999;
  --muted: #8c8c8c;
  --rule: #404040;
  --placeholder: #f1f0ee;

  --font: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "DM Mono", ui-monospace, "SFMono-Regular", monospace;

  --pad: clamp(20px, 4.17vw, 60px); /* side margin: 60px at the 1440 Figma frame, 20px on mobile */
  --gap: 32px;   /* fixed column gap of the 12-column grid */
  --max: 1920px; /* content stops growing beyond this, centred */

  /* Portrait sketch timing (front page) */
  --sketch-start: 0ms;     /* delay before the first line once triggered */
  --sketch-gap: 150ms;     /* pause between two lines */
  --sketch-short: 400ms;   /* short marks: sparkle ticks */
  --sketch-medium: 550ms;  /* arrow, underline */
  --sketch-long: 700ms;    /* the loop around the head */
  --sketch-ease: cubic-bezier(0.33, 1, 0.68, 1); /* ease-out: the pen slows and lifts */
  --sketch-hold: 5s;       /* how long the finished drawing stays */
  --sketch-fade: 400ms;    /* fade-out when it goes away */
  --sketch-mobile-wait: 2s; /* mobile: wait before each drawing (first one and every repeat) */
}

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

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

body {
  background: var(--light);
  color: var(--dark-txt);
  font-family: var(--font);
  font-weight: 400;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
}

img { display: block; max-width: 100%; }
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; text-align: inherit; }
ol, ul { list-style: none; }

:focus-visible { outline: 2px solid currentColor; outline-offset: 3px; }

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { transition: none !important; animation: none !important; }
}

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

.wrap { max-width: var(--max); margin-inline: auto; padding-inline: var(--pad); }

/* 12-column grid. By default each child takes one half: the first columns
   1–6, the second columns 7–12 (which starts at the middle of the page). */
.cols {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  column-gap: var(--gap);
}
.cols > * { grid-column: span 6; }

/* ---------- Type styles (Figma text styles) ---------- */

.t-logo    { font-size: clamp(34px, 2.36vw, 45px); font-weight: 500; line-height: 1.3; }
.t-h1      { font-size: clamp(48px, 3.33vw, 64px); font-weight: 300; line-height: 1.3; letter-spacing: -1.2px; }
.t-intro   { font-size: clamp(28px, 1.94vw, 37px); line-height: 1.214; letter-spacing: -0.42px; }
.t-section { font-size: clamp(18px, 1.25vw, 24px); line-height: 1.3; font-weight: 400; }
.t-body    { font-size: 16px; line-height: 24px; }
.t-list    { font-size: 12px; line-height: 1.25; }
.t-small   { font-size: 11px; line-height: 16px; }
.t-label   { font-size: 10px; line-height: 1.25; letter-spacing: 0.8px; text-transform: uppercase; }
.t-num     { font-family: var(--mono); font-size: 9px; line-height: 1.25; }
.grey      { color: var(--grey-txt); }

.link-hover { transition: color .2s ease; }
.link-hover:hover { color: var(--grey-txt); }

/* ---------- Header ---------- */

.site-header { padding-top: 41px; align-items: start; }
.site-header .logo { white-space: nowrap; justify-self: start; }
.header-right { display: flex; justify-content: space-between; align-items: flex-start; }
.nav { display: flex; flex-direction: column; }
.nav a { transition: color .2s ease; }
.nav a:hover,
.nav a:focus-visible { color: var(--grey-txt); }
.clock { color: var(--grey-txt); font-variant-numeric: tabular-nums; }

/* ---------- Media boxes ---------- */

.media {
  position: relative;
  overflow: hidden;
  background: var(--placeholder);
}
.media > img.cover   { width: 100%; height: 100%; object-fit: cover; }
.media > img.contain-left { width: 100%; height: 100%; object-fit: contain; object-position: left center; }
.media > img.crop,
.media > img.abs     { position: absolute; max-width: none; }
.media > img.abs     { height: auto; }
.media .clip         { position: absolute; overflow: hidden; }
.media .clip > img   { position: absolute; left: 0; top: 0; width: 100%; max-width: none; }
.media.bare          { background: transparent; }

/* ---------- Front page ---------- */

.portrait-row { margin-top: 135px; }
.portrait { position: relative; grid-column: 7 / span 6; width: max(200px, 34.78%); /* 224 of 644 in Figma */ display: flex; flex-direction: column; gap: 12px; }
.portrait img { width: 100%; aspect-ratio: 223 / 300; object-fit: fill; }

/* Hand-drawn sketch on the portrait, in two layers:
   - .sketch-photo covers the photo (viewBox 224×300), so the loop, arrow and
     sparkles scale with the face; some marks sit outside it (overflow: visible).
   - .sketch-caption is a fixed-size layer on the caption, whose text doesn't scale.
   Lines .l1–.l4 draw one after another, in that order, across both layers. */
.portrait {
  /* duration of each line, in drawing order */
  --d1: var(--sketch-long);
  --d2: var(--sketch-medium);
  --d3: var(--sketch-medium);
  --d4: var(--sketch-short);
}
.portrait figcaption { position: relative; }
.sketch {
  position: absolute;
  overflow: visible;
  pointer-events: none;
  fill: none;
  stroke: var(--dark-txt);
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: opacity var(--sketch-fade) ease;
}
.sketch-photo {
  left: 0;
  top: 0;
  width: 100%;
  aspect-ratio: 224 / 300;
  /* --sketch-scale = photo width / 224 (set by main.js), so the line stays
     1.75px on screen however large the portrait is */
  stroke-width: calc(1.75px / var(--sketch-scale, 1));
}
.sketch-caption { left: -4px; top: 0; width: 68px; height: 30px; }
/* No vector-effect: non-scaling-stroke here. It makes Chrome measure dashes in
   screen px, which breaks pathLength="1" once the photo is scaled up. */
.sketch path { stroke-dasharray: 1 2; }
.sketch .l1 { --dur: var(--d1); --at: var(--sketch-start); }
.sketch .l2 { --dur: var(--d2); --at: calc(var(--sketch-start) + var(--d1) + var(--sketch-gap)); }
.sketch .l3 { --dur: var(--d3); --at: calc(var(--sketch-start) + var(--d1) + var(--d2) + 2 * var(--sketch-gap)); }
.sketch .l4 { --dur: var(--d4); --at: calc(var(--sketch-start) + var(--d1) + var(--d2) + var(--d3) + 3 * var(--sketch-gap)); }

/* Hidden until triggered (main.js). Without JS the finished drawing shows. */
.js .sketch path { opacity: 0; }
.js .portrait.is-drawing .sketch path { animation: sketch-draw var(--dur) var(--sketch-ease) var(--at) both; }
.js .portrait.is-fading .sketch { opacity: 0; }
@keyframes sketch-draw {
  0%   { stroke-dashoffset: 1; opacity: 0; } /* opacity hides the round-cap dot before the pen starts */
  1%   { opacity: 1; }
  100% { stroke-dashoffset: 0; opacity: 1; }
}
@media (prefers-reduced-motion: reduce) {
  .js .sketch,
  .js .sketch path,
  .js .portrait.is-drawing .sketch path { animation: none; opacity: 1; stroke-dashoffset: 0; }
}

.intro { margin-top: 124px; align-items: end; }
.intro p.t-intro { max-width: 86.96%; /* 560 of 644 */ }
.intro-meta { display: flex; justify-content: space-between; align-items: flex-end; }
.intro-meta a { transition: transform .2s ease; }
.intro-meta a:hover { transform: translateY(2px); }

/* Selection strip. Each item sets --w and --h: its Figma width and resting
   height in px (unitless). Widths share the content width in that ratio with
   fixed gaps; every height is Figma px × --s, the strip's scale (1 when the
   images span their Figma 1184px), so aspect ratios hold at any width.
   Items share a bottom line; on hover the image grows upwards to --grow while
   its caption stays put. Each item is as tall as a fully grown one, so
   nothing below the strip moves. */
.gallery {
  --grow: 270;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --s: calc((100cqw - 4 * var(--gap)) / 1184); /* cqw resolves in the items, against this container */
  container-type: inline-size;
  margin-top: 89px;
  display: flex;
  gap: var(--gap);
  align-items: flex-end;
}
.g-item {
  flex: var(--w) 1 0;
  min-width: 0;
  height: calc(var(--grow) * var(--s) + 26px); /* + 10px gap + 16px caption */
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 10px;
}
.g-item:focus-visible { outline: none; }
.g-media {
  position: relative;
  overflow: hidden;
  height: calc(var(--h) * var(--s));
}
.g-media > img { width: 100%; height: 100%; object-fit: cover; }
/* Visit Svalbard: a page screenshot framed on a dark ground. Growing reveals
   more of the page instead of cropping it. */
.g-frame { background: #2a2724; }
.g-frame > img.g-screen { position: absolute; left: 7.29%; top: calc(10 * var(--s)); width: 85.42%; height: auto; }
.g-label { color: var(--grey-txt); transition: color .2s ease; }
.g-item:hover .g-label,
.g-item:focus-visible .g-label { color: var(--dark-txt); }
.g-item:focus-visible .g-label { text-decoration: underline; text-underline-offset: 3px; }

@media (min-width: 768px) and (prefers-reduced-motion: no-preference) {
  .g-media { transition: height 500ms var(--ease); }

  .g-item:focus-visible .g-media { height: calc(var(--grow) * var(--s)); }
}

@media (min-width: 768px) and (hover: hover) and (prefers-reduced-motion: no-preference) {
  .g-item:hover .g-media { height: calc(var(--grow) * var(--s)); }
}

/* Archive index */

.archive {
  margin-top: 123px;
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  column-gap: var(--gap);
  scroll-margin-top: 24px;
}
.archive > h2 { grid-column: 1 / span 2; }
.index { grid-column: 3 / -1; padding-block: 10px; }

.row { border-top: 1px solid var(--grey-txt); }

.row-head {
  width: 100%;
  min-height: 52px;
  padding: 8px 0;
  display: grid;
  grid-template-columns: 10.3% 51.47% 19.67% minmax(0, 1fr) auto;
  align-items: center;
  color: var(--dark-txt);
}
.row-meta { display: contents; }
.row-year { padding-left: 10px; }
.row-action { text-align: right; }
.row-action::after { content: "OPEN"; }
.row-head[aria-expanded="true"] .row-action::after { content: "CLOSE"; }
.row-head:hover .row-title { text-decoration: underline; text-underline-offset: 3px; }

.row-panel {
  display: grid;
  grid-template-rows: 0fr;
  transition: grid-template-rows .45s cubic-bezier(.2,.7,.2,1);
}
.row.is-open .row-panel { grid-template-rows: 1fr; }
.row-panel > div { overflow: hidden; min-height: 0; }

.row-content {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 20.46%;               /* 224 of the 1095px list */
  padding: 15px 0 35px;
}
.row-media {
  flex: 0 1 30.68%;          /* 336 of 1095 */
  aspect-ratio: 336 / 220;
  background: var(--dark-txt);
}
.row-media > img.screen { position: absolute; left: 8.93%; top: 10.9%; width: 81.85%; height: auto; }
.row-text {
  flex: 0 1 27.95%;          /* 306 of 1095 */
  display: flex;
  flex-direction: column;
  gap: 121px;
}
.read-case {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--dark-txt);
}
.read-case .arrow { font-size: 11px; line-height: 16px; transition: transform .2s ease; }
.read-case:hover .arrow { transform: translateX(4px); }

/* About */

.about { margin-top: 86px; scroll-margin-top: 24px; }
.about h2 { padding: 10px; margin-left: -10px; align-self: start; }
.about .about-text { padding: 10px 0; font-size: 14px; line-height: 21px; letter-spacing: -0.14px; }
.about-text p + p,
.about-text p + h3,
.about-text h3 + p { margin-top: 19px; }
.about-text h3 { font-size: 14px; line-height: 21px; font-weight: 600; }

/* ---------- Case pages ---------- */

.case-hero { margin-top: 159px; }
.case-sub { color: var(--grey-txt); margin-top: 2px; }
.case-header-media { margin-top: 88px; aspect-ratio: 1312 / 680; }

.case-about { margin-top: 61px; align-items: start; }
.case-about .prose { max-width: 86.96%; /* 560 of 644 */ }
.case-aside { margin-top: 333px; display: flex; flex-direction: column; gap: 40px; }

.prose p + p { margin-top: 24px; }
.prose a { font-weight: 600; text-decoration: underline; text-decoration-color: transparent; text-underline-offset: 3px; transition: text-decoration-color .2s ease; word-break: break-word; }
.prose a:hover { text-decoration-color: currentColor; }

.case-gallery { margin-top: 56px; align-items: start; }
.stack { display: flex; flex-direction: column; gap: 40px; min-width: 0; }
.stack .prose { margin-top: 20px; max-width: 86.96%; }

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

.site-footer { background: var(--dark); color: var(--light); margin-top: 160px; }
.home .site-footer { margin-top: 39px; }
.footer-inner { padding: 38px var(--pad); }
.footer-top { row-gap: 23px; }
.footer-title { grid-column: 1 / span 6; font-size: clamp(32px, 3.33vw, 64px); font-weight: 300; line-height: 1.3; letter-spacing: -1.2px; white-space: nowrap; }
.footer-info { grid-column: 7 / span 6; grid-row: 1; display: flex; gap: clamp(32px, 10.56vw, 202px); align-self: center; }
.footer-info dt { color: var(--muted); margin-bottom: 4px; }
.footer-info dd a { display: block; }
.footer-mail { grid-column: 1 / span 6; justify-self: start; }
.footer-bottom {
  margin-top: 219px;
  padding-top: 27px;
  border-top: 1px solid var(--rule);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.footer-bottom .copy { color: var(--muted); }
.site-footer a { transition: color .2s ease; }
.site-footer a:hover { color: var(--muted); }

/* ==========================================================================
   Tablet — keep the desktop structure, tighten spacing
   ========================================================================== */

@media (max-width: 1100px) {
  .case-aside { margin-top: 200px; }
}

/* ==========================================================================
   Mobile — Figma frames "frontpage – mobile" and "IKEA – Bästis – mobile"
   ========================================================================== */

@media (max-width: 767px) {
  .cols { grid-template-columns: minmax(0, 1fr); }
  .cols > * { grid-column: 1 / -1; }

  /* Header/Mobile */
  .site-header { display: flex; justify-content: space-between; padding-top: 24px; }
  .header-right { display: block; }
  .nav { align-items: flex-end; text-align: right; }
  .clock { display: none; }

  /* Front page: top */
  .portrait-row { margin-top: 64px; display: flex; justify-content: flex-end; }
  .portrait { width: 200px; grid-column: auto; }
  .portrait img { aspect-ratio: 200 / 269; }

  .intro { margin-top: 64px; row-gap: 32px; }
  .intro p.t-intro { font-size: 22px; line-height: 28px; letter-spacing: -0.22px; }

  /* Gallery (scroll) */
  /* Mobile Figma frame: the desktop strip at 80%, scrolled sideways, no hover. */
  .gallery {
    margin-top: 40px;
    height: auto;
    gap: 16px;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    scroll-snap-type: x mandatory;
    scroll-padding-inline: 20px;
    scrollbar-width: none;
    padding-inline: 20px;
  }
  .gallery::-webkit-scrollbar { display: none; }
  .g-item { flex: 0 0 calc(var(--w) * 0.8px); height: auto; scroll-snap-align: start; }
  .g-media { height: calc(var(--h) * 0.8px); }
  .g-frame > img.g-screen { top: 8px; }
  .intro p.t-intro { max-width: none; }

  /* Bottom: archive + about */
  .archive { margin-top: 96px; grid-template-columns: minmax(0, 1fr); row-gap: 20px; }
  .archive > h2, .index { grid-column: 1 / -1; }
  .index { padding: 0; }

  .row-head {
    grid-template-columns: 24px minmax(0, 1fr) auto;
    grid-template-areas:
      "num title action"
      "num meta  action";
    column-gap: 12px;
    row-gap: 2px;
    align-items: start;
    padding: 16px 0;
    min-height: 0;
  }
  .row-num    { grid-area: num; padding-top: 5px; }
  .row-title  { grid-area: title; font-size: 16px; line-height: 24px; }
  .row-meta   { grid-area: meta; display: block; color: var(--grey-txt); }
  .row-year   { padding-left: 0; }
  .row-year::before { content: " · "; }
  .row-action { grid-area: action; padding-top: 5px; }

  .row-content {
    flex-direction: column;
    align-items: stretch;
    gap: 16px;
    padding: 4px 0 24px;
  }
  .row-media { flex: none; width: 100%; aspect-ratio: 350 / 229.17; }
  .row-text { flex: none; gap: 16px; }
  .read-case { padding: 8px 0 10px; }

  .about { margin-top: 96px; row-gap: 20px; }
  .about h2 { padding: 0; margin-left: 0; }
  .about .about-text { padding: 0; }

  /* Case pages */
  .t-h1 { font-size: 32px; line-height: 1.25; letter-spacing: -0.64px; }
  .case-hero { margin-top: 88px; }
  .case-sub { margin-top: 8px; }
  .case-header-media { margin-top: 24px; width: 100%; height: 240px; }
  .case-header-media.keep-ratio { height: auto; aspect-ratio: 1312 / 680; }

  .case-about { margin-top: 48px; row-gap: 12px; }
  .case-about > div:first-child { display: contents; }
  .case-about .prose { order: 1; max-width: none; }
  .case-aside { order: 2; margin-top: 36px; gap: 12px; }
  .case-gallery { margin-top: 48px; row-gap: 12px; }
  .stack { gap: 12px; }
  .stack .prose { margin-top: 36px; max-width: none; }

  /* Footer dark/Mobile */
  .site-footer, .home .site-footer { margin-top: 96px; }
  .footer-inner { padding: 48px var(--pad) 32px; }
  .footer-top { row-gap: 0; }
  .footer-title { font-size: 32px; line-height: 1.25; letter-spacing: -0.64px; }
  .footer-title, .footer-mail { grid-column: 1 / -1; }
  .footer-mail { grid-row: 2; margin-top: 16px; }
  .footer-info { grid-column: 1 / -1; grid-row: 3; margin-top: 48px; gap: 32px; align-self: start; }
  .footer-bottom { margin-top: 48px; padding-top: 20px; align-items: flex-start; }
}
