:root {
  --ink: #43302b;
  --paper: #fffdf7;
  --bg: #fff4dc;
  --sun: #fff176;
  --header: #ffb547;
  --good: #2e7d32;
  --good-bg: #e8f5e9;
  --retry: #e65100;
  --retry-bg: #fff3e0;
  --blue: #1565c0;
  --font: "PingFang HK", "PingFang TC", "Noto Sans TC", "Noto Sans HK", "Microsoft JhengHei", "微軟正黑體", "Heiti TC", "WenQuanYi Micro Hei", sans-serif;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
  line-height: 1.35;
  touch-action: manipulation;
}

button, a { font: inherit; color: inherit; }

button {
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

button:focus { outline: none; }

:focus-visible {
  outline: 4px solid #1565c0;
  outline-offset: 3px;
}

.skip {
  position: absolute;
  left: 12px;
  top: -80px;
  background: #fff;
  padding: 8px 12px;
  z-index: 30;
}

.skip:focus { top: 12px; }

.top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 16px;
  padding: 10px clamp(12px, 2vw, 28px);
  background: linear-gradient(135deg, #ffd166, #ffb547);
  border-bottom: 4px solid #e8902a;
  position: relative;
  z-index: 5;
}

.title h1 {
  margin: 0;
  font-size: clamp(1.7rem, 3.6vw, 2.7rem);
  font-weight: 900;
  letter-spacing: 0.04em;
  color: #8a2c0d;
  text-shadow: 0 2px 0 #fff3d6;
  line-height: 1.15;
}

.title p {
  margin: 2px 0 0;
  font-size: clamp(1rem, 1.8vw, 1.3rem);
  font-weight: 800;
  color: #4a2a12;
}

.controls {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}

.btn {
  min-height: 56px;
  min-width: 56px;
  padding: 0 18px;
  border: 3px solid var(--ink);
  border-radius: 999px;
  background: var(--paper);
  font-size: clamp(1.05rem, 1.7vw, 1.28rem);
  font-weight: 800;
  box-shadow: 0 4px 0 var(--ink);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  text-align: center;
  line-height: 1.15;
  white-space: nowrap;
}

.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }

.btn:disabled {
  opacity: 0.45;
  cursor: default;
  transform: none;
}

