:root {
  color-scheme: light;
  --bg: #eef2f4;
  --surface: #ffffff;
  --surface-soft: #f8fafb;
  --ink: #1f2933;
  --muted: #64717b;
  --line: #d6dee2;
  --teal: #0f766e;
  --teal-dark: #115e59;
  --amber: #b7791f;
  --blue: #2563eb;
  --green: #15803d;
  --green-soft: #e9f7ee;
  --red: #b91c1c;
  --red-soft: #fdecec;
  --shadow: 0 16px 40px rgba(24, 39, 51, 0.10);
  --brand-gap: 10px;
  --brand-logo-size: 54px;
  --brand-title-size: 1.18rem;
}

* {
  box-sizing: border-box;
}

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

body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background:
    linear-gradient(180deg, rgba(37, 99, 235, 0.05), rgba(15, 118, 110, 0.02) 280px),
    var(--bg);
}

button,
select,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  display: grid;
  flex: 1 0 auto;
  grid-template-columns: 320px minmax(0, 1fr);
}

.sidebar {
  position: sticky;
  top: 0;
  align-self: start;
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 20px;
  border-right: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.88);
  backdrop-filter: blur(14px);
}

.brand {
  display: flex;
  align-items: center;
  gap: var(--brand-gap);
  padding-bottom: 8px;
}

.brand-logo {
  display: block;
  flex: 0 0 auto;
  width: var(--brand-logo-size);
  height: var(--brand-logo-size);
  object-fit: contain;
}

.brand-title,
.brand h1,
.brand p,
.topbar h2 {
  margin: 0;
}

.brand-title,
.brand h1 {
  display: block;
  font-size: var(--brand-title-size);
  font-weight: 700;
  line-height: 1.15;
  letter-spacing: 0;
  white-space: nowrap;
}

.brand-title {
  display: inline-block;
  width: max-content;
}

.brand p {
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.95rem;
}

.control-panel,
.score-panel,
.trainer {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.control-panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 16px;
}

.control-group,
.field {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.control-label,
.field span,
.metric-label,
.eyebrow {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

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

.segmented button,
.secondary-button,
.ghost-button,
.primary-button,
.icon-button {
  min-height: 40px;
  border: 1px solid transparent;
  border-radius: 6px;
  font-weight: 800;
}

.segmented button {
  background: transparent;
  color: var(--muted);
}

.segmented button.is-active {
  border-color: rgba(15, 118, 110, 0.28);
  background: #ffffff;
  color: var(--teal-dark);
  box-shadow: 0 2px 10px rgba(15, 118, 110, 0.12);
}

.field select {
  width: 100%;
  min-height: 42px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  background: var(--surface-soft);
}

.toggle-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 40px;
  color: var(--ink);
  font-weight: 700;
}

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

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

.save-status {
  margin: -4px 0 0;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 700;
  line-height: 1.35;
}

.secondary-button,
.ghost-button {
  border-color: var(--line);
  background: var(--surface-soft);
  color: var(--ink);
}

.secondary-button:hover,
.ghost-button:hover {
  border-color: var(--teal);
}

.score-panel {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1px;
  overflow: hidden;
}

.score-panel div {
  padding: 14px;
  background: var(--surface);
}

.score-panel strong {
  display: block;
  margin-top: 4px;
  font-size: 1.45rem;
}

.workspace {
  display: flex;
  flex-direction: column;
  gap: 16px;
  width: min(1120px, 100%);
  margin: 0 auto;
  padding: 24px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.topbar h2 {
  margin-top: 4px;
  font-size: 1.8rem;
  line-height: 1.15;
}

.home-link {
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 0 16px;
  border: 1px solid rgba(15, 118, 110, 0.22);
  border-radius: 6px;
  color: #ffffff;
  background: var(--teal);
  font-weight: 850;
  line-height: 1.1;
  text-align: center;
  text-decoration: none;
  box-shadow: 0 10px 24px rgba(15, 118, 110, 0.16);
}

.home-link:hover {
  background: var(--teal-dark);
}

.mobile-home-link,
.mobile-score-panel {
  display: none;
}

.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border-color: var(--line);
  background: var(--surface);
  color: var(--ink);
  font-size: 1.6rem;
  line-height: 1;
}

.icon-button span {
  display: grid;
  width: 1em;
  height: 1em;
  place-items: center;
  line-height: 1;
}

.icon-button:disabled,
.primary-button:disabled,
.secondary-button:disabled,
.ghost-button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

.trainer {
  margin-top: 8px;
  padding: 22px;
}

.question-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 18px;
}

