/* ===========================================================================
   VVCT — index card portfolio
   All of the design lives in this file. Content lives in src/content/*.md.

   Two rules hold the design together:
     1. Every text line sits on a ruled line of the card. --rule is that line
        height; entry rows, paragraph line-height, paragraph spacing and card
        padding are all derived from it.
     2. Nothing on a card is numbered. The cards are read, not indexed — codes,
        reference numbers and counters made plain sentences look like titles.
   =========================================================================== */

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

* {
  margin: 0;
  padding: 0;
}

:root {
  color-scheme: dark;

  /* Palette. Every foreground here clears 4.5:1 against the surface it is
     used on — --dim on --card-bg is the tightest at about 6:1. */
  --black: #0a0a0a;
  --white: #f2f2f2;
  --dim: #9a9a9a;
  --prose: #cfcfcf;
  --card-bg: #171717;
  --line-color: #2c2c2c;
  --red: #e2564a;

  /* Rhythm */
  --rule: 32px;
  --pad-x: clamp(20px, 4vw, 36px);
  --gutter: clamp(16px, 3vw, 32px);
  --border: 2px;
  --label-col: clamp(64px, 16vw, 96px);
  --tap: 44px;

  /* Type. A system monospace reads far better on a phone than Courier New,
     which most platforms render too thin at small sizes. */
  --font: ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas,
    'Liberation Mono', 'DejaVu Sans Mono', monospace;
  --fs-body: clamp(14px, 0.6rem + 0.5vw, 16px);
  --fs-tab: clamp(11px, 0.5rem + 0.35vw, 13px);
  --fs-small: clamp(11px, 0.5rem + 0.3vw, 13px);
}

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

body {
  background: var(--black);
  color: var(--white);
  font-family: var(--font);
  font-size: var(--fs-body);
  line-height: var(--rule);
  overflow-wrap: break-word;
  /* iOS: keep the sticky bottom bar clear of the home indicator. */
  padding-bottom: env(safe-area-inset-bottom);
}

::selection {
  background: var(--white);
  color: var(--black);
}

/* --- Page frame ---------------------------------------------------------- */

.site {
  min-height: 100vh;
  min-height: 100dvh;
  max-width: 1500px;
  margin-inline: auto;
  display: grid;
  gap: 0 var(--gutter);
  grid-template-columns: auto minmax(0, 1fr);
  grid-template-areas: "logo main";
  padding: var(--gutter);
  padding-inline: max(var(--gutter), env(safe-area-inset-left));
}

.masthead {
  grid-area: logo;
  align-self: start;
  position: sticky;
  top: var(--gutter);
}

.logo img {
  display: block;
  width: clamp(110px, 15vw, 200px);
  height: auto;
}

/* A column, so a short card still fills the space a tall one would take and
   the page does not change shape as you flip through. */
.tabs-wrapper {
  grid-area: main;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

/* Single column as soon as the logo starts crowding the cards. */
@media (max-width: 900px) {
  .site {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr);
    grid-template-areas:
      "logo"
      "main";
  }

  .masthead {
    position: static;
    margin-bottom: var(--gutter);
  }

  .logo img {
    width: clamp(92px, 26vw, 150px);
  }
}

/* Phone held sideways: height is the scarce dimension, so the logo and the
   page padding give some of it back. */
@media (max-height: 520px) and (orientation: landscape) {
  :root {
    --gutter: 12px;
  }

  .logo img {
    width: clamp(72px, 12vw, 110px);
  }
}

/* --- Tabs ---------------------------------------------------------------- */

.tab-strip {
  display: flex;
  flex-wrap: wrap;
  position: relative;
  z-index: 2;
  margin-bottom: calc(var(--border) * -1);
}

.tab-strip button[role="tab"] {
  background: var(--card-bg);
  border: var(--border) solid var(--white);
  color: var(--dim);
  font: inherit;
  font-size: var(--fs-tab);
  font-weight: bold;
  line-height: 1.2;
  text-transform: uppercase;
  letter-spacing: clamp(0.5px, 0.25vw, 2px);
  min-height: var(--tap);
  padding: 12px clamp(14px, 2.5vw, 26px);
  margin: 0 calc(var(--border) * -1) calc(var(--border) * -1) 0;
  cursor: pointer;
  transition: color 0.15s ease, background-color 0.15s ease;
}

.tab-strip button[role="tab"]:hover {
  color: var(--white);
}

.tab-strip button[role="tab"][aria-selected="true"] {
  background: var(--white);
  color: var(--black);
  position: relative;
  z-index: 3;
}

.tab-strip button[role="tab"]:focus-visible {
  outline: var(--border) solid var(--white);
  outline-offset: 3px;
  z-index: 4;
}

/* Narrow phones: let the tabs share the row evenly rather than leaving a
   ragged gap at the end of it. */
@media (max-width: 420px) {
  .tab-strip button[role="tab"] {
    flex: 1 1 auto;
    text-align: center;
    padding-inline: 10px;
  }
}

/* --- Card ---------------------------------------------------------------- */

.card {
  background: var(--card-bg);
  border: var(--border) solid var(--white);
  position: relative;
  color: var(--white);
  scroll-margin-top: var(--gutter);
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
}

/* Only ever seen with JavaScript off, where every card is on the page at once
   and they would otherwise touch. app.js hides all but one, and a hidden
   neighbour must not leave a gap behind. */
.card:not([hidden]) + .card:not([hidden]) {
  margin-top: var(--gutter);
}

.card:focus-visible {
  outline: var(--border) solid var(--white);
  outline-offset: 4px;
}

/* Perforated strips. The bottom one belongs to the footer strip when a card
   has one, so it stays visible against the white. */
