/* ============================================================= *
 *  R Project Scaffolder — styles
 * ============================================================= */

:root {
  --bg:        #0b1020;
  --bg-2:      #111831;
  --panel:     #141c38;
  --panel-2:   #1a2342;
  --border:    #26315a;
  --border-2:  #324079;
  --text:      #e8edff;
  --text-2:    #aab3d4;
  --muted:     #76809f;
  --brand:     #6ee7ff;
  --brand-2:   #8b7bff;
  --accent:    #34e0a1;
  --danger:    #ff7591;
  --code-bg:   #0c1226;
  --shadow:    0 20px 60px -20px rgba(0,0,0,.6);
  --radius:    16px;
  --radius-sm: 10px;
}

[data-theme="light"] {
  --bg:        #f4f6fc;
  --bg-2:      #ffffff;
  --panel:     #ffffff;
  --panel-2:   #f4f6fc;
  --border:    #e1e6f5;
  --border-2:  #c9d2ee;
  --text:      #131a33;
  --text-2:    #475079;
  --muted:     #8a93b4;
  --brand:     #1f8fff;
  --brand-2:   #7b5bff;
  --accent:    #0bbf7a;
  --danger:    #e23d63;
  --code-bg:   #0c1226;
  --shadow:    0 20px 50px -24px rgba(40,60,120,.35);
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

/* never allow sideways scroll / off-canvas shadows to leak onto the page */
html, body { overflow-x: clip; max-width: 100%; }

body {
  margin: 0;
  font-family: "Inter", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  overflow-wrap: break-word;
}

/* sticky header shouldn't hide anchored sections when jumped to */
#builder, #workflow { scroll-margin-top: 80px; }

/* lock background scroll while the mobile drawer is open */
body.nav-open { overflow: hidden; overscroll-behavior: none; }

code, pre, .mono { font-family: "JetBrains Mono", ui-monospace, monospace; }

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── top bar ─────────────────────────────────────────────── */
.topbar {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px;
  padding: 14px clamp(16px, 4vw, 48px);
  padding-left: max(clamp(16px, 4vw, 48px), env(safe-area-inset-left));
  padding-right: max(clamp(16px, 4vw, 48px), env(safe-area-inset-right));
  background: transparent;
  border-bottom: 1px solid var(--border);
}
/* Blur + tint live on a pseudo-element, NOT on .topbar itself. A backdrop-filter
   on .topbar would make it the containing block for its position:fixed children
   (the mobile drawer), pinning the drawer to the header instead of the viewport.
   Keeping the filter on a child box leaves the drawer free to size to the
   viewport. */
.topbar::before {
  content: ""; position: absolute; inset: 0; z-index: -1;
  background: color-mix(in srgb, var(--bg) 78%, transparent);
  backdrop-filter: blur(14px);
}
.brand { min-width: 0; }
.brand-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.brand { display: flex; align-items: center; gap: 10px; font-size: 1.05rem; }
.logo { font-size: 1.4rem; }
.brand-name { letter-spacing: -.01em; }
.brand-name strong { color: var(--brand); }
.topnav { display: flex; align-items: center; gap: clamp(12px, 2vw, 26px); }
.topnav a {
  position: relative;
  color: var(--text-2); font-weight: 500; font-size: .95rem;
  transition: color .18s ease;
}
.topnav a:hover { color: var(--text); text-decoration: none; }
.topnav a.is-active { color: var(--text); }
/* animated underline for hover + active (scrollspy) link */
.topnav a::after {
  content: ""; position: absolute; left: 0; right: 0; bottom: -6px; height: 2px;
  border-radius: 2px;
  background: linear-gradient(100deg, var(--brand), var(--brand-2));
  transform: scaleX(0); transform-origin: left; opacity: 0;
  transition: transform .22s ease, opacity .22s ease;
}
.topnav a:hover::after,
.topnav a.is-active::after { transform: scaleX(1); opacity: 1; }

.theme-toggle {
  display: inline-grid; place-items: center;
  width: 40px; height: 40px; padding: 0;
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 10px; cursor: pointer; color: var(--text);
  transition: border-color .18s ease, background .18s ease, transform .18s ease;
}
.theme-toggle:hover { border-color: var(--border-2); background: var(--panel-2); }
.theme-toggle:active { transform: scale(.92); }
.theme-toggle:focus-visible { outline: none; box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 30%, transparent); }
.theme-toggle .ti {
  grid-area: 1 / 1; transition: transform .3s ease, opacity .25s ease;
}
/* show the icon for the current theme, swap with a little rotate/fade */
.theme-toggle .ti-sun  { opacity: 0; transform: rotate(-90deg) scale(.6); }
.theme-toggle .ti-moon { opacity: 1; transform: rotate(0) scale(1); }
html[data-theme="light"] .theme-toggle .ti-sun  { opacity: 1; transform: rotate(0) scale(1); }
html[data-theme="light"] .theme-toggle .ti-moon { opacity: 0; transform: rotate(90deg) scale(.6); }

