@font-face {
  font-family: 'Archivo';
  src: url('/fonts/archivo-latin.woff2') format('woff2');
  font-weight: 100 900;
  font-stretch: 62% 125%;
  font-style: normal;
  font-display: swap;
}

/* Tokens. Navy ink on white paper; the yellow is the measuring tape and nothing else. */
:root {
  color-scheme: light;
  --paper: #ffffff;
  --paper-2: #f3f4f8;
  --ink: #151b3c;
  --ink-2: #4a5072;
  --ink-3: #656b8c;
  --line: #e3e5ee;
  --line-strong: #868cab;
  --axis: #c8cbd9;
  --tape: #ffc93c;
  --tape-ink: #151b3c;
  --hook: #151b3c;
  --series: #b07f00;
  --series-active: #8a6400;
  --danger: #c0303c;
  --danger-ink: #ffffff;
  --button-bg: #151b3c;
  --button-bg-hover: #2c3563;
  --button-ink: #ffffff;
  --focus: #151b3c;
  --tooltip-bg: #151b3c;
  --tooltip-ink: #ffffff;
  --backdrop: rgb(21 27 60 / 0.45);

  --font: 'Archivo', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --radius-control: 10px;
  --radius-panel: 18px;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --paper: #10142b;
    --paper-2: #181d3a;
    --ink: #eef0f8;
    --ink-2: #b9bed6;
    --ink-3: #8e94b3;
    --line: #262c4d;
    --line-strong: #636b98;
    --axis: #3a4170;
    --hook: #c9cde0;
    --series: #c98500;
    --series-active: #e3a019;
    --danger: #ff8a93;
    --danger-ink: #151b3c;
    --button-bg: #eef0f8;
    --button-bg-hover: #c9cde0;
    --button-ink: #151b3c;
    --focus: #ffc93c;
    --tooltip-bg: #eef0f8;
    --tooltip-ink: #151b3c;
    --backdrop: rgb(4 6 18 / 0.72);
  }
}

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

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

body {
  margin: 0;
  min-height: 100vh;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body:has(dialog[open]) { overflow: hidden; }

h1, h2, h3, p, dl, dd, figure { margin: 0; }
a { color: inherit; }
button, input, select { font: inherit; color: inherit; }
[hidden] { display: none !important; }
::selection { background: var(--tape); color: #151b3c; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

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

.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }

.icon {
  flex: none;
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.wrap { width: min(100% - 32px, 880px); margin-inline: auto; }

/* Header */
.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding-block: 20px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  font-size: 22px;
  font-weight: 750;
  font-stretch: 75%;
  letter-spacing: 0.01em;
  text-decoration: none;
}

.brand-tape { fill: var(--tape); }
.brand-ticks { fill: none; stroke: var(--tape-ink); stroke-width: 1.5; }
.brand-hook { fill: var(--hook); }

.header-link {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  color: var(--ink-2);
  font-weight: 600;
  text-decoration: none;
}

.header-link:hover { color: var(--ink); }

.count {
  min-width: 26px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--paper-2);
  color: var(--ink);
  font-size: 13px;
  line-height: 1.3;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

/* Hero form */
.shorten { padding-top: clamp(24px, 7vh, 80px); }

.shorten h1 {
  font-size: clamp(40px, 10.4vw, 78px);
  font-weight: 800;
  font-stretch: 62%;
  line-height: 0.93;
  letter-spacing: -0.01em;
}

.shorten h1 span { display: block; }

.shorten-form { margin-top: clamp(24px, 4.5vh, 40px); }

.field-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-areas:
    "input submit"
    "tape  .";
  column-gap: 10px;
}

.url-input {
  grid-area: input;
  width: 100%;
  height: 62px;
  padding: 0 18px;
  border: 1.5px solid var(--line-strong);
  border-radius: var(--radius-control);
  background: var(--paper);
  font-size: 19px;
  font-stretch: 87.5%;
  transition: border-color 0.15s;
}

.url-input::placeholder { color: var(--ink-3); opacity: 1; }
.url-input:hover { border-color: var(--ink-2); }

/* Text fields show focus as a thicker border in the focus colour, not a second ring. */
.url-input:focus-visible,
.select:focus-visible,
.input:focus-visible,
.affix:focus-within {
  outline: none;
  border-color: var(--focus);
  box-shadow: 0 0 0 1.5px var(--focus);
}

