:root {
  --ink: #17282b;
  --header: var(--krps-green);
  --header-line: #d39a22;
  --paper: #e9ebe5;
  --card: #fffefa;
  --gold: #b8780b;
  --gold-soft: #f1d18a;
  --karaim: #7a2b2b;
  --sage: #537069;
  --sage-soft: #dce4df;
  --russian: #275575;
  --russian-soft: #e6eef3;
  --polish: #315b45;
  --polish-soft: #e7efe9;
  --line: #cfd5cf;
  --line-dark: #607376;
  --muted: #68787a;
  --display: Georgia, "Times New Roman", serif;
  --body: "Segoe UI", Arial, sans-serif;
  --mono: Consolas, "SFMono-Regular", monospace;
  --krps-green: #17363a;
  --krps-deep: #102a2e;
  --krps-paper: #eae8e1;
  --krps-cream: #faf8f2;
  --krps-gold: #d8a537;
  --krps-gold-soft: #e9c580;
  --krps-ivory: #faf7ee;
  --krps-green-rgb: 23, 54, 58;
  --krps-ivory-rgb: 250, 247, 238;
  --krps-gold-soft-rgb: 233, 197, 128;
  --krps-blue: #3d7290;
  --krps-red: #7a2b2b;
  --krps-karaim: #7a2b2b;
  --krps-polish: #315b45;
  --krps-karaim-serif: "Times New Roman", Times, serif;
  --krps-serif: "PT Serif", Georgia, serif;
  --krps-display: "Source Serif 4", Georgia, serif;
  --krps-mono: "JetBrains Mono", Consolas, monospace;
}