/* hamburger toggle — hidden on desktop */
.nav-toggle {
  display: none;
  flex-direction: column; justify-content: center; gap: 5px;
  width: 42px; height: 42px; padding: 0;
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 10px; cursor: pointer;
}
.nav-toggle-bar {
  display: block; width: 20px; height: 2px; margin: 0 auto;
  background: var(--text); border-radius: 2px;
  transition: transform .25s ease, opacity .2s ease;
}
.nav-toggle.is-open .nav-toggle-bar:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.nav-toggle.is-open .nav-toggle-bar:nth-child(2) { opacity: 0; }
.nav-toggle.is-open .nav-toggle-bar:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }


/* ── hero ────────────────────────────────────────────────── */
.hero { position: relative; overflow: hidden; padding: clamp(48px, 9vw, 110px) 24px clamp(40px, 6vw, 72px); text-align: center; }
.hero-glow {
  position: absolute; inset: -30% 0 auto 0; height: 600px; pointer-events: none;
  background:
    radial-gradient(40% 50% at 30% 0%, color-mix(in srgb, var(--brand) 30%, transparent), transparent 70%),
    radial-gradient(45% 50% at 75% 10%, color-mix(in srgb, var(--brand-2) 32%, transparent), transparent 70%);
  filter: blur(10px); opacity: .8;
}
.hero-inner { position: relative; max-width: 880px; margin: 0 auto; }
.eyebrow {
  display: inline-block; padding: 5px 14px; margin-bottom: 22px;
  border: 1px solid var(--border-2); border-radius: 999px;
  font-size: .8rem; font-weight: 600; letter-spacing: .04em; text-transform: uppercase;
  color: var(--brand); background: color-mix(in srgb, var(--brand) 8%, transparent);
}
.hero h1 { font-size: clamp(2.2rem, 6vw, 4rem); line-height: 1.05; letter-spacing: -.03em; margin: 0 0 18px; font-weight: 800; }
.grad { background: linear-gradient(100deg, var(--brand), var(--brand-2)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.lede { font-size: clamp(1rem, 2vw, 1.2rem); color: var(--text-2); max-width: 660px; margin: 0 auto 32px; }
.lede code { background: var(--panel); padding: 1px 7px; border-radius: 6px; font-size: .9em; color: var(--brand); }
.hero-cta { display: flex; gap: 14px; justify-content: center; flex-wrap: wrap; }
.hero-badges { display: flex; gap: 22px; justify-content: center; flex-wrap: wrap; margin-top: 30px; color: var(--muted); font-size: .9rem; font-weight: 500; }

/* ── buttons ─────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 9px; justify-content: center;
  font-family: inherit; font-weight: 600; font-size: .98rem; cursor: pointer;
  padding: 12px 22px; border-radius: 12px; border: 1px solid transparent;
  transition: transform .12s ease, box-shadow .2s ease, background .2s ease, border-color .2s;
}
.btn:hover { text-decoration: none; transform: translateY(-2px); }
.btn:active { transform: translateY(0); }
.btn-lg { padding: 15px 28px; font-size: 1.05rem; }
.btn-sm { padding: 8px 14px; font-size: .88rem; border-radius: 10px; }
.btn-block { width: 100%; }
.btn-primary {
  color: #06122a; background: linear-gradient(100deg, var(--brand), var(--brand-2));
  box-shadow: 0 12px 30px -10px color-mix(in srgb, var(--brand) 60%, transparent);
}
.btn-primary:hover { box-shadow: 0 18px 40px -10px color-mix(in srgb, var(--brand-2) 70%, transparent); }
.btn-ghost { color: var(--text); background: var(--panel); border-color: var(--border-2); }
.btn-ghost:hover { background: var(--panel-2); }
.btn-icon { font-size: 1.1em; }
.btn:disabled { opacity: .55; cursor: progress; transform: none; }

/* ── builder layout ──────────────────────────────────────── */
.builder { max-width: 1240px; margin: 0 auto; padding: clamp(28px, 5vw, 56px) clamp(16px, 4vw, 40px); }
.builder-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.05fr); gap: 26px; align-items: start; }
@media (max-width: 920px) { .builder-grid { grid-template-columns: minmax(0, 1fr); } }

