:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --text: #1c2230;
  --muted: #667085;
  --line: #d9dde5;
  --primary: #1d4ed8;
  --primary-ink: #ffffff;
  --ok: #15803d;
  --ok-bg: #e7f6ec;
  --warn: #b45309;
  --warn-bg: #fff4e0;
  --err: #b91c1c;
  --radius: 14px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12151c; --card: #1b2029; --text: #eef1f6; --muted: #98a2b3; --line: #2e3542;
    --primary: #5b8cff; --primary-ink: #0b1220;
    --ok: #4ade80; --ok-bg: #16301f; --warn: #fbbf24; --warn-bg: #3a2c10; --err: #f87171;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: Vazirmatn, "Segoe UI", Tahoma, system-ui, sans-serif;
  font-size: 17px; line-height: 1.7;
}
[hidden] { display: none !important; }
#app { max-width: 640px; margin: 0 auto; padding: 20px 16px 48px; }

h1 { font-size: 1.45rem; line-height: 1.5; margin: 8px 0 8px; }
.lead { color: var(--muted); margin: 0 0 18px; }
.step { font-weight: 700; margin: 0 0 10px; }

/* course cards */
.courses { display: grid; gap: 10px; }
.course {
  display: flex; align-items: center; gap: 14px; width: 100%;
  background: var(--card); border: 1.5px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px; min-height: 72px; font: inherit; color: inherit; text-align: start; cursor: pointer;
}
.course:hover, .course:focus-visible { border-color: var(--primary); outline: none; }
.course .icon { font-size: 1.9rem; line-height: 1; }
.course .name { font-weight: 700; display: block; }
.course .desc { color: var(--muted); font-size: .88rem; display: block; line-height: 1.5; }
.course .count { display: block; color: var(--primary); font-size: .82rem; margin-top: 2px; }

/* header */
.top { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 8px 10px; margin-bottom: 14px; }
.course-chip {
  font: inherit; font-weight: 700; color: var(--text); background: var(--card);
  border: 1.5px solid var(--line); border-radius: 999px; padding: 6px 16px; cursor: pointer; min-height: 44px; white-space: nowrap;
}
.course-chip:hover { border-color: var(--primary); }
.mine { color: var(--muted); font-size: .9rem; }

/* tabs */
.tabs { display: grid; grid-template-columns: repeat(2, 1fr); background: var(--line); border-radius: 12px; padding: 4px; gap: 4px; margin-bottom: 16px; }
.tabs button {
  font: inherit; border: 0; background: transparent; color: var(--muted);
  border-radius: 9px; padding: 9px 4px; min-height: 44px; cursor: pointer; font-size: .95rem;
}
.tabs button[aria-selected="true"] { background: var(--card); color: var(--text); font-weight: 700; box-shadow: 0 1px 3px rgba(0,0,0,.12); }

/* fields */
.field { display: block; margin-bottom: 16px; }
.label { display: block; font-weight: 700; margin-bottom: 6px; }
textarea, input[type="text"], input[type="tel"] {
  width: 100%; font: inherit; color: var(--text); background: var(--card);
  border: 1.5px solid var(--line); border-radius: 12px; padding: 12px 14px;
}
textarea { resize: vertical; min-height: 96px; }
textarea:focus, input[type="text"]:focus, input[type="tel"]:focus { outline: 3px solid color-mix(in srgb, var(--primary) 35%, transparent); border-color: var(--primary); }

fieldset.options { border: 0; padding: 0; margin: 0 0 14px; }
fieldset.options legend { font-weight: 700; padding: 0; margin-bottom: 8px; }
fieldset.options legend small { font-weight: 400; color: var(--muted); }
.opt { display: flex; align-items: stretch; gap: 8px; margin-bottom: 8px; }
.opt input[type="text"] { flex: 1; min-width: 0; }
.mark {
  flex: none; width: 54px; font: inherit; font-weight: 700; cursor: pointer;
  background: var(--card); color: var(--muted); border: 1.5px solid var(--line); border-radius: 12px;
}
.mark:hover { border-color: var(--ok); }
.mark[aria-pressed="true"] { background: var(--ok); border-color: var(--ok); color: #fff; }
.mark[aria-pressed="true"]::after { content: " ✓"; }
.opt.is-correct input[type="text"] { border-color: var(--ok); background: var(--ok-bg); }


input[type="text"].hp, .hp { position: absolute !important; width: 1px !important; height: 1px !important; min-height: 0 !important; padding: 0 !important; border: 0 !important; overflow: hidden; clip-path: inset(50%); opacity: 0; pointer-events: none; }

button.primary {
  display: block; width: 100%; font: inherit; font-weight: 700; font-size: 1.05rem;
  background: var(--primary); color: var(--primary-ink); border: 0; border-radius: 14px;
  padding: 14px; min-height: 54px; cursor: pointer;
}
button.primary:disabled { opacity: .45; cursor: not-allowed; }
.hint { color: var(--muted); font-size: .82rem; text-align: center; margin: 8px 0 0; }
.error { color: var(--err); background: color-mix(in srgb, var(--err) 10%, transparent); border-radius: 10px; padding: 8px 12px; margin: 0 0 12px; font-size: .95rem; }

/* top bar + profile */
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; padding-bottom: 10px; border-bottom: 1px solid var(--line); }
.brand { display: inline-flex; align-items: center; }
.brand img { display: block; height: 42px; width: auto; max-width: 56vw; }
.chip {
  font: inherit; font-size: .92rem; color: var(--text); background: var(--card);
  border: 1.5px solid var(--line); border-radius: 999px; padding: 4px 14px; cursor: pointer; min-height: 40px;
  max-width: 60%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.chip:hover { border-color: var(--primary); }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 16px; }
