:root {
  --paper: #fffdf7;
  --ink: #26324a;
  --muted: #617089;
  --line: #d9e2ef;
  --sun: #ffd166;
  --sky: #73d2de;
  --leaf: #7bd88f;
  --rose: #ff6b6b;
  --violet: #9b5de5;
  --blue: #3a86ff;
  --shadow: 0 18px 38px rgba(38, 50, 74, 0.16);
  --soft-shadow: 0 10px 22px rgba(38, 50, 74, 0.1);
  color-scheme: light;
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  font-size: 18px;
  font-family: "Trebuchet MS", "Segoe UI", Arial, sans-serif;
  background:
    linear-gradient(135deg, #e7f7ff 0%, #fff4cf 42%, #ecffe8 100%);
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
  touch-action: manipulation;
}

button:disabled,
select:disabled,
input:disabled {
  cursor: not-allowed;
  opacity: 0.72;
}

.app-shell {
  width: min(1320px, calc(100% - 32px));
  margin: 0 auto;
  padding: 22px 0 34px;
}

.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
}

.title-block {
  min-width: 240px;
}

.eyebrow {
  margin: 0 0 5px;
  color: #516179;
  font-size: 1rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: 4.1rem;
  line-height: 1;
}

h2 {
  font-size: 2.7rem;
  line-height: 1.05;
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 10px;
}

.score-chip,
.tool-button,
.primary-button,
.ghost-button,
.answer-button {
  min-height: 62px;
  border: 2px solid #22314d;
  border-radius: 8px;
  box-shadow: 0 4px 0 #22314d;
  font-size: 1.08rem;
  font-weight: 900;
}

.score-chip {
  display: grid;
  place-items: center;
  padding: 0 16px;
  color: #182235;
  background: #ffffff;
}

.tool-button,
.primary-button {
  padding: 0 16px;
  color: #17223a;
  background: var(--sun);
}

.tool-button.secondary,
.ghost-button {
  background: #ffffff;
}

.tool-button:active,
.primary-button:active,
.ghost-button:active,
.answer-button:active,
.match-choice-button:active,
.subject-card:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 #22314d;
}

.game-area {
  min-height: 700px;
}

.home-layout {
  display: grid;
  grid-template-columns: minmax(280px, 0.82fr) 1.35fr;
  gap: 18px;
  align-items: stretch;
}

.intro-panel,
.quiz-panel,
.result-panel {
  border: 2px solid #22314d;
  border-radius: 8px;
  background: rgba(255, 253, 247, 0.94);
  box-shadow: var(--shadow);
}

.intro-panel {
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 20px;
}

.icon-board {
  width: 100%;
  overflow: hidden;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  aspect-ratio: 3 / 2;
}

.icon-board img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.intro-copy p {
  margin-bottom: 14px;
  color: var(--muted);
  font-size: 1.22rem;
  line-height: 1.45;
}

.legend-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.legend-badge {
  display: grid;
  gap: 2px;
  place-items: center;
  min-height: 70px;
  border: 2px solid #d6deea;
  border-radius: 8px;
  background: #ffffff;
  font-weight: 900;
  text-align: center;
}

.legend-badge small {
  color: var(--muted);
  font-size: 0.94rem;
}

.subject-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.subject-card {
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 11px;
  min-height: 230px;
  padding: 18px;
  border: 2px solid #22314d;
  border-radius: 8px;
  color: #17223a;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.82), rgba(255, 255, 255, 0.55)),
    var(--accent, #ffffff);
  box-shadow: 0 5px 0 #22314d, var(--soft-shadow);
  text-align: left;
}

.subject-card:focus-visible,
.tool-button:focus-visible,
.primary-button:focus-visible,
.ghost-button:focus-visible,
.answer-button:focus-visible,
.match-choice-button:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 4px solid #173fff;
  outline-offset: 3px;
}

.subject-icon {
  width: 96px;
  height: 96px;
  border: 2px solid rgba(34, 49, 77, 0.32);
  border-radius: 8px;
  background-color: #ffffff;
  background-image: var(--icon-image);
  background-repeat: no-repeat;
  background-size: contain;
  background-position: center;
  box-shadow: inset 0 0 0 4px rgba(255, 255, 255, 0.5);
}

