:root {
  --ink: #172033;
  --muted: #667085;
  --purple: #5f4bf5;
  --purple-dark: #4432ca;
  --mint: #c9f7df;
  --coral: #ff7864;
  --yellow: #ffd65a;
  --cream: #fffaf0;
  --white: #ffffff;
  --green: #1d9a63;
  --red: #d94252;
  --shadow: 0 18px 50px rgba(46, 37, 117, 0.14);
  --radius-xl: 30px;
  --radius-lg: 22px;
  --radius-md: 16px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html { min-height: 100%; background: #f4f1ff; }

body {
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 8% 12%, rgba(255, 214, 90, 0.24), transparent 24rem),
    radial-gradient(circle at 95% 80%, rgba(201, 247, 223, 0.7), transparent 26rem),
    linear-gradient(155deg, #f7f4ff 0%, #fffdf8 55%, #f2fffa 100%);
  font-family: "DM Sans", system-ui, sans-serif;
  overflow-x: hidden;
}

button, input { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }

.ambient {
  position: fixed;
  z-index: 0;
  border-radius: 999px;
  filter: blur(2px);
  opacity: 0.6;
  pointer-events: none;
}
.ambient-one { width: 170px; height: 170px; top: -65px; right: -40px; background: #d8d1ff; }
.ambient-two { width: 140px; height: 140px; bottom: 6%; left: -75px; background: #ffe7a2; }

.app-shell {
  position: relative;
  z-index: 1;
  width: min(100% - 28px, 720px);
  margin: 0 auto;
  padding: max(20px, env(safe-area-inset-top)) 0 max(32px, env(safe-area-inset-bottom));
}

.brand { display: flex; align-items: center; gap: 12px; margin: 0 4px 22px; }
.brand-mark { display: grid; place-items: center; width: 52px; height: 52px; border-radius: 17px; background: var(--white); box-shadow: 0 8px 24px rgba(55, 43, 133, 0.12); font-size: 29px; transform: rotate(-5deg); }
.brand h1 { margin: -2px 0 0; font-family: "Fredoka", sans-serif; font-size: clamp(1.65rem, 6vw, 2.05rem); line-height: 1; letter-spacing: -0.03em; }
.eyebrow { margin: 0 0 4px; color: var(--purple); font-size: 0.7rem; font-weight: 800; letter-spacing: 0.14em; }
.icon-button { margin-left: auto; width: 48px; height: 48px; border: 0; border-radius: 50%; background: rgba(255,255,255,.78); cursor: pointer; font-size: 20px; box-shadow: 0 8px 20px rgba(55,43,133,.08); }
.icon-button:focus-visible, button:focus-visible, input:focus-visible { outline: 4px solid rgba(95,75,245,.25); outline-offset: 3px; }

.screen { display: none; animation: rise .45s ease both; }
.screen.is-active { display: block; }
@keyframes rise { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }

.hero-card { overflow: hidden; position: relative; border-radius: var(--radius-xl); background: var(--purple); color: white; box-shadow: var(--shadow); }
.hero-visual { position: relative; display: grid; place-items: center; height: 225px; background: radial-gradient(circle, rgba(255,255,255,.16) 0 28%, transparent 29%), linear-gradient(135deg,#705dff,#4938dc); }
.hero-visual::before, .hero-visual::after { content: ""; position: absolute; border: 1px dashed rgba(255,255,255,.28); border-radius: 50%; }
.hero-visual::before { width: 240px; height: 110px; transform: rotate(-13deg); }
.hero-visual::after { width: 145px; height: 205px; transform: rotate(25deg); }
.globe { z-index: 2; font-size: 104px; filter: drop-shadow(0 16px 18px rgba(27,18,93,.25)); animation: float 3.4s ease-in-out infinite; }
@keyframes float { 50% { transform: translateY(-8px) rotate(2deg); } }
.floating-flag { position: absolute; z-index: 3; display: grid; place-items: center; width: 52px; height: 52px; border-radius: 15px; background: white; font-size: 27px; box-shadow: 0 10px 25px rgba(20,12,85,.25); }
.flag-a { left: 12%; top: 22%; transform: rotate(-8deg); }
.flag-b { right: 12%; top: 18%; transform: rotate(7deg); }
.flag-c { right: 18%; bottom: 10%; transform: rotate(-4deg); }
.passport-stamp { position: absolute; z-index: 4; left: 16%; bottom: 10%; display: grid; place-items: center; width: 64px; height: 64px; border: 2px solid rgba(255,255,255,.7); border-radius: 50%; text-align: center; font-size: 19px; font-weight: 800; line-height: .9; transform: rotate(-10deg); }
.passport-stamp small { font-size: 8px; letter-spacing: .12em; }
.hero-copy { padding: 25px 25px 28px; }
.pill { display: inline-flex; padding: 7px 11px; border-radius: 999px; color: #3e2fae; background: var(--yellow); font-size: .78rem; font-weight: 800; }
.hero-copy h2 { margin: 16px 0 10px; font-family: "Fredoka", sans-serif; font-size: clamp(1.85rem, 7.5vw, 2.7rem); line-height: 1.04; letter-spacing: -.025em; }
.hero-copy p { margin: 0; color: rgba(255,255,255,.82); font-size: 1rem; line-height: 1.55; }

.start-panel, .history-panel, .question-card, .result-card { margin-top: 16px; padding: 22px; border: 1px solid rgba(255,255,255,.9); border-radius: var(--radius-xl); background: rgba(255,255,255,.88); box-shadow: var(--shadow); backdrop-filter: blur(12px); }
.start-panel label { display: block; margin-bottom: 9px; font-size: .95rem; font-weight: 800; }
.name-row { position: relative; }
.name-row input { width: 100%; height: 58px; padding: 0 52px 0 17px; border: 2px solid #e4e0f4; border-radius: var(--radius-md); color: var(--ink); background: #fff; font-size: 1rem; transition: .2s; }
.name-row input:focus { border-color: var(--purple); outline: 0; box-shadow: 0 0 0 4px rgba(95,75,245,.1); }
.input-spark { position: absolute; right: 17px; top: 50%; transform: translateY(-50%); }
.field-error { min-height: 20px; margin: 6px 2px; color: var(--red); font-size: .82rem; font-weight: 700; }
.primary-button, .secondary-button, .danger-button { min-height: 56px; border: 0; border-radius: var(--radius-md); padding: 14px 18px; cursor: pointer; font-weight: 800; transition: transform .15s, box-shadow .15s, background .15s; }
.primary-button { width: 100%; display: flex; align-items: center; justify-content: center; gap: 10px; color: white; background: linear-gradient(135deg, var(--purple), var(--purple-dark)); box-shadow: 0 11px 24px rgba(95,75,245,.27); }
.primary-button:hover { transform: translateY(-2px); box-shadow: 0 14px 29px rgba(95,75,245,.34); }
.primary-button:active, .secondary-button:active { transform: translateY(1px); }
.secondary-button { color: var(--purple-dark); background: #eeeaff; }
.danger-button { color: white; background: var(--red); }

.section-heading { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 14px; }
.section-heading h3 { margin: 0; font-family: "Fredoka", sans-serif; font-size: 1.35rem; }
.best-badge { flex: none; padding: 7px 10px; border-radius: 999px; background: #fff4c7; color: #705315; font-size: .75rem; font-weight: 800; }
.history-list { display: grid; gap: 9px; }
.history-item { display: grid; grid-template-columns: 46px 1fr auto; align-items: center; gap: 11px; padding: 11px; border-radius: 15px; background: #f7f5ff; }
.history-icon { display: grid; place-items: center; width: 42px; height: 42px; border-radius: 13px; background: white; font-size: 21px; }
.history-item strong, .history-item span { display: block; }
.history-item strong { font-size: .9rem; }
.history-item span { color: var(--muted); font-size: .74rem; margin-top: 2px; }
.history-score { color: var(--purple); font-family: "Fredoka", sans-serif; font-size: 1.1rem; font-weight: 700; }

.quiz-topline, .progress-meta { display: flex; justify-content: space-between; align-items: center; }
.text-button { border: 0; padding: 10px 4px; color: var(--muted); background: transparent; cursor: pointer; font-size: .9rem; font-weight: 700; }
.score-chip { padding: 9px 13px; border-radius: 999px; background: white; font-weight: 800; box-shadow: 0 8px 20px rgba(55,43,133,.08); }
.progress-meta { margin: 15px 2px 8px; color: var(--muted); font-size: .82rem; font-weight: 700; }
.progress-track { overflow: hidden; height: 10px; border-radius: 999px; background: #e7e3f6; }
.progress-fill { width: 5%; height: 100%; border-radius: inherit; background: linear-gradient(90deg,var(--purple),#9a85ff); transition: width .35s ease; }

.question-card { margin-top: 18px; padding: 22px 18px 20px; text-align: center; }
.category-badge { display: inline-flex; align-items: center; padding: 7px 11px; border-radius: 999px; color: var(--purple-dark); background: #eeeaff; font-size: .76rem; font-weight: 800; }
.question-visual { min-height: 90px; display: grid; place-items: center; margin: 12px 0 3px; font-size: clamp(4.7rem, 20vw, 6.8rem); line-height: 1; filter: drop-shadow(0 10px 14px rgba(26,21,67,.12)); }
.question-visual.is-icon { font-size: 4.2rem; }
.question-card h2 { max-width: 530px; margin: 8px auto 22px; font-family: "Fredoka", sans-serif; font-size: clamp(1.55rem, 6vw, 2.15rem); line-height: 1.14; letter-spacing: -.02em; }
.answers { display: grid; gap: 11px; }
.answer-button { position: relative; min-height: 62px; width: 100%; border: 2px solid #e7e3f2; border-radius: 17px; padding: 12px 46px 12px 17px; color: var(--ink); background: white; cursor: pointer; text-align: left; font-weight: 800; transition: .15s ease; }
.answer-button::after { content: attr(data-letter); position: absolute; right: 15px; top: 50%; display: grid; place-items: center; width: 29px; height: 29px; border-radius: 9px; color: var(--muted); background: #f2eff8; transform: translateY(-50%); font-size: .78rem; }
.answer-button:hover:not(:disabled) { border-color: #b8adff; transform: translateY(-1px); }
.answer-button.correct { border-color: #6bd3a1; color: #11784b; background: #ebfff5; }
.answer-button.correct::after { content: "✓"; color: white; background: var(--green); }
.answer-button.wrong { border-color: #f3a7af; color: #a72d3a; background: #fff0f2; }
.answer-button.wrong::after { content: "×"; color: white; background: var(--red); }
.answer-button:disabled { cursor: default; }
.feedback { min-height: 0; margin-top: 0; font-weight: 800; transition: .2s; }
.feedback.visible { min-height: 25px; margin-top: 17px; }
.feedback.good { color: var(--green); }
.feedback.bad { color: var(--red); }
.next-button { margin-top: 14px; }

.result-card { text-align: center; padding: 28px 20px 22px; }
.result-emoji { font-size: 76px; animation: celebrate .7s cubic-bezier(.2,.8,.25,1.25) both; }
@keyframes celebrate { 0% { transform: scale(.3) rotate(-16deg); opacity: 0; } 70% { transform: scale(1.14) rotate(5deg); } }
.result-card h2 { margin: 8px 0; font-family: "Fredoka",sans-serif; font-size: clamp(2rem, 8vw, 3rem); }
.result-message { max-width: 470px; margin: 0 auto; color: var(--muted); line-height: 1.55; }
.score-ring { display: grid; place-items: center; width: 178px; height: 178px; margin: 23px auto; border-radius: 50%; background: conic-gradient(var(--purple) var(--score-angle,0deg), #e8e4f7 0); box-shadow: inset 0 0 0 12px white, 0 14px 30px rgba(54,42,143,.16); }
.score-ring > div { display: grid; place-items: center; width: 130px; height: 130px; border-radius: 50%; background: white; }
.score-ring strong { color: var(--purple); font-family: "Fredoka",sans-serif; font-size: 3.5rem; line-height: .9; }
.score-ring span { margin-top: 7px; color: var(--muted); font-size: .8rem; font-weight: 700; }
.category-results { display: grid; grid-template-columns: repeat(3,1fr); gap: 8px; margin: 4px 0 20px; }
.category-result { padding: 13px 7px; border-radius: 15px; background: #f7f5ff; }
.category-result span { display: block; font-size: 1.35rem; }
.category-result strong { display: block; margin: 4px 0 1px; font-size: .84rem; }
.category-result small { color: var(--muted); font-size: .71rem; }
.result-actions { display: grid; gap: 10px; }
.result-actions .secondary-button { width: 100%; }

.confirm-dialog { width: min(90%, 430px); border: 0; border-radius: 26px; padding: 0; color: var(--ink); box-shadow: 0 30px 90px rgba(25,18,77,.35); }
.confirm-dialog::backdrop { background: rgba(20,16,47,.55); backdrop-filter: blur(4px); }
.confirm-dialog form { padding: 27px; text-align: center; }
.dialog-emoji { font-size: 48px; }
.confirm-dialog h2 { margin: 8px 0; font-family: "Fredoka",sans-serif; }
.confirm-dialog p { margin: 0 0 20px; color: var(--muted); }
.dialog-actions { display: grid; gap: 9px; }

.confetti { position: fixed; inset: 0; z-index: 10; overflow: hidden; pointer-events: none; }
.confetti-piece { position: absolute; top: -20px; width: 10px; height: 17px; border-radius: 3px; animation: fall var(--duration) linear forwards; }
@keyframes fall { to { transform: translate3d(var(--drift),110vh,0) rotate(780deg); } }

@media (min-width: 620px) {
  .app-shell { padding-top: 32px; }
  .hero-card { display: grid; grid-template-columns: .9fr 1.1fr; min-height: 310px; }
  .hero-visual { height: 100%; }
  .hero-copy { display: flex; flex-direction: column; justify-content: center; padding: 36px; }
  .start-panel, .history-panel, .question-card, .result-card { padding: 28px; }
  .answers { gap: 13px; }
}

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