:root {
  --page: #f1f2f6;
  --card: #ffffff;
  --option: #fbfcff;
  --option-strong: #f6f8fc;
  --text: #202734;
  --muted: #8c91a0;
  --line: #e5e7ee;
  --primary: #5b5cff;
  --primary-soft: #e9ecff;
  --right: #26a269;
  --right-soft: #e8f7ef;
  --wrong: #d14343;
  --wrong-soft: #fff0f0;
  --shadow: 0 18px 34px rgba(32, 39, 52, 0.16);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  color: var(--text);
  font-family: "Trebuchet MS", "Microsoft YaHei", sans-serif;
  background: var(--page);
}

button {
  min-height: 46px;
  border: 0;
  border-radius: 14px;
  color: #fff;
  background: var(--primary);
  font: 800 1rem/1 "Trebuchet MS", "Microsoft YaHei", sans-serif;
  cursor: pointer;
}

button:disabled {
  opacity: 0.45;
}

.app-shell {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding:
    max(28px, calc(env(safe-area-inset-top, 0px) + 18px))
    max(12px, calc(env(safe-area-inset-right, 0px) + 12px))
    max(8px, calc(env(safe-area-inset-bottom, 0px) + 6px))
    max(12px, calc(env(safe-area-inset-left, 0px) + 12px));
}

.quiz-panel {
  width: min(560px, 100%);
  height: calc(100dvh - max(36px, calc(env(safe-area-inset-top, 0px) + env(safe-area-inset-bottom, 0px) + 24px)));
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.topbar {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 4px 2px 10px;
  color: var(--muted);
  font-weight: 900;
  letter-spacing: 0;
}

.topbar h1 {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

#progressText,
#scoreText {
  font-size: clamp(0.95rem, 4vw, 1.15rem);
}

#scoreText {
  justify-self: end;
}

.meter {
  position: relative;
  height: 10px;
  margin: 0 0 28px;
  border-radius: 999px;
  background: #e3e5ec;
}

.meter span {
  display: block;
  height: 100%;
  width: 0;
  border-radius: inherit;
  background: var(--primary);
  transition: width 220ms ease;
}

#questionSlider {
  position: absolute;
  inset: -14px -2px;
  width: calc(100% + 4px);
  margin: 0;
  opacity: 0;
  cursor: pointer;
}

.question-card {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: clamp(18px, 5vw, 34px);
  border: 1px solid rgba(217, 220, 230, 0.88);
  border-radius: 30px;
  background: var(--card);
  box-shadow: var(--shadow);
}

.question-stem {
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr);
  gap: 14px;
  align-items: center;
}

#questionNumber {
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  color: var(--primary);
  background: var(--primary-soft);
  font-size: 1.15rem;
  font-weight: 900;
}

h2 {
  max-height: 26dvh;
  margin: 0;
  overflow: auto;
  color: #17202e;
  font-size: clamp(1.08rem, 4.2vw, 1.5rem);
  line-height: 1.48;
  font-weight: 900;
  letter-spacing: 0;
}

.choices {
  flex: 1;
  min-height: 0;
  display: grid;
  align-content: start;
  gap: 12px;
  overflow: auto;
  padding: 1px 1px 3px;
}

.choice {
  min-height: 68px;
  display: grid;
  grid-template-columns: 54px minmax(0, 1fr);
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--option);
  box-shadow: 0 1px 2px rgba(32, 39, 52, 0.04);
  overflow: hidden;
  cursor: pointer;
  transition: transform 150ms ease, border-color 150ms ease, background 150ms ease;
}

.choice:active {
  transform: scale(0.992);
}

.choice input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.choice-number {
  justify-self: center;
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  color: #68717e;
  background: var(--option-strong);
  font-weight: 900;
  font-size: 1rem;
}

.choice-text {
  padding: 12px 16px 12px 0;
  color: #2d3644;
  font-size: clamp(0.96rem, 3.6vw, 1.18rem);
  line-height: 1.48;
  font-weight: 800;
}

.choice:has(input:checked) {
  border-color: var(--primary);
  background: #f7f8ff;
}

.choice.correct {
  border-color: rgba(38, 162, 105, 0.35);
  background: var(--right-soft);
}

.choice.correct .choice-number {
  color: #fff;
  background: var(--right);
}

.choice.wrong {
  border-color: rgba(209, 67, 67, 0.35);
  background: var(--wrong-soft);
}

.choice.wrong .choice-number {
  color: #fff;
  background: var(--wrong);
}

.choice.locked {
  cursor: default;
}

.feedback,
#submitBtn,
#nextBtn {
  display: none;
}

.actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 10px;
}

.actions button {
  min-width: 0;
  min-height: 42px;
  padding: 0 16px;
  border-radius: 16px;
}

#restartBtn,
#recordsBtn {
  display: block;
}

#restartBtn {
  color: #5d6573;
  background: #e9ebf2;
}

#installBtn {
  display: none;
}

.result-dialog {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding:
    max(24px, calc(env(safe-area-inset-top, 0px) + 18px))
    max(18px, calc(env(safe-area-inset-right, 0px) + 18px))
    max(18px, calc(env(safe-area-inset-bottom, 0px) + 18px))
    max(18px, calc(env(safe-area-inset-left, 0px) + 18px));
  background: rgba(28, 31, 39, 0.36);
}

