:root {
  --bg: #f4f6f5;
  --panel: #ffffff;
  --panel-soft: #f8faf9;
  --text: #17211f;
  --muted: #60706b;
  --line: #d9e1df;
  --brand: #146c66;
  --brand-dark: #0c4d49;
  --brand-soft: #dff1ef;
  --accent: #b7791f;
  --accent-soft: #fff5df;
  --danger: #a33b31;
  --danger-soft: #fff0ee;
  --ok: #277245;
  --ok-soft: #e9f7ee;
  --focus: 0 0 0 3px rgba(20, 108, 102, .22);
  --shadow: 0 10px 28px rgba(18, 33, 31, .08);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--text);
  background:
    linear-gradient(180deg, #fbfcfc 0%, var(--bg) 46%, #eef3f2 100%);
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

button,
.segment span,
.check-row span,
.meta-chips span,
.term-chips span,
.category-chip,
.order-chip,
.order-answer-chip,
.term-link {
  min-width: 0;
  overflow-wrap: anywhere;
}

button:disabled,
input:disabled,
select:disabled,
textarea:disabled {
  cursor: not-allowed;
  opacity: .62;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
summary:focus-visible,
[tabindex]:focus-visible {
  outline: none;
  box-shadow: var(--focus);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: auto minmax(320px, 1fr) auto;
  gap: 18px;
  align-items: center;
  padding: 12px 20px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, .94);
  backdrop-filter: blur(10px);
}

.brand-button {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-width: 230px;
  padding: 4px;
  color: var(--text);
  text-align: left;
  border: 0;
  border-radius: 8px;
  background: transparent;
}

.brand-mark {
  display: inline-grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 8px;
  color: #fff;
  background: var(--brand);
  font-weight: 800;
  letter-spacing: 0;
}

.brand-button strong,
.brand-button small {
  display: block;
}

.brand-button strong {
  line-height: 1.1;
}

.brand-button small,
.route-caption span,
.muted {
  color: var(--muted);
}

.topnav {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
}

.topnav button,
.primary-btn,
.soft-btn,
.danger-btn {
  min-height: 40px;
  padding: 9px 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  transition: background .15s ease, border-color .15s ease, transform .15s ease;
}

.topnav button:hover,
.soft-btn:hover,
.danger-btn:hover {
  border-color: #b9c8c5;
  transform: translateY(-1px);
}

.topnav button.is-active {
  color: #fff;
  border-color: var(--brand);
  background: var(--brand);
}

.primary-btn {
  color: #fff;
  border-color: var(--brand);
  background: var(--brand);
  font-weight: 700;
}

.primary-btn:hover {
  background: var(--brand-dark);
  transform: translateY(-1px);
}

.soft-btn {
  background: var(--panel-soft);
}

.danger-btn {
  color: var(--danger);
  border-color: #edc0ba;
  background: var(--danger-soft);
}

.route-caption {
  min-width: 190px;
  text-align: right;
}

.route-caption strong,
.route-caption span {
  display: block;
}

#app {
  width: min(1380px, calc(100% - 36px));
  margin: 22px auto 48px;
}

#app:focus {
  outline: none;
}

#app-status {
  width: min(1380px, calc(100% - 36px));
  margin: 14px auto 0;
}

.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, .98);
  box-shadow: var(--shadow);
}

.start-layout,
.game-layout {
  display: grid;
  grid-template-columns: minmax(420px, .9fr) minmax(540px, 1.1fr);
  gap: 18px;
  align-items: start;
}

.settings-panel,
.question-panel,
.list-panel,
.progress-panel,
.empty-route {
  padding: 20px;
}

.panel-head,
.screen-head,
.game-topline,
.map-toolbar,
.score-line,
.action-row,
.progress-strip,
.resume-card {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
}

.panel-head,
.screen-head,
.game-topline,
.map-toolbar,
.resume-card {
  justify-content: space-between;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 10px;
  font-size: 34px;
  line-height: 1.1;
}