.subject-name {
  align-self: center;
  font-size: 1.55rem;
  font-weight: 900;
  line-height: 1.12;
}

.subject-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 34px;
  color: var(--muted);
  font-size: 1.08rem;
  font-weight: 900;
}

.star-dot {
  display: inline-grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 2px solid #22314d;
  color: #ffffff;
  background: #c26f34;
}

.star-dot.silver {
  color: #233047;
  background: #dfe6f0;
}

.star-dot.gold {
  color: #3b2500;
  background: #ffd44d;
}

.quiz-panel {
  padding: 26px;
}

.quiz-header {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 14px;
  align-items: start;
  margin-bottom: 18px;
}

.quiz-title {
  display: flex;
  align-items: center;
  gap: 12px;
}

.mini-icon {
  width: 58px;
  height: 58px;
  flex: 0 0 auto;
  border-radius: 8px;
  border: 2px solid #22314d;
  background-color: #ffffff;
  background-image: var(--icon-image);
  background-repeat: no-repeat;
  background-size: contain;
  background-position: center;
}

.quiz-title h2 {
  margin-bottom: 3px;
}

.question-count {
  margin: 0;
  color: var(--muted);
  font-size: 1.18rem;
  font-weight: 900;
}

.quiz-score {
  display: grid;
  place-items: center;
  min-width: 148px;
  min-height: 96px;
  padding: 12px;
  border: 2px solid #22314d;
  border-radius: 8px;
  background: #ffffff;
  box-shadow: 0 4px 0 #22314d;
  font-size: 1.2rem;
  font-weight: 900;
  text-align: center;
}

.quiz-score strong {
  display: block;
  font-size: 2.7rem;
  line-height: 1;
}

.quiz-score.pop {
  animation: scorePop 520ms ease;
}

.progress-track {
  width: 100%;
  height: 24px;
  overflow: hidden;
  border: 2px solid #22314d;
  border-radius: 8px;
  background: #ffffff;
}

.progress-fill {
  width: var(--progress, 0%);
  height: 100%;
  background: linear-gradient(90deg, var(--rose), var(--sun), var(--leaf), var(--sky));
  transition: width 260ms ease;
}

.question-card {
  position: relative;
  min-height: 430px;
  margin-top: 18px;
  padding: 30px;
  border: 2px solid #d6deea;
  border-radius: 8px;
  background: #ffffff;
}

.question-text {
  margin-bottom: 24px;
  font-size: 2.35rem;
  font-weight: 900;
  line-height: 1.22;
}

.answer-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.answer-button {
  min-height: 104px;
  padding: 18px 20px;
  color: #17223a;
  background: #f5fbff;
  font-size: 1.55rem;
  text-align: left;
  line-height: 1.25;
}

.answer-button.correct {
  background: #bcf6ca;
}

.answer-button.wrong {
  background: #ffd3d3;
}

.match-list {
  display: grid;
  gap: 18px;
}

.match-row {
  display: grid;
  grid-template-columns: minmax(170px, 0.8fr) minmax(360px, 1.7fr);
  gap: 16px;
  align-items: center;
}

.match-term {
  min-height: 76px;
  padding: 18px;
  border: 2px solid #d6deea;
  border-radius: 8px;
  background: #f7fbff;
  font-size: 1.38rem;
  font-weight: 900;
}

.match-choice-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.match-choice-button {
  min-height: 76px;
  padding: 12px 14px;
  border: 2px solid #22314d;
  border-radius: 8px;
  color: #17223a;
  background: #fffdf7;
  box-shadow: 0 4px 0 #22314d;
  font-size: 1.18rem;
  font-weight: 900;
  line-height: 1.2;
}

.match-choice-button.selected {
  background: #e8f5ff;
  outline: 4px solid #3a86ff;
  outline-offset: 1px;
}

.match-choice-button.correct {
  background: #bcf6ca;
}

.match-choice-button.wrong {
  background: #ffd3d3;
}

.feedback {
  display: none;
  margin-top: 16px;
  padding: 18px 20px;
  border: 2px solid #22314d;
  border-radius: 8px;
  background: #fff7d6;
  font-size: 1.32rem;
  line-height: 1.42;
}

.feedback.show {
  display: block;
  animation: slideUp 280ms ease;
}

.feedback.is-correct {
  background: #dcffe5;
}

