:root {
  --clr-bg: #f5f4f1;
  --clr-surface: #ffffff;
  --clr-text: #2c2c2c;
  --clr-text-soft: #888;
  --clr-accent: #6b5cff;
  --clr-accent-light: #eeedff;
  --clr-accent-glow: rgba(107, 92, 255, 0.10);
  --clr-border: #e2e0db;
  --clr-token-bg: #fef3c7;
  --radius: 12px;

  --fs-h1:   clamp(24px, 3.5vw, 36px);
  --fs-h2:   clamp(18px, 2.4vw, 22px);
  --fs-body: clamp(14px, 1.4vw, 15.5px);
  --fs-nav:  clamp(12px, 1.2vw, 13.5px);
  --fs-small: clamp(11px, 1vw, 13px);

  --sp-section: clamp(20px, 4vw, 40px);
  --sp-container-pad: clamp(12px, 3vw, 24px);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
  scroll-padding-top: 72px;
}

@keyframes pageFadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

body {
  margin: 0;
  font-family: "Inter", sans-serif;
  background-color: var(--clr-bg);
  color: var(--clr-text);
  -webkit-font-smoothing: antialiased;
  animation: pageFadeIn 0.35s ease;
}

code {
  background: #e1e1e192;
  color: rgb(118, 118, 118);
  padding: 2px 6px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  font-size: 0.95em;
}

.navbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 32px;
  height: 60px;
  background: rgba(245, 244, 241, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--clr-border);
}

.logo {
  display: flex;
  align-items: center;
  gap: 9px;
  text-decoration: none;
  color: var(--clr-text);
}

.logo:hover { text-decoration: none; }

.logo-icon { width: 28px; height: 28px; object-fit: contain; display: block; }

.logo-text {
  font-size: 24px;
  font-weight: 600;
  letter-spacing: -0.3px;
  color: var(--clr-text);
}

.logo-highlight { color: var(--clr-accent); }

.nav-links {
  display: flex;
  align-items: center;
  gap: 4px;
}

.nav-link {
  font-size: var(--fs-nav);
  font-weight: 450;
  color: var(--clr-text-soft);
  text-decoration: none;
  padding: 7px 14px;
  border-radius: 7px;
  transition: color 0.2s, background 0.2s;
}

.nav-link:hover {
  color: var(--clr-text);
  background: rgba(0, 0, 0, 0.04);
  text-decoration: none;
}

.nav-link.active {
  color: var(--clr-accent);
  background: var(--clr-accent-light);
  font-weight: 500;
}

.container1 {
  max-width: 800px;
  margin: 60px auto 0 auto;
  padding: 20px var(--sp-container-pad);
}

.container2,
.container3 {
  max-width: 800px;
  margin: 20px auto;
  padding: 20px var(--sp-container-pad);
}

.container3 ol {
  max-width: 95%;
  margin: 20px auto;
  padding: 20px 24px;
}

h1 {
  font-weight: 300;
  color: var(--clr-accent);
  font-size: var(--fs-h1);
  margin-bottom: 24px;
  margin-top: var(--sp-section);
  letter-spacing: -0.5px;
}

h2 {
  font-weight: 400;
  color: #3c3c3c;
  font-size: var(--fs-h2);
  margin-top: 36px;
  margin-bottom: 12px;
}

p {
  line-height: 1.75;
  font-size: var(--fs-body);
  margin-bottom: 16px;
  color: #444;
}

.example-text {
  margin-left: 8px;
  font-size: 15px;
}

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

a:hover {
  text-decoration: underline;
}

strong {
  font-weight: 600;
  color: var(--clr-text);
}

ul, ol {
  padding-left: 24px;
  margin-bottom: 16px;
}

ul li, ol li {
  line-height: 1.75;
  font-size: var(--fs-body);
  margin-bottom: 6px;
  color: #444;
}

.algo_names {
  font-weight: 400;
  color: #4a4e8a;
  font-size: 20px;
  margin-top: 16px;
}

.token-box {
  max-width: 50%;
  margin: 80px auto 0 auto;
  padding: 22px 36px;
  background: var(--clr-surface);
  border-radius: var(--radius);
  border: 1px solid var(--clr-border);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.04);
}

.token-box h2 {
  text-align: center;
  margin: 0 0 4px 0;
  font-weight: 300;
  font-size: 28px;
  color: var(--clr-accent);
  letter-spacing: -0.3px;
}

.token-box-subtitle {
  text-align: center;
  margin: 0 0 24px 0;
  font-size: 14px;
  color: var(--clr-text-soft);
  line-height: 1.6;
}

