:root {
  color-scheme: light;
  --bg: #eef4f1;
  --bg-2: #f8fafc;
  --surface: rgba(255, 255, 255, 0.78);
  --surface-solid: #ffffff;
  --text: #17211f;
  --muted: #65736f;
  --line: rgba(15, 23, 42, 0.12);
  --primary: #0f766e;
  --primary-2: #0ea5a4;
  --accent: #f59e0b;
  --accent-2: #f97316;
  --info: #2563eb;
  --danger: #dc2626;
  --success: #16a34a;
  --warning: #d97706;
  --shadow: 0 22px 60px rgba(15, 23, 42, 0.14);
  --radius: 8px;
  --radius-sm: 6px;
  --font: "Poppins", "Segoe UI", Arial, sans-serif;
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #101817;
  --bg-2: #18201f;
  --surface: rgba(24, 31, 30, 0.78);
  --surface-solid: #171e1d;
  --text: #edf7f4;
  --muted: #aab7b2;
  --line: rgba(255, 255, 255, 0.14);
  --primary: #14b8a6;
  --primary-2: #22d3ee;
  --accent: #fbbf24;
  --accent-2: #fb7185;
  --info: #60a5fa;
  --danger: #f87171;
  --success: #4ade80;
  --warning: #facc15;
  --shadow: 0 22px 70px rgba(0, 0, 0, 0.35);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
}

body {
  min-height: 100%;
  margin: 0;
  font-family: var(--font);
  color: var(--text);
  background:
    radial-gradient(circle at 18% 12%, rgba(20, 184, 166, 0.14), transparent 26rem),
    radial-gradient(circle at 78% 6%, rgba(249, 115, 22, 0.13), transparent 24rem),
    linear-gradient(135deg, var(--bg), var(--bg-2));
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.58;
}

.app-shell {
  width: min(1220px, calc(100% - 32px));
  margin: 0 auto;
  padding: 22px 0 44px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  position: sticky;
  top: 12px;
  z-index: 20;
  padding: 10px 12px;
  margin-bottom: 22px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  backdrop-filter: blur(20px);
  box-shadow: var(--shadow);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  color: var(--text);
  text-decoration: none;
}

.brand-mark {
  width: 46px;
  height: 46px;
  flex: 0 0 46px;
}

.brand strong,
.brand small {
  display: block;
}

.brand strong {
  font-size: 0.98rem;
  line-height: 1.15;
}

.brand small {
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.76rem;
}

.top-actions,
.quiz-actions,
.result-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.glass-panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  backdrop-filter: blur(20px);
  box-shadow: var(--shadow);
}

.view {
  display: none;
}

.view.is-active {
  display: block;
  animation: rise 260ms ease both;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.hero-panel {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 180px;
  gap: 22px;
  align-items: center;
  padding: 28px;
  overflow: hidden;
}

.hero-copy h1 {
  margin: 10px 0 10px;
  max-width: 780px;
  font-size: clamp(2rem, 5vw, 4.6rem);
  line-height: 1.02;
  letter-spacing: 0;
}

.hero-copy p {
  max-width: 700px;
  margin: 0;
  color: var(--muted);
  font-size: 1rem;
  line-height: 1.7;
}

.eyebrow {
  color: var(--primary);
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.hero-meter {
  display: grid;
  place-items: center;
  position: relative;
  min-height: 170px;
}

.hero-meter svg {
  width: 160px;
  height: 160px;
  transform: rotate(-90deg);
}

.meter-bg,
.meter-value {
  fill: none;
  stroke-width: 12;
}

.meter-bg {
  stroke: rgba(100, 116, 139, 0.18);
}

.meter-value {
  stroke: url("#none");
  stroke: var(--primary);
  stroke-linecap: round;
  stroke-dasharray: 427;
  stroke-dashoffset: 427;
  transition: stroke-dashoffset 400ms ease;
}

.hero-meter strong,
.hero-meter span {
  position: absolute;
}

.hero-meter strong {
  font-size: 2rem;
  transform: translateY(-6px);
}

.hero-meter span {
  color: var(--muted);
  font-size: 0.78rem;
  transform: translateY(28px);
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 14px;
  margin: 16px 0;
}

.stat-card {
  min-height: 128px;
  padding: 18px;
}

.stat-card i {
  color: var(--accent-2);
  font-size: 1.35rem;
}

.stat-card span,
.stat-card strong {
  display: block;
}

.stat-card span {
  margin: 16px 0 5px;
  color: var(--muted);
  font-size: 0.82rem;
}

.stat-card strong {
  font-size: 1.65rem;
}

.builder-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(320px, 0.75fr);
  gap: 16px;
}

.practice-panel,
.question-panel,
.palette-panel,
.chart-panel,
.weak-panel,
.result-hero {
  padding: 20px;
}

.section-heading,
.palette-header,
.progress-header,
.drawer-header,
.quiz-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.section-heading h2,
.drawer-header h2,
.chart-panel h3,
.weak-panel h3 {
  margin: 4px 0 0;
}

.counter-pill,
.badge,
.timer {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 30px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 10px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.35);
  font-size: 0.76rem;
  font-weight: 700;
  white-space: nowrap;
}

