/* Self-hosted variable fonts (latin subset), SIL OFL 1.1 - see fonts/OFL-*.txt */
@font-face {
  font-family: 'Syne';
  font-style: normal;
  font-weight: 700 800;
  font-display: swap;
  src: url('fonts/syne-latin.woff2') format('woff2');
}

@font-face {
  font-family: 'Geist';
  font-style: normal;
  font-weight: 400 600;
  font-display: swap;
  src: url('fonts/geist-latin.woff2') format('woff2');
}

@font-face {
  font-family: 'Geist Mono';
  font-style: normal;
  font-weight: 400 500;
  font-display: swap;
  src: url('fonts/geist-mono-latin.woff2') format('woff2');
}

:root {
  --bg: #f6f5f9;
  --card: #ffffff;
  --ink: #16141d;
  --muted: #5d596c;
  --line: #e2dfea;
  --track: #eceaf2;
  --link-hover: #732982;
  --spectrum-end: #d9d6e2;
  --sheen: rgba(22, 20, 29, 0.35);
  --token-mix: 40%;
  --token-edge: rgba(22, 20, 29, 0.07);
  --error: #b3261e;
  --error-bg: rgba(179, 38, 30, 0.08);

  --font-display: 'Syne', ui-sans-serif, system-ui, sans-serif;
  --font-body: 'Geist', ui-sans-serif, system-ui, sans-serif;
  --font-mono: 'Geist Mono', ui-monospace, SFMono-Regular, Menlo, monospace;

  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b0a10;
    --card: #15141c;
    --ink: #efedf7;
    --muted: #9c98af;
    --line: #2a2834;
    --track: #24212d;
    --link-hover: #c9a2ec;
    --spectrum-end: #efedf7;
    --sheen: rgba(239, 237, 247, 0.45);
    --token-mix: 50%;
    --token-edge: rgba(239, 237, 247, 0.08);
    --error: #ffb4ab;
    --error-bg: rgba(255, 180, 171, 0.08);
  }
}

html {
  scroll-behavior: smooth;
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.5;
}

a {
  color: var(--ink);
  text-decoration: none;
}

a:hover {
  color: var(--link-hover);
}

code,
.mono {
  font-family: var(--font-mono);
}

code {
  font-size: 0.875em;
}

.muted {
  color: var(--muted);
  font-size: 0.875rem;
}

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

.page {
  box-sizing: border-box;
  padding: 32px clamp(16px, 6vw, 80px) 80px;
  display: flex;
  flex-direction: column;
  gap: 48px;
}

/* Everything keeps a readable width, apart from the model cards, which fill wide screens with more columns */
.page > * {
  box-sizing: border-box;
  width: 100%;
  max-width: 1120px;
  margin-inline: auto;
}


.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 24px;
}

.section-title {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.375rem;
}

/* Buttons */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  height: 44px;
  padding: 0 20px;
  background: var(--ink);
  color: var(--card);
  border: 0;
  border-radius: 999px;
  font-family: inherit;
  font-size: 0.9375rem;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  transition: opacity 0.2s;
}

.btn:hover {
  opacity: 0.85;
}

.btn:focus-visible,
.icon-btn:focus-visible,
.pill-link:focus-visible,
#counts a:focus-visible,
summary:focus-visible {
  outline: 2px solid var(--link-hover);
  outline-offset: 2px;
}

.icon-btn {
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  cursor: pointer;
  transition: color 0.2s, border-color 0.2s;
}

.icon-btn:hover {
  color: var(--error);
  border-color: currentColor;
}

/* Navigation */

.topnav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
}

.pill-link {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 44px;
  padding: 0 18px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--card);
  font-size: 0.875rem;
  font-weight: 500;
  white-space: nowrap;
}

.spectrum {
  display: flex;
  height: 10px;
  width: 220px;
  border-radius: 999px;
  overflow: hidden;
}