.method-dropdown {
  position: relative;
  margin: 0 auto 12px;
  display: block;
  width: fit-content;
  min-width: 220px;
}

.method-dropdown-btn {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 11px 14px;
  border: 1px solid var(--clr-border);
  border-radius: 8px;
  background: white;
  cursor: pointer;
  font-family: inherit;
  transition: border-color 0.2s;
}
.method-dropdown-btn:hover { border-color: #222; }
.method-dropdown.open .method-dropdown-btn {
  border-color: #222;
  border-radius: 8px 8px 0 0;
}

.method-dropdown-selected {
  display: flex;
  align-items: baseline;
  gap: 8px;
}
.method-dropdown-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--clr-accent);
}
.method-dropdown-full {
  font-size: 12px;
  color: var(--clr-text-soft);
}
.method-dropdown-arrow {
  font-size: 12px;
  color: var(--clr-text-soft);
  transition: transform 0.2s;
}
.method-dropdown.open .method-dropdown-arrow { transform: rotate(180deg); }

.method-dropdown-list {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: white;
  border: 1px solid #222;
  border-top: none;
  border-radius: 0 0 8px 8px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.08);
  z-index: 50;
  overflow: hidden;
  display: none;
}
.method-dropdown.open .method-dropdown-list {
  display: block;
}

.method-option {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border: none;
  background: none;
  cursor: pointer;
  font-family: inherit;
  text-align: left;
  transition: background 0.12s;
  border-bottom: 1px solid var(--clr-border);
}
.method-option:last-child { border-bottom: none; }
.method-option:hover { background: #fafaf9; }
.method-option.active { background: var(--clr-accent-light); }
.method-option-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--clr-text);
  min-width: 72px;
}
.method-option.active .method-option-name { color: var(--clr-accent); }
.method-option-full {
  font-size: 12px;
  color: var(--clr-text-soft);
}

.token-box textarea {
  width: 100%;
  height: 100px;
  padding: 12px 14px;
  border-radius: 8px;
  border: 1px solid var(--clr-border);
  font-family: inherit;
  font-size: 14px;
  resize: none;
  background: #fafaf9;
  transition: border-color 0.2s, box-shadow 0.2s;
  outline: none;
  line-height: 1.7;
  color: var(--clr-text);
}
.token-box textarea:focus {
  border-color: var(--clr-accent);
  background: white;
}
.token-box textarea::placeholder { color: #bbb; }

.button-row {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 12px;
}

.tokeniseButton {
  padding: 9px 24px;
  border: none;
  border-radius: 6px;
  background-color: var(--clr-accent);
  color: white;
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: background-color 0.2s, transform 0.1s;
}
.tokeniseButton:hover { background-color: #5a4be0; }
.tokeniseButton:active { transform: scale(0.97); }

.clearButton {
  padding: 9px 18px;
  border: 1px solid var(--clr-border);
  border-radius: 6px;
  background: white;
  color: var(--clr-text-soft);
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: border-color 0.2s, color 0.2s;
}
.clearButton:hover {
  border-color: #e53935;
  color: #e53935;
  background: #fff5f5;
}

.output-section {
  margin-top: 20px;
}

.output-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--clr-text-soft);
  margin-bottom: 8px;
}

.token-display {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-height: 48px;
  padding: 14px;
  background: #fafaf9;
  border: 1px solid var(--clr-border);
  border-radius: 8px;
}

.token {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  font-size: 13px;
  font-weight: 500;
  border-radius: 6px;
  cursor: default;
  transition: transform 0.15s, box-shadow 0.15s;
  position: relative;
}
.num:hover, .token:hover {
  transform: scale(1.06);
  z-index: 2;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}

.token .token-id {
  font-size: 10px;
  opacity: 0.5;
  margin-left: 5px;
}

.stats-bar {
  display: flex;
  gap: 0;
  margin-top: 16px;
  border: 1px solid var(--clr-border);
  border-radius: 8px;
  overflow: hidden;
}
.stat {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 14px 8px;
  background: #fafaf9;
  border-right: 1px solid var(--clr-border);
}
.stat:last-child { border-right: none; }
.stat-value {
  font-size: 22px;
  color: var(--clr-accent);
  line-height: 1;
  margin-bottom: 4px;
}
.stat-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.03em;
  color: var(--clr-text-soft);
}

