:root {
  --ink: #183153;
  --muted: #617088;
  --paper: #f7f4ed;
  --white: #fffefb;
  --coral: #ee765f;
  --blue: #3572e8;
  --mint: #cfeee1;
  --yellow: #f6d56d;
  --line: #d8dfeb;
  --correct: #25865d;
  --wrong: #c84e47;
  --shadow: 0 18px 50px rgba(24, 49, 83, .11);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  color: var(--ink);
  background: var(--paper);
  font-family: "Avenir Next", "Noto Sans TC", "Microsoft JhengHei", system-ui, sans-serif;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: .2;
  background-image: radial-gradient(#183153 0.55px, transparent 0.55px);
  background-size: 15px 15px;
}

.topbar, main, footer { position: relative; z-index: 1; }

.topbar {
  max-width: 1120px;
  margin: auto;
  padding: 28px 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.brand { color: var(--ink); text-decoration: none; font-size: 23px; font-weight: 900; letter-spacing: -.5px; }
.brand span { color: var(--coral); }
.level-pill { background: var(--ink); color: white; border-radius: 99px; padding: 8px 15px; font-size: 13px; font-weight: 800; letter-spacing: .8px; }

main { max-width: 1120px; margin: auto; padding: 28px 24px 80px; }
.screen { min-height: 590px; }
.hidden { display: none !important; }

.hero { display: grid; grid-template-columns: 1.5fr .8fr; align-items: center; gap: 72px; }
.eyebrow { color: var(--blue); font-size: 12px; font-weight: 900; letter-spacing: 2.2px; margin: 0 0 18px; }
h1 { font-family: Georgia, "Noto Serif TC", serif; font-size: clamp(50px, 8vw, 88px); line-height: .95; letter-spacing: -4px; margin: 0; }
h1 span { font-family: inherit; color: var(--coral); font-size: .55em; letter-spacing: -1px; }
.lede { max-width: 680px; font-size: 18px; line-height: 1.75; color: var(--muted); margin: 30px 0 22px; }
.subject-picker { display: flex; gap: 10px; margin: 0 0 20px; }
.subject-choice { display: grid; grid-template-columns: 34px auto; grid-template-rows: auto auto; column-gap: 10px; align-items: center; min-width: 175px; color: var(--ink); background: rgba(255,255,255,.55); border: 1.5px solid var(--line); border-radius: 14px; padding: 11px 14px; text-align: left; transition: .15s; }
.subject-choice:hover { border-color: var(--blue); transform: translateY(-1px); }
.subject-choice > span { grid-row: 1 / 3; display: grid; place-items: center; width: 34px; height: 34px; border-radius: 9px; background: #e4e8ee; font-weight: 900; }
.subject-choice b { font-size: 14px; }
.subject-choice small { color: var(--muted); font-size: 11px; }
.subject-choice.selected { border-color: var(--blue); background: #eef3ff; box-shadow: 0 0 0 2px rgba(53,114,232,.1); }
.subject-choice.selected > span { color: white; background: var(--blue); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 32px; }
.chips span { border: 1px solid var(--line); background: rgba(255,255,255,.55); border-radius: 99px; padding: 8px 13px; font-size: 13px; font-weight: 700; }

button { border: 0; font: inherit; cursor: pointer; }
.primary { background: var(--ink); color: white; border-radius: 14px; padding: 15px 22px; font-weight: 800; box-shadow: 0 8px 0 #0d2037; transition: transform .15s, box-shadow .15s; }
.primary:hover:not(:disabled) { transform: translateY(-2px); box-shadow: 0 10px 0 #0d2037; }
.primary:active:not(:disabled) { transform: translateY(4px); box-shadow: 0 4px 0 #0d2037; }
.primary:disabled { opacity: .42; cursor: not-allowed; box-shadow: none; }
.secondary { background: transparent; color: var(--ink); border: 1px solid var(--line); border-radius: 14px; padding: 14px 20px; font-weight: 800; }

.topic-card { position: relative; background: var(--white); border: 1px solid var(--line); border-radius: 24px; padding: 32px; box-shadow: var(--shadow); transform: rotate(1.5deg); overflow: hidden; }
.topic-card::after { content: ""; position: absolute; width: 120px; height: 120px; border-radius: 50%; background: var(--yellow); right: -48px; bottom: -40px; opacity: .65; }
.card-number { color: var(--coral); font: 700 14px Georgia, serif; }
.topic-card h2 { font: 700 27px Georgia, serif; margin: 8px 0 20px; }
.topic-card ul { list-style: none; padding: 0; margin: 0; }
.topic-card li { display: flex; justify-content: space-between; align-items: baseline; border-top: 1px solid var(--line); padding: 14px 0; }
.topic-card li b { font-size: 16px; }
.topic-card li small { color: var(--muted); }

#quiz { max-width: 850px; margin: auto; padding-top: 40px; }
.quiz-header { display: flex; justify-content: space-between; align-items: end; }
.quiz-header h2 { margin: 0; font: 700 34px Georgia, serif; }
.counter { font: 700 17px Georgia, serif; color: var(--muted); }
.counter span:first-child { color: var(--coral); font-size: 32px; }
.progress-track { height: 7px; border-radius: 99px; background: #dfe4eb; margin: 24px 0 34px; overflow: hidden; }
#progress-bar { height: 100%; width: 10%; background: var(--coral); border-radius: inherit; transition: width .25s ease; }
.question-card { background: var(--white); border: 1px solid var(--line); border-radius: 24px; padding: clamp(24px, 5vw, 48px); box-shadow: var(--shadow); }
.question-tag { display: inline-block; color: var(--blue); background: #e8efff; border-radius: 8px; padding: 6px 9px; font-size: 12px; font-weight: 800; text-transform: uppercase; letter-spacing: .7px; }
.question-passage { margin: 22px 0 0; padding: 17px 20px; border-left: 4px solid var(--coral); background: #fff7ef; border-radius: 0 12px 12px 0; color: #3c4652; font: 600 17px/1.75 Georgia, "Noto Serif TC", serif; }
.question-card h3 { font: 700 clamp(25px, 4vw, 34px)/1.45 Georgia, serif; margin: 25px 0 28px; }
.options { display: grid; gap: 12px; }
.option { width: 100%; display: flex; align-items: center; gap: 15px; text-align: left; color: var(--ink); background: white; border: 1.5px solid var(--line); border-radius: 13px; padding: 14px 17px; font-weight: 700; transition: .15s; }
.option:hover { border-color: var(--blue); transform: translateX(3px); }
.option.selected { border-color: var(--blue); background: #eef3ff; box-shadow: 0 0 0 2px rgba(53,114,232,.12); }
.option-letter { display: grid; place-items: center; min-width: 30px; height: 30px; border: 1px solid var(--line); border-radius: 8px; font-size: 12px; }
.option.selected .option-letter { background: var(--blue); border-color: var(--blue); color: white; }
.quiz-actions { display: flex; justify-content: space-between; margin-top: 25px; }

#results { display: grid; grid-template-columns: .65fr 1.35fr; gap: 35px; padding-top: 30px; }
.result-summary { align-self: start; position: sticky; top: 20px; text-align: center; background: var(--ink); color: white; padding: 36px 28px; border-radius: 24px; box-shadow: var(--shadow); }
.result-summary .eyebrow { color: var(--yellow); }
.score-ring { width: 150px; height: 150px; display: grid; place-content: center; margin: 8px auto 24px; border: 10px solid var(--mint); border-radius: 50%; }
.score-ring span { font: 700 55px/1 Georgia, serif; }
.score-ring small { color: #b8c7da; }
.result-summary h2 { font: 700 30px Georgia, serif; margin-bottom: 8px; }
.result-summary p:not(.eyebrow) { color: #d5deea; line-height: 1.6; }
.result-summary .primary { margin-top: 15px; background: var(--yellow); color: var(--ink); box-shadow: 0 8px 0 #ac9140; }
.review-panel { background: var(--white); border: 1px solid var(--line); padding: 30px; border-radius: 24px; }
.review-heading { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }
.review-heading h2 { font: 700 28px Georgia, serif; margin: 0; }
#accuracy-pill { background: var(--mint); color: var(--correct); padding: 7px 11px; border-radius: 99px; font-weight: 900; font-size: 13px; }
.review-item { border-top: 1px solid var(--line); padding: 22px 0; }
.review-item h3 { margin: 0 0 10px; font-size: 16px; line-height: 1.5; }
.review-answer { font-weight: 800; margin: 7px 0; }
.review-answer.correct { color: var(--correct); }
.review-answer.wrong { color: var(--wrong); }
.review-item p { color: var(--muted); line-height: 1.6; margin-bottom: 0; }

.coming-next { margin-top: 90px; padding-top: 55px; border-top: 1px solid var(--line); }
.coming-next h2 { font: 700 37px Georgia, serif; margin: 0 0 10px; }
.coming-next > p:not(.eyebrow) { color: var(--muted); }
.subject-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 13px; margin-top: 28px; }
.subject { display: grid; grid-template-columns: 44px 1fr; gap: 2px 13px; align-items: center; padding: 17px; border: 1px solid var(--line); background: rgba(255,255,255,.55); border-radius: 16px; opacity: .64; }
.subject span { grid-row: 1 / 3; display: grid; place-items: center; width: 44px; height: 44px; border-radius: 12px; background: #e4e8ee; font-weight: 900; }
.subject small { color: var(--muted); }
.subject.active { opacity: 1; border-color: #a6d7c3; background: #eaf8f2; }
.subject.active span { background: var(--mint); color: var(--correct); }

footer { max-width: 1120px; margin: auto; padding: 25px 24px 40px; border-top: 1px solid var(--line); display: flex; justify-content: space-between; gap: 20px; color: var(--muted); font-size: 12px; }
footer a { color: var(--blue); }
.source-links { display: flex; flex-wrap: wrap; gap: 12px; justify-content: flex-end; }

@media (max-width: 760px) {
  .hero, #results { grid-template-columns: 1fr; }
  .hero { padding-top: 30px; gap: 38px; }
  h1 { letter-spacing: -2px; }
  .screen { min-height: auto; }
  .topic-card { transform: none; }
  .subject-grid { grid-template-columns: 1fr 1fr; }
  .result-summary { position: static; }
  footer { flex-direction: column; }
  .source-links { justify-content: flex-start; }
}

@media (max-width: 440px) {
  main { padding-left: 16px; padding-right: 16px; }
  .topbar { padding-left: 16px; padding-right: 16px; }
  .subject-grid { grid-template-columns: 1fr; }
  .subject-picker { flex-direction: column; }
  .subject-choice { width: 100%; }
  .quiz-actions { gap: 10px; }
  .quiz-actions button { flex: 1; padding-left: 10px; padding-right: 10px; }
}
