:root {
  --bg: linear-gradient(135deg, #0f172a, #111827);
  --glass: rgba(255, 255, 255, 0.08);
  --glass-strong: rgba(255, 255, 255, 0.14);
  --border: rgba(255, 255, 255, 0.18);
  --text: #e5e7eb;
  --muted: #a1a1aa;
  --brand: #60a5fa;
  --brand-2: #a78bfa;
  --ok: #34d399;
  --warn: #fbbf24;
  --err: #f87171;
  --halo: radial-gradient(1200px 600px at 10% -20%, rgba(96,165,250,0.10), transparent 60%),
          radial-gradient(1000px 600px at 110% 10%, rgba(167,139,250,0.10), transparent 60%);
}
/* Light theme overrides */
body[data-theme="light"] {
  --bg: linear-gradient(135deg, #f5f7fb, #e9eef7);
  --glass: rgba(0, 0, 0, 0.06);
  --glass-strong: rgba(0, 0, 0, 0.10);
  --border: rgba(0, 0, 0, 0.15);
  --text: #0f172a;
  --muted: #4b5563;
  --halo: radial-gradient(1200px 600px at 10% -20%, rgba(96,165,250,0.12), transparent 60%),
          radial-gradient(1000px 600px at 110% 10%, rgba(167,139,250,0.10), transparent 60%);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI', Roboto, Inter, system-ui, sans-serif;
  color: var(--text);
  background: var(--bg);
  /* avoid jank when viewport units change on mobile scroll */
  background-attachment: scroll;
  overscroll-behavior-y: none;
}
html { scroll-behavior: smooth; }

.bg-grid::before {
  content: "";
  position: fixed;
  inset: 0;
  background-image: radial-gradient(rgba(255,255,255,0.08) 1px, transparent 1px);
  background-size: 18px 18px;
  pointer-events: none;
  z-index: 0;
}

.bg-grid::after {
  content: "";
  position: fixed; inset: 0; pointer-events: none; z-index: 0;
  background: var(--halo);
  filter: blur(40px) saturate(140%);
}

.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 24px;
  animation: pagePopIn 520ms cubic-bezier(.22,.61,.36,1) both;
}
/* Scroll reveal for all pages */
.reveal-on-scroll { opacity: 0; transform: translateY(18px); }
.reveal-on-scroll.is-visible { opacity: 1; transform: translateY(0); transition: opacity 900ms cubic-bezier(.22,.61,.36,1), transform 900ms cubic-bezier(.22,.61,.36,1); }

.glass {
  background: var(--glass);
  border: 1px solid var(--border);
  backdrop-filter: blur(20px) saturate(160%);
  -webkit-backdrop-filter: blur(20px) saturate(160%);
  border-radius: 16px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.25), inset 0 1px 0 rgba(255,255,255,0.06);
}

/* Header / Nav */
.nav {
  position: sticky;
  top: 0;
  z-index: 50;
  margin: calc(16px + env(safe-area-inset-top, 0px)) 16px 16px 16px;
}
.nav-inner {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 14px;
  background: linear-gradient(180deg, rgba(255,255,255,0.10), rgba(255,255,255,0.06));
  border: 1px solid rgba(255,255,255,0.18);
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  letter-spacing: 0.2px;
}
.brand-badge {
  width: 28px; height: 28px; border-radius: 8px;
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  box-shadow: 0 6px 18px rgba(96,165,250,0.35);
}
.nav-links { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }
.menu-btn {
  display: none;
  margin-left: auto;
  width: 40px; height: 40px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--glass);
  color: var(--text);
  align-items: center; justify-content: center;
  cursor: pointer;
}
.menu-btn svg { width: 20px; height: 20px; }
.nav a, .btn, .submenu-trigger {
  color: var(--text); text-decoration: none; font-weight: 500;
  padding: 8px 12px; border-radius: 10px; border: 1px solid transparent;
  transition: background 420ms ease, border-color 420ms ease, transform 420ms ease, box-shadow 420ms ease;
}
.nav a:focus-visible, .btn:focus-visible, .submenu-trigger:focus-visible, .pill:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible {
  outline: 2px solid rgba(96,165,250,0.9);
  outline-offset: 2px;
  box-shadow: 0 0 0 6px rgba(96,165,250,0.12);
}
.nav a:hover, .submenu-trigger:hover { border-color: var(--border); background: var(--glass-strong); }
.btn {
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  border-color: transparent; color: #0b1020; font-weight: 700;
  box-shadow: 0 10px 28px rgba(96,165,250,0.35);
}
.btn:hover { filter: brightness(1.05); }
.btn:active { transform: translateY(1px); }

a, button { -webkit-tap-highlight-color: transparent; touch-action: manipulation; user-select: none; }
button { cursor: pointer; }

