:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-muted: #eef2f5;
  --text: #172026;
  --muted: #65717c;
  --line: #d6dde3;
  --accent: #0f766e;
  --accent-strong: #115e59;
  --accent-soft: #dff5f1;
  --warning: #a16207;
  --warning-soft: #fef3c7;
  --danger: #b42318;
  --danger-soft: #fee4e2;
  --ok: #166534;
  --ok-soft: #dcfce7;
  font-family:
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  background: var(--bg);
  color: var(--text);
  letter-spacing: 0;
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
}

button,
select {
  border: 0;
  border-radius: 6px;
  font: inherit;
}

.app-shell {
  width: min(100%, 760px);
  min-height: 100vh;
  margin: 0 auto;
  padding: 18px 14px calc(88px + env(safe-area-inset-bottom));
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.title {
  margin: 0;
  font-size: 1.45rem;
  line-height: 1.25;
}

.subtitle,
.muted {
  color: var(--muted);
}

.subtitle {
  margin: 6px 0 0;
  font-size: 0.95rem;
}

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

.exam-item,
.question-panel,
.result-panel,
.error-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.exam-item {
  display: grid;
  gap: 8px;
  width: 100%;
  padding: 16px;
  text-align: left;
  color: var(--text);
}

.exam-item:active,
.answer-button:active,
.nav-button:active {
  transform: translateY(1px);
}

.exam-title {
  font-weight: 800;
}

.exam-meta {
  color: var(--muted);
  font-size: 0.92rem;
}

.quiz-header {
  display: grid;
  gap: 10px;
  margin-bottom: 12px;
}

.progress-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: 0.92rem;
}

.question-jump {
  display: flex;
  align-items: center;
  min-width: 0;
  gap: 8px;
  color: var(--muted);
  font-weight: 750;
}

.question-select {
  min-height: 38px;
  padding: 0 10px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  font-weight: 800;
}

.progress-track {
  overflow: hidden;
  height: 8px;
  border-radius: 999px;
  background: var(--surface-muted);
}

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

.question-panel {
  overflow: hidden;
}

.question-image {
  display: block;
  width: 100%;
  height: auto;
  background: #ffffff;
}

.answer-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin: 14px 0;
}

.answer-button {
  min-height: 52px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  font-weight: 800;
}

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

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

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

.footer-nav {
  position: sticky;
  bottom: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 0 -14px;
  padding: 10px 14px calc(10px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: rgba(246, 247, 249, 0.96);
  backdrop-filter: blur(8px);
}

.nav-button {
  min-height: 48px;
  padding: 0 12px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--line);
  font-weight: 750;
}

.topbar .nav-button {
  flex: 0 0 auto;
  min-width: 58px;
  white-space: nowrap;
}

.result-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: 14px;
}

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

.nav-button.warning {
  background: var(--warning-soft);
  color: var(--warning);
  border-color: #f5d36b;
}

.nav-button:disabled {
  color: #9aa5ae;
  background: #edf0f2;
}

.result-panel,
.error-panel {
  padding: 16px;
}

.score {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 16px 0;
}

.score-box {
  min-height: 70px;
  display: grid;
  place-content: center;
  gap: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-muted);
  text-align: center;
}

.score-box strong {
  font-size: 1.25rem;
}

.missed-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 10px 0 16px;
}

.missed-chip {
  min-width: 42px;
  min-height: 36px;
  padding: 0 10px;
  border: 1px solid var(--line);
  background: var(--surface);
}

.notice {
  margin: 12px 0;
  padding: 10px 12px;
  border-radius: 6px;
  background: var(--warning-soft);
  color: var(--warning);
}

.hidden {
  display: none;
}

@media (min-width: 640px) {
  .app-shell {
    padding-top: 28px;
  }

  .title {
    font-size: 1.75rem;
  }

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