.panel {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  min-width: 0;
}
.panel-title { margin: 0; padding: 18px 22px; font-size: .95rem; letter-spacing: .02em; text-transform: uppercase; color: var(--text-2); border-bottom: 1px solid var(--border); font-weight: 600; }

.form-panel { padding-bottom: 6px; }

/* presets */
.presets { padding: 16px 22px 4px; }
.presets-label { font-weight: 600; font-size: .9rem; color: var(--text-2); display: block; margin-bottom: 8px; }
.preset-row { display: flex; flex-wrap: wrap; gap: 8px; }
.preset {
  font-family: inherit; font-size: .88rem; font-weight: 600; cursor: pointer;
  padding: 8px 13px; border-radius: 999px; color: var(--text);
  background: var(--bg-2); border: 1px solid var(--border-2);
  transition: border-color .15s, background .15s, transform .1s;
}
.preset:hover { border-color: var(--brand); transform: translateY(-1px); }
.preset.is-active { border-color: var(--brand); background: color-mix(in srgb, var(--brand) 16%, var(--bg-2)); color: var(--brand); }

/* action row under download */
.action-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 12px; }
.file-count { color: var(--muted); font-size: .85rem; font-weight: 500; }
.fs { border: none; margin: 0; padding: 20px 22px 6px; }
.fs legend { font-weight: 700; font-size: 1.02rem; padding: 0; margin-bottom: 6px; color: var(--text); }

.field { display: flex; flex-direction: column; gap: 7px; margin-bottom: 16px; }
.field > span { font-weight: 600; font-size: .9rem; color: var(--text-2); }
.field > span em { color: var(--brand); font-style: normal; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 520px) { .field-row { grid-template-columns: 1fr; } }

input[type="text"], input[type="number"], input[type="email"], select {
  width: 100%; padding: 11px 13px; font-family: inherit; font-size: .98rem;
  color: var(--text); background: var(--bg-2);
  border: 1px solid var(--border-2); border-radius: var(--radius-sm);
  transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 22%, transparent); }
input::placeholder { color: var(--muted); }
.hint { color: var(--muted); font-size: .8rem; }
.hint code, .toggle-label code { color: var(--brand); }

/* toggles */
.toggle { display: flex; align-items: center; gap: 12px; cursor: pointer; padding: 10px 0; }
.toggle input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch { position: relative; flex: 0 0 auto; width: 42px; height: 24px; border-radius: 999px; background: var(--border-2); transition: background .2s; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: transform .2s; }
.toggle input:checked + .switch { background: linear-gradient(100deg, var(--brand), var(--brand-2)); }
.toggle input:checked + .switch::after { transform: translateX(18px); }
.toggle input:focus-visible + .switch { box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 30%, transparent); }
.toggle-label { font-weight: 600; font-size: .95rem; }
.toggle-label small { display: block; font-weight: 400; color: var(--muted); font-size: .8rem; }
.toggle.compact { padding: 8px 0; }

.chk-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 18px; margin-top: 4px; }
@media (max-width: 520px) { .chk-grid { grid-template-columns: 1fr; } }

/* package grid */
.pkg-field > span { font-weight: 600; font-size: .9rem; color: var(--text-2); display: block; margin-bottom: 8px; }
.pkg-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 8px; }
.pkg {
  display: flex; align-items: center; gap: 8px; padding: 9px 11px; cursor: pointer;
  background: var(--bg-2); border: 1px solid var(--border-2); border-radius: var(--radius-sm);
  font-size: .9rem; font-weight: 500; transition: border-color .15s, background .15s;
}
.pkg:hover { border-color: var(--brand); }
.pkg input { accent-color: var(--brand); width: 16px; height: 16px; }
.pkg.is-on { border-color: var(--brand); background: color-mix(in srgb, var(--brand) 10%, var(--bg-2)); }
.pkg code { font-size: .85rem; }

.form-actions { padding: 8px 22px 22px; }
.form-error { color: var(--danger); font-size: .88rem; margin: 12px 0 0; min-height: 1em; font-weight: 500; }

