:root {
  color-scheme: light;
  --bg: #f5f7f8;
  --surface: #ffffff;
  --surface-2: #edf2f4;
  --ink: #17212b;
  --muted: #637281;
  --line: #d7e0e6;
  --accent: #0d6b79;
  --accent-dark: #094e59;
  --accent-soft: #dceff2;
  --good: #1f7a55;
  --good-soft: #dff2e9;
  --bad: #b4473d;
  --bad-soft: #f7e2df;
  --warn: #8a6414;
  --warn-soft: #f6edcf;
  --focus: #2563eb;
  --shadow: 0 16px 42px rgba(21, 33, 43, 0.08);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
}

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

button,
a {
  -webkit-tap-highlight-color: transparent;
}

button {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
a:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.app-shell {
  display: grid;
  grid-template-columns: 340px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-width: 0;
  padding: 18px;
  border-right: 1px solid var(--line);
  background: var(--surface);
  overflow: auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 42px;
  height: 42px;
  border-radius: 6px;
  background: var(--accent-soft);
  color: var(--accent-dark);
  font-size: 24px;
  font-weight: 800;
}

.brand h1 {
  margin: 0;
  font-size: 21px;
  line-height: 1.1;
}

.brand p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.25;
}

.mode-tabs {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
}

.mode-tab {
  min-height: 38px;
  border: 0;
  border-right: 1px solid var(--line);
  border-radius: 0;
  background: var(--surface);
  font-size: 14px;
}

.mode-tab:last-child {
  border-right: 0;
}

.mode-tab.active {
  background: var(--accent);
  color: #fff;
  font-weight: 700;
}

.control-group {
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

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

.control-group h2 {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.2;
  text-transform: uppercase;
  letter-spacing: 0;
}

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

.check-list.compact {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.check-item,
.toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 32px;
  color: var(--ink);
  font-size: 14px;
}

.check-item input,
.toggle input {
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: var(--accent);
}

.check-item span:nth-child(2) {
  min-width: 0;
  overflow-wrap: anywhere;
}

.check-item span:last-child {
  margin-left: auto;
  color: var(--muted);
  font-size: 12px;
}

.check-list.compact .check-item span:last-child {
  margin-left: 0;
}

.field {
  display: grid;
  gap: 6px;
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 13px;
}

.field input,
.field select,
.field textarea {
  min-height: 38px;
  width: 100%;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--ink);
}

.field textarea {
  min-height: 150px;
  resize: vertical;
  line-height: 1.5;
}

.text-button {
  border: 0;
  background: transparent;
  color: var(--accent);
  padding: 3px 4px;
  font-size: 13px;
}

.action-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 42px;
  gap: 10px;
  margin-top: auto;
  padding-top: 8px;
}

.primary-button {
  min-height: 42px;
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
  font-weight: 800;
}

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

.icon-button {
  min-height: 42px;
  font-size: 20px;
}

.side-links {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}

.side-links a,
.back-link {
  color: var(--accent-dark);
  font-size: 13px;
  text-decoration: none;
}

.side-links a:hover,
.back-link:hover {
  text-decoration: underline;
}

.workspace {
  min-width: 0;
  padding: 20px;
}

.topbar {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}

.topbar > div {
  min-width: 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
}

.topbar span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.2;
}

.topbar strong {
  display: block;
  min-height: 24px;
  margin-top: 3px;
  overflow-wrap: anywhere;
  font-size: 20px;
  line-height: 1.2;
}

.notice-strip {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
  padding: 10px 12px;
  border: 1px solid #eadba7;
  border-radius: 6px;
  background: var(--warn-soft);
  color: #4c390d;
  font-size: 13px;
}

.notice-strip strong {
  flex: 0 0 auto;
}

.visual-summary {
  display: grid;
  gap: 8px;
  margin-bottom: 14px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
}

.summary-row {
  display: grid;
  grid-template-columns: 120px minmax(0, 1fr) 48px;
  align-items: center;
  gap: 10px;
  min-height: 24px;
  font-size: 13px;
}

.summary-row span:first-child {
  min-width: 0;
  overflow-wrap: anywhere;
}

.summary-track {
  height: 9px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--surface-2);
}

.summary-fill {
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
}

.summary-row strong {
  color: var(--muted);
  font-size: 12px;
  text-align: right;
}

.quiz-surface {
  min-height: 460px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

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

.empty-mark {
  display: grid;
  place-items: center;
  width: 56px;
  height: 56px;
  margin-bottom: 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-2);
  color: var(--accent-dark);
  font-size: 28px;
}

.empty-state h2 {
  margin: 0;
  color: var(--ink);
  font-size: 24px;
}

.question-view {
  display: grid;
  gap: 18px;
  padding: 24px;
}

.question-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.pill-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 12px;
}

.question-id {
  color: var(--muted);
  font-size: 13px;
}

.question-text {
  margin: 0;
  max-width: 980px;
  overflow-wrap: anywhere;
  font-size: 25px;
  line-height: 1.45;
}

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

.choice-button {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  align-items: start;
  gap: 12px;
  width: 100%;
  min-height: 58px;
  padding: 13px;
  text-align: left;
}

.choice-button:hover {
  border-color: #9bb4c1;
  background: #fbfdfe;
}

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

