:root {
  --bg: #0f0d0b;
  --panel: #191612;
  --panel-2: #221e19;
  --line: #2f2a23;
  --text: #ece4d8;
  --muted: #9a8f80;
  --accent: #d9a441;
  --accent-ink: #1a1306;
  --danger: #d0604d;
  --ok: #7fae6e;
  --radius: 12px;
  --ui: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --ar: "Noto Naskh Arabic", "Geeza Pro", "Times New Roman", serif;
  --display: "Fraunces", Georgia, serif;
  --s-idea: #8a8378;
  --s-research: #5f8fb5;
  --s-script: #b58ad1;
  --s-editing: #d9a441;
  --s-published: #7fae6e;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.5 var(--ui); -webkit-text-size-adjust: 100%; }
a { color: var(--accent); text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }

/* ---------- top bar / nav ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 24px;
  padding: calc(env(safe-area-inset-top) + 12px) 20px 12px;
  background: rgba(15, 13, 11, .92); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { font-family: var(--display); font-size: 22px; color: var(--text); letter-spacing: .3px; }
.tabs { display: flex; gap: 6px; }
.tabs a { color: var(--muted); padding: 6px 12px; border-radius: 999px; font-weight: 500; position: relative; }
.tabs a.active { color: var(--text); background: var(--panel-2); }
.badge { display: inline-block; min-width: 18px; padding: 0 5px; margin-left: 4px; border-radius: 9px; background: var(--accent); color: var(--accent-ink); font-size: 11px; font-weight: 600; text-align: center; line-height: 18px; }

@media (max-width: 700px) {
  .topbar { justify-content: center; backdrop-filter: none; background: var(--bg); }
  .tabs {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
    justify-content: space-around; padding: 8px 8px calc(env(safe-area-inset-bottom) + 8px);
    background: rgba(25, 22, 18, .96); backdrop-filter: blur(10px); border-top: 1px solid var(--line);
  }
  .tabs a { flex: 1; text-align: center; }
  main { padding-bottom: calc(env(safe-area-inset-bottom) + 80px) !important; }
}

main { max-width: 980px; margin: 0 auto; padding: 20px; }
.loading, .empty { color: var(--muted); padding: 40px 0; text-align: center; }

/* ---------- generic ---------- */
h1 { font-family: var(--display); font-weight: 600; font-size: 28px; margin: 4px 0 16px; }
h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 28px 0 10px; font-weight: 600; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 16px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--panel-2); color: var(--text); cursor: pointer; font-weight: 500; white-space: nowrap;
}
.btn:hover { border-color: #4a4237; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.danger { color: var(--danger); }
.btn.ghost { background: transparent; }
.btn:disabled { opacity: .5; cursor: default; }

input[type=text], input[type=email], input[type=password], input[type=url], textarea, select {
  width: 100%; padding: 10px 12px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--panel-2); outline: none;
}
input:focus, textarea:focus, select:focus { border-color: var(--accent); }
label { display: block; font-size: 13px; color: var(--muted); margin: 12px 0 6px; }

/* ---------- login ---------- */
.login { max-width: 360px; margin: 12vh auto 0; }
.login h1 { font-size: 40px; margin-bottom: 4px; }
.login .btn { width: 100%; margin-top: 18px; }
.error { color: var(--danger); font-size: 14px; margin-top: 10px; }

/* ---------- projects list ---------- */
.filters { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 14px; scrollbar-width: none; }
.filters button { border: 1px solid var(--line); background: transparent; color: var(--muted); padding: 5px 12px; border-radius: 999px; cursor: pointer; white-space: nowrap; }
.filters button.on { background: var(--panel-2); color: var(--text); border-color: #4a4237; }
.plist { display: grid; gap: 10px; }
.pitem { display: flex; gap: 14px; align-items: center; color: var(--text); }
.pitem:hover { border-color: #4a4237; }
.pitem .t { font-size: 17px; font-weight: 500; unicode-bidi: plaintext; }
.pill { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; padding: 3px 10px; border-radius: 999px; background: var(--panel-2); white-space: nowrap; }
.pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--c, var(--muted)); }

