:root {
  color-scheme: light dark;
  --bg: #f3f6f4;
  --panel: #ffffff;
  --text: #14211a;
  --muted: #66736c;
  --line: #dce5df;
  --accent: #198754;
  --accent-strong: #12653f;
  --accent-soft: #dff3e9;
  --danger: #c93232;
  --danger-soft: #fae2e2;
  --warn-soft: #fff4cf;
  --shadow: 0 10px 30px rgba(22, 45, 33, .08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.app {
  width: min(760px, 100%);
  margin: 0 auto;
  padding: 14px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 2px 14px;
}

h1 {
  margin: 0;
  font-size: 24px;
  line-height: 1.15;
}

p {
  margin: 4px 0 0;
}

.topbar p,
.status,
.label,
.meta,
.empty {
  color: var(--muted);
  font-size: 14px;
}

.icon-btn {
  width: 42px;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  font-size: 22px;
}

.tabs {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}

.tab,
.primary-btn,
.secondary-btn,
.choice,
.suggestion {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
}

.tab {
  min-height: 42px;
  font-weight: 700;
}

.tab.active,
.primary-btn {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

.panel,
.search,
.card,
.list-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.panel,
.search,
.list-card {
  padding: 12px;
  margin-bottom: 12px;
}

.stack {
  display: grid;
  gap: 10px;
}

.label {
  display: block;
  margin-bottom: 7px;
}

select,
input {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  padding: 10px 12px;
}

input:focus,
select:focus,
button:focus-visible {
  outline: 2px solid rgba(25, 135, 84, .24);
  border-color: var(--accent);
}

.status {
  min-height: 20px;
  margin-top: 8px;
}

.suggestions,
.button-list {
  display: grid;
  gap: 8px;
  margin-bottom: 12px;
}

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

.map-tile {
  min-height: 84px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  text-align: left;
  box-shadow: var(--shadow);
}

.map-tile.active {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.map-tile strong {
  display: block;
  margin-bottom: 6px;
  color: var(--accent);
}

.map-tile span {
  display: block;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.3;
}

.suggestion,
.list-row {
  width: 100%;
  display: block;
  text-align: left;
  padding: 11px 12px;
  box-shadow: var(--shadow);
}

.suggestion strong,
.list-row strong {
  display: block;
  margin-bottom: 4px;
  font-size: 14px;
  color: var(--accent);
}

.suggestion span,
.list-row span {
  display: -webkit-box;
  overflow: hidden;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  line-height: 1.32;
}

.suggestion small {
  display: block;
  margin-top: 7px;
  color: var(--muted);
  line-height: 1.32;
}

.suggestion em {
  display: block;
  margin-top: 6px;
  color: var(--muted);
  font-size: 13px;
  font-style: normal;
  line-height: 1.28;
}

.card {
  padding: 14px;
}

.card h2,
.list-card h2 {
  margin: 0 0 10px;
  font-size: 18px;
}

.question {
  margin-bottom: 14px;
  line-height: 1.35;
}

.answers,
.actions {
  display: grid;
  gap: 8px;
}

.answer,
.choice {
  padding: 10px;
  border-radius: 8px;
  border: 1px solid var(--line);
  line-height: 1.32;
}

.choice {
  width: 100%;
  text-align: left;
}

.choice.selected {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.answer.correct,
.choice.correct {
  border-color: rgba(25, 135, 84, .45);
  background: var(--accent-soft);
}

.answer.incorrect,
.choice.incorrect {
  border-color: rgba(201, 50, 50, .35);
  background: var(--danger-soft);
}

.answer.muted {
  color: var(--muted);
}

.actions {
  grid-template-columns: 1fr 1fr;
  margin-top: 14px;
}

.actions.one {
  grid-template-columns: 1fr;
}

.primary-btn,
.secondary-btn {
  min-height: 42px;
  padding: 9px 12px;
  font-weight: 700;
}

.secondary-btn {
  background: transparent;
}

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

.stat {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
}

.stat strong {
  display: block;
  font-size: 20px;
}

.result {
  margin: 12px 0 0;
  padding: 10px;
  border-radius: 8px;
  background: var(--warn-soft);
}

.result.ok {
  background: var(--accent-soft);
}

.normative {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 14px;
  line-height: 1.35;
}

.source-link {
  display: inline-grid;
  place-items: center;
  min-height: 42px;
  border: 1px solid var(--accent);
  border-radius: 8px;
  color: #fff;
  background: var(--accent);
  text-decoration: none;
  font-weight: 700;
}

.document-head {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 12px;
}

.document-source-row {
  margin-top: 10px;
}

.section-list {
  display: grid;
  gap: 12px;
  margin-top: 14px;
}

.doc-section {
  border-top: 1px solid var(--line);
  padding-top: 12px;
}

.doc-section p {
  margin: 6px 0 0;
  line-height: 1.55;
  white-space: pre-wrap;
}

.reference-document-open {
  padding-bottom: calc(94px + env(safe-area-inset-bottom, 0px));
}

.reference-doc-toolbar {
  position: fixed;
  left: max(10px, calc((100vw - 760px) / 2 + 10px));
  right: max(10px, calc((100vw - 760px) / 2 + 10px));
  bottom: calc(8px + env(safe-area-inset-bottom, 0px));
  z-index: 20;
  display: grid;
  grid-template-columns: 92px minmax(0, 1fr);
  gap: 8px;
  align-items: start;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 8px 28px rgba(22, 45, 33, .18);
  backdrop-filter: blur(10px);
}

.reference-back-btn {
  min-height: 38px;
  padding: 7px 8px;
  white-space: nowrap;
}

.reference-doc-search {
  min-width: 0;
}

.reference-search-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 38px 38px;
  gap: 6px;
}

.reference-doc-search input {
  min-height: 38px;
  padding: 7px 10px;
  border-radius: 8px;
}

.search-nav-btn {
  width: 38px;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  font-size: 18px;
  font-weight: 800;
}

.search-nav-btn:disabled {
  color: var(--muted);
  opacity: .42;
}

.reference-doc-search .status {
  min-height: 0;
  margin-top: 4px;
  overflow: hidden;
  font-size: 12px;
  line-height: 1.2;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.reference-document-html .reference-find-mark {
  border-radius: 4px;
  background: #fff2a8;
  color: inherit;
  padding: 0 2px;
}

.reference-document-html {
  margin-top: 14px;
  font-size: 16px;
  line-height: 1.58;
}

.reference-document-html p {
  margin: 0 0 13px;
}

.reference-document-html h3 {
  margin: 24px 0 12px;
  padding: 10px 12px;
  border-left: 4px solid var(--accent);
  border-radius: 8px;
  background: var(--accent-soft);
  font-size: 18px;
  line-height: 1.28;
}

.reference-document-html .doc-cover {
  margin: 4px 0 20px;
  padding: 16px;
  border: 1px solid var(--line);
  border-left: 5px solid var(--accent);
  border-radius: 8px;
  background: rgba(25, 135, 84, .07);
}

.reference-document-html .doc-meta {
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
}

.reference-document-html .doc-kind {
  margin-bottom: 8px;
  color: var(--accent-strong);
  font-size: 17px;
  font-weight: 800;
  line-height: 1.25;
}

.reference-document-html .doc-title {
  font-size: 21px;
  font-weight: 850;
  line-height: 1.22;
}

.reference-document-html .doc-adopted {
  margin-top: 12px;
  color: var(--muted);
  font-size: 14px;
}

.reference-document-html .table-wrap {
  width: 100%;
  overflow-x: auto;
  margin: 14px 0 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.reference-document-html table {
  width: 100%;
  min-width: 640px;
  border-collapse: collapse;
  font-size: 14px;
  line-height: 1.42;
}

.reference-document-html td {
  vertical-align: top;
  border: 1px solid var(--line);
  padding: 8px;
}

.reference-document-html tr:first-child td {
  background: rgba(25, 135, 84, .08);
  font-weight: 700;
}

.reference-document-html figure {
  margin: 14px 0 18px;
}

.reference-document-html img {
  display: block;
  max-width: 100%;
  height: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.fragments {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.fragment {
  border-top: 1px solid var(--line);
  padding-top: 12px;
}

.fragment p {
  margin: 6px 0 0;
  line-height: 1.5;
  white-space: pre-wrap;
}



.session-panel {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.session-panel strong,
.session-panel span {
  display: block;
}

.session-panel span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 14px;
}

.session-panel .secondary-btn {
  min-height: 38px;
  white-space: nowrap;
}.subheading {
  margin: 14px 0 8px;
  font-size: 16px;
}

.mode-grid,
.ticket-grid {
  display: grid;
  gap: 8px;
}

.mode-grid {
  grid-template-columns: 1fr;
  margin: 12px 0;
}

.ticket-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.mode-btn {
  width: 100%;
  min-height: 58px;
  text-align: left;
}

.mode-btn span,
.compact span {
  display: block;
  margin-top: 4px;
  color: inherit;
  opacity: .78;
  font-size: 13px;
  font-weight: 500;
  line-height: 1.25;
}

.compact {
  min-height: 54px;
  padding: 8px;
  line-height: 1.2;
}

.full {
  width: 100%;
  margin-top: 12px;
}

.feedback-panel {
  display: grid;
  gap: 8px;
  margin-top: 10px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.feedback-panel.hidden {
  display: none;
}

textarea {
  width: 100%;
  min-height: 86px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  padding: 10px 12px;
  font: inherit;
}

textarea:focus {
  outline: 2px solid rgba(25, 135, 84, .24);
  border-color: var(--accent);
}

.file-action {
  display: grid;
  place-items: center;
  text-align: center;
}

.file-action input {
  display: none;
}

.profile-card {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.profile-hero {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 16px;
  color: #fff;
  background: linear-gradient(135deg, var(--accent-strong), var(--accent));
}

.profile-hero h2 {
  margin: 0 0 4px;
  font-size: 20px;
  line-height: 1.12;
}

.profile-hero p {
  color: rgba(255, 255, 255, .82);
}

.profile-avatar {
  width: 54px;
  height: 54px;
  display: grid;
  place-items: center;
  border: 2px solid rgba(255, 255, 255, .7);
  border-radius: 8px;
  background: rgba(255, 255, 255, .18);
  font-size: 28px;
}

.level-chip {
  min-width: 62px;
  padding: 8px;
  border: 1px solid rgba(255, 255, 255, .26);
  border-radius: 8px;
  background: rgba(0, 0, 0, .16);
  text-align: center;
}

.level-chip span {
  display: block;
  font-size: 11px;
  opacity: .82;
}

.level-chip strong {
  display: block;
  font-size: 22px;
  line-height: 1;
}

.profile-progress {
  padding: 14px 16px 2px;
}

.profile-progress div {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 7px;
  color: var(--muted);
  font-size: 13px;
}

.profile-progress i,
.prep-progress-row i {
  display: block;
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--line);
}

.profile-progress em,
.prep-progress-row em {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
}

.badge-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  padding: 0 16px 12px;
}

.mini-badge {
  min-height: 74px;
  display: grid;
  place-items: center;
  gap: 5px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  text-align: center;
  font-size: 12px;
  font-weight: 700;
}

.mini-badge strong {
  font-size: 21px;
}

.mini-badge.locked {
  color: var(--muted);
  opacity: .72;
}

.profile-card > .empty {
  padding: 0 16px 14px;
}

.prep-progress-list {
  display: grid;
  gap: 8px;
}

.prep-progress-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px 12px;
  align-items: center;
  width: 100%;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  text-align: left;
}

.prep-progress-row small {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  line-height: 1.25;
}

.prep-progress-row i {
  grid-column: 1 / -1;
}

.hidden {
  display: none;
}

@media (max-width: 420px) {
  .actions,
  .stats,
  .reference-map,
  .document-head {
    grid-template-columns: 1fr;
  }

  .reference-doc-toolbar {
    left: 8px;
    right: 8px;
    grid-template-columns: 84px minmax(0, 1fr);
  }

  .tabs {
    grid-template-columns: 1fr;
  }
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101613;
    --panel: #17211c;
    --text: #edf5f0;
    --muted: #a7b5ad;
    --line: #2e3d35;
    --accent-soft: #183c2a;
    --danger-soft: #421e1e;
    --warn-soft: #3b3219;
    --shadow: none;
  }
}
