:root {
  --bg-page: #060812;
  --bg-grid: rgba(77, 234, 255, 0.08);
  --bg-panel: rgba(14, 20, 36, 0.82);
  --bg-card: rgba(20, 28, 48, 0.86);
  --bg-card-hover: rgba(28, 38, 62, 0.94);
  --text-main: #ecf4ff;
  --text-muted: #a4b2cd;
  --accent: #2ee6a6;
  --accent-2: #25b9ff;
  --danger: #ff5a7a;
  --ok-bg: rgba(24, 76, 54, 0.6);
  --bad-bg: rgba(102, 24, 46, 0.6);
  --outline: rgba(142, 176, 255, 0.3);
  --shadow-soft: 0 14px 40px rgba(0, 0, 0, 0.42);
  --radius-lg: 16px;
  --radius-md: 12px;
  --font-sans: 'Space Grotesk', 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', Consolas, monospace;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  padding: 24px;
  font-family: var(--font-sans);
  color: var(--text-main);
  background:
    radial-gradient(circle at 20% 20%, rgba(37, 185, 255, 0.22), transparent 36%),
    radial-gradient(circle at 82% 12%, rgba(46, 230, 166, 0.18), transparent 36%),
    radial-gradient(circle at 48% 78%, rgba(94, 117, 255, 0.15), transparent 42%),
    var(--bg-page);
}

.background-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(var(--bg-grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--bg-grid) 1px, transparent 1px);
  background-size: 32px 32px;
  opacity: 0.45;
  z-index: -1;
}

.quiz-container {
  width: min(980px, 100%);
  margin: 0 auto;
  background: var(--bg-panel);
  border: 1px solid var(--outline);
  border-radius: var(--radius-lg);
  padding: 28px;
  box-shadow: var(--shadow-soft);
  backdrop-filter: blur(12px);
  animation: lift-in 360ms ease-out;
}

.app-header {
  margin-bottom: 20px;
}

h1 {
  margin: 0;
  font-size: clamp(1.6rem, 3.2vw, 2.25rem);
  letter-spacing: 0.02em;
  color: var(--text-main);
}

.app-subtitle {
  margin: 8px 0 0;
  color: var(--text-muted);
  font-size: 0.95rem;
}

#loading-spinner {
  display: none;
  color: var(--text-muted);
  font-size: 0.95rem;
  margin-bottom: 12px;
}

#loading-spinner.visible {
  display: block;
}

.tab-navigation {
  display: flex;
  gap: 10px;
  margin-bottom: 22px;
}

.tab-button {
  flex: 1;
  border: 1px solid var(--outline);
  background: rgba(22, 32, 54, 0.64);
  color: var(--text-muted);
  border-radius: 999px;
  font-family: var(--font-sans);
  font-weight: 600;
  padding: 11px 10px;
  cursor: pointer;
  transition: 180ms ease;
}

.tab-button:hover,
.tab-button:focus-visible {
  color: var(--text-main);
  border-color: var(--accent-2);
  outline: none;
}

.tab-button.active {
  color: #04121d;
  background: linear-gradient(120deg, var(--accent), var(--accent-2));
  border-color: transparent;
}

.tab-content {
  display: none;
}

.tab-content.active {
  display: block;
  animation: fade-slide 220ms ease;
}

.progress-container {
  margin-bottom: 24px;
}

.progress-top-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}

#progress-text {
  color: var(--text-muted);
  font-weight: 500;
  font-size: 0.88rem;
}

.gamification-bar {
  display: flex;
  gap: 12px;
  font-size: 0.88rem;
  font-weight: 700;
}

#streak-display { color: #ffb649; }
#xp-display { color: #68f4c9; }

.progress-bar-container {
  border-radius: 999px;
  border: 1px solid var(--outline);
  height: 12px;
  overflow: hidden;
  background: rgba(13, 18, 33, 0.86);
}

#progress-bar-fill {
  width: 0;
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  transition: width 250ms ease;
}

#problem-title {
  margin: 0 0 10px;
  font-size: clamp(1.2rem, 2.2vw, 1.5rem);
}

#problem-statement {
  border: 1px solid var(--outline);
  border-radius: var(--radius-md);
  background: rgba(13, 18, 32, 0.78);
  color: var(--text-muted);
  padding: 14px;
  margin-bottom: 14px;
  line-height: 1.55;
  white-space: pre-wrap;
}

pre {
  margin: 0;
  border-radius: 10px;
  border: 1px solid rgba(145, 165, 214, 0.35);
  overflow: auto;
}

code {
  font-family: var(--font-mono);
  font-size: 0.88rem;
}

#code-skeleton,
.choice-label pre code {
  display: block;
  padding: 12px;
}

.todo-hint {
  margin: 10px 0 0;
  color: var(--text-muted);
  font-size: 0.88rem;
}

#choices-area {
  margin-top: 16px;
}

.choice-label {
  display: block;
  border: 1px solid var(--outline);
  border-radius: var(--radius-md);
  padding: 10px;
  background: var(--bg-card);
  margin-bottom: 10px;
  cursor: pointer;
  transition: 160ms ease;
}