.question-meta span {
  padding: 6px 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  background: var(--surface-soft);
  font-size: 0.84rem;
  font-weight: 800;
}

.question-text {
  margin: 0 0 18px;
  font-size: 1.25rem;
  font-weight: 800;
  line-height: 1.45;
}

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

.option-button {
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr);
  gap: 12px;
  align-items: start;
  width: 100%;
  min-height: 56px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: var(--surface);
  text-align: left;
}

.option-button:hover {
  border-color: var(--teal);
}

.option-letter {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border-radius: 6px;
  color: var(--teal-dark);
  background: rgba(15, 118, 110, 0.10);
  font-weight: 900;
}

.option-text {
  padding-top: 5px;
  line-height: 1.42;
}

.option-button.is-selected {
  border-color: var(--blue);
  background: #eff6ff;
}

.option-button.is-correct {
  border-color: rgba(21, 128, 61, 0.55);
  background: var(--green-soft);
}

.option-button.is-wrong {
  border-color: rgba(185, 28, 28, 0.55);
  background: var(--red-soft);
}

.option-button.is-correct .option-letter {
  color: #ffffff;
  background: var(--green);
}

.option-button.is-wrong .option-letter {
  color: #ffffff;
  background: var(--red);
}

.visual-frame {
  display: none;
  margin: 18px 0 0;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.visual-frame.is-visible {
  display: flex;
  justify-content: center;
  align-items: center;
}

.visual-frame img {
  display: block;
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 360px;
  object-fit: contain;
}

.feedback {
  display: none;
  margin-top: 16px;
  padding: 12px 14px;
  border-radius: 8px;
  font-weight: 800;
  line-height: 1.4;
}

.feedback.is-visible {
  display: block;
}

.feedback.is-correct {
  color: var(--green);
  background: var(--green-soft);
}

.feedback.is-wrong {
  color: var(--red);
  background: var(--red-soft);
}

.actions {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 18px;
}

.actions-nav {
  display: flex;
  gap: 8px;
  margin-left: auto;
}

.primary-button,
.ghost-button {
  padding: 0 18px;
}

.primary-button {
  border-color: var(--teal-dark);
  color: #ffffff;
  background: var(--teal);
}

.primary-button:hover {
  background: var(--teal-dark);
}

.question-map {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(46px, 1fr));
  gap: 8px;
}

.question-dot {
  min-height: 42px;
  min-width: 46px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
  background: var(--surface);
  font-weight: 900;
}

.question-dot.is-active {
  border-color: var(--blue);
  color: var(--blue);
  box-shadow: inset 0 0 0 1px var(--blue);
}

.question-dot.is-correct {
  border-color: rgba(21, 128, 61, 0.45);
  color: var(--green);
  background: var(--green-soft);
}

.question-dot.is-wrong {
  border-color: rgba(185, 28, 28, 0.45);
  color: var(--red);
  background: var(--red-soft);
}

.map-gap {
  display: grid;
  min-height: 42px;
  place-items: center;
  color: var(--muted);
  font-weight: 900;
}

.site-footer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-areas:
    "brand links"
    "tagline credit";
  align-items: flex-end;
  column-gap: 24px;
  row-gap: 6px;
  width: min(1120px, calc(100% - 36px));
  margin: 0 auto;
  padding: 30px 0;
  border-top: 1px solid var(--line);
  color: var(--muted);
}

.site-footer strong {
  grid-area: brand;
  display: block;
  color: var(--ink);
}

.site-footer p {
  grid-area: tagline;
  margin: 0;
}

.site-footer nav {
  grid-area: links;
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 14px;
}

.site-footer a {
  color: var(--teal-dark);
  font-weight: 850;
  text-decoration: none;
}

.site-footer a:hover {
  color: var(--teal);
}

.footer-credit {
  grid-area: credit;
  justify-self: end;
  align-self: end;
  max-width: min(640px, 100%);
  margin: 0;
  padding: 0;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 400;
  line-height: 1.5;
  text-align: right;
}

