/* Lexitally
   Vowels are amber, consonants are indigo-ink. That pairing means the same thing
   in the editor, the stat cards and the frequency comb. */

:root {
  --paper:      #EBEEE8;
  --paper-2:    #F7F9F4;
  --raised:     #FDFDFB;
  --ink:        #15191A;
  --ink-2:      #5C665E;
  --ink-3:      #8A9289;
  --rule:       #D4D9CD;
  --rule-soft:  #E1E5DA;

  --vowel:      #B26A00;
  --vowel-soft: rgba(178, 106, 0, 0.13);
  --consonant:  #2F4B9B;
  --cons-ink:   #2A3552;
  --cons-soft:  rgba(47, 75, 155, 0.11);

  --display: "Space Grotesk", "Helvetica Neue", Arial, sans-serif;
  --body:    "IBM Plex Sans", system-ui, -apple-system, Segoe UI, sans-serif;
  --mono:    "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, monospace;

  --wrap: 1160px;
  --r: 3px;
}

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

html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--body);
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* Faint graph-paper ground — this is a measuring instrument, not a brochure. */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background-image:
    linear-gradient(to right, rgba(21,25,26,.028) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(21,25,26,.028) 1px, transparent 1px);
  background-size: 26px 26px;
}
body > * { position: relative; z-index: 1; }

.wrap { width: 100%; max-width: var(--wrap); margin: 0 auto; padding: 0 24px; }

a { color: var(--consonant); text-decoration-thickness: 1px; text-underline-offset: 2px; }
a:hover { color: var(--vowel); }

:focus-visible {
  outline: 2px solid var(--consonant);
  outline-offset: 2px;
}

.skip {
  position: absolute; left: -9999px; top: 0;
  background: var(--ink); color: var(--paper); padding: 10px 16px; z-index: 100;
}
.skip:focus { left: 8px; top: 8px; }

.sr {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ------------------------------------------------------------------ header */

.masthead {
  border-bottom: 1px solid var(--rule);
  background: rgba(235,238,232,.86);
  backdrop-filter: blur(8px);
  position: sticky; top: 0; z-index: 20;
}
.masthead .wrap {
  display: flex; align-items: center; gap: 24px;
  min-height: 60px; flex-wrap: wrap;
}
.brand {
  font-family: var(--display);
  font-weight: 700;
  font-size: 19px;
  letter-spacing: -.02em;
  color: var(--ink);
  text-decoration: none;
  display: flex; align-items: baseline; gap: 1px;
}
.brand:hover { color: var(--ink); }
.brand .v { color: var(--vowel); }
.brand .c { color: var(--consonant); }

.legend {
  margin-left: auto;
  display: flex; gap: 18px; align-items: center;
  font-family: var(--mono);
  font-size: 11.5px;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--ink-2);
}
.legend span { display: inline-flex; align-items: center; gap: 7px; }
.legend i {
  width: 9px; height: 9px; border-radius: 50%; display: inline-block;
}
.legend .dot-v { background: var(--vowel); }
.legend .dot-c { background: var(--consonant); }

.navlinks {
  border-bottom: 1px solid var(--rule);
  background: var(--paper-2);
  overflow-x: auto;
}
.navlinks ul {
  display: flex; gap: 2px; list-style: none; margin: 0; padding: 0;
  white-space: nowrap;
}
.navlinks a {
  display: block; padding: 11px 15px;
  font-family: var(--mono); font-size: 12.5px; letter-spacing: .01em;
  color: var(--ink-2); text-decoration: none;
  border-bottom: 2px solid transparent;
}
.navlinks a:hover { color: var(--ink); background: rgba(255,255,255,.5); }
.navlinks a[aria-current="page"] {
  color: var(--ink); border-bottom-color: var(--vowel); background: var(--raised);
}

/* -------------------------------------------------------------------- hero */

.hero { padding: 44px 0 20px; }
.eyebrow {
  font-family: var(--mono);
  font-size: 11.5px; letter-spacing: .16em; text-transform: uppercase;
  color: var(--ink-3); margin: 0 0 14px;
}
h1 {
  font-family: var(--display);
  font-weight: 700;
  font-size: clamp(30px, 5.2vw, 52px);
  line-height: 1.04;
  letter-spacing: -.032em;
  margin: 0 0 16px;
  max-width: 20ch;
}
h1 em { font-style: normal; color: var(--vowel); }
.lede {
  font-size: clamp(16px, 1.6vw, 18.5px);
  color: var(--ink-2);
  max-width: 62ch;
  margin: 0;
}

/* ------------------------------------------------------------------ editor */

.tool { padding: 26px 0 60px; }

.tool-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 292px;
  gap: 20px;
  align-items: start;
}