.url-input[aria-invalid="true"],
.input[aria-invalid="true"],
.affix:has([aria-invalid="true"]) { border-color: var(--danger); box-shadow: 0 0 0 1.5px var(--danger); }

.field-row .button-large { grid-area: submit; }

/* The measuring tape: pulls out to the length of the link being typed,
   and snaps back to the short link's length once it's made. */
.tape {
  grid-area: tape;
  position: relative;
  height: 70px; /* room for the reading that hangs under the tape */
  padding-top: 14px;
}

.tape-track { position: relative; height: 22px; }

.tape-track::before {
  content: '';
  position: absolute;
  top: 50%;
  right: 0;
  left: 0;
  border-top: 1px solid var(--line);
}

.tape-strip {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: 0;
  border-radius: 2px 0 0 2px;
  background: var(--tape);
  box-shadow: inset 0 -2px 0 rgb(21 27 60 / 0.1);
  transition: width 0.16s ease-out;
}

/* the metal hook at the tape's end */
.tape-strip::after {
  content: '';
  position: absolute;
  top: -5px;
  right: -3px;
  bottom: -5px;
  width: 3px;
  border-radius: 1.5px;
  background: var(--hook);
}

.tape-strip.is-snapping { transition: width 0.8s cubic-bezier(0.25, 1.5, 0.45, 1); }

.tape-clip {
  position: absolute;
  inset: 0;
  overflow: hidden;
  border-radius: inherit;
}

.tape-ruler { position: absolute; top: 0; left: 0; }
.tape-ticks { fill: none; stroke: var(--tape-ink); stroke-width: 1; shape-rendering: crispEdges; }

.tape-ruler text {
  fill: var(--tape-ink);
  font-size: 9.5px;
  font-weight: 650;
  font-stretch: 75%;
}

.tape-reading {
  position: absolute;
  top: calc(100% + 7px);
  left: 100%;
  margin-left: -2px;
  color: var(--ink-2);
  font-size: 14px;
  font-stretch: 87.5%;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.tape-strip.reading-before .tape-reading { right: -3px; left: auto; margin-left: 0; }
.tape-strip.reading-start .tape-reading { left: 0; margin-left: 0; }

.form-error {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  color: var(--danger);
  font-weight: 550;
}

.form-error .icon { margin-top: 3px; }

/* Alias & expiry */
.options { margin-top: 8px; }

.options summary {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  color: var(--ink-2);
  font-weight: 600;
  cursor: pointer;
  list-style: none;
}

.options summary::-webkit-details-marker { display: none; }

.options summary::before {
  content: '';
  width: 7px;
  height: 7px;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(-45deg);
  transition: transform 0.15s;
}

.options[open] summary::before { margin-top: -4px; transform: rotate(45deg); }
.options summary:hover { color: var(--ink); }

.options-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.7fr) minmax(0, 1fr);
  gap: 16px 20px;
  padding: 6px 0 4px;
}

.field label {
  display: block;
  margin-bottom: 6px;
  font-size: 14px;
  font-weight: 600;
}

.optional { color: var(--ink-3); font-weight: 400; }

.help { margin-top: 6px; color: var(--ink-3); font-size: 13px; }

.field-wide { grid-column: 1 / -1; }

.affix,
.select,
.input {
  height: 48px;
  border: 1.5px solid var(--line-strong);
  border-radius: var(--radius-control);
  background: var(--paper);
}

.input { width: 100%; max-width: 420px; padding: 0 14px; font-stretch: 87.5%; }

.affix { display: flex; overflow: hidden; }
.affix:hover, .select:hover, .input:hover { border-color: var(--ink-2); }

