/* ===== Ferming — design tokens ===== */
@font-face {
  font-family: 'Vazirmatn';
  src: url('../fonts/Vazirmatn-Variable.woff2') format('woff2-variations');
  font-weight: 100 900;
  font-display: swap;
}

:root {
  --color-bg: #fff8f0;
  --color-bg-alt: #fef1e2;
  --color-surface: #ffffff;
  --color-surface-2: #fff3e6;
  --color-ink: #2b2440;
  --color-ink-soft: #6b6380;
  --color-border: #f0e2ce;

  --color-primary: #ff6b4a;
  --color-primary-dark: #e2502f;
  --color-primary-tint: #ffe7de;

  --color-secondary: #5b4b8a;
  --color-secondary-tint: #ece7f7;

  --color-accent: #ffc94a;
  --color-accent-tint: #fff3d6;

  --color-good: #2fa66a;
  --color-good-tint: #e2f6ea;
  --color-warn: #e2502f;
  --color-warn-tint: #fde7e0;

  --radius-lg: 22px;
  --radius-md: 16px;
  --radius-sm: 10px;
  --shadow-card: 0 10px 30px -12px rgba(91, 75, 138, 0.25);
  --shadow-pop: 0 18px 45px -14px rgba(43, 36, 64, 0.35);

  --font-body: 'Vazirmatn', Tahoma, sans-serif;

  --tier-perfect: #2fa66a;
  --tier-excellent: #4fb87e;
  --tier-great: #7cbf5a;
  --tier-good: #f0a63c;
  --tier-fair: #f2864a;
  --tier-off: #ef6a4c;
  --tier-wild: #e2502f;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: linear-gradient(180deg, var(--color-bg) 0%, var(--color-bg-alt) 100%);
  color: var(--color-ink);
  font-family: var(--font-body);
  direction: rtl;
  text-align: right;
  line-height: 1.8;
  min-height: 100vh;
}

h1, h2, h3, h4 { margin: 0 0 .5em; font-weight: 800; }
p { margin: 0 0 1em; }
button { font-family: inherit; }
input { font-family: inherit; }
a { color: var(--color-primary-dark); }
.hidden { display: none !important; }
.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

/* ===== Shell ===== */
.app-shell {
  max-width: 640px;
  margin: 0 auto;
  padding: 0 16px calc(100px + env(safe-area-inset-bottom));
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 4px;
  background: linear-gradient(180deg, rgba(255,248,240,.97) 60%, rgba(255,248,240,0));
  backdrop-filter: blur(6px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 800;
  font-size: 1.25rem;
  color: var(--color-secondary);
  cursor: pointer;
  background: none;
  border: none;
  padding: 4px;
}
.brand .brand-mark {
  width: 36px; height: 36px;
  display: block;
  object-fit: contain;
  border-radius: 10px;
  box-shadow: var(--shadow-card);
}

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

.icon-btn {
  border: none;
  background: var(--color-surface);
  width: 40px; height: 40px;
  border-radius: 50%;
  display: grid; place-items: center;
  font-size: 1.1rem;
  color: var(--color-secondary);
  cursor: pointer;
  box-shadow: 0 4px 12px -4px rgba(91,75,138,.25);
  transition: transform .15s ease;
}
.icon-btn:active { transform: scale(.92); }
.icon-btn.is-account { color: var(--color-primary); }

.streak-chip {
  display: flex; align-items: center; gap: 4px;
  background: var(--color-accent-tint);
  color: #8a5a00;
  border-radius: 999px;
  padding: 6px 12px;
  font-weight: 700;
  font-size: .85rem;
}

.puzzle-num-chip {
  display: flex; align-items: center;
  background: var(--color-secondary-tint);
  color: var(--color-secondary);
  border-radius: 999px;
  padding: 6px 12px;
  font-weight: 700;
  font-size: .85rem;
  direction: ltr;
}

main { flex: 1; }

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: none;
  border-radius: 999px;
  padding: 14px 24px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform .12s ease, box-shadow .12s ease, opacity .12s ease;
  font-family: inherit;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn--primary {
  background: linear-gradient(135deg, var(--color-primary), #ff8a5c);
  color: #fff;
  box-shadow: 0 10px 24px -8px rgba(255,107,74,.6);
  width: 100%;
}
.btn--secondary {
  background: var(--color-secondary);
  color: #fff;
  width: 100%;
}
.btn--ghost {
  background: var(--color-surface);
  color: var(--color-secondary);
  border: 1.5px solid var(--color-border);
}
.btn--sm { padding: 8px 16px; font-size: .85rem; }
.btn--block { width: 100%; }
.btn--text {
  background: none; color: var(--color-secondary);
  padding: 8px; text-decoration: underline;
}

/* ===== Cards ===== */
.card {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow-card);
  margin-bottom: 16px;
}

/* ===== Intro view ===== */
.hero {
  text-align: center;
  padding: 20px 4px 8px;
}
.hero-emoji {
  display: flex; justify-content: center; align-items: center;
  color: var(--color-primary);
  margin-bottom: 10px;
}
.hero h1 {
  font-size: 1.9rem;
  background: linear-gradient(135deg, var(--color-primary), var(--color-secondary));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.hero .sub { color: var(--color-ink-soft); font-size: 1.02rem; }

.how-it-works { display: flex; flex-direction: column; gap: 14px; }
.how-step {
  display: flex; gap: 14px; align-items: flex-start;
}
.how-step .num {
  flex: none;
  width: 34px; height: 34px;
  border-radius: 50%;
  background: var(--color-primary-tint);
  color: var(--color-primary-dark);
  display: grid; place-items: center;
  font-weight: 800;
}
.how-step h3 { margin: 0 0 4px; font-size: 1.02rem; }
.how-step p { margin: 0; color: var(--color-ink-soft); font-size: .95rem; }

.example-box {
  background: var(--color-surface-2);
  border-radius: var(--radius-md);
  padding: 16px 18px;
  font-size: .92rem;
  color: var(--color-ink);
}
.example-box strong { color: var(--color-secondary); }

/* ===== Progress dots ===== */
.progress-dots {
  display: flex; gap: 8px; justify-content: center; margin: 4px 0 18px;
}
.progress-dots .dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--color-border);
  transition: background .2s, transform .2s;
}
.progress-dots .dot.is-done { background: var(--color-good); }
.progress-dots .dot.is-current { background: var(--color-primary); transform: scale(1.3); }

