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

:root {
  color-scheme: light;
  --green: #123f37; --green-deep: #0c2b26; --gold: #c39a55; --gold-soft: #f1e3c4; --paper: #fbf9f4; --ink: #1f2a27;
  --muted: #6b756f; --line: #dfe3dc; --surface: #eef1ec; --danger: #9b3930;
  --urdu: Nastaliq, 'Noto Nastaliq Urdu', serif; --ui: Naskh, 'Segoe UI', system-ui, sans-serif;
  --safe-bottom: env(safe-area-inset-bottom, 0px); --safe-top: env(safe-area-inset-top, 0px);
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; max-width: 100%; overflow-x: hidden; }
body { font-family: var(--ui); font-size: 16px; color: var(--ink); background: var(--surface); display: flex; flex-direction: column; overflow: hidden; }
button { font: inherit; color: inherit; }
[hidden] { display: none !important; }

/* ——— header ——— */
.top { display: flex; align-items: center; gap: 6px; padding: calc(8px + var(--safe-top)) 10px 8px; background: var(--green); color: #f3f6f2; }
.top .icon { width: 42px; height: 42px; border: 0; border-radius: 12px; background: #ffffff14; color: inherit; font-size: 20px; flex: none; }
.top .icon:active { background: #ffffff2a; }
.title-wrap { flex: 1; min-width: 0; display: flex; align-items: baseline; gap: 10px; }
.brand { font-family: var(--urdu); font-size: 22px; line-height: 1.2; color: #f3d9a3; flex: none; }
.doc-title { font-family: var(--urdu); font-size: 15px; line-height: 1.4; opacity: .85; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.count { font-size: 11px; opacity: .6; white-space: nowrap; flex: none; }
.count::after { content: ' الفاظ'; font-family: var(--urdu); }
.engine-chip { border: 1px solid #ffffff33; background: #ffffff10; color: #e7efe9; border-radius: 999px; padding: 6px 12px; font-size: 13px; white-space: nowrap; }
.engine-chip.engine-device { border-color: #9fd7b3; color: #d6f5e0; }
.engine-chip.engine-server { border-color: #f3d9a3; color: #f7e6bd; }
.engine-chip.engine-none { border-color: #e0a5a0; color: #f4c8c4; }

/* ——— the page ——— */
.page { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 14px 12px 24px; }
.blocks { max-width: 720px; margin: 0 auto; background: var(--paper); border-radius: 16px; padding: 14px 14px 10px; box-shadow: 0 1px 2px #0000000d, 0 8px 28px #12352e0f; min-height: 40vh; }
.block { position: relative; padding: 4px 0 6px; }
.block + .block { border-top: 1px solid #ebe6da; }
.block-label { font-size: 11px; color: var(--muted); letter-spacing: .2px; margin: 4px 0 -2px; }
.block textarea { display: block; width: 100%; border: 0; background: transparent; resize: none; outline: none; padding: 4px 2px; font-family: var(--urdu); font-size: 22px; line-height: 2.15; color: var(--ink); overflow: hidden; }
.block textarea::placeholder { color: #b7b0a2; }
.block textarea:focus { background: #fff; border-radius: 8px; box-shadow: inset 0 0 0 1.5px #c39a5566; }
.block-title textarea { font-size: 30px; text-align: center; line-height: 1.9; }
.block-subtitle textarea { font-size: 19px; text-align: center; color: #5c6a63; }
.block-heading textarea { font-size: 26px; line-height: 2; }
.block-sher textarea, .block-band textarea { text-align: center; }
.block-quote textarea[data-field="text"] { font-family: Naskh, serif; font-size: 24px; line-height: 2; text-align: center; background: #f6f2e8; border-radius: 10px; padding: 8px 10px; }
.block-quote textarea[data-field="sub"] { font-size: 19px; text-align: center; color: #3f4a45; }
.block-note textarea { font-size: 18px; color: #4e5853; border-top: 1px dashed #d9d2c2; }
.pagebreak-line { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 12px; margin: 6px 0; }
.pagebreak-line::before, .pagebreak-line::after { content: ''; flex: 1; border-top: 1px dashed #c8c1b0; }
.pagebreak-remove { border: 0; background: transparent; color: var(--muted); font-size: 14px; }
.interim { max-width: 720px; margin: 12px auto 0; font-family: var(--urdu); font-size: 18px; line-height: 2; color: #6c7a72; padding: 6px 14px; }

/* ——— word alternatives ——— */
.alts { background: #fff; border-top: 1px solid var(--line); padding: 8px 12px 6px; box-shadow: 0 -6px 18px #0000000a; }
.alts-head { display: flex; align-items: center; gap: 10px; }
.alts-word { font-family: var(--urdu); font-size: 20px; line-height: 1.6; color: var(--green); }
.alts-hint { font-size: 12px; color: var(--muted); flex: 1; }
.alts-delete { border: 1px solid #e6c9c4; color: var(--danger); background: #fff5f3; border-radius: 999px; padding: 4px 12px; font-size: 13px; }
.icon.small { width: 32px; height: 32px; border: 0; background: transparent; color: var(--muted); font-size: 16px; }
.alts-list { display: flex; gap: 8px; overflow-x: auto; padding: 8px 0 4px; scrollbar-width: none; }
.alts-list::-webkit-scrollbar { display: none; }
.chip { flex: none; border: 1px solid #d5dbd5; background: #f6f8f5; border-radius: 999px; padding: 4px 14px; font-family: var(--urdu); font-size: 19px; line-height: 1.7; }
.chip:active { background: var(--gold-soft); }
.chip-learned { border-color: var(--gold); background: #fbf3e3; }
.chip-wait, .chip-none { color: var(--muted); font-family: var(--ui); font-size: 14px; }

/* ——— bottom bar ——— */
.bar { background: #fff; border-top: 1px solid var(--line); padding: 6px 10px calc(10px + var(--safe-bottom)); }
.block-tools { display: flex; gap: 6px; overflow-x: auto; padding: 2px 0 6px; scrollbar-width: none; align-items: center; }
.block-tools::-webkit-scrollbar { display: none; }
.block-tools button { flex: none; border: 1px solid var(--line); background: #f7f9f6; border-radius: 999px; padding: 6px 13px; font-family: var(--urdu); font-size: 15px; line-height: 1.6; }
.block-tools button[aria-pressed="true"] { background: var(--green); color: #fff; border-color: var(--green); }
.block-tools #block-up, .block-tools #block-down, .block-tools #block-delete { font-family: var(--ui); width: 38px; padding: 6px 0; text-align: center; }
.block-tools .danger { color: var(--danger); }
.tools-gap { flex: 1; min-width: 6px; }
.mic-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding-top: 4px; }
.side { display: flex; align-items: center; gap: 8px; flex: 1 1 0; min-width: 0; }
.side:last-child { justify-content: flex-end; }
.round { width: 46px; height: 46px; border-radius: 50%; border: 1px solid var(--line); background: #f7f9f6; font-size: 20px; }
.round:disabled { opacity: .35; }
#word-button { font-family: var(--urdu); font-size: 16px; line-height: 1; }
.status { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.mic-wrap { position: relative; display: flex; flex-direction: column; align-items: center; gap: 4px; flex: none; }
.mic-level { position: absolute; top: 0; left: 50%; width: 84px; height: 84px; margin-left: -42px; border-radius: 50%; background: var(--gold); opacity: .25; transform: scale(calc(1 + var(--level, 0) * .5)); transition: transform .08s linear; pointer-events: none; }
.mic { position: relative; width: 84px; height: 84px; border-radius: 50%; border: 0; background: var(--green); color: #f3d9a3; box-shadow: 0 6px 20px #12352e40, inset 0 0 0 4px #ffffff22; touch-action: none; -webkit-user-select: none; user-select: none; }
.mic svg { width: 36px; height: 36px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.mic.listening { background: #b8412f; color: #fff; box-shadow: 0 6px 24px #b8412f66, inset 0 0 0 4px #ffffff33; }
.mic.busy { background: #6b7a72; }
.mic:disabled { background: #b8bfba; box-shadow: none; }
.mic.no-engine { background: #8a958f; }
.setup { max-width: 720px; margin: 0 auto 12px; background: #fff8e8; border: 1px solid #ecd9ac; border-radius: 16px; padding: 12px 16px 14px; }
.setup h2 { font-family: var(--urdu); font-weight: 400; font-size: 20px; line-height: 1.9; margin: 0; color: #5c4515; }
.setup p { font-family: var(--urdu); font-size: 15px; line-height: 2; margin: 2px 0 8px; color: #4d4a42; }
.setup progress { width: 100%; height: 8px; margin-bottom: 8px; }
.setup-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.setup-actions .button { flex: 1 1 auto; }
.version { direction: ltr; text-align: left; margin-top: 12px; }
.mic-label { font-family: var(--urdu); font-size: 14px; line-height: 1.6; color: var(--muted); }

/* ——— sheets ——— */
dialog.sheet { border: 0; border-radius: 18px 18px 0 0; padding: 14px 16px calc(16px + var(--safe-bottom)); width: 100%; max-width: 100%; margin: auto 0 0; max-height: 88vh; overflow-y: auto; background: #fff; color: var(--ink); }
dialog.sheet.full { height: 92vh; max-height: 92vh; display: flex; flex-direction: column; }
dialog.sheet.full:not([open]) { display: none; }
dialog::backdrop { background: #12352e55; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.sheet-head h2 { font-family: var(--urdu); font-weight: 400; font-size: 22px; margin: 0; line-height: 1.8; }
.sheet-head .icon { width: 38px; height: 38px; border: 0; border-radius: 10px; background: var(--surface); font-size: 18px; }
.sheet h3 { font-size: 14px; color: var(--muted); font-weight: 600; margin: 16px 0 8px; }
.fine { font-size: 12.5px; color: var(--muted); line-height: 1.7; }
.fine a { color: var(--green); }
.row { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; margin: 10px 0; }
.row label { display: flex; align-items: center; gap: 8px; font-size: 14px; }
select, .field input { font: inherit; padding: 8px 10px; border: 1px solid var(--line); border-radius: 10px; background: #fff; }
.field { display: flex; align-items: center; gap: 10px; margin: 8px 0; font-size: 14px; }
.field input { flex: 1; min-width: 0; }
.button { border: 1px solid var(--line); background: #f7f9f6; border-radius: 12px; padding: 10px 16px; font-size: 15px; }
.button.primary { background: var(--green); color: #fff; border-color: var(--green); }
.button.small { padding: 6px 12px; font-size: 13px; border-radius: 999px; }
.button:disabled { opacity: .5; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; margin: 14px 0 8px; }
.actions .button { flex: 1 1 40%; }
#preview-frame { flex: 1; width: 100%; border: 1px solid var(--line); border-radius: 10px; background: #d9d6cf; }

.layout-choices { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; }
.layout-choice { border: 1px solid var(--line); background: #f7f9f6; border-radius: 12px; padding: 10px; text-align: right; display: flex; flex-direction: column; gap: 2px; }
.layout-choice strong { font-family: var(--urdu); font-weight: 400; font-size: 18px; line-height: 1.6; }
.layout-choice span { font-size: 12px; color: var(--muted); }
.docs-list { list-style: none; margin: 0; padding: 0; }
.docs-list li { display: flex; align-items: center; gap: 6px; border-bottom: 1px solid var(--line); }
.docs-list .empty { color: var(--muted); font-size: 13px; padding: 10px 0; }
.doc-item { flex: 1; border: 0; background: transparent; text-align: right; padding: 10px 4px; display: flex; flex-direction: column; gap: 2px; }
.doc-item strong { font-family: var(--urdu); font-weight: 400; font-size: 18px; line-height: 1.7; }
.doc-item span { font-size: 12px; color: var(--muted); }
.doc-remove { border: 0; background: transparent; font-size: 16px; padding: 8px; }

.layout-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 10px; }
.layout-card { position: relative; border: 1.5px solid var(--line); border-radius: 12px; padding: 8px; display: flex; flex-direction: column; gap: 4px; cursor: pointer; }
.layout-card input { position: absolute; opacity: 0; }
.layout-card:has(input:checked) { border-color: var(--gold); background: #fdf8ee; }
.layout-card strong { font-family: var(--urdu); font-weight: 400; font-size: 16px; line-height: 1.6; }
.layout-card small { font-size: 11px; color: var(--muted); }
.layout-art { display: block; height: 70px; border-radius: 6px; background: #fff; border: 1px solid #e5e1d6; position: relative; overflow: hidden; }
.layout-art::before, .layout-art::after { content: ''; position: absolute; left: 12%; right: 12%; background: #c9c2b2; height: 2px; border-radius: 2px; box-shadow: 0 6px 0 #d9d3c4, 0 12px 0 #d9d3c4, 0 18px 0 #d9d3c4, 0 24px 0 #d9d3c4; top: 24px; }
.layout-art::after { top: 12px; height: 4px; background: #9a7b3c; box-shadow: none; left: 35%; right: 35%; }
.layout-art-nasr::before { left: 10%; right: 10%; }
.layout-art-shaer::before { left: 25%; right: 25%; box-shadow: 0 6px 0 #d9d3c4, 0 16px 0 #d9d3c4, 0 22px 0 #d9d3c4, 0 32px 0 #d9d3c4; }
.layout-art-deeni::after { background: #4f7f5c; height: 6px; left: 20%; right: 20%; }
.layout-art-sada::after { display: none; }

.radio-list label, .check-list label { display: flex; align-items: center; gap: 10px; padding: 8px 2px; font-size: 15px; }
.radio-list label small { margin-right: auto; color: var(--muted); font-size: 12px; }
.radio-list label.unavailable span { color: var(--muted); }
.radio-list.inline { display: flex; gap: 14px; }
.models { list-style: none; margin: 0; padding: 0; }
.model { display: grid; grid-template-columns: 1fr auto; gap: 6px 10px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); }
.model strong { display: block; font-size: 14px; }
.model-note { font-size: 12px; color: var(--muted); font-family: var(--urdu); }
.model progress { grid-column: 1 / -1; width: 100%; height: 6px; }
.help { padding-right: 18px; font-family: var(--urdu); font-size: 17px; line-height: 2.1; }
.help li { margin-bottom: 6px; }

.toast { position: fixed; left: 50%; bottom: calc(150px + var(--safe-bottom)); transform: translate(-50%, 20px); background: #1f2a27; color: #fff; padding: 10px 16px; border-radius: 12px; font-family: var(--urdu); font-size: 15px; line-height: 1.8; max-width: 92vw; opacity: 0; transition: opacity .2s, transform .2s; pointer-events: none; z-index: 20; }
.toast.visible { opacity: 1; transform: translate(-50%, 0); }

@media (min-width: 900px) {
  .page { padding: 24px; }
  .blocks { padding: 28px 32px 20px; }
  .block textarea { font-size: 24px; }
  .mic { width: 76px; height: 76px; }
  .mic-level { width: 76px; height: 76px; margin-left: -38px; }
  dialog.sheet { max-width: 640px; margin: auto; border-radius: 18px; }
}
