:root {
  --bg: #f6f5f1;
  --surface: #ffffff;
  --surface-2: #f0efe9;
  --border: #e2e0d8;
  --text: #1c1b18;
  --muted: #6b6960;
  --accent: #0f766e;
  --accent-ink: #ffffff;
  --accent-soft: #e0f2ef;
  --danger: #b42318;
  --key: #ffffff;
  --key-fn: #e9e7e0;
  --key-shadow: #d3d0c6;
  --key-active: #ccebe6;
  --shadow: 0 1px 2px rgb(0 0 0 / .04), 0 8px 24px rgb(0 0 0 / .06);
  --radius: 14px;
  --ui: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --ar-system: "Geeza Pro", "Arabic Typesetting", "Segoe UI", Tahoma, Arial, sans-serif;
  --ar: "Noto Naskh Arabic", var(--ar-system);
  --editor-font: var(--ar);
  --editor-size: 28px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121412;
    --surface: #1b1e1c;
    --surface-2: #232725;
    --border: #2f3431;
    --text: #ecebe6;
    --muted: #a3a29b;
    --accent: #2dd4bf;
    --accent-ink: #062b27;
    --accent-soft: #163a35;
    --danger: #f97066;
    --key: #2a2e2c;
    --key-fn: #222624;
    --key-shadow: #0b0c0b;
    --key-active: #1f4a44;
    --shadow: 0 1px 2px rgb(0 0 0 / .3), 0 8px 24px rgb(0 0 0 / .25);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #121412;
  --surface: #1b1e1c;
  --surface-2: #232725;
  --border: #2f3431;
  --text: #ecebe6;
  --muted: #a3a29b;
  --accent: #2dd4bf;
  --accent-ink: #062b27;
  --accent-soft: #163a35;
  --danger: #f97066;
  --key: #2a2e2c;
  --key-fn: #222624;
  --key-shadow: #0b0c0b;
  --key-active: #1f4a44;
  --shadow: 0 1px 2px rgb(0 0 0 / .3), 0 8px 24px rgb(0 0 0 / .25);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.6 var(--ui);
}
a { color: var(--accent); }
button, select, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
.ico { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.wrap { max-width: 1080px; margin: 0 auto; padding: 0 16px; }
[hidden] { display: none !important; }
.sprite { position: absolute; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- header ---------- */
.site-header { border-bottom: 1px solid var(--border); background: var(--surface); }
.site-header .wrap { display: flex; align-items: center; gap: 16px; min-height: 60px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; color: var(--text); text-decoration: none; }
.brand .logo { width: 32px; height: 32px; }
.brand .ar { font-family: var(--ar); font-weight: 700; color: var(--accent); }
.nav { display: flex; gap: 4px; margin-inline-start: auto; }
.nav a { color: var(--muted); text-decoration: none; padding: 6px 10px; border-radius: 8px; font-size: 15px; }
.nav a:hover { color: var(--text); background: var(--surface-2); }
.lang-switch { display: flex; gap: 2px; border: 1px solid var(--border); border-radius: 999px; padding: 2px; }
.lang-switch a { font-size: 13px; font-weight: 600; text-decoration: none; color: var(--muted); padding: 3px 9px; border-radius: 999px; }
.lang-switch a[aria-current] { background: var(--accent); color: var(--accent-ink); }
@media (max-width: 760px) { .nav { display: none; } .lang-switch { margin-inline-start: auto; } }

/* ---------- hero ---------- */
.hero { padding: 28px 0 18px; }
.hero h1 { margin: 0; font-size: clamp(26px, 4vw, 38px); line-height: 1.15; letter-spacing: -.02em; }
.hero h1 .ar, .hero h1 .h1-sub { color: var(--accent); font-weight: 700; white-space: nowrap; }
.hero h1 .ar, .hero h1 .h1-sub:lang(ar), :root[lang="ar"] .hero h1 { font-family: var(--ar); }
:root[lang="ar"] .hero h1 .h1-sub { font-family: var(--ui); font-size: .7em; }
:root[lang="ar"] body { font-size: 17px; }
:root[lang="ar"] .content h2, :root[lang="ar"] .content h3 { letter-spacing: 0; }
.hero p { margin: 8px 0 0; color: var(--muted); max-width: 70ch; }
@media (max-width: 600px) {
  .hero { padding: 16px 0 12px; }
  .hero p { font-size: 14px; line-height: 1.5; }
  .app { padding: 10px; }
  .seg { flex: 1; }
  .seg button { flex: 1; white-space: nowrap; padding: 6px 8px; }
  #editor { min-height: 130px; }
}

/* ---------- app card ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.app { padding: 14px; display: grid; gap: 12px; }

.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; justify-content: space-between; }
.seg { display: inline-flex; background: var(--surface-2); border-radius: 10px; padding: 3px; gap: 2px; }
.seg button { border: 0; background: transparent; padding: 6px 12px; border-radius: 8px; font-size: 14px; font-weight: 600; color: var(--muted); }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgb(0 0 0 / .12); }
.tb-right { display: flex; gap: 6px; align-items: center; }
.btn, .icon-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--border); background: var(--surface); border-radius: 10px;
  padding: 7px 12px; font-size: 14px; font-weight: 600; min-height: 38px; white-space: nowrap;
}
.icon-btn { padding: 7px 10px; min-width: 38px; }
.btn:hover, .icon-btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.primary:hover { filter: brightness(1.05); background: var(--accent); }
.btn.danger { color: var(--danger); }
.btn.rec { background: var(--danger); color: #fff; border-color: var(--danger); animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 6px rgb(220 38 38 / .2); } }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.editor-wrap { position: relative; }
#editor {
  width: 100%; min-height: 180px; resize: vertical; display: block;
  padding: 14px 16px; border: 1px solid var(--border); border-radius: 12px;
  background: var(--bg); color: var(--text);
  font-family: var(--editor-font); font-size: var(--editor-size); line-height: 1.7;
}
#editor:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
#editor::placeholder { color: var(--muted); opacity: .7; }

.suggest {
  display: flex; align-items: center; gap: 8px; min-height: 46px; padding: 6px 8px;
  border: 1px dashed var(--border); border-radius: 12px; background: var(--surface-2); overflow-x: auto;
}
.sg-latin { font: 600 14px/1 ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--muted); }
.sg-latin:empty { display: none; }
.sg-list { display: flex; gap: 6px; }
.sg-item { border: 1px solid var(--border); background: var(--surface); border-radius: 8px; padding: 2px 12px; font: 22px/1.5 var(--ar); }
.sg-item.on { border-color: var(--accent); background: var(--accent-soft); }
.sg-hint { font-size: 14px; color: var(--muted); }

.actions { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.actions .count { margin-inline-start: auto; font-size: 13px; color: var(--muted); }
@media (max-width: 600px) { .actions .btn .lbl { display: none; } .actions .btn.primary .lbl { display: inline; } }

details.menu { position: relative; }
details.menu > summary { list-style: none; }
details.menu > summary::-webkit-details-marker { display: none; }
.menu-panel {
  position: absolute; z-index: 20; top: calc(100% + 6px); inset-inline-end: 0; min-width: 240px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow);
  padding: 6px; display: grid; gap: 2px;
}
.actions .menu-panel { inset-inline-end: auto; inset-inline-start: 0; }
details.menu:not([open]) > .menu-panel { display: none; }
@media (max-width: 600px) {
  .menu-panel { position: fixed; inset: auto 12px 12px 12px; top: auto; max-height: 75vh; overflow-y: auto; }
  .actions .menu-panel { inset: auto 12px 12px 12px; }
}
.menu-panel button { text-align: start; border: 0; background: none; padding: 8px 10px; border-radius: 8px; font-size: 14px; display: flex; gap: 8px; align-items: center; }
.menu-panel button:hover { background: var(--surface-2); }
.settings { padding: 12px; gap: 10px; min-width: 260px; }
.settings label { display: grid; gap: 4px; font-size: 13px; font-weight: 600; color: var(--muted); }
.settings label.check { display: flex; align-items: center; gap: 8px; color: var(--text); font-weight: 500; font-size: 14px; }
.settings select { padding: 6px 8px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); }
.settings input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--accent); }

.translit-panel { border: 1px solid var(--border); border-radius: 12px; padding: 10px 14px; background: var(--surface-2); }
.translit-panel header { display: flex; justify-content: space-between; align-items: center; font-size: 13px; font-weight: 600; color: var(--muted); }
#translit-out { margin: 6px 0 0; font-size: 17px; white-space: pre-wrap; min-height: 1.6em; }

/* ---------- keyboard ---------- */
.kb { display: grid; gap: 6px; padding: 10px; background: var(--surface-2); border-radius: 12px; user-select: none; -webkit-user-select: none; touch-action: manipulation; }
.kb-row { display: grid; grid-template-columns: repeat(60, minmax(0, 1fr)); gap: 6px; }
.key {
  position: relative; height: 54px; border: 0; border-radius: 9px; padding: 0;
  background: var(--key); box-shadow: 0 2px 0 var(--key-shadow); color: var(--text);
  display: flex; align-items: center; justify-content: center; overflow: hidden;
  transition: transform .05s, background .1s;
  -webkit-tap-highlight-color: transparent;
}
.key.fn { background: var(--key-fn); color: var(--muted); }
.key:hover { background: var(--key-active); }
.key.active { transform: translateY(2px); box-shadow: 0 0 0 var(--key-shadow); background: var(--key-active); }
.key.on { background: var(--accent-soft); color: var(--accent); }
.key.lock::after { content: ""; position: absolute; top: 6px; inset-inline-end: 6px; width: 6px; height: 6px; border-radius: 50%; background: var(--accent); }
.k-main { font: 400 24px/1 var(--ar); }
.k-alt { position: absolute; top: 4px; left: 6px; font: 13px/1 var(--ar); color: var(--muted); }
.k-lat { position: absolute; bottom: 4px; right: 6px; font: 600 10px/1 var(--ui); color: var(--muted); opacity: .8; }
.k-fn { font-size: 15px; font-weight: 600; }
.key[data-code="Space"] .k-fn { font-family: var(--ar); font-weight: 400; }
.key[data-code="CopyKey"] { gap: 6px; background: var(--accent); color: var(--accent-ink); }
.key[data-code="CopyKey"] .k-fn { font-size: 13px; }
.kb.shifted .key.char .k-main { color: var(--accent); }
body[data-mode="off"] .kb { opacity: .9; }

@media (max-width: 700px) {
  .kb { padding: 6px; gap: 5px; margin-inline: -8px; }
  .kb-row { gap: 3px; }
  .key { height: 46px; border-radius: 6px; }
  .k-main { font-size: 19px; }
  .k-alt { font-size: 10px; top: 2px; left: 3px; }
  .k-lat { display: none; }
  .k-fn { font-size: 13px; }
  .key[data-code="CopyKey"] .k-fn { display: none; }
}
@media (max-width: 380px) { .k-alt { display: none; } .k-main { font-size: 17px; } }

/* ---------- extra characters ---------- */
.extras { display: grid; gap: 8px; }
.tabs { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; }
.tabs button { border: 1px solid var(--border); background: var(--surface); border-radius: 999px; padding: 5px 12px; font-size: 13px; font-weight: 600; color: var(--muted); white-space: nowrap; }
.tabs button[aria-selected="true"] { background: var(--text); color: var(--bg); border-color: var(--text); }
#extras-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(52px, 1fr)); gap: 6px; }
.xkey { border: 1px solid var(--border); background: var(--surface); border-radius: 9px; min-height: 48px; font: 24px/1.2 var(--ar); display: grid; place-items: center; padding: 4px 2px; }
.xkey small { font: 600 10px/1 var(--ui); color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
@media (max-width: 700px) { .xkey small { display: none; } #extras-grid { grid-template-columns: repeat(auto-fill, minmax(44px, 1fr)); } }
.xkey:hover { border-color: var(--accent); background: var(--accent-soft); }

/* ---------- link chips ---------- */
.links { display: flex; flex-wrap: wrap; gap: 6px 14px; align-items: center; font-size: 14px; }
.links .grp { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.links .grp-label { color: var(--muted); font-weight: 600; font-size: 13px; }
.chip { display: inline-flex; align-items: center; gap: 5px; border: 1px solid var(--border); border-radius: 999px; padding: 4px 11px; color: var(--text); text-decoration: none; font-size: 13px; font-weight: 600; background: var(--surface); }
.chip:hover { border-color: var(--accent); color: var(--accent); }

/* ---------- content ---------- */
.content { padding: 40px 0 20px; display: grid; gap: 44px; }
.content > *, .app > * { min-width: 0; }
.content h2 { font-size: clamp(22px, 3vw, 28px); line-height: 1.2; margin: 0 0 12px; letter-spacing: -.01em; }
.content h3 { font-size: 18px; margin: 18px 0 6px; }
.content p, .content li { max-width: 75ch; }
.content .lead { color: var(--muted); margin-top: -4px; }
.steps { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px; padding: 0; list-style: none; counter-reset: step; }
.steps li { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 16px; counter-increment: step; }
.steps li::before { content: counter(step); display: grid; place-items: center; width: 28px; height: 28px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); font-weight: 700; margin-bottom: 8px; }
.steps strong { display: block; margin-bottom: 4px; }
.features { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; padding: 0; list-style: none; }
.features li { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 14px 16px; }
.features strong { display: block; }
.features span { color: var(--muted); font-size: 14px; }
kbd { font: 600 12px/1 ui-monospace, SFMono-Regular, Menlo, monospace; border: 1px solid var(--border); border-bottom-width: 2px; border-radius: 5px; padding: 2px 5px; background: var(--surface); }

.table-scroll { overflow-x: auto; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); }
table { border-collapse: collapse; width: 100%; font-size: 15px; }
th, td { padding: 8px 12px; text-align: start; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); background: var(--surface-2); }
tr:last-child td { border-bottom: 0; }
td.ar { font: 26px/1.4 var(--ar); }
td.forms { font: 22px/1.4 var(--ar); }
td.forms span { display: inline-block; min-width: 2.2em; margin-inline-end: .5em; text-align: center; }
.ar-sm { font: 18px/1.4 var(--ar); }
code { font: 600 14px/1 ui-monospace, SFMono-Regular, Menlo, monospace; background: var(--surface-2); padding: 2px 6px; border-radius: 5px; }

.chart-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 8px; }
.chart-grid div { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 8px; text-align: center; }
.chart-grid .a { display: block; font: 28px/1.3 var(--ar); }
.chart-grid code { font-size: 13px; }

.faq details { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 0 16px; margin-bottom: 8px; }
.faq summary { cursor: pointer; font-weight: 600; padding: 14px 0; }
.faq details[open] summary { border-bottom: 1px solid var(--border); margin-bottom: 8px; }
.faq details p { margin: 0 0 14px; }

/* ---------- footer, toast ---------- */
.site-footer { border-top: 1px solid var(--border); margin-top: 40px; padding: 24px 0 40px; color: var(--muted); font-size: 14px; }
.site-footer .wrap { display: grid; gap: 8px; }
.site-footer nav { display: flex; flex-wrap: wrap; gap: 14px; }
#toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 999px; font-weight: 600; font-size: 14px;
  transition: opacity .2s, transform .2s; z-index: 50; max-width: calc(100% - 32px); text-align: center;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; scroll-behavior: auto !important; } }
