/* ==========================================================================
   namhkim.com — local copy
   Baseline matches the live Cargo site. Change the tokens below first when
   experimenting; most of the look is driven from them.
   ========================================================================== */

@font-face {
  font-family: "Alte Haas Grotesk";
  src: url("../fonts/AlteHaasGrotesk-Regular.woff") format("woff");
  font-weight: 400;
  font-display: block;
}
@font-face {
  font-family: "Alte Haas Grotesk";
  src: url("../fonts/AlteHaasGrotesk-Bold.woff") format("woff");
  font-weight: 700;
  font-display: block;
}
@font-face {
  font-family: "Montagu Slab";
  src: url("../fonts/MontaguSlab-latin.woff2") format("woff2");
  font-weight: 100 700;
  font-display: block;
}

/* ---- Tokens ------------------------------------------------------------ */
:root {
  /* 1rem scales with the window, as on Cargo. js/site.js sets --base-size
     precisely; this is the no-JS fallback. */
  --base-size: 1.44vmin;

  --bg: #f6f6f6;
  --text: rgba(0, 0, 0, 0.85);
  --text-secondary: rgba(0, 0, 0, 0.75);
  --text-muted: rgba(0, 0, 0, 0.4);
  --rule: rgba(0, 0, 0, 0.18);
  --accent: rgb(211, 81, 24);

  --font-sans: "Alte Haas Grotesk", "Helvetica Neue", Helvetica, Arial, sans-serif;
  --font-serif: "Montagu Slab", Georgia, serif;

  --text-size: 1.2rem;
  --line-height: 1.4;
  --title-size: 1.4rem;

  --sidebar-width: 25%;
  --page-padding: 2rem;
  --sidebar-gap-lines: 13;      /* blank lines between the intro and the nav */

  --lightbox-bg: #ffffff;
  --lightbox-padding: 3rem;

  color-scheme: light;
}

/* Dark theme: js/theme.js sets data-theme on <html>. Only colours change. */
:root[data-theme="dark"] {
  --bg: #121212;
  --text: rgba(255, 255, 255, 0.88);
  --text-secondary: rgba(255, 255, 255, 0.75);
  --text-muted: rgba(255, 255, 255, 0.45);
  --rule: rgba(255, 255, 255, 0.2);
  --accent: rgb(238, 110, 56);
  --lightbox-bg: #0a0a0a;

  color-scheme: dark;
}

/* short colour fade while the theme button is switching */
.theme-switching,
.theme-switching * {
  transition: background-color 250ms ease, color 250ms ease, fill 250ms ease !important;
}

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

html {
  font-size: var(--base-size);
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

a:active { opacity: 0.7; }

/* ---- Type -------------------------------------------------------------- */
.bodycopy {
  font-family: var(--font-sans);
  font-size: var(--text-size);
  font-weight: 400;
  line-height: var(--line-height);
  letter-spacing: -0.01em;
  color: var(--text);
  overflow-wrap: break-word;
}

.bodycopy a { color: var(--text); text-decoration: underline; }

h1, h2, h3 {
  font-family: var(--font-sans);
  font-size: var(--text-size);
  letter-spacing: -0.01em;
  margin: 0;
}
h1 { font-weight: 700; line-height: 1.3; color: var(--text); }
h2 { font-weight: 400; line-height: 1.3; color: var(--text-secondary); }
h3 { font-weight: 700; line-height: var(--line-height); margin: 1em 0; }
h1 a, h2 a { color: inherit; text-decoration: none; }

small { font-size: inherit; }
sub, sup { font-size: inherit; position: relative; vertical-align: baseline; }
sub { top: 0.3em; }
sup { top: -0.4em; }

hr {
  display: block;
  height: 1px;
  margin: 0;
  border: 0;
  background: var(--rule);
}

.caption { display: block; color: var(--text-muted); }
.caption a { color: var(--text-muted); }

.project-title {
  display: block;
  font-family: var(--font-serif);
  font-size: var(--title-size);
  font-weight: 600;
  font-variation-settings: "opsz" 16;
  line-height: 1.2;
  letter-spacing: -0.02em;
  color: var(--text);
}
.bodycopy .project-title a,
.bodycopy a.project-title { color: var(--text); text-decoration: none; }
u > .project-title,
u .project-title a,
.project-title u { text-decoration: underline; }

.icon {
  display: inline-block;
  width: 1.2em;
  height: 1.2em;
  margin-top: -1em;
  margin-bottom: -0.25em;
  vertical-align: baseline;
  fill: currentColor;
}

/* ---- Layout ------------------------------------------------------------ */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 2;
  width: var(--sidebar-width);
  padding: var(--page-padding);
}
.sidebar-gap { height: calc(var(--sidebar-gap-lines) * var(--line-height) * 1em); }