.result-dialog[hidden] {
  display: none;
}

.result-box {
  width: min(380px, 100%);
  border-radius: 26px;
  background: #fff;
  box-shadow: 0 24px 64px rgba(28, 31, 39, 0.24);
  padding: 22px;
  text-align: center;
}

.result-mark {
  width: 52px;
  height: 52px;
  display: inline-grid;
  place-items: center;
  border-radius: 999px;
  color: white;
  font-size: 1.8rem;
  font-weight: 900;
}

.result-dialog.right .result-mark {
  background: var(--right);
}

.result-dialog.wrong .result-mark {
  background: var(--wrong);
}

.result-box h2 {
  max-height: none;
  margin-top: 12px;
  overflow: visible;
  font-size: 1.55rem;
  line-height: 1.18;
}

.result-box p {
  max-height: 32dvh;
  overflow: auto;
  margin: 12px 0 18px;
  color: #3b4350;
  font-size: 1rem;
  line-height: 1.55;
  font-weight: 700;
}

.result-box button {
  width: 100%;
}

.records-dialog {
  position: fixed;
  inset: 0;
  z-index: 22;
  display: grid;
  place-items: end center;
  padding:
    max(24px, calc(env(safe-area-inset-top, 0px) + 18px))
    max(14px, calc(env(safe-area-inset-right, 0px) + 14px))
    max(14px, calc(env(safe-area-inset-bottom, 0px) + 10px))
    max(14px, calc(env(safe-area-inset-left, 0px) + 14px));
  background: rgba(28, 31, 39, 0.34);
}

.records-dialog[hidden] {
  display: none;
}

.records-box {
  width: min(560px, 100%);
  max-height: min(76dvh, 680px);
  display: flex;
  flex-direction: column;
  border-radius: 28px;
  background: #fff;
  box-shadow: 0 24px 64px rgba(28, 31, 39, 0.26);
  padding: 18px;
}

.records-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
}

.records-head h2 {
  max-height: none;
  overflow: visible;
  margin: 0;
  font-size: 1.3rem;
  line-height: 1.2;
}

.records-head p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 800;
}

.icon-button {
  width: 38px;
  min-height: 38px;
  padding: 0;
  border-radius: 999px;
  color: #68717e;
  background: #f0f2f7;
  font-size: 1.5rem;
}

.records-legend {
  display: flex;
  gap: 14px;
  margin: 14px 0 12px;
  color: #626b78;
  font-size: 0.85rem;
  font-weight: 800;
}

.records-legend span {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.dot {
  width: 9px;
  height: 9px;
  border-radius: 999px;
  background: #d9dde6;
}

.dot.right {
  background: var(--right);
}

.dot.wrong {
  background: var(--wrong);
}

.records-grid {
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(42px, 1fr));
  gap: 8px;
  overflow: auto;
  padding: 2px 1px 4px;
}

.record-item {
  min-height: 38px;
  padding: 0;
  border-radius: 12px;
  color: #68717e;
  background: #f2f4f8;
  font-size: 0.92rem;
}

.record-item.right {
  color: #fff;
  background: var(--right);
}

.record-item.wrong {
  color: #fff;
  background: var(--wrong);
}

.record-item.current {
  outline: 3px solid var(--primary-soft);
  box-shadow: 0 0 0 1px var(--primary);
}

@media (max-width: 430px) {
  .app-shell {
    padding:
      max(34px, calc(env(safe-area-inset-top, 0px) + 18px))
      max(10px, calc(env(safe-area-inset-right, 0px) + 10px))
      max(6px, calc(env(safe-area-inset-bottom, 0px) + 4px))
      max(10px, calc(env(safe-area-inset-left, 0px) + 10px));
  }

  .quiz-panel {
    height: calc(100dvh - max(38px, calc(env(safe-area-inset-top, 0px) + env(safe-area-inset-bottom, 0px) + 22px)));
  }

  .meter {
    margin-bottom: 26px;
  }

  .question-card {
    gap: 14px;
    padding: 18px 18px 18px;
    border-radius: 28px;
  }

  .question-stem {
    grid-template-columns: 42px minmax(0, 1fr);
    gap: 12px;
  }

  #questionNumber {
    width: 40px;
    height: 40px;
    font-size: 1rem;
  }

  h2 {
    max-height: 24dvh;
  }

  .choices {
    gap: 10px;
  }

  .choice {
    min-height: 62px;
    grid-template-columns: 48px minmax(0, 1fr);
    border-radius: 16px;
  }

  .choice-number {
    width: 30px;
    height: 30px;
  }

  .choice-text {
    padding: 10px 12px 10px 0;
  }

  .actions {
    margin-top: 8px;
  }

  .actions button {
    min-height: 38px;
    border-radius: 14px;
    font-size: 0.9rem;
  }

  .records-box {
    max-height: 72dvh;
    border-radius: 24px;
    padding: 16px;
  }

  .records-grid {
    grid-template-columns: repeat(auto-fill, minmax(38px, 1fr));
    gap: 7px;
  }

  .record-item {
    min-height: 35px;
    border-radius: 11px;
    font-size: 0.86rem;
  }
}
