:root {
  --bg: #F7F3EA;
  --card: #FFFFFF;
  --ink: #16302C;
  --muted: #5E6E6A;
  --line: #E6DFD0;
  --brand: #0E5E57;
  --brand-ink: #FFFFFF;
  --brand-soft: #E3F0EC;
  --accent: #E2A13B;
  --accent-soft: #FBEFD9;
  --danger: #B3261E;
  --danger-soft: #FCE8E6;
  --wa: #1FA855;
  --paper: #FFFDF8;
  --shadow: 0 1px 2px rgba(22, 48, 44, .06), 0 6px 24px rgba(22, 48, 44, .06);
  --radius: 18px;
  --font: "IBM Plex Sans Arabic", system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
  --font-doc: "Noto Naskh Arabic", "IBM Plex Sans Arabic", Georgia, serif;
  --chev: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5l5 5 5-5' fill='none' stroke='%230E5E57' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  --chev-on: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5l5 5 5-5' fill='none' stroke='%23FFFFFF' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0F1716; --card: #17221F; --ink: #E8EFEC; --muted: #A2B2AD; --line: #2A3936;
    --brand: #3FA99C; --brand-ink: #06201C; --brand-soft: #1C3531; --accent: #F0B455; --accent-soft: #3A2E18;
    --danger: #F2B8B5; --danger-soft: #3B1F1D; --paper: #1B2724; --shadow: 0 1px 2px rgba(0,0,0,.3);
    --chev: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5l5 5 5-5' fill='none' stroke='%233FA99C' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    --chev-on: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5l5 5 5-5' fill='none' stroke='%2306201C' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink); font-family: var(--font);
  font-size: 16px; line-height: 1.6; -webkit-tap-highlight-color: transparent;
}
a { color: var(--brand); }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

.top {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  max-width: 640px; margin: 0 auto; padding: 12px 16px 4px;
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink); font-weight: 700; font-size: 22px; }
.brand img { border-radius: 9px; }
.langs { display: flex; gap: 4px; flex-wrap: wrap; justify-content: flex-end; }
.langs a { text-decoration: none; color: var(--muted); font-size: 14px; padding: 4px 9px; border-radius: 999px; }
.langs a[aria-current] { background: var(--brand-soft); color: var(--brand); font-weight: 600; }

main { max-width: 640px; margin: 0 auto; padding: 0 16px 24px; }

.hero { padding: 10px 2px 14px; }
.hero h1 { font-size: clamp(25px, 6.6vw, 34px); line-height: 1.25; margin: 6px 0 8px; letter-spacing: -.01em; }
.hero .sub { margin: 0 0 10px; color: var(--muted); font-size: 15.5px; }
.badges { list-style: none; display: flex; flex-wrap: wrap; gap: 6px; margin: 0; padding: 0; }
.badges li { background: var(--accent-soft); color: var(--ink); font-size: 13px; padding: 2px 10px; border-radius: 999px; font-weight: 600; }
.badges li::before { content: "✓ "; color: var(--accent); }

.card {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 18px 16px; margin: 12px 0; border: 1px solid var(--line);
}
.step-h { display: flex; align-items: center; gap: 10px; }
.step-h h2 { font-size: 18.5px; margin: 0; line-height: 1.35; }
.num {
  flex: none; width: 28px; height: 28px; border-radius: 50%; background: var(--brand); color: var(--brand-ink);
  display: grid; place-items: center; font-weight: 700; font-size: 15px;
}
.hint { color: var(--muted); font-size: 14.5px; margin: 8px 0 10px; }
.fine { color: var(--muted); font-size: 12.5px; margin: 10px 0 0; }

.dialect-row { display: flex; align-items: center; gap: 8px; margin: 4px 0 6px; font-size: 15px; }
.dialect-row label { color: var(--muted); }
select {
  appearance: none; -webkit-appearance: none; background-color: var(--brand-soft); border: 1px solid transparent; border-radius: 999px;
  padding: 6px 34px 6px 14px; font-weight: 600; color: var(--brand); min-height: 40px; max-width: 100%;
  background-image: var(--chev); background-repeat: no-repeat; background-size: 12px 8px; background-position: right 13px center;
}
[dir="rtl"] select { padding: 6px 14px 6px 34px; background-position: left 13px center; }
.dialect-row label { white-space: nowrap; }