.spectrum span {
  flex-grow: 1;
  background: var(--c);
}

@media (max-width: 720px) {
  .spectrum {
    display: none;
  }
}

@media (max-width: 480px) {
  .wide-only {
    display: none;
  }
}

/* Hero: the title tokenised by three vocabularies */

.hero {
  display: flex;
  flex-direction: column;
  gap: 32px;
}

.title {
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
  line-height: 1.25;
}

.title-row {
  display: grid;
  grid-template-columns: 7.5rem minmax(0, 1fr);
  gap: 24px;
  align-items: center;
}

.title-model {
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--muted);
  text-align: right;
}

/* The type scales with the row's own width so "Online LLM Tokenizer" never wraps or clips */
.title-tokens {
  min-width: 0;
  container-type: inline-size;
}

.title ruby {
  ruby-position: under;
  white-space: pre;
  margin-right: 0.1em;
}

.title ruby > span {
  font-size: clamp(1rem, 4.9cqi, 3rem);
  font-family: var(--font-display);
  font-weight: 800;
  letter-spacing: -0.03em;
  padding: 0 0.13em;
  border-radius: 0.2em;
  background: color-mix(in srgb, var(--c) var(--token-mix), transparent);
}

.title rt {
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  font-weight: 500;
  letter-spacing: 0;
  color: var(--muted);
  padding-top: 8px;
}

.intro {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 48px;
  padding-left: calc(7.5rem + 24px);
}

.intro p {
  margin: 0;
  text-wrap: pretty;
}

.intro-lead {
  font-size: 1.25rem;
  line-height: 1.55;
  font-weight: 500;
}

.intro-note {
  color: var(--muted);
  line-height: 1.6;
}

@media (max-width: 900px) {
  .intro {
    grid-template-columns: minmax(0, 1fr);
    gap: 16px;
    padding-left: 0;
  }
}

@media (max-width: 640px) {
  .title-row {
    grid-template-columns: minmax(0, 1fr);
    gap: 2px;
  }

  .title-model {
    text-align: left;
  }
}

/* Input */

.input-card {
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 28px clamp(20px, 3vw, 32px);
  border-radius: 28px;
}

.input-card-head,
.input-card-foot {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
}

.input-card-foot {
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

textarea#textInput {
  box-sizing: border-box;
  width: 100%;
  min-height: 5em;
  /* Long texts scroll inside, so the tokens stay close by */
  max-height: 40vh;
  padding: 0;
  overflow-y: auto;
  /* Grows with its text; tokenizer.js resizes it by hand where this isn't supported */
  field-sizing: content;
  resize: none;
  background: transparent;
  color: var(--ink);
  border: 0;
  outline: none;
  font-family: var(--font-mono);
  /* Not below 16px, or iOS zooms in on focus */
  font-size: 1rem;
  line-height: 1.55;
}

#shareBtn.copied {
  background: #008026;
  color: #ffffff;
}

/* Token count overview */

.counts {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* The rows share one grid, so the count column fits the longest count and the bars keep the same scale */
#counts {
  margin: 0 -12px;
  padding: 0;
  list-style: none;
  display: grid;
  grid-template-columns: minmax(0, 21rem) minmax(0, 1fr) max-content;
  gap: 4px 24px;
}

#counts li {
  display: grid;
  grid-column: 1 / -1;
  grid-template-columns: subgrid;
}

#counts a,
#counts .count-row {
  display: grid;
  grid-column: 1 / -1;
  grid-template-columns: subgrid;
  grid-template-areas: 'name bar count';
  row-gap: 8px;
  align-items: center;
  min-height: 44px;
  padding: 0 12px;
  border-radius: 12px;
}

#counts a:hover {
  background: var(--card);
  color: var(--ink);
}

#counts a:hover .count-name {
  text-decoration: underline;
  text-underline-offset: 3px;
}

