/* ─────────────────────────────────────────────────────────────────────────
   Manifold — design tokens
   Black / white / grey + a single accent. Light + dark.
   ───────────────────────────────────────────────────────────────────────── */

:root, [data-theme="light"] {
  --bg:           #fafaf9;
  --bg-1:         #f4f4f2;
  --bg-2:         #ececea;
  --surface:      #ffffff;
  --surface-2:    #fbfbfa;
  --line:         #e6e6e3;
  --line-2:       #d8d8d4;
  --line-3:       #bfbfba;
  --text:         #0c0c0b;
  --text-2:       #444443;
  --text-3:       #6b6b68;
  --text-4:       #97978f;
  --accent:       #2563eb;     /* a calm tonal blue */
  --accent-2:     #1d4ed8;
  --accent-soft:  #dbeafe;
  --accent-ink:   #ffffff;
  --pos:          #15803d;
  --pos-soft:     #dcfce7;
  --neg:          #b91c1c;
  --neg-soft:     #fee2e2;
  --warn:         #b45309;
  --warn-soft:    #fef3c7;
  --shadow-sm:    0 1px 2px rgba(20, 20, 18, 0.04);
  --shadow-md:    0 2px 6px rgba(20, 20, 18, 0.06), 0 0 0 .5px rgba(20,20,18,.04);
  --shadow-lg:    0 18px 40px rgba(20, 20, 18, 0.08), 0 0 0 .5px rgba(20,20,18,.04);
}

[data-theme="dark"] {
  --bg:           #0a0a0a;
  --bg-1:         #111111;
  --bg-2:         #161616;
  --surface:      #131313;
  --surface-2:    #181818;
  --line:         #232323;
  --line-2:       #2c2c2c;
  --line-3:       #3a3a3a;
  --text:         #fafafa;
  --text-2:       #cfcfcd;
  --text-3:       #9a9a96;
  --text-4:       #6a6a66;
  --accent:       #60a5fa;
  --accent-2:     #93c5fd;
  --accent-soft:  rgba(96, 165, 250, 0.16);
  --accent-ink:   #0a0a0a;
  --pos:          #4ade80;
  --pos-soft:     rgba(74, 222, 128, 0.14);
  --neg:          #f87171;
  --neg-soft:     rgba(248, 113, 113, 0.14);
  --warn:         #fbbf24;
  --warn-soft:    rgba(251, 191, 36, 0.14);
  --shadow-sm:    0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-md:    0 2px 6px rgba(0, 0, 0, 0.4), 0 0 0 .5px rgba(255,255,255,.05);
  --shadow-lg:    0 18px 40px rgba(0, 0, 0, 0.5), 0 0 0 .5px rgba(255,255,255,.06);
}

/* Type system ---------------------------------------------------------------*/
:root {
  --ff-sans:    "Geist", "Inter", "Noto Sans SC", system-ui, -apple-system, sans-serif;
  --ff-serif:   "Instrument Serif", "Source Han Serif SC", "Noto Serif SC", Georgia, serif;
  --ff-mono:    "JetBrains Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;
}

/* Base ----------------------------------------------------------------------*/
* { box-sizing: border-box; }
html, body, #root { height: 100%; }
body {
  margin: 0;
  font-family: var(--ff-sans);
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  font-feature-settings: "ss01", "cv01";
  text-rendering: optimizeLegibility;
}

::selection { background: var(--accent); color: var(--accent-ink); }

a { color: inherit; text-decoration: none; }
button { font-family: inherit; }
input, textarea, select { font-family: inherit; color: inherit; }

/* Generic chrome ------------------------------------------------------------*/
.mono { font-family: var(--ff-mono); font-feature-settings: "ss03"; }
.serif { font-family: var(--ff-serif); }
.tnum { font-variant-numeric: tabular-nums; }

