/* Design: a Sunday comic strip. The header is a sky-blue panel with the red doghouse;
   each block is a panel with an ink border; feedback appears in a speech bubble.
   Lexend font, designed for easy reading (falls back to the system font offline). */
:root {
  --paper: #fbf7ee;
  --card: #ffffff;
  --ink: #1b1b1b;
  --text: #22252a;
  --muted: #5a5f66;
  --sky: #cfe8f6;
  --red: #d7263d;
  --dark-red: #8e1424;
  --yellow: #f7c600;
  --light-yellow: #fff4c2;
  --green: #2b8a3e;
  --light-green: #e3f6e7;
  --error: #c92a2a;
  --light-error: #fde8e8;
  --blue: #1c5d99;
  --night: #24305e;
  --font: "Lexend", "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  --zigzag: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='40' height='24'%3E%3Cpath d='M0 12 L10 4 L20 12 L30 4 L40 12' fill='none' stroke='%231b1b1b' stroke-width='4'/%3E%3C/svg%3E");
  color-scheme: light;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 18px;
  line-height: 1.6;
  color: var(--text);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
}
main {
  max-width: 780px;
  margin: 0 auto;
  padding-block: 20px 64px;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  display: grid;
  gap: 22px;
}
h1, h2 { line-height: 1.25; text-wrap: balance; color: var(--ink); }
h1 { margin: 0; font-size: clamp(26px, 5vw, 36px); font-weight: 700; letter-spacing: -0.01em; }
h2 { margin: 0; font-size: 22px; font-weight: 600; }
p { margin: 0; }
.muted { color: var(--muted); font-size: 16px; }

/* Stripe with the zigzag from Charlie Brown's shirt */
.stripe { height: 26px; background: var(--yellow) var(--zigzag) repeat-x center; border-bottom: 3px solid var(--ink); }

/* Panels */
.panel, .card {
  background: var(--card);
  border: 3px solid var(--ink);
  border-radius: 4px;
  box-shadow: 5px 5px 0 var(--ink);
  padding: 22px;
}
.header {
  display: flex; align-items: flex-end; gap: 20px;
  background: var(--sky);
  padding: 18px 22px 0;
  overflow: hidden;
}
.header img { width: 170px; flex-shrink: 0; display: block; margin-bottom: -3px; }
.header .header-text { padding-bottom: 20px; min-width: 0; display: grid; gap: 6px; }
.header .muted { color: #2f4a5c; }
.kicker { font-size: 13px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--dark-red); }
a.kicker { text-decoration: none; }
a.kicker:hover { text-decoration: underline; }

.stack { display: grid; gap: 22px; }
.intro { font-size: 18px; }

/* Exam list */
.subject { display: grid; gap: 14px; }
.subject h2 { font-size: 24px; }
.exam-card {
  display: grid; grid-template-columns: 110px 1fr; gap: 18px; align-items: center;
  color: inherit; text-decoration: none; transition: transform .1s, box-shadow .1s;
}
.exam-card:hover { transform: translate(-2px, -2px); box-shadow: 7px 7px 0 var(--ink); }
.exam-card:focus-visible { outline: 3px solid var(--blue); outline-offset: 3px; }
.exam-card img { width: 100%; display: block; }
.exam-card .body { display: grid; gap: 6px; min-width: 0; justify-items: start; }
.exam-card strong { font-size: 20px; line-height: 1.3; }

/* Level cards: drawing + text */
.level-card { display: grid; grid-template-columns: 150px 1fr; gap: 20px; align-items: center; }
.level-card img { width: 100%; display: block; }
.level-card .body { display: grid; gap: 8px; min-width: 0; }
.level-card.l1 .drawing { background: var(--light-yellow); }
.level-card.l2 .drawing { background: var(--sky); }
.level-card.l3 .drawing { background: var(--night); }
.drawing { border: 3px solid var(--ink); border-radius: 4px; padding: 6px; }

