:root {
  color-scheme: light dark;
  --font-sans: "Inter", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-serif: "Noto Serif", "Times New Roman", serif;

  --transition-base: 200ms ease;

  --shadow-sm: 0 12px 25px rgba(15, 15, 15, 0.2);
  --shadow-md: 0 24px 45px rgba(10, 10, 10, 0.25);
}

html[data-theme="dark"] {
  --bg-primary: #0f172a;
  --bg-elevated: #111c33;
  --bg-accent: linear-gradient(135deg, rgba(99, 102, 241, 0.65), rgba(59, 130, 246, 0.55));
  --text-primary: #f8fafc;
  --text-secondary: #cbd5f5;
  --text-muted: #94a3b8;
  --border-color: rgba(148, 163, 184, 0.2);
  --accent: #60a5fa;
  --accent-strong: #93c5fd;
}

html[data-theme="light"] {
  --bg-primary: #f8fafc;
  --bg-elevated: #ffffff;
  --bg-accent: linear-gradient(135deg, rgba(99, 102, 241, 0.7), rgba(59, 130, 246, 0.6));
  --text-primary: #0f172a;
  --text-secondary: #1e293b;
  --text-muted: #475569;
  --border-color: rgba(148, 163, 184, 0.35);
  --accent: #2563eb;
  --accent-strong: #1d4ed8;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg-primary);
  color: var(--text-secondary);
  font-family: var(--font-sans);
  line-height: 1.6;
}

body.nav-open {
  overflow: hidden;
}

a {
  color: inherit;
}

a:hover,
a:focus {
  color: var(--accent);
}

