:root {
  --ink: #17213b;
  --muted: #6f7890;
  --line: #e5e9f3;
  --blue: #3156d8;
  --blue-dark: #2445bd;
  --blue-pale: #edf2ff;
  --orange: #ff8b52;
  --green: #22a873;
  --green-pale: #e9f9f2;
  --red: #e65c65;
  --red-pale: #fff0f1;
  font-family: Inter, ui-rounded, "SF Pro Rounded", "Segoe UI", sans-serif;
  color: var(--ink);
  background: #f8f9fd;
  font-synthesis: none;
}

* { box-sizing: border-box; }

html { min-width: 320px; min-height: 100%; }

body {
  min-height: 100vh;
  margin: 0;
  overflow-x: hidden;
  background:
    radial-gradient(circle at 5% 5%, rgba(85, 121, 233, 0.12), transparent 28%),
    radial-gradient(circle at 95% 85%, rgba(255, 163, 112, 0.14), transparent 25%),
    #f8f9fd;
}

button, select { font: inherit; }
button { color: inherit; }
button:not(:disabled) { cursor: pointer; }

button:focus-visible,
select:focus-visible,
a:focus-visible {
  outline: 3px solid rgba(49, 86, 216, 0.25);
  outline-offset: 3px;
}

.page-glow {
  position: fixed;
  z-index: -1;
  width: 420px;
  height: 420px;
  border-radius: 50%;
  filter: blur(85px);
  opacity: 0.16;
  pointer-events: none;
}

.page-glow--blue { top: -220px; left: -150px; background: #5274e5; }
.page-glow--orange { right: -180px; bottom: -210px; background: #ff9e69; }

.app-header {
  display: flex;
  width: min(1180px, calc(100% - 40px));
  min-height: 82px;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin: 0 auto;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  font-size: 24px;
  font-weight: 850;
  letter-spacing: -1.2px;
  text-decoration: none;
}

.brand > span:last-child span { color: var(--blue); }

.brand-mark {
  display: grid;
  width: 39px;
  height: 39px;
  place-items: center;
  border-radius: 13px;
  color: white;
  background: linear-gradient(145deg, #4770ea, #294fcf);
  box-shadow: 0 9px 22px rgba(49, 86, 216, 0.28);
}

.brand-mark svg,
.new-set-button svg,
.random-topic-button svg,
.audio-button svg,
.next-button svg,
.generation-note svg {
  width: 20px;
  height: 20px;
  fill: currentColor;
}

.header-tools,
.topic-picker,
.count-picker,
.source-chip,
.random-topic-button,
.new-set-button {
  display: flex;
  align-items: center;
}

.header-tools { gap: 10px; }

.source-chip {
  gap: 7px;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 99px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.8);
  font-size: 11px;
  font-weight: 700;
}

.source-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--blue);
  box-shadow: 0 0 0 4px rgba(49, 86, 216, 0.09);
}

.source-chip.is-demo .source-dot { background: var(--orange); box-shadow: 0 0 0 4px rgba(255, 139, 82, 0.1); }
.source-chip.is-error .source-dot { background: var(--red); box-shadow: 0 0 0 4px rgba(230, 92, 101, 0.1); }

.topic-picker,
.count-picker {
  gap: 9px;
  padding: 5px 6px 5px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.8);
  font-size: 11px;
  font-weight: 700;
}

.topic-picker select,
.count-picker select {
  padding: 7px 27px 7px 9px;
  border: 0;
  border-radius: 8px;
  color: var(--ink);
  background: var(--blue-pale);
  font-size: 12px;
  font-weight: 800;
}

.topic-picker select { max-width: 150px; }

.random-topic-button {
  gap: 7px;
  padding: 11px 14px;
  border: 0;
  border-radius: 12px;
  color: white;
  background: linear-gradient(145deg, #4770ea, #294fcf);
  box-shadow: 0 8px 18px rgba(49, 86, 216, 0.2);
  font-size: 12px;
  font-weight: 800;
}

.random-topic-button:not(:disabled):hover,
.new-set-button:not(:disabled):hover { transform: translateY(-2px); }

.new-set-button {
  gap: 7px;
  padding: 11px 14px;
  border: 0;
  border-radius: 12px;
  color: white;
  background: var(--ink);
  font-size: 12px;
  font-weight: 800;
}

.new-set-button svg,
.random-topic-button svg { width: 16px; height: 16px; }

.app-shell {
  width: min(1100px, calc(100% - 40px));
  margin: 12px auto 54px;
}

.lesson-card {
  position: relative;
  min-height: 720px;
  overflow: hidden;
  border: 1px solid rgba(225, 229, 241, 0.95);
  border-radius: 28px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 28px 80px rgba(38, 52, 97, 0.11);
  backdrop-filter: blur(12px);
}

.lesson-progress {
  padding: 24px 30px 20px;
  border-bottom: 1px solid var(--line);
}

.progress-copy {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  margin-bottom: 15px;
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--blue);
  font-size: 10px;
  font-weight: 850;
  letter-spacing: 1.7px;
}

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