/* ---------- project page ---------- */
.titleinput { width: calc(100% + 8px); font-family: var(--display); font-size: 26px; font-weight: 600; background: transparent; border: 1px solid transparent; padding: 4px 8px; margin-left: -8px; unicode-bidi: plaintext; }
.titleinput:hover { border-color: var(--line); }
.stepper { display: flex; gap: 4px; overflow-x: auto; margin: 6px 0 4px; scrollbar-width: none; }
.stepper button {
  flex: 1; min-width: 86px; padding: 8px 6px; border-radius: 9px; cursor: pointer;
  border: 1px solid var(--line); background: var(--panel); color: var(--muted); font-size: 13px; font-weight: 500; white-space: nowrap;
}
.stepper button.done { color: var(--text); }
.stepper button.on { background: var(--c); border-color: var(--c); color: #120f0b; font-weight: 600; }
.subtabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin: 22px 0 16px; overflow-x: auto; scrollbar-width: none; }
.subtabs button { background: none; border: none; color: var(--muted); padding: 10px 14px; cursor: pointer; border-bottom: 2px solid transparent; font-weight: 500; white-space: nowrap; }
.subtabs button.on { color: var(--text); border-bottom-color: var(--accent); }

.script {
  width: 100%; min-height: 60vh; resize: vertical;
  font-family: var(--ar); font-size: 19px; line-height: 2;
  padding: 18px 20px; direction: rtl; text-align: right;
  background: var(--panel); border-radius: var(--radius);
}
.savebar { position: sticky; bottom: 0; display: flex; gap: 10px; align-items: center; padding: 12px 0; background: linear-gradient(transparent, var(--bg) 30%); }
@media (max-width: 700px) { .savebar { bottom: calc(env(safe-area-inset-bottom) + 62px); } }
.dirty { color: var(--accent); font-size: 13px; }

.banner { background: #2b2213; border: 1px solid #5a4520; color: #f1d8a6; padding: 10px 14px; border-radius: 10px; margin-bottom: 12px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

.pdfframe { width: 100%; height: 75vh; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; }

.srclist { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.srclist li { display: flex; gap: 10px; align-items: flex-start; }
.srclist .u { word-break: break-all; }
.srclist .n { unicode-bidi: plaintext; color: var(--muted); font-size: 14px; }

.versions { display: grid; grid-template-columns: 260px 1fr; gap: 14px; }
@media (max-width: 700px) { .versions { grid-template-columns: 1fr; } }
.vlist { display: grid; gap: 6px; align-content: start; max-height: 70vh; overflow: auto; }
.vlist button { text-align: left; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--panel); cursor: pointer; }
.vlist button.on { border-color: var(--accent); }
.vview { white-space: pre-wrap; direction: rtl; text-align: right; font-family: var(--ar); font-size: 18px; line-height: 2; }
.vview del { background: rgba(208, 96, 77, .22); color: #f0b3a8; text-decoration: line-through; }
.vview ins { background: rgba(127, 174, 110, .22); color: #c9e6bd; text-decoration: none; }

/* ---------- activity ---------- */
.feed { list-style: none; padding: 0; margin: 0; }
.feed li { display: flex; gap: 12px; padding: 14px 4px; border-bottom: 1px solid var(--line); }
.feed li.new { background: linear-gradient(90deg, rgba(217, 164, 65, .10), transparent); }
.avatar { flex: none; width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; font-weight: 600; font-size: 14px; background: var(--panel-2); color: var(--accent); text-transform: uppercase; }
.feed .what { unicode-bidi: plaintext; }
.feed .ptitle { color: var(--text); font-weight: 500; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(env(safe-area-inset-bottom) + 90px); z-index: 50;
  background: var(--panel-2); border: 1px solid #4a4237; padding: 10px 16px; border-radius: 10px;
  box-shadow: 0 10px 30px rgba(0,0,0,.4); max-width: 90vw; unicode-bidi: plaintext;
}

dialog { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; width: min(420px, 92vw); }
dialog::backdrop { background: rgba(0,0,0,.6); }