/* recorder */
.recorder { display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 10px 0 4px; }
.mic {
  position: relative; width: 96px; height: 96px; border-radius: 50%; border: 0; background: var(--brand); color: var(--brand-ink);
  display: grid; place-items: center; box-shadow: 0 8px 24px rgba(14, 94, 87, .35); transition: transform .15s ease, background .2s;
  touch-action: manipulation;
}
.mic:active { transform: scale(.96); }
.mic svg { width: 44px; height: 44px; fill: currentColor; }
.mic .stop-ico { display: none; }
.mic.rec { background: #C2412D; box-shadow: 0 0 0 0 rgba(194, 65, 45, .5); animation: pulse 1.5s infinite; }
.mic.rec .mic-ico { display: none; }
.mic.rec .stop-ico { display: block; }
.mic.wait { opacity: .7; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(194, 65, 45, .45); } 70% { box-shadow: 0 0 0 22px rgba(194, 65, 45, 0); } 100% { box-shadow: 0 0 0 0 rgba(194, 65, 45, 0); } }
.level { display: flex; gap: 4px; height: 22px; align-items: center; opacity: 0; transition: opacity .2s; }
.recording .level { opacity: 1; }
.level i { width: 5px; height: 22px; border-radius: 3px; background: #C2412D; transform: scaleY(.15); transition: transform .08s linear; }
.mic-label { font-weight: 600; font-size: 16px; text-align: center; }
.timer { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 14px; }

.err {
  background: var(--danger-soft); color: var(--danger); border-radius: 12px; padding: 10px 12px; margin: 10px 0 0;
  font-size: 14.5px; white-space: pre-line;
}

.transcript { margin-top: 12px; }
.transcript label { display: block; font-size: 14px; color: var(--muted); margin-bottom: 6px; }
textarea, input[type="text"] {
  width: 100%; border: 1.5px solid var(--line); background: var(--paper); border-radius: 12px; padding: 10px 12px;
  font-size: 16px; line-height: 1.6; resize: vertical; min-height: 48px; outline: none;
}
textarea { min-height: 96px; }
textarea:focus, input[type="text"]:focus { border-color: var(--brand); }
.busy { display: flex; align-items: center; gap: 8px; color: var(--brand); font-size: 14px; margin-top: 6px; }
.dots { display: inline-flex; gap: 3px; }
.dots i { width: 6px; height: 6px; border-radius: 50%; background: currentColor; animation: blink 1.2s infinite; }
.dots i:nth-child(2) { animation-delay: .2s; } .dots i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .2; } 40% { opacity: 1; } }

.link { background: none; border: 0; color: var(--brand); padding: 8px 0; font-weight: 600; font-size: 15px; }

/* chips */
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.chip { position: relative; }
.chip input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.chip span {
  display: inline-flex; align-items: center; gap: 6px; min-height: 42px; padding: 7px 14px; border-radius: 999px;
  border: 1.5px solid var(--line); background: var(--paper); font-size: 15px; font-weight: 500; transition: all .15s;
}
.chip i { font-style: normal; }
.chip input:checked + span { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); font-weight: 600; }
.chip input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.more-out { margin-top: 10px; background-color: var(--paper); color: var(--ink); border: 1.5px solid var(--line); font-weight: 500; }
.more-out.on { background-color: var(--brand); color: var(--brand-ink); border-color: var(--brand); background-image: var(--chev-on); }