/* Responsive Nav */
@media (max-width: 860px) {
  .nav-inner { gap: 10px; }
  .nav-links { display: none; flex-direction: column; gap: 6px; position: fixed; left: 16px; right: 16px; top: 72px; z-index: 90; padding: 12px; border-radius: 14px; background: rgba(17, 24, 39, 0.72); border: 1px solid var(--border); box-shadow: 0 20px 60px rgba(0,0,0,0.45); }
  .nav.is-open .nav-links { display: flex; }
  .menu-btn { display: inline-flex; }
}
/* Nav overlay to block background interaction */
.nav-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.35); backdrop-filter: blur(1px); -webkit-backdrop-filter: blur(1px); z-index: 40; opacity: 0; pointer-events: none; transition: opacity 320ms ease; }
.nav.is-open + .nav-overlay { opacity: 1; pointer-events: auto; }

/* Submenu */
.has-submenu { position: relative; z-index: 1000; }
.submenu-trigger { background: transparent; border-color: transparent; display: inline-flex; align-items: center; gap: 8px; }
.submenu-trigger.active { background: rgba(255,255,255,0.06); border: 1px solid var(--border); }
.submenu { position: absolute; top: calc(100% + 8px); left: 0; min-width: 220px; display: none; flex-direction: column; gap: 6px; padding: 10px; border-radius: 12px; border: 1px solid var(--border); box-shadow: 0 20px 60px rgba(0,0,0,0.35); backdrop-filter: blur(18px) saturate(170%); -webkit-backdrop-filter: blur(18px) saturate(170%); background: rgba(17, 24, 39, 0.7); z-index: 1100; }
.has-submenu.open .submenu { display: flex; animation: menuIn 420ms cubic-bezier(.22,.61,.36,1) both; }
.has-submenu:hover .submenu { display: flex; }

@keyframes menuIn { from { opacity: 0; transform: translateY(6px) scale(0.98); } to { opacity: 1; transform: translateY(0) scale(1); } }

/* Stagger effect for mobile expanded menu */
.nav.is-open .nav-links > * { opacity: 0; transform: translateY(10px); animation: fadeInUp 760ms cubic-bezier(.22,.61,.36,1) both; animation-delay: var(--stagger, 0ms); }

/* Hero */
.hero {
  margin-top: 18px;
  padding: 28px;
  position: relative; overflow: hidden;
  animation: cardIn 1100ms cubic-bezier(.22,.61,.36,1) both;
}
.hero h1 { margin: 0; font-size: 34px; }
.hero p { margin: 8px 0 0; color: var(--muted); }

/* Grid */
.grid { display: grid; gap: 16px; }
@media (min-width: 720px) { .grid.cols-3 { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 720px) { .grid.cols-2 { grid-template-columns: repeat(2, 1fr); } }

.card {
  padding: 16px;
  display: flex; flex-direction: column; gap: 8px;
  transform: translateY(6px);
  transition: transform 640ms cubic-bezier(.22,.61,.36,1), box-shadow 640ms ease, background 640ms ease;
}
.card h3 { margin: 0; font-size: 18px; }
.card p { margin: 0; color: var(--muted); font-size: 14px; line-height: 1.5; }
.card .actions { margin-top: 8px; display: flex; gap: 8px; flex-wrap: wrap; }
.card:hover { transform: translateY(0); box-shadow: 0 26px 60px rgba(0,0,0,0.28); background: rgba(255,255,255,0.10); }

/* Footer */
.footer { margin: 24px 16px 32px; padding: 14px; text-align: center; color: var(--muted); }

/* Widgets */
.input, .select, textarea {
  width: 100%;
  padding: 10px 12px;
  color: var(--text);
  background: rgba(255,255,255,0.05);
  border: 1px solid var(--border);
  border-radius: 12px;
  outline: none;
  transition: box-shadow 300ms ease, border-color 300ms ease, background 300ms ease;
}
.input:focus, .select:focus, textarea:focus { box-shadow: 0 0 0 6px rgba(96,165,250,0.12); border-color: rgba(255,255,255,0.35); background: rgba(255,255,255,0.08); }
.row { display: flex; gap: 12px; flex-wrap: wrap; }
.row > * { flex: 1 1 200px; }
.label { font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.kbd { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; background: rgba(255,255,255,0.06); border: 1px solid var(--border); padding: 2px 6px; border-radius: 6px; }

.tag { font-size: 12px; padding: 4px 8px; border: 1px solid var(--border); border-radius: 999px; background: rgba(255,255,255,0.06); color: var(--muted); }

.muted { color: var(--muted); }
.center { text-align: center; }
.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 12px; }
.mt-3 { margin-top: 16px; }
.mt-4 { margin-top: 24px; }
.mt-6 { margin-top: 36px; }
.hidden { display: none; }

/* Table */
table { width: 100%; border-collapse: collapse; }
td, th { padding: 10px; border-bottom: 1px solid var(--border); text-align: left; }
tr:hover td { background: rgba(255,255,255,0.04); }

/* Utility */
.pill { padding: 8px 12px; border-radius: 999px; background: rgba(255,255,255,0.06); border: 1px solid var(--border); }

/* Motion system: iOS-like bouncy and cancellable feeling via smoother eases */
@keyframes cardIn { from { opacity: 0; transform: translateY(24px) scale(0.985);} to { opacity: 1; transform: translateY(0) scale(1);} }
@keyframes floaty { 0%,100% { transform: translateY(0);} 50% { transform: translateY(-4px);} }
@keyframes shimmer { 0%{background-position:0% 50%} 50%{background-position:100% 50%} 100%{background-position:0% 50%} }

.reveal { opacity: 0; transform: translateY(20px); }
.reveal.show { opacity: 1; transform: translateY(0); transition: opacity 1000ms cubic-bezier(.22,.61,.36,1.12), transform 1000ms cubic-bezier(.22,.61,.36,1.12); }

/* Springy transitions (bouncy like iOS) */
.springy { transition: transform 620ms cubic-bezier(.22,.61,.36,1.12), box-shadow 620ms cubic-bezier(.22,.61,.36,1.12), background 420ms ease, border-color 420ms ease; will-change: transform; }
.springy:active { transform: scale(0.985); }

/* Press ripple (ink-like but subtle) */
.ripple { position: relative; overflow: hidden; }
.ripple::after { content: ""; position: absolute; inset: 0; border-radius: inherit; background: radial-gradient(120px 120px at var(--rx,50%) var(--ry,50%), rgba(255,255,255,0.18), transparent 70%); opacity: 0; transition: opacity 260ms ease; pointer-events: none; }
.ripple.is-press::after { opacity: 1; transition: opacity 560ms ease; }

/* Premium motions */
.fade-in { opacity: 0; animation: fadeInUp 1100ms cubic-bezier(.22,.61,.36,1) forwards; }
@keyframes fadeInUp { from { opacity: 0; transform: translateY(24px); } to { opacity: 1; transform: translateY(0); } }

.hover-float { transition: transform 640ms cubic-bezier(.22,.61,.36,1), box-shadow 640ms ease; }
.hover-float:hover { transform: translateY(-2px); box-shadow: 0 26px 60px rgba(0,0,0,0.28); }

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.001s !important; animation-iteration-count: 1 !important; transition: none !important; }
}