.choice-label:hover,
.choice-label:focus-within {
  border-color: var(--accent-2);
  background: var(--bg-card-hover);
}

.choice-label input[type='radio'] {
  accent-color: var(--accent);
  margin: 0 8px 8px 0;
}

.choice-label pre {
  border: 1px solid rgba(145, 165, 214, 0.25);
}

.choice-explanation {
  display: none;
  margin: 8px 0 0;
  color: var(--text-muted);
  font-size: 0.86rem;
}

.choice-label.correct-style,
.choice-label.correct-answer-highlight {
  border-color: var(--accent);
  background: var(--ok-bg);
}

.choice-label.incorrect-style,
.choice-label.incorrect-selection-highlight {
  border-color: var(--danger);
  background: var(--bad-bg);
}

.choice-label.correct-style .choice-explanation,
.choice-label.incorrect-style .choice-explanation {
  display: block;
}

button {
  border-radius: 12px;
  border: 1px solid transparent;
  padding: 12px 14px;
  font-family: var(--font-sans);
  font-weight: 700;
  cursor: pointer;
  transition: 180ms ease;
}

#check-button,
#next-button {
  width: 100%;
  margin-top: 12px;
}

#check-button {
  background: linear-gradient(120deg, var(--accent), var(--accent-2));
  color: #031220;
}

#check-button:hover:not(:disabled),
#check-button:focus-visible {
  filter: brightness(1.05);
  outline: none;
}

#next-button {
  background: rgba(22, 31, 52, 0.94);
  color: var(--text-main);
  border-color: var(--outline);
}

#next-button:hover:not(:disabled),
#next-button:focus-visible {
  border-color: var(--accent-2);
  outline: none;
}

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

.feedback-area {
  min-height: 48px;
  margin-top: 12px;
  border-radius: 12px;
  border: 1px solid transparent;
  display: grid;
  place-items: center;
  text-align: center;
  font-weight: 700;
}

.feedback-area.correct {
  border-color: rgba(46, 230, 166, 0.6);
  background: rgba(17, 90, 63, 0.45);
  color: #9ef7d4;
}

.feedback-area.incorrect {
  border-color: rgba(255, 90, 122, 0.7);
  background: rgba(108, 24, 44, 0.5);
  color: #ff9eb2;
}

#questions-list {
  display: grid;
  gap: 10px;
}

.question-item {
  text-align: left;
  width: 100%;
  color: var(--text-main);
  background: var(--bg-card);
  border: 1px solid var(--outline);
}

.question-item.correct-answered {
  border-left: 5px solid var(--accent);
}

.question-item.incorrect-answered {
  border-left: 5px solid var(--danger);
}

#review-summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 10px;
}

.stat-card {
  border: 1px solid var(--outline);
  border-radius: 12px;
  background: var(--bg-card);
  padding: 14px;
  text-align: center;
}

.stat-value {
  display: block;
  color: var(--accent);
  font-size: 1.3rem;
  font-weight: 700;
}

.stat-label {
  display: block;
  font-size: 0.82rem;
  color: var(--text-muted);
}

#review-list {
  list-style: none;
  margin: 14px 0 0;
  padding: 0;
}

.review-item {
  border: 1px solid var(--outline);
  border-radius: 12px;
  background: var(--bg-card);
  padding: 12px;
  margin-bottom: 10px;
}

.review-details {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px dashed rgba(146, 171, 232, 0.35);
  color: var(--text-muted);
  font-size: 0.86rem;
}

#reset-progress-button {
  margin-top: 16px;
  background: rgba(255, 90, 122, 0.2);
  border-color: rgba(255, 90, 122, 0.6);
  color: #ffd8e2;
}

#achievement-toast-container {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 1000;
  display: grid;
  gap: 8px;
}

.achievement-toast {
  background: rgba(15, 26, 46, 0.95);
  border: 1px solid rgba(46, 230, 166, 0.7);
  border-radius: 12px;
  padding: 10px 12px;
  min-width: 220px;
  box-shadow: var(--shadow-soft);
  animation: toast-slide 240ms ease;
}

.toast-label {
  display: block;
  font-weight: 700;
  color: var(--accent);
}

.toast-desc {
  display: block;
  color: var(--text-muted);
  font-size: 0.82rem;
  margin-top: 2px;
}

.error-message {
  border: 1px solid rgba(255, 90, 122, 0.6);
  background: rgba(102, 24, 46, 0.4);
  border-radius: 12px;
  padding: 16px;
  color: #ffd8e2;
}

@keyframes fade-slide {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes toast-slide {
  from { opacity: 0; transform: translateX(24px); }
  to { opacity: 1; transform: translateX(0); }
}

@keyframes lift-in {
  from { opacity: 0; transform: translateY(12px) scale(0.99); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@media (max-width: 720px) {
  body { padding: 14px; }
  .quiz-container { padding: 16px; }
  .tab-navigation { flex-direction: column; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation: none !important;
    transition: none !important;
  }
}
