:root {
  --background: #f2f4f7;
  --card: #ffffff;
  --text: #111827;
  --muted: #667085;
  --accent: #6d28d9;
  --accent-text: #ffffff;
  --radius: 22px;
  --shadow: 0 12px 35px rgba(16, 24, 40, .10);
}

* { box-sizing: border-box; }
html { min-height: 100%; }
body {
  min-height: 100%;
  margin: 0;
  color: var(--text);
  background: var(--background);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, a { -webkit-tap-highlight-color: transparent; }
button { font: inherit; }
a { color: inherit; }

#backgroundLayer {
  position: fixed;
  inset: 0;
  z-index: -1;
  background-color: var(--background);
  background-position: center;
  background-size: cover;
  background-attachment: fixed;
}

.site-shell {
  width: min(100%, 720px);
  margin: 0 auto;
  padding: max(28px, env(safe-area-inset-top)) 18px max(34px, env(safe-area-inset-bottom));
}

.profile-header {
  position: relative;
  text-align: center;
  padding: 12px 42px 18px;
}

.share-button {
  position: absolute;
  top: 0;
  right: 0;
}

.icon-button {
  width: 42px;
  height: 42px;
  border: 1px solid color-mix(in srgb, var(--text) 12%, transparent);
  border-radius: 999px;
  display: inline-grid;
  place-items: center;
  background: color-mix(in srgb, var(--card) 88%, transparent);
  color: var(--text);
  cursor: pointer;
  backdrop-filter: blur(12px);
}
.icon-button:hover { transform: translateY(-1px); }
.icon-button svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.avatar-wrap {
  width: 92px;
  height: 92px;
  margin: 0 auto 14px;
  border-radius: 50%;
  padding: 4px;
  background: color-mix(in srgb, var(--card) 86%, transparent);
  box-shadow: var(--shadow);
}
.avatar { width: 100%; height: 100%; object-fit: cover; border-radius: inherit; display: block; }
.profile-name { margin: 0; font-size: clamp(24px, 6vw, 34px); line-height: 1.15; letter-spacing: -.03em; }
.profile-bio { margin: 10px auto 0; max-width: 560px; color: var(--muted); font-size: 15px; line-height: 1.55; white-space: pre-wrap; }
.socials { display: flex; justify-content: center; flex-wrap: wrap; gap: 10px; margin-top: 16px; }
.social-link {
  width: 40px;
  height: 40px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  color: var(--text);
  background: color-mix(in srgb, var(--card) 88%, transparent);
  border: 1px solid color-mix(in srgb, var(--text) 10%, transparent);
  text-decoration: none;
  transition: transform .18s ease, box-shadow .18s ease;
}
.social-link:hover { transform: translateY(-2px); box-shadow: 0 8px 18px rgba(16, 24, 40, .12); }
.social-link svg { width: 20px; height: 20px; fill: currentColor; }

.content { display: grid; gap: 24px; }
.collection { display: grid; gap: 12px; }
.collection-body { display: grid; gap: 12px; }
.collection-body[hidden] { display: none !important; }
.collection-title { display: block; min-width: 0; margin: 2px 6px 0; font-size: 14px; font-weight: 750; letter-spacing: .01em; overflow-wrap: anywhere; }
.collection-toggle { width: 100%; border: 0; background: transparent; color: var(--text); display: grid; grid-template-columns: minmax(0,1fr) auto; align-items: center; gap: 8px; padding: 0; cursor: pointer; }
.collection-toggle .collection-title { margin: 0 6px; }
.collection-chevron { width: 9px; height: 9px; margin-right: 4px; border-right: 2px solid currentColor; border-bottom: 2px solid currentColor; transform: rotate(45deg); transition: transform .18s ease; }
.collection-toggle[aria-expanded="true"] .collection-chevron { transform: rotate(225deg); }

