:root {
  --bg: #f3f6fb;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --text: #111827;
  --muted: #5f6b7a;
  --line: #d7dee8;
  --primary: #2563eb;
  --primary-dark: #1e40af;
  --green: #166534;
  --green-bg: #ecfdf3;
  --red: #b42318;
  --red-bg: #fff1f0;
  --orange: #a15c07;
  --orange-bg: #fff8e6;
  --shadow: 0 12px 30px rgba(31, 43, 68, 0.09);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.65;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

button,
input,
summary {
  font: inherit;
}

button {
  cursor: pointer;
}

.container {
  width: min(1080px, calc(100% - 32px));
  margin: 0 auto;
}

.site-header {
  background: #10233f;
  color: #ffffff;
  padding: 24px 0;
}

.header-content,
.section-heading,
.quiz-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}

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

h1 {
  max-width: 760px;
  margin-bottom: 0;
  font-size: 2.15rem;
  line-height: 1.2;
  font-weight: 800;
}

h2 {
  margin-bottom: 0;
  font-size: 1.4rem;
  line-height: 1.3;
}

h3 {
  margin-bottom: 10px;
  font-size: 1.08rem;
  line-height: 1.45;
}

.eyebrow {
  margin-bottom: 6px;
  color: #8cc5ff;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

.panel .eyebrow {
  color: var(--primary);
}

.main-layout {
  display: grid;
  gap: 20px;
  padding: 24px 0 42px;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 24px;
}

.hidden {
  display: none !important;
}

.upload-box {
  display: grid;
  place-items: center;
  gap: 8px;
  min-height: 180px;
  margin-top: 18px;
  border: 2px dashed #9db4d5;
  border-radius: 8px;
  background: #f8fbff;
  color: var(--muted);
  text-align: center;
  transition: border-color 0.2s ease, background 0.2s ease;
}

.upload-box:hover {
  border-color: var(--primary);
  background: #eef6ff;
}

.upload-box input {
  display: none;
}

.quick-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 14px;
}

.upload-icon {
  display: grid;
  place-items: center;
  width: 58px;
  height: 58px;
  border-radius: 8px;
  background: #dbeafe;
  color: var(--primary-dark);
  font-weight: 800;
}

.upload-title {
  color: var(--text);
  font-size: 1.08rem;
  font-weight: 700;
}

.upload-note {
  max-width: 440px;
  font-size: 0.92rem;
}

.status-pill {
  border-radius: 999px;
  background: #eef2f7;
  color: var(--muted);
  padding: 6px 12px;
  font-size: 0.9rem;
  font-weight: 700;
  white-space: nowrap;
  max-width: 100%;
  overflow-wrap: anywhere;
}

.message {
  margin-top: 16px;
  border-radius: 8px;
  padding: 12px 14px;
  font-weight: 700;
}

.message.info {
  background: #eaf4ff;
  color: #175cd3;
}

.message.warning {
  background: var(--orange-bg);
  color: var(--orange);
}

.message.error {
  background: var(--red-bg);
  color: var(--red);
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(120px, 1fr));
  gap: 12px;
  margin: 18px 0;
}

.summary-grid.compact {
  grid-template-columns: repeat(2, 92px);
  margin: 0;
}

.summary-grid div {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
  padding: 14px;
}

.summary-grid span {
  display: block;
  color: var(--primary-dark);
  font-size: 1.55rem;
  font-weight: 800;
}

.summary-grid small {
  color: var(--muted);
}

.exam-list {
  display: grid;
  gap: 12px;
  margin-top: 18px;
}

.exam-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
  padding: 16px;
}

.exam-card.is-selected {
  border-color: var(--primary);
  background: #eef6ff;
}

.exam-card h3 {
  margin-bottom: 0;
}

.exam-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

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

.question-preview-details {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
  padding: 14px;
}

.question-preview-details summary {
  cursor: pointer;
  font-weight: 800;
}

.question-list {
  display: grid;
  gap: 14px;
  margin-top: 18px;
}

.question-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  padding: 18px;
}

