:root {
  --bg: #f4f2ee;
  --surface: #ffffff;
  --surface-2: #ece9e2;
  --text: #191c24;
  --muted: #5e6472;
  --border: #dedad0;
  --accent: #2e4bd1;
  --accent-ink: #ffffff;
  --accent-soft: #e3e8fc;
  --gold: #b07a1f;
  --key: #ffffff;
  --key-edge: #cfcabd;
  --key-text: #191c24;
  --shadow: 0 1px 2px rgb(25 28 36 / 6%), 0 10px 30px rgb(25 28 36 / 8%);
  --radius: 20px;
  --editor-size: 2rem;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-arabic: "Geeza Pro", "Noto Naskh Arabic", "Segoe UI", "Arabic Typesetting", "Traditional Arabic", serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d0f15; --surface: #161922; --surface-2: #1e222d; --text: #eceef3; --muted: #9aa1b0; --border: #2a2f3c;
    --accent: #8ea4ff; --accent-ink: #0d0f15; --accent-soft: #1f2748; --gold: #e3b45b;
    --key: #232734; --key-edge: #0a0c11; --key-text: #eceef3;
    --shadow: 0 1px 2px rgb(0 0 0 / 30%), 0 10px 30px rgb(0 0 0 / 30%);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0d0f15; --surface: #161922; --surface-2: #1e222d; --text: #eceef3; --muted: #9aa1b0; --border: #2a2f3c;
  --accent: #8ea4ff; --accent-ink: #0d0f15; --accent-soft: #1f2748; --gold: #e3b45b;
  --key: #232734; --key-edge: #0a0c11; --key-text: #eceef3;
  --shadow: 0 1px 2px rgb(0 0 0 / 30%), 0 10px 30px rgb(0 0 0 / 30%);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.55 var(--font); -webkit-font-smoothing: antialiased; }
a { color: var(--accent); text-underline-offset: 3px; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; border-radius: 6px; }
.ar { font-family: var(--font-arabic); direction: rtl; unicode-bidi: isolate; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.wrap { width: min(1040px, 100% - 32px); margin-inline: auto; }

/* Header */
.site-header { padding: 18px 0 8px; }
.site-header .wrap { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.brand { display: inline-flex; align-items: center; gap: 10px; color: var(--text); text-decoration: none; font-weight: 700; font-size: 1.1rem; letter-spacing: -0.01em; }
.brand-mark { width: 32px; height: 32px; border-radius: 9px; display: grid; place-items: center; background: var(--accent); color: var(--accent-ink); font-family: var(--font-arabic); font-size: 1.15rem; line-height: 1; padding-bottom: 3px; }
.site-nav { display: flex; gap: 4px; flex-wrap: wrap; }
.site-nav a { color: var(--muted); text-decoration: none; padding: 8px 12px; border-radius: 999px; font-size: 0.95rem; }
.site-nav a:hover { background: var(--surface-2); color: var(--text); }

/* Intro */
.intro { padding: clamp(18px, 4vw, 40px) 0 clamp(16px, 3vw, 28px); }
.intro h1 { margin: 0; font-size: clamp(1.9rem, 5vw, 3rem); line-height: 1.05; letter-spacing: -0.03em; }
.intro p { margin: 10px 0 0; color: var(--muted); font-size: 1.08rem; max-width: 46ch; }
.intro .example { color: var(--text); }
.intro kbd { font: 600 0.95em var(--font); background: var(--surface); border: 1px solid var(--border); border-bottom-width: 2px; border-radius: 6px; padding: 0 6px; }

/* Cards */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
main > section + section { margin-top: 24px; }

/* Editor */
.editor-card { overflow: hidden; }
.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 10px 16px; flex-wrap: wrap; padding: 12px 14px; }
.toolbar + .editor-wrap { border-top: 1px solid var(--border); }
.toolbar-group { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.switch { display: inline-flex; align-items: center; gap: 10px; font-size: 0.92rem; font-weight: 600; cursor: pointer; user-select: none; }
.switch input { appearance: none; width: 40px; height: 24px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); position: relative; margin: 0; cursor: pointer; transition: background .15s; }
.switch input::after { content: ""; position: absolute; top: 2px; left: 2px; width: 18px; height: 18px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgb(0 0 0 / 25%); transition: transform .15s; }
.switch input:checked { background: var(--accent); border-color: var(--accent); }
.switch input:checked::after { transform: translateX(16px); }
.segmented { display: inline-flex; background: var(--surface-2); border-radius: 999px; padding: 3px; gap: 2px; }
.segmented label { position: relative; }
.segmented input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.segmented span { display: block; padding: 5px 11px; border-radius: 999px; font-size: 0.85rem; color: var(--muted); white-space: nowrap; }
.segmented input:checked + span { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgb(0 0 0 / 12%); font-weight: 600; }
.segmented input:focus-visible + span { outline: 3px solid var(--gold); }
.segmented-label { font-size: 0.85rem; color: var(--muted); }

.editor-wrap { position: relative; }
#editor {
  display: block; width: 100%; min-height: 220px; resize: vertical; border: 0; outline: none; background: transparent;
  padding: 22px 24px; font-family: var(--font-arabic); font-size: var(--editor-size); line-height: 1.7; color: var(--text);
}
#editor::placeholder { color: var(--muted); opacity: 0.55; }
.editor-wrap:focus-within { box-shadow: inset 0 0 0 2px var(--accent-soft); }