.kbd {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 18px; height: 18px; padding: 0 5px;
  font-family: var(--ff-mono); font-size: 10.5px;
  border: 1px solid var(--line-2); border-bottom-width: 1.5px;
  background: var(--surface); color: var(--text-2);
  border-radius: 4px;
}

/* Buttons */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  height: 32px; padding: 0 12px;
  border-radius: 8px; border: 1px solid var(--line-2);
  background: var(--surface); color: var(--text);
  font-size: 13px; font-weight: 500;
  cursor: pointer; transition: background .12s, border-color .12s;
}
.btn:hover { background: var(--surface-2); border-color: var(--line-3); }
.btn-primary {
  background: var(--text); color: var(--bg);
  border-color: var(--text);
}
.btn-primary:hover { background: var(--text-2); border-color: var(--text-2); }
.btn-accent {
  background: var(--accent); color: var(--accent-ink); border-color: var(--accent);
}
.btn-accent:hover { background: var(--accent-2); border-color: var(--accent-2); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--bg-1); color: var(--text); }
.btn-sm { height: 26px; padding: 0 8px; font-size: 12px; border-radius: 6px; }
.btn-lg { height: 40px; padding: 0 16px; font-size: 14px; border-radius: 9px; }

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
}
.card-pad { padding: 20px; }
.card-pad-lg { padding: 28px; }

/* Inputs */
.field {
  display: flex; align-items: center; gap: 8px;
  height: 32px; padding: 0 10px;
  border: 1px solid var(--line-2); border-radius: 8px;
  background: var(--surface);
  font-size: 13px;
}
.field:focus-within { border-color: var(--text-3); }
.field input, .field textarea {
  flex: 1; border: 0; outline: 0; background: transparent;
  font-size: 13px;
}

/* Badges */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  height: 20px; padding: 0 7px;
  border-radius: 4px;
  font-size: 11px; font-weight: 500;
  background: var(--bg-1); color: var(--text-2);
  border: 1px solid var(--line);
  font-family: var(--ff-mono);
  letter-spacing: 0.01em;
}
.badge.pos  { background: var(--pos-soft); color: var(--pos); border-color: transparent; }
.badge.neg  { background: var(--neg-soft); color: var(--neg); border-color: transparent; }
.badge.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.badge.accent { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.badge.solid { background: var(--text); color: var(--bg); border-color: transparent; }

.dot {
  display: inline-block; width: 6px; height: 6px; border-radius: 50%;
  background: var(--text-3);
}
.dot.pos { background: var(--pos); }
.dot.neg { background: var(--neg); }
.dot.warn { background: var(--warn); }
.dot.accent { background: var(--accent); }

/* Tables */
.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl th {
  text-align: left; font-weight: 500; color: var(--text-3);
  padding: 8px 12px; border-bottom: 1px solid var(--line);
  font-size: 11.5px; letter-spacing: 0.04em; text-transform: uppercase;
}
.tbl td {
  padding: 12px;
  border-bottom: 1px solid var(--line);
}
.tbl tr:last-child td { border-bottom: 0; }
.tbl tr:hover td { background: var(--surface-2); }

/* Scrollbars */
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-thumb {
  background: var(--line-2); border-radius: 5px;
  border: 2px solid transparent; background-clip: content-box;
}
*::-webkit-scrollbar-thumb:hover { background: var(--line-3); background-clip: content-box; border: 2px solid transparent;}
*::-webkit-scrollbar-track { background: transparent; }

/* Headings */
h1, h2, h3, h4, h5, p { margin: 0; }
.h-display { font-family: var(--ff-serif); font-weight: 400; letter-spacing: -0.015em; line-height: 1; }
.h-eyebrow {
  font-size: 11px; font-weight: 500; letter-spacing: 0.12em;
  text-transform: uppercase; color: var(--text-3);
  font-family: var(--ff-mono);
}

/* Misc */
.divider { height: 1px; background: var(--line); }
.divider-v { width: 1px; background: var(--line); align-self: stretch; }

/* Animated underline link */
.lnk {
  position: relative; color: var(--text-2);
  transition: color .15s;
}
.lnk:hover { color: var(--text); }
.lnk::after {
  content: ""; position: absolute; left: 0; right: 0; bottom: -2px;
  height: 1px; background: currentColor; transform: scaleX(0); transform-origin: left;
  transition: transform .2s ease;
}
.lnk:hover::after { transform: scaleX(1); }

/* Animations */
@keyframes pulse-soft {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.45; }
}
@keyframes fade-in {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}
.fade-in { animation: fade-in .25s ease both; }

