@import url("https://fonts.googleapis.com/css2?family=Bangers&family=Noto+Sans+TC:wght@500;700;900&display=swap");

:root {
  --ink: #1c140c;
  --paper: #f3e2b8;
  --panel: #fffdf6;
  --red: #e31c23;
  --yellow: #ffd000;
  --cyan: #17b4e6;
  --ok: #157a3e;
  --bad: #c41515;
  --muted: #5c4a32;
  --dot: rgba(28, 20, 12, 0.16);
  --shadow: 6px 6px 0 var(--ink);
  --font-display: "Bangers", "Noto Sans TC", sans-serif;
  --font-body: "Noto Sans TC", "PingFang TC", sans-serif;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --radius-md: 14px;
  --motion-fast: 180ms;
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  min-height: 100%;
  color: var(--ink);
  font-family: var(--font-body);
  background-color: var(--paper);
  background-image:
    radial-gradient(circle, var(--dot) 1.2px, transparent 1.25px);
  background-size: 7px 7px;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}
button:not(:disabled), [role="button"]:not(:disabled) { cursor: pointer; }

.page {
  max-width: 900px;
  margin: 0 auto;
  padding: 14px 12px 48px;
  padding-left: max(12px, env(safe-area-inset-left));
  padding-right: max(12px, env(safe-area-inset-right));
}

.hero {
  display: grid;
  grid-template-columns: 88px 1fr minmax(140px, 200px);
  gap: var(--space-3);
  align-items: center;
  margin-bottom: var(--space-4);
}
.mascot {
  width: 88px;
  height: 104px;
  filter: drop-shadow(4px 4px 0 var(--ink));
}
.burst {
  position: relative;
  background: var(--yellow);
  border: 5px solid var(--ink);
  box-shadow: var(--shadow);
  padding: 12px 16px 14px;
  transform: rotate(-1.2deg);
}
.burst h1 {
  margin: 0;
  font-size: clamp(1.7rem, 6vw, 2.55rem);
  font-weight: 900;
  letter-spacing: 0.03em;
  line-height: 1.12;
  text-wrap: balance;
}
.kicker {
  margin: 0 0 2px;
  font-family: var(--font-display);
  letter-spacing: 0.14em;
  font-size: 15px;
  color: var(--red);
}
.tag {
  margin: 4px 0 0;
  font-size: 13px;
  font-weight: 800;
}
.hero-side {
  background: var(--cyan);
  border: 5px solid var(--ink);
  box-shadow: var(--shadow);
  padding: 10px 12px;
  font-size: 13px;
  font-weight: 700;
  line-height: 1.45;
  transform: rotate(1.6deg);
}

.controls {
  background: var(--panel);
  border: 5px solid var(--ink);
  box-shadow: var(--shadow);
  padding: 14px;
  display: grid;
  grid-template-columns: 1.5fr 1fr 0.7fr auto;
  gap: 10px;
  align-items: end;
  margin-bottom: var(--space-4);
}
label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12px;
  font-weight: 800;
  color: var(--muted);
}
select, input, button {
  font-family: inherit;
  font-size: 16px;
  border: 3px solid var(--ink);
  background: #fff;
  color: var(--ink);
  min-height: 48px;
  padding: 8px 10px;
}
.primary {
  background: var(--red);
  color: #fff;
  font-weight: 900;
  box-shadow: 4px 4px 0 var(--ink);
  padding: 8px 18px;
  letter-spacing: 0.06em;
  transition: transform var(--motion-fast) var(--ease-out), box-shadow var(--motion-fast) var(--ease-out);
}
.primary:hover { transform: translate(-1px, -1px); }
.primary:active { transform: translate(3px, 3px); box-shadow: none; }
.ghost {
  background: var(--yellow);
  font-weight: 800;
}
.check-btn {
  background: var(--cyan);
  font-weight: 900;
}

.meta {
  display: inline-block;
  background: var(--ink);
  color: var(--yellow);
  font-weight: 800;
  font-size: 13px;
  padding: 6px 12px;
  margin: 0 0 14px;
}

.sheet { display: grid; gap: 20px; }