.card {
  position: relative;
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--card) 96%, transparent);
  border: 1px solid color-mix(in srgb, var(--text) 9%, transparent);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.card-link {
  min-height: 74px;
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 14px;
  align-items: center;
  padding: 12px 16px 12px 12px;
  text-decoration: none;
  transition: transform .18s ease, box-shadow .18s ease;
}
.card-link:hover { transform: translateY(-2px); box-shadow: 0 16px 36px rgba(16, 24, 40, .15); }
.card-link.featured { min-height: 170px; grid-template-columns: 1fr; align-content: end; padding: 18px; }
.card-link.featured.has-image::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(to top, rgba(0,0,0,.68), rgba(0,0,0,.04) 70%);
  z-index: 1;
}
.card-link.featured .link-copy { position: relative; z-index: 2; }
.card-link.featured.has-image .link-title,
.card-link.featured.has-image .link-subtitle { color: #fff; }
.card-link.featured .link-arrow { position: absolute; top: 14px; right: 14px; z-index: 2; }
.link-thumb { width: 52px; height: 52px; border-radius: calc(var(--radius) * .55); object-fit: cover; background: color-mix(in srgb, var(--background) 80%, var(--card)); }
.featured-image { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.link-copy { min-width: 0; }
.link-title { margin: 0; font-size: 15px; line-height: 1.35; font-weight: 750; }
.link-subtitle { margin: 4px 0 0; color: var(--muted); font-size: 13px; line-height: 1.4; white-space: pre-wrap; }
.link-arrow {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: color-mix(in srgb, var(--background) 70%, transparent);
}
.link-arrow svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.note-card { padding: 20px; }
.note-card.classic { padding: 16px 18px; }
.note-media { width: 100%; max-height: 300px; object-fit: cover; border-radius: calc(var(--radius) * .7); margin-bottom: 16px; }
.note-title { margin: 0 0 8px; font-size: 17px; line-height: 1.3; }
.note-text { margin: 0; color: var(--muted); font-size: 14px; line-height: 1.58; white-space: pre-wrap; }
.note-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 17px; }
.note-button {
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 16px;
  border-radius: 999px;
  text-decoration: none;
  font-size: 14px;
  font-weight: 720;
  transition: transform .16s ease, opacity .16s ease;
}
.note-button:hover { transform: translateY(-1px); }
.note-button.primary { background: var(--accent); color: var(--accent-text); }
.note-button.secondary { background: transparent; color: var(--text); border: 1px solid color-mix(in srgb, var(--text) 18%, transparent); }
.note-button.text { padding-inline: 3px; color: var(--accent); }

.heading-block { margin: 8px 6px 2px; font-size: 18px; line-height: 1.35; text-align: center; }
.empty-state, .error-state {
  padding: 24px;
  text-align: center;
  color: var(--muted);
  background: color-mix(in srgb, var(--card) 90%, transparent);
  border: 1px dashed color-mix(in srgb, var(--text) 18%, transparent);
  border-radius: var(--radius);
}

.footer { padding: 24px 8px 0; text-align: center; color: var(--muted); font-size: 12px; }
.footer p { margin: 6px 0; white-space: pre-wrap; }
.toast {
  position: fixed;
  left: 50%;
  bottom: max(22px, env(safe-area-inset-bottom));
  transform: translate(-50%, 14px);
  opacity: 0;
  pointer-events: none;
  padding: 10px 15px;
  border-radius: 999px;
  color: #fff;
  background: #111827;
  box-shadow: 0 12px 28px rgba(0,0,0,.24);
  transition: opacity .2s ease, transform .2s ease;
  z-index: 20;
  font-size: 13px;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 520px) {
  .site-shell { padding-inline: 14px; }
  .profile-header { padding-inline: 36px; }
  .profile-name { font-size: 25px; }
  .card-link.featured { min-height: 150px; }
  .note-actions { display: grid; }
  .note-button { width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}


/* Automatic Arabic and mixed-language direction */
[dir="rtl"] { direction: rtl; }
[dir="ltr"] { direction: ltr; }
.card[dir="rtl"], .note-card[dir="rtl"], .card-link[dir="rtl"] { text-align: right; }
.card[dir="ltr"], .note-card[dir="ltr"], .card-link[dir="ltr"] { text-align: left; }
.note-actions { justify-content: flex-start; }


/* Manual alignment and note detail layouts */
[data-align="left"] { text-align: left; direction: ltr; }
[data-align="center"] { text-align: center; direction: auto; }
[data-align="right"] { text-align: right; direction: rtl; }
.card-link[data-align="center"] { grid-template-columns: auto 1fr auto; }
.note-summary-card { width: 100%; min-height: 76px; display: grid; grid-template-columns: auto 1fr auto; gap: 14px; align-items: center; padding: 12px 16px 12px 12px; color: var(--text); font: inherit; cursor: pointer; }
.note-summary-card:hover { transform: translateY(-2px); box-shadow: 0 16px 36px rgba(16,24,40,.15); }
.note-summary-thumb { width: 52px; height: 52px; border-radius: calc(var(--radius) * .55); object-fit: cover; background: color-mix(in srgb, var(--background) 80%, var(--card)); }
.note-summary-copy { min-width: 0; }
.note-summary-title { margin: 0; font-size: 15px; line-height: 1.35; font-weight: 750; }
.note-summary-text { margin: 4px 0 0; color: var(--muted); font-size: 13px; line-height: 1.4; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.note-summary-arrow { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; background: color-mix(in srgb, var(--background) 70%, transparent); font-size: 24px; line-height: 1; }
.inline-note-link { color: var(--accent); text-decoration: underline; text-underline-offset: 2px; overflow-wrap: anywhere; }
.note-text { unicode-bidi: plaintext; }
body.detail-open { overflow: hidden; }
.note-detail { position: fixed; inset: 0; z-index: 50; background: rgba(16,24,40,.44); backdrop-filter: blur(4px); padding: 0; }
.note-detail-shell { width: min(100%, 720px); height: 100%; margin: 0 auto; display: flex; flex-direction: column; background: var(--background); color: var(--text); box-shadow: 0 0 60px rgba(0,0,0,.25); }
.note-detail-header { min-height: 66px; display: grid; grid-template-columns: 42px 1fr 42px; align-items: center; gap: 10px; padding: max(12px, env(safe-area-inset-top)) 16px 12px; border-bottom: 1px solid color-mix(in srgb, var(--text) 10%, transparent); background: color-mix(in srgb, var(--card) 94%, transparent); position: sticky; top: 0; z-index: 2; }
.note-detail-header strong { text-align: center; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.detail-icon-button { width: 40px; height: 40px; border: 1px solid color-mix(in srgb, var(--text) 12%, transparent); border-radius: 50%; background: var(--card); color: var(--text); font-size: 23px; display: grid; place-items: center; cursor: pointer; }
.note-detail-content { flex: 1; overflow: auto; padding: 18px 18px max(30px, env(safe-area-inset-bottom)); }
.note-detail-note { min-height: 100%; padding: 22px; border-radius: var(--radius); background: var(--card); border: 1px solid color-mix(in srgb, var(--text) 9%, transparent); box-shadow: var(--shadow); }
.note-detail-note .note-media { max-height: 360px; }
.note-detail-note .note-text { color: var(--text); }
.note-card.featured .note-text { color: var(--muted); }

@media (max-width: 520px) {
  .note-detail-content { padding: 10px; }
  .note-detail-note { padding: 18px; border-radius: 18px; }
}

/* Profile alignment */
.profile-header[data-align="left"] { text-align: left; }
.profile-header[data-align="center"] { text-align: center; }
.profile-header[data-align="right"] { text-align: right; }
.profile-header[data-align="left"] .avatar-wrap { margin-left: 0; margin-right: auto; }
.profile-header[data-align="center"] .avatar-wrap { margin-left: auto; margin-right: auto; }
.profile-header[data-align="right"] .avatar-wrap { margin-left: auto; margin-right: 0; }
.profile-header[data-align="left"] .profile-bio { margin-left: 0; margin-right: auto; }
.profile-header[data-align="center"] .profile-bio { margin-left: auto; margin-right: auto; }
.profile-header[data-align="right"] .profile-bio { margin-left: auto; margin-right: 0; }
.profile-header[data-align="left"] .socials { justify-content: flex-start; }
.profile-header[data-align="center"] .socials { justify-content: center; }
.profile-header[data-align="right"] .socials { justify-content: flex-end; }