img,
svg {
  display: block;
  max-width: 100%;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.site-header {
  position: sticky;
  top: 0;
  backdrop-filter: blur(16px);
  background: rgba(10, 16, 28, 0.85);
  border-bottom: 1px solid rgba(148, 163, 184, 0.1);
  z-index: 1000;
  transform: translateY(0);
  transition: transform var(--transition-base), background var(--transition-base), border-color var(--transition-base);
  will-change: transform;
  /* Respect safe area on iOS */
  padding-top: env(safe-area-inset-top, 0px);
}

html[data-theme="light"] .site-header {
  background: rgba(248, 250, 252, 0.9);
  border-bottom-color: rgba(148, 163, 184, 0.2);
}

.site-header.is-hidden {
  transform: translateY(-100%);
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  max-width: 1140px;
  margin: 0 auto;
  padding: 1rem clamp(1rem, 3vw, 2rem);
  gap: 1.75rem;
}

.branding {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  max-width: 18rem;
}

.site-title {
  font-family: var(--font-serif);
  font-size: clamp(1.1rem, 1.4vw, 1.45rem);
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: 0.01em;
}

.nav-toggle {
  display: none;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  width: 44px;
  height: 44px;
  border: 1px solid var(--border-color);
  border-radius: 0.75rem;
  background: var(--bg-elevated);
  cursor: pointer;
  transition: transform var(--transition-base), border-color var(--transition-base);
}

.nav-toggle:focus-visible,
.theme-toggle:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

.nav-toggle:hover {
  border-color: var(--accent);
}

.nav-toggle-bar {
  width: 20px;
  height: 2px;
  background: var(--text-primary);
  margin: 3px 0;
  border-radius: 2px;
  transition: background var(--transition-base);
}

.nav-links {
  display: flex;
  align-items: center;
  gap: clamp(0.8rem, 2vw, 1.5rem);
  list-style: none;
  padding: 0;
  margin: 0;
}

.nav-links > li {
  position: relative;
}

.nav-links > li > a,
.nav-links > li > .dropdown-header > a {
  position: relative;
  display: inline-flex;
  align-items: center;
  padding: 0.5rem 0;
  font-weight: 500;
  text-decoration: none;
  color: var(--text-muted);
  transition: color var(--transition-base);
}

.nav-links > li > a::after,
.nav-links > li > .dropdown-header > a::after {
  content: "";
  position: absolute;
  bottom: -0.35rem;
  left: 0;
  width: 100%;
  height: 2px;
  background: var(--accent);
  transform: scaleX(0);
  transform-origin: bottom right;
  transition: transform var(--transition-base);
}

.nav-links > li > a:hover::after,
.nav-links > li > a:focus::after,
.nav-links > li > a.active::after,
.nav-links > li > .dropdown-header > a:hover::after,
.nav-links > li > .dropdown-header > a:focus::after,
.nav-links > li > .dropdown-header > a.active::after {
  transform: scaleX(1);
  transform-origin: bottom left;
}

.nav-links > li > a.active,
.nav-links > li > .dropdown-header > a.active {
  color: var(--text-primary);
}

.nav-links > li.has-dropdown > .dropdown-header {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
}

.nav-links > li.has-dropdown > .dropdown-header > a {
  padding-right: 1.65rem;
}

.dropdown-toggle-button {
  display: none;
  width: 34px;
  height: 34px;
  border-radius: 0.75rem;
  border: 1px solid var(--border-color);
  background: var(--bg-elevated);
  color: var(--text-muted);
  cursor: pointer;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: transform var(--transition-base), border-color var(--transition-base), color var(--transition-base);
}

.dropdown-toggle-button:hover,
.dropdown-toggle-button:focus-visible {
  border-color: var(--accent);
  color: var(--accent);
}

.dropdown-toggle-button::before {
  content: "";
  width: 0.45rem;
  height: 0.45rem;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(45deg);
  transition: transform var(--transition-base);
}

.dropdown-toggle-button[aria-expanded="true"]::before {
  transform: rotate(-135deg);
}

.nav-links > li.has-dropdown > .dropdown-header > a::before {
  content: "";
  position: absolute;
  right: 0.1rem;
  top: 50%;
  width: 0.45rem;
  height: 0.45rem;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: translateY(-50%) rotate(45deg);
  transition: transform var(--transition-base);
}

.nav-links > li.has-dropdown:hover > .dropdown-header > a::before,
.nav-links > li.has-dropdown:focus-within > .dropdown-header > a::before {
  transform: translateY(-20%) rotate(225deg);
}

.nav-links .dropdown-menu {
  list-style: none;
  margin: 0;
  padding: 0.75rem;
  position: absolute;
  top: 100%;
  left: 0;
  min-width: clamp(14rem, 20vw, 18rem);
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  border-radius: 0;
  background: rgba(9, 14, 24, 0.98);
  box-shadow: 0 22px 48px rgba(15, 23, 42, 0.32);
  border: 1px solid rgba(148, 163, 184, 0.2);
  opacity: 0;
  visibility: hidden;
  transform: translateY(12px) scale(0.97);
  transform-origin: top;
  pointer-events: none;
  transition: opacity 200ms ease, transform 240ms cubic-bezier(0.22, 0.61, 0.36, 1), visibility 0s linear 240ms;
  z-index: 1200;
}

html[data-theme="light"] .nav-links .dropdown-menu {
  background: rgba(248, 250, 252, 0.98);
  border-color: rgba(148, 163, 184, 0.25);
  box-shadow: 0 22px 48px rgba(15, 23, 42, 0.16);
}

.nav-links .dropdown-menu::before {
  content: "";
  position: absolute;
  top: -12px;
  left: 0;
  width: 100%;
  height: 12px;
  background: transparent;
}

.nav-links .dropdown-menu li {
  opacity: 0;
  transform: perspective(600px) rotateY(90deg);
  transform-origin: left center;
  animation: none;
  backface-visibility: hidden;
}

.nav-links .dropdown-menu li:nth-child(1) { animation-delay: 0ms; }
.nav-links .dropdown-menu li:nth-child(2) { animation-delay: 60ms; }
.nav-links .dropdown-menu li:nth-child(3) { animation-delay: 120ms; }
.nav-links .dropdown-menu li:nth-child(4) { animation-delay: 180ms; }
.nav-links .dropdown-menu li:nth-child(5) { animation-delay: 240ms; }
.nav-links .dropdown-menu li:nth-child(6) { animation-delay: 300ms; }
.nav-links .dropdown-menu li:nth-child(7) { animation-delay: 360ms; }
.nav-links .dropdown-menu li:nth-child(8) { animation-delay: 420ms; }
.nav-links .dropdown-menu li:nth-child(9) { animation-delay: 480ms; }
.nav-links .dropdown-menu li:nth-child(10) { animation-delay: 540ms; }
.nav-links .dropdown-menu li:nth-child(11) { animation-delay: 600ms; }
.nav-links .dropdown-menu li:nth-child(12) { animation-delay: 660ms; }
.nav-links .dropdown-menu li:nth-child(13) { animation-delay: 720ms; }
.nav-links .dropdown-menu li:nth-child(14) { animation-delay: 780ms; }
.nav-links .dropdown-menu li:nth-child(n+15) { animation-delay: 780ms; }

.nav-links .dropdown-menu a {
  font-weight: 500;
  color: var(--text-muted);
  text-decoration: none;
  padding: 0.3rem 0;
  transition: color var(--transition-base);
}

.nav-links .dropdown-menu a:hover,
.nav-links .dropdown-menu a:focus-visible {
  color: var(--accent);
}

.nav-links > li.has-dropdown:hover > .dropdown-menu,
.nav-links > li.has-dropdown:focus-within > .dropdown-menu {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
  pointer-events: auto;
  transition-delay: 0s;
}

.nav-links > li.has-dropdown:hover > .dropdown-menu li,
.nav-links > li.has-dropdown:focus-within > .dropdown-menu li {
  opacity: 1;
  animation-name: homeDropdownReveal;
  animation-duration: 380ms;
  animation-fill-mode: forwards;
  animation-timing-function: cubic-bezier(0.22, 0.61, 0.36, 1);
}

@keyframes homeDropdownReveal {
  0% {
    transform: perspective(600px) rotateY(90deg);
    opacity: 0;
  }
  80% {
    transform: perspective(600px) rotateY(-10deg);
    opacity: 1;
  }
  100% {
    transform: perspective(600px) rotateY(0deg);
    opacity: 1;
  }
}

.theme-toggle {
  position: relative;
  width: 40px;
  height: 40px;
  border-radius: 0.9rem;
  border: 1px solid var(--border-color);
  background: var(--bg-elevated);
  cursor: pointer;
  display: grid;
  place-items: center;
  padding: 0;
  transition: transform var(--transition-base), border-color var(--transition-base);
}

.theme-toggle:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
}