.affix-prefix {
  flex: none;
  max-width: 60%;
  padding-left: 14px;
  overflow: hidden;
  color: var(--ink-3);
  font-stretch: 87.5%;
  line-height: 45px;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.affix input {
  flex: 1;
  min-width: 0;
  padding: 0 14px 0 1px;
  border: 0;
  background: transparent;
  font-stretch: 87.5%;
}

.affix input:focus { outline: none; }

.select-wrap { position: relative; }

.select-wrap::after {
  content: '';
  position: absolute;
  top: 50%;
  right: 18px;
  width: 7px;
  height: 7px;
  border-right: 2px solid var(--ink-2);
  border-bottom: 2px solid var(--ink-2);
  transform: translateY(-70%) rotate(45deg);
  pointer-events: none;
}

.select {
  width: 100%;
  padding: 0 44px 0 14px;
  appearance: none;
  cursor: pointer;
}

/* Buttons */
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 18px;
  border: 1.5px solid var(--line-strong);
  border-radius: var(--radius-control);
  background: transparent;
  color: var(--ink);
  font-size: 15px;
  font-weight: 600;
  line-height: 1.1;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  transition: background-color 0.15s, border-color 0.15s, color 0.15s;
}

.button:hover { border-color: var(--ink); }
.button:disabled { opacity: 0.65; cursor: progress; }

.button-primary { border-color: var(--button-bg); background: var(--button-bg); color: var(--button-ink); }
.button-primary:hover { border-color: var(--button-bg-hover); background: var(--button-bg-hover); }

.button-large { min-width: 9.5em; height: 62px; padding: 0 26px; font-size: 17px; }
.button-small { min-height: 40px; padding: 0 14px; font-size: 14px; }

.button-danger { border-color: currentColor; color: var(--danger); }
.button-danger:hover { border-color: currentColor; background: color-mix(in srgb, var(--danger) 10%, transparent); }

.button-danger-solid { border-color: var(--danger); background: var(--danger); color: var(--danger-ink); }
.button-danger-solid:hover { border-color: var(--danger); background: color-mix(in srgb, var(--danger) 85%, var(--ink)); }

.text-button {
  min-height: 32px;
  padding: 0;
  border: 0;
  background: none;
  color: var(--ink-2);
  font-size: 14px;
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}

.text-button:hover { color: var(--ink); }

.icon-button {
  display: inline-grid;
  place-items: center;
  width: 44px;
  height: 44px;
  margin: -8px -10px 0 0;
  border: 0;
  border-radius: 10px;
  background: none;
  color: var(--ink-2);
  cursor: pointer;
}

.icon-button:hover { background: var(--paper-2); color: var(--ink); }
.icon-button .icon { width: 22px; height: 22px; }

/* Result */
.result {
  margin-top: 16px;
  padding: clamp(20px, 3.6vw, 30px);
  border-radius: var(--radius-panel);
  background: var(--paper-2);
}

.result-link {
  display: inline-block;
  max-width: 100%;
  font-size: clamp(24px, 4.8vw, 38px);
  font-weight: 600;
  font-stretch: 112.5%;
  line-height: 1.15;
  letter-spacing: -0.01em;
  text-decoration: none;
  overflow-wrap: anywhere;
}

.result-link:hover { text-decoration: underline; text-decoration-thickness: 2px; text-underline-offset: 5px; }

.result-origin {
  margin-top: 8px;
  overflow: hidden;
  color: var(--ink-3);
  font-stretch: 75%;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 20px; }

/* QR stays dark-on-white in both themes so it always scans. */
.qr {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 14px 24px;
  width: fit-content;
  max-width: 100%;
  margin-top: 16px;
  padding: 14px 22px 14px 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #ffffff;
  color: #151b3c;
}

.qr img { display: block; width: 168px; height: 168px; }
.qr-text { display: grid; gap: 10px; max-width: 26ch; font-size: 14px; }
.qr-text a { font-weight: 650; text-underline-offset: 3px; }
.qr :focus-visible { outline-color: #151b3c; }

/* My links */
.my-links { margin-top: clamp(56px, 11vh, 104px); scroll-margin-top: 24px; }

.section-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 4px 20px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
}

.section-head h2 {
  font-size: 32px;
  font-weight: 750;
  font-stretch: 75%;
  line-height: 1.1;
}

.section-head h2:focus { outline: none; }
.section-note { color: var(--ink-3); font-size: 14px; }

.link-list { margin: 0; padding: 0; list-style: none; }

.link-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 10px 22px;
  padding: 14px 0;
  border-bottom: 1px solid var(--line);
}

.link-open {
  display: grid;
  gap: 2px;
  min-width: 0;
  margin: -8px -10px;
  padding: 8px 10px;
  border: 0;
  border-radius: 10px;
  background: none;
  text-align: left;
  cursor: pointer;
}

