/* ═══════════════════════════════════════════════
   Design tokens
   ═══════════════════════════════════════════════ */
:root {
  --bg:              #07071a;
  --bg-surface:      rgba(255,255,255,0.04);
  --bg-surface-hov:  rgba(255,255,255,0.07);
  --border:          rgba(255,255,255,0.08);
  --border-accent:   rgba(108,99,255,0.45);

  --accent-1:        #6C63FF;
  --accent-2:        #38BDF8;
  --grad-accent:     linear-gradient(135deg, #6C63FF 0%, #38BDF8 100%);
  --grad-random:     linear-gradient(135deg, #F59E0B 0%, #EF4444 100%);

  --text-primary:    #EEEEFF;
  --text-secondary:  #7878A8;
  --text-muted:      #444466;

  --success:         #34D399;
  --success-bg:      rgba(52,211,153,0.10);
  --success-border:  rgba(52,211,153,0.28);
  --error:           #F87171;
  --error-bg:        rgba(248,113,113,0.10);
  --error-border:    rgba(248,113,113,0.28);
  --warn:            #FBBF24;

  --radius-sm:  8px;
  --radius-md:  14px;
  --radius-lg:  22px;
  --radius-xl:  30px;

  --shadow-card:   0 8px 40px rgba(0,0,0,0.45);
  --shadow-accent: 0 0 60px rgba(108,99,255,0.12);

  --font: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}

/* ═══════════════════════════════════════════════
   Reset
   ═══════════════════════════════════════════════ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }

/* ═══════════════════════════════════════════════
   Base
   ═══════════════════════════════════════════════ */
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text-primary);
  line-height: 1.55;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

/* Ambient glow layers */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse 80% 45% at 15% -5%,  rgba(108,99,255,0.14)  0%, transparent 65%),
    radial-gradient(ellipse 55% 40% at 85% 105%, rgba(56,189,248,0.09)  0%, transparent 55%);
  pointer-events: none;
  z-index: 0;
}

/* Dot-grid texture */
body::after {
  content: '';
  position: fixed;
  inset: 0;
  background-image: radial-gradient(circle, rgba(255,255,255,0.035) 1px, transparent 1px);
  background-size: 30px 30px;
  pointer-events: none;
  z-index: 0;
}

/* ═══════════════════════════════════════════════
   App shell
   ═══════════════════════════════════════════════ */
.app {
  width: 100%;
  max-width: 1100px;
  background: var(--bg-app);
  border-radius: var(--radius-lg);
  padding: 20px 40px;
  box-shadow: 0 24px 80px rgba(0,0,0,0.4);
  backdrop-filter: blur(20px);
  border: 1px solid var(--border);
  margin: 40px auto;
  position: relative;
  z-index: 1;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.07em;
}

/* ═══════════════════════════════════════════════
   Difficulty bar
   ═══════════════════════════════════════════════ */
.difficulty-bar {
  display: flex;
  align-items: center;
  gap: 20px;
  margin-bottom: 24px;
  flex-wrap: wrap;
  padding: 4px 0;
}

.diff-group, .custom-group {
  display: flex;
  align-items: center;
  gap: 14px;
}

.difficulty-label {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.09em;
  white-space: nowrap;
}

.difficulty-buttons {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.diff-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 22px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-surface);
  color: var(--text-secondary);
  font-family: var(--font);
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.2s, color 0.2s, background 0.2s, box-shadow 0.2s, transform 0.15s;
}

.diff-btn:hover:not(.active) {
  border-color: var(--border-accent);
  color: var(--text-primary);
  background: var(--bg-surface-hov);
}

.diff-btn:active { transform: scale(0.97); }

.diff-btn.active {
  background: var(--grad-accent);
  border-color: transparent;
  color: #fff;
  box-shadow: 0 4px 18px rgba(108,99,255,0.38);
}

.diff-btn--random.active {
  background: var(--grad-random);
  box-shadow: 0 4px 18px rgba(245,158,11,0.38);
}

/* ── Custom inputs ── */
.custom-inputs {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  padding: 4px 6px 4px 10px;
  border-radius: var(--radius-sm);
}

.custom-inputs input {
  width: 40px;
  background: transparent;
  border: none;
  border-bottom: 1px solid transparent;
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 0.875rem;
  font-weight: 700;
  text-align: center;
  padding: 2px 0;
  outline: none;
  transition: border-color 0.2s;
  -moz-appearance: textfield;
}

.custom-inputs input:focus {
  border-bottom-color: var(--accent-1);
}

.custom-inputs input::-webkit-inner-spin-button,
.custom-inputs input::-webkit-outer-spin-button { -webkit-appearance: none; }

.custom-inputs .sep {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 600;
}

.custom-inputs .diff-btn {
  padding: 5px 14px;
  font-size: 0.75rem;
  margin-left: 4px;
}

/* ═══════════════════════════════════════════════
   Exercise layout
   ═══════════════════════════════════════════════ */
.exercise-area {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 380px;
  gap: 24px;
  align-items: start;
}

/* ── Canvas card ── */
.canvas-card {
  position: relative;
  background: #FFFFFF;
  border: 1px solid rgba(0,0,0,0.1);
  border-radius: var(--radius-lg);
  overflow: hidden;
  aspect-ratio: 1 / 1;
  box-shadow: 0 4px 20px rgba(0,0,0,0.1);
}

#three-canvas {
  display: block;
  width: 100% !important;
  height: 100% !important;
}