.theme-icon {
  width: 20px;
  height: 20px;
  border-radius: 0.6rem;
  background-repeat: no-repeat;
  background-position: center;
  background-size: 18px 18px;
  transition: transform var(--transition-base), opacity var(--transition-base);
}

html[data-theme="dark"] .theme-icon {
  background-image: url("data:image/svg+xml,%3Csvg%20xmlns=%22http://www.w3.org/2000/svg%22%20viewBox=%220%200%2024%2024%22%20fill=%22none%22%20stroke=%22%23facc15%22%20stroke-width=%222%22%20stroke-linecap=%22round%22%20stroke-linejoin=%22round%22%3E%3Cpath%20d=%22M21%2012.79A9%209%200%201111.21%203%207%207%200%200021%2012.79z%22/%3E%3C/svg%3E");
}

html[data-theme="light"] .theme-icon {
  background-image: url("data:image/svg+xml,%3Csvg%20xmlns=%22http://www.w3.org/2000/svg%22%20viewBox=%220%200%2024%2024%22%20fill=%22none%22%20stroke=%22%23f59e0b%22%20stroke-width=%222%22%20stroke-linecap=%22round%22%20stroke-linejoin=%22round%22%3E%3Ccircle%20cx=%2212%22%20cy=%2212%22%20r=%225%22/%3E%3Cline%20x1=%2212%22%20x2=%2212%22%20y1=%221%22%20y2=%223%22/%3E%3Cline%20x1=%2212%22%20x2=%2212%22%20y1=%2221%22%20y2=%2223%22/%3E%3Cline%20x1=%224.22%22%20x2=%225.64%22%20y1=%224.22%22%20y2=%225.64%22/%3E%3Cline%20x1=%2218.36%22%20x2=%2219.78%22%20y1=%2218.36%22%20y2=%2219.78%22/%3E%3Cline%20x1=%221%22%20x2=%223%22%20y1=%2212%22%20y2=%2212%22/%3E%3Cline%20x1=%2221%22%20x2=%2223%22%20y1=%2212%22%20y2=%2212%22/%3E%3Cline%20x1=%224.22%22%20x2=%225.64%22%20y1=%2219.78%22%20y2=%2218.36%22/%3E%3Cline%20x1=%2218.36%22%20x2=%2219.78%22%20y1=%225.64%22%20y2=%224.22%22/%3E%3C/svg%3E");
}

main {
  max-width: 1140px;
  margin: 0 auto;
  padding: clamp(2rem, 6vw, 4rem) clamp(1rem, 3vw, 2rem) 4rem;
}

