:root {
  --ink: #17282b;
  --header: #17363a;
  --header-line: #d39a22;
  --paper: #e9ebe5;
  --card: #fffefa;
  --gold: #b8780b;
  --gold-soft: #f1d18a;
  --sage: #537069;
  --sage-soft: #dce4df;
  --russian: #275575;
  --russian-soft: #e6eef3;
  --polish: #7d3548;
  --polish-soft: #f4e9ec;
  --line: #cfd5cf;
  --line-dark: #607376;
  --muted: #68787a;
  --display: Georgia, "Times New Roman", serif;
  --body: "Segoe UI", Arial, sans-serif;
  --mono: Consolas, "SFMono-Regular", monospace;
}

* { box-sizing: border-box; }
html { min-width: 320px; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 16px/1.55 var(--body);
  letter-spacing: 0;
}
button, input { font: inherit; letter-spacing: 0; }
.wrap { width: min(1080px, calc(100% - 32px)); margin: 0 auto; }

.app-header {
  color: #f7f7f1;
  background: var(--header);
  border-bottom: 3px solid var(--header-line);
}
.header-inner { padding: 24px 0 28px; }
h1 {
  margin: 0;
  color: #fffefa;
  font: 800 40px/1.08 var(--display);
}

.language-rail { width: min(620px, 100%); margin: 14px auto 0; }
.language-rail svg { display: block; width: 100%; height: 80px; overflow: visible; }
#direction-arc { fill: none; stroke: var(--gold-soft); stroke-width: 2; stroke-linecap: round; }
#arrow-tip path { fill: var(--gold-soft); }
.rail-node { cursor: pointer; }
.rail-node circle { fill: transparent; stroke: #82999a; stroke-width: 1.5; transition: 160ms ease; }
.rail-node text { fill: #a9bbba; font: 700 12px var(--mono); text-anchor: middle; pointer-events: none; }
.rail-node:hover circle { stroke: var(--gold-soft); }
.rail-node.is-source circle { stroke: var(--gold-soft); stroke-width: 2.5; }
.rail-node.is-source text { fill: var(--gold-soft); }
.rail-node.is-target circle { fill: var(--gold-soft); stroke: var(--gold-soft); }
.rail-node.is-target text { fill: var(--header); }
.rail-node:focus-visible { outline: 2px solid var(--gold-soft); outline-offset: 3px; }

.direction-controls {
  display: flex;
  align-items: end;
  justify-content: center;
  gap: 12px;
  margin: -2px 0 18px;
}
.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;
}
.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); }

.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(130px, 230px) 1fr 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-head { font: 700 18px var(--display); }
.suggestion-context { min-width: 0; overflow: hidden; color: var(--muted); font-size: 13px; text-overflow: ellipsis; white-space: nowrap; }
.suggestion.source-first .suggestion-context { color: var(--ink); font: 700 16px var(--display); }
.suggestion.source-first .suggestion-head { color: var(--sage); font-size: 16px; }
.suggestion-tag { color: var(--sage); font: 10px var(--mono); text-transform: uppercase; }

.main-content { padding: 26px 0 72px; }
.loading, .start-state, .empty-state { padding: 56px 20px; color: var(--muted); text-align: center; }
.start-number { display: block; margin-bottom: 6px; color: var(--ink); font: 700 24px var(--display); }
.result-status {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 0 0 16px;
  color: var(--sage);
  font: 11px var(--mono);
  text-transform: uppercase;
}
.result-status::after { content: ""; flex: 1; height: 1px; background: #bdc7c1; }

.entry-card {
  margin: 0 0 14px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--card);
  box-shadow: 0 10px 30px -25px #07191b;
  overflow: hidden;
}
.entry-layout { display: grid; grid-template-columns: minmax(0, 1fr) 330px; }
.entry-copy { min-width: 0; padding: 20px 22px 18px; }
.entry-head { padding-bottom: 11px; border-bottom: 1px solid var(--line); }
.head-line { display: flex; align-items: baseline; gap: 9px; flex-wrap: wrap; }
.headword { margin: 0; font: 800 29px/1.1 var(--display); overflow-wrap: anywhere; }
.homonym { color: var(--gold); font: 700 17px var(--display); }
.dialect-group { display: inline-flex; gap: 5px; }
.dialect, .origin { color: var(--sage); font: italic 16px var(--display); }
.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: #17363a;
  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: #17363a;
  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; }
