@import url("https://fonts.googleapis.com/css2?family=Vazirmatn:wght@400;500;600;700;800&family=JetBrains+Mono:wght@500;700&display=swap");

:root[data-theme="light"] {
  --bg: #f1ede3;
  --surface: #ffffff;
  --surface-2: #f7f4ec;
  --ink: #1e2433;
  --muted: #6b7078;
  --border: rgba(30, 36, 51, 0.12);
  --accent: #b5772a;
  --accent-ink: #ffffff;
  --rail: #2f3b52;
  --good: #3e8e7e;
  --bad: #c0533e;
  --shadow: 0 10px 30px rgba(30, 36, 51, 0.08);
}

:root[data-theme="dark"] {
  --bg: #10141d;
  --surface: #1a2130;
  --surface-2: #212a3c;
  --ink: #ece9df;
  --muted: #9aa3b6;
  --border: rgba(255, 255, 255, 0.09);
  --accent: #dc9a4c;
  --accent-ink: #1a1204;
  --rail: #dc9a4c;
  --good: #59b39f;
  --bad: #e17458;
  --shadow: 0 10px 34px rgba(0, 0, 0, 0.45);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
}

body {
  font-family: "Vazirmatn", "Tahoma", sans-serif;
  direction: rtl;
  line-height: 1.7;
  min-height: 100vh;
}

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px clamp(16px, 4vw, 40px);
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 800;
  font-size: 1.05rem;
}

.brand__mark {
  width: 30px; height: 30px;
  border-radius: 7px;
  background: var(--accent);
  display: grid;
  place-items: center;
  color: var(--accent-ink);
  font-family: "JetBrains Mono", monospace;
  font-weight: 700;
  font-size: 0.85rem;
}

.header-actions { display: flex; gap: 8px; align-items: center; }

.icon-btn {
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--ink);
  width: 38px; height: 38px;
  border-radius: 10px;
  cursor: pointer;
  display: grid;
  place-items: center;
  font-size: 1rem;
}
.icon-btn:hover { border-color: var(--accent); }

main#app {
  max-width: 980px;
  margin: 0 auto;
  padding: clamp(16px, 4vw, 32px);
  padding-bottom: 60px;
}

/* ---- buttons ---- */
.btn {
  font-family: inherit;
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 12px 18px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.08s ease, opacity 0.15s ease;
}
.btn:active { transform: scale(0.98); }
.btn--primary { background: var(--accent); color: var(--accent-ink); width: 100%; margin-top: 10px; }
.btn--ghost { background: transparent; border-color: var(--border); color: var(--ink); width: 100%; margin-top: 8px; }
.btn--danger { background: transparent; color: var(--bad); border-color: var(--bad); }
.btn--block { width: 100%; margin-top: 14px; }
.btn--sm { width: auto; padding: 6px 12px; font-size: 0.8rem; margin: 0; }
.btn[disabled] { opacity: 0.35; cursor: not-allowed; }

/* ---- hero / home ---- */
.hero { text-align: center; padding: 28px 0 20px; }
.hero__eyebrow { color: var(--accent); font-weight: 700; margin: 0 0 8px; }
.hero h1 { font-size: clamp(1.6rem, 4vw, 2.3rem); margin: 0 0 10px; }
.hero__sub { color: var(--muted); max-width: 560px; margin: 0 auto; }

.levels-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 16px;
  margin: 24px 0;
}

.level-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 18px;
  box-shadow: var(--shadow);
}
.level-card.locked { opacity: 0.92; }
.level-card__top { display: flex; align-items: center; justify-content: space-between; }
.level-card__top h3 { margin: 0; font-size: 1.15rem; }
.level-card__sub { color: var(--muted); font-size: 0.88rem; margin: 6px 0 12px; }
.level-card__meta { display: flex; gap: 14px; font-size: 0.82rem; color: var(--muted); margin-bottom: 6px; font-family: "JetBrains Mono", monospace; direction: ltr; justify-content: flex-end; }

.badge { font-size: 0.72rem; padding: 3px 10px; border-radius: 999px; font-weight: 700; }
.badge--free { background: color-mix(in srgb, var(--good) 18%, transparent); color: var(--good); }
.badge--lock { background: color-mix(in srgb, var(--accent) 20%, transparent); color: var(--accent); }

.modes {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 16px;
  margin-top: 8px;
}
.mode-card {
  background: var(--surface-2);
  border: 1px dashed var(--border);
  border-radius: 16px;
  padding: 18px;
}
.mode-card h3 { margin: 0 0 6px; }
.mode-card p { color: var(--muted); font-size: 0.9rem; margin: 0 0 6px; }

/* ---- modal ---- */
.modal { position: fixed; inset: 0; background: rgba(10, 12, 18, 0.55); display: grid; place-items: center; z-index: 40; padding: 16px; }
.modal[hidden] { display: none; }
.modal__box { background: var(--surface); border-radius: 16px; padding: 22px; width: min(420px, 100%); box-shadow: var(--shadow); }
.modal__box select { width: 100%; padding: 10px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface-2); color: var(--ink); font-family: inherit; margin-top: 10px; }
.modal__actions { display: flex; gap: 8px; margin-top: 16px; }
.modal__actions .btn { margin-top: 0; }

/* ---- exam screen ---- */
.exam__bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.exam__title { font-weight: 700; color: var(--muted); font-size: 0.9rem; }
.exam__timer {
  font-family: "JetBrains Mono", monospace;
  font-size: 1.3rem;
  font-weight: 700;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 6px 14px;
  direction: ltr;
}
.exam__timer--danger { color: var(--bad); border-color: var(--bad); animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: 0.55; } }

