@font-face { font-family: "Naskh"; src: url("fonts/NotoNaskhArabic-Regular.ttf") format("truetype"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Naskh"; src: url("fonts/NotoNaskhArabic-Bold.ttf") format("truetype"); font-weight: 700; font-display: swap; }

:root {
  --navy: #14213d; --ivory: #fcf9f2; --gold: #c8a96a; --green: #2e8b57; --red: #d64545;
  --orange: #d9822b; --muted: #5b6275; --card: #ffffff; --border: #e6e0d4;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  font-family: "Naskh", "Noto Naskh Arabic", "Noto Sans Arabic", serif;
  background: var(--ivory); color: var(--navy); font-size: 20px; line-height: 1.7;
}
main { max-width: 560px; margin: 0 auto; min-height: 100%; padding: max(16px, env(safe-area-inset-top)) 18px max(24px, env(safe-area-inset-bottom)); }

.screen { display: none; }
body[data-screen="loading"] #loading,
body[data-screen="error"] #error,
body[data-screen="intro"] #intro,
body[data-screen="mic-help"] #mic-help,
body[data-screen="item"] #item,
body[data-screen="section-done"] #section-done,
body[data-screen="done"] #done { display: block; }
.center { text-align: center; padding-top: 12vh; }

h1 { font-size: 30px; margin: 8px 0 12px; }
h2 { font-size: 24px; margin: 0; }
.lead { font-size: 21px; margin: 8px 0; }
.big { font-size: 24px; font-weight: 700; margin: 10px 0; }
.small { font-size: 16px; color: var(--muted); }
.note { font-size: 18px; background: #f3ecdc; border-radius: 14px; padding: 12px 14px; }
.icon-xl { font-size: 64px; }

.steps { list-style: none; padding: 0; margin: 16px 0; }
.steps li { display: flex; gap: 12px; align-items: flex-start; background: var(--card); border: 1px solid var(--border);
  border-radius: 16px; padding: 12px 14px; margin-bottom: 10px; font-size: 19px; }
.step-icon { font-size: 28px; line-height: 1.2; }

.btn { display: block; width: 100%; border: none; border-radius: 18px; padding: 16px; font: inherit; font-size: 22px;
  font-weight: 700; margin: 10px 0; cursor: pointer; min-height: 60px; }
.btn.primary { background: var(--green); color: #fff; }
.btn.secondary { background: var(--navy); color: #fff; }
.btn.retry { background: var(--orange); color: #fff; }
.btn.ghost { background: transparent; color: var(--navy); border: 2px solid var(--border); }
.btn.huge { font-size: 28px; min-height: 76px; }
.btn:active { transform: scale(0.98); }
.small-btn { width: auto; display: inline-block; font-size: 17px; padding: 8px 14px; min-height: 44px; margin: 0; }
.row { display: flex; gap: 12px; }
.row .btn { flex: 1; }

.topbar { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.progress-text { font-size: 18px; color: var(--muted); }
.progress { height: 10px; background: #ebe4d4; border-radius: 99px; overflow: hidden; margin: 10px 0 14px; }
.progress-fill { height: 100%; width: 0; background: var(--gold); transition: width .3s; }

.card { background: var(--card); border: 1px solid var(--border); border-radius: 24px; padding: 14px 16px 18px; text-align: center;
  box-shadow: 0 6px 20px rgba(20, 33, 61, .06); }
.chip { display: inline-block; background: #f3ecdc; color: #7a5c1e; border-radius: 99px; padding: 2px 14px; font-size: 17px; }
.item-text { font-size: clamp(72px, 26vw, 140px); line-height: 1.5; font-weight: 700; margin: 6px 0; word-break: keep-all; }
.item-text.long { font-size: clamp(44px, 13vw, 72px); }
.hint { font-size: 18px; color: var(--muted); }

.controls { text-align: center; margin-top: 18px; min-height: 230px; }
.state { display: none; }
body[data-state="idle"] .state-idle,
body[data-state="starting"] .state-idle,
body[data-state="recording"] .state-recording,
body[data-state="review"] .state-review,
body[data-state="saving"] .state-saving { display: block; }
body[data-state="starting"] #rec,
body[data-state="recording"] #open-list,
body[data-state="saving"] #open-list { opacity: .4; pointer-events: none; }

.rec-btn { width: 132px; height: 132px; border-radius: 50%; border: 8px solid #f6d5d5; background: var(--red);
  display: inline-flex; align-items: center; justify-content: center; cursor: pointer; box-shadow: 0 8px 24px rgba(214, 69, 69, .35); }
.rec-btn .dot { width: 46px; height: 46px; border-radius: 50%; background: #fff; }
.rec-btn:active { transform: scale(0.96); }
.live { color: var(--red); }
.meter { height: 26px; background: #ebe4d4; border-radius: 99px; overflow: hidden; margin: 18px 0 8px; }
.meter-fill { height: 100%; width: 0; background: var(--green); transition: width .08s linear; }
.warn { color: var(--orange); font-size: 19px; min-height: 1.5em; font-weight: 700; }
.toast { text-align: center; color: var(--green); font-size: 18px; min-height: 1.6em; margin: 8px 0 0; }

.spinner { width: 44px; height: 44px; border: 5px solid #e6dcc6; border-top-color: var(--gold); border-radius: 50%;
  margin: 12px auto; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

dialog { border: none; border-radius: 20px; padding: 16px; width: min(560px, 94vw); max-height: 86vh; background: var(--ivory); color: var(--navy); }
dialog::backdrop { background: rgba(20, 33, 61, .5); }
.list-head { display: flex; justify-content: space-between; align-items: center; }
.list-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 8px; margin-top: 10px; }
.list-grid button { font: inherit; border: 2px solid var(--border); background: var(--card); border-radius: 14px; padding: 6px 4px;
  font-size: 26px; min-height: 64px; position: relative; color: var(--navy); }
.list-grid button small { display: block; font-size: 13px; color: var(--muted); }
.list-grid button.done { border-color: var(--green); background: #eef7f1; }
.list-grid button.done::after { content: "✓"; position: absolute; top: 2px; left: 6px; color: var(--green); font-size: 16px; font-weight: 700; }
.list-grid button.current { outline: 3px solid var(--gold); }