/* Numeric ticker (used on landing live counter) */
@keyframes shimmer {
  0% { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}

/* ─────────────────────────────────────────────────────────────────────
   Responsive — tablet (<=1024px) and mobile (<=720px)
   ───────────────────────────────────────────────────────────────────── */

/* Tablet adjustments */
@media (max-width: 1024px) {
  .card-pad-lg { padding: 20px; }
  .h-display { letter-spacing: -0.01em; }
}

/* Mobile breakpoint */
@media (max-width: 720px) {
  body { font-size: 13.5px; }

  .card-pad      { padding: 16px; }
  .card-pad-lg   { padding: 16px; }
  .card          { border-radius: 10px; }

  /* Headings scale way down */
  h1.h-display, .h-display { letter-spacing: -0.01em; }

  /* Buttons stay tappable */
  .btn-lg { height: 44px; padding: 0 14px; font-size: 14px; }

  /* Tables — wrap in scroll container; reduce padding */
  .tbl th { padding: 6px 10px; font-size: 11px; }
  .tbl td { padding: 10px; }

  /* Form fields get bigger on mobile for touch */
  .field { height: 38px; }

  /* Generic grid utility: any direct .grid-2 / .grid-3 collapse to 1 */
  .grid-mobile-1 > * { grid-column: span 1 !important; }
}

/* Drawer / Sidebar -------- */
.sidebar-backdrop {
  position: fixed; inset: 0; background: rgba(10, 10, 10, .45);
  z-index: 80; backdrop-filter: blur(2px);
  animation: fade-in .2s ease;
}

@media (max-width: 720px) {
  .sidebar-mobile {
    position: fixed !important;
    top: 0; left: 0; bottom: 0;
    z-index: 90;
    width: 260px !important;
    flex: 0 0 260px !important;
    height: 100vh !important;
    box-shadow: var(--shadow-lg);
    transform: translateX(-100%);
    transition: transform .25s cubic-bezier(.3,.7,.4,1);
  }
  .sidebar-mobile.open {
    transform: translateX(0);
  }
}

/* Page head gets compact */
@media (max-width: 720px) {
  .page-head-h1 { font-size: 28px !important; }
}

/* Tables become scrollable */
.tbl-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* Hide on mobile */
@media (max-width: 720px) {
  .hide-mobile { display: none !important; }
}
@media (max-width: 1024px) {
  .hide-tablet-down { display: none !important; }
}
@media (min-width: 721px) {
  .show-mobile-only { display: none !important; }
}

/* ─────────────────────────────────────────────────────────────────────
   Mobile grid stacking — applied via data-stack on container
   data-stack="md"   stacks at <=1024px
   data-stack="sm"   stacks at <=720px (default)
   data-stack-2="sm" stacks to 2 cols at <=720px (instead of 1)
   ───────────────────────────────────────────────────────────────────── */
@media (max-width: 1024px) {
  [data-stack="md"] { grid-template-columns: 1fr !important; }
  [data-stack-2="md"] { grid-template-columns: repeat(2, 1fr) !important; }
}
@media (max-width: 720px) {
  [data-stack], [data-stack="sm"] { grid-template-columns: 1fr !important; }
  [data-stack-2], [data-stack-2="sm"] { grid-template-columns: repeat(2, 1fr) !important; }
}

/* Reduce page padding on mobile (matches PageHead etc.) */
@media (max-width: 720px) {
  [data-page] { padding-left: 16px !important; padding-right: 16px !important; padding-top: 20px !important; }
  [data-page-head] { flex-direction: column !important; align-items: flex-start !important; gap: 14px !important; }
  [data-page-head] > div:last-child { width: 100%; }
  [data-page-head] h1.h-display { font-size: 28px !important; line-height: 1.1 !important; }

  /* Common 'aside + main' split layouts collapse */
  [data-split] { grid-template-columns: 1fr !important; }

  /* Landing sections */
  [data-landing-hero] { padding: 40px 16px 32px !important; }
  .landing-headline { font-size: 56px !important; }
  .landing-section { padding: 48px 16px !important; }
  .landing-h2 { font-size: 36px !important; line-height: 1.05 !important; }

  /* Wide drawers should fill the screen */
  [data-drawer] { width: 100vw !important; max-width: 100vw !important; }
}

/* Mobile preview frame — when active, wraps the app in a phone-sized viewport */
.mobile-preview-frame {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 24px;
  background: repeating-linear-gradient(
    45deg, var(--bg-1), var(--bg-1) 8px,
    var(--bg) 8px, var(--bg) 16px
  );
  min-height: 100vh;
  width: 100vw;
}
.mobile-preview-inner {
  width: 420px;
  max-width: 100%;
  height: calc(100vh - 48px);
  min-height: 600px;
  background: var(--bg);
  border-radius: 28px;
  border: 6px solid var(--text);
  overflow: hidden;
  position: relative;
  box-shadow: 0 30px 80px rgba(0,0,0,.25);
  contain: layout;
}
.mobile-preview-notch {
  position: absolute; top: 0; left: 50%; transform: translateX(-50%);
  width: 110px; height: 22px; background: var(--text);
  border-radius: 0 0 14px 14px; z-index: 100;
}
.mobile-preview-inner > * { height: 100%; }
/* Contain fixed-positioned children inside the phone frame instead of escaping to the viewport */
.mobile-preview-inner .sidebar-mobile {
  position: absolute !important;
  width: 240px !important;
  flex: 0 0 240px !important;
}
.mobile-preview-inner .sidebar-backdrop {
  position: absolute !important;
}
.mobile-preview-inner .twk-panel { /* keep tweaks usable outside frame */ }

/* Mirror the mobile rules inside the preview frame */
.mobile-preview-inner [data-stack],
.mobile-preview-inner [data-stack="sm"],
.mobile-preview-inner [data-stack="md"] { grid-template-columns: 1fr !important; }
.mobile-preview-inner [data-stack-2],
.mobile-preview-inner [data-stack-2="sm"],
.mobile-preview-inner [data-stack-2="md"] { grid-template-columns: repeat(2, 1fr) !important; }
.mobile-preview-inner [data-page] { padding-left: 16px !important; padding-right: 16px !important; padding-top: 20px !important; }
.mobile-preview-inner [data-page-head] { flex-direction: column !important; align-items: flex-start !important; gap: 14px !important; }
.mobile-preview-inner [data-page-head] > div:last-child { width: 100%; }
.mobile-preview-inner [data-page-head] h1.h-display { font-size: 28px !important; line-height: 1.1 !important; }
.mobile-preview-inner [data-split] { grid-template-columns: 1fr !important; }
.mobile-preview-inner [data-landing-hero] { padding: 40px 16px 32px !important; }
.mobile-preview-inner .landing-headline { font-size: 56px !important; }
.mobile-preview-inner .landing-section { padding: 48px 16px !important; }
.mobile-preview-inner .landing-h2 { font-size: 36px !important; line-height: 1.05 !important; }
.mobile-preview-inner .hide-mobile { display: none !important; }
.mobile-preview-inner .card-pad      { padding: 16px; }
.mobile-preview-inner .card-pad-lg   { padding: 16px; }