.tag {
  justify-self: start; display: inline-block; font-size: 13px; font-weight: 600; letter-spacing: .04em;
  background: var(--yellow); color: var(--ink); border: 2px solid var(--ink);
  padding: 1px 12px; border-radius: 99px;
}
.tag.l2 { background: var(--red); color: #fff; }
.tag.l3 { background: var(--night); color: #fff; }

/* Buttons */
a.button, button {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font: inherit; font-size: 17px; font-weight: 600; cursor: pointer; text-decoration: none;
  background: var(--red); color: #fff;
  border: 3px solid var(--ink); border-radius: 8px;
  padding: 9px 22px; box-shadow: 3px 3px 0 var(--ink);
}
a.button:hover, button:hover:not(:disabled) { filter: brightness(1.06); }
a.button:active, button:active:not(:disabled) { transform: translate(2px, 2px); box-shadow: 1px 1px 0 var(--ink); }
a.button:focus-visible, button:focus-visible, input:focus-visible { outline: 3px solid var(--blue); outline-offset: 3px; }
button:disabled { opacity: .45; cursor: default; }
.secondary { background: var(--card) !important; color: var(--ink) !important; }

label { font-weight: 600; font-size: 19px; }
input[type=text], input[type=password] {
  font: inherit; width: 100%; padding: 12px 14px; margin-top: 10px;
  border: 3px solid var(--ink); border-radius: 8px; background: #fff; color: var(--text);
}

/* Question */
.question-header { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.prompt { font-size: 22px; font-weight: 600; margin: 14px 0 6px; }
.answers { display: grid; gap: 10px; margin-top: 14px; }
.option {
  justify-content: flex-start; width: 100%; text-align: left;
  background: #fff; color: var(--text); font-weight: 400; font-size: 18px;
  padding: 10px 14px; box-shadow: 2px 2px 0 var(--ink);
}
.option .letter {
  flex-shrink: 0; width: 30px; height: 30px; border-radius: 50%;
  display: inline-grid; place-items: center;
  border: 2px solid var(--ink); background: var(--light-yellow); font-weight: 700; font-size: 15px;
}
.option.selected { background: var(--light-yellow); }
.option.selected .letter { background: var(--yellow); }
.option.right { background: var(--light-green); border-color: var(--green); }
.option.right .letter { background: var(--green); color: #fff; border-color: var(--green); }
.option.wrong { background: var(--light-error); border-color: var(--error); }
.option.wrong .letter { background: var(--error); color: #fff; border-color: var(--error); }
.option:disabled { opacity: 1; cursor: default; }

/* Speech bubble */
.feedback {
  position: relative; margin-top: 22px; padding: 14px 16px 14px 70px;
  border: 3px solid var(--ink); border-radius: 22px; background: var(--light-green);
  min-height: 70px;
}
.feedback::before {
  content: ""; position: absolute; left: 14px; top: 12px; width: 44px; height: 44px;
  background: url("img/bird.svg") center / contain no-repeat;
}
.feedback.wrong::before { filter: grayscale(1); opacity: .55; }
.feedback::after {
  content: ""; position: absolute; left: 30px; top: -13px; width: 20px; height: 20px;
  background: inherit; border-left: 3px solid var(--ink); border-top: 3px solid var(--ink);
  transform: rotate(45deg);
}
.feedback.wrong { background: var(--light-error); }
.character { display: block; font-weight: 700; color: var(--blue); }
.explanation { display: block; margin-top: 4px; }
.source { display: block; margin-top: 8px; font-size: 15px; color: var(--muted); }

/* Mistake review at the end */
.review { margin-top: 22px; padding-top: 18px; border-top: 3px dashed var(--ink); display: grid; gap: 14px; }
.review h3 { margin: 0; font-size: 20px; }
.mistake { border: 3px solid var(--ink); border-radius: 4px; padding: 14px 16px; display: grid; gap: 6px; background: #fff; }
.mistake p { margin: 0; }
.mistake-question { font-weight: 600; }
.your-answer, .right-answer { padding: 4px 10px; border-radius: 6px; }
.your-answer { background: var(--light-error); }
.right-answer { background: var(--light-green); }
.your-answer span, .right-answer span { font-weight: 600; }

.progress { height: 18px; background: #fff; border: 3px solid var(--ink); border-radius: 99px; overflow: hidden; }
.progress div { height: 100%; background: var(--yellow) var(--zigzag) repeat-x center / 20px 12px; transition: width .3s; }
.actions { display: flex; gap: 12px; justify-content: flex-end; flex-wrap: wrap; margin-top: 18px; }
.hidden { display: none !important; }
.footer { font-size: 15px; color: var(--muted); text-align: center; }
.footer a { color: var(--blue); font-weight: 600; }

.finish { display: grid; grid-template-columns: 150px 1fr; gap: 20px; align-items: center; }
.finish img { width: 100%; }
.finish .body { display: grid; gap: 8px; min-width: 0; }

table { width: 100%; border-collapse: collapse; font-size: 16px; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: 8px; border-bottom: 2px solid #ece6d6; }
th { font-weight: 600; }

@media (max-width: 560px) {
  .header { flex-direction: column; align-items: flex-start; padding-top: 16px; }
  .header img { width: 130px; order: 2; align-self: center; }
  .header .header-text { padding-bottom: 0; }
  .level-card, .finish { grid-template-columns: 1fr; }
  .level-card .drawing, .finish img { max-width: 170px; }
  .exam-card { grid-template-columns: 80px 1fr; }
  .prompt { font-size: 20px; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* Previous attempts (stored on the device) */
.best-score { font-size: 16px; font-weight: 600; color: var(--blue); }
.review-empty { font-weight: 600; }
.previous { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.previous li { display: flex; justify-content: space-between; gap: 12px; padding: 6px 12px;
  border: 2px solid var(--ink); border-radius: 6px; background: var(--light-yellow); font-variant-numeric: tabular-nums; }
.attempt { padding: 0; }
.attempt summary { display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 16px 22px; cursor: pointer; list-style-position: inside; }
.attempt summary .body { display: grid; min-width: 0; }
.attempt-score { font-weight: 700; white-space: nowrap; font-variant-numeric: tabular-nums; }
.attempt[open] summary { border-bottom: 3px dashed var(--ink); }
.attempt > .mistake, .attempt > .review-empty { margin: 14px 22px; }