.hero {
  display: grid;
  gap: clamp(1.5rem, 4vw, 2.75rem);
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  padding: clamp(2.4rem, 5vw, 3.5rem);
  border-radius: 1.75rem;
  background: linear-gradient(145deg, rgba(37, 99, 235, 0.8), rgba(12, 74, 110, 0.75));
  color: #f8fafc;
  box-shadow: var(--shadow-md);
}

html[data-theme="light"] .hero {
  background: linear-gradient(145deg, rgba(37, 99, 235, 0.75), rgba(30, 64, 175, 0.7));
}

.page-hero {
  background: var(--bg-accent);
  color: var(--text-primary);
}

html[data-theme="dark"] .page-hero .hero-highlight {
  background: rgba(15, 23, 42, 0.45);
  border-color: rgba(226, 232, 240, 0.28);
}

.hero h1 {
  margin: 0 0 1rem;
  font-family: var(--font-serif);
  font-size: clamp(2.5rem, 5vw, 3.25rem);
  line-height: 1.1;
}

.hero p {
  margin: 0 0 1.5rem;
  color: rgba(241, 245, 249, 0.92);
}

.hero-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.65rem 1.35rem;
  border-radius: 999px;
  border: 1px solid transparent;
  font-weight: 600;
  font-size: 0.95rem;
  text-decoration: none;
  transition: background var(--transition-base), color var(--transition-base), transform var(--transition-base), box-shadow var(--transition-base);
}

.button.primary {
  background: rgba(248, 250, 252, 0.95);
  color: #0f172a;
  box-shadow: 0 12px 30px rgba(15, 23, 42, 0.25);
}

.button.primary:hover,
.button.primary:focus {
  transform: translateY(-2px);
  box-shadow: 0 15px 36px rgba(15, 23, 42, 0.35);
}

.button.secondary {
  background: transparent;
  color: #e2e8f0;
  border-color: rgba(226, 232, 240, 0.6);
}

.button.secondary:hover,
.button.secondary:focus {
  background: rgba(226, 232, 240, 0.15);
  border-color: rgba(226, 232, 240, 0.9);
}

.button.tertiary {
  background: var(--bg-elevated);
  color: var(--text-primary);
  border-color: var(--border-color);
}

.button.tertiary:hover,
.button.tertiary:focus {
  border-color: var(--accent);
  color: var(--accent-strong);
}

.hero-highlight {
  background: rgba(15, 23, 42, 0.35);
  border: 1px solid rgba(226, 232, 240, 0.22);
  border-radius: 1.25rem;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  font-family: var(--font-serif);
}

.hero-highlight p {
  font-size: 1.05rem;
  margin: 0;
}

.hero-highlight .highlight-source {
  align-self: flex-end;
  font-size: 0.85rem;
  letter-spacing: 0.02em;
}

.section-intro {
  max-width: 720px;
  margin: clamp(3rem, 6vw, 4.5rem) auto clamp(2rem, 4vw, 3rem);
  text-align: center;
}

.section-intro h2 {
  margin: 0 0 0.75rem;
  font-family: var(--font-serif);
  font-size: clamp(2rem, 4vw, 2.6rem);
  color: var(--text-primary);
}

.section-intro p {
  margin: 0;
  color: var(--text-muted);
}

.topics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: clamp(1.25rem, 3vw, 1.75rem);
}

.topic-card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding: clamp(1.4rem, 3vw, 1.8rem);
  background: var(--bg-elevated);
  border: 1px solid var(--border-color);
  border-radius: 1.4rem;
  box-shadow: var(--shadow-sm);
  transition: transform var(--transition-base), border-color var(--transition-base), box-shadow var(--transition-base);
}

.topic-card h3 {
  margin: 0;
  color: var(--text-primary);
  font-family: var(--font-serif);
  font-size: 1.15rem;
}

.topic-card p {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.95rem;
}

.topic-card .card-link {
  margin-top: auto;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-weight: 600;
  color: var(--accent);
  text-decoration: none;
}

.topic-card .card-link::after {
  content: "→";
  font-size: 1.1rem;
  transition: transform var(--transition-base);
}

.topic-card:hover,
.topic-card:focus-within {
  transform: translateY(-4px);
  border-color: var(--accent);
  box-shadow: 0 20px 35px rgba(37, 99, 235, 0.2);
}

.topic-card:hover .card-link::after,
.topic-card:focus-within .card-link::after {
  transform: translateX(4px);
}

