:root {
  color-scheme: light;
  --rose: #d9366f;
  --rose-deep: #a91f55;
  --coral: #ff7a7a;
  --lavender: #8e67bd;
  --mint: #8ccfb0;
  --teal: #1599a2;
  --gold: #f5b942;
  --gold-deep: #b87613;
  --ink: #3f2543;
  --muted: #7b6073;
  --paper: #fff8ea;
  --paper-strong: #fffdf5;
  --line: rgba(151, 89, 82, 0.25);
  --shadow: 0 24px 70px rgba(95, 42, 74, 0.2);
  --soft-shadow: 0 14px 34px rgba(113, 55, 80, 0.14);
  font-family:
    ui-rounded,
    "Avenir Next",
    "Trebuchet MS",
    system-ui,
    sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(90deg, rgba(255, 228, 236, 0.58), rgba(255, 252, 232, 0.3)),
    url("./assets/royal-study.png") center / cover fixed;
}

button,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
}

.game-shell {
  display: grid;
  grid-template-columns: minmax(122px, 170px) minmax(420px, 1fr) minmax(270px, 350px);
  gap: clamp(12px, 1.7vw, 24px);
  width: min(1480px, calc(100vw - 32px));
  min-height: calc(100vh - 32px);
  margin: 16px auto;
  align-items: center;
}

.progress-panel,
.hint-card,
.reward-card,
.flashcard,
.round-dialog form,
.parent-dialog form {
  border: 2px solid rgba(190, 140, 53, 0.45);
  background:
    linear-gradient(145deg, rgba(255, 255, 250, 0.92), rgba(255, 244, 223, 0.9)),
    var(--paper);
  box-shadow: var(--soft-shadow);
}

.progress-panel {
  display: grid;
  justify-items: center;
  gap: 8px;
  min-height: 500px;
  padding: 22px 16px;
  border-radius: 28px;
}

.mini-crown {
  position: relative;
  width: 42px;
  height: 30px;
  filter: drop-shadow(0 5px 4px rgba(151, 87, 22, 0.22));
}

