/* Base elements, layout primitives, buttons, navigation, footer. */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ar);
  font-size: 16px;
  line-height: 1.7;
  min-height: 100dvh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  transition: background-color var(--normal), color var(--normal);
}
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; cursor: pointer; background: none; border: 0; padding: 0; }
input, textarea, select { font: inherit; color: inherit; }
img { max-width: 100%; display: block; }
[dir='ltr'], .en { font-family: var(--font-en); }
h1, h2, h3, h4 { margin: 0; line-height: 1.25; font-weight: 700; }
p { margin: 0; }
::selection { background: var(--accent-soft); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }

.display { font-family: var(--font-display); letter-spacing: -0.01em; }
.muted { color: var(--text-muted); }
.faint { color: var(--text-faint); }
.accent { color: var(--accent); }
.grad-text { background: var(--grad-text); -webkit-background-clip: text; background-clip: text; color: transparent; }
.container { width: 100%; max-width: var(--container); margin-inline: auto; padding-inline: 24px; }
.narrow { max-width: 48rem; }
.stack { display: flex; flex-direction: column; }
.row { display: flex; align-items: center; gap: 12px; }
.spacer { flex: 1; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 10px 20px; border-radius: 999px;
  font-weight: 700; font-size: 15px; white-space: nowrap;
  background: var(--surface); border: 1px solid var(--border); color: var(--text);
  transition: transform var(--fast) var(--ease), background-color var(--fast), box-shadow var(--fast), opacity var(--fast);
}
.btn:hover { background: var(--surface-hover); }
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--grad); border-color: transparent; color: #fff; box-shadow: var(--glow); }
.btn-primary:hover { background: var(--grad); filter: brightness(1.08); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: var(--surface); }
.btn-lg { min-height: 56px; padding: 14px 32px; font-size: 18px; }
.btn-sm { min-height: 34px; padding: 6px 14px; font-size: 13px; }
.btn-block { width: 100%; }
.btn[disabled] { opacity: 0.5; pointer-events: none; }
.icon-btn {
  display: inline-grid; place-items: center; width: 40px; height: 40px; border-radius: 999px;
  color: var(--text-muted); transition: background-color var(--fast), color var(--fast);
}
.icon-btn:hover { background: var(--surface); color: var(--text); }
.icon { width: 20px; height: 20px; flex: 0 0 auto; }

.pill {
  display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px;
  background: var(--surface); color: var(--text-muted); font-size: 12px; font-weight: 500;
}
.pill-accent { background: var(--accent-soft); color: var(--accent); }
.kbd { font-family: var(--font-mono); font-size: 12px; padding: 1px 6px; border-radius: 6px; border: 1px solid var(--border); background: var(--bg-elev); }

/* ---------- Cards ---------- */
.card { background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--r-xl); }
.card-pad { padding: 24px; }
.surface { background: var(--surface); border-radius: var(--r-lg); }

/* ---------- Level badge ---------- */
.lvl { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text-muted); }
.lvl::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: var(--lvl-color, var(--lvl-1)); }
.lvl-A1 { --lvl-color: var(--lvl-1); }
.lvl-A2 { --lvl-color: var(--lvl-2); }
.lvl-B1 { --lvl-color: var(--lvl-3); }
.lvl-B2 { --lvl-color: var(--lvl-4); }
.lvl-C1 { --lvl-color: var(--lvl-5); }

/* ---------- Logo ---------- */
.logo { display: inline-flex; align-items: center; gap: 9px; line-height: 1; }
.logo svg { width: 24px; height: 24px; }
.logo-word { font-family: var(--font-en); font-weight: 700; font-size: 25px; letter-spacing: -0.035em; background: var(--grad-text); -webkit-background-clip: text; background-clip: text; color: transparent; padding-bottom: 2px; }

/* ---------- Top navigation (marketing + app) ---------- */
.topbar {
  position: sticky; top: 0; z-index: 40;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: saturate(1.4) blur(14px); -webkit-backdrop-filter: saturate(1.4) blur(14px);
  border-bottom: 1px solid var(--border);
}
.topbar-inner { display: flex; align-items: center; gap: 16px; height: 64px; }
.topbar-links { display: flex; gap: 28px; margin-inline: auto; font-size: 15px; color: var(--text-muted); }
.topbar-links a { transition: color var(--fast); }
.topbar-links a:hover, .topbar-links a.active { color: var(--text); }
.topbar-actions { display: flex; align-items: center; gap: 6px; }
.nav-badge { min-width: 18px; height: 18px; padding: 0 5px; border-radius: 999px; background: var(--accent); color: var(--accent-ink); font-size: 11px; font-weight: 700; display: inline-grid; place-items: center; margin-inline-start: 4px; }