/* CTA */
.cta { position: sticky; bottom: 10px; z-index: 5; margin: 14px 0; }
.btn-primary {
  width: 100%; min-height: 58px; border: 0; border-radius: 16px; background: var(--accent); color: #2A1A00;
  font-size: 19px; font-weight: 700; box-shadow: 0 8px 22px rgba(226, 161, 59, .45); transition: transform .1s;
}
.btn-primary:active { transform: scale(.98); }
.btn-primary.busy { opacity: .85; }
.btn-secondary { border: 0; background: var(--brand); color: var(--brand-ink); border-radius: 12px; padding: 0 16px; min-height: 48px; font-weight: 600; flex: none; }
.btn-wa { width: 100%; min-height: 50px; border: 0; border-radius: 14px; background: var(--wa); color: #fff; font-weight: 700; font-size: 16.5px; }

/* result */
.result { border-color: var(--brand); border-width: 1.5px; }
.result-h { font-weight: 700; font-size: 17px; margin-bottom: 10px; color: var(--brand); }
.doc {
  background: var(--paper); border: 1px solid var(--line); border-radius: 12px; padding: 16px 14px; min-height: 120px;
  white-space: pre-wrap; word-wrap: break-word; font-family: var(--font-doc); font-size: 17.5px; line-height: 1.85; outline: none;
}
.doc[dir="ltr"] { font-family: var(--font); font-size: 16.5px; line-height: 1.7; }
.doc[contenteditable="true"] { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.loading .doc:empty::before { content: "…"; color: var(--muted); }
.loading .doc::after { content: "▍"; color: var(--brand); animation: blink 1s infinite; }
mark.ph { background: var(--accent-soft); color: inherit; border-radius: 4px; padding: 0 2px; outline: 1px dashed var(--accent); }
.note { background: var(--brand-soft); border-radius: 12px; padding: 10px 12px; margin-top: 10px; font-size: 15px; }
.ph-hint { font-size: 14px; color: var(--muted); margin: 8px 0 0; }
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 14px; }
.act {
  min-height: 48px; border-radius: 12px; border: 1.5px solid var(--line); background: var(--paper); font-weight: 600; font-size: 15px;
  display: flex; align-items: center; justify-content: center; gap: 6px;
}
.act.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.act.wa { background: var(--wa); color: #fff; border-color: var(--wa); }
.act.on { border-color: var(--accent); background: var(--accent-soft); }
.feedback { display: flex; align-items: center; gap: 8px; margin-top: 14px; color: var(--muted); font-size: 15px; }
.feedback button { border: 1.5px solid var(--line); background: var(--paper); border-radius: 999px; width: 44px; height: 40px; font-size: 18px; }
.feedback.done button { display: none; }
.refine { margin-top: 16px; border-top: 1px dashed var(--line); padding-top: 12px; }
.refine h3 { font-size: 16px; margin: 0 0 4px; }
.chips.small { margin-top: 6px; }
.chip-btn { border: 1.5px solid var(--line); background: var(--paper); border-radius: 999px; padding: 6px 13px; min-height: 40px; font-size: 14.5px; }
.refine-row { display: flex; gap: 8px; align-items: center; margin-top: 10px; }
.mic.small { width: 48px; height: 48px; flex: none; box-shadow: none; }
.mic.small svg { width: 24px; height: 24px; }

.share h3, .how h3 { margin: 0 0 6px; font-size: 17px; }
.share p { margin: 0 0 12px; color: var(--muted); }
.how ol, .how ul { margin: 0 0 12px; padding-inline-start: 22px; }
.how li { margin: 3px 0; }
.examples { color: var(--muted); }
.history summary { cursor: pointer; font-weight: 600; }
.history ul { list-style: none; padding: 0; margin: 10px 0 0; }
.history li button { width: 100%; text-align: start; border: 1px solid var(--line); background: var(--paper); border-radius: 10px; padding: 8px 10px; margin: 4px 0; font-size: 14px; }
.history small { color: var(--muted); }
.prose h1 { font-size: 24px; margin-top: 0; }

/* worked example */
.example blockquote { margin: 6px 0 12px; padding: 10px 12px; background: var(--accent-soft); border-radius: 12px; font-size: 15px; }
.ex-label { margin: 8px 0 4px; font-weight: 600; color: var(--muted); font-size: 14px; }
.ex-doc { font-size: 15.5px; max-height: 360px; overflow: auto; }
.popular { margin-bottom: 10px; line-height: 2; }
.popular a { white-space: nowrap; }

footer { max-width: 640px; margin: 0 auto; padding: 8px 16px 40px; text-align: center; color: var(--muted); font-size: 14px; }

.toast {
  position: fixed; left: 50%; bottom: 84px; transform: translateX(-50%); background: var(--ink); color: var(--bg);
  padding: 10px 18px; border-radius: 999px; font-weight: 600; z-index: 20; box-shadow: var(--shadow); max-width: 90vw; text-align: center;
}

body:not(.has-text) .cta { position: static; }

@media (min-width: 700px) {
  .card { padding: 22px 22px; }
  .actions { grid-template-columns: repeat(3, 1fr); }
}

@media print {
  body.print-doc * { visibility: hidden; }
  body.print-doc .doc, body.print-doc .doc * { visibility: visible; }
  body.print-doc .doc { position: absolute; inset: 0 auto auto 0; width: 100%; border: 0; background: #fff; color: #000; padding: 0; font-size: 13pt; }
  body.print-doc mark.ph { outline: 0; background: none; }
}