[data-theme="dark"] .counter-pill,
[data-theme="dark"] .badge,
[data-theme="dark"] .timer {
  background: rgba(255, 255, 255, 0.06);
}

.difficulty.easy {
  color: var(--success);
}

.difficulty.medium {
  color: var(--warning);
}

.difficulty.competitive {
  color: var(--danger);
}

.form-row,
.range-row {
  margin-top: 20px;
}

.form-row label,
.range-row label,
.search-panel label {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 700;
}

select,
input[type="search"] {
  width: 100%;
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 0 12px;
  color: var(--text);
  background: var(--surface-solid);
  outline: none;
}

select:focus,
input[type="search"]:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(20, 184, 166, 0.16);
}

.segmented-control,
.mode-grid,
.action-grid {
  display: grid;
  gap: 10px;
  margin-top: 18px;
}

.segmented-control {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  padding: 5px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.segment,
.mode-option span {
  border: 0;
  border-radius: var(--radius-sm);
  color: var(--muted);
  background: transparent;
  font-weight: 700;
  min-height: 40px;
}

.segment.is-active,
.mode-option.is-active span {
  color: #ffffff;
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
}

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

.mode-option input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.mode-option span {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid var(--line);
}

.range-row {
  display: grid;
  grid-template-columns: 1fr minmax(160px, 240px) 52px;
  align-items: center;
  gap: 12px;
}

input[type="range"] {
  accent-color: var(--primary);
}

output {
  text-align: center;
  font-weight: 800;
}

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

.action-grid.compact {
  grid-template-columns: 1fr 1fr;
}

.primary-button,
.secondary-button,
.danger-button,
.icon-text-button,
.icon-button,
.back-button,
.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  padding: 0 14px;
  font-weight: 800;
  color: var(--text);
  background: var(--surface-solid);
  transition: transform 160ms ease, box-shadow 160ms ease, border-color 160ms ease;
}

.primary-button:hover,
.secondary-button:hover,
.danger-button:hover,
.icon-text-button:hover,
.icon-button:hover,
.back-button:hover,
.theme-toggle:hover {
  transform: translateY(-1px);
  box-shadow: 0 12px 28px rgba(15, 23, 42, 0.14);
}

.primary-button {
  color: #ffffff;
  border: 0;
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
}

.secondary-button {
  color: var(--primary);
}

.back-button {
  color: var(--text);
  background: rgba(255, 255, 255, 0.5);
}

[data-theme="dark"] .back-button {
  background: rgba(255, 255, 255, 0.08);
}

.danger-button {
  color: #ffffff;
  border: 0;
  background: linear-gradient(135deg, var(--danger), var(--accent-2));
}

.icon-button {
  width: 44px;
  padding: 0;
}

.theme-toggle {
  min-width: 92px;
}

.focus-list {
  display: grid;
  gap: 10px;
  margin: 18px 0;
}

