:root {
  --c: #a855f7;
  --glow: rgba(168,85,247,.5);
  --ink: #f4f1ff;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  font-family: 'Bricolage Grotesque', system-ui, sans-serif;
  background: #0a0812;
  color: var(--ink);
  min-height: 100vh;
  overflow-x: hidden;
}
.fa { font-family: 'Vazirmatn', sans-serif; direction: rtl; }
.tabular-nums { font-variant-numeric: tabular-nums; font-family: 'JetBrains Mono', monospace; }

/* Layout */
.app-shell { position: relative; min-height: 100vh; display: flex; align-items: flex-start; justify-content: center; padding: 24px 16px 40px; }
.content-wrap { position: relative; z-index: 2; width: 100%; max-width: 620px; }

/* Background atmosphere */
.bg-fx { position: fixed; inset: 0; z-index: 0; overflow: hidden; }
.blob { position: absolute; border-radius: 50%; filter: blur(70px); opacity: .55; animation: float 14s ease-in-out infinite; }
.b1 { width: 420px; height: 420px; background: var(--c); top: -120px; left: -100px; }
.b2 { width: 380px; height: 380px; background: #ec4899; bottom: -140px; right: -110px; animation-delay: -5s; }
.b3 { width: 300px; height: 300px; background: #06b6d4; top: 40%; left: 55%; animation-delay: -9s; opacity: .35; }
@keyframes float { 0%,100% { transform: translate(0,0) scale(1); } 33% { transform: translate(40px,-30px) scale(1.1); } 66% { transform: translate(-30px,25px) scale(.95); } }
.grid-overlay { position: absolute; inset: 0; background-image: linear-gradient(rgba(255,255,255,.03) 1px, transparent 1px), linear-gradient(90deg, rgba(255,255,255,.03) 1px, transparent 1px); background-size: 40px 40px; }

/* Header */
.title-main { font-size: clamp(2.6rem, 9vw, 4.2rem); font-weight: 800; line-height: .95; letter-spacing: -.03em; margin: 0; background: linear-gradient(120deg, #fff, #d8b4fe 40%, #f9a8d4 80%); -webkit-background-clip: text; background-clip: text; color: transparent; }
.title-sub { font-family: 'Vazirmatn'; direction: rtl; font-weight: 900; font-size: clamp(1.2rem, 5vw, 1.8rem); margin: 6px 0 2px; color: #f9a8d4; }
.tagline { opacity: .7; font-size: .95rem; margin: 4px 0 0; }
.hs-badge { background: rgba(255,255,255,.06); border: 1px solid rgba(255,255,255,.12); padding: 8px 16px; border-radius: 999px; font-size: .9rem; backdrop-filter: blur(8px); }

/* Level cards */
.level-grid { display: flex; flex-direction: column; gap: 12px; margin-bottom: 24px; }
.level-card {
  display: flex; align-items: center; gap: 16px;
  padding: 18px 20px; border-radius: 22px; cursor: pointer;
  background: rgba(255,255,255,.05);
  border: 1.5px solid color-mix(in srgb, var(--c) 55%, transparent);
  color: var(--ink); text-align: left; width: 100%;
  transition: transform .15s ease, box-shadow .25s ease, background .2s;
}
.level-card:hover { transform: translateY(-3px) scale(1.015); box-shadow: 0 14px 40px var(--glow); background: color-mix(in srgb, var(--c) 14%, rgba(255,255,255,.04)); }
.level-card:active { transform: scale(.98); }
.lvl-emoji { font-size: 2rem; filter: drop-shadow(0 0 10px var(--glow)); }
.lvl-name { font-weight: 800; font-size: 1.25rem; }
.lvl-name .fa { font-weight: 700; }
.lvl-range { font-family: 'JetBrains Mono', monospace; font-size: .78rem; opacity: .6; margin-top: 2px; }
.lvl-arrow { font-size: 1.6rem; color: var(--c); font-weight: 800; }

/* Play top bar */
.quit-btn { background: rgba(255,255,255,.06); border: 1px solid rgba(255,255,255,.12); padding: 8px 14px; border-radius: 12px; color: var(--ink); font-weight: 700; cursor: pointer; }
.quit-btn:hover { background: rgba(255,255,255,.12); }
.lvl-chip { background: color-mix(in srgb, var(--c) 20%, transparent); border: 1px solid color-mix(in srgb, var(--c) 50%, transparent); padding: 8px 14px; border-radius: 999px; font-weight: 700; font-size: .9rem; }

/* Stats */
.stats-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 18px; }
.stat-pill { display: flex; align-items: center; gap: 10px; background: rgba(255,255,255,.06); border: 1px solid rgba(255,255,255,.1); border-radius: 18px; padding: 12px 14px; backdrop-filter: blur(8px); }

/* Timer */
.timer-wrap { position: relative; height: 30px; background: rgba(255,255,255,.08); border-radius: 999px; overflow: hidden; margin-bottom: 20px; border: 1px solid rgba(255,255,255,.1); }
.timer-bar { height: 100%; border-radius: 999px; transition: width .05s linear, background .3s; }
.timer-bar.pulse { animation: barpulse .5s ease-in-out infinite; }
@keyframes barpulse { 0%,100% { opacity: 1; } 50% { opacity: .55; } }
.timer-label { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-family: 'JetBrains Mono', monospace; font-weight: 800; font-size: .95rem; text-shadow: 0 1px 3px rgba(0,0,0,.6); }

/* Problem card */
.problem-card { background: rgba(255,255,255,.06); border: 1.5px solid rgba(255,255,255,.12); border-radius: 28px; padding: 30px 24px; text-align: center; backdrop-filter: blur(10px); box-shadow: 0 20px 60px rgba(0,0,0,.35); }
.problem-card.flash-ok { animation: pop 0.5s ease; border-color: #22c55e; box-shadow: 0 0 0 3px rgba(34,197,94,.4), 0 20px 60px rgba(34,197,94,.25); }
.problem-card.flash-bad { animation: shake 0.4s ease; border-color: #ef4444; box-shadow: 0 0 0 3px rgba(239,68,68,.4); }
@keyframes pop { 0%{transform:scale(1);} 40%{transform:scale(1.03);} 100%{transform:scale(1);} }
@keyframes shake { 0%,100%{transform:translateX(0);} 20%{transform:translateX(-10px);} 40%{transform:translateX(10px);} 60%{transform:translateX(-7px);} 80%{transform:translateX(7px);} }
.problem-text { font-family: 'JetBrains Mono', monospace; font-weight: 800; font-size: clamp(2.4rem, 11vw, 4rem); letter-spacing: -.02em; margin-bottom: 22px; text-shadow: 0 0 30px var(--glow); }

.answer-zone { display: flex; gap: 10px; align-items: stretch; }
.answer-input {
  flex: 1; min-width: 0; text-align: center;
  font-family: 'JetBrains Mono', monospace; font-weight: 800;
  font-size: clamp(1.8rem, 8vw, 2.6rem);
  padding: 12px 10px; border-radius: 18px;
  background: rgba(0,0,0,.3); border: 2px solid color-mix(in srgb, var(--c) 60%, transparent);
  color: #fff; outline: none;
}
.answer-input:focus { border-color: var(--c); box-shadow: 0 0 0 4px var(--glow); }
.answer-input:disabled { opacity: .6; }
.submit-btn {
  padding: 0 22px; border-radius: 18px; border: none; cursor: pointer;
  background: linear-gradient(135deg, var(--c), #ec4899);
  color: #fff; font-weight: 800; font-size: 1.05rem; white-space: nowrap;
  transition: transform .12s, filter .2s;
}
.submit-btn:hover { filter: brightness(1.12); }
.submit-btn:active { transform: scale(.95); }
.submit-btn:disabled { opacity: .5; cursor: default; }

/* Feedback */
.feedback { margin-top: 18px; font-weight: 700; font-size: 1.05rem; animation: fade-up .3s ease; }
.fb-ok { color: #86efac; }
.fb-bad { color: #fca5a5; }

/* Numpad (mobile) */
.hint-numpad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 18px; }
.np { padding: 16px 0; border-radius: 14px; background: rgba(255,255,255,.07); border: 1px solid rgba(255,255,255,.12); color: #fff; font-family: 'JetBrains Mono', monospace; font-weight: 800; font-size: 1.4rem; cursor: pointer; }
.np:active { background: rgba(255,255,255,.18); transform: scale(.95); }
.np-x { color: #fca5a5; }
.np-go { background: linear-gradient(135deg, var(--c), #ec4899); }

/* Results */
.results-hero { margin: 20px 0 26px; }
.tier-emoji { font-size: 5rem; filter: drop-shadow(0 0 24px var(--glow)); animation: bounceIn .6s ease; }
@keyframes bounceIn { 0%{transform:scale(0);} 60%{transform:scale(1.2);} 100%{transform:scale(1);} }
.tier-en { font-size: 2.2rem; font-weight: 800; margin: 8px 0 0; }
.tier-fa { font-weight: 900; font-size: 1.4rem; color: #f9a8d4; margin: 4px 0 0; }
.newhigh-badge { display: inline-block; margin-top: 14px; padding: 10px 20px; border-radius: 999px; background: linear-gradient(135deg,#f59e0b,#ef4444); font-weight: 800; animation: barpulse 1s infinite; }
.results-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.result-card { background: rgba(255,255,255,.06); border: 1px solid rgba(255,255,255,.12); border-radius: 20px; padding: 18px 14px; }
.result-value { font-size: 2rem; font-weight: 800; margin-top: 4px; }
.result-label { font-family: 'JetBrains Mono', monospace; font-size: .72rem; text-transform: uppercase; letter-spacing: .12em; opacity: .6; margin-top: 2px; }

.play-again { padding: 16px 28px; border-radius: 18px; border: none; cursor: pointer; background: linear-gradient(135deg, var(--c), #ec4899); color: #fff; font-weight: 800; font-size: 1.15rem; box-shadow: 0 12px 34px var(--glow); transition: transform .12s, filter .2s; }
.play-again:hover { filter: brightness(1.12); transform: translateY(-2px); }
.play-again:active { transform: scale(.96); }
.change-level { padding: 16px 24px; border-radius: 18px; cursor: pointer; background: rgba(255,255,255,.07); border: 1px solid rgba(255,255,255,.15); color: var(--ink); font-weight: 700; font-size: 1rem; }
.change-level:hover { background: rgba(255,255,255,.14); }

/* Footer */
.app-footer { text-align: center; margin-top: 34px; }
.app-footer a { color: rgba(255,255,255,.45); text-decoration: none; font-size: .85rem; font-family: 'JetBrains Mono', monospace; transition: color .2s; }
.app-footer a:hover { color: #f9a8d4; }

/* Confetti */
.confetti-layer { position: fixed; inset: 0; pointer-events: none; z-index: 50; overflow: hidden; }
.confetti-bit { position: absolute; top: -40px; animation: fall linear forwards; }
@keyframes fall { to { transform: translateY(105vh) rotate(540deg); opacity: 0; } }

/* Entrance */
.fade-up { animation: fade-up .5s ease both; }
@keyframes fade-up { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: translateY(0); } }