/* ── Design tokens ── */
:root {
  --bg:            #F7F4EE;
  --bg-alt:        #EFEAE1;
  --surface:       #FFFFFF;
  --surface-2:     #FBF9F5;
  --ink:           #12211F;
  --text:          #1D2C2A;
  --muted:         #5F6F6C;
  --faint:         #8B9793;
  --primary:       #0F5C52;
  --primary-dark:  #0A423B;
  --primary-soft:  #E3EFEC;
  --accent:        #C9A227;
  --accent-soft:   #FBF3DC;
  --danger:        #B3261E;
  --danger-soft:   #FBEAE8;
  --border:        #E3DCD0;
  --border-strong: #D3C9B8;
  --radius-sm:     10px;
  --radius:        16px;
  --radius-lg:     22px;
  --shadow-sm:     0 1px 2px rgba(18,33,31,.05);
  --shadow:        0 6px 24px rgba(18,33,31,.07);
  --shadow-lg:     0 18px 50px rgba(18,33,31,.16);
  --font-head:     'Noto Naskh Arabic', 'Segoe UI', serif;
  --font-body:     'Noto Sans Arabic', 'Segoe UI', system-ui, sans-serif;
}
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }
body {
  font-family: var(--font-body);
  background: var(--bg); color: var(--text);
  line-height: 1.75; min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
}
.bg-wash {
  position: fixed; inset: 0; pointer-events: none; z-index: 0;
  background:
    radial-gradient(ellipse at 100% 0%, rgba(15,92,82,.10), transparent 55%),
    radial-gradient(ellipse at 0% 20%, rgba(201,162,39,.12), transparent 50%);
}
h1, h2, h3, strong { font-family: var(--font-head); }
button, input { font-family: inherit; }
::selection { background: var(--primary); color: #fff; }

/* ── Topbar ── */
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: .7rem clamp(1rem, 4vw, 2.5rem);
  background: rgba(247,244,238,.88); backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: .7rem; }
.brand-mark {
  width: 42px; height: 42px; border-radius: 13px; flex: none;
  display: grid; place-items: center;
  background: linear-gradient(140deg, var(--primary), var(--primary-dark));
  color: #fff; font-family: var(--font-head); font-size: .92rem; font-weight: 700;
  box-shadow: var(--shadow-sm);
}
.brand-text { display: flex; flex-direction: column; line-height: 1.3; }
.brand-text strong { font-size: 1.02rem; color: var(--ink); }
.brand-text span { font-size: .74rem; color: var(--muted); }
.top-actions { display: flex; gap: .5rem; flex-wrap: wrap; }