/* ===== Question view ===== */
.archive-banner {
  background: var(--color-surface-2);
  color: var(--color-secondary);
  border-radius: var(--radius-md);
  padding: 10px 16px;
  font-size: .85rem;
  font-weight: 700;
  text-align: center;
  margin-bottom: 12px;
}
.category-badge {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--color-primary-tint);
  color: var(--color-primary-dark);
  font-weight: 700;
  font-size: .82rem;
  padding: 6px 12px;
  border-radius: 999px;
  margin-bottom: 12px;
}

.question-text {
  font-size: 1.28rem;
  font-weight: 700;
  line-height: 1.9;
  margin-bottom: 6px;
}

.concept-chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0 4px; }
.concept-chip {
  background: var(--color-accent-tint);
  color: #8a5a00;
  border: none;
  border-radius: 999px;
  padding: 6px 14px;
  font-size: .82rem;
  font-weight: 700;
  cursor: pointer;
}
.concept-panel {
  background: var(--color-accent-tint);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  margin-top: 10px;
  font-size: .9rem;
  color: #5c3d00;
}
.concept-panel strong { display: block; margin-bottom: 4px; }

.guess-form { margin-top: 18px; }
.guess-label {
  display: block;
  font-weight: 700;
  margin-bottom: 8px;
  color: var(--color-ink-soft);
  font-size: .92rem;
}
.guess-input-row {
  display: flex;
  align-items: stretch;
  gap: 8px;
}
.guess-input {
  flex: 1;
  min-width: 0;
  font-size: 1.4rem;
  font-weight: 800;
  text-align: center;
  padding: 14px 10px;
  border-radius: var(--radius-md);
  border: 2px solid var(--color-border);
  background: var(--color-bg-alt);
  color: var(--color-ink);
  direction: ltr;
}
.guess-input:focus { outline: none; border-color: var(--color-primary); }
.unit-tag {
  flex: none;
  display: grid; place-items: center;
  padding: 0 14px;
  border-radius: var(--radius-md);
  background: var(--color-secondary-tint);
  color: var(--color-secondary);
  font-weight: 700;
  font-size: .88rem;
  max-width: 40%;
  text-align: center;
}
.calc-toggle-btn {
  flex: none;
  width: 54px;
  border-radius: var(--radius-md);
  border: 2px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-secondary);
  display: grid; place-items: center;
  font-size: 1.2rem;
  cursor: pointer;
}
.field-error { color: var(--color-warn); font-size: .85rem; margin-top: 8px; min-height: 1.2em; }