.count-name {
  grid-area: name;
  font-size: 0.9375rem;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.count-bar {
  grid-area: bar;
  position: relative;
  overflow: hidden;
  height: 14px;
  border-radius: 999px;
  background: var(--track);
}

.count-bar > span {
  display: block;
  height: 100%;
  border-radius: 999px;
  background: var(--ink);
  transition:
    width 0.3s ease-out,
    opacity 0.2s;
}

.count-bar.pending {
  background: repeating-linear-gradient(90deg, var(--track) 0 14px, transparent 14px 22px);
}

.count-value {
  grid-area: count;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1.625rem;
  text-align: right;
}

.count-status {
  grid-area: count;
  font-size: 0.875rem;
  color: var(--muted);
  text-align: right;
}

.count-status.error {
  color: var(--error);
}

/* While a model re-tokenises, its old count fades and a sheen sweeps along the bar */
.count-value {
  transition: opacity 0.2s;
}

#counts .processing .count-bar > span,
#counts .processing .count-value {
  opacity: 0.4;
}

#counts .processing .count-bar::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent, var(--sheen), transparent);
  animation: sweep 1.1s ease-in-out infinite;
}

@keyframes sweep {
  from {
    transform: translateX(-100%);
  }

  to {
    transform: translateX(100%);
  }
}

@media (prefers-reduced-motion: reduce) {
  #counts .processing .count-bar::after {
    animation: none;
    display: none;
  }

  .count-bar > span {
    transition: opacity 0.2s;
  }
}

@media (max-width: 720px) {
  #counts {
    grid-template-columns: minmax(0, 1fr) max-content;
  }

  #counts a,
  #counts .count-row {
    grid-template-areas: 'name count' 'bar bar';
    padding: 8px 12px;
  }
}

/* Model cards: fill the page's full width with as many 29.5rem+ columns as fit (two from a 1100px viewport) */

.page > .models {
  max-width: none;
  display: flex;
  flex-direction: column;
}

/* Sticks to the bottom right while the cards are in view, hidden above them and settling below the last one */
.to-counts {
  position: sticky;
  bottom: 16px;
  align-self: flex-end;
  margin-top: 16px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
}

.counts {
  scroll-margin-top: 16px;
}

ul#models {
  max-width: none;
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 29.5rem), 1fr));
  gap: 24px;
  align-items: start;
}

.model-card {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 24px clamp(20px, 3vw, 28px) 28px;
  /* Less than the grid gap, so the row above is fully out of view and can't become the scroll anchor:
     its cards are re-rendered as their tokens arrive, which loses the anchor and lets this card drift away */
  scroll-margin-top: 16px;
}

.model-card:target {
  animation: highlight 1.8s ease-out;
}

@keyframes highlight {
  from {
    box-shadow: 0 0 0 3px var(--ink);
  }

  to {
    box-shadow: 0 0 0 3px transparent;
  }
}

.model-card.loading {
  background: transparent;
  border: 1.5px dashed var(--line);
}

.model-header {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
}

