:root {
  --bg: #f5f5f7;
  --surface: #ffffff;
  --surface-2: #fafafa;
  --text: #1d1d1f;
  --muted: #6e6e73;
  --line: #e5e5ea;
  --line-strong: #d2d2d7;
  --accent: #111111;
  --accent-text: #ffffff;
  --danger: #c4281c;
  --danger-bg: #fdecea;
  --ok: #1e7b34;
  --ok-bg: #e9f6ec;
  --info-bg: #f0f0f3;
  --focus: rgba(0, 0, 0, 0.18);
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 8px 24px rgba(0, 0, 0, 0.04);
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: #000000;
  --surface: #1c1c1e;
  --surface-2: #232325;
  --text: #f5f5f7;
  --muted: #a1a1a6;
  --line: #2c2c2e;
  --line-strong: #3a3a3c;
  --accent: #f5f5f7;
  --accent-text: #000000;
  --danger: #ff6b5e;
  --danger-bg: #3a1714;
  --ok: #4cd168;
  --ok-bg: #12301a;
  --info-bg: #262628;
  --focus: rgba(255, 255, 255, 0.25);
  --shadow: none;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "IBM Plex Sans Arabic", -apple-system, BlinkMacSystemFont, "Segoe UI", Tahoma, sans-serif;
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; }
a.link { color: var(--text); font-weight: 600; text-decoration: underline; text-underline-offset: 3px; text-decoration-thickness: 1px; }
a.link:hover { text-decoration-thickness: 2px; }

/* ---------- top bar */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  height: 60px; padding: 0 20px;
  background: color-mix(in srgb, var(--surface) 86%, transparent);
  backdrop-filter: saturate(180%) blur(16px);
  -webkit-backdrop-filter: saturate(180%) blur(16px);
  border-bottom: 1px solid var(--line);
}
.brand { display: inline-flex; align-items: center; gap: 10px; text-decoration: none; font-weight: 700; font-size: 18px; letter-spacing: -0.01em; }
.brand-mark { display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 9px; background: var(--accent); color: var(--accent-text); font-size: 15px; font-weight: 700; }
.brand small { color: var(--muted); font-weight: 500; font-size: 13px; }
.topbar-actions { display: flex; align-items: center; gap: 8px; }

/* ---------- theme toggle */
.theme-toggle { width: 36px; min-height: 36px; padding: 0; }
.theme-toggle svg { width: 18px; height: 18px; }
.theme-toggle .icon-sun { display: none; }
:root[data-theme="dark"] .theme-toggle .icon-sun { display: block; }
:root[data-theme="dark"] .theme-toggle .icon-moon { display: none; }

/* ---------- buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 18px;
  border-radius: 999px; border: 1px solid transparent;
  font: inherit; font-weight: 600; font-size: 15px; text-decoration: none; cursor: pointer;
  transition: opacity .15s ease, background-color .15s ease, border-color .15s ease;
}
.btn:focus-visible, .input:focus-visible, .check input:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.btn-primary { background: var(--accent); color: var(--accent-text); }
.btn-primary:hover { opacity: .88; }
.btn-secondary { background: transparent; color: var(--text); border-color: var(--line-strong); }
.btn-secondary:hover { background: var(--surface-2); }
.btn-ghost { background: transparent; color: var(--text); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-danger { background: transparent; color: var(--danger); border-color: var(--line-strong); }
.btn-sm { min-height: 36px; padding: 0 14px; font-size: 14px; }
.btn-block { width: 100%; }
.btn[disabled] { opacity: .5; cursor: default; }

/* ---------- auth layout */
.auth {
  display: grid; grid-template-columns: minmax(0, 440px) minmax(0, 380px);
  justify-content: center; align-items: start; gap: 56px;
  max-width: 1040px; margin: 0 auto; padding: 48px 20px 64px;
}
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 32px; box-shadow: var(--shadow);
}
.card h1 { margin: 0 0 6px; font-size: 26px; line-height: 1.25; letter-spacing: -0.02em; }
.card .lead { margin: 0 0 24px; color: var(--muted); }

