:root {
  color-scheme: light;
  font-family: "Trebuchet MS", "Segoe UI", sans-serif;
  color: #172554;
  background: #f3f6ff;
  font-synthesis: none;
  --ink: #172554;
  --muted: #64748b;
  --blue: #3156c9;
  --violet: #7548d8;
  --mint: #c8f4e3;
  --gold: #ffd66b;
  --card: rgba(255, 255, 255, 0.94);
  --shadow: 0 18px 50px rgba(37, 57, 118, 0.13);
}

* { box-sizing: border-box; }

body {
  min-width: 0;
  min-height: 100vh;
  margin: 0;
  background:
    radial-gradient(ellipse at 12% 9%, rgba(196, 221, 255, 0.72), transparent 34rem),
    radial-gradient(ellipse at 92% 20%, rgba(229, 210, 255, 0.56), transparent 30rem),
    #f5f7ff;
}

button { font: inherit; }
[hidden] { display: none !important; }
button:focus-visible, a:focus-visible, summary:focus-visible {
  outline: 3px solid #f59e0b;
  outline-offset: 3px;
}

.app-shell {
  width: min(1120px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  padding: clamp(16px, 4vw, 42px);
}

.loading-state {
  display: grid;
  min-height: 75vh;
  place-content: center;
  justify-items: center;
  color: var(--muted);
}

.loading-orbit { font-size: 4rem; color: var(--violet); animation: float 2s ease-in-out infinite; }

.hero {
  position: relative;
  overflow: hidden;
  min-height: 320px;
  padding: clamp(26px, 5vw, 54px);
  border: 1px solid rgba(255,255,255,.55);
  border-radius: 32px;
  color: white;
  background: linear-gradient(120deg, #17377a 0%, #3659ce 53%, #8050d7 100%);
  box-shadow: 0 25px 55px rgba(49, 70, 165, .24);
  isolation: isolate;
}

.hero::before, .hero::after {
  position: absolute;
  z-index: -1;
  content: "";
  border: 1px solid rgba(255,255,255,.18);
  border-radius: 50%;
}

.hero::before { width: 370px; height: 370px; right: -80px; top: -150px; }
.hero::after { width: 260px; height: 260px; right: 80px; bottom: -180px; }

.hero-sparkles { position: absolute; inset: 0; pointer-events: none; }
.sparkle {
  position: absolute;
  color: rgba(255,255,255,.76);
  animation: float 4s ease-in-out infinite;
}
.sparkle:nth-child(1) { top: 18%; right: 24%; font-size: 25px; }
.sparkle:nth-child(2) { top: 62%; right: 12%; font-size: 18px; animation-delay: -1.5s; }
.sparkle:nth-child(3) { top: 29%; right: 8%; font-size: 32px; animation-delay: -2.5s; }

.hero-kicker, .eyebrow {
  margin: 0 0 10px;
  font-size: .78rem;
  font-weight: 800;
  letter-spacing: .04em;
}
.hero-kicker { color: #d7e4ff; }

.hero h1 {
  max-width: 680px;
  margin: 0;
  font-size: clamp(2.7rem, 8vw, 5rem);
  line-height: .98;
  letter-spacing: -.055em;
}

.hero-copy {
  max-width: 590px;
  margin: 20px 0 25px;
  color: #eff4ff;
  font-size: clamp(1rem, 2.4vw, 1.18rem);
  line-height: 1.65;
}

.hero-actions, .toolbar, .button-row, .progress-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
}

.button, .icon-button, .back-button {
  display: inline-flex;
  min-height: 48px;
  align-items: center;
  justify-content: center;
  gap: 9px;
  padding: 12px 19px;
  border: 0;
  border-radius: 15px;
  font-weight: 800;
  cursor: pointer;
  transition: transform .18s ease, box-shadow .18s ease, background .18s ease;
}
.button:hover, .icon-button:hover, .back-button:hover { transform: translateY(-2px); }
.button:active, .icon-button:active, .back-button:active { transform: translateY(0); }
.button-primary { color: #263c8d; background: var(--gold); box-shadow: 0 8px 18px rgba(18, 30, 82, .18); }
.button-secondary { color: white; border: 1px solid rgba(255,255,255,.42); background: rgba(255,255,255,.12); }
.button-dark { color: white; background: var(--blue); box-shadow: 0 8px 18px rgba(49,86,201,.2); }
.button-quiet { color: #3c4d83; background: #edf1ff; }
.button:disabled { opacity: .48; cursor: not-allowed; transform: none; }

.map-section { padding-top: clamp(30px, 5vw, 54px); }
.section-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}
.section-heading h2 { margin: 0; font-size: clamp(1.65rem, 4vw, 2.3rem); letter-spacing: -.035em; }
.section-heading p { max-width: 490px; margin: 0; color: var(--muted); line-height: 1.6; }

.pack-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 15px;
}

.pack-card {
  position: relative;
  display: flex;
  min-height: 190px;
  flex-direction: column;
  align-items: flex-start;
  padding: 20px;
  border: 1px solid #e4e9fb;
  border-radius: 22px;
  text-align: left;
  color: var(--ink);
  background: var(--card);
  box-shadow: 0 9px 28px rgba(37,57,118,.06);
  cursor: pointer;
  transition: transform .2s ease, border-color .2s ease, box-shadow .2s ease;
}
.pack-card:hover { transform: translateY(-5px); border-color: #b6c4ff; box-shadow: var(--shadow); }
.pack-card:disabled { opacity: .65; cursor: wait; transform: none; }
.pack-icon { display: grid; width: 47px; height: 47px; place-items: center; margin-bottom: 16px; border-radius: 15px; font-size: 25px; background: var(--pack-tint, #e6ecff); }
.pack-title { margin: 0; font-size: 1.04rem; line-height: 1.3; font-weight: 900; }
.pack-description { margin: 7px 0 14px; color: var(--muted); font-size: .88rem; line-height: 1.45; }
.pack-coverage { margin: -3px 0 14px; color: #53628a; font-size: .78rem; line-height: 1.5; }
.pack-coverage strong { color: #3b4a75; }
.pack-meta { display: flex; width: 100%; justify-content: space-between; gap: 10px; margin-top: auto; color: #53628a; font-size: .77rem; font-weight: 800; }
.pack-progress { color: #5b42c2; }

.topic-picker { max-width: 1000px; margin: 0 auto; }
.topic-picker > .back-button { margin-bottom: 20px; }
.topic-picker-header, .topic-index {
  padding: clamp(20px, 4vw, 32px);
  border: 1px solid #e4e9fb;
  border-radius: 24px;
  background: var(--card);
  box-shadow: 0 9px 28px rgba(37,57,118,.06);
}
.topic-picker-header .eyebrow { color: #6b58c4; }
.topic-picker-header h1 { margin: 0 0 10px; font-size: clamp(1.8rem, 5vw, 2.5rem); }
.topic-picker-header > p:last-child { margin: 0; color: var(--muted); line-height: 1.6; }
.topic-section-title, .topic-index h2 { margin: 26px 0 14px; font-size: 1.2rem; }
.topic-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 220px), 1fr)); gap: 12px; }
.topic-card {
  display: flex;
  min-height: 84px;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  gap: 7px;
  padding: 16px;
  border: 1px solid #e1e7fa;
  border-radius: 18px;
  color: var(--ink);
  background: white;
  text-align: left;
  cursor: pointer;
  transition: transform .18s ease, border-color .18s ease, box-shadow .18s ease;
}
.topic-card:hover { transform: translateY(-2px); border-color: #b6c4ff; box-shadow: 0 9px 24px rgba(37,57,118,.1); }
.topic-card-title { font-weight: 900; line-height: 1.4; overflow-wrap: anywhere; }
.topic-card-count { color: var(--muted); font-size: .82rem; font-weight: 700; }
.topic-tags { display: flex; flex-wrap: wrap; gap: 8px; }
.topic-tag { padding: 7px 11px; border-radius: 999px; color: #3c4d83; background: #edf1ff; font-size: .84rem; line-height: 1.4; }
.topic-note { margin: 15px 0 0; color: var(--muted); line-height: 1.55; }
.topic-all-button { margin-top: 20px; }

.coach-card, .progress-card {
  border: 1px solid #e4e9fb;
  border-radius: 20px;
  background: rgba(255,255,255,.8);
}
.game-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 18px;
}
.back-button { color: #34446f; background: white; box-shadow: 0 6px 20px rgba(37,57,118,.08); }
.session-stats { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; color: #45557f; font-size: .9rem; font-weight: 800; }
.stat-pill { padding: 9px 13px; border: 1px solid #e4e9fb; border-radius: 999px; background: white; }
.progress-track { height: 9px; overflow: hidden; margin: 0 0 23px; border-radius: 999px; background: #e2e8fb; }
.progress-fill { width: 0; height: 100%; border-radius: inherit; background: linear-gradient(90deg, #29b890, #7684ef); transition: width .45s ease; }

.activity-card {
  overflow: hidden;
  border: 1px solid #e4e9fb;
  border-radius: 28px;
  background: var(--card);
  box-shadow: var(--shadow);
  animation: rise-in .35s ease both;
}
.activity-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 22px clamp(20px, 4vw, 34px);
  color: white;
  background: linear-gradient(110deg, #284ab1, #7049d1);
}
.activity-banner > div { min-width: 0; }
.activity-banner h1 { margin: 0; font-size: clamp(1.18rem, 3vw, 1.65rem); overflow-wrap: anywhere; }
.activity-banner p { margin: 5px 0 0; color: #e2e9ff; font-size: .9rem; }
.mascot { flex: 0 0 auto; display: grid; width: 62px; height: 62px; place-items: center; border: 2px solid rgba(255,255,255,.45); border-radius: 20px; background: rgba(255,255,255,.14); font-size: 34px; animation: float 3s ease-in-out infinite; }
.activity-body { padding: clamp(20px, 4vw, 36px); }
.topic-chip { display: inline-block; max-width: 100%; margin: 0 0 10px; padding: 6px 11px; border-radius: 999px; color: #4d3bb2; background: #f0edff; font-size: .8rem; font-weight: 800; line-height: 1.45; overflow-wrap: anywhere; }
.question-label { margin: 0 0 8px; color: #6b58c4; font-size: .82rem; font-weight: 900; letter-spacing: .02em; }
.question { margin: 0 0 24px; color: #172554; font-size: clamp(1.25rem, 3.2vw, 1.85rem); line-height: 1.45; letter-spacing: -.025em; }
.task-instruction { margin: -10px 0 20px; color: var(--muted); line-height: 1.5; }

.tile-bank, .sentence-tray, .repair-row, .proof-slots {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}
.tile-bank { min-height: 70px; padding: 14px; border: 1px dashed #b6c4e7; border-radius: 18px; background: #f7f8ff; }
.word-tile, .phrase-tile, .placed-tile {
  max-width: 100%;
  min-height: 45px;
  padding: 10px 15px;
  border: 1px solid #d5defa;
  border-radius: 14px;
  color: #293d81;
  background: white;
  box-shadow: 0 4px 11px rgba(49,70,165,.08);
  font-weight: 800;
  cursor: grab;
  user-select: none;
  touch-action: manipulation;
  transition: transform .16s ease, background .16s ease, opacity .16s ease;
  overflow-wrap: anywhere;
  white-space: normal;
}
.word-tile:hover, .phrase-tile:hover { transform: translateY(-2px) rotate(-1deg); background: #eff3ff; }
.word-tile:active, .phrase-tile:active { cursor: grabbing; }
.word-tile.is-used, .phrase-tile.is-used { display: none; }
.word-tile.is-selected, .phrase-tile.is-selected { border-color: #7550d9; box-shadow: 0 0 0 3px rgba(117,80,217,.16); }
.sentence-tray, .proof-slots { min-height: 72px; margin: 15px 0; padding: 13px; border: 2px dashed #a9b5df; border-radius: 18px; background: #fbfcff; }
.sentence-tray.is-over, .drop-zone.is-over { border-color: #7251db; background: #f0edff; }
.sentence-tray:empty::before { content: "Your sentence will take shape here…"; color: #8290b5; font-size: .92rem; }
.placed-tile { display: inline-flex; align-items: center; gap: 6px; min-height: 38px; padding: 7px 10px; border: 0; color: #234a3d; background: var(--mint); cursor: pointer; }
.placed-tile::after { content: "×"; color: #4a7565; font-size: 1.05rem; }

.drop-zone {
  display: flex;
  width: 100%;
  min-height: 94px;
  align-items: center;
  justify-content: center;
  padding: 18px;
  border: 2px dashed #a9b5df;
  border-radius: 18px;
  color: #7a88ad;
  background: #fbfcff;
  font-size: 1.05rem;
  font-weight: 700;
  text-align: center;
  cursor: pointer;
  transition: background .16s ease, border-color .16s ease;
}
.drop-zone.has-answer { border-style: solid; border-color: #8fd9bc; color: #245c48; background: #edfbf5; }
.drop-zone .answer-value { color: #234a3d; font-size: 1.15rem; }

.proof-story {
  margin: 16px 0 22px;
  padding: 20px;
  border: 1px solid #e1e7fa;
  border-radius: 18px;
  color: #26365d;
  background: #f8f9ff;
  font-size: 1.08rem;
  line-height: 1.85;
}
.proof-error { padding: 1px 3px; border-radius: 4px; color: #8b3c58; background: #ffe2e9; text-decoration: underline wavy #ef7091; text-decoration-thickness: 1px; }
.proof-slot { display: grid; min-width: min(100%, 220px); flex: 1 1 220px; gap: 8px; padding: 13px; border: 1px dashed #b6c4e7; border-radius: 16px; background: white; }
.proof-slot-label { color: #657398; font-size: .8rem; font-weight: 800; }
.proof-slot .drop-zone { min-height: 62px; padding: 10px; font-size: .9rem; }
.proof-slot .drop-zone.has-answer .answer-value { font-size: .98rem; }

.coach-card { margin-top: 20px; padding: 17px 19px; color: #445477; line-height: 1.55; }
.coach-card summary { color: #4d3bb2; font-weight: 900; cursor: pointer; }
.coach-card p { margin: 10px 0 0; }
.feedback-card { margin-top: 20px; padding: 18px 20px; border-radius: 18px; line-height: 1.6; animation: rise-in .25s ease both; }
.feedback-card.success { border: 1px solid #a7e6cb; color: #245c48; background: #eafbf3; }
.feedback-card.try-again { border: 1px solid #f5d490; color: #715119; background: #fff8e6; }
.feedback-card strong { display: block; margin-bottom: 4px; font-size: 1.08rem; }
.feedback-card p { margin: 0; }
.feedback-card .corrected-story { margin-top: 12px; padding-top: 12px; border-top: 1px solid rgba(36,92,72,.18); }
.activity-footer { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 12px; margin-top: 22px; }
.text-button { padding: 10px 4px; border: 0; color: #52628b; background: transparent; font-weight: 800; cursor: pointer; }
.text-button:hover { color: #4d3bb2; text-decoration: underline; }

.error-card { max-width: 680px; margin: 12vh auto; padding: 30px; border: 1px solid #f2c8ce; border-radius: 24px; background: white; box-shadow: var(--shadow); }
.error-card h1 { color: #8b3147; }
.error-card p { color: #5f6473; line-height: 1.6; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

@keyframes float { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-9px); } }
@keyframes rise-in { from { opacity: 0; transform: translateY(9px); } to { opacity: 1; transform: translateY(0); } }

@media (max-width: 850px) {
  .pack-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .section-heading { align-items: flex-start; flex-direction: column; }
}

@media (max-width: 560px) {
  .app-shell { padding: 14px; }
  .hero { min-height: 0; padding: 27px 22px; border-radius: 25px; }
  .hero h1 { font-size: clamp(2.45rem, 15vw, 3.7rem); }
  .hero-copy { margin-top: 14px; }
  .hero-actions { align-items: stretch; flex-direction: column; }
  .hero-actions .button { width: 100%; }
  .pack-grid { grid-template-columns: 1fr; gap: 11px; }
  .pack-card { min-height: 0; padding: 16px; }
  .pack-icon { width: 40px; height: 40px; margin-bottom: 10px; font-size: 22px; }
  .pack-description { margin: 5px 0 10px; }
  .pack-coverage { margin-bottom: 12px; }
  .topic-picker > .back-button { width: 100%; }
  .topic-all-button { width: 100%; }
  .game-header { align-items: flex-start; flex-direction: column; }
  .session-stats { width: 100%; }
  .activity-banner { padding: 17px 18px; }
  .mascot { width: 50px; height: 50px; border-radius: 16px; font-size: 27px; }
  .activity-body { padding: 20px 16px; }
  .question { margin-bottom: 20px; }
  .word-tile, .phrase-tile { min-height: 44px; padding: 9px 12px; }
  .proof-story { padding: 15px; font-size: 1rem; }
  .activity-footer { align-items: stretch; flex-direction: column-reverse; }
  .activity-footer .button { width: 100%; }
}

@media (pointer: coarse) {
  .word-tile, .phrase-tile, .placed-tile { min-height: 48px; cursor: pointer; }
}

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