/* The heart is the light / dark button: filled in light mode, outlined in
   dark mode. js/site.js turns it toward the cursor. */
.theme-toggle {
  display: inline-block;
  margin: 0;
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  line-height: inherit;
  cursor: pointer;
  transition: transform 120ms ease-out;
}
[data-theme="dark"] .heart-fill { display: none; }
.theme-toggle:active { opacity: 0.7; }
.theme-toggle:focus-visible { outline: 1px solid var(--text); outline-offset: 0.2em; }

.page {
  margin-left: var(--sidebar-width);
  padding: var(--page-padding);
}

/* 12-column rows: <div class="cols"> with <div class="col" style="--span: N"> */
.cols {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  column-gap: var(--gutter, 2rem);
}
.col { grid-column: span var(--span, 12); min-width: 0; }

/* ---- Media ------------------------------------------------------------- */
.media {
  display: inline-block;
  width: 100%;
  margin: 0;
  vertical-align: bottom;
  line-height: 0;
}
.media img,
.media video {
  display: block;
  width: 100%;
  height: auto;
}
.media.zoomable { cursor: zoom-in; }
a.media { cursor: pointer; }

/* ---- Galleries --------------------------------------------------------- */
.gallery { --gutter: 1rem; }

.gallery-grid {
  display: grid;
  grid-template-columns: repeat(var(--columns, 3), minmax(0, 1fr));
  gap: var(--gutter);
  align-items: center;
}

/* Masonry: js/site.js deals items into .masonry-col columns (shortest first).
   Without JS it falls back to CSS columns. */
.gallery-masonry { columns: var(--columns, 3); column-gap: var(--gutter); }
.gallery-masonry > .media { margin-bottom: var(--gutter); break-inside: avoid; }
.gallery-masonry.is-laid-out { columns: auto; display: flex; gap: var(--gutter); align-items: flex-start; }
.gallery-masonry .masonry-col { flex: 1 1 0; min-width: 0; display: flex; flex-direction: column; gap: var(--gutter); }
.gallery-masonry.is-laid-out .media { margin-bottom: 0; }

/* Justified rows: js/site.js sets each item's width so rows fill the line.
   Without JS, flex-grow by aspect ratio gives a close result. */
.gallery-justified { --row-height: 11.4rem; display: flex; flex-wrap: wrap; gap: var(--gutter); }
.gallery-justified > .media {
  flex: var(--ar) 1 calc(var(--ar) * var(--row-height));
  width: auto;
}
.gallery-justified.is-laid-out > .media { flex: 0 0 auto; }

/* ---- Lightbox (click a zoomable image) --------------------------------- */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--lightbox-padding);
  background: var(--lightbox-bg);
  cursor: zoom-out;
  opacity: 0;
  visibility: hidden;
  transition: opacity 150ms ease, visibility 150ms;
}
.lightbox.is-open { opacity: 1; visibility: visible; }
.lightbox img,
.lightbox video {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
}
.lightbox-nav {
  position: absolute;
  top: 50%;
  width: 30px;
  height: 30px;
  margin-top: -15px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: rgba(87, 87, 87, 0.35);
  color: rgba(255, 255, 255, 0.9);
  cursor: pointer;
}
.lightbox-nav:active { opacity: 0.7; }
.lightbox-nav svg { display: block; width: 100%; height: 100%; fill: none; stroke: currentColor; stroke-width: 1.5; }
.lightbox-prev { left: 20px; }
.lightbox-next { right: 20px; }
body.lightbox-open { overflow: hidden; }

/* ---- Small screens ----------------------------------------------------- */
@media (max-width: 720px) {
  :root { --sidebar-gap-lines: 1; --page-padding: 1.4rem; }

  .sidebar { position: static; width: 100%; padding-bottom: 0; }
  .page { margin-left: 0; }

  .cols { display: block; }
  .col:empty { display: none; }

  .lightbox { padding: 10px; }
}