h1 { margin-bottom: 0; font-size: 24px; line-height: 1.15; letter-spacing: -0.7px; }

.step-count {
  padding: 7px 11px;
  border-radius: 99px;
  color: var(--muted);
  background: #f3f5fa;
  font-size: 12px;
}

.step-count strong { color: var(--blue); }

.progress-track {
  height: 8px;
  overflow: hidden;
  border-radius: 99px;
  background: #edf0f6;
}

.progress-track span {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--blue), #6e8bef);
  box-shadow: 0 2px 10px rgba(49, 86, 216, 0.3);
  transition: width 0.45s ease;
}

.quiz-body { padding: 28px 30px 26px; }

.question-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 20px;
}

.question-number {
  display: inline-block;
  margin-bottom: 9px;
  color: var(--blue);
  font-size: 10px;
  font-weight: 850;
  letter-spacing: 1.2px;
}

.question-copy h2 {
  margin-bottom: 6px;
  font-size: clamp(22px, 3vw, 30px);
  line-height: 1.2;
  letter-spacing: -0.8px;
}

.question-copy p { margin-bottom: 0; color: var(--muted); font-size: 12px; }

.audio-controls { display: flex; flex: 0 0 auto; gap: 9px; }

.audio-button {
  display: flex;
  min-width: 145px;
  align-items: center;
  gap: 9px;
  padding: 11px 13px;
  border: 1px solid #dce2f2;
  border-radius: 14px;
  color: var(--blue);
  background: white;
  text-align: left;
  transition: transform 0.2s, box-shadow 0.2s, border-color 0.2s;
}