.choice-button.correct {
  border-color: #8fceb2;
  background: var(--good-soft);
}

.choice-button.wrong {
  border-color: #dfa6a0;
  background: var(--bad-soft);
}

.choice-label {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 6px;
  background: var(--surface-2);
  color: var(--ink);
  font-weight: 800;
}

.choice-button.correct .choice-label {
  background: var(--good);
  color: #fff;
}

.choice-button.wrong .choice-label {
  background: var(--bad);
  color: #fff;
}

.choice-text {
  min-width: 0;
  overflow-wrap: anywhere;
  line-height: 1.45;
}

.explanation {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fbfcfd;
}

.explanation strong {
  display: block;
  margin-bottom: 6px;
}

.explanation p {
  margin: 0;
  overflow-wrap: anywhere;
  line-height: 1.55;
}

.question-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 10px;
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.secondary-button,
.ghost-button,
.danger-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  padding: 7px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.secondary-button {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
  font-weight: 700;
}

.ghost-button {
  background: var(--surface);
}

.danger-button {
  border-color: #dfa6a0;
  background: var(--bad-soft);
  color: #73261f;
}

.as-link {
  color: var(--ink);
  text-decoration: none;
}

.result-view,
.review-view,
.print-view {
  display: grid;
  gap: 16px;
  padding: 24px;
}

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

.metric {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fbfcfd;
}

.metric span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.metric strong {
  display: block;
  margin-top: 4px;
  font-size: 24px;
}

.review-list {
  display: grid;
  gap: 10px;
}

.review-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fbfcfd;
}

.review-item strong,
.review-item p {
  overflow-wrap: anywhere;
}

.review-item p {
  margin: 4px 0 0;
  color: var(--muted);
  line-height: 1.4;
}

.print-set {
  display: grid;
  gap: 18px;
}

.print-question {
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
  break-inside: avoid;
}

.print-question h3 {
  margin: 0 0 8px;
  font-size: 17px;
}

.print-question ol {
  margin: 8px 0 0;
  padding-left: 24px;
}

.doc-page {
  background: var(--bg);
}

.doc-shell {
  width: min(760px, calc(100% - 32px));
  margin: 32px auto;
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.doc-shell h1 {
  margin: 18px 0 12px;
  font-size: 30px;
}

.doc-shell h2 {
  margin: 24px 0 8px;
  font-size: 18px;
}

.doc-shell p {
  margin: 0 0 12px;
  line-height: 1.65;
}

.report-shell {
  display: grid;
  gap: 16px;
}

.report-panel,
.report-form {
  display: grid;
  gap: 14px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fbfcfd;
}

.report-panel h2 {
  margin-bottom: 0;
}

.report-meta {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin: 0;
}

.report-meta div {
  min-width: 0;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
}

.report-meta dt {
  color: var(--muted);
  font-size: 12px;
}

.report-meta dd {
  margin: 4px 0 0;
  overflow-wrap: anywhere;
  font-weight: 700;
}

.report-preview {
  display: grid;
  gap: 10px;
  overflow-wrap: anywhere;
  line-height: 1.55;
}

.report-question-text,
.report-answer-text {
  margin: 0;
}

.report-question-text {
  font-weight: 800;
}

.report-choice-list {
  display: grid;
  gap: 6px;
  margin: 0;
  padding-left: 22px;
}

.report-answer-text {
  color: var(--accent-dark);
}

.copy-status {
  min-height: 22px;
  margin: 0;
  color: var(--accent-dark);
  font-size: 13px;
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

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

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

@media (max-width: 620px) {
  body {
    padding-bottom: 66px;
  }

  .sidebar,
  .workspace {
    padding: 14px;
  }

  .brand h1 {
    font-size: 19px;
  }

  .mode-tabs,
  .check-list.compact,
  .topbar,
  .result-grid {
    grid-template-columns: 1fr 1fr;
  }

  .notice-strip {
    align-items: flex-start;
    flex-direction: column;
    gap: 4px;
  }

  .summary-row {
    grid-template-columns: 88px minmax(0, 1fr) 40px;
    gap: 8px;
  }

  .report-meta {
    grid-template-columns: 1fr;
  }

  .question-view,
  .result-view,
  .review-view,
  .print-view {
    padding: 16px;
  }

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

  .choice-button {
    grid-template-columns: 30px minmax(0, 1fr);
    min-height: 54px;
    padding: 11px;
  }

  .choice-label {
    width: 28px;
    height: 28px;
  }

  .question-actions,
  .review-item {
    grid-template-columns: 1fr;
  }

  .action-row {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 5;
    margin: 0;
    padding: 10px 14px;
    border-top: 1px solid var(--line);
    background: var(--surface);
    box-shadow: 0 -10px 24px rgba(21, 33, 43, 0.08);
  }

  .doc-shell {
    width: min(100% - 24px, 760px);
    margin: 16px auto;
    padding: 20px;
  }
}

@media print {
  .sidebar,
  .topbar,
  .notice-strip,
  .visual-summary,
  .question-actions,
  .side-links {
    display: none !important;
  }

  body,
  .workspace,
  .quiz-surface {
    background: #fff;
    box-shadow: none;
    border: 0;
    padding: 0;
  }

  .app-shell {
    display: block;
  }
}
