/* =========================================================
   Number Hunter — Mobile-first dark/neon theme
   طراحی برای عرض ۳۶۰ تا ۴۳۰ پیکسل، پشتیبانی RTL/LTR
   ========================================================= */

:root {
  --bg: #0b0f1a;
  --bg2: #121829;
  --card: #171f33;
  --card2: #1e2740;
  --line: #263152;
  --text: #eaf0ff;
  --muted: #8fa0c7;
  --neon: #34e7c4;      /* سبز-فیروزه‌ای */
  --neon2: #7c5cff;     /* بنفش */
  --neon3: #ff5c8a;     /* صورتی */
  --gold: #ffd166;      /* ستاره */
  --danger: #ff4d6d;
  --ok: #3ddc84;
  --radius: 18px;
  --tap: 56px;          /* حداقل اندازه لمس */
  --sa-top: env(safe-area-inset-top, 0px);
  --sa-bottom: env(safe-area-inset-bottom, 0px);
  --shadow: 0 8px 24px rgba(0, 0, 0, .45);
}

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

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: Vazirmatn, "Segoe UI", Tahoma, system-ui, -apple-system, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;         /* جلوگیری از pull-to-refresh */
  touch-action: manipulation;        /* جلوگیری از double-tap zoom */
  -webkit-text-size-adjust: 100%;
}

body {
  background:
    radial-gradient(1000px 500px at 90% -10%, rgba(124, 92, 255, .18), transparent 60%),
    radial-gradient(800px 400px at -10% 110%, rgba(52, 231, 196, .14), transparent 60%),
    var(--bg);
}

button, select, input { font-family: inherit; color: inherit; }
button { border: none; cursor: pointer; background: none; }

.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 14px; }

/* ===== بوم افکت‌ها (confetti) ===== */
#fx {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 90;
}

/* ===== لایه اصلی ===== */
#app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: var(--sa-top) 12px calc(var(--sa-bottom) + 8px);
}