.products h2 { margin: 6px 0 20px; font-size: 20px; letter-spacing: -0.01em; }
.product { display: flex; align-items: center; gap: 14px; padding: 12px 0; border-bottom: 1px solid var(--line); text-decoration: none; }
.product:last-child { border-bottom: 0; }
.tile {
  flex: none; display: grid; place-items: center; width: 44px; height: 44px; border-radius: 12px;
  color: #fff; font-weight: 700; font-size: 15px; letter-spacing: -0.02em;
}
.tile-img { background: #fff; border: 1px solid var(--line); padding: 7px; }
.tile-img img { display: block; width: 100%; height: 100%; object-fit: contain; }
.product .meta strong { display: block; font-size: 15px; }
.product .meta span { display: block; color: var(--muted); font-size: 13px; }
.products-note { margin-top: 18px; color: var(--muted); font-size: 13px; }

/* ---------- forms */
.form { display: grid; gap: 16px; }
.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field { display: grid; gap: 6px; }
.field label { font-size: 14px; font-weight: 600; }
.field .hint { color: var(--muted); font-size: 13px; }
.input {
  width: 100%; min-height: 46px; padding: 10px 14px;
  border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text); font: inherit; font-size: 16px;
}
.input:focus { border-color: var(--text); }
.input[readonly] { background: var(--surface-2); color: var(--muted); }
.input.code { text-align: center; letter-spacing: .5em; font-size: 22px; font-variant-numeric: tabular-nums; direction: ltr; }
.ltr { direction: ltr; text-align: start; }
[dir="rtl"] .ltr { text-align: right; }
.check { display: flex; align-items: flex-start; gap: 10px; font-size: 14px; }
.check input { width: 18px; height: 18px; margin: 2px 0 0; accent-color: var(--accent); flex: none; }
.form-foot { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; font-size: 14px; }
.divider { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: 13px; margin: 6px 0; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.switch-line { margin-top: 20px; text-align: center; color: var(--muted); font-size: 14px; }

/* ---------- notices */
.alert { padding: 12px 14px; border-radius: var(--radius-sm); font-size: 14px; margin-bottom: 16px; }
.alert-error { background: var(--danger-bg); color: var(--danger); }
.alert-ok { background: var(--ok-bg); color: var(--ok); }
.alert-info { background: var(--info-bg); color: var(--text); }

/* ---------- account page */
.page { max-width: 760px; margin: 0 auto; padding: 32px 20px 64px; }
.page-head { display: flex; align-items: center; gap: 16px; margin-bottom: 28px; }
.avatar { display: grid; place-items: center; width: 56px; height: 56px; border-radius: 50%; background: var(--accent); color: var(--accent-text); font-weight: 700; font-size: 20px; flex: none; }
.page-head h1 { margin: 0; font-size: 24px; letter-spacing: -0.02em; }
.page-head p { margin: 2px 0 0; color: var(--muted); }
.section { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 20px; box-shadow: var(--shadow); scroll-margin-top: 80px; }
.section-head { padding: 20px 24px 0; }
.section-head h2 { margin: 0; font-size: 18px; letter-spacing: -0.01em; }
.section-head p { margin: 4px 0 0; color: var(--muted); font-size: 14px; }
.section-body { padding: 16px 24px 24px; }
.list { list-style: none; margin: 0; padding: 0; }
.list-item { display: flex; align-items: center; gap: 14px; padding: 14px 0; border-bottom: 1px solid var(--line); }
.list-item:last-child { border-bottom: 0; padding-bottom: 0; }
.list-item .grow { flex: 1; min-width: 0; }
.list-item strong { display: block; }
.list-item small { display: block; color: var(--muted); font-size: 13px; overflow-wrap: anywhere; }
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 2px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--info-bg); color: var(--muted); white-space: nowrap; }
.badge-ok { background: var(--ok-bg); color: var(--ok); }
.kv { display: flex; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.kv:last-child { border-bottom: 0; }
.kv span { color: var(--muted); }
details.fold summary { cursor: pointer; list-style: none; }
details.fold summary::-webkit-details-marker { display: none; }
details.fold[open] summary { margin-bottom: 14px; }

/* ---------- consent */
.consent-pair { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 12px; margin: 8px 0 24px; }
.consent-box { border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 14px; text-align: center; min-width: 0; }
.consent-box .tile { margin: 0 auto 8px; }
.consent-box strong { display: block; font-size: 14px; }
.consent-box small { display: block; color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }
.consent-arrow { color: var(--muted); font-size: 20px; }
.consent-points { margin: 0 0 24px; padding: 0; list-style: none; display: grid; gap: 10px; font-size: 14px; }
.consent-points li { display: flex; gap: 10px; }
.consent-points li::before { content: "•"; color: var(--muted); }
.actions { display: flex; gap: 10px; flex-wrap: wrap; }
.actions .btn { flex: 1; }

/* ---------- 2FA setup */
.qr { display: block; width: 184px; height: 184px; margin: 4px auto 12px; background: #fff; border-radius: 12px; padding: 8px; }
.secret { text-align: center; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 14px; letter-spacing: .06em; color: var(--muted); direction: ltr; overflow-wrap: anywhere; }

/* ---------- legal */
.prose h1 { font-size: 26px; margin: 0 0 12px; }
.prose h2 { font-size: 17px; margin: 24px 0 8px; }
.prose p, .prose li { color: var(--text); }

.footer { text-align: center; color: var(--muted); font-size: 13px; padding: 24px 20px 40px; }
.footer a { color: var(--muted); }
.footer .sep { margin: 0 8px; }

@media (max-width: 900px) {
  .auth { grid-template-columns: minmax(0, 520px); gap: 32px; padding-top: 24px; }
  .products { order: 2; }
}
@media (max-width: 520px) {
  .topbar { padding: 0 16px; }
  .brand small, .hide-xs { display: none; }
  .auth, .page { padding-left: 16px; padding-right: 16px; }
  .card { padding: 24px 20px; border-radius: 0; border-left: 0; border-right: 0; margin: 0 -16px; box-shadow: none; }
  .row-2 { grid-template-columns: 1fr; }
  .section-head { padding: 18px 18px 0; }
  .section-body { padding: 14px 18px 20px; }
  .consent-pair { grid-template-columns: 1fr; }
  .consent-arrow { transform: rotate(90deg); justify-self: center; }
}

/* ---------- phase 2: developer site, platform settings */
.topbar-start { display: flex; align-items: center; gap: 22px; min-width: 0; }
.topnav { display: flex; gap: 4px; }
.topnav a { padding: 6px 10px; border-radius: 8px; text-decoration: none; color: var(--muted); font-weight: 600; font-size: 14px; }
.topnav a:hover { color: var(--text); background: var(--surface-2); }
.brand-mark-sm { width: 22px; height: 22px; font-size: 12px; border-radius: 7px; background: var(--accent-text); color: var(--accent); }
.page-wide { max-width: 1040px; }
.hero { padding: 24px 0 32px; }
.hero h1 { font-size: 34px; line-height: 1.2; letter-spacing: -0.03em; margin: 0 0 10px; }
.hero .lead { color: var(--muted); font-size: 17px; max-width: 640px; margin: 0 0 22px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; margin-bottom: 24px; }
.card-link { display: block; text-decoration: none; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); transition: border-color .15s ease; }
.card-link:hover { border-color: var(--line-strong); }
.card-link strong { display: block; font-size: 16px; margin-bottom: 6px; }
.card-link span { color: var(--muted); font-size: 14px; }
.keybox { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding: 14px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface-2); margin-bottom: 12px; }
.keybox code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 14px; overflow-wrap: anywhere; min-width: 0; flex: 1; }
.code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 12px 14px; overflow-x: auto; white-space: pre; margin: 8px 0; }
.subhead { font-size: 15px; margin: 22px 0 4px; }
.back-link { display: inline-block; margin-bottom: 14px; color: var(--muted); font-size: 14px; text-decoration: none; }
.back-link::before { content: "→ "; }
[dir="ltr"] .back-link::before { content: "← "; }
.check-row { justify-content: space-between; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); }
.check-row .grow { flex: 1; min-width: 0; }
.check-row strong { display: block; font-size: 14px; }
.check-row small { display: block; color: var(--muted); font-size: 13px; }
.switch { appearance: none; -webkit-appearance: none; width: 42px !important; height: 26px !important; border-radius: 999px; background: var(--line-strong); position: relative; cursor: pointer; transition: background .15s ease; margin: 0 !important; }
.switch::after { content: ""; position: absolute; top: 3px; inset-inline-start: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.2); transition: inset-inline-start .15s ease; }
.switch:checked { background: var(--accent); }
.switch:checked::after { inset-inline-start: 19px; }
:root[data-theme="dark"] .switch:checked::after { background: #000; }
.kv-value { display: flex; align-items: center; gap: 6px; min-width: 0; }
.kv-value b { overflow-wrap: anywhere; }
.actions-inline { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }
.actions-inline .btn { flex: none; }
.warn { color: #b25e00 !important; }
.hint { color: var(--muted); font-size: 13px; }
@media (max-width: 760px) {
  .grid-3 { grid-template-columns: 1fr; }
  .topnav { display: none; }
  .hero h1 { font-size: 26px; }
}