.callout {
  margin-top: clamp(4rem, 8vw, 6rem);
  padding: clamp(2.5rem, 5vw, 3.5rem);
  border-radius: 1.75rem;
  border: 1px solid var(--border-color);
  background: var(--bg-elevated);
  box-shadow: var(--shadow-sm);
}

.callout h2 {
  margin: 0 0 1rem;
  font-family: var(--font-serif);
  color: var(--text-primary);
}

.callout p {
  margin: 0 0 1.5rem;
  color: var(--text-muted);
  max-width: 680px;
}

.contact-form {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  margin-top: 1.25rem;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1.25rem;
}

.form-grid label {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  font-weight: 600;
  color: var(--text-primary);
}

.form-grid input,
.form-grid select,
.form-grid textarea {
  padding: 0.75rem 0.9rem;
  border-radius: 0.9rem;
  border: 1px solid var(--border-color);
  background: var(--bg-elevated);
  color: var(--text-secondary);
  font: inherit;
  transition: border-color var(--transition-base), box-shadow var(--transition-base);
}

.form-grid input:focus,
.form-grid select:focus,
.form-grid textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.25);
  outline: none;
}

.form-grid textarea {
  resize: vertical;
}

.form-grid .full-width {
  grid-column: 1 / -1;
}

.post-section {
  margin-top: clamp(3.5rem, 7vw, 5rem);
}

.post-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: clamp(1.4rem, 3vw, 1.9rem);
}

.post-card {
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
  padding: clamp(1.4rem, 3vw, 1.9rem);
  background: var(--bg-elevated);
  border: 1px solid var(--border-color);
  border-radius: 1.45rem;
  box-shadow: var(--shadow-sm);
  transition: transform var(--transition-base), border-color var(--transition-base), box-shadow var(--transition-base);
}

.post-card .post-meta {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--accent-strong);
}

.post-card h3 {
  margin: 0;
  font-family: var(--font-serif);
  font-size: 1.35rem;
  color: var(--text-primary);
}

.post-card p {
  margin: 0;
  color: var(--text-muted);
}

.post-card .button {
  align-self: flex-start;
  margin-top: auto;
}

.post-card:hover,
.post-card:focus-within {
  transform: translateY(-6px);
  border-color: var(--accent);
  box-shadow: 0 24px 40px rgba(37, 99, 235, 0.18);
}

.post-card:hover .button,
.post-card:focus-within .button {
  border-color: var(--accent);
  color: var(--accent-strong);
}

.post {
  max-width: 800px;
  margin: clamp(2.5rem, 6vw, 4.5rem) auto 4.5rem;
  padding: clamp(2rem, 5vw, 3rem);
  background: var(--bg-elevated);
  border: 1px solid var(--border-color);
  border-radius: 1.75rem;
  box-shadow: var(--shadow-md);
}

.post-header {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  margin-bottom: clamp(2rem, 4vw, 2.8rem);
}

.post-meta {
  font-size: 0.8rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--accent-strong);
}

.post-title {
  margin: 0;
  font-family: var(--font-serif);
  font-size: clamp(2.2rem, 5vw, 2.9rem);
  line-height: 1.15;
  color: var(--text-primary);
}

.post-subtitle {
  margin: 0;
  font-size: 1.05rem;
  color: var(--text-muted);
}

