:root {
  --bg-deep: #0b0716;
  --bg-card: #160f28;
  --bg-card-2: #1c1336;
  --purple: #a855f7;
  --purple-bright: #c084fc;
  --purple-dim: #6d28d9;
  --violet-glow: rgba(168, 85, 247, 0.35);
  --text-main: #f4f1fb;
  --text-muted: #a597c4;
  --border: rgba(168, 85, 247, 0.25);

  --match: #34d399;
  --match-glow: rgba(52, 211, 153, 0.35);
  --danger: #fb7185;
  --danger-glow: rgba(251, 113, 133, 0.5);
  --amber: #fbbf24;
  --amber-glow: rgba(251, 191, 36, 0.35);

  --editor-bg: #0d0a17;
  --line-num: #5f5478;
  --tok-kw: #c084fc;
  --tok-str: #6ee7b7;
  --tok-num: #fbbf24;
  --tok-fn: #67e8f9;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  min-height: 100vh;
  background:
    radial-gradient(circle at 20% 15%, rgba(168, 85, 247, 0.18), transparent 45%),
    radial-gradient(circle at 85% 85%, rgba(124, 58, 237, 0.16), transparent 50%),
    var(--bg-deep);
  font-family: 'Inter', sans-serif;
  color: var(--text-main);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.app { width: 100%; max-width: 540px; position: relative; }

.panel {
  background: linear-gradient(160deg, var(--bg-card) 0%, var(--bg-card-2) 100%);
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: 28px 26px 26px;
  box-shadow:
    0 0 0 1px rgba(255,255,255,0.02) inset,
    0 30px 60px -20px rgba(0,0,0,0.6),
    0 0 60px -15px var(--violet-glow);
  position: relative;
  overflow: hidden;
}

.panel::before {
  content: "";
  position: absolute;
  top: -60%;
  left: -20%;
  width: 140%;
  height: 140%;
  background: conic-gradient(from 180deg, transparent, var(--violet-glow), transparent 35%);
  animation: spin 16s linear infinite;
  opacity: 0.3;
  pointer-events: none;
}

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

header { text-align: center; margin-bottom: 14px; position: relative; z-index: 1; }

h1 {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 24px;
  letter-spacing: 0.5px;
  background: linear-gradient(90deg, var(--purple-bright), var(--purple), #818cf8);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  background-size: 200% auto;
  animation: shimmer 4s ease-in-out infinite;
  margin-bottom: 6px;
}

@keyframes shimmer {
  0%, 100% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
}

.subtitle {
  color: var(--text-muted);
  font-size: 13px;
  margin-bottom: 14px;
}

.stats-row {
  display: flex;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
}

.stat-pill {
  background: rgba(0,0,0,0.2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 6px 14px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.stat-label {
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-muted);
  font-weight: 600;
}

.stat-value {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 15px;
  font-weight: 700;
  color: var(--purple-bright);
  transition: transform 0.2s, color 0.2s;
}

.stat-value.bump { animation: bump 0.35s ease; }
@keyframes bump { 0% { transform: scale(1); } 40% { transform: scale(1.3); } 100% { transform: scale(1); } }

.stat-value.danger { color: var(--danger); }

.difficulty-row {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin: 16px 0;
  position: relative;
  z-index: 1;
}

.diff-btn {
  background: rgba(168, 85, 247, 0.06);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 600;
  padding: 7px 16px;
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.2s;
}

.diff-btn:hover { border-color: var(--purple); color: var(--text-main); }

.diff-btn.active {
  background: linear-gradient(135deg, var(--purple), var(--purple-dim));
  border-color: transparent;
  color: white;
  box-shadow: 0 0 16px -4px var(--violet-glow);
}

.diff-btn:disabled { opacity: 0.4; cursor: not-allowed; }

.level-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  justify-content: center;
  margin-bottom: 12px;
  position: relative;
  z-index: 1;
}

.level-banner.hidden { display: none; }

.level-tag {
  background: linear-gradient(135deg, var(--purple), var(--purple-dim));
  color: white;
  font-size: 11px;
  font-weight: 700;
  padding: 4px 12px;
  border-radius: 999px;
  white-space: nowrap;
}

.level-title {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 15px;
  font-weight: 700;
  color: var(--text-main);
}

.code-panel {
  background: var(--editor-bg);
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
  margin-bottom: 14px;
  box-shadow: inset 0 0 30px rgba(0,0,0,0.4);
  position: relative;
  z-index: 1;
}

.code-window-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 14px;
  background: rgba(255,255,255,0.03);
  border-bottom: 1px solid var(--border);
}

.dot { width: 10px; height: 10px; border-radius: 50%; }
.dot.red { background: #fb7185; }
.dot.yellow { background: #fbbf24; }
.dot.green { background: #34d399; }

.file-name {
  margin-left: 8px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  color: var(--text-muted);
}

.code-lines {
  font-family: 'JetBrains Mono', monospace;
  font-size: 13px;
  line-height: 1.9;
  padding: 14px 0;
  min-height: 160px;
}

.idle-hint {
  font-family: 'Inter', sans-serif;
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
  padding: 50px 20px;
}

.code-line {
  display: flex;
  align-items: center;
  padding: 2px 16px;
  cursor: pointer;
  border-left: 3px solid transparent;
  transition: background 0.15s, border-color 0.15s;
  white-space: pre;
}

.code-line:hover {
  background: rgba(168, 85, 247, 0.08);
}

.line-num {
  color: var(--line-num);
  width: 26px;
  flex-shrink: 0;
  -webkit-user-select: none; /* Safari 3+, iOS 3+ */
  user-select: none;
}

.line-code { color: #d8d2e8; }

.tok-kw { color: var(--tok-kw); font-weight: 600; }
.tok-str { color: var(--tok-str); }
.tok-num { color: var(--tok-num); }
.tok-fn { color: var(--tok-fn); }

.code-line.wrong {
  background: rgba(251, 113, 133, 0.18);
  border-left-color: var(--danger);
  animation: flashRed 0.35s ease;
}

@keyframes flashRed {
  0%, 100% { background: rgba(251, 113, 133, 0.18); }
  50% { background: rgba(251, 113, 133, 0.32); }
}

.code-line.correct {
  background: rgba(52, 211, 153, 0.15);
  border-left-color: var(--match);
  box-shadow: inset 0 0 18px -4px var(--match-glow);
}

.code-line.revealed {
  background: rgba(251, 191, 36, 0.15);
  border-left-color: var(--amber);
  box-shadow: inset 0 0 18px -4px var(--amber-glow);
}

.feedback-box {
  border-radius: 12px;
  padding: 12px 16px;
  margin-bottom: 16px;
  font-size: 13px;
  border: 1px solid var(--border);
  background: rgba(0,0,0,0.2);
  position: relative;
  z-index: 1;
  animation: fadeIn 0.25s ease;
}

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

.feedback-box.hidden { display: none; }

.feedback-box strong { display: block; margin-bottom: 4px; font-size: 13px; }

.feedback-box p { color: var(--text-muted); line-height: 1.5; }

.feedback-box.success strong { color: var(--match); }
.feedback-box.success { border-color: rgba(52, 211, 153, 0.3); }

.feedback-box.timeout strong { color: var(--amber); }
.feedback-box.timeout { border-color: rgba(251, 191, 36, 0.3); }

.button-row {
  display: flex;
  gap: 10px;
  position: relative;
  z-index: 1;
}

.primary-btn {
  flex: 1;
  background: linear-gradient(135deg, var(--purple), var(--purple-dim));
  border: none;
  color: white;
  font-weight: 700;
  font-size: 13px;
  padding: 11px 24px;
  border-radius: 12px;
  cursor: pointer;
  box-shadow: 0 0 20px -4px var(--violet-glow);
  transition: transform 0.15s, box-shadow 0.2s, opacity 0.2s;
}

.primary-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 0 26px -2px var(--violet-glow);
}

.primary-btn:active { transform: translateY(0) scale(0.97); }

.primary-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.secondary-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-weight: 600;
  font-size: 13px;
  padding: 11px 18px;
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.2s;
}

.secondary-btn:hover:not(:disabled) {
  border-color: var(--danger);
  color: var(--danger);
  background: rgba(251, 113, 133, 0.06);
}

.secondary-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.win-overlay {
  position: fixed;
  inset: 0;
  background: rgba(8, 5, 15, 0.78);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 20px;
}

.win-overlay.hidden { display: none; }

.win-modal {
  background: linear-gradient(160deg, var(--bg-card) 0%, var(--bg-card-2) 100%);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 30px 32px;
  text-align: center;
  box-shadow: 0 0 60px -10px var(--violet-glow);
  animation: pop 0.4s cubic-bezier(.34,1.56,.64,1);
  max-width: 320px;
}

@keyframes pop {
  0% { transform: scale(0.7); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

.win-modal h2 {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 22px;
  margin-bottom: 14px;
  color: var(--match);
}

.win-modal p {
  font-size: 14px;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.win-modal p span {
  color: var(--purple-bright);
  font-weight: 700;
  font-family: 'Space Grotesk', sans-serif;
}

.best-tag {
  color: #fbbf24 !important;
  font-weight: 700;
  font-size: 13px !important;
  margin: 8px 0 4px !important;
}

.best-tag.hidden { display: none; }

.win-modal .primary-btn { margin-top: 14px; width: 100%; }

@media (max-width: 420px) {
  h1 { font-size: 20px; }
  .code-lines { font-size: 11.5px; }
  .stat-pill { padding: 6px 10px; }
  .button-row { flex-direction: column; }
}