.link-open:hover { background: var(--paper-2); }

.link-code {
  font-size: 19px;
  font-weight: 600;
  font-stretch: 112.5%;
  line-height: 1.3;
  overflow-wrap: anywhere;
}

.link-target {
  overflow: hidden;
  color: var(--ink-2);
  font-stretch: 75%;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.link-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0 12px;
  color: var(--ink-3);
  font-size: 13px;
}

.status-expired {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--danger);
  font-weight: 600;
}

.status-expired .icon { width: 14px; height: 14px; }

.link-clicks {
  color: var(--ink-3);
  font-size: 13px;
  line-height: 1.2;
  text-align: right;
  white-space: nowrap;
}

.link-clicks strong {
  display: block;
  color: var(--ink);
  font-size: 22px;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
}

.empty { padding: 28px 0; color: var(--ink-2); }

.site-footer {
  margin-top: clamp(64px, 12vh, 120px);
  padding-block: 22px 40px;
  border-top: 1px solid var(--line);
  color: var(--ink-3);
  font-size: 14px;
}

/* Link detail dialog */
.detail {
  width: min(100% - 24px, 780px);
  max-width: none;
  max-height: calc(100% - 24px);
  margin: auto;
  padding: 0;
  overflow: auto;
  overscroll-behavior: contain;
  border: 0;
  border-radius: var(--radius-panel);
  background: var(--paper);
  color: var(--ink);
  box-shadow: 0 24px 80px rgb(0 0 0 / 0.3);
}

.detail::backdrop { background: var(--backdrop); }
.detail[open] { animation: detail-in 0.2s ease-out; }

@keyframes detail-in {
  from { opacity: 0; transform: translateY(12px); }
}

.detail-inner { padding: clamp(20px, 4vw, 32px); }

.detail-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
  gap: 16px;
}

.detail-title {
  font-size: clamp(22px, 4.2vw, 30px);
  font-weight: 600;
  font-stretch: 112.5%;
  line-height: 1.2;
  overflow-wrap: anywhere;
}

.detail-target {
  display: -webkit-box;
  margin-top: 8px;
  overflow: hidden;
  color: var(--ink-2);
  font-stretch: 75%;
  overflow-wrap: anywhere;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
}

.detail-meta { margin-top: 4px; color: var(--ink-3); font-size: 14px; }

.detail-error {
  margin-top: 24px;
  padding: 14px 16px;
  border-radius: 12px;
  background: var(--paper-2);
  color: var(--danger);
  font-weight: 550;
}

.stats { margin-top: 28px; transition: opacity 0.2s; }
.stats.is-loading { opacity: 0.45; }

.tiles {
  display: grid;
  grid-template-columns: 1.35fr repeat(3, minmax(0, 1fr));
  border-block: 1px solid var(--line);
}

.tile {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 16px 0 16px 18px;
  border-left: 1px solid var(--line);
}

.tile:first-child { padding-left: 0; border-left: 0; }
.tile dt { color: var(--ink-3); font-size: 13px; }
.tile dd { font-size: 26px; font-weight: 650; line-height: 1.15; }
.tile-hero dd { font-size: 52px; font-weight: 700; line-height: 1; letter-spacing: -0.02em; }
.tile-text dd { font-size: 18px; font-weight: 600; }

.tile-note {
  display: block;
  margin-top: 2px;
  color: var(--ink-3);
  font-size: 12px;
  font-weight: 400;
  line-height: 1.3;
}

.chart { margin-top: 32px; }

.chart-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 4px 16px;
  margin-bottom: 12px;
}

.chart-title,
.breakdown h3 { font-size: 16px; font-weight: 650; }

