:root {
  --ink: #20243a;
  --muted: #6d7184;
  --cream: #fffaf0;
  --card: rgba(255, 255, 255, 0.9);
  --coral: #ff5f57;
  --orange: #ff9f43;
  --green: #36c98f;
  --blue: #4c7cf3;
  --purple: #8c63ee;
  --shadow: 0 24px 70px rgba(61, 52, 89, 0.16);
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  min-height: 100%;
  margin: 0;
  overscroll-behavior: none;
}

body {
  color: var(--ink);
  font-family: "Noto Sans SC", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  background:
    radial-gradient(circle at 12% 12%, rgba(255, 196, 86, 0.34), transparent 28rem),
    radial-gradient(circle at 90% 18%, rgba(255, 101, 123, 0.25), transparent 26rem),
    linear-gradient(145deg, #fff8df 0%, #fff2e8 45%, #e8fbf5 100%);
}

button,
select {
  font: inherit;
}

button {
  -webkit-tap-highlight-color: transparent;
}

.app-shell {
  min-height: 100dvh;
}

.screen {
  display: none;
  min-height: 100dvh;
}

.screen.active {
  display: flex;
}

.selection-screen {
  align-items: center;
  flex-direction: column;
  justify-content: center;
  padding: max(24px, env(safe-area-inset-top)) 20px max(24px, env(safe-area-inset-bottom));
}

.brand {
  display: flex;
  align-items: center;
  width: min(680px, 100%);
  margin-bottom: 22px;
  gap: 18px;
}

.brand-fruit {
  display: grid;
  flex: 0 0 82px;
  width: 82px;
  height: 82px;
  place-items: center;
  font-size: 54px;
  transform: rotate(-8deg);
  filter: drop-shadow(0 10px 12px rgba(255, 95, 87, 0.22));
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--coral);
  font-size: 13px;
  font-weight: 900;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(34px, 8vw, 52px);
  line-height: 1.05;
  letter-spacing: -0.05em;
}

.tagline {
  margin: 7px 0 0;
  color: var(--muted);
  font-weight: 650;
}

.selection-card,
.result-card {
  width: min(680px, 100%);
  border: 1px solid rgba(255, 255, 255, 0.8);
  border-radius: 28px;
  background: var(--card);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.selection-card {
  padding: 26px;
}

.step-heading {
  display: flex;
  justify-content: space-between;
  margin-bottom: 18px;
  font-size: 14px;
  font-weight: 850;
}

#selectionProgress {
  color: var(--blue);
}

.selectors {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

label,
.field-label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

label span {
  display: block;
  margin: 0 0 7px 3px;
}

select {
  width: 100%;
  height: 48px;
  padding: 0 38px 0 13px;
  border: 1.5px solid #e6e3eb;
  border-radius: 14px;
  color: var(--ink);
  background: #fff;
  font-weight: 750;
  outline: none;
}

select:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 4px rgba(76, 124, 243, 0.12);
}

.lesson-section {
  margin-top: 20px;
}

.field-label {
  margin: 0 0 9px 3px;
}

.lesson-list {
  display: grid;
  gap: 9px;
}

.lesson-option,
.loading-card {
  width: 100%;
  min-height: 60px;
  padding: 13px 16px;
  border: 1.5px solid #e9e5ec;
  border-radius: 16px;
  text-align: left;
  background: #fff;
}

.lesson-option {
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--ink);
  cursor: pointer;
  font-weight: 780;
  transition: transform 150ms ease, border-color 150ms ease, background 150ms ease;
}

.lesson-option:not(:disabled):hover {
  transform: translateY(-1px);
  border-color: #a9bdf9;
}

.lesson-option.selected {
  border-color: var(--blue);
  background: #eef3ff;
  box-shadow: inset 0 0 0 1px var(--blue);
}

.lesson-option:disabled {
  color: #9a9daa;
  background: #f6f5f7;
  cursor: not-allowed;
}

.status-pill {
  flex: 0 0 auto;
  margin-left: 12px;
  padding: 4px 9px;
  border-radius: 999px;
  color: #985b00;
  background: #fff0c7;
  font-size: 11px;
  font-weight: 900;
}

.status-pill.soon {
  color: #777985;
  background: #e9e8eb;
}

.loading-card {
  display: grid;
  place-items: center;
  color: var(--muted);
  text-align: center;
  font-weight: 700;
}

.inline-message {
  min-height: 22px;
  margin: 12px 2px 6px;
  color: #ce3c35;
  font-size: 13px;
  font-weight: 750;
}

.game-rules {
  display: grid;
  grid-template-columns: 1fr 1fr;
  margin: 4px 2px 14px;
  padding: 12px 14px;
  border-radius: 14px;
  color: #4f5365;
  background: #f6f4f1;
  gap: 5px 14px;
  font-size: 12px;
  font-weight: 750;
}

.game-rules span::before {
  margin-right: 5px;
  color: var(--green);
  content: "•";
}