/* ── preview ─────────────────────────────────────────────── */
.preview-panel { position: sticky; top: 78px; }
.preview-head { display: flex; align-items: center; justify-content: space-between; }
.preview-head .panel-title { border-bottom: none; flex: 1; }
.copy-btn {
  font-family: inherit; font-size: .82rem; font-weight: 600; cursor: pointer;
  margin-right: 16px; padding: 6px 12px; border-radius: 9px;
  color: var(--text-2); background: var(--bg-2); border: 1px solid var(--border-2);
}
.copy-btn:hover { border-color: var(--brand); color: var(--brand); }
.tabs { display: flex; gap: 4px; padding: 12px 14px 0; border-top: 1px solid var(--border); border-bottom: 1px solid var(--border); flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: thin; }
.tab { white-space: nowrap; flex: 0 0 auto; }
.tab {
  font-family: inherit; font-size: .85rem; font-weight: 600; cursor: pointer;
  color: var(--text-2); background: transparent; border: none;
  padding: 9px 12px; border-radius: 9px 9px 0 0; border-bottom: 2px solid transparent;
}
.tab:hover { color: var(--text); background: var(--panel-2); }
.tab.is-active { color: var(--brand); border-bottom-color: var(--brand); }
.tabpane { display: none; }
.tabpane.is-active { display: block; }

.codeblock {
  margin: 0; padding: 18px 20px; background: var(--code-bg); color: #d7e0ff;
  font-size: .82rem; line-height: 1.65; overflow: auto;
  max-height: 560px; border-radius: 0 0 var(--radius) var(--radius);
  white-space: pre; tab-size: 2;
}
.codeblock.tree { color: #c7d2ff; }

/* ── workflow ────────────────────────────────────────────── */
.workflow { max-width: 1160px; margin: 0 auto; padding: clamp(40px, 7vw, 90px) 24px; }
.section-title { text-align: center; font-size: clamp(1.6rem, 4vw, 2.4rem); letter-spacing: -.02em; margin: 0 0 10px; }
.section-sub { text-align: center; color: var(--text-2); max-width: 600px; margin: 0 auto 48px; }

.flow { display: flex; align-items: stretch; justify-content: center; gap: 8px; flex-wrap: wrap; margin-bottom: 64px; }
.flow-step { flex: 1 1 150px; max-width: 200px; background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px 18px; text-align: left; }
.flow-step h3 { margin: 8px 0 6px; font-size: 1.05rem; }
.flow-step p { margin: 0; font-size: .85rem; color: var(--text-2); }
.flow-step code { font-size: .8em; color: var(--brand); word-break: break-all; }
.flow-n { font-family: "JetBrains Mono", monospace; font-size: .85rem; font-weight: 600; color: var(--brand-2); }
.flow-arrow { display: flex; align-items: center; color: var(--muted); font-size: 1.4rem; }
@media (max-width: 760px) { .flow-arrow { display: none; } }

.features { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 18px; margin-bottom: 56px; }
.feature { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 22px; }
.feat-ic { font-size: 1.6rem; }
.feature h3 { margin: 12px 0 6px; font-size: 1.1rem; }
.feature p { margin: 0; color: var(--text-2); font-size: .9rem; }
.feature code { color: var(--brand); font-size: .85em; }

.next-card { background: linear-gradient(135deg, color-mix(in srgb, var(--brand) 12%, var(--panel)), color-mix(in srgb, var(--brand-2) 12%, var(--panel))); border: 1px solid var(--border-2); border-radius: var(--radius); padding: 28px 32px; max-width: 760px; margin: 0 auto; }
.next-card h3 { margin: 0 0 14px; font-size: 1.3rem; }
.next-card ol { margin: 0; padding-left: 22px; color: var(--text-2); }
.next-card li { margin-bottom: 8px; }
.next-card code {
  background: var(--code-bg); color: var(--brand);
  padding: 2px 8px; border-radius: 6px; font-size: .88em;
  /* long paths like 02_scripts/01_download_data.R must wrap on narrow screens */
  white-space: normal; overflow-wrap: anywhere; word-break: break-word;
  max-width: 100%;
}

/* ── footer ──────────────────────────────────────────────── */
.footer { text-align: center; padding: 40px 24px; border-top: 1px solid var(--border); color: var(--text-2); }
.footer p { margin: 4px 0; }
.muted { color: var(--muted); font-size: .9rem; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--border-2); border-radius: 8px; }
::-webkit-scrollbar-track { background: transparent; }

/* ── mobile ──────────────────────────────────────────────── */
@media (max-width: 920px) {
  .preview-panel { position: static; }
  .codeblock { max-height: 420px; }
}