.footer-credit a {
  color: var(--teal-dark);
  font-weight: inherit;
  text-decoration: none;
}

.footer-credit a:hover {
  color: var(--teal);
}

.footer-made {
  display: inline;
}

.scroll-top-button {
  position: fixed;
  right: clamp(18px, 3vw, 38px);
  bottom: 82px;
  z-index: 30;
  display: grid;
  width: 52px;
  height: 52px;
  place-items: center;
  border: 1px solid rgba(15, 118, 110, 0.18);
  border-radius: 999px;
  color: #ffffff;
  background: var(--teal);
  box-shadow: 0 16px 34px rgba(15, 76, 86, 0.24);
  opacity: 0;
  pointer-events: none;
  transform: translateY(12px);
  transition:
    opacity 180ms ease,
    transform 180ms ease,
    background 180ms ease;
}

.scroll-top-button span {
  display: grid;
  width: 22px;
  height: 22px;
  place-items: center;
  font-size: 1.35rem;
  font-weight: 900;
  line-height: 1;
}

.scroll-top-button.is-visible {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

.scroll-top-button:hover {
  background: #105f59;
}

.scroll-top-button:focus-visible {
  outline: 3px solid rgba(198, 146, 46, 0.46);
  outline-offset: 4px;
}

.is-hidden {
  display: none;
}

@media (min-width: 861px) {
  .workspace {
    gap: 12px;
    padding: 18px 24px 8px;
  }

  .trainer {
    padding: 18px 22px;
  }

  .question-meta {
    margin-bottom: 12px;
  }

  .question-text {
    margin-bottom: 12px;
  }

  .options {
    gap: 8px;
  }

  .option-button {
    min-height: 50px;
    padding: 10px;
  }

  .actions {
    margin-top: 12px;
  }

  .site-footer p {
    margin-top: 0;
  }
}

@media (max-width: 860px) {
  :root {
    --brand-gap: 8px;
    --brand-logo-size: clamp(36px, 10.5vw, 42px);
    --brand-title-size: 1.02rem;
  }

  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    min-height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .brand {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    gap: var(--brand-gap);
    align-items: center;
  }

  .brand-logo {
    width: var(--brand-logo-size);
    height: var(--brand-logo-size);
  }

  .brand-title,
  .brand h1 {
    font-size: var(--brand-title-size);
  }

  .brand p {
    font-size: 0.82rem;
  }

  .desktop-score-panel,
  .topbar-home-link {
    display: none;
  }

  .workspace {
    gap: 12px;
    padding: 18px;
  }

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

  .topbar h2 {
    font-size: 1.35rem;
  }

  .home-link {
    min-height: 38px;
    padding: 0 12px;
    font-size: 0.86rem;
  }

  .brand .mobile-home-link {
    display: inline-flex;
    max-width: 136px;
    min-height: 38px;
    padding: 0 10px;
    font-size: 0.72rem;
  }

  .mobile-score-panel {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    box-shadow: none;
  }

  .mobile-score-panel div {
    padding: 10px 12px;
  }

  .mobile-score-panel strong {
    font-size: 1.22rem;
  }

  .trainer {
    margin-top: 0;
  }

  .site-footer {
    grid-template-columns: 1fr;
    grid-template-areas:
      "brand"
      "tagline"
      "links"
      "credit";
    align-items: start;
    padding-top: 26px;
    padding-bottom: 26px;
  }

  .site-footer nav {
    justify-self: center;
    justify-content: center;
    margin-top: 8px;
    text-align: center;
  }

  .footer-credit {
    justify-self: center;
    box-sizing: border-box;
    max-width: 100%;
    padding-inline: 56px;
    text-align: center;
  }

  .footer-made {
    display: block;
    margin-top: 2px;
  }

  .scroll-top-button {
    right: 14px;
    bottom: 14px;
    width: 48px;
    height: 48px;
  }
}

@media (max-width: 520px) {
  .sidebar,
  .workspace {
    padding: 14px;
  }

  .control-panel,
  .trainer {
    padding: 14px;
  }

  .button-grid,
  .desktop-score-panel {
    grid-template-columns: 1fr;
  }

  .mobile-score-panel {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .question-text {
    font-size: 1.08rem;
  }

  .option-button {
    grid-template-columns: 34px minmax(0, 1fr);
  }
}
