:root {
  --bg: #f6f7f5;
  --surface: #ffffff;
  --surface-2: #eef1ef;
  --text: #1c2321;
  --muted: #5d6a66;
  --border: #d9dfdc;
  --accent: #0f766e;
  --accent-contrast: #ffffff;
  --key: #ffffff;
  --key-shadow: #c9d1ce;
  --key-special: #e4e9e7;
  --key-active: #ccefe9;
  --ar-font: 'Noto Naskh Arabic', serif;
  --text-size: 28px;
  --radius: 10px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111615;
    --surface: #1a201f;
    --surface-2: #222a28;
    --text: #e6ece9;
    --muted: #9aa8a3;
    --border: #2f3936;
    --accent: #2bb3a3;
    --accent-contrast: #062b27;
    --key: #252d2b;
    --key-shadow: #0b0f0e;
    --key-special: #1d2422;
    --key-active: #1f4b45;
  }
}
:root[data-theme="dark"] {
  --bg: #111615;
  --surface: #1a201f;
  --surface-2: #222a28;
  --text: #e6ece9;
  --muted: #9aa8a3;
  --border: #2f3936;
  --accent: #2bb3a3;
  --accent-contrast: #062b27;
  --key: #252d2b;
  --key-shadow: #0b0f0e;
  --key-special: #1d2422;
  --key-active: #1f4b45;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  line-height: 1.5;
}

.wrap { max-width: 1000px; margin: 0 auto; padding: 0 16px; }

.site-header { border-bottom: 1px solid var(--border); background: var(--surface); }
.header-inner { display: flex; align-items: center; justify-content: space-between; height: 56px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; color: var(--text); text-decoration: none; }
.brand-logo {
  display: grid; place-items: center; width: 34px; height: 34px; border-radius: 8px;
  background: var(--accent); color: var(--accent-contrast);
  font-family: 'Amiri', serif; font-size: 22px; line-height: 1;
}

.hero { padding: 28px 0 12px; }
.hero h1 { font-size: clamp(1.5rem, 4vw, 2.1rem); margin: 0 0 6px; line-height: 1.25; }
.hero h1 .ar { display: inline-block; font-family: 'Amiri', serif; font-weight: 400; color: var(--accent); }
.lead { color: var(--muted); margin: 0; max-width: 65ch; }

.tool {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px;
  margin: 16px 0 32px;
}

.toolbar { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.toolbar-group { display: flex; flex-wrap: wrap; gap: 6px; }

.btn {
  font: inherit; font-size: 0.9rem;
  padding: 7px 12px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
  cursor: pointer;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); color: var(--accent-contrast); border-color: var(--accent); font-weight: 600; }

.icon-btn {
  font: inherit; cursor: pointer; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text);
  width: 36px; height: 36px; border-radius: 8px; font-size: 1.1rem;
}
.icon-btn.small { width: auto; height: 30px; padding: 0 8px; font-size: 0.85rem; }

.editor { border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg); overflow: hidden; }
.editor:focus-within { border-color: var(--accent); }
#text {
  display: block; width: 100%; min-height: 160px; resize: vertical;
  border: 0; outline: 0; padding: 14px 16px;
  background: transparent; color: var(--text);
  font-family: var(--ar-font); font-size: var(--text-size); line-height: 1.7;
}
.editor-footer {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px;
  padding: 6px 10px; border-top: 1px solid var(--border); background: var(--surface);
  font-size: 0.85rem; color: var(--muted);
}
.editor-settings { display: flex; align-items: center; gap: 10px; }
.editor-settings select {
  font: inherit; margin-left: 4px; padding: 3px 6px; border-radius: 6px;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
}
.size-ctrl { display: flex; gap: 4px; }

.options { display: flex; flex-wrap: wrap; gap: 6px 18px; margin: 12px 2px; font-size: 0.9rem; color: var(--muted); }
.switch { display: flex; align-items: center; gap: 6px; cursor: pointer; }
.switch input { accent-color: var(--accent); width: 16px; height: 16px; }

/* ---------- Clavier ---------- */
.keyboard {
  display: flex; flex-direction: column; gap: 6px;
  padding: 10px; border-radius: var(--radius); background: var(--surface-2);
  user-select: none; -webkit-user-select: none; touch-action: manipulation;
}
.kb-row { display: flex; gap: 6px; }
.key {
  position: relative; flex: 1 1 0; min-width: 0;
  height: 56px; padding: 0;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--key); color: var(--text);
  box-shadow: 0 2px 0 var(--key-shadow);
  cursor: pointer; font: inherit;
  transition: transform .05s, background .1s;
}
.key:hover { border-color: var(--accent); }
.key.pressed, .key:active { transform: translateY(2px); box-shadow: 0 0 0 var(--key-shadow); background: var(--key-active); }
.key .main { font-family: var(--ar-font); font-size: 1.45rem; line-height: 1; }
.key .alt {
  position: absolute; top: 3px; left: 6px;
  font-family: var(--ar-font); font-size: 0.85rem; color: var(--muted);
}
.key .latin { position: absolute; bottom: 3px; right: 6px; font-size: 0.65rem; color: var(--muted); text-transform: uppercase; }
.keyboard.phonetic .key .latin { text-transform: none; }

.keyboard.shift .key[data-code] .alt { position: static; display: block; font-size: 1.45rem; color: var(--text); }
.keyboard.shift .key[data-code] .main { display: none; }

.key.special { background: var(--key-special); font-size: 0.85rem; color: var(--muted); }
.key.special.on { background: var(--accent); color: var(--accent-contrast); border-color: var(--accent); }
.key.space { flex-grow: 6; }

