:root {
  color-scheme: light;
  --navy: #343d5a;
  --navy-2: #252d46;
  --coral: #de6a5b;
  --coral-dark: #bc5044;
  --mint: #eaf4f3;
  --blue-gray: #bcc9d1;
  --cream: #f4eae0;
  --paper: #ffffff;
  --ink: #232a3d;
  --muted: #6a7183;
  --line: #dce1e8;
  --shadow: 0 18px 45px rgba(52, 61, 90, 0.11);
  font-family: Inter, "Roboto Flex", Roboto, Arial, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  min-width: 320px;
  color: var(--ink);
  background: linear-gradient(180deg, #f6f8fb 0, #fff 340px);
  font-size: 16px;
  line-height: 1.5;
}

button, input { font: inherit; }
button { cursor: pointer; }

.topbar {
  min-height: 82px;
  padding: 14px clamp(20px, 4vw, 64px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  color: white;
  background: var(--navy);
  border-bottom: 5px solid var(--coral);
}

.brand { display: flex; align-items: center; gap: 14px; }
.brand-mark {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border-radius: 15px 15px 15px 4px;
  color: white;
  background: var(--coral);
  font-family: Georgia, serif;
  font-size: 30px;
  font-weight: 700;
}
.brand h1 { margin: 0; font-size: clamp(1.25rem, 2.2vw, 1.8rem); line-height: 1.1; }
.brand p { margin: 4px 0 0; color: #dfe4ef; font-size: .88rem; }

.top-actions { display: flex; align-items: center; gap: 18px; }
.site-nav { display: flex; gap: 6px; padding: 4px; background: rgba(255,255,255,.08); border-radius: 12px; }
.site-nav a { padding: 8px 13px; color: #e5e9f1; border-radius: 9px; text-decoration: none; font-size: .9rem; font-weight: 700; }
.site-nav a:hover, .site-nav a.active { color: var(--navy); background: white; }

.ghost-button {
  padding: 10px 15px;
  color: white;
  background: transparent;
  border: 1px solid rgba(255,255,255,.42);
  border-radius: 10px;
}
.ghost-button:hover { background: rgba(255,255,255,.08); }

.shell { padding: 30px clamp(16px, 4vw, 64px) 64px; }
.workspace { max-width: 1760px; margin: 0 auto; }

.search-card {
  padding: clamp(22px, 3vw, 34px);
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 24px;
  box-shadow: var(--shadow);
}
.search-card > label { display: block; margin-bottom: 10px; color: var(--navy); font-weight: 750; font-size: 1.05rem; }
.search-row { position: relative; display: flex; align-items: center; }
.search-icon { position: absolute; left: 18px; color: var(--coral); font-size: 1.8rem; transform: rotate(-15deg); }
.search-row input {
  width: 100%;
  min-height: 58px;
  padding: 12px 54px;
  color: var(--navy-2);
  background: #fafbfc;
  border: 2px solid var(--blue-gray);
  border-radius: 16px;
  outline: none;
  font-size: 1.08rem;
}
.search-row input:focus { border-color: var(--coral); box-shadow: 0 0 0 4px rgba(222,106,91,.13); }
.clear-button { position: absolute; right: 13px; width: 36px; height: 36px; border: 0; border-radius: 50%; color: var(--muted); background: transparent; font-size: 1.55rem; }
.clear-button:hover { color: var(--navy); background: var(--cream); }
.quick-links { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.quick-links button { padding: 7px 12px; color: var(--navy); background: var(--mint); border: 0; border-radius: 999px; }
.quick-links button:hover { color: white; background: var(--navy); }

.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin: 22px 0; }
.stats div { display: flex; align-items: baseline; gap: 10px; padding: 15px 18px; background: white; border: 1px solid var(--line); border-radius: 15px; }
.stats strong { color: var(--coral); font-size: 1.6rem; line-height: 1; }
.stats span { color: var(--muted); font-size: .88rem; }

.content-grid { display: grid; grid-template-columns: 245px minmax(420px, .95fr) minmax(420px, 1.15fr); gap: 18px; align-items: start; }
.filters, .results, .detail-panel { background: var(--paper); border: 1px solid var(--line); border-radius: 18px; }
.filters { position: sticky; top: 18px; padding: 20px; }
.filter-heading, .results-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.filter-heading h2, .results-head h2 { margin: 0; color: var(--navy); font-size: 1.18rem; }
.filter-heading button { color: var(--coral-dark); background: transparent; border: 0; font-size: .88rem; }
.section-filters { display: grid; gap: 7px; margin: 15px 0 20px; }
.section-button { display: grid; grid-template-columns: 28px 1fr; gap: 8px; align-items: center; width: 100%; padding: 9px 10px; text-align: left; color: var(--navy); background: transparent; border: 0; border-radius: 10px; }
.section-button .number { width: 27px; height: 27px; display: grid; place-items: center; color: var(--coral-dark); background: var(--cream); border-radius: 8px; font-weight: 800; }
.section-button span:last-child { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; font-size: .9rem; }
.section-button:hover, .section-button.active { background: var(--mint); }
.section-button.active .number { color: white; background: var(--coral); }
.check-row { display: flex; align-items: flex-start; gap: 10px; padding: 10px 0; border-top: 1px solid var(--line); font-size: .9rem; }
.check-row input { width: 18px; height: 18px; margin-top: 2px; accent-color: var(--coral); }
.thesaurus-filter-row { color: var(--navy); font-weight: 750; }

.results { min-height: 620px; padding: 20px 12px; }
.results-head { padding: 0 8px 15px; border-bottom: 1px solid var(--line); }
.eyebrow { margin: 0 0 3px; color: var(--coral-dark); font-size: .72rem; font-weight: 850; letter-spacing: .1em; text-transform: uppercase; }
.count-pill { min-width: 42px; padding: 5px 10px; text-align: center; color: var(--navy); background: var(--mint); border-radius: 999px; font-size: .85rem; font-weight: 750; }
.result-list { display: grid; }
.term-row { width: 100%; display: grid; grid-template-columns: 58px 1fr auto; gap: 10px; align-items: center; padding: 15px 10px; text-align: left; color: inherit; background: transparent; border: 0; border-bottom: 1px solid var(--line); }
.term-row:hover, .term-row.active { background: #f8fafb; }
.term-row.active { box-shadow: inset 4px 0 0 var(--coral); }
.code { color: var(--coral-dark); font-weight: 800; font-size: .86rem; }
.term-name { color: var(--navy-2); font-weight: 720; }
.term-meta { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; margin-top: 3px; color: var(--muted); font-size: .78rem; }
.thesaurus-badge { display: inline-flex; align-items: center; gap: 5px; padding: 3px 8px; color: #7b382f; background: #fff1d8; border: 1px solid #efbc71; border-radius: 999px; font-size: .76rem; font-weight: 850; line-height: 1.2; white-space: nowrap; }
.thesaurus-badge::before { content: "✓"; color: var(--coral-dark); font-weight: 900; }
.arrow { color: var(--blue-gray); font-size: 1.2rem; }
.load-more { width: calc(100% - 16px); margin: 14px 8px 0; padding: 11px; color: var(--navy); background: var(--mint); border: 0; border-radius: 10px; font-weight: 700; }
.empty-state { padding: 54px 20px; text-align: center; color: var(--muted); }
.empty-state strong, .empty-state span { display: block; }
.empty-state strong { margin-bottom: 7px; color: var(--navy); font-size: 1.1rem; }

.detail-panel {
  position: sticky;
  top: 18px;
  height: var(--detail-viewport-height, calc(100vh - 36px));
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
  scrollbar-width: thin;
  scrollbar-color: var(--blue-gray) transparent;
}
.detail-panel::-webkit-scrollbar { width: 10px; }
.detail-panel::-webkit-scrollbar-track { background: transparent; }
.detail-panel::-webkit-scrollbar-thumb { background: var(--blue-gray); border: 3px solid white; border-radius: 999px; }
.detail-panel::-webkit-scrollbar-thumb:hover { background: #98a9b5; }
.site-credit {
  max-width: 1760px;
  margin: 18px auto 0;
  padding: 18px clamp(16px, 4vw, 64px) 28px;
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 14px;
  color: var(--muted);
  font-size: .78rem;
  letter-spacing: .01em;
  border-top: 1px solid var(--line);
}
.site-credit a { display: inline-flex; opacity: .72; transition: opacity .16s ease; }
.site-credit a:hover, .site-credit a:focus-visible { opacity: 1; }
.site-credit img { display: block; width: 112px; height: auto; }
.detail-empty { min-height: 618px; display: grid; place-content: center; padding: 36px; text-align: center; color: var(--muted); }
.detail-empty h2 { margin: 12px 0 4px; color: var(--navy); }
.detail-empty p { max-width: 350px; margin: 0; }
.book-symbol { width: 64px; height: 64px; display: grid; place-items: center; margin: auto; color: white; background: var(--coral); border-radius: 50% 50% 50% 12px; font-size: 1.7rem; }
.detail-hero { padding: 26px 28px 22px; color: white; background: var(--navy); border-bottom: 5px solid var(--coral); }
.detail-badges { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.detail-code { display: inline-block; padding: 4px 9px; color: var(--navy); background: white; border-radius: 7px; font-size: .8rem; font-weight: 850; }
.hero-badge { padding: 5px 10px; color: #713126; background: #ffd294; border-color: #ffd294; font-size: .76rem; }
.detail-hero h2 { margin: 0; font-family: Georgia, "Times New Roman", serif; font-size: clamp(1.65rem, 3vw, 2.4rem); line-height: 1.12; }
.detail-body { display: grid; gap: 20px; padding: 25px 28px 30px; }
.detail-section h3 { margin: 0 0 9px; color: var(--navy); font-size: .85rem; letter-spacing: .07em; text-transform: uppercase; }
.definition { margin: 0; font-size: 1.08rem; line-height: 1.62; }
.definition.loading { color: var(--muted); }
.definition-gallery { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin: 18px 0 4px; }
.definition-gallery[hidden] { display: none; }
.definition-gallery figure { min-width: 0; margin: 0; }
.definition-gallery figure:first-child:nth-last-child(3) { grid-column: 1 / -1; }
.definition-gallery img { display: block; width: 100%; height: 210px; object-fit: contain; object-position: center; border: 1px solid var(--line); border-radius: 14px; background: #fff; }
.definition-gallery figure:first-child:nth-last-child(3) img { height: 300px; }
.definition-gallery figcaption { margin-top: 7px; color: var(--muted); font-size: .76rem; }
.definition-gallery figcaption a { color: var(--muted); text-underline-offset: 2px; }
.source-link { display: inline-flex; margin-top: 10px; color: var(--coral-dark); font-weight: 700; text-underline-offset: 3px; }
.source-lines { margin: 0; padding-left: 1.15rem; color: #3d4559; }
.source-lines li + li { margin-top: 7px; }
.status-box { padding: 14px 16px; background: var(--mint); border-left: 4px solid #76a99a; border-radius: 8px; }
.status-box.warning { color: #7e352d; background: #fbecea; border-left-color: var(--coral); }
.thesaurus-box { display: grid; gap: 4px; padding: 15px 16px; color: #5e312a; background: linear-gradient(135deg, #fff7e8, #f4eae0); border: 1px solid #edc07c; border-left: 5px solid var(--coral); border-radius: 10px; }
.thesaurus-box + .thesaurus-box { margin-top: 8px; }
.thesaurus-box strong { color: var(--navy); }
.thesaurus-box span { color: #735e58; font-size: .87rem; }
.subsection { color: var(--muted); font-size: .92rem; }

dialog { width: min(660px, calc(100% - 32px)); padding: 30px; color: var(--ink); background: white; border: 0; border-radius: 20px; box-shadow: var(--shadow); }
dialog::backdrop { background: rgba(27,34,54,.58); }
dialog h2 { margin: 0 0 16px; color: var(--navy); font-family: Georgia, serif; font-size: 2rem; }
.dialog-close { position: absolute; top: 12px; right: 14px; width: 38px; height: 38px; border: 0; border-radius: 50%; color: var(--navy); background: var(--cream); font-size: 1.4rem; }

@media (max-width: 1180px) {
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .content-grid { grid-template-columns: 220px 1fr; }
  .detail-panel {
    grid-column: 1 / -1;
    position: static;
    height: auto;
    min-height: 0;
    overflow: visible;
    scrollbar-gutter: auto;
  }
  .detail-empty { min-height: 260px; }
}

@media (max-width: 760px) {
  .site-credit { justify-content: center; flex-wrap: wrap; gap: 8px 12px; padding-top: 14px; }
  .site-credit img { width: 98px; }
  .topbar { align-items: flex-start; }
  .top-actions { align-items: flex-end; flex-direction: column-reverse; gap: 7px; }
  .site-nav a { padding: 6px 9px; font-size: .78rem; }
  .ghost-button { padding: 8px 10px; font-size: .8rem; }
  .brand p { display: none; }
  .shell { padding-top: 18px; }
  .stats { grid-template-columns: 1fr; gap: 8px; }
  .stats div { padding: 11px 14px; }
  .content-grid { display: block; }
  .filters { position: static; margin-bottom: 16px; }
  .section-filters { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .section-button { display: block; padding: 7px; text-align: center; }
  .section-button span:last-child { display: none; }
  .section-button .number { margin: auto; }
  .results { min-height: 0; }
  .detail-panel { margin-top: 16px; }
  .detail-empty { min-height: 230px; }
  .definition-gallery { grid-template-columns: 1fr; }
  .definition-gallery figure:first-child:nth-last-child(3) { grid-column: auto; }
  .definition-gallery img,
  .definition-gallery figure:first-child:nth-last-child(3) img { height: auto; max-height: 300px; }
  .quick-links { display: none; }
}

/* Проверка знаний */
.quiz-page { min-height: 100vh; background: linear-gradient(180deg, #f4f7fa 0, #fff 390px); }
.quiz-shell { width: min(1040px, calc(100% - 32px)); margin: 0 auto; padding: 38px 0 70px; }
.quiz-intro { margin-bottom: 24px; }
.quiz-intro h2 { margin: 0 0 8px; color: var(--navy); font-family: Georgia, "Times New Roman", serif; font-size: clamp(2rem, 5vw, 3.7rem); line-height: 1.06; }
.quiz-intro p { max-width: 720px; margin: 0; color: var(--muted); font-size: 1.03rem; }
.quiz-card { padding: clamp(22px, 4vw, 42px); background: white; border: 1px solid var(--line); border-radius: 26px; box-shadow: var(--shadow); }
.mode-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; margin: 24px 0; }
.mode-card { position: relative; padding: 24px; text-align: left; color: var(--ink); background: #fafbfc; border: 2px solid var(--line); border-radius: 18px; }
.mode-card:hover { border-color: var(--blue-gray); }
.mode-card.selected { background: var(--mint); border-color: var(--coral); box-shadow: 0 0 0 4px rgba(222,106,91,.1); }
.mode-icon { width: 46px; height: 46px; display: grid; place-items: center; margin-bottom: 16px; color: white; background: var(--navy); border-radius: 14px 14px 14px 5px; font-size: 1.25rem; font-weight: 900; }
.mode-card.selected .mode-icon { background: var(--coral); }
.mode-card strong { display: block; margin-bottom: 6px; color: var(--navy); font-size: 1.12rem; }
.mode-card span { color: var(--muted); font-size: .92rem; }
.primary-button, .next-button { min-height: 48px; padding: 11px 22px; color: white; background: var(--coral); border: 0; border-radius: 12px; font-weight: 800; }
.primary-button:hover, .next-button:hover { background: var(--coral-dark); }
.primary-button:disabled { cursor: not-allowed; opacity: .45; }
.quiz-topline { display: flex; align-items: center; justify-content: space-between; gap: 18px; margin-bottom: 12px; color: var(--muted); font-weight: 700; }
.quiz-score { color: var(--coral-dark); }
.progress-track { width: 100%; height: 9px; overflow: hidden; background: #edf0f4; border-radius: 999px; }
.progress-fill { height: 100%; width: 0; background: var(--coral); border-radius: inherit; transition: width .25s ease; }
.question-wrap { padding: 32px 0 20px; }
.question-label { margin: 0 0 9px; color: var(--coral-dark); font-size: .76rem; font-weight: 900; letter-spacing: .09em; text-transform: uppercase; }
.question-text { margin: 0; color: var(--navy); font-family: Georgia, "Times New Roman", serif; font-size: clamp(1.45rem, 3vw, 2.15rem); line-height: 1.3; }
.answer-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.answer-button { min-height: 66px; padding: 14px 16px; text-align: left; color: var(--navy); background: #fafbfc; border: 2px solid var(--line); border-radius: 14px; font-weight: 750; }
.answer-button:hover:not(:disabled) { border-color: var(--coral); background: #fff8f7; }
.answer-button.correct { color: #245a49; background: #e5f5ee; border-color: #6fab95; }
.answer-button.incorrect { color: #8b3128; background: #fce9e6; border-color: var(--coral); }
.answer-button:disabled { cursor: default; }
.feedback { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; margin-top: 18px; padding: 18px 20px; background: var(--mint); border-radius: 14px; }
.feedback.wrong { background: var(--coralPale, #f9e9e6); }
.feedback strong { display: block; margin-bottom: 3px; color: var(--navy); }
.feedback p { margin: 0; color: var(--muted); }
.result-summary { text-align: center; }
.result-ring { width: 126px; height: 126px; display: grid; place-items: center; margin: 0 auto 20px; color: white; background: var(--navy); border: 9px solid var(--coral); border-radius: 50%; font-size: 2rem; font-weight: 900; }
.result-summary h2 { margin: 0; color: var(--navy); font-family: Georgia, serif; font-size: 2.25rem; }
.result-summary > p { margin: 8px auto 24px; color: var(--muted); }
.mistakes { margin: 22px 0; padding: 0; text-align: left; list-style: none; }
.mistakes li { padding: 13px 0; border-bottom: 1px solid var(--line); }
.mistakes strong { color: var(--navy); }
.mistakes span { display: block; color: var(--muted); font-size: .9rem; }
.result-actions { display: flex; justify-content: center; flex-wrap: wrap; gap: 10px; }
.secondary-button { min-height: 48px; padding: 11px 20px; color: var(--navy); background: white; border: 2px solid var(--blue-gray); border-radius: 12px; text-decoration: none; font-weight: 800; }

@media (max-width: 700px) {
  .mode-grid, .answer-grid { grid-template-columns: 1fr; }
  .feedback { align-items: stretch; flex-direction: column; }
  .next-button { width: 100%; }
}

@media (prefers-reduced-motion: no-preference) {
  .term-row, .section-button, .quick-links button { transition: background-color .16s ease, color .16s ease, box-shadow .16s ease; }
}