h2 {
  margin-bottom: 8px;
  font-size: 24px;
  line-height: 1.18;
}

p {
  line-height: 1.55;
}

.eyebrow {
  margin-bottom: 6px;
  color: var(--brand-dark);
  font-size: 13px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .08em;
}

.storage-pill {
  padding: 6px 9px;
  border: 1px solid #c8d9d6;
  border-radius: 8px;
  color: var(--brand-dark);
  background: var(--brand-soft);
  font-size: 13px;
  font-weight: 700;
}

fieldset {
  margin: 16px 0 0;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

legend {
  padding: 0 6px;
  color: var(--muted);
  font-weight: 700;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.segment input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.segment span {
  display: grid;
  min-height: 42px;
  place-items: center;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  font-weight: 700;
  text-align: center;
}

.segment input:checked + span {
  color: #fff;
  border-color: var(--brand);
  background: var(--brand);
}

.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.grid-3 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(142px, 1fr));
  gap: 12px;
}

.field,
.check-row {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
}

.field input,
.field select {
  width: 100%;
  min-height: 40px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
}

.check-row {
  display: flex;
  align-items: center;
  gap: 9px;
}

.check-row input {
  width: 18px;
  height: 18px;
  accent-color: var(--brand);
}

.switch-row {
  align-self: end;
  min-height: 40px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.advanced {
  margin-top: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
}

.advanced summary {
  padding: 12px 14px;
  font-weight: 800;
  cursor: pointer;
}

.type-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 9px;
  padding: 0 14px 14px;
}

.notice {
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  color: var(--text);
}

.notice-info {
  border-color: #bfd9e4;
  background: #eef8fb;
}

.notice-warn {
  border-color: #e8cd92;
  background: var(--accent-soft);
  color: #6c4a10;
}

.notice-ok {
  border-color: #b6dbbf;
  background: var(--ok-soft);
  color: var(--ok);
}

.map-preview-panel,
.game-map-panel {
  padding: 16px;
}

.score-line {
  color: var(--muted);
  font-size: 14px;
}

.score-line strong {
  color: var(--text);
  font-size: 18px;
}

#map-container.map-container {
  height: min(62vh, 620px);
  min-height: 390px;
  overflow: hidden;
  border: 1px solid #c4d3d0;
  border-radius: 8px;
}

#map-container.map-container-game {
  height: min(68vh, 680px);
}

.question-panel {
  position: sticky;
  top: 88px;
}

.timer-shell {
  display: grid;
  grid-template-columns: 54px minmax(150px, 220px);
  gap: 8px;
  align-items: center;
}

#timer-text {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  font-weight: 800;
  text-align: right;
}

.timer-track {
  height: 9px;
  overflow: hidden;
  border-radius: 8px;
  background: #e4ebe9;
}

#timer-bar-fill {
  width: 0;
  height: 100%;
  border-radius: 8px;
  background: var(--brand);
  transition: width .2s ease, background .2s ease;
}

#timer-bar-fill.timer-green {
  background: var(--ok);
}

#timer-bar-fill.timer-yellow {
  background: var(--accent);
}

#timer-bar-fill.timer-red {
  background: var(--danger);
}

.timer-pulse {
  color: var(--danger);
}

.progress-strip {
  margin: 18px 0;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
}

.answer-list {
  display: grid;
  gap: 10px;
  margin: 18px 0;
}

.answer-option {
  display: grid;
  grid-template-columns: 38px 1fr;
  gap: 12px;
  align-items: center;
  width: 100%;
  min-height: 52px;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  text-align: left;
}

.answer-option:hover {
  border-color: var(--brand);
  background: var(--brand-soft);
}

.answer-check {
  grid-template-columns: 22px 38px 1fr;
  cursor: pointer;
}

.answer-check input {
  width: 18px;
  height: 18px;
  accent-color: var(--brand);
}

.answer-check:has(input:checked) {
  border-color: var(--brand);
  background: var(--brand-soft);
}