.primary-button,
.secondary-button {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 54px;
  border: 0;
  border-radius: 16px;
  cursor: pointer;
  font-weight: 900;
}

.primary-button {
  gap: 10px;
  color: #fff;
  background: linear-gradient(100deg, var(--coral), var(--orange));
  box-shadow: 0 12px 25px rgba(255, 104, 78, 0.24);
}

.primary-button:disabled {
  box-shadow: none;
  opacity: 0.42;
  cursor: not-allowed;
}

.secondary-button {
  color: var(--ink);
  background: #f1f0f4;
}

.how-to {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  width: min(680px, 100%);
  margin-top: 18px;
  gap: 10px 22px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 750;
}

.game-screen {
  position: relative;
  overflow: hidden;
  flex-direction: column;
  background: linear-gradient(180deg, #132b42 0%, #102131 58%, #17281f 100%);
  touch-action: none;
  user-select: none;
}

.game-screen::after {
  position: absolute;
  right: -10%;
  bottom: -70px;
  left: -10%;
  height: 150px;
  border-radius: 50% 50% 0 0;
  background: #264b33;
  content: "";
  pointer-events: none;
}

.game-topbar {
  position: relative;
  z-index: 3;
  display: grid;
  grid-template-columns: auto auto 1fr auto;
  align-items: center;
  min-height: 78px;
  padding: max(12px, env(safe-area-inset-top)) 18px 10px;
  gap: 16px;
  color: #fff;
  background: rgba(8, 20, 31, 0.75);
  backdrop-filter: blur(12px);
}

.icon-button {
  width: 38px;
  height: 38px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 12px;
  color: #fff;
  background: rgba(255, 255, 255, 0.08);
  font-size: 25px;
  cursor: pointer;
}

.stat {
  display: flex;
  min-width: 56px;
  align-items: center;
  flex-direction: column;
}

.stat-label {
  color: #aebbc6;
  font-size: 10px;
  font-weight: 850;
  letter-spacing: 0.12em;
}

.stat strong {
  font-size: 25px;
  line-height: 1.1;
}

#timerDisplay.warning {
  color: #ff7169;
  animation: pulse 0.7s infinite alternate;
}

.round-progress {
  display: flex;
  min-width: 0;
  align-items: center;
  flex-direction: column;
  gap: 7px;
}

.round-progress > span {
  overflow: hidden;
  max-width: 100%;
  font-size: 12px;
  font-weight: 750;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.progress-track {
  overflow: hidden;
  width: 100%;
  max-width: 220px;
  height: 6px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.14);
}

#progressFill {
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #45e3a2, #ffd55c);
  transition: width 250ms ease;
}

.question-card {
  position: absolute;
  z-index: 3;
  top: max(94px, calc(env(safe-area-inset-top) + 84px));
  left: 50%;
  width: min(520px, calc(100% - 28px));
  min-height: 118px;
  padding: 14px 22px 16px;
  border: 1px solid rgba(255, 255, 255, 0.72);
  border-radius: 24px;
  text-align: center;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.2);
  transform: translateX(-50%);
  backdrop-filter: blur(12px);
}

#questionTypeLabel {
  display: inline-block;
  margin-bottom: 5px;
  padding: 3px 9px;
  border-radius: 999px;
  color: #245f55;
  background: #dff9ee;
  font-size: 10px;
  font-weight: 900;
  letter-spacing: 0.07em;
}

#questionPrimary {
  font-size: clamp(28px, 7vw, 38px);
  font-weight: 950;
  line-height: 1.15;
}

#questionSecondary {
  margin-top: 3px;
  color: var(--muted);
  font-size: clamp(16px, 4vw, 20px);
  font-weight: 720;
}

.feedback {
  position: absolute;
  z-index: 5;
  top: max(224px, calc(env(safe-area-inset-top) + 214px));
  left: 50%;
  padding: 9px 18px;
  border-radius: 999px;
  color: #fff;
  background: rgba(13, 23, 31, 0.88);
  font-size: 16px;
  font-weight: 900;
  opacity: 0;
  transform: translate(-50%, -8px) scale(0.92);
  transition: opacity 140ms ease, transform 140ms ease;
  pointer-events: none;
}

.feedback.show {
  opacity: 1;
  transform: translate(-50%, 0) scale(1);
}

.feedback.good {
  background: #168a61;
}

.feedback.bad {
  background: #c34a43;
}

.feedback.miss {
  background: #8552cf;
}

.feedback.bomb {
  color: #2a2034;
  background: #ffd45c;
}