.audio-button:not(:disabled):hover { transform: translateY(-2px); border-color: #b8c5ee; box-shadow: 0 8px 20px rgba(49, 86, 216, 0.1); }
.audio-button--primary { color: white; border-color: var(--blue); background: linear-gradient(145deg, #4168e3, #2a50ce); box-shadow: 0 8px 20px rgba(49, 86, 216, 0.22); }
.audio-button.is-speaking svg { animation: speaker 0.65s ease-in-out infinite alternate; }

@keyframes speaker { to { transform: scale(1.17); } }

.audio-button > span { display: flex; flex-direction: column; }
.audio-button strong { font-size: 12px; }
.audio-button small { margin-top: 2px; color: currentColor; font-size: 9px; opacity: 0.68; }

.image-status {
  display: flex;
  min-height: 29px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-bottom: 12px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 650;
}

.image-status.is-ready .mini-spinner { display: none; }
.image-status.is-ready { color: var(--green); }
.image-status.is-warning { color: #b56b34; }

.mini-spinner,
.loader {
  display: inline-block;
  border: 2px solid #dfe5f5;
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.mini-spinner { width: 14px; height: 14px; }
.loader { width: 28px; height: 28px; border-width: 3px; }

@keyframes spin { to { transform: rotate(360deg); } }

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

.answer-card {
  position: relative;
  min-width: 0;
  padding: 7px;
  border: 2px solid transparent;
  border-radius: 19px;
  background: #f3f5fa;
  transition: transform 0.2s, border-color 0.2s, background 0.2s, box-shadow 0.2s;
}

.answer-card:not(:disabled):hover { transform: translateY(-3px); border-color: #b9c6ee; box-shadow: 0 12px 25px rgba(38, 52, 97, 0.09); }
.answer-card.is-selected { border-color: var(--blue); background: var(--blue-pale); box-shadow: 0 0 0 4px rgba(49, 86, 216, 0.08); }
.answer-card.is-correct { border-color: var(--green); background: var(--green-pale); box-shadow: 0 0 0 4px rgba(34, 168, 115, 0.08); }
.answer-card.is-wrong { border-color: var(--red); background: var(--red-pale); animation: shake 0.3s ease; }

@keyframes shake { 33% { transform: translateX(-5px); } 66% { transform: translateX(5px); } }

.image-frame {
  position: relative;
  display: block;
  overflow: hidden;
  aspect-ratio: 16 / 10;
  border-radius: 13px;
  background: #e9edf5;
}

.image-frame img { display: block; width: 100%; height: 100%; object-fit: cover; opacity: 0; transition: opacity 0.35s ease; }
.image-frame img.is-loaded { opacity: 1; }

.image-frame.is-local-3d {
  isolation: isolate;
  background: radial-gradient(circle at 50% 30%, #fff 0%, color-mix(in srgb, var(--option-color) 34%, white) 55%, var(--option-color) 100%);
}

.image-frame.is-local-3d::before {
  position: absolute;
  z-index: 0;
  right: 8%;
  bottom: 8%;
  left: 8%;
  height: 18%;
  border-radius: 50%;
  background: rgba(42, 57, 93, 0.13);
  filter: blur(13px);
  content: "";
}

.image-frame img.is-local-3d {
  position: relative;
  z-index: 1;
  padding: clamp(24px, 4.2vw, 44px) 13%;
  object-fit: contain;
  filter: drop-shadow(0 16px 12px rgba(38, 53, 88, 0.24));
  transform: scale(1.04);
}

.image-skeleton {
  position: absolute;
  inset: 0;
  background: linear-gradient(100deg, #e8ebf3 20%, #f6f7fb 38%, #e8ebf3 56%);
  background-size: 220% 100%;
  animation: shimmer 1.25s linear infinite;
}

.answer-card.is-ready .image-skeleton { display: none; }

@keyframes shimmer { to { background-position-x: -220%; } }

.answer-order {
  position: absolute;
  z-index: 2;
  top: 15px;
  left: 15px;
  display: grid;
  width: 28px;
  height: 28px;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.8);
  border-radius: 9px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.82);
  box-shadow: 0 4px 12px rgba(23, 33, 59, 0.12);
  backdrop-filter: blur(8px);
  font-size: 11px;
  font-weight: 850;
}

.answer-state {
  position: absolute;
  z-index: 2;
  right: 15px;
  bottom: 15px;
  display: none;
  width: 31px;
  height: 31px;
  place-items: center;
  border-radius: 50%;
  color: white;
  font-size: 17px;
  font-weight: 900;
}

.answer-card.is-correct .answer-state { display: grid; background: var(--green); }
.answer-card.is-correct .answer-state::before { content: "✓"; }
.answer-card.is-wrong .answer-state { display: grid; background: var(--red); }
.answer-card.is-wrong .answer-state::before { content: "×"; }

.feedback {
  margin-top: 14px;
  padding: 13px 15px;
  border: 1px solid #c7eadc;
  border-radius: 15px;
  background: var(--green-pale);
}

.feedback:not([hidden]) { display: flex; align-items: center; gap: 11px; animation: rise 0.3s ease; }
.feedback.is-wrong { border-color: #f0cbd0; background: var(--red-pale); }

@keyframes rise { from { opacity: 0; transform: translateY(7px); } }

.feedback-icon {
  display: grid;
  flex: 0 0 34px;
  width: 34px;
  height: 34px;
  place-items: center;
  border-radius: 50%;
  color: white;
  background: var(--green);
  font-weight: 900;
}

.feedback.is-wrong .feedback-icon { background: var(--red); }
.feedback strong { font-size: 13px; }
.feedback p { margin: 3px 0 0; color: var(--muted); font-size: 11px; line-height: 1.45; }

.quiz-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-top: 20px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.generation-note { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 10px; }
.generation-note svg { width: 16px; height: 16px; color: var(--blue); }
.footer-actions { display: flex; gap: 9px; }

.check-button,
.next-button {
  display: inline-flex;
  min-width: 145px;
  min-height: 44px;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 11px 20px;
  border: 0;
  border-radius: 13px;
  color: white;
  background: linear-gradient(145deg, #4168e3, #294fce);
  box-shadow: 0 9px 22px rgba(49, 86, 216, 0.23);
  font-size: 12px;
  font-weight: 850;
}

.check-button:disabled { color: #a7aec0; background: #edf0f5; box-shadow: none; cursor: not-allowed; }
.next-button[hidden] { display: none; }
.next-button svg { width: 17px; height: 17px; }

.loading-overlay {
  position: absolute;
  z-index: 10;
  inset: 0;
  display: grid;
  grid-template-columns: minmax(300px, 0.85fr) minmax(320px, 1.15fr);
  align-items: center;
  gap: 25px;
  padding: 48px;
  background: rgba(249, 250, 254, 0.97);
  backdrop-filter: blur(14px);
  transition: opacity 0.35s, visibility 0.35s;
}

.loading-overlay.is-hidden { opacity: 0; visibility: hidden; pointer-events: none; }
.loading-overlay img { width: 100%; max-width: 390px; justify-self: end; border-radius: 30px; box-shadow: 0 25px 60px rgba(38, 52, 97, 0.14); }
.loading-copy { max-width: 410px; }
.loading-copy .loader { margin-bottom: 20px; }
.loading-copy h2 { margin-bottom: 9px; font-size: 30px; line-height: 1.2; letter-spacing: -1px; }
.loading-copy > p:last-child { color: var(--muted); font-size: 13px; line-height: 1.65; }

.toast {
  position: fixed;
  z-index: 30;
  right: 22px;
  bottom: 22px;
  max-width: min(390px, calc(100% - 32px));
  padding: 12px 16px;
  border-radius: 13px;
  color: white;
  background: var(--ink);
  box-shadow: 0 14px 35px rgba(23, 33, 59, 0.24);
  font-size: 12px;
  font-weight: 650;
  opacity: 0;
  pointer-events: none;
  transform: translateY(10px);
  transition: opacity 0.25s, transform 0.25s;
}

.toast.is-visible { opacity: 1; transform: translateY(0); }

.completion-modal[hidden] { display: none; }
.completion-modal { position: fixed; z-index: 50; inset: 0; display: grid; place-items: center; padding: 20px; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(18, 27, 55, 0.56); backdrop-filter: blur(8px); }
.modal-card { position: relative; width: min(420px, 100%); padding: 36px; border-radius: 26px; background: white; box-shadow: 0 28px 80px rgba(18, 27, 55, 0.28); text-align: center; animation: rise 0.35s ease; }
.modal-emoji { display: block; margin-bottom: 12px; font-size: 45px; }
.modal-card h2 { margin-bottom: 7px; font-size: 28px; letter-spacing: -0.8px; }
.modal-card > p:not(.eyebrow) { color: var(--muted); font-size: 13px; }
.result-score { display: flex; flex-direction: column; gap: 3px; margin: 22px 0; padding: 18px; border-radius: 16px; background: var(--blue-pale); }
.result-score strong { color: var(--blue); font-size: 28px; }
.result-score span { color: var(--muted); font-size: 11px; }

button:disabled,
select:disabled { opacity: 0.58; }

@media (max-width: 800px) {
  .app-header { align-items: flex-start; flex-direction: column; padding: 18px 0; }
  .header-tools { width: 100%; flex-wrap: wrap; }
  .question-row { align-items: flex-start; flex-direction: column; }
  .audio-controls { width: 100%; }
  .audio-button { flex: 1; }
  .loading-overlay { grid-template-columns: 1fr; text-align: center; }
  .loading-overlay img { width: min(280px, 75%); justify-self: center; }
  .loading-copy { justify-self: center; }
}

@media (max-width: 560px) {
  .app-header, .app-shell { width: calc(100% - 24px); }
  .source-chip { order: 3; width: 100%; justify-content: center; }
  .topic-picker { width: 100%; justify-content: space-between; }
  .topic-picker select { max-width: none; }
  .count-picker { flex: 1; justify-content: space-between; }
  .random-topic-button, .new-set-button { flex: 1; justify-content: center; }
  .lesson-card { min-height: 760px; border-radius: 22px; }
  .lesson-progress, .quiz-body { padding-right: 18px; padding-left: 18px; }
  .answer-grid { gap: 9px; }
  .answer-card { padding: 5px; border-radius: 15px; }
  .image-frame { aspect-ratio: 1 / 1; border-radius: 10px; }
  .image-frame img.is-local-3d { padding: 22px; }
  .audio-controls { flex-direction: column; }
  .quiz-footer { align-items: stretch; flex-direction: column; }
  .generation-note { justify-content: center; text-align: center; }
  .footer-actions, .check-button, .next-button { width: 100%; }
  .loading-overlay { padding: 25px; }
  .loading-overlay img { width: min(230px, 82%); }
  .loading-copy h2 { font-size: 25px; }
}

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