/* ===== Calculator ===== */
.calculator {
  margin-top: 14px;
  background: var(--color-ink);
  border-radius: var(--radius-md);
  padding: 14px;
  box-shadow: var(--shadow-pop);
}
.calc-display {
  color: #fff;
  font-size: 1.6rem;
  font-weight: 700;
  text-align: left;
  direction: ltr;
  padding: 10px 6px;
  min-height: 1.6em;
  word-break: break-all;
}
.calc-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-top: 8px;
}
.calc-key {
  border: none;
  border-radius: 12px;
  background: rgba(255,255,255,.08);
  color: #fff;
  font-size: 1.1rem;
  font-weight: 700;
  padding: 14px 0;
  cursor: pointer;
}
.calc-key:active { background: rgba(255,255,255,.2); }
.calc-key--op { background: var(--color-primary); }
.calc-key--eq { background: var(--color-good); }
.calc-key--use { background: var(--color-accent); color: #4a3400; grid-column: span 2; }
.calc-key--clear { background: var(--color-warn); }

/* ===== Reveal view ===== */
.reveal-score {
  text-align: center;
  padding: 6px 0 10px;
}
.reveal-score .multiplier {
  font-size: 2.6rem;
  font-weight: 800;
  color: var(--color-primary-dark);
}
.reveal-score .tier-tag {
  display: inline-block;
  margin-top: 4px;
  padding: 5px 14px;
  border-radius: 999px;
  font-weight: 700;
  font-size: .85rem;
  color: #fff;
}
.reveal-comment {
  text-align: center;
  font-size: 1.05rem;
  font-weight: 600;
  margin: 10px 0 18px;
}
.reveal-compare {
  text-align: center;
  font-size: .85rem;
  color: var(--color-ink-soft);
  margin: -12px 0 18px;
}

.reveal-scale {
  position: relative;
  height: 44px;
  margin: 18px 4px 30px;
  direction: ltr;
}
.reveal-scale .track {
  position: absolute; top: 20px; right: 0; left: 0; height: 4px;
  background: var(--color-border);
  border-radius: 4px;
}
.reveal-scale .marker {
  position: absolute; top: 8px;
  width: 2px; height: 28px;
  transform: translateX(50%);
}
.reveal-scale .marker .dot {
  position: absolute; top: -6px; right: -6px;
  width: 14px; height: 14px; border-radius: 50%;
  border: 3px solid #fff;
  box-shadow: 0 2px 8px rgba(0,0,0,.2);
}
.reveal-scale .marker .label {
  position: absolute; top: 30px; right: 50%;
  transform: translateX(50%);
  white-space: nowrap;
  font-size: .78rem;
  font-weight: 700;
}
.reveal-scale .marker.guess { background: var(--color-secondary); z-index: 3; }
.reveal-scale .marker.guess .dot { background: var(--color-secondary); }
.reveal-scale .marker.answer { background: var(--color-good); z-index: 3; }
.reveal-scale .marker.answer .dot { background: var(--color-good); }
.reveal-scale .marker.other {
  width: 1px; height: 12px; top: 16px;
  background: transparent;
  z-index: 1;
}
.reveal-scale .marker.other .dot {
  width: 6px; height: 6px; top: -3px; right: -3px;
  border-width: 1px;
  background: var(--color-ink-soft);
  opacity: .45;
  box-shadow: none;
}

.explanation-box {
  background: var(--color-surface-2);
  border-radius: var(--radius-md);
  padding: 16px 18px;
  font-size: .96rem;
}
.explanation-box h4 { color: var(--color-secondary); margin-bottom: 6px; font-size: .95rem; }
.scale-note {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-top: 12px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  border: 1px dashed var(--color-secondary);
  color: var(--color-secondary);
  font-size: .85rem;
  font-weight: 700;
  line-height: 1.6;
}
.scale-note svg { flex: none; margin-top: 2px; }

/* ===== Summary view ===== */
.summary-title {
  text-align: center;
  font-size: 1.6rem;
  margin-top: 4px;
}
.summary-score {
  text-align: center;
  color: var(--color-ink-soft);
  margin-bottom: 18px;
}
.summary-score b { color: var(--color-primary-dark); font-size: 1.3rem; }
.summary-compare {
  text-align: center;
  font-size: .85rem;
  color: var(--color-ink-soft);
  margin-top: -12px;
  margin-bottom: 18px;
}

.recap-item {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--color-border);
}
.recap-item:last-child { border-bottom: none; }
.recap-item .recap-text { flex: 1; font-size: .92rem; }
.recap-item .recap-score {
  flex: none;
  font-weight: 800;
  padding: 4px 10px;
  border-radius: 999px;
  color: #fff;
  font-size: .85rem;
}