.chart-plot { position: relative; }
.chart-plot svg { display: block; overflow: visible; }
.chart-plot svg:focus-visible { outline-offset: 4px; border-radius: 4px; }
.chart-grid { stroke: var(--line); shape-rendering: crispEdges; }
.chart-baseline { stroke: var(--axis); shape-rendering: crispEdges; }
.chart-label { fill: var(--ink-3); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart-value { fill: var(--ink); font-size: 12px; font-weight: 650; font-variant-numeric: tabular-nums; }
.chart-value.is-covered { visibility: hidden; }
.chart-bar { fill: var(--series); }
.chart-bar.is-active { fill: var(--series-active); }
.chart-hit { fill: transparent; }

.chart-empty {
  padding: 40px 16px;
  border-block: 1px solid var(--line);
  color: var(--ink-3);
  text-align: center;
}

.chart-tooltip {
  position: absolute;
  z-index: 1;
  padding: 7px 10px;
  border-radius: 8px;
  background: var(--tooltip-bg);
  color: var(--tooltip-ink);
  font-size: 13px;
  line-height: 1.35;
  white-space: nowrap;
  pointer-events: none;
  transform: translate(-50%, calc(-100% - 10px));
}

.chart-tooltip strong { display: block; font-size: 15px; font-weight: 700; }
.chart-tooltip span { opacity: 0.8; }

.chart-table {
  width: 100%;
  margin-top: 16px;
  border-collapse: collapse;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}

.chart-table th { color: var(--ink-3); font-weight: 600; }

.chart-table th,
.chart-table td { padding: 7px 0; border-bottom: 1px solid var(--line); text-align: left; }

.chart-table :is(th, td):last-child { text-align: right; }

.breakdowns {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 32px 40px;
  margin-top: 36px;
}

.breakdown h3 { margin-bottom: 12px; }
.breakdown .help { margin-top: 12px; }

.bars { display: grid; gap: 12px; margin: 0; padding: 0; list-style: none; }
.bars li { display: grid; gap: 4px; }

.bar-name { overflow: hidden; font-size: 14px; white-space: nowrap; text-overflow: ellipsis; }
.bar-row { display: flex; align-items: center; gap: 8px; }

.bar-fill {
  flex: none;
  width: calc((100% - 52px) * var(--share, 0));
  min-width: 3px;
  height: 8px;
  border-radius: 0 4px 4px 0;
  background: var(--series);
}

.bar-count { color: var(--ink-2); font-size: 14px; font-weight: 600; font-variant-numeric: tabular-nums; }
.bars-empty { color: var(--ink-3); font-size: 14px; }

.detail-foot { margin-top: 36px; padding-top: 20px; border-top: 1px solid var(--line); }
.confirm { display: grid; gap: 12px; }
.confirm p { font-weight: 550; }
.confirm-actions { display: flex; flex-wrap: wrap; gap: 8px; }

/* Server-rendered 404 / expired pages */
.message-page { padding-block: clamp(40px, 14vh, 140px) 96px; }

.message-page h1 {
  font-size: clamp(40px, 9vw, 72px);
  font-weight: 800;
  font-stretch: 62%;
  line-height: 0.95;
}

.message-page p { max-width: 50ch; margin-top: 18px; color: var(--ink-2); font-size: 18px; }
.message-page strong { color: var(--ink); overflow-wrap: anywhere; }
.message-page .button { margin-top: 28px; }

/* Small screens */
@media (max-width: 600px) {
  .field-row {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas: "input" "tape" "submit";
  }

  .button-large { width: 100%; }
  .options-grid { grid-template-columns: minmax(0, 1fr); }

  /* the main action gets the full row; the other two share the next */
  .actions { display: grid; grid-template-columns: 1fr 1fr; }
  .actions .button-primary { grid-column: 1 / -1; }

  .link-item {
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas: "open open" "clicks copy";
  }

  .link-open { grid-area: open; }
  .link-clicks { grid-area: clicks; text-align: left; }
  .link-clicks strong { display: inline; margin-right: 4px; font-size: 17px; }
  .link-copy { grid-area: copy; }

  .detail {
    width: 100%;
    height: 100%;
    max-height: 100%;
    margin: 0;
    border-radius: 0;
  }

  .tiles { grid-template-columns: 1fr 1fr; }
  .tile:nth-child(3) { padding-left: 0; border-left: 0; }
  .tile:nth-child(n + 3) { border-top: 1px solid var(--line); }
  .tile-hero dd { font-size: 48px; }
  .breakdowns { grid-template-columns: minmax(0, 1fr); }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .tape-strip,
  .tape-strip.is-snapping { transition: none; }
  .detail[open] { animation: none; }
}

@media (forced-colors: active) {
  .tape-strip, .bar-fill { background: Highlight; }
  .tape-strip::after { background: CanvasText; }
  .chart-bar { fill: Highlight; }
}