.exam__progress {
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--muted);
  font-size: 0.88rem;
  margin-bottom: 10px;
}

.palette {
  display: none;
  flex-wrap: wrap;
  gap: 6px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px;
  margin-bottom: 14px;
  max-height: 160px;
  overflow-y: auto;
}
.palette--open { display: flex; }
.pal-item {
  width: 32px; height: 32px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  font-family: "JetBrains Mono", monospace;
  font-size: 0.78rem;
  cursor: pointer;
}
.pal-item--current { border-color: var(--accent); color: var(--accent); font-weight: 700; }
.pal-item--answered { background: color-mix(in srgb, var(--good) 16%, var(--surface)); color: var(--good); }
.pal-item--skipped { background: color-mix(in srgb, var(--bad) 12%, var(--surface)); color: var(--bad); }

.stack-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 30px 20px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  align-items: center;
}
.stack { display: flex; flex-direction: column; align-items: stretch; min-width: 180px; }
.stack-row {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  font-family: "JetBrains Mono", monospace;
  font-size: clamp(1.4rem, 5vw, 2.1rem);
  font-weight: 700;
  direction: ltr;
  padding: 3px 0;
}
.stack-sign { color: var(--accent); width: 1.2ch; text-align: center; }
.stack-value { min-width: 5ch; text-align: left; }
.stack-rule { height: 3px; background: var(--ink); border-radius: 2px; margin-top: 6px; width: 100%; opacity: 0.8; }

.answer-row { margin: 18px 0 6px; }
.answer-row input {
  width: 100%;
  padding: 16px;
  font-size: 1.3rem;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--ink);
  text-align: center;
  font-family: "JetBrains Mono", monospace;
  direction: ltr;
}
.answer-row input:focus { outline: 2px solid var(--accent); }

.exam__nav { display: flex; gap: 8px; margin-top: 10px; }
.exam__nav .btn { margin-top: 0; }

/* ---- upgrade / paywall ---- */
.upgrade__lede { color: var(--muted); }
.upgrade__features { list-style: none; padding: 0; margin: 18px 0; display: grid; gap: 8px; }
.upgrade__price { display: flex; align-items: baseline; gap: 10px; margin: 18px 0; }
.upgrade__amount { font-size: 1.8rem; font-weight: 800; color: var(--accent); }
.upgrade__period { color: var(--muted); }
.upgrade__pay { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 18px; margin: 14px 0; }
.card-number { font-family: "JetBrains Mono", monospace; font-size: 1.2rem; letter-spacing: 2px; direction: ltr; text-align: center; padding: 10px; background: var(--surface-2); border-radius: 10px; margin-top: 8px; }
.upgrade__owner { color: var(--muted); font-size: 0.85rem; margin-top: 6px; }
.upgrade__activate { margin-top: 18px; }
.upgrade__activate-row { display: flex; gap: 8px; margin-top: 6px; }
.upgrade__activate-row input { flex: 1; padding: 12px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface-2); color: var(--ink); font-family: inherit; }
.upgrade__activate-row .btn { width: auto; margin: 0; }
.upgrade__note { font-size: 0.85rem; margin-top: 6px; color: var(--bad); }
.upgrade__note.ok { color: var(--good); }

/* ---- results ---- */
.results__sub { color: var(--muted); margin-top: -6px; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin: 18px 0; }
.stat-card { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 14px; text-align: center; }
.stat-card__value { font-family: "JetBrains Mono", monospace; font-size: 1.3rem; font-weight: 700; direction: ltr; }
.stat-card__label { color: var(--muted); font-size: 0.78rem; margin-top: 4px; }

.type-table { width: 100%; border-collapse: collapse; margin-top: 10px; font-size: 0.9rem; }
.type-table th, .type-table td { padding: 9px 8px; border-bottom: 1px solid var(--border); text-align: right; }
.type-table thead th { color: var(--muted); font-weight: 600; }
.row--weak td:first-child { border-right: 3px solid var(--bad); }
.row--strong td:first-child { border-right: 3px solid var(--good); }
.tip { font-size: 0.88rem; color: var(--muted); margin-top: 10px; }

.time-chart { margin-top: 26px; }
.bars { display: flex; align-items: flex-end; gap: 3px; height: 140px; overflow-x: auto; padding: 8px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; }
.bar { width: 6px; min-width: 6px; border-radius: 3px 3px 0 0; }
.bar--ok { background: var(--good); }
.bar--bad { background: var(--bad); }
.bar--skip { background: var(--border); }

.results__actions { display: grid; gap: 8px; margin-top: 20px; }
@media (min-width: 560px) {
  .results__actions { grid-template-columns: 1fr 1fr 1fr; }
  .results__actions .btn { margin-top: 0; }
}

.detail-list { margin-top: 18px; display: grid; gap: 8px; }
.detail-item { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 12px; }
.detail-item__stack { font-family: "JetBrains Mono", monospace; direction: ltr; text-align: left; color: var(--muted); font-size: 0.85rem; }
.detail-item__meta { display: flex; flex-wrap: wrap; gap: 12px; font-size: 0.85rem; margin-top: 6px; }

/* ---- history ---- */
.trend { display: flex; align-items: flex-end; gap: 4px; height: 120px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 8px; margin: 16px 0; }
.trend-bar { flex: 1; background: var(--accent); border-radius: 3px 3px 0 0; min-height: 4px; }
.empty { color: var(--muted); text-align: center; padding: 30px 0; }

footer.site-footer { text-align: center; color: var(--muted); font-size: 0.8rem; padding: 20px; }

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