.actions { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; padding: 12px 14px; border-top: 1px solid var(--border); background: color-mix(in srgb, var(--surface-2) 45%, var(--surface)); }
.count { font-size: 0.88rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.btn {
  display: inline-flex; align-items: center; gap: 7px; border: 1px solid var(--border); background: var(--surface); color: var(--text);
  border-radius: 999px; padding: 8px 14px; font-size: 0.92rem; font-weight: 500; text-decoration: none; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn svg { width: 17px; height: 17px; flex: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn-primary:hover { background: color-mix(in srgb, var(--accent) 88%, #000); }
.btn-icon { padding: 7px 10px; }

/* On-screen keyboard */
.keyboard { padding: 16px; display: grid; gap: 14px; }
.key-row { display: grid; grid-template-columns: repeat(10, minmax(0, 1fr)); gap: 7px; direction: rtl; }
.key-row.small { grid-template-columns: repeat(12, minmax(0, 1fr)); }
.key-group-title { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); margin: 4px 2px -6px; direction: ltr; }
.key {
  position: relative; display: grid; place-items: center; gap: 0; padding: 8px 2px 6px; min-height: 58px;
  background: var(--key); color: var(--key-text); border: 1px solid var(--border); border-bottom: 3px solid var(--key-edge);
  border-radius: 12px; touch-action: manipulation; user-select: none; -webkit-user-select: none; transition: transform .05s, border-bottom-width .05s;
}
.key:hover { border-color: var(--accent); border-bottom-color: color-mix(in srgb, var(--accent) 60%, var(--key-edge)); }
.key:active, .key.pressed { transform: translateY(2px); border-bottom-width: 1px; }
.key .glyph { font-family: var(--font-arabic); font-size: 1.6rem; line-height: 1.1; }
.key .hint { font-size: 0.7rem; color: var(--muted); direction: ltr; font-weight: 600; letter-spacing: 0.02em; min-height: 1em; }
.key.wide { grid-column: span 3; }
.key.wide .glyph { font-family: var(--font); font-size: 0.95rem; }

/* Help */
.help { padding: clamp(18px, 3vw, 28px); }
.help h2 { margin: 0 0 6px; font-size: 1.35rem; letter-spacing: -0.01em; }
.help > p { margin: 0 0 16px; color: var(--muted); }
.map { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 8px; margin: 0; padding: 0; list-style: none; }
.map li { display: flex; align-items: center; gap: 12px; padding: 8px 12px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); }
.map kbd { font: 700 0.95rem/1 ui-monospace, SFMono-Regular, Menlo, monospace; min-width: 2.4em; color: var(--accent); }
.map .ar { font-size: 1.5rem; line-height: 1; }
.map small { display: block; color: var(--muted); font-size: 0.75rem; line-height: 1.2; }
.map-title { margin: 22px 0 10px; font-size: 1rem; }
.prose-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 24px; }
.prose h3 { margin: 18px 0 6px; font-size: 1.05rem; }
.prose h3:first-child { margin-top: 0; }
.prose p { margin: 0 0 10px; color: var(--muted); }
.prose p strong { color: var(--text); }
.prose .example-ar { font-family: var(--font-arabic); font-size: 1.25em; color: var(--text); }

/* Footer */
.site-footer { margin: 48px 0 32px; color: var(--muted); font-size: 0.9rem; }
.site-footer .wrap { display: flex; flex-wrap: wrap; gap: 12px 24px; justify-content: space-between; border-top: 1px solid var(--border); padding-top: 20px; }
.site-footer nav { display: flex; gap: 18px; flex-wrap: wrap; }
.site-footer a { color: var(--muted); }

.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: 0.95rem;
  transition: opacity .2s, transform .2s; box-shadow: var(--shadow);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.page { max-width: 760px; padding: clamp(18px, 3vw, 28px); }
.page h1 { font-size: 2rem; letter-spacing: -0.02em; margin-top: 0; }
.page p { color: var(--muted); }

@media (max-width: 760px) {
  .prose-grid { grid-template-columns: 1fr; }
  .site-nav { display: none; }
}
@media (max-width: 560px) {
  .keyboard { padding: 10px 8px; gap: 10px; }
  .key-row { gap: 4px; }
  .key-row.small { grid-template-columns: repeat(6, minmax(0, 1fr)); }
  .key { min-height: 48px; border-radius: 9px; padding: 6px 0 4px; }
  .key .glyph { font-size: 1.3rem; }
  .key .hint { font-size: 0.6rem; }
  .key.wide { grid-column: span 3; }
  #editor { padding: 16px; min-height: 160px; }
  .toolbar { padding: 10px; }
  .actions .btn span.label-optional { display: none; }
}
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } .key, .toast, .switch input, .switch input::after { transition: none; } }