.post-byline {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.post-byline .author-name {
  font-family: var(--font-serif);
  font-weight: 600;
}

.post-body {
  display: grid;
  gap: 1.5rem;
  font-size: 1.05rem;
  color: var(--text-secondary);
}

.post-body p {
  margin: 0;
}

.post-body blockquote {
  margin: 0;
  padding: 1.5rem 1.75rem;
  border-left: 4px solid var(--accent);
  border-radius: 1.1rem;
  background: rgba(37, 99, 235, 0.12);
  color: var(--text-primary);
  font-family: var(--font-serif);
  font-size: 1.05rem;
  line-height: 1.65;
}

.post-body blockquote cite {
  display: block;
  margin-top: 0.85rem;
  font-size: 0.9rem;
  font-style: normal;
  color: var(--text-muted);
}

.post-body strong {
  color: var(--text-primary);
}

.post-body em {
  font-family: var(--font-serif);
}

.post-body u {
  text-decoration-color: var(--accent);
  text-decoration-thickness: 0.12em;
  text-underline-offset: 0.25em;
}

.post-body .arabic-note {
  font-family: "Noto Serif", "Scheherazade New", serif;
  font-size: 1.05rem;
}

.dropcap {
  float: left;
  font-family: var(--font-serif);
  font-size: 3.2rem;
  line-height: 0.85;
  margin-right: 0.6rem;
  color: var(--accent-strong);
}

.post-footer {
  margin-top: clamp(2rem, 4vw, 3rem);
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  justify-content: space-between;
  align-items: center;
}

.post-footer .button.secondary {
  border-color: var(--accent);
  color: var(--accent-strong);
}

.post-footer .button.secondary:hover,
.post-footer .button.secondary:focus {
  background: rgba(37, 99, 235, 0.14);
}

/* In-page form alerts */
.form-alert {
  margin-top: 0.75rem;
  padding: 0.75rem 1rem;
  border-radius: 0.75rem;
  border: 1px solid var(--border-color);
  background: var(--bg-elevated);
  color: var(--text-secondary);
  font-size: 0.95rem;
}
.form-alert.success {
  border-color: rgba(34, 197, 94, 0.45);
  box-shadow: 0 6px 16px rgba(34, 197, 94, 0.15);
}
.form-alert.error {
  border-color: rgba(239, 68, 68, 0.45);
  box-shadow: 0 6px 16px rgba(239, 68, 68, 0.15);
}

/* --- Scroll reveal utilities (desktop + mobile) --- */
/* Only activate when JS adds the flag to avoid FOUC */
.reveal-enabled .reveal-on-scroll {
  opacity: 0;
  transform: translateY(8px);
  transition:
    opacity 280ms ease-out,
    transform 360ms cubic-bezier(0.22, 0.61, 0.36, 1);
  will-change: opacity, transform;
}

.reveal-enabled .reveal-on-scroll.is-visible {
  opacity: 1;
  transform: none;
}

/* Ensure hover/focus lift still applies to cards when revealed */
.reveal-enabled .topic-card.reveal-on-scroll.is-visible:hover,
.reveal-enabled .topic-card.reveal-on-scroll.is-visible:focus-within {
  transform: translateY(-4px);
}

.reveal-enabled .post-card.reveal-on-scroll.is-visible:hover,
.reveal-enabled .post-card.reveal-on-scroll.is-visible:focus-within {
  transform: translateY(-6px);
}

@media (prefers-reduced-motion: reduce) {
  .reveal-enabled .reveal-on-scroll {
    transition-duration: 1ms;
    transform: none;
    opacity: 1;
  }
}

.site-footer {
  border-top: 1px solid var(--border-color);
  padding: 2rem clamp(1rem, 3vw, 2rem);
  text-align: center;
  background: rgba(15, 23, 42, 0.75);
  color: var(--text-muted);
}

html[data-theme="light"] .site-footer {
  background: rgba(226, 232, 240, 0.5);
}

.site-footer p {
  margin: 0;
  font-size: 0.9rem;
}

@media (max-width: 960px) {
  /* Mobile: use container transform so the header fully slides out */
  .site-header { will-change: transform; }
  .site-header.is-hidden { transform: translateY(-100%); }
  /* Force fixed positioning for reliable slide on all mobile browsers */
  html.mobile-fixed-header .site-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    width: 100%;
  }
  html.mobile-fixed-header main {
    padding-top: var(--header-height, 64px);
  }
  /* Avoid horizontal scroll due to wide elements on mobile/tablet */
  html, body {
    overflow-x: hidden;
  }
  /* Standardize footer size across all pages on mobile/tablet widths */
  .site-footer {
    display: flex;
    align-items: center;
    justify-content: center;
    /* Increase side padding to keep text off edges on small screens */
    padding: 2rem clamp(1.25rem, 5vw, 1.75rem);
    padding-bottom: calc(2rem + env(safe-area-inset-bottom, 0px));
  }
  .site-footer p {
    /* Allow wrapping to prevent overflow beyond edges */
    white-space: normal;
    overflow-wrap: anywhere;
    word-break: break-word;
    font-size: 0.9rem; /* match home page */
    line-height: 1.3;
    max-width: 100%;
    text-align: center;
  }
  .header-inner {
    flex-wrap: nowrap;
    align-items: center;
    padding: 0.7rem clamp(0.85rem, 4vw, 1.3rem);
    gap: 0.75rem;
  }

  .branding {
    flex: 1 1 auto;
    max-width: none;
    gap: 0.15rem;
  }

  .site-nav {
    order: 3;
    width: auto;
    position: static;
    margin-left: 0.4rem;
    display: flex;
    align-items: center;
  }

  .site-title {
    font-size: clamp(1rem, 3vw, 1.2rem);
  }

  .site-subtitle {
    font-size: 0.78rem;
  }

  .nav-toggle {
    display: flex;
    width: 40px;
    height: 40px;
    border-radius: 0.65rem;
    position: relative;
    z-index: 1101;
  }

  /* Animated hamburger to X */
  .nav-toggle .nav-toggle-bar {
    position: absolute;
    left: 50%;
    top: 50%;
    width: 22px;
    height: 2px;
    margin: 0;
    background: var(--text-primary);
    border-radius: 2px;
    transform-origin: center;
    transition: transform 260ms cubic-bezier(0.2, 0.6, 0.3, 1),
                opacity 200ms ease,
                background var(--transition-base);
  }

  /* Top, middle, bottom bars initial positions (sr-only is first child) */
  .nav-toggle .nav-toggle-bar:nth-child(2) {
    transform: translate(-50%, calc(-50% - 7px));
  }
  .nav-toggle .nav-toggle-bar:nth-child(3) {
    transform: translate(-50%, -50%);
  }
  .nav-toggle .nav-toggle-bar:nth-child(4) {
    transform: translate(-50%, calc(-50% + 7px));
  }

  /* Expanded state -> morph into X */
  .nav-toggle[aria-expanded="true"] .nav-toggle-bar:nth-child(2) {
    transform: translate(-50%, -50%) rotate(45deg);
  }
  .nav-toggle[aria-expanded="true"] .nav-toggle-bar:nth-child(3) {
    opacity: 0;
    transform: translate(-50%, -50%) scaleX(0.5);
  }
  .nav-toggle[aria-expanded="true"] .nav-toggle-bar:nth-child(4) {
    transform: translate(-50%, -50%) rotate(-45deg);
  }

  .nav-links {
    position: fixed;
    inset: 0;
    width: 100vw;
    height: 100dvh;
    padding: clamp(4.5rem, 14vw, 6.5rem) clamp(1.6rem, 8vw, 2.75rem) clamp(2.25rem, 8vw, 3rem);
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 0;
    background: rgba(9, 14, 24, 0.98);
    border: 0;
    border-radius: 0;
    box-shadow: -18px 0 45px rgba(15, 23, 42, 0.35);
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
    opacity: 0;
    visibility: hidden;
    transform: translateX(100%);
    pointer-events: none;
    overflow-y: auto;
    max-height: none;
    transition: transform 360ms cubic-bezier(0.24, 0.6, 0.32, 1), opacity 320ms ease, visibility 0s linear 360ms;
    transition-delay: 0s, 0s, 360ms;
    z-index: 1100; /* above fixed header */
  }

  html[data-theme="light"] .nav-links {
    background: rgba(248, 250, 252, 0.98);
    box-shadow: -18px 0 45px rgba(15, 23, 42, 0.15);
  }

  .nav-links[data-expanded="true"] {
    opacity: 1;
    visibility: visible;
    transform: translateX(0);
    pointer-events: auto;
    transition-delay: 0s, 0s, 0s;
  }

  .nav-links > li {
    width: 100%;
    opacity: 0;
    transform: translateX(20px) scale(0.97);
    transition: opacity 220ms ease, transform 340ms cubic-bezier(0.22, 0.61, 0.36, 1);
    transition-delay: var(--drop-delay, 0ms);
    will-change: transform, opacity;
  }

  .nav-links > li + li {
    margin-top: 0.55rem;
  }

  .nav-links[data-expanded="true"] > li {
    opacity: 1;
    transform: translateX(0) scale(1);
  }

  .nav-links > li > a,
  .nav-links > li > .dropdown-header > a {
    display: inline-flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 0.75rem 0;
    font-size: 1.1rem;
    color: var(--text-primary);
  }

  .nav-links > li.has-dropdown > .dropdown-header {
    display: flex;
    align-items: center;
    gap: 0.65rem;
  }

  .nav-links > li.has-dropdown > .dropdown-header > a {
    flex: 1 1 auto;
    justify-content: flex-start;
    padding-right: 0;
  }

  .nav-links > li.has-dropdown > .dropdown-header > a::after {
    display: none;
  }

  .nav-links > li.has-dropdown > .dropdown-header > a::before {
    display: none;
  }

  .dropdown-toggle-button {
    display: inline-flex;
  }

  .nav-links .dropdown-menu {
    position: static;
    width: 100%;
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
    transform: none;
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    max-height: 0;
    overflow: hidden;
    transition: max-height 260ms ease, padding 220ms ease;
  }

  .nav-links .dropdown-menu::before {
    display: none;
  }

  .nav-links .dropdown-menu[data-expanded="true"] {
    max-height: 1000px;
    padding: 0.4rem 0 0.95rem;
    border-top: 1px solid var(--border-color);
    margin-top: 0.35rem;
  }

  .nav-links .dropdown-menu li {
    opacity: 1;
    transform: none;
    transition: none;
    animation: none !important;
    animation-delay: 0s;
  }

  .nav-links .dropdown-menu a {
    padding: 0.55rem 0;
    padding-left: 1rem;
    font-size: 0.98rem;
    color: var(--text-muted);
  }

  .nav-links > li:nth-child(1) {
    --drop-delay: 70ms;
  }

  .nav-links > li:nth-child(2) {
    --drop-delay: 130ms;
  }

  .nav-links > li:nth-child(3) {
    --drop-delay: 190ms;
  }

  .nav-links > li:nth-child(4) {
    --drop-delay: 250ms;
  }

  .nav-links > li:nth-child(5) {
    --drop-delay: 310ms;
  }

  .nav-links > li:nth-child(6) {
    --drop-delay: 370ms;
  }

  .nav-links > li:nth-child(7) {
    --drop-delay: 430ms;
  }

  .nav-links > li:nth-child(8) {
    --drop-delay: 490ms;
  }

  .nav-links > li:nth-child(9) {
    --drop-delay: 550ms;
  }

  .nav-links .nav-theme-toggle-item {
    margin-top: clamp(1.6rem, 7vw, 2.2rem);
    padding-top: 1rem;
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: center;
    --drop-delay: 610ms;
  }

  .nav-theme-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 100%;
  }

  .nav-theme-toggle .theme-toggle {
    display: inline-grid;
    width: 34px;
    height: 34px;
    border-radius: 0.75rem;
    margin: 0 auto;
  }

  .nav-theme-toggle .theme-toggle:hover {
    transform: none;
  }

  .theme-toggle {
    display: none;
  }
}

