:root {
  color-scheme: light;
  --bg: #f4f6f2;
  --ink: #16201c;
  --muted: #64716b;
  --soft: #f8faf7;
  --surface: #ffffff;
  --line: #dbe3dc;
  --line-strong: #b9c7be;
  --primary: #0f6b5d;
  --primary-strong: #09483f;
  --primary-soft: #e4f3ef;
  --gold: #a76516;
  --gold-soft: #fff4df;
  --blue: #285f92;
  --blue-soft: #e8f1fb;
  --danger: #b42318;
  --danger-soft: #fff1f0;
  --ok: #247345;
  --ok-soft: #edf8f0;
  --shadow: 0 18px 42px rgba(32, 45, 38, 0.1);
  --shadow-soft: 0 8px 24px rgba(32, 45, 38, 0.08);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(180deg, rgba(15, 107, 93, 0.08), transparent 280px),
    repeating-linear-gradient(90deg, rgba(22, 32, 28, 0.025) 0 1px, transparent 1px 74px),
    var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input {
  font: inherit;
}

button {
  border: 0;
}

h1,
h2,
p {
  margin: 0;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  align-items: center;
  padding: 18px clamp(16px, 4vw, 48px);
  border-bottom: 1px solid rgba(219, 227, 220, 0.92);
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(18px);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.brand-mark {
  display: grid;
  place-items: center;
  flex: 0 0 48px;
  width: 48px;
  height: 48px;
  border-radius: var(--radius);
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.18), transparent 45%),
    var(--primary);
  color: #fff;
  font-weight: 900;
  box-shadow: 0 12px 26px rgba(15, 107, 93, 0.22);
  position: relative;
  overflow: hidden;
}

.brand-mark::after {
  content: "";
  position: absolute;
  width: 34px;
  height: 3px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.5);
  bottom: 11px;
}

.brand-mark span {
  position: relative;
  z-index: 1;
}

h1 {
  font-size: clamp(21px, 2.6vw, 32px);
  line-height: 1.12;
  letter-spacing: 0;
}

.topbar p {
  color: var(--muted);
  margin-top: 5px;
}

.stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(86px, 1fr));
  gap: 10px;
}

.stats span,
.exam-meta span {
  display: grid;
  gap: 3px;
  min-width: 96px;
  padding: 11px 13px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(248, 250, 247, 0.92);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.75);
}

.stats strong {
  font-size: 23px;
  line-height: 1;
}

small {
  color: var(--muted);
  font-size: 12px;
}

.layout {
  display: grid;
  grid-template-columns: minmax(250px, 310px) minmax(0, 1fr);
  gap: 22px;
  max-width: 1460px;
  margin: 0 auto;
  padding: 22px clamp(16px, 4vw, 48px) 42px;
}

.sidebar,
.workspace {
  min-width: 0;
}

.sidebar {
  position: sticky;
  top: 104px;
  align-self: start;
}

.panel,
.toolbar,
.question-card,
.result-panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.97);
  box-shadow: var(--shadow);
}

.panel {
  padding: 15px;
  margin-bottom: 14px;
}

.panel-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.panel h2 {
  font-size: 13px;
  color: var(--muted);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

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

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 5px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--soft);
}

.category-list {
  max-height: calc(100vh - 420px);
  min-height: 120px;
  overflow: auto;
  padding-right: 2px;
}

button {
  border-radius: var(--radius);
  cursor: pointer;
  min-height: 42px;
  transition:
    background-color 0.16s ease,
    border-color 0.16s ease,
    color 0.16s ease,
    transform 0.16s ease,
    box-shadow 0.16s ease;
}

.segment,
.mode,
.category,
.option,
.secondary {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
}

.segment,
.mode,
.category {
  width: 100%;
  padding: 10px 12px;
  text-align: left;
}

.segment {
  text-align: center;
  min-height: 38px;
  font-weight: 800;
}

.mode {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-weight: 750;
}

.mode::after {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: var(--line-strong);
}

.category {
  color: #293733;
}

.segment:hover,
.mode:hover,
.category:hover,
.secondary:hover {
  border-color: var(--line-strong);
  background: var(--soft);
}

.segment.active,
.mode.active,
.category.active {
  border-color: rgba(15, 107, 93, 0.38);
  background: var(--primary-soft);
  color: var(--primary-strong);
  font-weight: 800;
}

.mode.active::after {
  background: var(--primary);
  box-shadow: 0 0 0 4px rgba(15, 107, 93, 0.12);
}

.secondary.active {
  border-color: rgba(167, 101, 22, 0.45);
  background: var(--gold-soft);
  color: var(--gold);
}

.full-width {
  width: 100%;
}

.compact-panel {
  box-shadow: var(--shadow-soft);
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 17px 18px;
  margin-bottom: 16px;
}

#modeLabel {
  display: inline-flex;
  color: var(--primary);
  font-size: 13px;
  font-weight: 850;
  margin-bottom: 5px;
}

#categoryLabel {
  display: block;
  font-size: clamp(21px, 2vw, 27px);
  line-height: 1.18;
}

.progress-track {
  width: min(360px, 52vw);
  height: 7px;
  margin-top: 12px;
  border-radius: 999px;
  background: #e8eee9;
  overflow: hidden;
}

.progress-track span {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--primary), var(--blue));
  transition: width 0.2s ease;
}