.card .field:last-of-type { margin-bottom: 18px; }
input[type="tel"] { text-align: right; }
input[type="text"], input[type="tel"] { min-height: 50px; }

.sheet-wrap {
  position: fixed; inset: 0; z-index: 10; background: rgba(10, 14, 22, .55);
  display: flex; align-items: flex-end; justify-content: center;
}
.sheet {
  width: 100%; max-width: 480px; background: var(--card); color: var(--text);
  border-radius: 18px 18px 0 0; padding: 20px 16px calc(20px + env(safe-area-inset-bottom));
}
.sheet h2 { font-size: 1.15rem; margin: 0 0 14px; }
.mine-link {
  display: flex; justify-content: space-between; align-items: center; width: 100%;
  font: inherit; font-weight: 600; color: var(--primary); background: transparent;
  border: 1.5px solid var(--line); border-radius: 12px; padding: 12px 14px; min-height: 50px; cursor: pointer;
}
.mine-link:hover { border-color: var(--primary); }
.mine-link .count { color: var(--muted); font-weight: 400; }
.mine-link .count:not(:empty)::before { content: "("; }
.mine-link .count:not(:empty)::after { content: ")"; }
.sheet-actions { display: grid; grid-template-columns: 2fr 1fr; gap: 10px; margin-top: 12px; }
button.ghost {
  font: inherit; font-weight: 600; background: transparent; color: var(--muted);
  border: 1.5px solid var(--line); border-radius: 14px; min-height: 54px; cursor: pointer;
}
button.ghost.cancel { display: block; width: 100%; margin-top: 10px; }
@media (min-width: 700px) {
  .sheet-wrap { align-items: center; }
  .sheet { border-radius: 18px; }
}

/* batch */
.preview { display: grid; gap: 10px; margin-bottom: 14px; }
.pq { background: var(--card); border: 1.5px solid var(--line); border-radius: 12px; padding: 12px 14px; }
.pq.bad { border-color: var(--warn); background: var(--warn-bg); }
.pq .q { font-weight: 700; margin: 0 0 6px; }
.pq .why { color: var(--warn); font-size: .9rem; margin: 0 0 4px; }
.pq ol { list-style: none; margin: 0; padding: 0; font-size: .95rem; }
.pq li { display: flex; gap: 8px; align-items: baseline; padding: 1px 0; }
.pq li button { font: inherit; font-size: .8rem; border: 1px solid var(--line); background: transparent; color: var(--muted); border-radius: 6px; padding: 0 7px; cursor: pointer; flex: none; }
.pq li.c button { background: var(--ok); border-color: var(--ok); color: #fff; }
.pq li.c { color: var(--ok); font-weight: 600; }
.pq .noans { color: var(--muted); font-size: .85rem; margin: 4px 0 0; }

/* my questions + edit mode */
.edit-banner { display: flex; justify-content: space-between; align-items: center; gap: 10px; background: var(--warn-bg); color: var(--warn); border-radius: 10px; padding: 8px 12px; margin-bottom: 14px; font-weight: 600; }
button.link { font: inherit; background: none; border: 0; color: var(--primary); cursor: pointer; text-decoration: underline; padding: 4px; }
.pq .meta { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin: 0 0 6px; font-size: .82rem; color: var(--muted); }
.pq .st { border: 1px solid var(--line); border-radius: 6px; padding: 0 8px; }
.pq .st.approved { color: var(--ok); border-color: var(--ok); }
.pq .st.new { color: var(--warn); border-color: var(--warn); }
.pq .acts { display: flex; gap: 8px; margin-top: 10px; }
.pq .acts button { font: inherit; font-size: .9rem; background: var(--card); color: var(--text); border: 1.5px solid var(--line); border-radius: 10px; padding: 6px 16px; min-height: 40px; cursor: pointer; }
.pq .acts button.danger { color: var(--err); }

/* toast */
#toast {
  position: fixed; inset-inline: 16px; bottom: calc(18px + env(safe-area-inset-bottom)); margin: 0 auto; max-width: 420px;
  background: #1c2230; color: #fff; border-radius: 12px; padding: 12px 16px; text-align: center; font-weight: 600;
  opacity: 0; transform: translateY(12px); pointer-events: none; transition: opacity .2s, transform .2s;
}
#toast.show { opacity: 1; transform: none; }
#toast.ok { background: var(--ok); color: #fff; }
#toast.warn { background: var(--warn); color: #fff; }
#toast.err { background: var(--err); color: #fff; }

@media (min-width: 700px) { .desktop-only { display: block; } }
@media (max-width: 699px) { .desktop-only { display: none; } }
@media (prefers-reduced-motion: reduce) { #toast { transition: none; } }