.answer-letter {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border-radius: 8px;
  color: #fff;
  background: var(--brand);
  font-weight: 800;
}

.question-ru {
  margin-bottom: 8px;
}

.meta-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin: 12px 0 16px;
}

.meta-chips span {
  padding: 5px 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.answer-form {
  display: grid;
  gap: 14px;
  margin: 18px 0;
}

.answer-actions {
  margin-top: 0;
}

.matching-grid,
.tf-list,
.category-item-list {
  display: grid;
  gap: 10px;
}

.matching-row,
.category-item-row {
  display: grid;
  grid-template-columns: minmax(180px, .8fr) minmax(220px, 1fr);
  gap: 10px;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.matching-left {
  font-weight: 800;
}

.matching-row select,
.category-item-row select {
  width: 100%;
  min-height: 40px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.fill-template {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  font-size: 18px;
  line-height: 2.2;
}

.blank-input {
  width: min(130px, 100%);
  min-height: 38px;
  margin: 0 6px;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
}

.blank-field {
  margin: 10px 0;
}

.ordering-builder,
.category-zones {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.ordering-column,
.category-zone {
  min-height: 160px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
}

.ordering-column h3,
.category-zone h3 {
  margin-bottom: 10px;
  font-size: 17px;
}

.ordering-bank,
.ordering-answer,
.category-zone-items {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: flex-start;
}

.order-chip,
.order-answer-chip,
.category-chip {
  min-height: 36px;
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  font-weight: 700;
}

.order-answer-chip {
  display: inline-flex;
  gap: 7px;
  align-items: center;
  border-color: #c8d9d6;
  background: var(--brand-soft);
}

.order-answer-chip span {
  display: inline-grid;
  width: 24px;
  height: 24px;
  place-items: center;
  border-radius: 8px;
  color: #fff;
  background: var(--brand);
  font-size: 13px;
}

.category-chip {
  display: inline-flex;
  background: #fff;
}

.tf-statement {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  margin: 0;
}

.tf-statement legend {
  flex-basis: 100%;
  color: var(--text);
}

.tf-statement label {
  display: inline-flex;
  gap: 7px;
  align-items: center;
  min-height: 36px;
  padding: 6px 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  font-weight: 700;
}

textarea {
  width: 100%;
  min-height: 120px;
  padding: 10px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
}

.short-answer-review-slot:empty {
  display: none;
}

.short-answer-review,
.short-answer-feedback {
  display: grid;
  gap: 12px;
  margin-top: 4px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
}

.short-answer-review h3,
.short-answer-feedback h3,
.short-answer-review h4,
.short-answer-feedback h4 {
  margin: 0;
}

.sample-answer {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.sample-answer p,
.sample-answer ul {
  margin-bottom: 0;
}

.short-answer-columns {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.short-answer-term-grid {
  display: grid;
  gap: 8px;
  margin-top: 8px;
}

.short-answer-term-card {
  display: grid;
  gap: 4px;
  padding: 10px;
  border: 1px solid #c8d9d6;
  border-radius: 8px;
  background: #fff;
}

.short-answer-term-card span {
  color: var(--muted);
  font-size: 13px;
}

.terms-prominent {
  box-shadow: 0 0 0 3px rgba(20, 108, 102, .14);
}

.feedback-list {
  display: grid;
  grid-template-columns: minmax(120px, .35fr) minmax(0, 1fr);
  gap: 10px 14px;
  margin: 18px 0;
}

.feedback-list dt {
  color: var(--muted);
  font-weight: 800;
}

.feedback-list dd {
  margin: 0;
}

.term-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 14px 0 18px;
}

.term-chips span {
  padding: 5px 8px;
  border: 1px solid #c8d9d6;
  border-radius: 8px;
  color: var(--brand-dark);
  background: var(--brand-soft);
  font-size: 13px;
  font-weight: 700;
}

.progress-columns {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
  margin: 18px 0;
}

.weak-list {
  display: grid;
  gap: 8px;
  margin: 0;
  padding-left: 20px;
}

.compact-metrics {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin: 16px 0;
}

.list-panel,
.progress-panel,
.empty-route {
  min-height: 360px;
}

.empty-state {
  display: grid;
  min-height: 220px;
  place-items: center;
  padding: 28px;
  border: 1px dashed #bdcbc8;
  border-radius: 8px;
  background: var(--panel-soft);
  text-align: center;
}

.card-grid,
.metric-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 12px;
}

.mini-card,
.metric {
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.metric strong {
  display: block;
  color: var(--brand-dark);
  font-size: 36px;
  line-height: 1;
}

.metric span {
  display: block;
  margin-top: 8px;
  color: var(--muted);
  font-weight: 700;
}

.dictionary-controls {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) minmax(210px, .35fr) auto;
  gap: 12px;
  align-items: end;
  margin: 16px 0;
}

.dictionary-count {
  display: grid;
  min-width: 130px;
  min-height: 40px;
  align-content: center;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
}

.dictionary-count strong {
  color: var(--brand-dark);
  font-size: 22px;
  line-height: 1;
}

.dictionary-count span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.dictionary-grid {
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
}

.term-card,
.ready-answer-card {
  display: grid;
  gap: 12px;
  align-content: start;
}

.term-card h2,
.ready-answer-card h2,
.ready-answer-card h3 {
  margin-bottom: 0;
}

.ready-answer-card h3 {
  color: var(--brand-dark);
  font-size: 18px;
}

.ready-answer-text {
  padding: 11px 12px;
  border-left: 4px solid var(--brand);
  background: var(--panel-soft);
  font-weight: 700;
}

.term-article {
  margin-bottom: 0;
  color: var(--muted);
}

.term-definition-list {
  display: grid;
  grid-template-columns: 86px minmax(0, 1fr);
  gap: 8px 12px;
  margin: 0;
}

.term-definition-list dt {
  color: var(--muted);
  font-weight: 800;
}

.term-definition-list dd {
  margin: 0;
}

.term-aliases {
  margin-bottom: 0;
  color: var(--muted);
}

.term-card section,
.ready-answer-card section,
.result-section,
.progress-terms {
  display: grid;
  gap: 8px;
}

.term-card h3,
.ready-answer-card h3 {
  margin: 0;
}

.term-link-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.term-link {
  min-height: 32px;
  padding: 6px 9px;
  border: 1px solid #c8d9d6;
  border-radius: 8px;
  color: var(--brand-dark);
  background: var(--brand-soft);
  font-size: 13px;
  font-weight: 800;
}

.term-link:hover {
  border-color: var(--brand);
  background: #eef8f6;
}

.question-link-list {
  display: grid;
  gap: 6px;
  margin: 0;
  padding-left: 20px;
}

.question-link-list li {
  line-height: 1.45;
}

.result-section {
  margin-top: 14px;
}

@media (max-width: 1180px) {
  .topbar {
    grid-template-columns: 1fr;
  }

  .topnav {
    justify-content: flex-start;
  }

  .route-caption {
    text-align: left;
  }

  .start-layout,
  .game-layout {
    grid-template-columns: 1fr;
  }

  .question-panel {
    position: static;
  }
}

@media (max-width: 720px) {
  #app,
  #app-status {
    width: min(100% - 20px, 1380px);
  }

  .topbar {
    padding: 10px;
  }

  .brand-button {
    min-width: 0;
  }

  .segmented,
  .grid-2,
  .grid-3,
  .type-grid,
  .feedback-list,
    .progress-columns,
    .short-answer-columns,
    .compact-metrics,
    .dictionary-controls,
    .matching-row,
    .category-item-row,
    .ordering-builder,
    .category-zones {
    grid-template-columns: 1fr;
  }

  .panel-head,
  .screen-head,
  .game-topline,
  .map-toolbar {
    align-items: flex-start;
  }

  h1 {
    font-size: 28px;
  }

  #map-container.map-container {
    min-height: 330px;
  }
}