.key.span-2 { grid-column: span 2; }
.key.span-6 { grid-column: span 6; }
.key.action .glyph { font-family: var(--font); font-size: 0.95rem; font-weight: 600; }
.key.action svg { width: 22px; height: 22px; }
.key-row.marks { grid-template-columns: repeat(8, minmax(0, 1fr)); }
.key.mark { padding-top: 4px; }
.key.mark .glyph { font-size: 1.7rem; line-height: 1.9; }
@media (max-width: 560px) { .key-row.marks { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
@media (max-width: 560px) {
  #smaller, #bigger { display: none; }
  .toolbar { gap: 10px; }
  .actions .toolbar-group { width: 100%; flex-wrap: nowrap; }
  .actions .btn-primary { margin-left: auto; }
  .map { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .map li { gap: 8px; padding: 8px; }
  .map small { display: none; }
}

/* Arabic words and key names inside French sentences must not reorder their neighbours. */
.example-ar, .intro .example { direction: rtl; unicode-bidi: isolate; }
.help kbd, .prose kbd { unicode-bidi: isolate; font: 600 0.9em ui-monospace, SFMono-Regular, Menlo, monospace; background: var(--surface-2); border: 1px solid var(--border); border-radius: 5px; padding: 0 5px; color: var(--text); }

/* Theme toggle */
.header-actions { display: flex; align-items: center; gap: 8px; }
.theme-toggle {
  display: inline-flex; align-items: center; gap: 6px; min-height: 36px; padding: 6px 12px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text); font-size: 0.88rem;
}
.theme-toggle:hover { background: var(--surface-2); }
.theme-toggle svg { width: 17px; height: 17px; flex: none; }
@media (max-width: 480px) { .theme-toggle .theme-label { display: none; } .theme-toggle { padding: 6px 9px; } }