.hint { font-size: 0.85rem; color: var(--muted); margin: 10px 2px 0; }
kbd {
  font-family: inherit; font-size: 0.8em; padding: 1px 6px;
  border: 1px solid var(--border); border-bottom-width: 2px; border-radius: 4px; background: var(--surface-2);
}

/* ---------- Contenu ---------- */
.content { padding-bottom: 32px; max-width: 75ch; }
.content h2 { font-size: 1.3rem; margin: 28px 0 10px; }
.content ol { padding-left: 20px; }
.content li { margin-bottom: 6px; }
details { border: 1px solid var(--border); border-radius: 8px; background: var(--surface); margin-bottom: 8px; padding: 10px 14px; }
summary { cursor: pointer; font-weight: 600; }
details p { margin: 8px 0 0; color: var(--muted); }

.site-footer { border-top: 1px solid var(--border); padding: 18px 0; font-size: 0.85rem; color: var(--muted); }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px);
  background: var(--text); color: var(--bg); padding: 8px 16px; border-radius: 8px;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; font-size: 0.9rem;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- Mobile ---------- */
@media (max-width: 640px) {
  .tool { padding: 10px; margin-left: -6px; margin-right: -6px; }
  .keyboard { padding: 6px 3px; gap: 4px; }
  .kb-row { gap: 3px; }
  .key { height: 46px; border-radius: 6px; }
  .key .main { font-size: 1.15rem; }
  .key .alt { font-size: 0.65rem; top: 1px; left: 3px; }
  .keyboard.shift .key[data-code] .alt { font-size: 1.15rem; }
  .key .latin { display: none; }
  .key.special { font-size: 0.7rem; }
  .key.hide-mobile { display: none; }
  #text { min-height: 120px; }
}

/* ---------- Tableaux, langue ---------- */
.header-actions { display: flex; align-items: center; gap: 12px; }
.lang-link { font-family: 'Noto Naskh Arabic', serif; font-size: 1.05rem; color: var(--text); text-decoration: none; border: 1px solid var(--border); border-radius: 999px; padding: 4px 14px; min-height: 32px; display: inline-flex; align-items: center; }
.lang-link:hover { border-color: var(--accent); }
.content p, .content ul { line-height: 1.6; }
.content ul { padding-left: 20px; }
.table-wrap { overflow-x: auto; margin: 12px 0; }
.corr { border-collapse: collapse; width: 100%; background: var(--surface); font-size: 0.95rem; }
.corr caption { text-align: left; font-size: 0.85rem; color: var(--muted); padding-bottom: 6px; }
.corr th, .corr td { border: 1px solid var(--border); padding: 6px 10px; text-align: center; }
.corr th { background: var(--surface-2); font-weight: 600; }
.corr td[lang="ar"] { font-family: 'Noto Naskh Arabic', serif; font-size: 1.35rem; }
[dir="rtl"] .content ol, [dir="rtl"] .content ul { padding-left: 0; padding-right: 20px; }
[dir="rtl"] .corr caption { text-align: right; }

/* ---------- Pages prénoms ---------- */
.nav-link { color: var(--text); text-decoration: none; font-weight: 500; font-size: 0.95rem; }
.nav-link:hover { color: var(--accent); }
.crumbs { font-size: 0.85rem; color: var(--muted); padding-top: 16px; }
.crumbs a { color: var(--muted); }
.name-card { text-align: center; }
.name-big { font-family: 'Amiri', serif; font-size: clamp(4rem, 14vw, 7rem); line-height: 1.3; margin: 8px 0 16px; color: var(--accent); }
.name-actions { justify-content: center; flex-wrap: wrap; }
.name-actions a.btn { text-decoration: none; display: inline-flex; align-items: center; }
.fonts-title { font-size: 1rem; margin: 24px 0 10px; color: var(--muted); font-weight: 600; }
.name-fonts { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; }
.name-fonts li { border: 1px solid var(--border); border-radius: var(--radius); padding: 10px; display: flex; flex-direction: column; gap: 4px; background: var(--surface-2); }
.name-fonts span { font-size: 2.4rem; line-height: 1.4; }
.name-fonts small { color: var(--muted); font-size: 0.75rem; }
.letters { list-style: none; padding: 0 !important; margin: 12px 0; display: flex; flex-wrap: wrap; gap: 8px; }
.letters li { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); padding: 8px 12px; min-width: 64px; text-align: center; display: flex; flex-direction: column; }
.l-ar { font-family: 'Noto Naskh Arabic', serif; font-size: 1.9rem; line-height: 1.3; }
.l-nom { font-size: 0.8rem; color: var(--muted); }
.ar-inline { font-family: 'Noto Naskh Arabic', serif; font-size: 1.2em; }
.name-grid { list-style: none; padding: 0 !important; display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.name-grid a { display: flex; justify-content: space-between; align-items: center; gap: 8px; min-height: 44px; padding: 6px 12px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text); text-decoration: none; }
.name-grid a:hover { border-color: var(--accent); }
.name-grid span { font-family: 'Noto Naskh Arabic', serif; font-size: 1.25rem; color: var(--accent); }
.prenom-form label { display: block; font-weight: 600; margin-bottom: 6px; }
.prenom-row { display: flex; gap: 8px; flex-wrap: wrap; }
.prenom-row input { flex: 1 1 220px; min-height: 44px; font: inherit; font-size: 1.05rem; padding: 0 14px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text); }
.prenom-row .btn { min-height: 44px; }