@media (max-width: 600px) {
  .hero {
    padding: 2.4rem;
  }

  .topics-grid {
    grid-template-columns: 1fr;
  }

  .form-grid {
    grid-template-columns: 1fr;
  }

  .post {
    padding: 2rem;
  }
}

@media (max-width: 720px) {
  main {
    padding: clamp(1.75rem, 5vw, 2.5rem) clamp(1rem, 6vw, 1.5rem) 3rem;
  }

  .hero {
    grid-template-columns: 1fr;
  }

  .hero-highlight {
    padding: 1.25rem;
  }

  .post {
    margin: clamp(1.5rem, 5vw, 2.5rem) auto 3.5rem;
    padding: clamp(1.75rem, 5vw, 2.2rem);
  }

  .post-body {
    font-size: 1rem;
    gap: 1.35rem;
  }
}

@media (max-width: 480px) {
  .header-inner {
    padding: 0.55rem 0.85rem;
    gap: 0.85rem;
  }

  .site-title {
    font-size: clamp(0.95rem, 6vw, 1.1rem);
  }

  .site-subtitle {
    font-size: 0.72rem;
  }

  .nav-toggle {
    width: 36px;
    height: 36px;
  }

  main {
    padding: 1.5rem 1.1rem 3rem;
  }

  .hero {
    padding: 2rem 1.5rem;
    text-align: left;
  }

  .hero h1 {
    font-size: clamp(2rem, 8vw, 2.5rem);
  }

  .hero-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .hero-actions .button {
    width: 100%;
  }

  .section-intro {
    margin: 2.5rem auto 1.75rem;
    padding: 0 0.25rem;
  }

  .post-card {
    padding: 1.25rem;
  }

  .post-title {
    font-size: clamp(1.85rem, 7vw, 2.3rem);
  }

  .post-body {
    font-size: 0.98rem;
  }

  .dropcap {
    float: none;
    margin-right: 0;
    font-size: 2.4rem;
  }

  .post-footer {
    flex-direction: column;
    align-items: stretch;
  }

  .post-footer .button {
    width: 100%;
  }

}