.question-card.correct {
  border-color: #8bd7a8;
  background: var(--green-bg);
}

.question-card.incorrect {
  border-color: #ffb0a5;
  background: var(--red-bg);
}

.question-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.tag {
  border-radius: 999px;
  background: #eef2f7;
  color: var(--muted);
  padding: 4px 10px;
  font-size: 0.86rem;
  font-weight: 700;
}

.tag.correct {
  background: var(--green-bg);
  color: var(--green);
}

.tag.incorrect {
  background: var(--red-bg);
  color: var(--red);
}

.answer-list {
  display: grid;
  gap: 8px;
  margin: 12px 0 0;
  padding: 0;
  list-style: none;
}

.answer-item,
.answer-option {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
  padding: 12px 14px;
  overflow-wrap: anywhere;
}

.answer-option {
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

.answer-option input {
  flex: 0 0 auto;
  width: 20px;
  height: 20px;
  margin-top: 4px;
  accent-color: var(--primary);
}

.answer-item.is-correct,
.answer-option.is-correct {
  border-color: #86d69c;
  background: var(--green-bg);
  color: var(--green);
  font-weight: 700;
}

.answer-item.is-selected-wrong,
.answer-option.is-selected-wrong {
  border-color: #ffb0a5;
  background: var(--red-bg);
  color: var(--red);
  font-weight: 700;
}

.progress-panel {
  position: fixed;
  top: 92px;
  right: 18px;
  z-index: 30;
  width: min(240px, calc(100vw - 28px));
  max-height: calc(100vh - 120px);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
  box-shadow: var(--shadow);
  padding: 12px;
  overflow: auto;
}

.progress-heading {
  display: grid;
  gap: 8px;
  margin-bottom: 10px;
}

.progress-heading h3 {
  margin-bottom: 0;
  font-size: 1rem;
}

.progress-counts {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.progress-counts span {
  border-radius: 999px;
  background: #ffffff;
  border: 1px solid var(--line);
  color: var(--muted);
  padding: 4px 8px;
  font-size: 0.78rem;
  font-weight: 700;
  white-space: nowrap;
}

.progress-counts strong {
  color: var(--primary-dark);
}

.progress-number-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(34px, 1fr));
  gap: 7px;
}

.progress-number {
  display: grid;
  place-items: center;
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--text);
  padding: 0;
  font-size: 0.9rem;
  font-weight: 900;
}

.progress-number.is-answered {
  border-color: #86d69c;
  background: var(--green-bg);
  color: var(--green);
}

.progress-number:hover,
.progress-number:focus-visible {
  border-color: var(--primary);
  outline: 2px solid #bfdbfe;
  outline-offset: 1px;
}

.error-details {
  margin-top: 18px;
  border: 1px solid #f2c572;
  border-radius: 8px;
  background: var(--orange-bg);
  color: var(--orange);
  padding: 12px 14px;
}

.error-details summary {
  cursor: pointer;
  font-weight: 800;
}

.error-item {
  margin-top: 10px;
  border-top: 1px solid #f1d08f;
  padding-top: 10px;
}

.error-item pre {
  max-width: 100%;
  overflow-x: auto;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.option-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
  margin: 18px 0;
}

.choice-card,
.time-input {
  display: flex;
  gap: 12px;
  min-height: 104px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
  padding: 14px;
}

.choice-card input {
  width: 20px;
  height: 20px;
  margin-top: 3px;
  accent-color: var(--primary);
}

.choice-card small {
  display: block;
  color: var(--muted);
  margin-top: 4px;
}

.time-input {
  display: grid;
  align-content: start;
}

.time-input span {
  font-weight: 700;
}

.time-input input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  min-height: 48px;
  padding: 10px 12px;
}

.primary-button,
.ghost-button {
  min-height: 48px;
  border: 0;
  border-radius: 8px;
  padding: 11px 18px;
  font-weight: 800;
  line-height: 1.35;
}

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

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

.primary-button.danger {
  background: var(--red);
  margin-top: 18px;
}