* { box-sizing: border-box; }
body {
  font: 16px/1.55 var(--body);
  letter-spacing: 0;
}
button, input { font: inherit; letter-spacing: 0; }
.wrap { margin: 0 auto; }
.header-top { position: relative; }
h1 {
  margin: 0;
  color: #fffefa;
  font: 800 40px/1.08 var(--display);
  text-align: center;
}
.admin-link {
  top: 3px;
  right: 0;
}
.admin-link:hover { text-decoration: underline; }
.admin-link:focus-visible { outline: 1px solid #b9d6c1; outline-offset: 3px; }

.direction-controls {
  display: flex;
  align-items: end;
  justify-content: center;
  gap: 12px;
  margin: 18px 0;
}
.picker { min-width: 258px; }
.picker > span {
  display: block;
  margin-bottom: 5px;
  color: #a9bbba;
  font: 10px/1.3 var(--mono);
  text-transform: uppercase;
}
.segments { display: grid; grid-template-columns: repeat(3, 1fr); border: 1px solid var(--line-dark); border-radius: 3px; overflow: hidden; }
.segments button {
  min-width: 0;
  height: 36px;
  padding: 0 10px;
  border: 0;
  border-right: 1px solid var(--line-dark);
  background: transparent;
  color: #bdc9c7;
  cursor: pointer;
  font: 12px var(--mono);
}
.segments button:last-child { border-right: 0; }
.segments button:hover { color: #fff; background: #21494d; }
.segments button[aria-pressed="true"] { color: var(--header); background: var(--gold-soft); font-weight: 700; }
.segments button:focus-visible, .icon-button:focus-visible { outline: 2px solid var(--gold-soft); outline-offset: 2px; }
.segment-short { display: none; }
.icon-button {
  display: inline-grid;
  place-items: center;
  border: 0;
  padding: 0;
  cursor: pointer;
}
.swap-button {
  width: 38px;
  height: 38px;
  border: 1px solid var(--line-dark);
  border-radius: 50%;
  background: transparent;
  color: var(--gold-soft);
  font-size: 20px;
}
.swap-button:hover { background: #21494d; }

.search-area { position: relative; }
.search-field { position: relative; }
.search-field input {
  width: 100%;
  height: 60px;
  padding: 0 54px 0 52px;
  border: 1px solid #9da7a2;
  border-radius: 4px;
  background: var(--card);
  color: var(--ink);
  box-shadow: 0 12px 26px -18px #07191b;
  font: 23px var(--display);
}
.search-field input:focus { outline: 3px solid var(--header-line); outline-offset: 2px; }
.search-icon {
  position: absolute;
  z-index: 1;
  left: 20px;
  top: 20px;
  width: 16px;
  height: 16px;
  border: 2px solid var(--sage);
  border-radius: 50%;
  pointer-events: none;
}
.search-icon::after {
  content: "";
  position: absolute;
  width: 8px;
  height: 2px;
  right: -6px;
  bottom: -3px;
  background: var(--sage);
  transform: rotate(45deg);
}
.clear-button {
  position: absolute;
  right: 8px;
  top: 8px;
  width: 44px;
  height: 44px;
  background: transparent;
  color: var(--muted);
  font-size: 28px;
  visibility: hidden;
  display: none !important;
}
.clear-button.visible { visibility: visible; }
.clear-button:hover { color: var(--ink); }
.dataset-count { min-height: 18px; margin: 8px 0 0; color: #a9bbba; font: 11px var(--mono); }

.ask-console {
  position: relative;
  z-index: 30;
  display: grid;
  grid-template-columns: max(0px, calc((100% - 578px) / 2 - 12px)) minmax(0, 420px) minmax(0, 1fr);
  gap: 12px;
  align-items: end;
  width: 100%;
  margin: 16px auto 0;
  padding: 0;
  background: transparent;
}
.ask-form { grid-column: 2; width: auto; margin: 0; }
.ask-form label {
  display: block;
  margin: 0 0 4px 2px;
  color: #aebfbd;
  font: 9px var(--mono);
  text-transform: uppercase;
}
.ask-controls { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; }
.ask-controls input {
  min-width: 0;
  height: 40px;
  padding: 0 12px;
  border: 2px solid #24484b;
  border-radius: 22px;
  background: #cad8cd;
  color: var(--ink);
  font-size: 13px;
}
.ask-controls input:focus { position: relative; border-color: #102f32; outline: 2px solid #102f32; outline-offset: 1px; }
.ask-controls button {
  min-width: 84px;
  height: 40px;
  padding: 0 12px;
  border: 1px solid #91a9a1;
  border-radius: 20px;
  background: transparent;
  color: var(--gold-soft);
  cursor: pointer;
  font-weight: 700;
  font-size: 13px;
}
.ask-controls button:hover { background: #2d5659; color: #ffe2a0; }
.ask-controls button:focus-visible { outline: 2px solid var(--header-line); outline-offset: 2px; }
.ask-controls button:disabled { cursor: default; opacity: .7; }
.ask-value-panel {
  grid-column: 3;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 12px;
  align-items: center;
  justify-self: end;
  min-width: 0;
  width: calc(100% + 12px);
  min-height: 40px;
  padding: 0 2px;
  border: 0;
  background: transparent;
  overflow: visible;
}
.ask-value-panel strong {
  min-width: 56px;
  padding: 0;
  color: var(--gold-soft);
  font: 800 28px var(--display);
  text-align: right;
  white-space: nowrap;
}
.ask-value-panel small {
  display: block;
  min-width: 0;
  overflow: visible;
  color: #c7d2d0;
  font: 11px/1.4 var(--mono);
  white-space: normal;
}
.ask-value-panel small.error { color: #ffb1bf; }
.ask-truncated { margin: 0; padding: 8px 12px; border-top: 1px solid #d7e0d9; color: var(--muted); font: 10px var(--mono); text-align: center; }

.suggestions {
  display: none;
  position: absolute;
  z-index: 20;
  top: 66px;
  left: 0;
  right: 0;
  max-height: 410px;
  overflow: auto;
  border: 1px solid #aeb7b2;
  border-radius: 4px;
  background: var(--card);
  box-shadow: 0 26px 52px -24px #061719;
}
.suggestions.open { display: block; }
.suggestion {
  display: grid;
  grid-template-columns: minmax(200px, 1fr) minmax(200px, 330px) auto;
  gap: 14px;
  align-items: baseline;
  width: 100%;
  min-height: 52px;
  padding: 9px 14px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
  color: var(--ink);
  text-align: left;
  cursor: pointer;
}
.suggestion:last-child { border-bottom: 0; }
.suggestion:hover, .suggestion.active { background: #f1f0e9; box-shadow: inset 3px 0 var(--header-line); }
.suggestion-primary { min-width: 0; color: var(--ink); font: 700 18px var(--display); overflow-wrap: anywhere; }
.suggestion-translations { display: grid; min-width: 0; gap: 3px; }
.suggestion-translation { display: grid; min-width: 0; grid-template-columns: 26px minmax(0,1fr); gap: 7px; align-items: baseline; color: var(--sage); }
.suggestion-language { color: color-mix(in srgb, currentColor 70%, transparent); font: 9px var(--mono); text-transform: uppercase; }
.suggestion-translation-text { min-width: 0; overflow: hidden; font-size: 13px; text-overflow: ellipsis; white-space: nowrap; }
.suggestion-tag { display: flex; min-width: 54px; justify-content: flex-end; gap: 7px; color: var(--sage); font: 11px var(--mono); text-align: right; white-space: nowrap; }
.suggestion-origin { color: color-mix(in srgb, currentColor 72%, transparent); }
.loading, .start-state, .empty-state { color: var(--muted); text-align: center; }
.ask-clarification { width: min(760px, calc(100% - 40px)); margin: 42px auto; }
.ask-clarification h2 { margin: 0 0 8px; color: var(--ink); font: 700 24px/1.25 var(--display); }
.ask-clarification > p { margin: 0 0 22px; color: var(--muted); }
.ask-clarification-options { border-top: 1px solid var(--line); }
.ask-clarification-options button {
  display: grid;
  width: 100%;
  gap: 4px;
  padding: 14px 8px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
  color: var(--ink);
  text-align: left;
  cursor: pointer;
}
.ask-clarification-options button:hover { background: var(--sage-soft); box-shadow: inset 3px 0 var(--header-line); }
.ask-clarification-options button:focus-visible { outline: 2px solid var(--header-line); outline-offset: -2px; }
.ask-clarification-options strong { font: 700 16px/1.35 var(--display); }
.ask-clarification-options span { color: var(--sage); font: 10px/1.4 var(--mono); }
.loading-indicator { display: inline-flex; align-items: center; gap: 6px; }
.loading-indicator i { width: 6px; height: 6px; border-radius: 50%; background: currentColor; animation: loadingPulse 1.1s ease-in-out infinite; }
.loading-indicator i:nth-child(2) { animation-delay: .14s; }
.loading-indicator i:nth-child(3) { animation-delay: .28s; }

@keyframes loadingPulse {
  0%, 70%, 100% { opacity: .28; transform: scale(.72); }
  35% { opacity: 1; transform: scale(1); }
}

@media (prefers-reduced-motion: reduce) {
  .loading-indicator i { animation: none; opacity: .65; }
}
.start-number { display: block; margin-bottom: 6px; }
.result-status {
  display: flex;
  align-items: center;
  text-transform: uppercase;
  letter-spacing: .09em;
}
.result-status::after { content: ""; flex: 1; height: 1px; }
.entry-layout { display: grid; }
.head-line { display: flex; align-items: baseline; flex-wrap: wrap; }
.headword { margin: 0; overflow-wrap: anywhere; }
.homonym { font: 700 17px var(--display); }
.dialect-group { display: inline-flex; }
.entry-origin { display: inline-flex; flex-wrap: wrap; align-items: baseline; gap: 5px; color: var(--sage); font: italic 14px/1.3 var(--display); }
.entry-origin-label { color: #7f8f88; font: 500 8px/1 var(--mono); text-transform: uppercase; }
.abbreviation {
  border-radius: 2px;
  cursor: help;
  text-decoration-line: underline;
  text-decoration-style: dotted;
  text-decoration-color: #91a49a;
  text-underline-offset: 4px;
}
.abbreviation:hover, .abbreviation:focus-visible {
  color: var(--ink);
  outline: none;
  background: #e4e9e3;
}
.abbreviation-tooltip {
  position: fixed;
  z-index: 1000;
  max-width: min(280px, calc(100vw - 20px));
  padding: 7px 10px;
  border: 1px solid #34565a;
  border-radius: 3px;
  background: var(--krps-green);
  box-shadow: 0 8px 20px -12px #07191b;
  color: #fff;
  font: 12px/1.35 var(--sans);
  pointer-events: none;
}
.abbreviation-tooltip::after {
  content: "";
  position: absolute;
  left: calc(50% - 5px);
  bottom: -6px;
  width: 9px;
  height: 9px;
  border-right: 1px solid #34565a;
  border-bottom: 1px solid #34565a;
  background: var(--krps-green);
  transform: rotate(45deg);
}
.abbreviation-tooltip.below::after {
  top: -6px;
  bottom: auto;
  border: 0;
  border-top: 1px solid #34565a;
  border-left: 1px solid #34565a;
}
.abbreviation-tooltip[hidden] { display: none; }
.phrase-only { color: var(--polish); font: 10px var(--mono); text-transform: uppercase; }
.source-abbreviation { color: inherit; font: inherit; font-style: normal; }

.sense { position: relative; }
.sense + .sense { border-top: 1px dashed var(--line); }
.sense-number {
  position: absolute;
}
.category + .category { position: relative; border-top: 1px solid var(--line); }
.category + .category::before {
  content: "||";
  position: absolute;
  top: -11px;
  left: 0;
  padding-right: 7px;
  background: var(--card);
  color: var(--sage);
  font: 700 13px var(--mono);
}
.translation-row { display: grid; }
.translation-text { overflow-wrap: anywhere; }
mark { padding: 0 1px; background: #f2d887; color: inherit; }

.examples { margin: 8px 0 2px; border-top: 0; }
.example { padding: 7px 10px 8px; border-radius: 4px; background: #f2f2ec; }
.example + .example { margin-top: 4px; border-top: 0; }
.example-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 7px; }
.example-label { padding: 2px 6px; border-radius: 3px; background: #efe4cc; color: #81591d; font: 700 9px/1.2 var(--mono); text-transform: uppercase; }
.example-translations { display: flex; flex-direction: column; align-items: stretch; gap: 3px; margin-top: 3px; }
.example-translation { display: grid; grid-template-columns: 34px minmax(0, 1fr); align-items: baseline; gap: 5px; margin-top: 0; font-size: 14px; font-style: normal; overflow-wrap: anywhere; }
.example-translation-text i { font-style: italic; }
.example-translation.kar { color: var(--karaim); font-family: var(--display); font-style: normal; font-weight: 700; }
.morph-gloss-link { color: inherit; text-decoration: underline; text-decoration-color: #b57d67; text-decoration-thickness: 1px; text-underline-offset: 2px; }
.morph-gloss-link:hover { color: #7d3029; text-decoration-color: currentColor; }
.morph-gloss-link:focus-visible { outline: 2px solid #b57d67; outline-offset: 2px; }
.example-translation.kar .morph-gloss-link { text-decoration: none; }
.example-translation.ru { color: var(--russian); }
.example-translation .lang-code { display: inline-block; padding: 2px 4px; border-radius: 3px; }
.example-translation.kar .lang-code { background: #f2e6e3; color: var(--karaim); font-family: var(--mono); font-weight: 400; }
.example-translation.ru .lang-code { background: var(--russian-soft); color: var(--russian); }
.example-translation.pl .lang-code { background: var(--polish-soft); color: var(--polish); }
.example-source-references { margin-left: 6px; color: #7f6530; font: 11px var(--mono); font-style: normal; white-space: nowrap; }
.idioms { margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--line); }
.meaning-subcategory { padding-left: 0; }
.examples.meaning-subcategory { margin-left: 52px; }
.idioms.meaning-subcategory { margin-left: 98px; }
.redirects { margin-top: 10px; color: var(--sage); font-style: italic; }
.entry-footer { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.entry-meta { color: var(--muted); font: 10px/1.5 var(--mono); }
.verify-button {
  flex: 0 0 auto;
  cursor: pointer;
}
.verify-button:hover { border-color: var(--sage); background: var(--sage-soft); color: var(--ink); }
.verify-button:focus-visible { outline: 2px solid var(--header-line); outline-offset: 2px; }
.verify-button:disabled { cursor: default; opacity: .72; }
.verify-button.sent { border-color: #6d9077; background: #e3eee5; color: #315b3c; }

.scan-panel {
  display: flex;
  flex-direction: column;
}
.scan-stage {
  display: grid;
  place-items: center;
  overflow: hidden;
}
.scan-stage canvas { display: block; height: auto; }
.ocr-scan-surface { position: relative; width: 100%; min-width: 0; line-height: 0; }
.ocr-scan-surface canvas { user-select: none; }
.ocr-text-layer { position: absolute; top: 0; left: 0; transform-origin: top left; pointer-events: none; user-select: text; -webkit-user-select: text; }
.ocr-scan-char { position: absolute; display: inline-block; white-space: pre; color: transparent; font-family: var(--krps-karaim-serif); transform-origin: top left; pointer-events: auto; cursor: text; }
.scan-panel .ocr-scan-char[data-morph-word] { cursor: help; }
.scan-panel .ocr-scan-char[data-morph-target] { cursor: pointer; }
.scan-panel .ocr-scan-char[data-morph-target]:focus-visible { outline: 2px solid #9e4536; outline-offset: 2px; }
.morph-tooltip { position: fixed; z-index: 1000; display: flex; align-items: center; flex-wrap: wrap; gap: 3px; max-width: min(440px, calc(100vw - 16px)); padding: 5px 6px; border: 1px solid #cbd2d3; border-radius: 5px; background: #fff; box-shadow: 0 3px 12px #26323029; pointer-events: none; font: 700 14px/1.2 var(--krps-karaim-serif); }
.morph-tooltip[hidden] { display: none; }
.morph-part { padding: 3px 6px; border-radius: 7px; white-space: nowrap; }
.morph-part-0 { background: #dce9f2; color: #183e61; }
.morph-part-1 { background: #e7d9ef; color: #693783; }
.morph-part-2 { background: #f5d8dd; color: #92373d; }
.morph-part-3 { background: #fbe8b8; color: #805511; }
.morph-separator { color: #899298; padding: 0 1px; }
.ocr-paint-gap { display: none; position: absolute; pointer-events: none; }
.ocr-selection-painted:has(+ .ocr-selection-painted) > .ocr-paint-gap,
.source-view.ocr-select-all .ocr-paint-gap { display: block; background: rgba(36, 118, 203, .32); }
.ocr-scan-char.ocr-selection-painted::before,
.source-view.ocr-select-all .ocr-scan-char::before {
  content: "";
  position: absolute;
  left: var(--ocr-paint-left, 0px);
  top: var(--ocr-paint-top, 0px);
  width: var(--ocr-paint-width, 100%);
  height: var(--ocr-paint-height, 100%);
  background: rgba(36, 118, 203, .32);
  pointer-events: none;
}
.ocr-scan-char[data-ocr-end-pipe="true"]::after,
.ocr-scan-char[data-ocr-end-hyphen="true"]::after,
.ocr-scan-char[data-ocr-end-glyph="true"]::after { content: ""; position: absolute; left: 100%; top: 0; width: 12px; height: 100%; }
.source-view *::selection,
.ocr-text-layer::selection,
.ocr-text-layer *::selection { color: transparent !important; background: transparent !important; }
.ocr-selection-mirror { position: fixed; left: 0; top: 0; width: 1px; height: 1px; overflow: hidden; opacity: 0; font-size: 0; white-space: pre; pointer-events: none; }
.scan-linebreak-meta {
  display: inline-block;
  margin-left: 4px;
  color: var(--muted);
  font-size: 0.9em;
}
.scan-linebreak-meta code {
  color: var(--ink);
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 0.95em;
}
.scan-message { padding: 20px; color: var(--muted); font: 11px var(--mono); text-align: center; }
.scan-error { color: var(--krps-red); }
.scan-caption { margin-top: 8px; }
.load-more {
  display: block;
  min-width: 160px;
  height: 42px;
  margin: 22px auto 0;
  border: 1px solid var(--sage);
  border-radius: 3px;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
}
.load-more:hover { background: var(--sage-soft); }

@media (max-width: 960px) {
  .ask-console {
    grid-template-columns: minmax(0, 1.35fr) minmax(260px, 1fr);
    gap: 12px;
    width: min(820px, 100%);
  }
  .ask-form { grid-column: 1; }
  .ask-value-panel { grid-column: 2; }
}

@media (max-width: 820px) {
  .header-top { padding-right: 52px; }
  h1 { font-size: 34px; text-align: left; }
  .admin-link { top: 2px; }
  .ask-console { grid-template-columns: 1fr; gap: 8px; }
  .ask-form, .ask-value-panel { grid-column: 1; }
  .ask-value-panel { width: 100%; }
  .scan-panel { border-top: 1px solid var(--line); }
}

@media (max-width: 640px) {
  h1 { font-size: 29px; }
  .ask-value-panel { height: 34px; padding-left: 2px; }
  .direction-controls { display: grid; grid-template-columns: 1fr 38px 1fr; gap: 7px; }
  .picker { min-width: 0; }
  .segments button { height: 34px; padding: 0 5px; font-size: 10px; }
  .segment-long { display: none; }
  .segment-short { display: inline; }
  .search-field input { height: 54px; font-size: 20px; }
  .search-icon { top: 17px; }
  .clear-button { top: 5px; }
  .suggestion { grid-template-columns: minmax(0, 1fr) auto; gap: 4px 10px; }
  .suggestion-primary { grid-column: 1; }
  .suggestion-translations { grid-column: 1 / -1; white-space: normal; }
  .suggestion-translation-text { white-space: normal; }
  .suggestion-tag { grid-column: 2; grid-row: 1; }
  .entry-footer { align-items: flex-start; flex-direction: column; }
}
