:root {
  --paper: #F3EBDA;
  --paper-2: #EADFC8;
  --ink: #1F2A44;
  --text: #2A2620;
  --muted: #8A7F6C;
  --seal: #8C2F1B;
  --card: #F8F2E5;
  --shadow: 0 1px 0 rgba(60, 40, 10, .06), 0 6px 18px -10px rgba(60, 40, 10, .25);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #16140F;
    --paper-2: #1E1B15;
    --ink: #E9DFC8;
    --text: #E2D8C2;
    --muted: #8D846F;
    --seal: #D0774F;
    --card: #1D1A14;
    --shadow: 0 1px 0 rgba(0, 0, 0, .3), 0 8px 20px -12px rgba(0, 0, 0, .7);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--text);
  font: 16px/1.7 'IBM Plex Sans Arabic', system-ui, -apple-system, 'Segoe UI', Tahoma, sans-serif;
  -webkit-tap-highlight-color: transparent;
  min-height: 100dvh;
}
button, textarea, input { font: inherit; color: inherit; }
button { cursor: pointer; touch-action: manipulation; -webkit-user-select: none; user-select: none; }

.app {
  max-width: 640px;
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) 16px max(32px, env(safe-area-inset-bottom));
}

/* Header */
.top { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 12px; position: relative; padding: 8px 0 20px; }
.brand { text-align: center; }
.logo { font-family: 'Aref Ruqaa', 'Noto Naskh Arabic', serif; font-weight: 700; font-size: 56px; line-height: 1; color: var(--ink); }
.tag { font-size: 13px; color: var(--muted); margin-top: 6px; letter-spacing: .02em; }
.side { font-size: 12px; line-height: 1.5; color: var(--muted); }
.side:first-child { text-align: right; }
.side:nth-child(3) { text-align: left; }
.icon-btn { position: absolute; top: 0; left: 0; background: none; border: 0; color: var(--muted); padding: 8px; border-radius: 50%; }
.icon-btn:hover { color: var(--ink); }
@media (max-width: 420px) { .side { visibility: hidden; } }

/* Compose */
.compose { background: var(--card); border-radius: 14px; box-shadow: var(--shadow); padding: 14px; display: grid; gap: 10px; }
.compose textarea, .sheet textarea {
  width: 100%; border: 0; outline: 0; resize: none; background: transparent;
  font-family: 'Noto Naskh Arabic', serif; font-size: 19px; line-height: 1.9; color: var(--ink);
}
.compose textarea::placeholder { color: var(--muted); opacity: .7; }

.btn { border: 0; border-radius: 999px; padding: 10px 20px; font-weight: 600; font-size: 15px; transition: transform .12s ease, opacity .2s ease, background .2s ease; }
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .35; cursor: default; transform: none; }
.btn.ink { background: var(--ink); color: var(--paper); }
.btn.ghost { background: transparent; color: var(--ink); box-shadow: inset 0 0 0 1.5px color-mix(in oklab, var(--ink) 25%, transparent); }
.btn.danger { background: transparent; color: var(--seal); }
.compose .btn { justify-self: start; }

/* Sections */
.section { margin-top: 28px; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin: 0 4px 10px; }
.section-head h2 { margin: 0; font-size: 15px; font-weight: 600; color: var(--ink); }
.section-head p { margin: 0; font-size: 12px; color: var(--muted); text-align: left; }
.section.near h2 { color: var(--seal); }

.notes { display: grid; gap: 10px; }
.note {
  display: block; width: 100%; text-align: right; border: 0; border-radius: 12px;
  padding: 14px 16px 10px; background-color: var(--card); box-shadow: var(--shadow);
  -webkit-user-select: text; user-select: text;
}
.note:active { transform: scale(.995); }
.note .ink {
  font-family: 'Noto Naskh Arabic', serif; font-size: 18px; line-height: 1.9;
  display: -webkit-box; -webkit-line-clamp: 6; -webkit-box-orient: vertical; overflow: hidden;
  white-space: pre-wrap; overflow-wrap: anywhere;
}
.w {
  color: color-mix(in oklab, var(--ink) calc(var(--k) * 1%), transparent);
  transition: color 1.6s cubic-bezier(.2, .7, .2, 1) var(--d, 0s);
}
.note .meta { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); margin-top: 6px; }
.note.pinned { box-shadow: var(--shadow), inset -3px 0 0 var(--seal); }

.empty { text-align: center; color: var(--muted); margin: 40px 0; font-family: 'Noto Naskh Arabic', serif; font-size: 18px; }

/* Intro */
.intro { margin-top: 20px; padding: 18px; border-radius: 14px; box-shadow: inset 0 0 0 1.5px color-mix(in oklab, var(--ink) 15%, transparent); }
.intro h2 { margin: 0 0 6px; font-size: 17px; color: var(--ink); }
.intro p { margin: 0 0 14px; color: var(--text); }
.intro .row { display: flex; flex-wrap: wrap; gap: 8px; }

/* Foot */
.foot { text-align: center; font-size: 12px; color: var(--muted); margin-top: 40px; line-height: 2; }
.foot a { color: var(--muted); }

/* Sheets */
.sheet {
  border: 0; padding: 0; margin: auto auto 0; width: min(640px, 100%); max-height: 92dvh;
  background: var(--paper); color: var(--text); border-radius: 20px 20px 0 0;
  box-shadow: 0 -10px 40px rgba(0, 0, 0, .25);
}
.sheet::backdrop { background: rgba(10, 8, 4, .45); }
.sheet[open] { animation: up .28s cubic-bezier(.2, .8, .2, 1); }
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
.sheet-body { padding: 20px 16px max(20px, env(safe-area-inset-bottom)); display: grid; gap: 12px; }
.sheet h2 { margin: 0; font-size: 18px; color: var(--ink); }
.sheet h3 { margin: 8px 0 0; font-size: 14px; color: var(--muted); font-weight: 500; }
.sheet textarea { min-height: 38dvh; background: var(--card); border-radius: 12px; padding: 12px 14px; }
.sheet-meta { margin: 0; font-size: 13px; color: var(--muted); }
.sheet-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.muted { color: var(--muted); font-size: 13px; margin: 4px 0; }

.choices { display: flex; flex-wrap: wrap; gap: 8px; }
.choices label { position: relative; }
.choices input { position: absolute; opacity: 0; inset: 0; }
.choices span { display: inline-block; padding: 8px 16px; border-radius: 999px; box-shadow: inset 0 0 0 1.5px color-mix(in oklab, var(--ink) 25%, transparent); color: var(--ink); }
.choices input:checked + span { background: var(--ink); color: var(--paper); box-shadow: none; }
.choices input:focus-visible + span { outline: 2px solid var(--seal); outline-offset: 2px; }

/* Toast + banner */
#toast {
  position: fixed; left: 50%; bottom: max(24px, env(safe-area-inset-bottom)); transform: translate(-50%, 20px);
  background: var(--ink); color: var(--paper); padding: 10px 18px; border-radius: 999px; font-size: 14px;
  opacity: 0; pointer-events: none; transition: opacity .25s ease, transform .25s ease; max-width: calc(100% - 32px); text-align: center;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
.banner { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 14px; margin-bottom: 14px; border-radius: 12px; background: var(--paper-2); font-size: 14px; }

@media (prefers-reduced-motion: reduce) {
  .w { transition: none; }
  .sheet[open] { animation: none; }
}