.editor {
  position: relative;
  background: var(--raised);
  border: 1px solid var(--rule);
  border-radius: var(--r);
  box-shadow: 0 1px 0 rgba(21,25,26,.04), 0 12px 28px -22px rgba(21,25,26,.4);
  overflow: hidden;
}
.editor.dropping { border-color: var(--vowel); box-shadow: 0 0 0 3px var(--vowel-soft); }

.editor-bar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 9px 12px;
  border-bottom: 1px solid var(--rule-soft);
  background: var(--paper-2);
}
.editor-bar .label {
  font-family: var(--mono); font-size: 11px; letter-spacing: .12em;
  text-transform: uppercase; color: var(--ink-3); margin-right: auto;
}

.btn {
  font-family: var(--mono); font-size: 12px;
  padding: 5px 11px;
  border: 1px solid var(--rule);
  background: var(--raised);
  color: var(--ink-2);
  border-radius: var(--r);
  cursor: pointer;
  transition: color .12s, border-color .12s, background .12s;
}
.btn:hover { color: var(--ink); border-color: var(--ink-3); }
.btn:active { background: var(--paper-2); }

.toggle {
  display: inline-flex; align-items: center; gap: 7px;
  font-family: var(--mono); font-size: 12px; color: var(--ink-2);
  cursor: pointer; user-select: none;
}
.toggle input { accent-color: var(--vowel); margin: 0; width: 14px; height: 14px; }

/* The overlay pair: a painted backdrop under a transparent-text textarea.
   Every metric below must match exactly or the letters will drift apart. */
.editor-stack { position: relative; }

#lx-backdrop, #lx-input {
  margin: 0;
  padding: 22px 24px 26px;
  font-family: var(--mono);
  font-size: 15px;
  line-height: 1.78;
  letter-spacing: 0;
  white-space: pre-wrap;
  overflow-wrap: break-word;
  word-break: normal;
  tab-size: 2;
  border: 0;
}

#lx-backdrop {
  position: absolute; inset: 0;
  overflow: hidden;
  color: var(--cons-ink);
  pointer-events: none;
  z-index: 1;
}
#lx-backdrop .hv {
  font-weight: 500;
  color: var(--vowel);
  background: var(--vowel-soft);
  border-radius: 2px;
}
#lx-backdrop .hc { font-weight: 400; color: var(--cons-ink); }

#lx-input {
  position: relative;
  z-index: 2;
  display: block;
  width: 100%;
  min-height: 340px;
  resize: vertical;
  background: transparent;
  color: transparent;
  -webkit-text-fill-color: transparent;
  caret-color: var(--ink);
  outline: none;
}
#lx-input::selection { background: rgba(47,75,155,.22); }
#lx-input::placeholder { color: var(--ink-3); -webkit-text-fill-color: var(--ink-3); }

/* No-highlight mode: show the real textarea text and hide the painted layer. */
body.no-highlight #lx-input { color: var(--ink); -webkit-text-fill-color: var(--ink); }
body.no-highlight #lx-backdrop { display: none; }

/* ------------------------------------------------------------------- stats */

.readout {
  border: 1px solid var(--rule);
  border-radius: var(--r);
  background: var(--raised);
  overflow: hidden;
  position: sticky;
  top: 76px;
}

.stat {
  display: flex; align-items: baseline; justify-content: space-between; gap: 12px;
  padding: 13px 16px;
  border-bottom: 1px solid var(--rule-soft);
}
.stat:last-child { border-bottom: 0; }
.stat-k {
  font-family: var(--mono); font-size: 11.5px; letter-spacing: .08em;
  text-transform: uppercase; color: var(--ink-2);
}
.stat-v {
  font-family: var(--mono); font-weight: 500; font-size: 20px;
  font-variant-numeric: tabular-nums; letter-spacing: -.01em;
  color: var(--ink);
}

.stat.lead { padding: 17px 16px; background: var(--paper-2); }
.stat.lead .stat-v { font-size: 32px; font-weight: 600; }

.stat.is-vowel .stat-k { color: var(--vowel); }
.stat.is-vowel .stat-v { color: var(--vowel); }
.stat.is-cons  .stat-k { color: var(--consonant); }
.stat.is-cons  .stat-v { color: var(--consonant); }

.ratio {
  height: 7px;
  background: var(--consonant);
  position: relative;
  overflow: hidden;
}
.ratio::before {
  content: "";
  position: absolute; inset: 0 auto 0 0;
  width: var(--vowel-share, 0%);
  background: var(--vowel);
  transition: width .18s ease-out;
}
.ratio-label {
  padding: 8px 16px 11px;
  font-family: var(--mono); font-size: 11px; color: var(--ink-3);
  letter-spacing: .02em;
}