.btn-sun { background: var(--sun); }
.btn-good { background: #c8e6c9; color: #1b5e20; }
.btn-retry { background: #ffe082; }
.btn-next { background: #bbdefb; }
.btn-quiet { background: var(--paper); }

.btn[aria-pressed="true"] { background: #c8e6c9; }

.btn-xl {
  min-height: 84px;
  padding: 0 28px;
  font-size: clamp(1.5rem, 3vw, 2rem);
  background: var(--sun);
  box-shadow: 0 6px 0 var(--ink);
}

.btn-replay {
  width: 100%;
  min-height: 84px;
  font-size: clamp(1.8rem, 4vw, 2.5rem);
  background: var(--sun);
  border-width: 4px;
  box-shadow: 0 6px 0 var(--ink);
}

.btn-replay.is-playing { background: #ffe082; }

main {
  flex: 1;
  display: flex;
  flex-direction: column;
  width: min(1180px, 100%);
  margin: 0 auto;
  padding: 14px clamp(12px, 2vw, 24px) 18px;
}

.flow {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin: 6px 0 12px;
  padding: 0;
  list-style: none;
}

.flow li {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--paper);
  border: 3px solid var(--ink);
  border-radius: 999px;
  padding: 6px 14px 6px 6px;
  font-size: clamp(1.15rem, 2vw, 1.45rem);
  font-weight: 900;
  box-shadow: 0 4px 0 var(--ink);
}

.flow b {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--sun);
  border: 3px solid var(--ink);
}

.flow .arrow { font-weight: 900; background: transparent; border: 0; box-shadow: none; padding: 0; }

.home-stack {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.lead {
  font-size: clamp(1.15rem, 2vw, 1.4rem);
  font-weight: 700;
  margin: 0 0 8px;
  word-break: keep-all;
}

.preview {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  margin: 0 0 14px;
  overflow: visible;
}

.preview-row {
  display: flex;
  justify-content: center;
  align-items: flex-end;
  gap: 6px;
  width: 100%;
  overflow: visible;
}

.preview-row svg {
  width: min(22%, 130px);
  height: auto;
  display: block;
  overflow: visible;
}

.panel {
  background: var(--paper);
  border: 4px solid var(--ink);
  border-radius: 28px;
  box-shadow: 0 8px 0 var(--ink);
  padding: clamp(14px, 2vw, 22px);
}

.panel h2 {
  margin: 0 0 6px;
  font-size: clamp(1.6rem, 3vw, 2.1rem);
}

.cats {
  display: grid;
  gap: 14px;
  margin-top: 12px;
}

@media (min-width: 860px) {
  .cats { grid-template-columns: repeat(3, 1fr); }
}

.cat {
  width: 100%;
  min-height: 210px;
  border-radius: 28px;
  border-width: 4px;
  box-shadow: 0 6px 0 var(--ink);
  flex-direction: column;
  align-items: stretch;
  justify-content: flex-start;
  padding: 12px 12px 14px;
  white-space: normal;
  gap: 6px;
}

.cat-animals { background: #e8f5e9; }
.cat-instruments { background: #e3f2fd; }
.cat-mix { background: #fff9c4; }

.cat-heroes {
  display: flex;
  justify-content: center;
  align-items: flex-end;
  gap: 2px;
  min-height: 92px;
  overflow: visible;
}

.cat-heroes svg {
  width: min(32%, 108px);
  height: auto;
  display: block;
  overflow: visible;
}

.cat strong {
  font-size: clamp(1.45rem, 2.4vw, 1.8rem);
  text-align: center;
}

.cat em {
  font-style: normal;
  font-weight: 700;
  font-size: 1rem;
  text-align: center;
  line-height: 1.35;
  word-break: keep-all;
}

.feedback {
  min-height: 4.4rem;
  margin: 0 0 12px;
  padding: 10px 16px;
  border-radius: 22px;
  border: 4px solid var(--ink);
  background: var(--paper);
  box-shadow: 0 4px 0 var(--ink);
}

.feedback strong {
  display: block;
  font-size: clamp(1.45rem, 3vw, 2rem);
}

.feedback p {
  margin: 2px 0 0;
  font-size: clamp(1.05rem, 1.8vw, 1.25rem);
  font-weight: 700;
}

.feedback.is-correct { background: var(--good-bg); color: var(--good); }
.feedback.is-retry { background: var(--retry-bg); }
.feedback.is-reveal { background: #e3f2fd; }

.choices {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin: 12px 0;
  overflow: visible;
}

.choice {
  background: var(--paper);
  border: 4px solid var(--ink);
  border-radius: 24px;
  box-shadow: 0 5px 0 var(--ink);
  padding: 8px 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  overflow: visible;
  min-width: 0;
}

.choice.is-wrong { background: var(--retry-bg); }
.choice.is-correct,
.choice.is-answer { background: var(--good-bg); }

.choice-hit {
  border: 0;
  background: transparent;
  box-shadow: none;
  padding: 0;
  width: 100%;
  min-height: 0;
  overflow: visible;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.choice-hit:active { transform: none; box-shadow: none; }

.stage {
  width: 100%;
  border-radius: 16px;
  padding: 4px 6px 0;
  overflow: visible;
  display: grid;
  place-items: center;
}

.stage-animals { background: linear-gradient(#d9f2c4, #fffdf7 70%); }
.stage-instruments { background: linear-gradient(#ffe8a3, #fffdf7 70%); }

.choice-art {
  width: min(100%, 210px);
  overflow: visible;
  line-height: 0;
}

.choice-art svg {
  width: 100%;
  height: auto;
  display: block;
  overflow: visible;
}

.choice-name {
  font-size: clamp(1.7rem, 3.2vw, 2.3rem);
  font-weight: 900;
  line-height: 1.1;
}

.choice-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 52px;
  flex-wrap: wrap;
}

.badge {
  font-size: 1.05rem;
  font-weight: 900;
  padding: 4px 10px;
  border-radius: 999px;
  border: 3px solid var(--ink);
  background: #fff;
}

.speak-btn {
  min-width: 76px;
  min-height: 48px;
  border-radius: 999px;
  border: 3px solid var(--ink);
  background: #fff;
  font-weight: 800;
  font-size: 1.05rem;
  padding: 4px 12px;
  box-shadow: 0 3px 0 var(--ink);
}

.speak-btn.is-speaking { background: #bbdefb; }

.hint {
  margin: 8px 0 0;
  font-size: 1.05rem;
  font-weight: 800;
}

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

.teacher .btn { width: 100%; }

.speak-status {
  min-height: 1.3rem;
  margin: 0;
  padding: 0 16px 8px;
  text-align: center;
  font-size: 1rem;
  font-weight: 700;
}

.foot {
  padding: 8px 16px;
  text-align: center;
  background: #3e2c25;
  color: #fff8e7;
  font-size: clamp(0.95rem, 1.5vw, 1.12rem);
  font-weight: 700;
  line-height: 1.45;
}

.done { text-align: center; }

.done h2 {
  font-size: clamp(2rem, 5vw, 2.8rem);
  margin: 0 0 8px;
}

.done-score {
  font-size: clamp(2.6rem, 7vw, 4.2rem);
  font-weight: 900;
  margin: 8px 0;
}

.stars {
  font-size: clamp(1.8rem, 4vw, 2.6rem);
  letter-spacing: 0.08em;
  color: #f4a300;
}

.done-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: center;
  margin-top: 16px;
}

.score-pill {
  background: var(--paper);
  min-width: 5.2rem;
}

details.help { margin-top: 10px; font-size: 1rem; font-weight: 700; }

details.help summary {
  cursor: pointer;
  min-height: 44px;
  display: flex;
  align-items: center;
}

#confetti {
  pointer-events: none;
  position: fixed;
  inset: 0;
  overflow: hidden;
  z-index: 20;
}

#confetti i {
  position: absolute;
  top: -12px;
  width: 12px;
  height: 18px;
  border-radius: 3px;
  animation: fall 1.15s ease-in forwards;
}

@keyframes fall {
  to { transform: translateY(100vh) rotate(240deg); opacity: 0.85; }
}

@media (orientation: landscape) and (min-width: 900px) {
  .choices { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .teacher { grid-template-columns: repeat(4, 1fr); }
}

@media (orientation: portrait) {
  .title p { max-width: 16rem; }
  .choice-name { font-size: clamp(1.8rem, 6vw, 2.4rem); }
}

@media (max-height: 760px) and (orientation: landscape) {
  .title p { display: none; }
  .top { padding-top: 6px; padding-bottom: 6px; }
  .btn-replay, .btn-xl { min-height: 68px; }
  .choice-art { width: min(100%, 150px); }
  .feedback { min-height: 0; padding: 8px 14px; }
  main { padding-top: 8px; padding-bottom: 8px; }
  .preview { margin-bottom: 8px; }
}

@media (max-width: 720px) {
  .btn { padding: 0 12px; }
  .cat { min-height: 180px; }
}

@media (prefers-reduced-motion: reduce) {
  #confetti i { animation: none; display: none; }
  .btn:active { transform: none; }
}