/* Remove blue tap highlight on iOS/Safari Chrome */
input, textarea, select, button, a { -webkit-tap-highlight-color: rgba(0,0,0,0); }
/* Better touch-action defaults for interactive components */
.btn, .pill, a, button { touch-action: manipulation; }

/* Contrast fixes: ensure button text always readable */
.btn { color: #0b1020; }
.pill { color: var(--text); }

/* Mobile canvas container utility */
.canvas-wrap { width: 100%; display: flex; justify-content: center; }
canvas.responsive { width: 100%; height: auto; max-width: 520px; }

/* Hit target size for touch */
button, .pill, .btn { min-height: 40px; }

/* Selection and scrollbars */
::selection { background: rgba(147,112,219,0.35); }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.18); border-radius: 8px; }
::-webkit-scrollbar-track { background: rgba(255,255,255,0.06); }

/* Print: simplify background and borders */
@media print {
  body { background: #fff; color: #111; }
  .bg-grid::before, .bg-grid::after, .nav, .footer { display: none !important; }
  .glass { background: transparent; border: 1px solid #ddd; box-shadow: none; }
}

/* High contrast users */
@media (prefers-contrast: more) {
  .glass { background: rgba(255,255,255,0.12); border-color: rgba(255,255,255,0.4); }
  .nav-links { background: rgba(17,24,39,0.85); }
}

/* Page and link polish */
@keyframes pagePopIn { from { opacity: 0; transform: translateY(10px) scale(0.985); } to { opacity: 1; transform: translateY(0) scale(1); } }
a { color: #93c5fd; }
a:hover { color: #bfdbfe; }

/* Command palette */
.cmdk-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.45); z-index: 1400; display: none; align-items: flex-start; justify-content: center; padding: 10vh 16px 16px; }
.cmdk { width: 100%; max-width: 680px; background: rgba(17,24,39,0.78); border: 1px solid var(--border); border-radius: 12px; backdrop-filter: blur(16px) saturate(160%); -webkit-backdrop-filter: blur(16px) saturate(160%); box-shadow: 0 30px 80px rgba(0,0,0,0.4); }
.cmdk .head { padding: 10px; border-bottom: 1px solid var(--border); }
.cmdk input { width: 100%; background: transparent; border: none; color: var(--text); font-size: 16px; outline: none; }
.cmdk .list { max-height: 50vh; overflow:auto; }
.cmdk .item { display:flex; align-items:center; gap:10px; padding: 10px 12px; border-bottom: 1px solid rgba(255,255,255,0.06); cursor: pointer; }
.cmdk .item.active { background: rgba(255,255,255,0.08); }
.cmdk-overlay.is-open { display: flex; }

/* Back to top */
.back-to-top { position: fixed; right: 16px; bottom: 16px; z-index: 1300; opacity: 0; pointer-events: none; transition: opacity 320ms ease, transform 320ms ease; transform: translateY(8px); }
.back-to-top.show { opacity: 1; pointer-events: auto; transform: translateY(0); }

/* Manual reduce motion */
body.reduce-motion * { transition: none !important; animation: none !important; }