/* --------------------------------------------------------------- panels */

.panels {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 20px;
  margin-top: 20px;
}
.panel {
  border: 1px solid var(--rule);
  border-radius: var(--r);
  background: var(--raised);
  padding: 18px 20px 20px;
}
.panel h2, .panel h3 {
  font-family: var(--mono);
  font-size: 11.5px; letter-spacing: .12em; text-transform: uppercase;
  color: var(--ink-3);
  margin: 0 0 14px;
  font-weight: 500;
}
.panel.wide { grid-column: 1 / -1; }

.grid-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(158px, 1fr));
  gap: 1px;
  background: var(--rule-soft);
  border: 1px solid var(--rule-soft);
}
.grid-stats > div {
  background: var(--raised);
  padding: 14px 15px;
}
.grid-stats dt {
  font-family: var(--mono); font-size: 10.5px; letter-spacing: .08em;
  text-transform: uppercase; color: var(--ink-3); margin: 0 0 4px;
}
.grid-stats dd {
  margin: 0;
  font-family: var(--mono); font-size: 17px; font-weight: 500;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
  overflow-wrap: anywhere;
}

/* Frequency comb */
.comb {
  display: grid;
  grid-template-columns: repeat(26, 1fr);
  gap: 3px;
  align-items: end;
  height: 132px;
}
.comb .bar {
  position: relative;
  height: 100%;
  display: flex; flex-direction: column; justify-content: flex-end;
  padding-bottom: 18px;
}
.comb .bar-fill {
  width: 100%;
  min-height: 2px;
  background: var(--consonant);
  border-radius: 1px 1px 0 0;
  transition: height .18s ease-out;
}
.comb .bar.v .bar-fill { background: var(--vowel); }
.comb .bar.y .bar-fill { background: linear-gradient(var(--vowel), var(--consonant)); }
.comb .bar-l {
  position: absolute; bottom: 0; left: 0; right: 0;
  text-align: center;
  font-family: var(--mono); font-size: 10.5px; color: var(--ink-3);
}
.comb .bar.v .bar-l { color: var(--vowel); }
.comb .bar-n {
  position: absolute; top: -2px; left: 0; right: 0;
  text-align: center;
  font-family: var(--mono); font-size: 9px; color: var(--ink-3);
  opacity: 0; transition: opacity .12s;
}
.comb .bar:hover .bar-n { opacity: 1; }

/* Keyword density */
.kwlist { list-style: none; margin: 0; padding: 0; }
.kwlist li {
  display: grid;
  grid-template-columns: minmax(60px, 1fr) 2fr auto;
  align-items: center; gap: 10px;
  padding: 5px 0;
  font-family: var(--mono); font-size: 12.5px;
}
.kw-word { color: var(--ink); overflow: hidden; text-overflow: ellipsis; }
.kw-bar { height: 6px; background: var(--rule-soft); border-radius: 3px; overflow: hidden; }
.kw-bar i { display: block; height: 100%; background: var(--consonant); border-radius: 3px; }
.kw-n {
  color: var(--ink); font-variant-numeric: tabular-nums;
  display: flex; align-items: baseline; gap: 7px; justify-content: flex-end;
}
.kw-n em { font-style: normal; font-size: 11px; color: var(--ink-3); min-width: 34px; text-align: right; }
.kw-empty { display: block; color: var(--ink-3); grid-template-columns: 1fr; }

/* y policy segmented control */
.segmented { display: flex; flex-wrap: wrap; gap: 6px; max-width: 100%; }
.segmented button {
  font-family: var(--mono); font-size: 12px;
  padding: 6px 12px;
  border: 1px solid var(--rule);
  border-radius: var(--r);
  background: var(--raised); color: var(--ink-2);
  cursor: pointer;
  transition: background .12s, color .12s, border-color .12s;
}
.segmented button[aria-pressed="true"] {
  background: var(--vowel); border-color: var(--vowel); color: #fff;
}
.segmented button:hover:not([aria-pressed="true"]) { background: var(--paper-2); color: var(--ink); border-color: var(--ink-3); }

.setting-row {
  display: flex; flex-direction: column; align-items: flex-start; gap: 10px;
  font-family: var(--mono); font-size: 12px; color: var(--ink-2);
}

/* ------------------------------------------------------------------ prose */