.focus-list button {
  display: grid;
  grid-template-columns: 24px 1fr auto;
  align-items: center;
  gap: 10px;
  min-height: 54px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 0 14px;
  color: var(--text);
  background: var(--surface-solid);
  text-align: left;
}

.focus-list i {
  color: var(--accent-2);
}

.progress-block {
  margin-top: 22px;
}

.progress-track {
  height: 10px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(100, 116, 139, 0.2);
}

.progress-track span {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--primary), var(--accent));
  transition: width 240ms ease;
}

.topic-board {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-top: 16px;
}

.topic-card {
  padding: 16px;
}

.topic-card h3 {
  min-height: 44px;
  margin: 0 0 12px;
  font-size: 0.95rem;
}

.topic-card p {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 0.8rem;
}

.topic-meta {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
  margin-bottom: 12px;
}

.topic-meta span {
  display: grid;
  place-items: center;
  min-height: 30px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  color: var(--muted);
  background: rgba(255, 255, 255, 0.32);
  font-size: 0.7rem;
  font-weight: 800;
  text-align: center;
}

[data-theme="dark"] .topic-meta span {
  background: rgba(255, 255, 255, 0.06);
}

.topic-start {
  width: 100%;
  margin-top: 4px;
}

.quiz-layout {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}

.palette-panel {
  position: sticky;
  top: 96px;
}

.palette-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  margin-top: 16px;
  max-height: 62vh;
  overflow: auto;
  padding-right: 4px;
}

.palette-grid button {
  aspect-ratio: 1;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  color: var(--text);
  background: var(--surface-solid);
  font-weight: 800;
}

.palette-grid button.is-active {
  outline: 3px solid rgba(20, 184, 166, 0.24);
  border-color: var(--primary);
}

.palette-grid button.is-answered {
  color: #ffffff;
  background: var(--success);
}

.palette-grid button.is-skipped {
  color: #ffffff;
  background: var(--warning);
}

.palette-grid button.is-review {
  color: #ffffff;
  background: var(--info);
}

.question-panel {
  min-height: 560px;
}

.quiz-meta {
  flex-wrap: wrap;
}

.quiz-progress {
  margin: 18px 0 24px;
}

#quiz-question {
  min-height: 88px;
  margin: 0 0 18px;
  font-size: 1.35rem;
  line-height: 1.5;
}

.options-list {
  display: grid;
  gap: 12px;
}

.option-button {
  display: grid;
  grid-template-columns: 40px 1fr;
  align-items: center;
  gap: 12px;
  min-height: 64px;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 14px;
  color: var(--text);
  background: var(--surface-solid);
  text-align: left;
}

.option-button strong {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  color: var(--primary);
  background: rgba(20, 184, 166, 0.12);
}

.option-button.is-selected {
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(20, 184, 166, 0.13);
}

.option-button.is-correct {
  border-color: var(--success);
  background: rgba(22, 163, 74, 0.11);
}

.option-button.is-wrong {
  border-color: var(--danger);
  background: rgba(220, 38, 38, 0.1);
}

.explanation-box {
  margin-top: 16px;
  border-left: 4px solid var(--primary);
  border-radius: var(--radius-sm);
  padding: 14px;
  color: var(--muted);
  background: rgba(20, 184, 166, 0.08);
}

.quiz-actions {
  margin-top: 22px;
}

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

.result-hero h2 {
  margin: 4px 0 8px;
  font-size: 2rem;
}

.result-hero p {
  margin: 0;
  color: var(--muted);
}

.score-card {
  display: grid;
  place-items: center;
  min-width: 160px;
  min-height: 132px;
  border-radius: var(--radius);
  color: #ffffff;
  background: linear-gradient(135deg, var(--primary), var(--accent-2));
}

.score-card strong {
  font-size: 2.6rem;
}

.score-card span {
  margin-top: -28px;
  font-weight: 700;
}

.analytics-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  margin-top: 16px;
}

.chart-panel canvas {
  width: 100%;
  max-height: 280px;
}

.chart-fallback {
  display: none;
  gap: 8px;
}