.share-actions { display: flex; gap: 10px; margin-top: 16px; }
.share-actions .btn { flex: 1; }

/* ===== Tabs ===== */
.tabs { display: flex; gap: 8px; margin-bottom: 16px; }
.tab-btn {
  flex: 1;
  border: none;
  background: var(--color-surface);
  padding: 12px 8px;
  border-radius: var(--radius-md);
  font-weight: 700;
  color: var(--color-ink-soft);
  cursor: pointer;
  box-shadow: 0 2px 8px -4px rgba(91,75,138,.2);
}
.tab-btn.is-active { background: var(--color-secondary); color: #fff; }

/* ===== Leaderboard ===== */
.lb-row {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
}
.lb-row.is-viewer { background: var(--color-primary-tint); }
.lb-rank {
  flex: none; width: 28px; text-align: center;
  font-weight: 800; color: var(--color-ink-soft);
}
.lb-name { flex: 1; font-weight: 700; }
.lb-name .account-tag { font-size: .7rem; color: var(--color-good); margin-inline-start: 4px; }
.lb-score { flex: none; font-weight: 800; color: var(--color-primary-dark); }

/* ===== Archive ===== */
.archive-day-row {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  box-shadow: 0 2px 8px -4px rgba(91,75,138,.15);
  margin-bottom: 8px;
  cursor: pointer;
  border: none;
  width: 100%;
  text-align: right;
  font-family: inherit;
}
.archive-day-row.is-today { background: var(--color-primary-tint); }
.archive-day-row .arc-num {
  flex: none; width: 40px; text-align: center;
  font-weight: 800; color: var(--color-secondary); font-size: .85rem;
}
.archive-day-row .arc-info { flex: 1; }
.archive-day-row .arc-date { font-weight: 700; font-size: .92rem; }
.archive-day-row .arc-sub { font-size: .78rem; color: var(--color-ink-soft); }
.archive-day-row .arc-score {
  flex: none; font-weight: 800; color: var(--color-primary-dark); font-size: .9rem;
}
.archive-day-row .arc-badge {
  flex: none; font-size: .75rem; font-weight: 700;
  padding: 3px 10px; border-radius: 999px;
  background: var(--color-accent-tint); color: #8a5a00;
}

/* ===== State placeholders (loading / empty / error) ===== */
.state-box {
  text-align: center;
  padding: 36px 16px;
  color: var(--color-ink-soft);
}
.state-box .state-emoji { font-size: 2.2rem; margin-bottom: 10px; }
.state-box.is-error { color: var(--color-warn); }
.spinner {
  width: 30px; height: 30px;
  border-radius: 50%;
  border: 4px solid var(--color-border);
  border-top-color: var(--color-primary);
  margin: 0 auto 14px;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== Profile ===== */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-bottom: 18px;
}
.stat-tile {
  background: var(--color-surface-2);
  border-radius: var(--radius-md);
  padding: 16px;
  text-align: center;
}
.stat-tile .val { font-size: 1.5rem; font-weight: 800; color: var(--color-secondary); }
.stat-tile .lbl { font-size: .82rem; color: var(--color-ink-soft); }

.history-item {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--color-border);
  font-size: .9rem;
}
.history-item:last-child { border-bottom: none; }

.progress-chart {
  width: 100%;
  height: 140px;
  display: block;
}
.progress-chart .bar { fill: var(--color-primary); }
.progress-chart .bar:hover { fill: var(--color-primary-dark); }
.progress-chart .axis-label {
  font-family: var(--font-body);
  font-size: 9px;
  fill: var(--color-ink-soft);
}
.chart-empty-note { text-align: center; color: var(--color-ink-soft); font-size: .85rem; padding: 20px 0; }

.marathon-cta { margin-top: 16px; }
.marathon-cta p { color: var(--color-ink-soft); font-size: .92rem; margin: 8px 0 14px; }

.lives-row { display: flex; justify-content: center; gap: 8px; margin: 4px 0 18px; }
.lives-row .life svg { width: 22px; height: 22px; stroke: var(--color-primary); stroke-width: 2; transition: fill .2s, stroke .2s; }
.lives-row .life.is-alive svg { fill: var(--color-primary); }
.lives-row .life.is-lost svg { fill: none; stroke: var(--color-border); }