/* ── Buttons ── */
.btn {
  display: inline-flex; align-items: center; gap: .45rem;
  padding: .55rem 1rem; border-radius: 999px; cursor: pointer;
  font-size: .84rem; font-weight: 600; border: 1px solid transparent;
  transition: transform .18s ease, box-shadow .18s ease, background .18s ease, color .18s ease;
}
.btn svg { width: 16px; height: 16px; flex: none; }
.btn:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.btn-primary { background: var(--primary); color: #fff; box-shadow: 0 6px 20px rgba(15,92,82,.22); }
.btn-primary:hover { background: var(--primary-dark); transform: translateY(-2px); }
.btn-ghost { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-ghost:hover { background: var(--surface-2); border-color: var(--border-strong); transform: translateY(-2px); }
.btn-accent { background: var(--accent); color: #2A2205; }
.btn-accent:hover { transform: translateY(-2px); box-shadow: 0 8px 22px rgba(201,162,39,.35); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { transform: translateY(-2px); box-shadow: 0 8px 22px rgba(179,38,30,.3); }
.btn-quiet { background: transparent; color: var(--muted); border-color: var(--border); }
.btn-quiet:hover { color: var(--primary); border-color: var(--primary); background: var(--primary-soft); }

/* ── Hero ── */
.hero {
  position: relative; z-index: 1; text-align: center;
  max-width: 900px; margin: 0 auto; padding: clamp(2.5rem, 6vw, 4.5rem) 1.25rem 1.5rem;
  animation: fadeUp .6s ease both;
}
.eyebrow {
  display: inline-flex; align-items: center; gap: .4rem;
  font-size: .74rem; font-weight: 700; letter-spacing: .08em;
  color: var(--primary); background: var(--primary-soft);
  padding: .3rem .85rem; border-radius: 999px; margin-bottom: 1rem;
}
.eyebrow svg { width: 14px; height: 14px; }
.hero h1 {
  font-size: clamp(1.85rem, 4.6vw, 3rem); font-weight: 700; color: var(--ink);
  line-height: 1.25; margin-bottom: .9rem;
}
.hero p {
  color: var(--muted); font-size: clamp(.95rem, 1.6vw, 1.05rem);
  max-width: 720px; margin: 0 auto;
}
.hero p strong { color: var(--primary); }
.hero-stats {
  display: flex; flex-wrap: wrap; justify-content: center; gap: .6rem; margin-top: 1.75rem;
}
.stat-chip {
  display: inline-flex; align-items: center; gap: .5rem;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 999px; padding: .45rem 1rem; box-shadow: var(--shadow-sm);
  font-size: .84rem; color: var(--muted);
}
.stat-chip b { font-family: var(--font-head); font-size: 1.05rem; color: var(--ink); }
.stat-chip svg { width: 16px; height: 16px; color: var(--primary); }

/* ── Toolbar ── */
.toolbar {
  position: relative; z-index: 1;
  max-width: 1180px; margin: 1.5rem auto .5rem;
  padding: 0 clamp(1rem, 4vw, 2.5rem);
  display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap;
}
.tabs {
  display: inline-flex; gap: .2rem; padding: .25rem;
  background: var(--surface); border: 1px solid var(--border); border-radius: 999px;
}
.tab {
  display: inline-flex; align-items: center; gap: .4rem;
  padding: .45rem 1.05rem; border-radius: 999px; border: none; cursor: pointer;
  background: transparent; color: var(--muted); font-size: .84rem; font-weight: 600;
  transition: background .18s ease, color .18s ease;
}
.tab svg { width: 15px; height: 15px; }
.tab:hover { color: var(--primary); }
.tab.active { background: var(--primary); color: #fff; }
.search {
  display: flex; align-items: center; gap: .5rem; flex: 1 1 260px; max-width: 380px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 999px;
  padding: .45rem 1rem; box-shadow: var(--shadow-sm);
}
.search svg { width: 16px; height: 16px; color: var(--faint); }
.search input {
  border: none; outline: none; background: transparent; width: 100%;
  font-size: .88rem; color: var(--text);
}

/* ── Layout ── */
.wrap { position: relative; z-index: 1; max-width: 1180px; margin: 0 auto; padding: 1rem clamp(1rem, 4vw, 2.5rem) 3rem; }
.grid { display: grid; gap: 1.4rem; grid-template-columns: repeat(auto-fill, minmax(360px, 1fr)); }

/* ── Axis card ── */
.axis {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); box-shadow: var(--shadow);
  overflow: hidden; display: flex; flex-direction: column;
  animation: fadeUp .5s ease both;
  transition: transform .2s ease, box-shadow .2s ease, border-color .2s ease;
}
.axis:hover { transform: translateY(-3px); box-shadow: var(--shadow-lg); }
.axis.is-pinned { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft), var(--shadow); }
.axis-head {
  padding: 1.15rem 1.25rem 1rem;
  background: linear-gradient(150deg, var(--primary) 0%, var(--primary-dark) 100%);
  color: #fff; position: relative;
}
.axis-head-row { display: flex; align-items: flex-start; gap: .8rem; }
.axis-num {
  width: 38px; height: 38px; flex: none; border-radius: 12px;
  display: grid; place-items: center; font-family: var(--font-head); font-weight: 700; font-size: 1.1rem;
  background: rgba(255,255,255,.14); border: 1px solid rgba(255,255,255,.22);
}
.axis-title { font-family: var(--font-head); font-size: 1.12rem; font-weight: 700; line-height: 1.45; }
.axis-sub { font-size: .76rem; color: rgba(255,255,255,.72); margin-top: .3rem; }
.axis-head-actions { display: flex; gap: .35rem; margin-inline-start: auto; }
.icon-btn {
  width: 32px; height: 32px; border-radius: 10px; cursor: pointer; flex: none;
  display: grid; place-items: center; border: 1px solid transparent;
  background: rgba(255,255,255,.12); color: #fff;
  transition: background .18s ease, transform .18s ease, color .18s ease;
}
.icon-btn svg { width: 15px; height: 15px; }
.icon-btn:hover { background: rgba(255,255,255,.26); transform: translateY(-1px); }
.icon-btn.on { background: var(--accent); color: #2A2205; }
.axis-body { padding: 1.1rem 1.25rem 1.25rem; display: flex; flex-direction: column; gap: 1.1rem; }

/* ── Block (sub-axes / questions) ── */
.block-head {
  display: flex; align-items: center; gap: .5rem;
  font-size: .78rem; font-weight: 700; letter-spacing: .04em;
  color: var(--primary); text-transform: uppercase; margin-bottom: .55rem;
}
.block-head svg { width: 15px; height: 15px; }
.block-head .count { color: var(--faint); font-weight: 600; letter-spacing: 0; text-transform: none; }
.list { list-style: none; display: flex; flex-direction: column; gap: .5rem; }

.row {
  display: flex; align-items: flex-start; gap: .6rem;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: .6rem .7rem;
  transition: border-color .18s ease, background .18s ease, box-shadow .18s ease;
  animation: fadeUp .35s ease both;
}
.row:hover { border-color: var(--border-strong); background: #fff; box-shadow: var(--shadow-sm); }
.row.is-pinned { border-color: var(--accent); background: var(--accent-soft); }
.row-marker {
  flex: none; width: 22px; height: 22px; border-radius: 7px; margin-top: .22rem;
  display: grid; place-items: center; font-size: .7rem; font-weight: 700;
  background: var(--primary-soft); color: var(--primary); font-family: var(--font-head);
}
.row.q .row-marker { background: var(--accent-soft); color: #7A5F00; }
.row-text { flex: 1; font-size: .88rem; line-height: 1.65; color: var(--text); }
.row.q .row-text { font-family: var(--font-head); font-size: .92rem; }
.row-actions { display: flex; gap: .25rem; flex: none; opacity: .55; transition: opacity .18s ease; }
.row:hover .row-actions, .row:focus-within .row-actions { opacity: 1; }
.act {
  width: 28px; height: 28px; border-radius: 9px; cursor: pointer;
  display: grid; place-items: center; border: 1px solid var(--border);
  background: #fff; color: var(--muted);
  transition: all .16s ease;
}
.act svg { width: 14px; height: 14px; }
.act:hover { transform: translateY(-1px); }
.act.pin:hover { color: var(--accent); border-color: var(--accent); background: var(--accent-soft); }
.act.edit:hover { color: var(--primary); border-color: var(--primary); background: var(--primary-soft); }
.act.del:hover { color: var(--danger); border-color: var(--danger); background: var(--danger-soft); }
.act.is-pinned { background: var(--accent); border-color: var(--accent); color: #2A2205; }
.add-btn {
  margin-top: .5rem; width: 100%; justify-content: center;
  border: 1px dashed var(--border-strong); background: transparent;
  color: var(--muted); border-radius: var(--radius-sm); padding: .5rem;
  font-size: .8rem; font-weight: 600; cursor: pointer; display: inline-flex; align-items: center; gap: .4rem;
  transition: all .18s ease;
}
.add-btn svg { width: 15px; height: 15px; }
.add-btn:hover { border-color: var(--primary); color: var(--primary); background: var(--primary-soft); }

/* ── Modal / toast / empty ── */
.modal-root {
  position: fixed; inset: 0; z-index: 60; padding: 1rem;
  display: grid; place-items: center;
  background: rgba(18,33,31,.5); backdrop-filter: blur(4px);
  animation: fadeIn .2s ease both;
}
.modal {
  background: var(--surface); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
  width: min(620px, 100%); max-height: 88vh; overflow: auto; padding: 1.6rem;
  animation: fadeUp .3s ease both;
}
.modal h3 { font-size: 1.2rem; color: var(--ink); margin-bottom: .35rem; }
.modal .hint { font-size: .84rem; color: var(--muted); margin-bottom: 1rem; }
.modal textarea {
  width: 100%; min-height: 120px; resize: vertical; padding: .8rem .9rem;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface-2); color: var(--text); font-size: .92rem; line-height: 1.7; outline: none;
}
.modal textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.modal-foot { display: flex; justify-content: flex-end; gap: .5rem; margin-top: 1.15rem; flex-wrap: wrap; }
.export-box {
  width: 100%; min-height: 300px; direction: rtl; text-align: start;
  font-family: ui-monospace, 'Courier New', monospace; font-size: .8rem; line-height: 1.8;
}
.warn-note {
  display: flex; gap: .5rem; align-items: flex-start;
  background: var(--danger-soft); color: #7A1A14; border-radius: var(--radius-sm);
  padding: .7rem .85rem; font-size: .85rem; margin-bottom: 1rem;
}
.warn-note svg { width: 17px; height: 17px; flex: none; margin-top: .2rem; }
.toast-wrap { position: fixed; bottom: 1.25rem; inset-inline-start: 1.25rem; z-index: 80; display: flex; flex-direction: column; gap: .5rem; }
.toast {
  display: flex; align-items: center; gap: .5rem;
  padding: .7rem 1.1rem; border-radius: 999px; font-size: .85rem; font-weight: 600;
  background: var(--ink); color: #fff; box-shadow: var(--shadow-lg); animation: fadeUp .25s ease both;
}
.toast svg { width: 16px; height: 16px; }
.toast.ok { background: var(--primary); }
.toast.err { background: var(--danger); }
.toast.gold { background: var(--accent); color: #2A2205; }
.empty {
  grid-column: 1 / -1; text-align: center; padding: 4rem 1rem;
  border: 1px dashed var(--border-strong); border-radius: var(--radius-lg);
  color: var(--muted); background: var(--surface);
}
.empty svg { width: 34px; height: 34px; color: var(--faint); margin-bottom: .6rem; }

/* ── Footer ── */
.foot {
  position: relative; z-index: 1; text-align: center;
  padding: 1.5rem 1rem 2.5rem; color: var(--faint); font-size: .8rem;
  display: flex; justify-content: center; gap: .5rem; flex-wrap: wrap;
}
.foot .dot { color: var(--border-strong); }

/* ── Animations ── */
@keyframes fadeUp { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: none; } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* ── Responsive ── */
@media (max-width: 860px) {
  .grid { grid-template-columns: 1fr; }
  .top-actions .btn span { display: none; }
  .toolbar { justify-content: center; }
  .search { max-width: none; }
}
@media (max-width: 560px) {
  .topbar { flex-direction: column; align-items: stretch; }
  .top-actions { justify-content: center; }
  .axis-title { font-size: 1.02rem; }
  .row-actions { opacity: 1; }
  .hero h1 { font-size: 1.7rem; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* ── Fix: hidden attribute must win over display:grid ── */
.modal-root[hidden] { display: none; }
.row-actions { flex-wrap: wrap; }