.prose { padding: 8px 0 72px; max-width: 74ch; }
.prose h2 {
  font-family: var(--display); font-weight: 700;
  font-size: clamp(23px, 3vw, 30px); letter-spacing: -.02em;
  margin: 52px 0 14px; line-height: 1.15;
}
.prose h3 {
  font-family: var(--display); font-weight: 700;
  font-size: 18px; letter-spacing: -.01em; margin: 30px 0 8px;
}
.prose p { margin: 0 0 15px; color: #2C332E; }
.prose ul, .prose ol { margin: 0 0 15px; padding-left: 20px; color: #2C332E; }
.prose li { margin-bottom: 7px; }
.prose code {
  font-family: var(--mono); font-size: .89em;
  background: var(--paper-2); border: 1px solid var(--rule-soft);
  padding: 1px 5px; border-radius: 2px;
}
.prose strong { font-weight: 600; }

.rules {
  border-top: 1px solid var(--rule);
  margin: 26px 0;
}
.rules dl { margin: 0; }
.rules div {
  display: grid; grid-template-columns: 148px 1fr; gap: 20px;
  padding: 14px 0; border-bottom: 1px solid var(--rule-soft);
}
.rules dt {
  font-family: var(--mono); font-size: 11.5px; letter-spacing: .08em;
  text-transform: uppercase; color: var(--ink-2); padding-top: 2px;
}
.rules dd { margin: 0; color: #2C332E; }

details.faq {
  border-bottom: 1px solid var(--rule-soft);
}
details.faq summary {
  cursor: pointer; padding: 15px 0;
  font-family: var(--display); font-weight: 700; font-size: 17px;
  letter-spacing: -.01em;
  list-style: none;
  display: flex; justify-content: space-between; align-items: center; gap: 16px;
}
details.faq summary::-webkit-details-marker { display: none; }
details.faq summary::after {
  content: "+"; font-family: var(--mono); font-weight: 400; font-size: 18px;
  color: var(--ink-3); flex: none;
}
details.faq[open] summary::after { content: "\2013"; }
details.faq p { margin: 0 0 15px; color: #2C332E; }

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

.foot {
  border-top: 1px solid var(--rule);
  background: var(--paper-2);
  padding: 34px 0 44px;
  font-size: 14px;
  color: var(--ink-2);
}
.foot-grid { display: flex; gap: 40px; flex-wrap: wrap; justify-content: space-between; }
.foot h2 {
  font-family: var(--mono); font-size: 11px; letter-spacing: .12em;
  text-transform: uppercase; color: var(--ink-3); margin: 0 0 10px; font-weight: 500;
}
.foot ul { list-style: none; margin: 0; padding: 0; }
.foot li { margin-bottom: 6px; }
.foot a { color: var(--ink-2); text-decoration: none; }
.foot a:hover { color: var(--vowel); text-decoration: underline; }
.foot .note { max-width: 34ch; margin: 0; }

/* ------------------------------------------------------------- responsive */

@media (max-width: 900px) {
  .tool-grid { grid-template-columns: 1fr; }
  .comb { height: 104px; gap: 2px; }
  .comb .bar-n { display: none; }

  /* Counts move above the editor and stay pinned, so they never scroll out of
     view while you're typing into the box below them. */
  .readout {
    order: -1;
    position: sticky;
    top: 59px;
    z-index: 15;
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    box-shadow: 0 8px 18px -14px rgba(21,25,26,.5);
  }
  .readout .stat,
  .readout .stat.lead {
    flex-direction: column;
    align-items: flex-start;
    justify-content: flex-start;
    gap: 1px;
    padding: 9px 4px 9px 9px;
    border-bottom: 0;
    border-right: 1px solid var(--rule-soft);
    background: var(--raised);
  }
  .readout .stat:nth-of-type(5) { border-right: 0; }
  .readout .stat { min-width: 0; }
  .readout .stat-k {
    font-size: 8.5px; letter-spacing: .01em; line-height: 1.25;
    white-space: normal; overflow-wrap: anywhere;
  }
  .readout .stat-v,
  .readout .stat.lead .stat-v { font-size: 17px; font-weight: 600; }
  .ratio { grid-column: 1 / -1; height: 5px; }
  .ratio-label { grid-column: 1 / -1; padding: 6px 10px 7px; font-size: 10px; }
}

@media (max-width: 620px) {
  .wrap { padding: 0 16px; }
  .hero { padding: 30px 0 14px; }
  .legend { width: 100%; margin-left: 0; padding-bottom: 10px; }
  .masthead .wrap { min-height: 0; padding-top: 12px; }
  #lx-backdrop, #lx-input { padding: 16px 16px 20px; font-size: 14px; }
  #lx-input { min-height: 250px; }
  .rules div { grid-template-columns: 1fr; gap: 4px; }
  .grid-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .comb { grid-template-columns: repeat(13, 1fr); height: auto; gap: 6px 4px; }
  .comb .bar { height: 60px; }
}

@media print {
  .masthead, .navlinks, .editor-bar, .foot, .btn { display: none; }
}
