: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; }
.header-top { position: relative; }
h1 {
  margin: 0;
  color: #fffefa;
  font: 800 40px/1.08 var(--display);
  text-align: center;
}
.admin-link {
  position: absolute;
  top: 3px;
  right: 0;
  color: #b9d6c1;
  font: 10px/1.3 var(--mono);
  text-decoration: none;
}
.admin-link:hover { color: #e1f1e5; 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;
}
.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-results {
  position: absolute;
  top: calc(100% + 8px);
  left: max(0px, calc((100% - 578px) / 2));
  width: min(820px, calc(100% - max(0px, calc((100% - 578px) / 2))));
  max-height: 430px;
  overflow: auto;
  border: 1px solid #b8c8bd;
  border-radius: 16px;
  background: #f4f7f3;
  color: var(--ink);
  box-shadow: 0 18px 36px -25px rgba(6, 23, 25, .55);
  transform: none;
}
.ask-results-toolbar {
  position: sticky;
  z-index: 2;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 38px;
  padding: 0 8px 0 12px;
  border-bottom: 1px solid #d7e0d9;
  background: #edf3ee;
  color: var(--muted);
  font: 10px var(--mono);
}
.ask-results-close {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  padding: 0;
  border: 0;
  border-radius: 2px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 22px;
}
.ask-results-close:hover { background: #e2ebe4; color: var(--ink); }
.ask-results-close:focus-visible { outline: 2px solid var(--header-line); }
.ask-result-item {
  display: grid;
  grid-template-columns: minmax(110px, 1fr) minmax(130px, 1.35fr) 38px 92px;
  gap: 10px;
  align-items: baseline;
  min-height: 50px;
  padding: 10px 12px;
  border-bottom: 1px solid #d7e0d9;
  color: var(--ink);
  text-decoration: none;
}
.ask-result-item:last-of-type { border-bottom: 0; }
.ask-result-item:hover { background: #e8f0e9; box-shadow: inset 2px 0 var(--header-line); }
.ask-result-value { font: 700 16px/1.35 var(--display); overflow-wrap: anywhere; }
.ask-result-context { color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }
.ask-result-dialect, .ask-result-location { color: var(--sage); font: 10px var(--mono); }
.ask-result-dialect { text-align: right; }
.ask-result-location { text-align: right; white-space: nowrap; }
.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(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 { min-width: 34px; color: var(--sage); font: 11px var(--mono); text-align: right; white-space: nowrap; }

.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: 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; }
  .ask-results { right: 0; left: auto; width: 100%; transform: none; }
}

@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%; }
  .ask-result-item { grid-template-columns: minmax(130px, 1fr) minmax(160px, 1.4fr) 44px; }
  .ask-result-location { display: none; }
  .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; }
  .ask-value-panel { height: 34px; padding-left: 2px; }
  .direction-controls { display: grid; grid-template-columns: 1fr 38px 1fr; gap: 7px; }
  .ask-result-item { grid-template-columns: minmax(110px, .8fr) minmax(0, 1.2fr) 34px; gap: 8px; padding: 9px; }
  .ask-result-value { font-size: 15px; }
  .ask-result-context { font-size: 11px; }
  .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; }
}
