/* LexicRo demo.
 *
 * Two accents carry meaning rather than decoration: amber is the first reading
 * of an ambiguous form, teal is the second. The page exists to show that one
 * word can be two words, so the palette says it too.
 *
 * Self-contained on purpose -- no webfonts, no CDN. A Romanian NLP demo has no
 * business handing every visitor's IP to a font host.
 */

/* ---------- tokens: light is the base, dark overrides ---------- */

:root {
  --bg:          #eef1f8;
  --bg-tint:     #e4e9f4;
  --ink:         #171b2c;
  --muted:       #626a85;
  --glass:       rgba(255, 255, 255, 0.62);
  --glass-edge:  rgba(255, 255, 255, 0.9);
  --hairline:    rgba(23, 27, 44, 0.1);
  --shadow:      0 1px 2px rgba(23, 27, 44, 0.05), 0 12px 32px rgba(23, 27, 44, 0.09);
  --a:           #a35d03;   /* reading A */
  --b:           #0c6f66;   /* reading B */
  --orb-a:       rgba(240, 166, 60, 0.20);
  --orb-b:       rgba(53, 196, 180, 0.17);
  --focus-ring:  #2f6df0;
  --on-accent:   #ffffff;   /* text ON the action colour */
  --action:      #14625a;   /* calls to action only */

  --fam-verbal:     108 86 214;
  --fam-agreement:  27 110 190;
  --fam-lexical:    88 100 122;
  --fam-other:      88 100 122;

  --radius:      16px;
  --radius-sm:   9px;
  --blur:        18px;
  --measure:     min(76rem, 100% - 2.5rem);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg:         #0c1020;
    --bg-tint:    #11172b;
    --ink:        #e7eaf4;
    --muted:      #939ab4;
    --glass:      rgba(255, 255, 255, 0.055);
    --glass-edge: rgba(255, 255, 255, 0.14);
    --hairline:   rgba(255, 255, 255, 0.09);
    --shadow:     0 1px 2px rgba(0, 0, 0, 0.4), 0 16px 40px rgba(0, 0, 0, 0.45);
    --a:          #f0a63c;
    --b:          #35c4b4;
    --orb-a:      rgba(240, 166, 60, 0.22);
    --orb-b:      rgba(53, 196, 180, 0.2);
    --focus-ring: #79a8ff;
    --on-accent:  #08120f;
    --action:     #3fd3c2;

    --fam-verbal:    155 140 250;
    --fam-agreement: 108 176 250;
    --fam-lexical:   150 162 186;
    --fam-other:     150 162 186;
  }
}

:root[data-theme="dark"] {
  --bg:         #0c1020;
  --bg-tint:    #11172b;
  --ink:        #e7eaf4;
  --muted:      #939ab4;
  --glass:      rgba(255, 255, 255, 0.055);
  --glass-edge: rgba(255, 255, 255, 0.14);
  --hairline:   rgba(255, 255, 255, 0.09);
  --shadow:     0 1px 2px rgba(0, 0, 0, 0.4), 0 16px 40px rgba(0, 0, 0, 0.45);
  --a:          #f0a63c;
  --b:          #35c4b4;
  --orb-a:      rgba(240, 166, 60, 0.22);
  --orb-b:      rgba(53, 196, 180, 0.2);
  --focus-ring: #79a8ff;
  --on-accent:  #08120f;
  --action:     #3fd3c2;

  --fam-verbal:    155 140 250;
  --fam-agreement: 108 176 250;
  --fam-lexical:   150 162 186;
  --fam-other:     150 162 186;
}

/* ---------- base ---------- */

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

/* Author styles beat the UA sheet, so `button { display: inline-block }` was
   un-hiding elements carrying the hidden attribute. Restore it explicitly. */
[hidden] { display: none !important; }

html { color-scheme: light dark; }
:root[data-theme="light"] { color-scheme: light; }
:root[data-theme="dark"]  { color-scheme: dark; }

body {
  margin: 0;
  min-height: 100vh;
  font: 400 16px/1.6 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

/* The glass needs something to refract; over a flat fill, backdrop-filter is
   an expensive no-op. These two fields are that something. */
.ambient {
  position: fixed;
  inset: 0;
  z-index: -1;
  overflow: hidden;
  background: linear-gradient(160deg, var(--bg) 0%, var(--bg-tint) 100%);
}
.orb {
  position: absolute;
  display: block;
  width: 46vmax;
  height: 46vmax;
  border-radius: 50%;
  filter: blur(80px);
}
.orb-a { top: -14vmax; left: -10vmax;  background: var(--orb-a); }
.orb-b { bottom: -18vmax; right: -12vmax; background: var(--orb-b); }

.site-header, main, footer { width: var(--measure); margin-inline: auto; }

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

.site-header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1.25rem;
  padding: 2.5rem 0 1.5rem;
}
.brand h1 {
  margin: 0;
  text-wrap: balance;
  font-size: clamp(1.35rem, 1.05rem + 1.1vw, 1.9rem);
  font-weight: 650;
  letter-spacing: -0.022em;
}
.tagline { margin: 0.35rem 0 0; color: var(--muted); max-width: 62ch; text-wrap: balance; }