.grid-badge {
  position: absolute;
  top: 14px;
  left: 14px;
  background: rgba(0,0,0,0.08);
  border: 1px solid rgba(0,0,0,0.18);
  color: #444;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  padding: 4px 11px;
  border-radius: 6px;
  text-transform: uppercase;
}

.canvas-hint {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  text-align: center;
  font-size: 0.68rem;
  color: #AAA;
  padding: 10px 16px;
  background: linear-gradient(transparent, rgba(255,255,255,0.90));
}

/* ── Answer card ── */
.answer-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  overflow: hidden;
}

.answer-card-inner {
  display: flex;
  flex-direction: column;
  gap: 22px;
  padding: 28px 28px 24px;
}

/* Question */
.question-block { display: flex; flex-direction: column; gap: 6px; }

.question-text {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.38;
}

.question-hint {
  font-size: 0.78rem;
  color: var(--text-secondary);
  line-height: 1.5;
}

/* Attempts */
.attempts-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.attempts-label {
  font-size: 0.70rem;
  font-weight: 700;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.09em;
}

.attempt-dots { display: flex; gap: 8px; }

.attempt-dot {
  width: 13px;
  height: 13px;
  border-radius: 50%;
  transition: background 0.3s, border-color 0.3s, box-shadow 0.3s;
  border: 1.5px solid rgba(255,255,255,0.12);
  background: rgba(255,255,255,0.08);
}

.attempt-dot.filled {
  background: var(--grad-accent);
  border-color: transparent;
  box-shadow: 0 0 9px rgba(108,99,255,0.55);
}

.attempt-dot.empty {
  background: rgba(248,113,113,0.12);
  border-color: rgba(248,113,113,0.32);
}

/* Input */
.input-group {
  display: flex;
  gap: 10px;
}

.answer-input {
  flex: 1;
  background: rgba(255,255,255,0.05);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 1.5rem;
  font-weight: 800;
  text-align: center;
  padding: 10px 12px;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
  -moz-appearance: textfield;
}

.answer-input::-webkit-inner-spin-button,
.answer-input::-webkit-outer-spin-button { -webkit-appearance: none; }

.answer-input::placeholder { color: var(--text-muted); font-weight: 400; }

.answer-input:focus {
  border-color: var(--accent-1);
  box-shadow: 0 0 0 3px rgba(108,99,255,0.18);
}

.answer-input:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.check-btn {
  padding: 10px 22px;
  background: var(--grad-accent);
  border: none;
  border-radius: var(--radius-sm);
  color: #fff;
  font-family: var(--font);
  font-size: 0.92rem;
  font-weight: 700;
  white-space: nowrap;
  cursor: pointer;
  box-shadow: 0 4px 18px rgba(108,99,255,0.32);
  transition: transform 0.15s, box-shadow 0.2s, opacity 0.2s;
}

.check-btn:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 6px 22px rgba(108,99,255,0.44);
}

.check-btn:active:not(:disabled) { transform: translateY(0); }

.check-btn:disabled {
  opacity: 0.38;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

/* Feedback */
.feedback-area {
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  font-weight: 600;
  line-height: 1.45;
  overflow: hidden;
  max-height: 0;
  padding: 0 16px;
  transition: max-height 0.3s ease, padding 0.2s ease;
}

.feedback-area.show {
  max-height: 120px;
  padding: 12px 16px;
  animation: feedbackIn 0.22s ease;
}

.feedback-area.feedback--correct {
  color: var(--success);
  background: var(--success-bg);
  border: 1px solid var(--success-border);
}

.feedback-area.feedback--wrong {
  color: var(--error);
  background: var(--error-bg);
  border: 1px solid var(--error-border);
}

.feedback-area.feedback--failed {
  color: var(--error);
  background: var(--error-bg);
  border: 1px solid var(--error-border);
}

/* Layer breakdown */
.layer-breakdown {
  display: none;
  flex-direction: column;
  gap: 7px;
  padding: 14px 16px;
  background: rgba(255,255,255,0.03);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  animation: feedbackIn 0.25s ease;
}

.layer-breakdown.visible { display: flex; }

.layer-breakdown-title {
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--text-secondary);
  margin-bottom: 2px;
}

.layer-row {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.80rem;
  color: var(--text-secondary);
}

.layer-swatch {
  width: 13px;
  height: 13px;
  border-radius: 3px;
  flex-shrink: 0;
}

.layer-row strong { color: var(--text-primary); }

/* Next button */
.next-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 13px;
  background: var(--bg-surface-hov);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-family: var(--font);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s, color 0.2s;
}

.next-btn:hover {
  background: rgba(255,255,255,0.09);
  border-color: var(--border-accent);
  color: var(--text-primary);
}

.next-arrow { transition: transform 0.2s; }
.next-btn:hover .next-arrow { transform: translateX(5px); }

/* ═══════════════════════════════════════════════
   Responsive
   ═══════════════════════════════════════════════ */
@media (max-width: 780px) {
  .exercise-area {
    grid-template-columns: 1fr;
  }

  .canvas-card {
    max-height: min(70vw, 370px);
  }
}

@media (max-width: 520px) {
  .app { padding: 0 14px 32px; }

  .difficulty-bar { flex-direction: column; align-items: flex-start; gap: 12px; }

  .brand-tagline { display: none; }

  .answer-card-inner { padding: 20px; gap: 18px; }
}

/* ═══════════════════════════════════════════════
   Keyframes
   ═══════════════════════════════════════════════ */
@keyframes streakBump {
  0%   { transform: scale(1); }
  35%  { transform: scale(1.45); }
  65%  { transform: scale(0.90); }
  100% { transform: scale(1); }
}

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