.feedback.is-wrong {
  background: #ffe1e1;
}

.feedback.is-note {
  background: #e8f5ff;
}

.feedback strong {
  display: block;
  margin-bottom: 4px;
}

.inline-next-action {
  display: none;
}

.inline-next-action:not(:empty) {
  display: block;
  margin-top: 18px;
}

.next-question-button {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  width: 100%;
  min-height: 112px;
  padding: 20px 24px;
  font-size: 1.75rem;
  line-height: 1.1;
  text-align: center;
}

.next-arrow {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  border: 2px solid #22314d;
  border-radius: 50%;
  background: #ffffff;
  font-size: 2.4rem;
  line-height: 1;
}

.quiz-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 16px;
}

.after-actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.points-burst {
  position: fixed;
  z-index: 5;
  top: 110px;
  right: 32px;
  padding: 10px 14px;
  border: 2px solid #22314d;
  border-radius: 8px;
  background: #fff176;
  box-shadow: 0 4px 0 #22314d;
  font-weight: 900;
  animation: burst 820ms ease forwards;
  pointer-events: none;
}

.result-panel {
  display: grid;
  gap: 18px;
  place-items: center;
  max-width: 760px;
  margin: 0 auto;
  padding: 30px;
  text-align: center;
}

.reward-star {
  display: grid;
  place-items: center;
  width: 150px;
  height: 150px;
  border: 3px solid #22314d;
  border-radius: 50%;
  color: #ffffff;
  background: #c26f34;
  box-shadow: 0 8px 0 #22314d, var(--shadow);
  font-size: 5.4rem;
  line-height: 1;
  animation: rewardPop 700ms ease;
}

.reward-star.silver {
  color: #233047;
  background: #dfe6f0;
}

.reward-star.gold {
  color: #3b2500;
  background: #ffd44d;
}

.result-score {
  margin-bottom: 0;
  font-size: 2.1rem;
  font-weight: 900;
}

.result-message {
  max-width: 560px;
  margin-bottom: 0;
  color: var(--muted);
  font-size: 1.35rem;
  line-height: 1.45;
}

.result-actions {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 12px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@keyframes scorePop {
  0%,
  100% {
    transform: scale(1);
  }
  40% {
    transform: scale(1.13) rotate(-2deg);
  }
}

@keyframes burst {
  0% {
    opacity: 0;
    transform: translateY(10px) scale(0.8);
  }
  25% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform: translateY(-38px) scale(1.08);
  }
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes rewardPop {
  0% {
    transform: scale(0.3) rotate(-14deg);
  }
  70% {
    transform: scale(1.08) rotate(4deg);
  }
  100% {
    transform: scale(1) rotate(0);
  }
}

@media (max-width: 920px) {
  .top-bar,
  .home-layout {
    grid-template-columns: 1fr;
  }

  .top-bar {
    display: grid;
  }

  .toolbar {
    justify-content: flex-start;
  }

  .home-layout {
    display: grid;
  }

  .intro-panel {
    display: grid;
    grid-template-columns: minmax(220px, 0.8fr) 1fr;
  }
}

@media (max-width: 760px) {
  .app-shell {
    width: min(100% - 20px, 1320px);
    padding-top: 12px;
  }

  h1 {
    font-size: 2.4rem;
  }

  h2 {
    font-size: 2rem;
  }

  .subject-grid,
  .answer-grid {
    grid-template-columns: 1fr;
  }

  .question-card {
    min-height: 360px;
    padding: 20px;
  }

  .question-text {
    font-size: 1.7rem;
  }

  .answer-button {
    min-height: 84px;
    font-size: 1.28rem;
  }

  .match-choice-grid {
    grid-template-columns: 1fr;
  }

  .intro-panel,
  .quiz-header,
  .match-row {
    grid-template-columns: 1fr;
  }

  .subject-card {
    min-height: 150px;
    grid-template-columns: auto 1fr;
    grid-template-rows: auto auto;
    align-items: center;
  }

  .subject-icon {
    grid-row: 1 / 3;
  }

  .subject-meta {
    justify-content: flex-start;
  }

  .quiz-actions {
    align-items: stretch;
  }

  .quiz-actions > *,
  .after-actions,
  .primary-button,
  .ghost-button {
    width: 100%;
  }

  .after-actions {
    display: grid;
  }
}