.controls { display: flex; flex-wrap: wrap; gap: 0.55rem; align-items: center; }

.langs, .themes {
  display: flex;
  gap: 2px;
  padding: 3px;
  border-radius: 999px;
  background: var(--glass);
  border: 1px solid var(--glass-edge);
  backdrop-filter: blur(var(--blur)) saturate(140%);
  -webkit-backdrop-filter: blur(var(--blur)) saturate(140%);
}

.lang, .theme-opt {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.34rem 0.7rem;
  border-radius: 999px;
  color: var(--muted);
  text-decoration: none;
  font-size: 0.85rem;
  line-height: 1;
  transition: background-color 0.18s ease, color 0.18s ease;
}
.theme-opt { padding: 0.38rem; }
.lang:hover, .theme-opt:hover { color: var(--ink); background: var(--hairline); }
.lang.is-current, .theme-opt.is-current {
  color: var(--ink);
  background: var(--glass-edge);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
}
.flag {
  width: 20px;
  height: 14px;
  border-radius: 2px;
  box-shadow: 0 0 0 1px var(--hairline);
  flex: none;
}
.theme-opt svg { width: 17px; height: 17px; display: block; }

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

.hero { padding-top: 1rem; }
h2 {
  margin: 0 0 0.4rem;
  text-wrap: balance;
  font-size: clamp(1.15rem, 1rem + 0.7vw, 1.45rem);
  font-weight: 640;
  letter-spacing: -0.018em;
}
.lede { margin: 0 0 2rem; color: var(--muted); max-width: 76ch; text-wrap: balance; }

.pair { margin: 0 0 2.25rem; }

/* The shared form, set as data rather than as prose: this product turns words
   into structured output, so the word is typeset like the output. */
.pair-form {
  display: flex;
  align-items: baseline;
  gap: 0.7rem;
  margin: 0 0 0.7rem;
  padding-left: 0.15rem;
}
.form-word {
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  font-size: clamp(1.5rem, 1.2rem + 1.3vw, 2.1rem);
  font-weight: 600;
  letter-spacing: -0.02em;
  background: linear-gradient(96deg, var(--a), var(--b));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.form-note {
  font-size: 0.78rem;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.pair-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 23rem), 1fr));
  gap: 1rem;
}

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

.panel {
  min-width: 0;              /* the whole reason the page used to scroll sideways */
  margin: 0;
  padding: 1.1rem 1.15rem 1.25rem;
  border-radius: var(--radius);
  background: var(--glass);
  border: 1px solid var(--glass-edge);
  box-shadow: var(--shadow);
  backdrop-filter: blur(var(--blur)) saturate(150%);
  -webkit-backdrop-filter: blur(var(--blur)) saturate(150%);
  position: relative;
  overflow: hidden;
}
/* Reading A and B are tinted along the top edge -- the one place the two
   accents appear as pure colour. */
.panel.reading-a::before, .panel.reading-b::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 2px;
}
.panel.reading-a::before { background: linear-gradient(90deg, var(--a), transparent 85%); }
.panel.reading-b::before { background: linear-gradient(90deg, var(--b), transparent 85%); }
.panel.reading-a { --accent: var(--a); }
.panel.reading-b { --accent: var(--b); }

.panel figcaption {
  font-size: 1.02rem;
  font-weight: 560;
  letter-spacing: -0.01em;
  margin-bottom: 0.85rem;
}

/* ---------- tokens ---------- */

.token-list { display: flex; flex-direction: column; gap: 0.1rem; }

.token {
  padding: 0.5rem 0.6rem;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
}

/* The ambiguous word is the reason the panel exists. Ring it. */
.token.is-focus {
  background: var(--focus-tint, rgba(127, 127, 127, 0.08));
  border-color: var(--focus-edge, rgba(127, 127, 127, 0.3));
}
.panel.reading-a { --focus-tint: rgba(240, 166, 60, 0.12); --focus-edge: rgba(240, 166, 60, 0.4); }
.panel.reading-b { --focus-tint: rgba(53, 196, 180, 0.12); --focus-edge: rgba(53, 196, 180, 0.4); }

.token-head {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 0.5rem;
}
.t-form, .t-lemma {
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.95rem;
}
.t-form { font-weight: 600; }
.t-lemma { color: var(--muted); }
.t-arrow { color: var(--muted); opacity: 0.55; font-size: 0.85rem; }
.token.is-focus .t-lemma { color: var(--ink); }

.t-upos {
  font-size: 0.68rem;
  font-weight: 640;
  letter-spacing: 0.06em;
  padding: 0.14rem 0.42rem;
  border-radius: 5px;
  border: 1px solid var(--hairline);
  color: var(--muted);
}
.token.is-focus .t-upos {
  color: var(--accent, var(--a));
  border-color: currentColor;
}
.t-source {
  margin-left: auto;
  font-size: 0.7rem;
  color: var(--muted);
  opacity: 0.75;
}

/* ---------- feature chips ---------- */