.exam-meta {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.exam-meta b {
  font-size: 18px;
  line-height: 1.1;
}

.question-card {
  min-height: 500px;
  padding: clamp(20px, 3vw, 38px);
}

.question-header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
  color: var(--muted);
  font-size: 14px;
}

.question-header span {
  min-width: 0;
}

.question-header span:first-child {
  display: inline-flex;
  align-items: center;
  border: 1px solid #cddfd8;
  border-radius: 999px;
  padding: 6px 11px;
  background: var(--primary-soft);
  color: var(--primary-strong);
  font-weight: 800;
}

.question-header span:last-child {
  font-variant-numeric: tabular-nums;
  font-weight: 800;
}

.question-text {
  max-width: 980px;
  font-size: clamp(23px, 2.3vw, 33px);
  line-height: 1.34;
  margin-bottom: 24px;
}

.question-image {
  margin: 0 0 22px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background:
    linear-gradient(135deg, rgba(40, 95, 146, 0.08), transparent 40%),
    #fbfcfd;
}

.question-image img {
  display: block;
  width: 100%;
  max-height: 360px;
  object-fit: contain;
}

.options {
  display: grid;
  gap: 12px;
}

.option {
  width: 100%;
  display: flex;
  gap: 13px;
  align-items: flex-start;
  padding: 15px;
  text-align: left;
  box-shadow: none;
  line-height: 1.55;
}

.option:hover {
  border-color: var(--primary);
  background: #fbfefd;
  transform: translateY(-1px);
}

.option.selected {
  border-color: var(--primary);
  background: var(--primary-soft);
  box-shadow: 0 10px 24px rgba(15, 107, 93, 0.12);
}

.option.correct {
  border-color: var(--ok);
  background: var(--ok-soft);
}

.option.wrong {
  border-color: var(--danger);
  background: var(--danger-soft);
}

.option-key {
  display: inline-grid;
  place-items: center;
  flex: 0 0 31px;
  width: 31px;
  height: 31px;
  border-radius: var(--radius);
  background: #edf2ee;
  color: var(--primary-strong);
  font-weight: 900;
}

.option.selected .option-key,
.option.correct .option-key {
  background: var(--primary);
  color: #fff;
}

.option.wrong .option-key {
  background: var(--danger);
  color: #fff;
}

.explanation {
  margin-top: 18px;
  padding: 15px 16px;
  border: 1px solid rgba(167, 101, 22, 0.3);
  border-left: 4px solid var(--gold);
  border-radius: var(--radius);
  background: var(--gold-soft);
  color: var(--ink);
  line-height: 1.65;
}

.actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 16px;
  flex-wrap: wrap;
}

.actions button {
  padding: 11px 18px;
  font-weight: 850;
}

#checkBtn {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 12px 26px rgba(15, 107, 93, 0.24);
}

#checkBtn:hover {
  background: var(--primary-strong);
  transform: translateY(-1px);
}

.secondary {
  padding-inline: 16px;
}

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

button:focus-visible {
  outline: 3px solid rgba(40, 95, 146, 0.24);
  outline-offset: 2px;
}

.result-panel {
  margin-top: 16px;
  padding: 18px;
  border-color: rgba(40, 95, 146, 0.28);
}

.result-panel h2 {
  margin-bottom: 8px;
}

.result-panel p {
  color: var(--muted);
  line-height: 1.6;
}

.hidden {
  display: none;
}

.is-hidden {
  display: none !important;
}

.empty-state {
  display: grid;
  place-items: center;
  min-height: 360px;
  color: var(--muted);
  text-align: center;
}

@media (max-width: 900px) {
  .topbar,
  .toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .stats,
  .exam-meta {
    justify-content: stretch;
  }

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

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

  .panel {
    margin-bottom: 0;
  }

  .panel:nth-child(3) {
    grid-column: 1 / -1;
  }

  .category-list {
    max-height: 230px;
  }

  .progress-track {
    width: 100%;
  }
}

@media (max-width: 560px) {
  body {
    background: var(--bg);
  }

  .topbar {
    padding: 14px 14px 12px;
  }

  .brand {
    align-items: flex-start;
  }

  .brand-mark {
    width: 40px;
    height: 40px;
    flex-basis: 40px;
  }

  h1 {
    font-size: 20px;
  }

  .topbar p {
    font-size: 13px;
  }

  .stats {
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
  }

  .stats span,
  .exam-meta span {
    min-width: 0;
    padding: 9px 8px;
  }

  .stats strong {
    font-size: 19px;
  }

  .layout {
    padding: 14px 12px 98px;
    gap: 14px;
  }

  .workspace {
    order: 1;
  }

  .sidebar {
    order: 2;
  }

  .toolbar,
  .question-card,
  .panel {
    box-shadow: var(--shadow-soft);
  }

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

  .panel {
    padding: 13px;
  }

  .question-card {
    min-height: 430px;
    padding: 18px;
  }

  .question-header {
    flex-direction: column;
    margin-bottom: 15px;
  }

  .question-text {
    font-size: 22px;
  }

  .option {
    padding: 13px;
  }

  .actions {
    position: sticky;
    bottom: 0;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    padding: 10px 0 calc(10px + env(safe-area-inset-bottom));
    border-top: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.94);
    backdrop-filter: blur(18px);
    z-index: 20;
    margin-top: 12px;
  }

  .actions button {
    min-height: 44px;
    padding: 10px 12px;
  }

  #checkBtn {
    grid-column: 1 / -1;
    order: -1;
  }
}