.transcriptions { margin-top: 5px; color: var(--sage); font: 14px var(--display); }
.transcription + .transcription::before { content: ", "; color: #9baa9f; }
.source-mark { color: #7f6530; font: 11px var(--mono); }
.source-abbreviation { color: inherit; font: inherit; font-style: normal; }
.derivative { margin-top: 8px; color: var(--muted); font-style: italic; }

.sense { position: relative; padding: 13px 0 4px 38px; }
.sense + .sense { border-top: 1px dashed var(--line); }
.sense-number {
  position: absolute;
  left: 0;
  top: 13px;
  color: var(--gold);
  font: 800 18px var(--display);
}
.category + .category { position: relative; margin-top: 12px; padding-top: 15px; 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; grid-template-columns: 38px minmax(0, 1fr); gap: 8px; padding: 4px 7px; border-left: 3px solid transparent; }
.translation-row.target { border-left-color: var(--header-line); }
.translation-row.ru { color: var(--russian); }
.translation-row.pl { color: var(--polish); }
.lang-code { padding-top: 4px; color: var(--muted); font: 10px var(--mono); }
.translation-text { font: 17px/1.5 var(--display); overflow-wrap: anywhere; }
.translation-row.target .translation-text { font-size: 19px; font-weight: 700; }
mark { padding: 0 1px; background: #f2d887; color: inherit; }

.examples { margin: 8px 0 2px; border-top: 1px solid var(--line); }
.example { padding: 9px 0 8px; }
.example + .example { border-top: 1px dotted var(--line); }
.example-original { font: 700 16px/1.45 var(--display); overflow-wrap: anywhere; }
.example-translation { margin-top: 2px; font-size: 14px; font-style: italic; overflow-wrap: anywhere; }
.example-translation.ru { color: var(--russian); }
.example-translation.pl { color: var(--polish); }
.idioms { margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--line); }
.idiom-title { margin: 0 0 5px; color: var(--gold); font: 13px var(--mono); }
.redirects { margin-top: 10px; color: var(--sage); font-style: italic; }
.entry-footer { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 12px; }
.entry-meta { color: var(--muted); font: 10px/1.5 var(--mono); }
.verify-button {
  flex: 0 0 auto;
  min-height: 28px;
  padding: 4px 9px;
  border: 1px solid #9caaa4;
  border-radius: 3px;
  background: transparent;
  color: var(--sage);
  cursor: pointer;
  font: 10px/1.2 var(--mono);
}
.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;
  min-width: 0;
  padding: 16px;
  border-left: 1px solid var(--line);
  background: #f1f2ed;
}
.scan-stage {
  display: grid;
  place-items: center;
  min-height: 148px;
  overflow: hidden;
  border: 1px solid #c9cec8;
  background: #fff;
}
.scan-stage canvas { display: block; width: 100%; height: auto; }
.scan-message { padding: 20px; color: var(--muted); font: 11px var(--mono); text-align: center; }
.scan-caption { margin-top: 8px; color: var(--muted); font: 10px/1.45 var(--mono); }
.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: 820px) {
  h1 { font-size: 34px; }
  .entry-layout { grid-template-columns: 1fr; }
  .scan-panel { border-top: 1px solid var(--line); border-left: 0; }
  .scan-stage { min-height: 100px; }
}

@media (max-width: 640px) {
  .wrap { width: min(100% - 20px, 1080px); }
  .header-inner { padding-top: 18px; }
  h1 { font-size: 29px; }
  .language-rail { margin-top: 8px; }
  .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: 1fr auto; gap: 4px 10px; }
  .suggestion-context { grid-column: 1 / -1; white-space: normal; }
  .entry-copy { padding: 17px 15px 15px; }
  .entry-footer { align-items: flex-start; flex-direction: column; }
  .headword { font-size: 25px; }
  .sense { padding-left: 30px; }
  .translation-row { grid-template-columns: 32px minmax(0, 1fr); padding-right: 2px; }
  .translation-text { font-size: 16px; }
  .translation-row.target .translation-text { font-size: 18px; }
}