/* ===== نوار بالا ===== */
.topbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 4px;
}
.brand {
  font-weight: 800;
  font-size: 17px;
  letter-spacing: .3px;
  flex: 1;
  background: linear-gradient(90deg, var(--neon), var(--neon2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.top-actions { display: flex; align-items: center; gap: 8px; }

.chip {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 13px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.chip.combo {
  background: linear-gradient(135deg, var(--neon2), var(--neon3));
  border: none;
  animation: pop .3s ease;
}
.chip.time-chip { font-variant-numeric: tabular-nums; }

.icon-btn {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  background: var(--card);
  border: 1px solid var(--line);
  font-size: 18px;
  display: grid;
  place-items: center;
  transition: transform .12s ease, box-shadow .12s ease;
}
.icon-btn:active { transform: scale(.92); box-shadow: 0 0 0 3px rgba(52, 231, 196, .25); }
#btn-back { font-size: 26px; line-height: 1; }

/* ===== نوار زمان ===== */
#timer {
  height: 8px;
  border-radius: 999px;
  background: var(--card);
  overflow: hidden;
  margin: 2px 4px 10px;
  border: 1px solid var(--line);
}
#timer-fill {
  height: 100%;
  width: 100%;
  border-radius: 999px;
  background: var(--ok);
  transition: width .2s linear, background-color .5s ease;
  transform-origin: right center;
}
[dir="ltr"] #timer-fill { transform-origin: left center; }
#timer-fill.warn { background: var(--gold); }
#timer-fill.danger { background: var(--danger); }

/* ===== محتوا ===== */
main {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 8px;
}
.view { animation: fadeIn .25s ease; }

.section-title {
  font-size: 18px;
  margin: 6px 4px 12px;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}
.section-title .sub { font-size: 13px; color: var(--muted); font-weight: 400; }

/* ===== کارت عمومی ===== */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  text-align: center;
}
.daily-card { display: flex; flex-direction: column; align-items: center; gap: 12px; padding: 28px 20px; }
.daily-icon { font-size: 44px; }
.daily-date { font-size: 15px; color: var(--muted); }
.streak { font-size: 22px; font-weight: 800; color: var(--gold); }

/* ===== ماشین‌حساب ===== */
.calc-display {
  background: var(--bg2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
  min-height: 96px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: flex-end;
  overflow: hidden;
}
.calc-expr { color: var(--muted); font-size: 15px; min-height: 20px; word-break: break-all; }
.calc-result { font-size: 38px; font-weight: 300; word-break: break-all; }

.calc-pad {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}

/* ===== دکمه‌ها ===== */
.btn {
  min-height: var(--tap);
  border-radius: 16px;
  font-size: 21px;
  font-weight: 700;
  background: var(--card2);
  color: var(--text);
  border: 1px solid var(--line);
  transition: transform .1s ease, box-shadow .15s ease, filter .15s ease;
  user-select: none;
}
.btn:active {
  transform: scale(.94);
  box-shadow: 0 0 18px rgba(52, 231, 196, .35);
  filter: brightness(1.15);
}
.btn.num { background: var(--card2); }
.btn.op {
  background: linear-gradient(135deg, rgba(124, 92, 255, .35), rgba(124, 92, 255, .15));
  border-color: rgba(124, 92, 255, .5);
  color: #cfc4ff;
}
.btn.eq {
  background: linear-gradient(135deg, var(--neon), #17b89a);
  border: none;
  color: #06281f;
}
.btn.fn { background: var(--card); font-size: 16px; }
.btn.hint {
  background: linear-gradient(135deg, rgba(255, 209, 102, .25), rgba(255, 209, 102, .1));
  border-color: rgba(255, 209, 102, .55);
  color: var(--gold);
  font-size: 15px;
}
.btn.wide { grid-column: span 2; }
.btn.primary {
  background: linear-gradient(135deg, var(--neon), #17b89a);
  color: #06281f;
  border: none;
  font-size: 18px;
  padding-inline: 26px;
  min-width: 150px;
}
.btn:disabled { opacity: .4; pointer-events: none; }

/* ===== شبکه مراحل ===== */
.levels-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 10px;
}
.level-cell {
  aspect-ratio: 1;
  border-radius: 16px;
  background: var(--card);
  border: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-weight: 800;
  font-size: 18px;
  position: relative;
  transition: transform .12s ease;
}
.level-cell:active { transform: scale(.93); }
.level-cell.locked { opacity: .38; }
.level-cell.done {
  background: linear-gradient(160deg, rgba(52, 231, 196, .16), rgba(124, 92, 255, .12));
  border-color: rgba(52, 231, 196, .45);
}
.level-cell .lv-stars { font-size: 10px; letter-spacing: 1px; }
.level-cell .lock { font-size: 16px; }

/* ===== صفحه بازی ===== */
.game-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 4px 4px 10px;
  flex-wrap: wrap;
}
.game-label { font-size: 14px; color: var(--muted); font-weight: 700; flex: 1; }

.target-card {
  background: linear-gradient(160deg, var(--card2), var(--card));
  border: 1px solid rgba(52, 231, 196, .4);
  border-radius: var(--radius);
  padding: 14px;
  text-align: center;
  box-shadow: 0 0 30px rgba(52, 231, 196, .12), var(--shadow);
  margin-bottom: 12px;
}
.target-label { font-size: 13px; color: var(--muted); }
#target-num {
  font-size: 54px;
  font-weight: 900;
  line-height: 1.15;
  background: linear-gradient(90deg, var(--neon), var(--neon2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  font-variant-numeric: tabular-nums;
}

.expr-box {
  background: var(--bg2);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 14px;
  min-height: 64px;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  justify-content: center;
  margin-bottom: 10px;
}
.expr-text {
  font-size: 22px;
  font-weight: 700;
  word-break: break-all;
  text-align: end;
  min-height: 30px;
  font-variant-numeric: tabular-nums;
}
.expr-text .placeholder { color: var(--muted); font-size: 14px; font-weight: 400; }
.expr-text .tok-op { color: var(--neon2); padding: 0 4px; }
.expr-text .tok-used { color: var(--neon); }
.expr-val { font-size: 14px; color: var(--muted); font-variant-numeric: tabular-nums; }
.expr-val.bad { color: var(--danger); }

.feedback {
  font-size: 14px;
  text-align: center;
  padding: 6px;
  border-radius: 10px;
  margin-bottom: 8px;
  animation: fadeIn .2s ease;
}
.feedback.err { background: rgba(255, 77, 109, .15); color: var(--danger); }
.feedback.info { background: rgba(52, 231, 196, .12); color: var(--neon); }

/* کارت‌های عدد */
.cards {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
}
.num-card {
  min-width: 64px;
  min-height: var(--tap);
  padding: 8px 16px;
  font-size: 24px;
  font-weight: 800;
  border-radius: 16px;
  background: linear-gradient(160deg, var(--card2), var(--card));
  border: 1px solid var(--line);
  color: var(--text);
  font-variant-numeric: tabular-nums;
  transition: transform .12s ease, opacity .2s ease, box-shadow .2s ease;
  position: relative;
}
.num-card:active { transform: scale(.93); box-shadow: 0 0 16px rgba(124, 92, 255, .4); }
.num-card.used {
  opacity: .25;
  pointer-events: none;
  transform: scale(.9);
}
.num-card.hint-glow {
  animation: hintGlow 1s ease infinite;
}

/* کارت در حال پرواز به ماشین‌حساب */
.fly-clone {
  position: fixed;
  z-index: 80;
  pointer-events: none;
  transition: transform .38s cubic-bezier(.4, 0, .2, 1), opacity .38s ease;
}

/* ===== کیبورد بازی ===== */
.keypad {
  background: rgba(11, 15, 26, .9);
  backdrop-filter: blur(8px);
  border-top: 1px solid var(--line);
  padding: 10px 4px 6px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.kp-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}
.keypad .btn { font-size: 24px; }
.keypad .btn.fn { font-size: 14px; }

/* ===== ناوبری پایین ===== */
#tabbar {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  padding-top: 8px;
}
.tab-btn {
  min-height: var(--tap);
  border-radius: 14px;
  background: var(--card);
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  transition: transform .12s ease, color .15s ease, border-color .15s ease;
}
.tab-btn .ic { font-size: 20px; }
.tab-btn:active { transform: scale(.94); }
.tab-btn.active {
  color: var(--text);
  border-color: rgba(52, 231, 196, .55);
  background: linear-gradient(160deg, rgba(52, 231, 196, .14), rgba(124, 92, 255, .1));
}

/* ===== مودال‌ها ===== */
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(4, 7, 14, .72);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 16px;
  padding-bottom: calc(16px + var(--sa-bottom));
  animation: fadeIn .2s ease;
}
.sheet {
  width: 100%;
  max-width: 440px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 22px 22px 18px 18px;
  padding: 22px 18px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 14px;
  animation: slideUp .28s cubic-bezier(.2, .8, .3, 1);
  max-height: 86dvh;
  overflow-y: auto;
}
.sheet h3 { font-size: 20px; text-align: center; }

.field {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--bg2);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 15px;
}
.field select {
  background: var(--card2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 15px;
  min-height: 40px;
}
.field input[type="checkbox"] { width: 22px; height: 22px; accent-color: var(--neon); }
.rules { font-size: 13px; color: var(--muted); line-height: 1.9; }

.result-sheet { text-align: center; align-items: center; }
.result-stars { font-size: 40px; letter-spacing: 8px; min-height: 50px; }
.result-stars span { display: inline-block; opacity: 0; transform: scale(0); }
.result-stars span.on { animation: starPop .45s cubic-bezier(.2, 1.4, .4, 1) forwards; }
#result-title { font-size: 22px; }
.break {
  width: 100%;
  background: var(--bg2);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 14px;
  display: flex;
  flex-direction: column;
  gap: 7px;
}
.break .row { display: flex; justify-content: space-between; }
.break .row.total {
  border-top: 1px dashed var(--line);
  padding-top: 7px;
  font-weight: 800;
  font-size: 16px;
  color: var(--neon);
}
.result-actions { display: flex; gap: 10px; width: 100%; }
.result-actions .btn { flex: 1; }

/* ===== توست ===== */
.toast {
  position: fixed;
  bottom: calc(96px + var(--sa-bottom));
  left: 50%;
  transform: translateX(-50%);
  background: var(--card2);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 700;
  z-index: 110;
  box-shadow: var(--shadow);
  animation: fadeIn .2s ease;
  max-width: 90vw;
  text-align: center;
}

/* ===== لرزش صفحه ===== */
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-7px); }
  40% { transform: translateX(7px); }
  60% { transform: translateX(-5px); }
  80% { transform: translateX(5px); }
}
.shake-err { animation: shake .35s ease; }
.shake-win { animation: shake .5s ease; }

/* ===== انیمیشن‌ها ===== */
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { transform: translateY(40px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
@keyframes pop { 0% { transform: scale(.6); } 100% { transform: scale(1); } }
@keyframes starPop {
  0% { opacity: 0; transform: scale(0) rotate(-30deg); }
  70% { opacity: 1; transform: scale(1.3) rotate(8deg); }
  100% { opacity: 1; transform: scale(1) rotate(0); }
}
@keyframes hintGlow {
  0%, 100% { box-shadow: 0 0 6px rgba(255, 209, 102, .5); border-color: var(--gold); }
  50% { box-shadow: 0 0 22px rgba(255, 209, 102, .9); border-color: var(--gold); }
}
@keyframes targetPulse {
  0% { transform: scale(1); }
  50% { transform: scale(1.06); }
  100% { transform: scale(1); }
}
.target-card.pulse { animation: targetPulse .4s ease; }

/* کاهش انیمیشن برای کاربران حساس */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