/* Bottom tab bar (app, phones) */
.tabbar { display: none; }
@media (max-width: 760px) {
  .topbar-links { display: none; }
  .tabbar {
    position: fixed; inset-inline: 0; bottom: 0; z-index: 40; display: grid; grid-template-columns: repeat(5, 1fr);
    background: color-mix(in srgb, var(--bg-elev) 92%, transparent); backdrop-filter: blur(14px);
    border-top: 1px solid var(--border); padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  }
  .tabbar a { display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 11px; color: var(--text-faint); padding: 4px 0; position: relative; }
  .tabbar a.active { color: var(--accent); }
  .tabbar .nav-badge { position: absolute; top: 0; inset-inline-start: 55%; }
  body.has-tabbar { padding-bottom: 72px; }
}

/* ---------- Footer ---------- */
.footer { border-top: 1px solid var(--border); background: var(--bg-elev); margin-top: 96px; }
.footer-cta { display: flex; align-items: center; justify-content: space-between; gap: 24px; padding-block: 56px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.footer-cta h3 { font-family: var(--font-display); font-size: 28px; }
.footer-grid { display: grid; grid-template-columns: 1.4fr 1fr 1fr 1fr; gap: 32px; padding-block: 40px; }
.footer-grid h4 { font-size: 15px; margin-bottom: 14px; }
.footer-grid a { display: block; color: var(--text-muted); font-size: 15px; padding: 3px 0; }
.footer-grid a:hover { color: var(--text); }
.footer-bottom { display: flex; justify-content: space-between; gap: 12px; padding-block: 20px 32px; border-top: 1px solid var(--border); color: var(--text-faint); font-size: 13px; flex-wrap: wrap; }
@media (max-width: 760px) { .footer-grid { grid-template-columns: 1fr 1fr; } }

/* ---------- Page scaffolding ---------- */
.page { padding-block: 32px 64px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 24px; flex-wrap: wrap; }
.page-title { font-family: var(--font-display); font-size: clamp(28px, 4vw, 40px); }
.page-sub { color: var(--text-muted); font-size: 17px; margin-top: 6px; max-width: 40rem; }
.section-title { font-family: var(--font-display); font-size: 24px; margin: 40px 0 16px; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.section-title a { font-family: var(--font-ar); font-size: 14px; font-weight: 500; color: var(--accent); }
.back-link { display: inline-flex; align-items: center; gap: 6px; color: var(--text-muted); font-size: 15px; margin-bottom: 16px; }
.back-link:hover { color: var(--text); }
.empty { text-align: center; color: var(--text-muted); padding: 48px 16px; }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 960px) { .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 600px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } .container { padding-inline: 16px; } }

/* ---------- Form controls ---------- */
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 14px; color: var(--text-muted); }
.input, .textarea, .select {
  width: 100%; padding: 12px 16px; border-radius: var(--r-lg); border: 1px solid var(--border);
  background: var(--bg-elev); font-size: 16px; transition: border-color var(--fast), box-shadow var(--fast);
}
.input:focus, .textarea:focus, .select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
.textarea { min-height: 140px; resize: vertical; line-height: 1.7; }
.segmented { display: inline-flex; padding: 4px; gap: 4px; border-radius: 999px; background: var(--surface); flex-wrap: wrap; }
.segmented button { padding: 6px 14px; border-radius: 999px; font-size: 14px; color: var(--text-muted); }
.segmented button.on { background: var(--bg-elev); color: var(--text); box-shadow: var(--shadow); }

/* ---------- Progress ---------- */
.progress { height: 6px; border-radius: 999px; background: var(--surface); overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--grad); border-radius: inherit; transform-origin: right; transition: width var(--normal) var(--ease); }

/* ---------- Toast ---------- */
.toast {
  position: fixed; bottom: 28px; left: 50%; z-index: 100; transform: translate(-50%, 16px); opacity: 0; pointer-events: none;
  background: var(--text); color: var(--bg); padding: 10px 20px; border-radius: 999px; font-weight: 500; font-size: 15px;
  box-shadow: var(--shadow); transition: opacity var(--normal) var(--ease), transform var(--normal) var(--ease);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
@media (max-width: 760px) { .toast { bottom: 96px; } }

/* ---------- Modal ---------- */
.modal-backdrop { position: fixed; inset: 0; z-index: 90; background: #000a; display: grid; place-items: center; padding: 16px; animation: fade-in var(--normal) var(--ease); }
.modal { width: min(520px, 100%); max-height: 90dvh; overflow: auto; padding: 28px; }
@keyframes fade-in { from { opacity: 0; } }
@keyframes rise-in { from { opacity: 0; transform: translateY(12px); } }
.rise { animation: rise-in 500ms var(--ease) both; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 1ms !important; transition-duration: 1ms !important; scroll-behavior: auto !important; }
}

.made-by { font-family: var(--font-en); letter-spacing: 0.01em; }
.made-by b { background: var(--grad-text); -webkit-background-clip: text; background-clip: text; color: transparent; font-weight: 700; }