/* hamburger nav kicks in on tablet / phone */
@media (max-width: 760px) {
  .nav-toggle { display: flex; }

  /* off-canvas drawer. .topbar no longer carries a backdrop-filter, so this
     fixed element sizes to the viewport — not the header. */
  .topnav {
    position: fixed; top: 0; right: 0; z-index: 45;
    flex-direction: column; align-items: stretch; justify-content: flex-start;
    gap: 6px;
    width: min(84vw, 330px); height: 100dvh;
    padding: 84px 22px calc(28px + env(safe-area-inset-bottom));
    padding-right: max(22px, env(safe-area-inset-right));
    background: var(--bg-2);
    border-left: 1px solid var(--border);
    box-shadow: none;
    transform: translateX(100%);
    transition: transform .28s ease, box-shadow .28s ease;
    overflow-y: auto;
    overscroll-behavior: contain;
  }
  body.nav-open .topnav { transform: translateX(0); box-shadow: -24px 0 70px -28px rgba(0,0,0,.7); }

  /* dimmed page behind the drawer; tapping it closes the menu (handled in JS) */
  body.nav-open::after {
    content: ""; position: fixed; inset: 0; z-index: 40;
    background: rgba(4,8,20,.55); backdrop-filter: blur(3px);
  }

  .topnav a {
    font-size: 1.05rem; font-weight: 600;
    padding: 14px 14px; border-radius: 12px;
    color: var(--text);
  }
  /* only apply hover styling on devices that truly hover — on touch screens a
     hover rule can swallow the first tap, forcing a second tap to activate. */
  @media (hover: hover) {
    .topnav a:hover { background: var(--panel-2); text-decoration: none; }
  }
  .topnav a.is-active { background: color-mix(in srgb, var(--brand) 14%, transparent); }
  /* drop the desktop underline inside the drawer */
  .topnav a::after { display: none; }

  .theme-toggle {
    margin-top: 12px; align-self: stretch;
    width: 44px; height: 44px;
  }
}

@media (max-width: 680px) {
  .hero { padding-top: clamp(40px, 12vw, 72px); }
  .hero-badges { gap: 10px 16px; font-size: .82rem; }
  .hero-cta { gap: 10px; }
  .hero-cta .btn-lg { width: 100%; }
  .builder { padding-left: 0; padding-right: 0; }
  .builder-grid { gap: 16px; }
  .panel { border-radius: 0; border-left: none; border-right: none; }
  .fs { padding: 16px 16px 4px; }
  .presets, .panel-title, .preview-head { padding-left: 16px; padding-right: 16px; }
  .copy-btn { margin-right: 0; }
  .form-actions { padding: 8px 16px 18px; }
  .tabs { padding-left: 12px; padding-right: 12px; }
  .codeblock { font-size: .74rem; padding: 14px; max-height: 60vh; }
  /* 16px inputs stop iOS Safari from auto-zooming on focus */
  input[type="text"], input[type="number"], input[type="email"], select { font-size: 16px; }
  .pkg-grid { grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); }
  .flow-step { max-width: none; }
  .next-card { border-radius: 0; border-left: none; border-right: none; padding: 24px 18px; }
}

@media (max-width: 420px) {
  .brand-name { font-size: .95rem; }
  .preset { flex: 1 1 calc(50% - 4px); text-align: center; }
  .tab { font-size: .8rem; padding: 9px 9px; }
  .action-row { flex-direction: column; align-items: flex-start; gap: 6px; }
}

/* respect reduced-motion preferences */
@media (prefers-reduced-motion: reduce) {
  .topnav, .nav-toggle-bar, .btn, .theme-toggle .ti, .topnav a::after { transition: none; }
  html { scroll-behavior: auto; }
}

/* ── custom variables / folders ──────────────────────────────────────── */
.custom-list { display: flex; flex-direction: column; gap: 6px; margin-bottom: 10px; }

.custom-row {
  display: flex;
  gap: 6px;
  align-items: center;
}

.custom-row input {
  flex: 1;
  min-width: 0;
}

.custom-row .remove-btn {
  flex: 0 0 auto;
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--danger);
  cursor: pointer;
  padding: 4px 9px;
  font-size: .8rem;
  line-height: 1;
}

.custom-row .remove-btn:hover { background: color-mix(in srgb, var(--danger) 12%, transparent); }

.add-row-btn { margin-top: 2px; }