.chips { display: flex; flex-wrap: wrap; gap: 0.3rem; margin-top: 0.45rem; }

.chip {
  --fam: var(--fam-other);
  display: inline-flex;
  align-items: baseline;
  gap: 0.28rem;
  padding: 0.16rem 0.46rem;
  border-radius: 6px;
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.72rem;
  line-height: 1.5;
  background: rgba(var(--fam), 0.12);
  border: 1px solid rgba(var(--fam), 0.26);
  position: relative;
}
.chip.fam-verbal    { --fam: var(--fam-verbal); }
.chip.fam-agreement { --fam: var(--fam-agreement); }
.chip.fam-lexical   { --fam: var(--fam-lexical); }
.chip b { font-weight: 600; color: rgb(var(--fam)); }
.chip b::after { content: "="; opacity: 0.5; }
.chip i { font-style: normal; color: var(--ink); }

.chip.has-gloss { cursor: help; }
.chip small {
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%) translateY(3px);
  width: max-content;
  max-width: min(20rem, 70vw);
  padding: 0.4rem 0.6rem;
  border-radius: 8px;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 0.75rem;
  line-height: 1.35;
  color: var(--ink);
  background: var(--bg-tint);
  border: 1px solid var(--glass-edge);
  box-shadow: var(--shadow);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.16s ease, transform 0.16s ease, visibility 0.16s;
  pointer-events: none;
  z-index: 5;
}
.chip.has-gloss:hover small,
.chip.has-gloss:focus-visible small,
.chip.is-open small {
  opacity: 1;
  visibility: visible;
  transform: translateX(-50%) translateY(0);
}

.candidates {
  margin: 0.45rem 0 0;
  font-size: 0.76rem;
  color: var(--muted);
  font-style: italic;
}
.truncated { font-size: 0.8rem; color: var(--muted); }

/* ---------- analyser ---------- */

.analyser { margin: 3rem 0 0; }
#analyse-form { margin-top: 1rem; }

textarea {
  width: 100%;
  padding: 0.85rem 0.9rem;
  font: inherit;
  color: var(--ink);
  background: transparent;
  border: 1px solid var(--hairline);
  border-radius: var(--radius-sm);
  resize: vertical;
}
textarea::placeholder { color: var(--muted); }
textarea:focus { outline: none; border-color: var(--focus-ring); }

.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-top: 0.7rem;
}
#counter { font-size: 0.8rem; color: var(--muted); font-variant-numeric: tabular-nums; }

button, .button {
  font: inherit;
  font-weight: 560;
  font-size: 0.92rem;
  padding: 0.52rem 1.1rem;
  border: 1px solid transparent;
  border-radius: 999px;
  cursor: pointer;
  color: var(--on-accent);
  background: var(--action);
  text-decoration: none;
  display: inline-block;
  transition: transform 0.15s ease, filter 0.15s ease;
}
button:hover, .button:hover { transform: translateY(-1px); filter: brightness(1.06); }
button:active, .button:active { transform: translateY(0); }

button.ghost {
  margin-top: 1rem;
  color: var(--muted);
  background: none;
  border-color: var(--hairline);
  font-size: 0.82rem;
  padding: 0.34rem 0.8rem;
}
button.ghost:hover { color: var(--ink); transform: none; filter: none; }

#result { margin-top: 1.25rem; }
#result:empty { display: none; }
pre {
  margin-top: 0.75rem;
  padding: 1rem;
  overflow-x: auto;
  border-radius: var(--radius-sm);
  background: var(--bg-tint);
  border: 1px solid var(--hairline);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.78rem;
}

.cta { margin: 2.75rem 0 0; }

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

footer {
  margin-top: 3.5rem;
  padding: 1.5rem 0 3rem;
  border-top: 1px solid var(--hairline);
  color: var(--muted);
  font-size: 0.86rem;
}
footer p { margin: 0 0 0.4rem; max-width: 105ch; text-wrap: balance; }
footer a { color: var(--ink); text-decoration-color: var(--hairline); }
.links { display: flex; gap: 0.6rem; }

/* ---------- accessibility and graceful degradation ---------- */

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

:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
  border-radius: 4px;
}

/* Glass is a finish, never the thing carrying the text. Where the browser
   cannot blur, or the visitor has asked for less transparency, fall back to a
   solid surface rather than leaving text over an unblurred background. */
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .panel, .langs, .themes { background: var(--bg-tint); }
}
@media (prefers-reduced-transparency: reduce) {
  .panel, .langs, .themes {
    background: var(--bg-tint);
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
  }
  .orb { display: none; }
}

.pair, .analyser, .cta {
  animation: rise 0.5s cubic-bezier(0.2, 0.7, 0.3, 1) backwards;
  animation-delay: calc(var(--stagger, 2) * 70ms);
}
@keyframes rise {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

@media (max-width: 34rem) {
  .site-header { padding-top: 1.75rem; }
  .controls { width: 100%; justify-content: space-between; }
  .lang span { display: none; }   /* flags alone read fine at this width */
  .lang { padding: 0.34rem 0.5rem; }
}