.card::before,
.card:not(:has(> footer))::after,
.card > footer::before {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  height: 8px;
  background: repeating-linear-gradient(
    90deg,
    var(--white) 0px,
    var(--white) 2px,
    transparent 2px,
    transparent 8px
  );
  pointer-events: none;
}

.card::before { top: 0; }
.card:not(:has(> footer))::after { bottom: 0; }

.card > footer::before {
  top: 0;
  background: repeating-linear-gradient(
    90deg,
    var(--black) 0px,
    var(--black) 2px,
    transparent 2px,
    transparent 8px
  );
}

.hole {
  position: absolute;
  width: 16px;
  height: 16px;
  border: var(--border) solid var(--white);
  border-radius: 50%;
  background: var(--black);
  top: 18px;
}

.hole.left { left: 16px; }
.hole.right { right: 16px; }

.corner {
  position: absolute;
  width: 16px;
  height: 16px;
  border: var(--border) solid var(--white);
}

.corner.tl { top: 10px; left: 10px; border-right: none; border-bottom: none; }
.corner.br { bottom: 10px; right: 10px; border-left: none; border-top: none; }

/* The decorations get in the way once the card is phone-sized. */
@media (max-width: 520px) {
  .hole,
  .corner {
    display: none;
  }
}

.content {
  /* Top padding is two ruled lines, so the ruling lines up with the text. */
  padding: calc(var(--rule) * 2) var(--pad-x) var(--rule);
  flex: 1 1 auto;
}

.ruled {
  background-image: linear-gradient(
    transparent calc(var(--rule) - 1px),
    var(--line-color) calc(var(--rule) - 1px),
    var(--line-color) var(--rule),
    transparent var(--rule)
  );
  background-size: 100% var(--rule);
  background-origin: content-box;
}

@media (max-width: 520px) {
  .content {
    padding-top: var(--rule);
  }
}

/* --- The list at the top of a card --------------------------------------- */

.index-list {
  list-style: none;
  margin-bottom: var(--rule);
}

.entry {
  display: flex;
  align-items: baseline;
  gap: clamp(10px, 2vw, 18px);
  min-height: var(--rule);
  line-height: var(--rule);
}

/* Small left-hand label — "Email", "Address". Blank on continuation lines,
   where it only holds the indent. */
.entry-label {
  flex: 0 0 var(--label-col);
  font-size: var(--fs-small);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--dim);
}

.entry-text {
  flex: 1 1 auto;
  min-width: 0;
}

/* An entry with no label gets a drawn dash instead: it marks the line as a
   list item and hangs the indent, without adding a number and without adding
   anything a screen reader has to read out. */
.entry > .entry-text:first-child {
  position: relative;
  padding-left: 1.7em;
}

.entry > .entry-text:first-child::before {
  content: '';
  position: absolute;
  left: 0;
  top: calc(var(--rule) / 2 - 1px);
  width: 0.85em;
  height: 2px;
  background: var(--dim);
}

/* --- Prose --------------------------------------------------------------- */

.prose {
  color: var(--prose);
  /* Keep the measure readable on wide screens; the ruling still runs edge to
     edge, so the card does not look narrower than it is. */
  max-width: 72ch;
}

.prose p {
  line-height: var(--rule);
  margin-bottom: var(--rule);
}

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

.prose a,
.entry a {
  color: var(--white);
  text-decoration-thickness: 1px;
  text-underline-offset: 4px;
  transition: color 0.15s ease;
}

.prose a:hover,
.entry a:hover {
  color: var(--red);
}

.prose a:focus-visible,
.entry a:focus-visible {
  outline: var(--border) solid var(--white);
  outline-offset: 3px;
  text-decoration: none;
}

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

.card > footer {
  background: var(--white);
  color: var(--black);
  padding: 14px var(--pad-x);
  font-size: var(--fs-small);
  line-height: 1.3;
  font-weight: bold;
  text-transform: uppercase;
  letter-spacing: clamp(1px, 0.3vw, 2px);
  position: relative;
}

/* --- Utilities ----------------------------------------------------------- */

.skip-link {
  position: absolute;
  top: -100px;
  left: var(--gutter);
  background: var(--white);
  color: var(--black);
  padding: 12px 20px;
  text-decoration: none;
  font-size: var(--fs-small);
  text-transform: uppercase;
  letter-spacing: 2px;
  z-index: 1000;
}

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

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

[hidden] {
  display: none !important;
}

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

/* --- Print --------------------------------------------------------------- */

@media print {
  .tab-strip,
  .skip-link,
  .hole,
  .corner {
    display: none;
  }

  /* On paper there is no viewport to fill: cards take the height of their
     text, so the logo and the first card share the first page. */
  .site {
    display: block;
    min-height: 0;
    max-width: none;
    padding: 0;
  }

  .masthead {
    position: static;
    margin-bottom: 12px;
  }

  .tabs-wrapper,
  .card,
  .content {
    display: block;
    flex: none;
  }

  .card[hidden] {
    display: block !important;
  }

  /* White keys on transparent would be invisible on white paper. */
  .logo img {
    filter: invert(1);
    width: 120px;
  }

  /* A card can be longer than a page, so it may break; a line of text may not.
     Forcing the whole card to stay together left the first page nearly empty. */
  .card {
    border-color: #000;
    background: #fff;
    color: #000;
    margin-bottom: 16px;
  }

  .entry,
  .prose p {
    break-inside: avoid;
  }

  .card::before,
  .card > footer::before,
  .ruled {
    background: none;
  }

  .card > footer {
    background: #fff;
    color: #000;
    border-top: 2px solid #000;
  }

  .entry-label,
  .prose {
    color: #333;
  }

  .entry > .entry-text:first-child::before {
    background: #333;
  }

  body {
    background: #fff;
    color: #000;
  }

  .prose a,
  .entry a {
    color: #000;
  }
}