.char-counter {
  text-align: right;
  font-size: 11px;
  color: var(--clr-text-soft);
  margin-top: 4px;
  min-height: 16px;
  transition: color 0.2s;
}
.char-counter--warn { color: #e17055; }
.char-counter--over { color: #d63031; font-weight: 600; }

.token-detail {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-top: 12px;
  padding: 12px 40px 12px 16px;
  background: white;
  border: 1px solid var(--clr-border);
  border-radius: 10px;
  position: relative;
  animation: detailReveal 0.2s ease;
}
@keyframes detailReveal {
  from { opacity: 0; transform: translateY(-6px); }
  to   { opacity: 1; transform: translateY(0); }
}
.token-detail[hidden] { display: none; }
.token-detail-chip {
  font-family: monospace;
  font-size: 15px;
  font-weight: 600;
  padding: 6px 14px;
  border-radius: 8px;
  flex-shrink: 0;
}
.token-detail-info {
  display: flex;
  gap: 24px;
}
.token-detail-row {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}
.token-detail-label {
  font-size: 10px;
  font-weight: 600;
  color: var(--clr-text-soft);
}
.token-detail-val {
  font-size: 15px;
  font-weight: 500;
  color: var(--clr-accent);
}
.token-detail-close {
  position: absolute;
  top: 6px;
  right: 10px;
  border: none;
  background: none;
  font-size: 18px;
  color: var(--clr-text-soft);
  cursor: pointer;
  line-height: 1;
  padding: 2px 4px;
}
.token-detail-close:hover { color: var(--clr-text); }

.token--active {
  outline: 2px solid var(--clr-accent);
  outline-offset: 1px;
  transform: scale(1.06);
  z-index: 2;
}

.step1-visual {
  margin-top: 30px;
  text-align: center;
}

.step1-visual .typing-box {
  display: inline-block;
  padding: 14px 20px;
  border-radius: 10px;
  border: 1px solid #ddd;
  font-family: monospace;
  font-size: 18px;
  background: white;
}

.step1-visual .arrow {
  font-size: 26px;
  margin: 15px 0;
  color: #888;
}

.step1-visual .processed {
  background: #eaedff;
}

.step2-visual {
  margin-top: 30px;
  text-align: center;
}

.text-box {
  display: inline-block;
  padding: 14px 20px;
  border-radius: 10px;
  border: 1px solid #ddd;
  font-family: monospace;
  font-size: 18px;
  background: white;
}

.original {
  margin-bottom: 10px;
}

.arrow {
  font-size: 26px;
  margin: 15px 0;
  color: #888;
}

.processed {
  background: #eaedff;
}

.step3-visual {
  margin: 30px 0 40px;
  text-align: center;
}

.sentence {
  font-family: monospace;
  font-size: 16px;
  padding: 12px 20px;
  border-radius: 8px;
  border: 1px solid #ddd;
  background: white;
  display: inline-block;
}

.step3-visual .arrow {
  font-size: 24px;
  margin: 14px 0;
  color: #888;
}

.step3-visual .tokens {
  margin-top: 8px;
}

.token-output {
  display: inline-block;
  margin: 5px 4px;
  padding: 6px 12px;
  border-radius: 10px;
  font-family: monospace;
  font-size: 14px;
  color: #4a4e8a;
}

.token {
  display: inline-block;
  margin: 5px 4px;
  padding: 6px 12px;
  border-radius: 16px;
  font-family: monospace;
  font-size: 14px;
  background: #eeedff;
  color: #4a4e8a;
}

.bracket {
  font-family: monospace;
  font-size: 18px;
  margin: 0 4px;
  color: #888;
}

.step4-visual {
  margin: 30px 0 40px;
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 20px;
  text-align: center;
}

.token-pair {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.step4-visual .arrow-down {
  font-size: 18px;
  color: #888;
  line-height: 1;
}

.step4-visual .num {
  display: inline-block;
  padding: 6px 12px;
  border-radius: 16px;
  background: #fef3c7;
  font-family: monospace;
  font-size: 14px;
  font-weight: 500;
  color: #92600a;
  transition: transform 0.15s, box-shadow 0.15s;
}
.num:hover {
  transform: scale(1.06);
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}

.vis-diagram {
  margin: 28px 0 40px;
  text-align: center;

  max-width: 80%;
  margin: 20px auto;
  padding: 20px 24px;
}

.vis-stage {
  display: inline-block;
  padding: 18px 24px;
  background: rgb(238, 238, 238);
  border: 1px solid #ddd;
  border-radius: 10px;
  text-align: center;
  width: 100%;
  max-width: 100%;
}

.vis-lbl {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.01em;
  color: var(--clr-text-soft);
  margin-bottom: 12px;
}

.vis-flow-arrow {
  font-size: 24px;
  color: #888;
  margin: 14px 0;
  text-align: center;
  line-height: 1;
}

.vis-flow-arrow span {
  font-size: 12px;
  font-family: monospace;
  vertical-align: middle;
  margin-left: 6px;
  color: var(--clr-text-soft);
}

.vis-cells {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  justify-content: center;
}

.vc {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 28px;
  height: 36px;
  padding: 0 4px;
  font-family:  monospace;
  font-size: 15px;
  font-weight: 500;
  border-radius: 8px;
  background: #fafaf9;
  border: 1px solid var(--clr-border);
  color: var(--clr-text);
}

.vc--space {
  border-style: dashed;
  color: var(--clr-text-soft);
  font-size: 10px;
  background: transparent;
}

.vc--split {
  border-color: var(--clr-accent);
  background: var(--clr-accent-light);
}

.vis-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}

.vt {
  display: inline-block;
  padding: 6px 12px;
  border-radius: 16px;
  font-family: monospace;
  font-size: 14px;
  font-weight: 500;
  cursor: default;
  transition: transform 0.15s, box-shadow 0.15s;
}

.vt:hover {
  transform: scale(1.06);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.vt--word   { background: rgba(86,180,233,0.18);  color: #005f8a; }
.vt--sub    { background: rgba(0,158,115,0.15);   color: #00634a; }
.vt--sent   { background: rgba(230,159,0,0.18);   color: #7a5400; }
.vt--char   { background: rgba(213,94,0,0.15);    color: #8a3a00; }
.vt--merged {
  background: #eeedff;
  color: #4a4e8a;
  border: 1px dashed var(--clr-accent);
}

.vis-source-text {
  font-family: monospace;
  font-size: 16px;
  color: var(--clr-text);
  line-height: 1.8;
  padding: 4px 0;
}

.vis-source-text .bnd {
  color: var(--clr-accent);
  font-weight: 700;
  font-size: 18px;
}

.vis-footnote {
  font-size: 13px;
  color: var(--clr-text-soft);
  margin-top: 14px;
  line-height: 1.6;
  text-align: center;
  font-style: italic;
}

.vis-footnote strong {
  color: var(--clr-accent);
  font-style: normal;
}

.vis-diagram--bpe {
  text-align: center;
}

.vis-diagram--bpe .vis-lbl {
  margin-bottom: 16px;
}

.bpe-timeline {
  display: inline-block;
  text-align: left;
  background: rgb(238, 238, 238);
  border: 1px solid #ddd;
  border-radius: 10px;
  padding: 8px 0;
  width: 100%;
}

.bpe-row {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 9px 20px;
  border-bottom: 1px solid #dadada;
}

.bpe-row:last-child {
  border-bottom: none;
}

.bpe-row__label {
  font-family: monospace;
  font-size: 12px;
  font-weight: 600;
  color: var(--clr-accent);
  min-width: 130px;
  flex-shrink: 0;
}

.bpe-row__label--muted {
  color: var(--clr-text-soft);
}

.bpe-row__chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

@media (max-width: 640px) {
  .navbar {
    padding: 0 16px;
    height: 50px;
  }

  .logo-text { font-size: 16px; }
  .logo-icon { width: 20px; height: 20px; }

  .nav-link {
    font-size: 12px;
    padding: 6px 10px;
  }

  .token-box {
    max-width: calc(100% - 32px);
    padding: 20px 16px;
    margin: 66px auto 24px;
  }

  .token-box h2 {
    font-size: 22px;
  }

  .token-box-subtitle {
    font-size: 13px;
    margin-bottom: 16px;
  }

  .method-dropdown {
    width: 100%;
    min-width: 0;
  }

  .lang-presets {
    gap: 6px;
    margin-bottom: 10px;
  }

  .lang-btn {
    font-size: 12px;
    padding: 5px 10px;
  }

  .token-box textarea {
    height: 88px;
    font-size: 14px;
  }

  .token-detail {
    flex-wrap: wrap;
    gap: 12px;
    padding: 12px 36px 12px 14px;
  }

  .token-detail-info {
    gap: 16px;
  }

  .container1,
  .container2,
  .container3 {
    max-width: 100%;
    padding: 0 16px;
  }

  .text-box,
  .sentence {
    font-size: 14px;
    padding: 10px 14px;
  }

  .step4-visual {
    gap: 12px;
  }

  .token-pair {
    gap: 4px;
  }

  .vis-diagram {
    max-width: 100%;
    margin: 20px 0 28px;
    padding: 0;
  }

  .vis-stage {
    padding: 14px 16px;
  }

  .vc {
    min-width: 22px;
    height: 30px;
    font-size: 13px;
  }

  .vt {
    padding: 5px 10px;
    font-size: 12px;
  }

  .vis-chips {
    gap: 5px;
  }

  .vis-flow-arrow {
    font-size: 20px;
    margin: 10px 0;
  }

  .vis-source-text {
    font-size: 14px;
  }

  .vis-footnote {
    font-size: 12px;
  }

  .bpe-timeline {
    padding: 6px 0;
  }

  .bpe-row {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
    padding: 10px 14px;
  }

  .bpe-row__label {
    min-width: 0;
    font-size: 11px;
  }

  .stats-bar {
    flex-wrap: wrap;
  }

  .stat {
    flex: 1 1 calc(50% - 1px);
    border-right: none;
    border-bottom: 1px solid var(--clr-border);
  }

  .stat:nth-child(odd) {
    border-right: 1px solid var(--clr-border);
  }

  .stat:nth-last-child(-n+2) {
    border-bottom: none;
  }
}

@media (min-width: 641px) and (max-width: 900px) {
  .token-box {
    max-width: 75%;
  }

  .vis-diagram {
    margin: 24px 0 32px;
  }

  .bpe-row__label {
    min-width: 110px;
    font-size: 11px;
  }
}

.compare-box {
  max-width: 960px;
  margin: 80px auto 40px;
  padding: 28px 36px;
  background: var(--clr-surface);
  border-radius: var(--radius);
  border: 1px solid var(--clr-border);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.04);
}

.compare-box h2 {
  text-align: center;
  margin: 0 0 4px;
  font-weight: 300;
  font-size: 28px;
  color: var(--clr-accent);
  letter-spacing: -0.3px;
}

.lang-presets {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}

.lang-presets-label {
  font-size: 12px;
  color: var(--clr-text-soft);
  font-weight: 600;
  letter-spacing: 0.06em;
}

.lang-btn {
  padding: 5px 13px;
  border: 1px solid var(--clr-border);
  border-radius: 20px;
  background: white;
  font-size: 12.5px;
  font-family: inherit;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
  color: var(--clr-text);
}

.lang-btn:hover {
  border-color: var(--clr-accent);
  background: var(--clr-accent-light);
}

.lang-btn.active-lang {
  border-color: var(--clr-accent);
  background: var(--clr-accent-light);
  font-weight: 500;
}

.compare-box textarea {
  width: 100%;
  height: 72px;
  padding: 12px 14px;
  border-radius: 8px;
  border: 1px solid var(--clr-border);
  font-family: inherit;
  font-size: 14px;
  resize: none;
  background: #fafaf9;
  transition: border-color 0.2s, box-shadow 0.2s;
  outline: none;
  line-height: 1.7;
  color: var(--clr-text);
  margin-bottom: 16px;
}

.compare-box textarea:focus {
  border-color: var(--clr-accent);
  background: white;
  box-shadow: 0 0 0 3px var(--clr-accent-glow);
}

.compare-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

.compare-col {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.compare-col-header {
  padding: 10px 12px;
  background: #fafaf9;
  border: 1px solid var(--clr-border);
  border-radius: 8px;
  text-align: center;
}

.compare-col-name {
  display: block;
  font-size: 14px;
  font-weight: 600;
  color: var(--clr-accent);
}

.compare-col-sub {
  display: block;
  font-size: 11px;
  color: var(--clr-text-soft);
  margin-top: 2px;
}

.compare-col-tag {
  display: inline-block;
  margin-top: 6px;
  padding: 2px 8px;
  border-radius: 10px;
  background: var(--clr-accent);
  color: white;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.compare-col .token-display {
  flex: 1;
  min-height: 80px;
  align-content: flex-start;
}

.compare-stats {
  display: flex;
  gap: 16px;
  justify-content: center;
  padding: 8px 0 2px;
  border-top: 1px solid var(--clr-border);
}

.cmp-stat {
  font-size: 12px;
  color: var(--clr-text-soft);
  text-align: center;
}

.cmp-stat b {
  display: block;
  font-size: 18px;
  font-weight: 500;
  color: var(--clr-accent);
  line-height: 1.2;
}

.compare-insight {
  margin-top: 16px;
  padding: 12px 16px;
  background: var(--clr-accent-light);
  border: 1px solid rgba(107, 92, 255, 0.18);
  border-radius: 8px;
  font-size: 13px;
  color: #4a4e8a;
  line-height: 1.6;
  text-align: center;
  min-height: 42px;
}

@media (max-width: 900px) {
  .compare-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .compare-box {
    max-width: calc(100% - 32px);
    padding: 20px 16px;
    margin-top: 70px;
  }

  .compare-stats {
    gap: 24px;
  }
}

@media (min-width: 641px) and (max-width: 900px) {
  .compare-box {
    max-width: 90%;
    padding: 24px 24px;
  }
}

/* ─────────────  ALGORITHMS PAGE  ───────────── */

.algo-page {
  max-width: 820px;
  margin: 80px auto 0;
  padding: 20px var(--sp-container-pad);
}

.algo-intro {
  font-size: var(--fs-body);
  line-height: 1.75;
  color: #444;
}

/* Card wrapping one algorithm */
.algo-card {
  background: var(--clr-surface);
  border: 1px solid var(--clr-border);
  border-radius: var(--radius);
  padding: 24px 28px;
  margin: 22px 0;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.04);
}

.algo-card h2 {
  margin-top: 0;
  display: flex;
  align-items: baseline;
  gap: 10px;
  flex-wrap: wrap;
}

.algo-tag {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 3px 9px;
  border-radius: 20px;
  background: var(--clr-accent-light);
  color: var(--clr-accent);
}

.algo-tag--sub  { background: rgba(0,158,115,0.14);  color: #00634a; }
.algo-tag--base { background: rgba(86,180,233,0.18); color: #005f8a; }

/* "Key idea" callout */
.algo-keyidea {
  border-left: 3px solid var(--clr-accent);
  background: var(--clr-accent-light);
  border-radius: 0 8px 8px 0;
  padding: 12px 16px;
  margin: 16px 0;
  font-size: var(--fs-body);
  line-height: 1.7;
  color: #3a3a55;
}

.algo-keyidea strong { color: var(--clr-accent); }

/* Sub-heading inside a card e.g. Training / Encoding */
.algo-subhead {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--clr-text-soft);
  margin: 22px 0 8px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.algo-subhead::before {
  content: "";
  width: 14px;
  height: 2px;
  background: var(--clr-accent);
  display: inline-block;
}

/* Pseudocode block */
.pseudo {
  background: #1f1f29;
  color: #e6e6ef;
  border-radius: 10px;
  padding: 16px 18px;
  margin: 14px 0;
  overflow-x: auto;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  font-size: 12.8px;
  line-height: 1.65;
}

.pseudo-title {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: #9b97c9;
  margin-bottom: 10px;
  padding-bottom: 8px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}

.pseudo pre {
  margin: 0;
  white-space: pre;
  font-family: inherit;
}

.pseudo .kw   { color: #c792ea; font-weight: 600; }   /* keywords */
.pseudo .fn   { color: #82aaff; }                      /* function names */
.pseudo .cm   { color: #6f7390; font-style: italic; }  /* comments */
.pseudo .st   { color: #c3e88d; }                      /* strings/literals */
.pseudo .nm   { color: #f78c6c; }                      /* numbers */

/* Worked example / trace box */
.algo-trace {
  background: #fafaf9;
  border: 1px solid var(--clr-border);
  border-radius: 10px;
  padding: 14px 16px;
  margin: 14px 0;
  font-size: 13.5px;
  line-height: 1.7;
  color: #444;
}

.algo-trace .trace-step {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 12.5px;
  color: #4a4e8a;
}

/* Complexity / property footer row */
.algo-props {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 18px;
}

.algo-prop {
  flex: 1 1 140px;
  background: #fafaf9;
  border: 1px solid var(--clr-border);
  border-radius: 8px;
  padding: 10px 12px;
}

.algo-prop .algo-prop-label {
  display: block;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--clr-text-soft);
  margin-bottom: 4px;
}

.algo-prop .algo-prop-val {
  font-size: 13px;
  color: var(--clr-text);
  line-height: 1.5;
}

.algo-prop .algo-prop-val code {
  background: var(--clr-accent-light);
  color: var(--clr-accent);
}

/* In-page table of contents */
.algo-toc {
  background: var(--clr-surface);
  border: 1px solid var(--clr-border);
  border-radius: var(--radius);
  padding: 18px 22px;
  margin: 20px 0;
}

.algo-toc h3 {
  margin: 0 0 10px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--clr-text-soft);
}

.algo-toc ul {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.algo-toc li { margin: 0; }

.algo-toc a {
  display: inline-block;
  padding: 6px 12px;
  border-radius: 20px;
  border: 1px solid var(--clr-border);
  font-size: 13px;
  color: var(--clr-text);
  background: #fafaf9;
  transition: border-color 0.2s, background 0.2s, color 0.2s;
}

.algo-toc a:hover {
  border-color: var(--clr-accent);
  background: var(--clr-accent-light);
  color: var(--clr-accent);
  text-decoration: none;
}

@media (max-width: 640px) {
  .algo-page { max-width: 100%; padding: 0 14px; margin-top: 66px; }
  .algo-card { padding: 18px 16px; }
  .pseudo { font-size: 11.5px; padding: 14px; }
}

/* ─────────  INTERACTIVE BPE LAB  ───────── */

.lab {
  border: 1px solid var(--clr-border);
  border-radius: var(--radius);
  background: #fafaf9;
  padding: 18px;
  margin: 16px 0;
}

.lab-badge {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 3px 9px;
  border-radius: 20px;
  background: var(--clr-accent);
  color: #fff;
  margin-bottom: 12px;
}

.lab-corpus-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}

.lab-corpus-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--clr-text-soft);
}

.lab-corpus {
  flex: 1 1 260px;
  min-width: 0;
  padding: 8px 11px;
  border: 1px solid var(--clr-border);
  border-radius: 8px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 13px;
  background: #fff;
  color: var(--clr-text);
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.lab-corpus:focus {
  border-color: var(--clr-accent);
  box-shadow: 0 0 0 3px var(--clr-accent-glow);
}

.lab-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}

.lab-btn {
  padding: 8px 16px;
  border: 1px solid var(--clr-border);
  border-radius: 7px;
  background: #fff;
  color: var(--clr-text);
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: border-color 0.18s, background 0.18s, color 0.18s, transform 0.1s;
}
.lab-btn:hover:not(:disabled) { border-color: var(--clr-accent); color: var(--clr-accent); }
.lab-btn:active:not(:disabled) { transform: scale(0.97); }
.lab-btn:disabled { opacity: 0.4; cursor: not-allowed; }

.lab-btn--primary {
  background: var(--clr-accent);
  border-color: var(--clr-accent);
  color: #fff;
}
.lab-btn--primary:hover:not(:disabled) { background: #5a4be0; color: #fff; }

.lab-status {
  font-size: 13.5px;
  line-height: 1.6;
  color: #444;
  background: var(--clr-accent-light);
  border: 1px solid rgba(107, 92, 255, 0.18);
  border-radius: 8px;
  padding: 10px 14px;
  margin-bottom: 14px;
  min-height: 20px;
}
.lab-status b { color: var(--clr-accent); }
.lab-status .mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

.lab-cols {
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 14px;
}

.lab-panel {
  background: #fff;
  border: 1px solid var(--clr-border);
  border-radius: 9px;
  padding: 12px 14px;
}

.lab-panel-title {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--clr-text-soft);
  margin-bottom: 10px;
}

/* word table */
.lab-word {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 5px 0;
  border-bottom: 1px dashed var(--clr-border);
}
.lab-word:last-child { border-bottom: none; }

.lab-freq {
  flex-shrink: 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 11px;
  font-weight: 600;
  color: var(--clr-text-soft);
  background: #f0f0ee;
  border-radius: 5px;
  padding: 2px 6px;
  min-width: 26px;
  text-align: center;
}

.lab-syms {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.sym {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  padding: 3px 7px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 13px;
  border-radius: 6px;
  background: #f3f3f1;
  border: 1px solid var(--clr-border);
  color: var(--clr-text);
  transition: background 0.2s, border-color 0.2s, transform 0.2s;
}
.sym--eow { color: #bbb; font-size: 11px; background: transparent; border-style: dashed; }

.sym--pending {
  background: var(--clr-accent-light);
  border-color: var(--clr-accent);
  color: var(--clr-accent);
}
.sym--merged {
  background: rgba(0,158,115,0.16);
  border-color: #009E73;
  color: #00634a;
  animation: symPop 0.3s ease;
}
@keyframes symPop {
  0% { transform: scale(1.25); }
  100% { transform: scale(1); }
}

/* pair counts */
.pair-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
  font-size: 12.5px;
}
.pair-name {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  min-width: 78px;
  color: var(--clr-text);
}
.pair-bar-wrap {
  flex: 1;
  background: #f0f0ee;
  border-radius: 4px;
  height: 12px;
  overflow: hidden;
}
.pair-bar {
  height: 100%;
  background: #cfcbe9;
  border-radius: 4px;
  transition: width 0.3s ease;
}
.pair-count {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 11px;
  color: var(--clr-text-soft);
  min-width: 18px;
  text-align: right;
}
.pair-row--top .pair-name { color: var(--clr-accent); font-weight: 700; }
.pair-row--top .pair-bar { background: var(--clr-accent); }
.pair-row--top .pair-count { color: var(--clr-accent); font-weight: 700; }

/* merge log */
.lab-merges {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.merge-chip {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 12px;
  padding: 3px 9px;
  border-radius: 20px;
  background: rgba(0,158,115,0.13);
  border: 1px solid rgba(0,158,115,0.35);
  color: #00634a;
}
.merge-chip .merge-idx { opacity: 0.55; margin-right: 5px; }
.lab-empty { font-size: 12.5px; color: var(--clr-text-soft); font-style: italic; }

@media (max-width: 700px) {
  .lab-cols { grid-template-columns: 1fr; }
}

/* shared single-field row (word + vocab inputs) */
.lab-field-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}
.lab-field-row .lab-corpus-label { flex-shrink: 0; }

/* ---- WordPiece: greedy longest-match window ---- */
.wp-word {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-bottom: 6px;
}
.wp-cell {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 30px;
  height: 38px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 16px;
  border-radius: 8px;
  background: #f3f3f1;
  border: 1px solid var(--clr-border);
  color: var(--clr-text);
  transition: background 0.18s, border-color 0.18s, transform 0.18s, opacity 0.18s;
}
.wp-cell--done {
  background: rgba(0,158,115,0.14);
  border-color: rgba(0,158,115,0.4);
  color: #00634a;
}
.wp-cell--window {
  background: var(--clr-accent-light);
  border-color: var(--clr-accent);
  color: var(--clr-accent);
}
.wp-cell--drop {
  opacity: 0.35;
  border-style: dashed;
}
.wp-candidate {
  font-size: 13.5px;
  color: #444;
  margin: 4px 0 2px;
}
.wp-candidate .mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  background: #fff;
  border: 1px solid var(--clr-border);
  border-radius: 6px;
  padding: 2px 8px;
  font-weight: 600;
}
.wp-candidate .hit  { color: #00634a; border-color: rgba(0,158,115,0.5); background: rgba(0,158,115,0.1); }
.wp-candidate .miss { color: #b15; border-color: rgba(200,40,80,0.35); background: rgba(200,40,80,0.06); }

/* vocab chips (WordPiece) */
.vocab-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}
.vocab-chip {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 12px;
  padding: 3px 8px;
  border-radius: 6px;
  background: #f3f3f1;
  border: 1px solid var(--clr-border);
  color: var(--clr-text-soft);
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.vocab-chip--hit {
  background: var(--clr-accent);
  border-color: var(--clr-accent);
  color: #fff;
}
.vocab-note { font-size: 11.5px; color: var(--clr-text-soft); font-style: italic; margin-top: 8px; }

/* result chips (shared by WP + Unigram) */
.result-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.result-chip {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 13px;
  padding: 4px 11px;
  border-radius: 16px;
  background: rgba(0,158,115,0.13);
  border: 1px solid rgba(0,158,115,0.35);
  color: #00634a;
}

/* ---- Unigram: Viterbi lattice ---- */
.uni-strip {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 2px;
  padding: 6px 0 2px;
}
.uni-node {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  min-width: 34px;
}
.uni-dot {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid var(--clr-border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 700;
  color: var(--clr-text-soft);
  transition: border-color 0.2s, background 0.2s, color 0.2s;
}
.uni-dot--active { border-color: var(--clr-accent); background: var(--clr-accent-light); color: var(--clr-accent); }
.uni-dot--path  { border-color: #009E73; background: rgba(0,158,115,0.16); color: #00634a; }
.uni-score {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 10px;
  color: var(--clr-text-soft);
  min-height: 13px;
}
.uni-score--set { color: var(--clr-accent); font-weight: 600; }
.uni-char {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 16px;
  color: var(--clr-text);
  width: 18px;
  text-align: center;
  align-self: flex-start;
  margin-top: 1px;
}

.uni-cands { margin-top: 6px; }
.uni-cand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 12.5px;
  padding: 3px 0;
  color: #444;
}
.uni-cand--win { color: #00634a; font-weight: 700; }
.uni-cand-piece {
  background: #f3f3f1;
  border: 1px solid var(--clr-border);
  border-radius: 6px;
  padding: 1px 7px;
  min-width: 44px;
  text-align: center;
}
.uni-cand--win .uni-cand-piece { background: rgba(0,158,115,0.13); border-color: rgba(0,158,115,0.4); }
.uni-cand-calc { color: var(--clr-text-soft); }
.uni-cand--win .uni-cand-calc { color: #00634a; }

/* back-to-hub navbar link */
.nav-link--hub {
  color: var(--clr-accent);
  margin-right: 4px;
  padding-right: 12px;
  border-right: 1px solid var(--clr-border);
  border-radius: 0;
}
.nav-link--hub:hover { background: var(--clr-accent-light); border-radius: 7px; }
