:root {
  color-scheme: light;
  font-family: ui-rounded, "SF Pro Rounded", system-ui, -apple-system, sans-serif;
  --ink: #1a263f;
  --secondary-ink: #596b89;
  --purple: #625cef;
  --violet: #942be8;
  --panel: rgba(255, 255, 255, 0.96);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 300px;
  min-height: 100vh;
  min-height: 100svh;
  color: var(--ink);
  background: linear-gradient(135deg, #29b8ed, #7878f2 52%, #9742e8);
}

button { font: inherit; }

.screen {
  width: 100%;
  min-height: 100vh;
  min-height: 100svh;
}

.setup-shell {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: min(760px, 100%);
  min-height: 100svh;
  margin: auto;
  padding: max(8px, env(safe-area-inset-top)) 14px max(8px, env(safe-area-inset-bottom));
}

.brand-row {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  padding: 0 44px;
  color: white;
  font-size: clamp(1.35rem, 7vw, 2rem);
  font-weight: 900;
  white-space: nowrap;
  text-shadow: 0 3px 6px rgba(48, 46, 125, 0.22);
}

.brand-row .bolt { margin-right: 7px; }
.brand-row .quest { color: #ffda38; }

.icon-button {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 50%;
  color: white;
  background: rgba(255, 255, 255, 0.18);
  cursor: pointer;
}

.progress-button { position: absolute; right: 0; }

.setup-panel {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 12px;
  padding: 14px;
  border-radius: 28px;
  background: var(--panel);
  box-shadow: 0 12px 28px rgba(54, 53, 135, 0.2);
}

.hero {
  display: flex;
  align-items: center;
  gap: 12px;
  padding-bottom: 5px;
}

.rocket {
  display: grid;
  flex: 0 0 48px;
  place-items: center;
  width: 48px;
  height: 48px;
  border-radius: 14px;
  color: white;
  font-size: 1.8rem;
  background: linear-gradient(135deg, var(--purple), var(--violet));
  box-shadow: 0 5px 10px rgba(60, 53, 150, 0.25);
}

.hero h1 {
  overflow: hidden;
  margin: 0;
  font-size: clamp(1rem, 5.2vw, 1.25rem);
  font-weight: 900;
  white-space: nowrap;
}

.hero p {
  overflow: hidden;
  margin: 2px 0 0;
  color: var(--secondary-ink);
  font-size: 0.78rem;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.section-title {
  margin: 0 0 7px;
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.025em;
}

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

.topic-card {
  display: flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
  height: 52px;
  padding: 7px;
  border: 1.5px solid rgba(90, 100, 120, 0.22);
  border-radius: 15px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.5);
  cursor: pointer;
}

.topic-card.selected {
  border: 2px solid var(--purple);
  background: rgba(98, 92, 239, 0.08);
}

.topic-icon {
  display: grid;
  flex: 0 0 34px;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 10px;
  color: white;
  font-size: 1rem;
  font-weight: 900;
}

.topic-name {
  overflow: hidden;
  font-size: 0.75rem;
  font-weight: 800;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.bottom-controls { margin-top: auto; }

.legal-links {
  display: flex;
  justify-content: center;
  gap: 8px;
  color: var(--secondary-ink);
  font-size: 0.72rem;
}
.legal-links a { color: var(--purple); font-weight: 800; text-decoration: none; }

.legal-page { min-height: 100svh; padding: 24px 14px; background: #f4f6ff; }
.legal-card { width: min(720px, 100%); margin: auto; padding: clamp(20px, 5vw, 38px); border-radius: 24px; background: white; box-shadow: 0 8px 24px rgba(58, 64, 120, 0.12); }
.legal-card h1 { margin-top: 0; }
.legal-card h2 { margin-top: 1.5em; font-size: 1.15rem; }
.legal-card p, .legal-card li { color: var(--secondary-ink); line-height: 1.6; }
.legal-card a { color: var(--purple); font-weight: 700; }
.legal-card .back-link { display: inline-block; margin-bottom: 18px; text-decoration: none; }

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

.difficulty-card {
  height: 52px;
  border: 1.5px solid rgba(90, 100, 120, 0.22);
  border-radius: 15px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.5);
  cursor: pointer;
}

.difficulty-card.selected {
  border: 2px solid var(--purple);
  background: rgba(98, 92, 239, 0.08);
}

.difficulty-card strong,
.difficulty-card small { display: block; }
.difficulty-card strong { font-size: 0.86rem; }
.difficulty-card small { margin-top: 2px; color: var(--secondary-ink); font-size: 0.64rem; }

.primary-button {
  width: 100%;
  height: 52px;
  margin-top: 10px;
  border: 0;
  border-radius: 16px;
  color: white;
  font-size: 1.05rem;
  font-weight: 800;
  background: linear-gradient(90deg, var(--purple), var(--violet));
  box-shadow: 0 7px 14px rgba(98, 92, 239, 0.28);
  cursor: pointer;
}

.quest-shell {
  display: flex;
  flex-direction: column;
  width: min(620px, 100%);
  min-height: 100svh;
  margin: auto;
  padding: max(12px, env(safe-area-inset-top)) 16px max(12px, env(safe-area-inset-bottom));
}

.quest-header { display: flex; align-items: center; justify-content: space-between; }
.score { color: white; font-weight: 800; }

.question-card {
  margin: auto 0;
  padding: 24px;
  border-radius: 28px;
  background: var(--panel);
  box-shadow: 0 12px 25px rgba(54, 53, 135, 0.24);
}

.question-meta { display: flex; align-items: center; justify-content: space-between; gap: 10px; color: var(--secondary-ink); font-size: 0.8rem; font-weight: 800; }
.question-meta span:first-child { color: var(--purple); }
#question-timer { margin-left: auto; font-variant-numeric: tabular-nums; }

.progress-track { height: 5px; margin-top: 18px; overflow: hidden; border-radius: 4px; background: #e2e3ee; }
.progress-fill { height: 100%; border-radius: inherit; background: var(--purple); transition: width 180ms ease; }

.prompt {
  min-height: 100px;
  display: grid;
  place-items: center;
  margin: 10px 0;
  font-size: clamp(1.65rem, 8vw, 2.5rem);
  font-weight: 900;
  text-align: center;
}
.prompt.with-diagram { min-height: 48px; margin-bottom: 0; font-size: clamp(1.3rem, 5vw, 1.65rem); }
.area-diagram { height: 130px; margin-bottom: 8px; }
.area-diagram svg { display: block; width: 100%; height: 100%; overflow: visible; }
.area-diagram .dimension-label { fill: var(--ink); font: 800 13px ui-rounded, "SF Pro Rounded", system-ui, sans-serif; paint-order: stroke; stroke: white; stroke-width: 5px; stroke-linejoin: round; }
.area-diagram .height-line { stroke: #e78b2f; stroke-width: 2; stroke-dasharray: 5 4; }

.answer-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.answer-button {
  height: 70px;
  border: 2px solid rgba(100, 105, 120, 0.2);
  border-radius: 17px;
  color: var(--ink);
  background: white;
  font-size: 1.4rem;
  font-weight: 800;
  cursor: pointer;
}
.answer-button.correct { border-color: #2da861; color: #21844b; background: #edf9f1; }
.answer-button.incorrect { border-color: #e34949; color: #c33232; background: #fff0f0; }
.answer-button:disabled { cursor: default; }

.next-slot { min-height: 65px; }
.next-slot .primary-button { opacity: 0; pointer-events: none; transition: opacity 180ms ease; }
.next-slot.visible .primary-button { opacity: 1; pointer-events: auto; }

.progress-screen { min-height: 100svh; padding: max(14px, env(safe-area-inset-top)) 14px max(14px, env(safe-area-inset-bottom)); background: #f4f6ff; }
.progress-page { width: min(700px, 100%); margin: auto; }
.progress-nav { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.progress-nav h1 { margin: 0; font-size: 1.35rem; }
.text-button { border: 0; color: var(--purple); background: transparent; font-weight: 800; cursor: pointer; }
.progress-card { margin-bottom: 14px; padding: 18px; border-radius: 20px; background: white; box-shadow: 0 5px 13px rgba(58, 64, 120, 0.08); }
.summary-grid { display: grid; grid-template-columns: repeat(3, 1fr); text-align: center; }
.summary-grid > div + div { border-left: 1px solid #e2e3e9; }
.summary-value { display: block; color: var(--purple); font-size: 1.6rem; font-weight: 900; }
.summary-label { color: var(--secondary-ink); font-size: 0.65rem; font-weight: 800; }
.progress-card h2 { margin: 0 0 4px; font-size: 1.1rem; }
.section-subtitle { margin: 0 0 10px; color: var(--secondary-ink); font-size: 0.75rem; }
.skill-row { display: flex; gap: 8px; padding: 6px 0; }
.skill-row strong { flex: 1; }
.attempt { padding: 10px 0; border-bottom: 1px solid #e8e9ef; }
.attempt:last-child { border-bottom: 0; }
.attempt-top { display: flex; justify-content: space-between; color: var(--purple); font-size: 0.75rem; font-weight: 800; }
.attempt-prompt { margin: 6px 0; font-weight: 800; }
.attempt-detail, .empty-copy { color: var(--secondary-ink); font-size: 0.8rem; }
.wrong { color: #c33232; }

@media (min-width: 600px) and (min-height: 900px) {
  .setup-panel { gap: 18px; padding: 20px; }
  .hero { flex-direction: column; text-align: center; }
  .rocket { width: 72px; height: 72px; flex-basis: 72px; border-radius: 20px; font-size: 2.6rem; }
  .hero h1 { font-size: 1.7rem; }
  .hero p { font-size: 1rem; }
  .topic-grid { gap: 10px; }
  .topic-card { height: 68px; padding: 10px; }
  .topic-icon { width: 42px; height: 42px; flex-basis: 42px; }
  .topic-name { font-size: 0.94rem; }
  .difficulty-card { height: 62px; }
  .primary-button { height: 58px; }
}

@media (max-height: 650px) {
  .setup-shell { overflow-y: auto; }
  .setup-panel { flex: none; }
}