.life-lost-note {
  display: flex; align-items: center; justify-content: center; gap: 6px;
  color: var(--color-primary); font-weight: 700; font-size: .85rem; margin: -12px 0 18px;
}

.dist-chart-block { margin-top: 14px; }
.dist-chart-title {
  font-size: .78rem;
  font-weight: 700;
  color: var(--color-ink-soft);
  margin-bottom: 4px;
}
.dist-hist {
  width: 100%;
  height: 100px;
  display: block;
  direction: ltr;
}
.dist-hist .dist-bar { fill: var(--color-border); }
.dist-hist .dist-bar.is-you { fill: var(--color-secondary); }
.dist-hist .dist-you-line {
  stroke: var(--color-secondary);
  stroke-width: 1.5;
  stroke-dasharray: 3 2;
}
.dist-hist .dist-you-label {
  font-family: var(--font-body);
  font-size: 10px;
  font-weight: 800;
  fill: var(--color-secondary);
}
.dist-hist .dist-axis-label {
  font-family: var(--font-body);
  font-size: 9px;
  fill: var(--color-ink-soft);
}

/* ===== Bottom nav ===== */
.bottom-nav {
  position: fixed;
  left: 50%;
  bottom: calc(14px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  width: calc(100% - 32px);
  max-width: 420px;
  display: flex;
  gap: 8px;
  background: var(--color-surface);
  padding: 10px;
  border-radius: 999px;
  box-shadow: var(--shadow-pop);
  z-index: 30;
}
.bottom-nav button {
  flex: 1;
  background: none;
  border: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 6px 0;
  font-size: .74rem;
  font-weight: 700;
  color: var(--color-ink-soft);
  cursor: pointer;
}
.bottom-nav button .bn-icon { font-size: 1.25rem; }
.bottom-nav button.is-active { color: var(--color-primary-dark); }

/* ===== Modal (auth) ===== */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(43,36,64,.55);
  display: flex; align-items: flex-end;
  justify-content: center;
  z-index: 50;
  padding: 0;
}
@media (min-width: 560px) {
  .modal-backdrop { align-items: center; padding: 20px; }
}
.modal-sheet {
  background: var(--color-bg);
  width: 100%;
  max-width: 480px;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  padding: 26px 22px 30px;
  box-shadow: var(--shadow-pop);
  max-height: 92vh;
  overflow-y: auto;
}
@media (min-width: 560px) {
  .modal-sheet { border-radius: var(--radius-lg); }
}
.modal-close {
  border: none; background: var(--color-surface-2);
  width: 34px; height: 34px; border-radius: 50%;
  float: left; cursor: pointer; font-size: 1rem;
  color: var(--color-ink-soft);
  display: grid; place-items: center;
}
.form-field { margin-bottom: 14px; }
.form-field label { display: block; font-weight: 700; font-size: .88rem; margin-bottom: 6px; }
.form-field input {
  width: 100%;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 2px solid var(--color-border);
  background: var(--color-surface);
  font-size: 1rem;
}
.form-field input:focus { outline: none; border-color: var(--color-primary); }
.form-error {
  background: var(--color-warn-tint); color: var(--color-warn);
  border-radius: var(--radius-sm);
  padding: 10px 14px; font-size: .88rem; margin-bottom: 14px;
}
.form-success {
  background: var(--color-good-tint); color: var(--color-good);
  border-radius: var(--radius-sm);
  padding: 10px 14px; font-size: .88rem; margin-bottom: 14px;
}
.muted-note { color: var(--color-ink-soft); font-size: .85rem; text-align: center; margin-top: 10px; }

/* ===== Toast ===== */
.toast {
  position: fixed;
  bottom: 90px;
  right: 50%;
  transform: translateX(50%);
  background: var(--color-ink);
  color: #fff;
  padding: 12px 20px;
  border-radius: 999px;
  font-size: .88rem;
  z-index: 60;
  box-shadow: var(--shadow-pop);
  animation: toast-in .2s ease;
}
@keyframes toast-in { from { opacity: 0; transform: translate(50%, 10px);} to { opacity:1; transform: translateX(50%);} }

/* ===== Utility ===== */
.text-center { text-align: center; }
.mt-0 { margin-top: 0; }
.flex-row { display: flex; align-items: center; gap: 8px; }
.section-title { font-size: 1.15rem; margin-bottom: 12px; }

@media (min-width: 640px) {
  .app-shell { padding: 0 24px calc(100px + env(safe-area-inset-bottom)); }
}