.ghost-button {
  border: 1px solid var(--line);
  background: #ffffff;
  color: var(--text);
}

.danger-text {
  color: var(--red);
}

.export-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.timer {
  min-width: 150px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
  padding: 10px 14px;
  text-align: center;
}

.timer span {
  display: block;
  font-size: 1.35rem;
  font-weight: 900;
}

.timer.warning {
  border-color: #f2c572;
  background: var(--orange-bg);
  color: var(--orange);
}

.history-list {
  display: grid;
  gap: 10px;
  margin-top: 16px;
}

.history-item {
  display: grid;
  grid-template-columns: 1.4fr repeat(4, minmax(90px, 1fr));
  gap: 10px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
  padding: 12px;
}

.history-item strong,
.history-item span {
  overflow-wrap: anywhere;
}

.empty-state {
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  padding: 18px;
  text-align: center;
}

@media (max-width: 820px) {
  body {
    background: #ffffff;
  }

  .site-header {
    padding: 18px 0;
  }

  .header-content,
  .section-heading,
  .quiz-topbar {
    align-items: flex-start;
    flex-direction: column;
    gap: 12px;
  }

  .summary-grid,
  .option-grid {
    grid-template-columns: 1fr;
  }

  .exam-card {
    align-items: stretch;
    flex-direction: column;
  }

  .exam-actions {
    justify-content: flex-start;
  }

  .summary-grid.compact {
    grid-template-columns: repeat(2, 1fr);
    width: 100%;
  }

  .timer {
    width: 100%;
  }

  #quizSection {
    padding-bottom: 180px;
  }

  .progress-counts {
    justify-content: flex-start;
  }

  .progress-panel {
    top: auto;
    right: 10px;
    bottom: 10px;
    width: min(260px, calc(100vw - 20px));
    max-height: 34vh;
    padding: 10px;
  }

  .history-item {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 520px) {
  .container {
    width: 100%;
    padding-inline: 12px;
  }

  .main-layout {
    gap: 12px;
    padding: 12px 0 24px;
  }

  .site-header .container {
    padding-inline: 14px;
  }

  .panel {
    border-left: 0;
    border-right: 0;
    border-radius: 0;
    box-shadow: none;
    padding: 16px 14px;
  }

  #quizSection {
    padding-bottom: 160px;
  }

  h1 {
    font-size: 1.55rem;
    line-height: 1.25;
  }

  h2 {
    font-size: 1.22rem;
  }

  h3 {
    font-size: 1rem;
  }

  .upload-box {
    min-height: 150px;
    padding: 18px 12px;
  }

  .upload-icon {
    width: 50px;
    height: 50px;
  }

  .status-pill {
    white-space: normal;
  }

  .summary-grid {
    gap: 8px;
  }

  .summary-grid div {
    padding: 12px;
  }

  .summary-grid span {
    font-size: 1.35rem;
  }

  .question-list {
    gap: 10px;
    margin-top: 12px;
  }

  .question-card,
  .question-preview-details {
    padding: 14px;
  }

  .answer-list {
    gap: 10px;
  }

  .answer-option {
    min-height: 52px;
  }

  .progress-panel {
    width: min(228px, calc(100vw - 20px));
    max-height: 30vh;
    padding: 10px;
  }

  .progress-heading {
    gap: 8px;
    margin-bottom: 10px;
  }

  .progress-heading h3 {
    font-size: 1rem;
  }

  .progress-heading .muted-text {
    display: none;
  }

  .progress-counts span {
    padding: 4px 7px;
    font-size: 0.75rem;
  }

  .progress-number-grid {
    grid-template-columns: repeat(auto-fill, minmax(30px, 1fr));
    gap: 6px;
  }

  .progress-number {
    min-height: 30px;
    font-size: 0.82rem;
  }

  .choice-card,
  .time-input {
    min-height: auto;
    padding: 14px;
  }

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

  .export-actions,
  .primary-button,
  .ghost-button {
    width: 100%;
  }

  .export-actions button {
    width: 100%;
  }
}