.fallback-row {
  display: grid;
  grid-template-columns: minmax(92px, 160px) 1fr 48px;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 0.8rem;
}

.fallback-bar {
  height: 9px;
  border-radius: 999px;
  background: rgba(100, 116, 139, 0.18);
  overflow: hidden;
}

.fallback-bar span {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--primary), var(--accent));
}

.weak-panel ul {
  padding: 0;
  margin: 14px 0 0;
  list-style: none;
}

.weak-panel li {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
}

.result-actions {
  justify-content: flex-end;
  margin-top: 18px;
}

.search-panel {
  position: fixed;
  top: 88px;
  left: 50%;
  z-index: 40;
  width: min(720px, calc(100% - 32px));
  max-height: calc(100vh - 120px);
  transform: translateX(-50%);
  padding: 18px;
  overflow: auto;
}

.search-row {
  display: grid;
  grid-template-columns: 1fr 44px;
  gap: 10px;
}

.search-results {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.search-result {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 12px;
  background: var(--surface-solid);
}

.search-result strong {
  display: block;
  margin-bottom: 5px;
}

.search-result p {
  margin: 0;
  color: var(--muted);
  font-size: 0.86rem;
}

.settings-drawer {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  justify-items: end;
  pointer-events: none;
  background: rgba(15, 23, 42, 0);
  transition: background 200ms ease;
}

.settings-drawer.is-open {
  pointer-events: auto;
  background: rgba(15, 23, 42, 0.28);
}

.drawer-inner {
  width: min(380px, 100%);
  height: 100%;
  padding: 20px;
  border-radius: 0;
  transform: translateX(100%);
  transition: transform 220ms ease;
}

.settings-drawer.is-open .drawer-inner {
  transform: translateX(0);
}

.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 56px;
  border-bottom: 1px solid var(--line);
  font-weight: 700;
}

.switch-row input {
  width: 44px;
  height: 24px;
  accent-color: var(--primary);
}

.wide {
  width: 100%;
  margin-top: 16px;
}

.toast-host {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 80;
  display: grid;
  gap: 10px;
}

.toast {
  max-width: 340px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
  color: var(--text);
  background: var(--surface-solid);
  box-shadow: var(--shadow);
  animation: toast-in 180ms ease both;
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
}

@media (max-width: 980px) {
  .stats-grid,
  .topic-board {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .builder-grid,
  .quiz-layout,
  .analytics-grid {
    grid-template-columns: 1fr;
  }

  .palette-panel {
    position: static;
  }

  .palette-grid {
    grid-template-columns: repeat(10, 1fr);
    max-height: 160px;
  }
}

@media (max-width: 700px) {
  .app-shell {
    width: min(100% - 20px, 1220px);
    padding-top: 10px;
  }

  .topbar {
    align-items: flex-start;
  }

  .brand small,
  .theme-toggle span {
    display: none;
  }

  .hero-panel {
    grid-template-columns: 1fr;
    padding: 20px;
  }

  .hero-meter {
    min-height: 130px;
  }

  .hero-meter svg {
    width: 128px;
    height: 128px;
  }

  .stats-grid,
  .topic-board,
  .mode-grid,
  .action-grid,
  .action-grid.compact,
  .segmented-control,
  .result-stats {
    grid-template-columns: 1fr;
  }

  .range-row {
    grid-template-columns: 1fr;
  }

  .quiz-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .quiz-actions .primary-button,
  .quiz-actions .danger-button {
    grid-column: span 2;
  }

  .result-hero {
    align-items: stretch;
    flex-direction: column;
  }

  .score-card {
    min-height: 110px;
  }

  .palette-grid {
    grid-template-columns: repeat(6, 1fr);
  }
}

@media print {
  body {
    background: #ffffff;
    color: #000000;
  }

  .topbar,
  .quiz-view,
  .home-view,
  .settings-drawer,
  .search-panel,
  .result-actions,
  .toast-host {
    display: none !important;
  }

  .view,
  .result-view {
    display: block !important;
  }

  .glass-panel {
    border: 1px solid #d0d0d0;
    box-shadow: none;
    background: #ffffff;
  }
}