.q {
  background: var(--panel);
  border: 5px solid var(--ink);
  box-shadow: var(--shadow);
  padding: 12px 12px 16px;
  display: grid;
  gap: 10px;
}
.q-head {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
}
.pow {
  background: var(--yellow);
  border: 3px solid var(--ink);
  font-family: var(--font-display);
  font-size: 22px;
  letter-spacing: 0.05em;
  padding: 2px 12px 4px;
  transform: rotate(-3deg);
  box-shadow: 3px 3px 0 var(--ink);
}
.badge {
  background: #fff;
  border: 3px solid var(--ink);
  font-size: 12px;
  font-weight: 800;
  padding: 4px 8px;
  max-width: 64%;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.comic-fig {
  margin: 0;
  overflow: hidden;
  background:
    radial-gradient(circle, rgba(28,20,12,.11) 1px, transparent 1.15px),
    #fff;
  background-size: 5px 5px;
  border: 4px solid var(--ink);
  padding: 4px 4px 0;
}
.comic-fig svg {
  width: 100%;
  height: auto;
  display: block;
}
.comic-fig figcaption {
  margin: 0;
  padding: 7px 8px;
  background: var(--yellow);
  border-top: 3px solid var(--ink);
  font-size: 13px;
  font-weight: 800;
  text-align: center;
  line-height: 1.4;
}
.hint {
  margin: 0;
  padding: 8px 10px;
  background: #fff;
  border: 3px dashed var(--ink);
  font-size: 13px;
  font-weight: 800;
  line-height: 1.4;
}
.comic-fig .hint {
  border: 0;
  border-top: 3px dashed var(--ink);
}

.bubble {
  position: relative;
  background: #fff;
  border: 3px solid var(--ink);
  border-radius: 22px 22px 22px 8px;
  padding: 12px 14px 14px;
  font-size: 17px;
  line-height: 1.65;
  font-weight: 700;
  text-wrap: pretty;
}
.bubble:after {
  content: "";
  position: absolute;
  left: 22px;
  bottom: -11px;
  width: 18px;
  height: 12px;
  background: #fff;
  border-left: 3px solid var(--ink);
  border-bottom: 3px solid var(--ink);
  transform: skewX(-32deg);
}

.answer-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-top: 4px;
}
.answer-row input {
  flex: 1 1 160px;
  min-width: 140px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}
.unit-chip {
  background: var(--ink);
  color: var(--yellow);
  font-size: 12px;
  font-weight: 800;
  padding: 6px 8px;
  min-height: 0;
}
.msg { font-weight: 900; min-height: 1.2em; }
.msg.ok, .msg.bad {
  color: #fff;
  padding: 6px 10px;
  border: 3px solid var(--ink);
}
.msg.ok { background: var(--ok); }
.msg.bad { background: var(--bad); }

.explain {
  border: 3px dashed var(--ink);
  background: #fff6d6;
  padding: 12px;
  font-size: 15px;
  line-height: 1.7;
}
.explain h3 {
  margin: 10px 0 4px;
  font-size: 14px;
  color: var(--red);
}
.explain h3:first-child { margin-top: 0; }
.vert {
  font-family: ui-monospace, "Courier New", monospace;
  background: #fff;
  border: 3px solid var(--ink);
  padding: 10px 12px;
  white-space: pre;
  overflow-x: auto;
}

.foot {
  margin-top: 28px;
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  text-align: center;
}

@media (max-width: 720px) {
  .hero { grid-template-columns: 72px 1fr; }
  .mascot { width: 72px; height: 86px; }
  .hero-side { grid-column: 1 / -1; transform: none; }
  .burst, .pow { transform: none; }
  .controls { grid-template-columns: 1fr 1fr; }
  .primary { grid-column: 1 / -1; }
  .bubble { font-size: 16px; }
  .page { overflow-x: hidden; }
}

@media (prefers-reduced-motion: reduce) {
  .primary, .primary:hover, .primary:active { transform: none; transition: none; }
}

@media print {
  body { background: #fff; }
  .controls, .foot, .answer-row button, .hero-side, .mascot { display: none !important; }
  .q { box-shadow: none; break-inside: avoid; }
  .explain { display: block !important; }
}