.stage-message {
  position: absolute;
  z-index: 6;
  top: 43%;
  left: 50%;
  width: max-content;
  max-width: calc(100% - 30px);
  padding: 13px 22px;
  border: 2px solid rgba(255, 255, 255, 0.8);
  border-radius: 18px;
  color: #fff;
  text-align: center;
  background: linear-gradient(110deg, #7359df, #ff695d);
  box-shadow: 0 14px 36px rgba(0, 0, 0, 0.28);
  font-size: clamp(20px, 5vw, 30px);
  font-weight: 950;
  opacity: 0;
  transform: translate(-50%, -50%) scale(0.8);
  transition: opacity 160ms ease, transform 160ms ease;
  pointer-events: none;
}

.stage-message.show {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}

.game-arena {
  position: absolute;
  inset: 78px 0 0;
  z-index: 2;
  overflow: hidden;
  min-width: 0;
  min-height: 0;
  touch-action: none;
}

#gameCanvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

.result-screen {
  position: relative;
  overflow: hidden;
  align-items: center;
  justify-content: center;
  padding: max(28px, env(safe-area-inset-top)) 18px max(28px, env(safe-area-inset-bottom));
}

.result-card {
  position: relative;
  z-index: 2;
  max-height: calc(100dvh - 38px);
  overflow-y: auto;
  padding: 28px;
  text-align: center;
}

.result-icon {
  font-size: 58px;
  filter: drop-shadow(0 9px 10px rgba(255, 159, 67, 0.24));
}

.result-card h2 {
  margin: 4px 0 7px;
  font-size: clamp(27px, 7vw, 39px);
  line-height: 1.1;
}

.result-subtitle {
  margin: 0;
  color: var(--muted);
  font-weight: 650;
}

.result-stats {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  margin: 24px 0;
  gap: 8px;
}

.score-breakdown {
  margin: 0 0 20px;
  padding: 16px;
  border-radius: 17px;
  text-align: left;
  background: #f7f5f2;
}

.score-breakdown h3 {
  margin: 0 0 11px;
  font-size: 15px;
}

.score-breakdown > div {
  display: flex;
  justify-content: space-between;
  padding: 5px 0;
  gap: 12px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.score-breakdown strong {
  flex: 0 0 auto;
  color: var(--ink);
}

.score-breakdown .score-total {
  margin-top: 7px;
  padding-top: 10px;
  border-top: 1px solid #dedbe2;
  color: var(--ink);
  font-size: 15px;
  font-weight: 900;
}

.result-stats > div {
  display: flex;
  min-height: 82px;
  align-items: center;
  flex-direction: column;
  justify-content: center;
  border-radius: 16px;
  background: #f7f5f2;
}

.result-stats strong {
  font-size: 21px;
}

.result-stats span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 750;
}

.unfinished-section {
  margin: 0 0 20px;
  text-align: left;
}

.unfinished-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 9px;
}

.unfinished-heading h3 {
  margin: 0;
  font-size: 15px;
}

.unfinished-heading span {
  color: var(--coral);
  font-size: 12px;
  font-weight: 850;
}

.unfinished-list {
  display: grid;
  max-height: 190px;
  overflow-y: auto;
  gap: 7px;
}

.unfinished-word {
  display: flex;
  align-items: baseline;
  padding: 10px 13px;
  border-radius: 13px;
  background: #f7f5f2;
  gap: 3px 12px;
}

.unfinished-word strong {
  font-size: 19px;
}

.unfinished-word span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

.no-review {
  padding: 13px;
  border-radius: 13px;
  color: #24755a;
  text-align: center;
  background: #e5f8ef;
  font-size: 13px;
  font-weight: 850;
}

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

.celebration span {
  position: absolute;
  z-index: 1;
  top: -30px;
  font-size: 24px;
  animation: confetti-fall linear infinite;
}

@keyframes confetti-fall {
  to {
    transform: translateY(110vh) rotate(700deg);
  }
}

@keyframes pulse {
  to {
    transform: scale(1.12);
  }
}

@media (max-width: 560px) {
  .selection-screen {
    justify-content: flex-start;
    padding-top: max(28px, env(safe-area-inset-top));
  }

  .brand {
    margin-bottom: 16px;
  }

  .brand-fruit {
    flex-basis: 62px;
    width: 62px;
    height: 62px;
    font-size: 43px;
  }

  .selection-card {
    padding: 19px;
    border-radius: 23px;
  }

  .selectors {
    grid-template-columns: 1fr 1fr;
  }

  .selectors label:last-child {
    grid-column: span 2;
  }

  .game-topbar {
    grid-template-columns: auto auto 1fr auto;
    padding-right: 11px;
    padding-left: 11px;
    gap: 8px;
  }

  .round-progress > span {
    max-width: 110px;
  }

  .result-card {
    padding: 23px 18px;
  }

  .result-stats {
    grid-template-columns: 1fr 1fr;
  }

  .result-stats > div:first-child {
    grid-column: span 2;
  }

  .game-rules {
    grid-template-columns: 1fr;
  }
}

@media (max-height: 680px) {
  .question-card {
    top: 82px;
    min-height: 98px;
    padding: 10px 18px;
  }

  .feedback {
    top: 188px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