.mini-crown span {
  position: absolute;
  bottom: 2px;
  width: 18px;
  height: 24px;
  border-radius: 5px 5px 0 0;
  background: linear-gradient(#ffe386, #ec9f24);
  clip-path: polygon(50% 0, 100% 45%, 78% 100%, 22% 100%, 0 45%);
}

.mini-crown span:nth-child(1) {
  left: 0;
  transform: rotate(-18deg);
}

.mini-crown span:nth-child(2) {
  left: 12px;
  bottom: 5px;
}

.mini-crown span:nth-child(3) {
  right: 0;
  transform: rotate(18deg);
}

.eyebrow {
  margin: 0;
  color: var(--rose-deep);
  font-size: 0.82rem;
  font-weight: 800;
  letter-spacing: 0;
}

.progress-panel strong {
  font-size: clamp(1.1rem, 2vw, 1.35rem);
}

.progress-track {
  display: grid;
  gap: 10px;
  width: 100%;
  margin: 10px 0 0;
  padding: 0;
  list-style: none;
}

.progress-track li {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  margin: 0 auto;
  border: 2px solid rgba(176, 135, 65, 0.38);
  border-radius: 50%;
  background: #f1e4cf;
  color: rgba(73, 54, 56, 0.4);
  box-shadow: inset 0 4px 10px rgba(255, 255, 255, 0.72);
}

.progress-track li::before,
.star-icon,
.big-star {
  content: "";
  display: block;
  width: 28px;
  aspect-ratio: 1;
  background: currentColor;
  clip-path: polygon(50% 0, 61% 35%, 98% 35%, 68% 56%, 79% 91%, 50% 70%, 21% 91%, 32% 56%, 2% 35%, 39% 35%);
}

.progress-track li.done {
  background: linear-gradient(145deg, #ffe89a, var(--gold));
  color: #fff1a8;
  border-color: #c99022;
  box-shadow: 0 9px 14px rgba(180, 118, 19, 0.24);
}

.play-area {
  display: grid;
  gap: clamp(12px, 1.7vw, 18px);
  align-content: center;
}

.game-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}

h1 {
  display: inline-block;
  margin: 4px 0 0;
  padding: 8px 26px 13px;
  border: 2px solid rgba(245, 185, 66, 0.52);
  border-radius: 26px 26px 34px 34px;
  background: linear-gradient(145deg, rgba(217, 54, 111, 0.92), rgba(255, 122, 122, 0.92));
  color: #f7f2ff;
  font-size: clamp(2.1rem, 5.2vw, 4rem);
  line-height: 0.95;
  text-shadow:
    0 5px 0 rgba(166, 42, 87, 0.48),
    0 14px 34px rgba(81, 22, 52, 0.34);
  box-shadow: var(--soft-shadow);
}

.game-header .eyebrow {
  display: inline-flex;
  padding: 7px 14px;
  border-radius: 999px;
  background: rgba(255, 248, 234, 0.82);
  color: var(--teal);
}

.score-pill {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-width: 116px;
  padding: 12px 16px;
  border: 2px solid rgba(188, 137, 33, 0.44);
  border-radius: 999px;
  background: rgba(255, 248, 234, 0.9);
  box-shadow: var(--soft-shadow);
}

.star-icon {
  width: 28px;
  color: var(--gold);
  filter: drop-shadow(0 3px 0 #c17b17);
}

.score-pill strong {
  font-size: 1.55rem;
  color: var(--rose-deep);
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  justify-content: center;
}

.segmented,
.level-select,
.parent-mode-button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px;
  border: 2px solid rgba(190, 140, 53, 0.32);
  border-radius: 22px;
  background: rgba(255, 248, 234, 0.9);
  box-shadow: 0 10px 24px rgba(86, 47, 70, 0.1);
}

.segment,
.level-select select {
  min-width: 62px;
  min-height: 44px;
  border: 0;
  border-radius: 16px;
  color: var(--ink);
  background: #f2e7d6;
  font-weight: 900;
}

.segment.active {
  color: #fff;
  background: linear-gradient(145deg, var(--rose), var(--coral));
  box-shadow: 0 8px 16px rgba(217, 54, 111, 0.26);
}

.level-select span {
  padding-left: 8px;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 800;
}

.level-select select {
  padding: 0 12px;
  background: #e0f2df;
}

.parent-mode-button {
  min-height: 60px;
  padding: 8px 18px;
  color: #fff;
  background: linear-gradient(145deg, var(--teal), #5abf9b);
  font-weight: 900;
}

.flashcard {
  position: relative;
  display: grid;
  place-items: center;
  min-height: clamp(230px, 31vh, 330px);
  padding: clamp(20px, 3.5vw, 42px);
  border-radius: 32px;
  overflow: hidden;
}

.flashcard::before,
.flashcard::after {
  content: "";
  position: absolute;
  width: 80px;
  height: 80px;
  border: 2px solid rgba(217, 54, 111, 0.25);
  pointer-events: none;
}

.flashcard::before {
  top: 18px;
  left: 18px;
  border-right: 0;
  border-bottom: 0;
  border-radius: 22px 0 0;
}

.flashcard::after {
  right: 18px;
  bottom: 18px;
  border-left: 0;
  border-top: 0;
  border-radius: 0 0 22px;
}

.card-mode {
  align-self: start;
  margin: 0;
  padding: 7px 16px;
  border-radius: 999px;
  background: #e7f5ee;
  color: #126d59;
  font-weight: 900;
}

.problem {
  font-size: clamp(3.2rem, 10vw, 7.4rem);
  font-weight: 900;
  line-height: 1;
  text-align: center;
  color: var(--rose);
  text-shadow: 0 5px 0 rgba(255, 211, 224, 0.9);
}

.problem.long-problem {
  font-size: clamp(2.7rem, 7.4vw, 5.8rem);
}

.problem.very-long-problem {
  font-size: clamp(2.2rem, 5.8vw, 4.5rem);
}

.feedback {
  min-height: 32px;
  margin: 0;
  color: var(--muted);
  font-size: clamp(1rem, 2vw, 1.25rem);
  font-weight: 800;
  text-align: center;
}

.feedback.correct {
  color: #147f67;
}

.feedback.try {
  color: var(--rose-deep);
}

.answers {
  display: grid;
  grid-template-columns: repeat(4, minmax(104px, 1fr));
  gap: clamp(10px, 2vw, 18px);
}

.answer-button {
  position: relative;
  min-height: 82px;
  border: 2px solid rgba(190, 140, 53, 0.35);
  border-radius: 24px;
  background: linear-gradient(145deg, #fff9ec, #ffe0eb);
  color: var(--rose-deep);
  font-size: clamp(2.1rem, 5vw, 3.7rem);
  font-weight: 900;
  box-shadow: var(--soft-shadow);
  transition:
    transform 150ms ease,
    box-shadow 150ms ease,
    background 150ms ease;
}

.answer-button.long-answer {
  font-size: clamp(1.8rem, 3.6vw, 2.8rem);
}

.answer-button.very-long-answer {
  font-size: clamp(1.45rem, 3vw, 2.25rem);
}

.answer-button::before {
  content: "";
  position: absolute;
  top: -13px;
  left: calc(50% - 14px);
  width: 28px;
  height: 22px;
  background: linear-gradient(#ffe386, #ec9f24);
  clip-path: polygon(50% 0, 62% 36%, 100% 36%, 75% 100%, 25% 100%, 0 36%, 38% 36%);
}

.answer-button:nth-child(2) {
  background: linear-gradient(145deg, #f6fff6, #dff4e8);
  color: #145c44;
}

.answer-button:nth-child(3) {
  background: linear-gradient(145deg, #fff5ff, #eadcff);
  color: #673290;
}

.answer-button:nth-child(4) {
  background: linear-gradient(145deg, #fff9dc, #ffe6a4);
  color: #8c5a0e;
}

.answer-button:hover:not(:disabled),
.answer-button:focus-visible {
  transform: translateY(-4px);
  box-shadow: 0 18px 34px rgba(113, 55, 80, 0.22);
}

.answer-button.correct {
  color: #fff;
  background: linear-gradient(145deg, #2bbf92, var(--teal));
}

.answer-button.wrong {
  opacity: 0.5;
  transform: scale(0.98);
}

.hint-panel {
  display: grid;
  gap: 16px;
  align-content: center;
}

.hint-card,
.reward-card {
  border-radius: 28px;
  padding: 18px;
}

.panel-title {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}

.panel-title h2 {
  margin: 0;
  color: var(--rose-deep);
  font-size: clamp(1.6rem, 4vw, 2.15rem);
}

.lamp-icon {
  width: 46px;
  height: 46px;
  border: 3px solid rgba(148, 82, 35, 0.35);
  border-radius: 50%;
  background:
    radial-gradient(circle at 50% 42%, #fff6a6 0 23%, transparent 24%),
    linear-gradient(145deg, #ff6a97, #e03770);
  box-shadow: inset 0 0 0 4px rgba(255, 255, 255, 0.2);
}

.hint-list {
  display: grid;
  gap: 10px;
  min-height: 152px;
}

.hint-step,
.empty-hint {
  margin: 0;
  padding: 12px 14px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.72);
  color: var(--ink);
  font-weight: 800;
  line-height: 1.35;
}

.hint-step {
  display: grid;
  grid-template-columns: 30px 1fr;
  gap: 10px;
  align-items: start;
}

.hint-step span {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  color: #fff;
  background: var(--rose);
}

.wand-button,
.next-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  min-height: 60px;
  border: 0;
  border-radius: 22px;
  color: #fff;
  background: linear-gradient(145deg, var(--rose), var(--rose-deep));
  font-weight: 900;
  box-shadow: 0 15px 28px rgba(151, 31, 85, 0.28);
}

.wand-button:disabled,
.next-button:disabled {
  opacity: 0.52;
  box-shadow: none;
}

.wand-icon {
  position: relative;
  width: 28px;
  height: 28px;
}

.wand-icon::before {
  content: "";
  position: absolute;
  left: 11px;
  top: 7px;
  width: 6px;
  height: 24px;
  border-radius: 999px;
  background: #fff6b0;
  transform: rotate(45deg);
}

.wand-icon::after {
  content: "";
  position: absolute;
  width: 18px;
  aspect-ratio: 1;
  background: #fff6b0;
  clip-path: polygon(50% 0, 61% 35%, 98% 35%, 68% 56%, 79% 91%, 50% 70%, 21% 91%, 32% 56%, 2% 35%, 39% 35%);
}

.reward-row {
  display: flex;
  align-items: center;
  gap: 18px;
  margin-top: 8px;
}

.big-star {
  width: 58px;
  color: var(--gold);
  filter: drop-shadow(0 5px 0 #c27e18);
}

.reward-row span {
  display: block;
  color: var(--muted);
  font-weight: 800;
}

.reward-row strong {
  color: var(--teal);
  font-size: 2.4rem;
  line-height: 1;
}

.round-dialog,
.parent-dialog {
  padding: 0;
  border: 0;
  border-radius: 30px;
  background: transparent;
}

.round-dialog {
  width: min(420px, calc(100vw - 32px));
}

.parent-dialog {
  width: min(760px, calc(100vw - 32px));
}

.round-dialog::backdrop,
.parent-dialog::backdrop {
  background: rgba(67, 31, 57, 0.35);
  backdrop-filter: blur(4px);
}

.round-dialog form,
.parent-dialog form {
  display: grid;
  gap: 14px;
  padding: 26px;
  border-radius: 30px;
}

.round-dialog form {
  text-align: center;
}

.round-dialog h2 {
  margin: 0;
  color: var(--rose-deep);
  font-size: 2rem;
}

.round-dialog p {
  margin: 0;
  color: var(--muted);
  font-weight: 800;
}

.parent-header {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 16px;
}

.parent-header h2 {
  margin: 2px 0 0;
  color: var(--rose-deep);
  font-size: 2rem;
}

.close-button {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  color: #fff;
  background: var(--rose-deep);
  font-weight: 900;
}

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

.parent-stat-card {
  display: grid;
  gap: 10px;
  padding: 16px;
  border: 2px solid rgba(190, 140, 53, 0.25);
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.68);
}

.parent-stat-card h3 {
  margin: 0;
  color: var(--teal);
  font-size: 1.25rem;
}

.parent-stat-card dl {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px 12px;
  margin: 0;
}

.parent-stat-card dt,
.parent-stat-card dd {
  margin: 0;
  font-weight: 800;
}

.parent-stat-card dt {
  color: var(--muted);
}

.parent-stat-card dd {
  color: var(--ink);
  text-align: right;
}

@media (max-width: 980px) {
  body {
    background-attachment: scroll;
  }

  .game-shell {
    grid-template-columns: 1fr;
    align-items: stretch;
    width: min(720px, calc(100vw - 24px));
    margin: 12px auto;
  }

  .progress-panel {
    min-height: auto;
    grid-template-columns: auto auto 1fr;
    justify-items: start;
    align-items: center;
    border-radius: 22px;
  }

  .progress-track {
    grid-column: 1 / -1;
    display: flex;
    gap: 7px;
    overflow-x: auto;
    padding-bottom: 3px;
  }

  .progress-track li {
    flex: 0 0 38px;
    width: 38px;
    height: 38px;
  }

  .progress-track li::before {
    width: 20px;
  }

  .game-header {
    align-items: end;
  }

  .answers {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .hint-panel {
    grid-template-columns: 1fr;
  }

  .hint-list {
    min-height: auto;
  }
}

@media (min-width: 700px) and (max-width: 1180px) {
  .game-shell {
    grid-template-columns: minmax(96px, 130px) minmax(420px, 1fr);
    width: min(1000px, calc(100vw - 24px));
    align-items: start;
  }

  .progress-panel {
    grid-template-columns: 1fr;
    justify-items: center;
    align-items: start;
    min-height: 640px;
  }

  .progress-track {
    display: grid;
    overflow: visible;
  }

  .hint-panel {
    grid-column: 2;
    grid-template-columns: minmax(260px, 1fr) minmax(220px, 0.65fr);
    align-items: stretch;
  }

  .next-button {
    grid-column: 1 / -1;
  }

  .parent-stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 560px) {
  .game-shell {
    width: calc(100vw - 16px);
    margin: 8px auto;
    gap: 10px;
  }

  .game-header {
    align-items: stretch;
    flex-direction: column;
  }

  h1 {
    max-width: 100%;
    padding: 7px 18px 10px;
    font-size: 2.45rem;
    overflow-wrap: anywhere;
  }

  .game-header .eyebrow {
    align-self: flex-start;
  }

  .score-pill {
    align-self: flex-start;
  }

  .segmented,
  .level-select,
  .parent-mode-button {
    width: 100%;
  }

  .segmented {
    justify-content: space-between;
  }

  .segment {
    min-width: 0;
    flex: 1;
  }

  .level-select select {
    flex: 1;
  }

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

  .flashcard {
    min-height: 232px;
    border-radius: 24px;
  }

  .problem {
    font-size: clamp(3.1rem, 17vw, 5.6rem);
  }

  .problem.long-problem {
    font-size: clamp(2.3rem, 12vw, 4.2rem);
  }

  .problem.very-long-problem {
    font-size: clamp(1.8rem, 9vw, 3.2rem);
  }

  .answer-button {
    min-height: 78px;
    border-radius: 20px;
  }

  .answer-button.long-answer {
    font-size: clamp(1.55rem, 8vw, 2.7rem);
  }

  .answer-button.very-long-answer {
    font-size: clamp(1.25rem, 6.8vw, 2.2rem);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition: none !important;
    animation: none !important;
  }
}