/* On narrow cards the count moves below the name rather than squeezing it to a few letters per line */
.model-name {
  flex: 1 1 10rem;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.model-org {
  font-size: 0.875rem;
  color: var(--muted);
}

.model-name h2 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.model-meta {
  display: flex;
  align-items: baseline;
  gap: 12px;
  flex-shrink: 0;
  margin-left: auto;
}

/* Each card's remove button hovers in the next colour of the spectrum */
#models > li:nth-child(9n + 1) { --accent: #E40303; }
#models > li:nth-child(9n + 2) { --accent: #FF8C00; }
#models > li:nth-child(9n + 3) { --accent: #FFED00; }
#models > li:nth-child(9n + 4) { --accent: #008026; }
#models > li:nth-child(9n + 5) { --accent: #061393; }
#models > li:nth-child(9n + 6) { --accent: #732982; }
#models > li:nth-child(9n + 7) { --accent: #5BCEFA; }
#models > li:nth-child(9n + 8) { --accent: #F5A9B8; }
#models > li:nth-child(9n + 9) { --accent: #8F3F2B; }

/* Mixed towards the text colour, so navy stays visible on dark and yellow on light */
.remove-btn:hover {
  color: color-mix(in oklab, var(--accent, var(--error)) 70%, var(--ink));
}

.model-count {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
}

.model-count strong {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(2.25rem, 1.5rem + 2.5vw, 2.75rem);
  line-height: 1;
}

.model-count span {
  font-size: 0.8125rem;
  color: var(--muted);
}

.skeleton {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.skeleton span {
  height: 34px;
  border-radius: 6px;
  background: var(--track);
  animation: pulse 1.4s ease-in-out infinite alternate;
}

@keyframes pulse {
  to {
    opacity: 0.45;
  }
}

.model-error {
  margin: 0;
  padding: 16px;
  white-space: pre-line;
  font-family: var(--font-mono);
  font-size: 0.875rem;
  color: var(--error);
  background: var(--error-bg);
  border-radius: 12px;
}

/* Tokens: text above, token ID below */

.tokens {
  /* Sets the height of the empty lines that blank lines in the text leave */
  line-height: 1.5;
  overflow-wrap: anywhere;
  tab-size: 2;
}

/* A column rather than ruby layout: Firefox takes ~40x longer to lay out thousands of rubies with preserved spaces */
.tokens ruby {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  vertical-align: top;
  margin: 2px 3px 2px 0;
  white-space: pre;
}

.tokens ruby > span {
  line-height: 1.3;
  font-family: var(--font-mono);
  font-size: clamp(0.875rem, 0.75rem + 0.3vw, 1rem);
  padding: 3px;
  border-radius: 6px;
  background: color-mix(in srgb, var(--c) var(--token-mix), transparent);
  box-shadow: inset 0 0 0 1px var(--token-edge);
}

.tokens rt {
  display: block;
  margin-top: -5px;
  line-height: 1.3;
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  color: var(--muted);
  padding-top: 6px;
}

.clean-up-toggle {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px 8px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
  font-size: 0.8125rem;
  cursor: pointer;
}

.clean-up-toggle input {
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: var(--ink);
  cursor: pointer;
}

.clean-up-toggle input:focus-visible {
  outline: 2px solid var(--link-hover);
  outline-offset: 2px;
}

/* Add model */

.add-model {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 10px 10px 10px 28px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 999px;
}

.add-model label {
  font-size: 0.9375rem;
  font-weight: 600;
  white-space: nowrap;
}

.add-model input {
  flex-grow: 1;
  min-width: 0;
  height: 48px;
  padding: 0 16px;
  background: var(--bg);
  color: var(--ink);
  border: 0;
  border-radius: 999px;
  font-size: 1rem;
}

.add-model .btn {
  height: 48px;
}

@media (max-width: 720px) {
  .add-model {
    flex-wrap: wrap;
    padding: 16px;
    border-radius: 24px;
  }

  .add-model label {
    width: 100%;
  }

  .add-model .btn {
    width: 100%;
    justify-content: center;
  }
}

/* About */

.about {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 24px;
  align-items: start;
}

@media (max-width: 900px) {
  .about {
    grid-template-columns: minmax(0, 1fr);
  }
}

.about details {
  border-radius: 20px;
}

.about summary {
  display: flex;
  justify-content: space-between;
  align-items: center;
  min-height: 64px;
  padding: 0 24px;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.25rem;
  cursor: pointer;
  list-style: none;
}

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

.about summary .icon {
  transition: transform 0.2s;
}

.about details[open] summary .icon {
  transform: rotate(180deg);
}

.about ul {
  margin: 0;
  padding: 0 24px 24px 44px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  color: var(--muted);
  line-height: 1.55;
}

.about strong {
  color: var(--ink);
  font-weight: 600;
}
