/* ============ Scaffold Studio — Blueprint theme ============ */

:root {
  --ink: #0a1428;
  --ink-2: #0d1a33;
  --ink-3: #10203c;
  --grid-line: rgba(150, 180, 225, 0.055);
  --hair: rgba(210, 226, 248, 0.16);
  --hair-strong: rgba(210, 226, 248, 0.32);
  --paper: #edf3fc;
  --muted: #8fa5c6;
  --faint: #5d7194;
  --copper: #d28a4c;
  --copper-bright: #e5a266;
  --copper-dim: rgba(210, 138, 76, 0.14);
  --danger: #e07878;
  --radius: 3px;
  --font: "Space Grotesk", -apple-system, "Segoe UI", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
}

* { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
}

html, body {
  overflow-x: hidden;
  overflow-x: clip; /* backstop: no sideways scroll; clip keeps sticky working */
}

body {
  margin: 0;
  font-family: var(--font);
  color: var(--paper);
  background-color: var(--ink);
  background-image:
    linear-gradient(var(--grid-line) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-line) 1px, transparent 1px);
  background-size: 32px 32px;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

main { flex: 1; }

.wrap {
  width: 100%;
  max-width: 1080px;
  margin: 0 auto;
  padding-left: 24px;
  padding-right: 24px;
}

.mono { font-family: var(--mono); }
.small { font-size: 13px; }
.muted { color: var(--muted); }

h1, h2, h3 { margin: 0 0 12px; line-height: 1.12; letter-spacing: -0.01em; }
h1 { font-size: clamp(40px, 7vw, 68px); font-weight: 700; }
h1 em, .wordmark-text em { font-style: normal; color: var(--copper); }
h2 { font-size: clamp(26px, 4vw, 36px); font-weight: 600; }
h3 { font-size: 19px; font-weight: 600; }
p { margin: 0 0 14px; line-height: 1.65; }

a { color: var(--copper-bright); }
a:hover { color: var(--copper); }

.eyebrow {
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0 0 16px;
}
.eyebrow.copper { color: var(--copper); }

.lede { font-size: 18px; color: var(--muted); max-width: 560px; }

/* ============ Header ============ */

.site-header {
  border-bottom: 1px solid var(--hair);
  background: rgba(10, 20, 40, 0.82);
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 50;
}
.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 64px;
}
.wordmark {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--paper);
}
.wordmark-mark {
  width: 14px; height: 14px;
  border: 1.5px solid var(--copper);
  position: relative;
  flex: none;
  transition: transform 0.35s ease;
}
.wordmark-mark::after {
  content: "";
  position: absolute;
  inset: 3px;
  background: var(--copper);
  opacity: 0.85;
}
.wordmark:hover .wordmark-mark { transform: rotate(45deg); }
.wordmark-text { font-weight: 700; font-size: 18px; letter-spacing: -0.01em; }
.wordmark-text.small { font-size: 15px; }
.header-actions { display: flex; align-items: center; gap: 10px; }

/* ============ Buttons ============ */

.btn {
  display: inline-block;
  font-family: var(--font);
  font-size: 15px;
  font-weight: 600;
  padding: 11px 22px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.2s ease, border-color 0.2s ease, color 0.2s ease, transform 0.15s ease;
  white-space: nowrap;
}
.btn:active { transform: translateY(1px); }
.btn.sm { font-size: 13.5px; padding: 8px 15px; }
.btn.block { display: block; width: 100%; margin-top: 6px; }
.btn.primary {
  background: var(--copper);
  border-color: var(--copper);
  color: #14100a;
}
.btn.primary:hover { background: var(--copper-bright); border-color: var(--copper-bright); color: #14100a; }
.btn.ghost {
  background: transparent;
  border-color: var(--hair-strong);
  color: var(--paper);
}
.btn.ghost:hover { border-color: var(--copper); color: var(--copper-bright); }
.btn.danger-ghost {
  background: transparent;
  border-color: var(--hair);
  color: var(--muted);
}
.btn.danger-ghost:hover { border-color: var(--danger); color: var(--danger); }

/* ============ Views ============ */

.view { padding: 56px 0 72px; }
.view[hidden] { display: none; }
.view:not([hidden]) { animation: viewIn 0.45s ease both; }
@keyframes viewIn {
  from { opacity: 0; transform: translateY(14px); }
  to { opacity: 1; transform: none; }
}

/* ============ Landing ============ */

.sheet-frame {
  position: relative;
  border: 1px solid var(--hair-strong);
  background: rgba(13, 26, 51, 0.55);
  padding: 64px 48px 40px;
  margin-top: 8px;
  overflow: hidden;
}
.reg { position: absolute; width: 18px; height: 18px; }
.reg::before, .reg::after {
  content: "";
  position: absolute;
  background: var(--copper);
}
.reg::before { width: 100%; height: 2px; }
.reg::after { width: 2px; height: 100%; }
.reg.tl { top: 10px; left: 10px; }
.reg.tr { top: 10px; right: 10px; transform: scaleX(-1); }
.reg.bl { bottom: 10px; left: 10px; transform: scaleY(-1); }
.reg.br { bottom: 10px; right: 10px; transform: scale(-1); }

.sheet-meta {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 6px 16px;
  font-size: 11px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--faint);
}
.sheet-foot { margin-top: 44px; padding-top: 14px; border-top: 1px dashed var(--hair); }

.hero { position: relative; z-index: 2; max-width: 640px; }
.hero-actions { display: flex; gap: 12px; margin-top: 28px; flex-wrap: wrap; }

.hero-draw {
  position: absolute;
  right: 40px;
  top: 50%;
  transform: translateY(-50%);
  width: 300px;
  opacity: 0.9;
  z-index: 1;
}
.hero-draw .draw {
  stroke-dasharray: 1;
  stroke-dashoffset: 1;
  animation: drawLine 2.6s ease forwards;
}
.hero-draw .draw.d { animation-delay: 0.7s; animation-duration: 2s; }
@keyframes drawLine { to { stroke-dashoffset: 0; } }

.fade-up { animation: fadeUp 0.7s ease both; }
.fade-up.d1 { animation-delay: 0.12s; }
.fade-up.d2 { animation-delay: 0.24s; }
.fade-up.d3 { animation-delay: 0.36s; }
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(18px); }
  to { opacity: 1; transform: none; }
}

/* Eight-sheet strip */
.set-preview { margin-top: 56px; }
.sheet-strip {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 10px;
  margin: 18px 0 14px;
}
.mini-sheet {
  border: 1px solid var(--hair);
  background: rgba(13, 26, 51, 0.5);
  padding: 18px 6px;
  text-align: center;
  font-size: 10.5px;
  letter-spacing: 0.06em;
  color: var(--muted);
  border-radius: 2px;
  transition: border-color 0.25s ease, color 0.25s ease, transform 0.25s ease;
}
.mini-sheet:hover {
  border-color: var(--copper);
  color: var(--copper-bright);
  transform: translateY(-3px);
}

/* Steps */
.steps {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 18px;
  margin-top: 56px;
}
.step {
  border: 1px solid var(--hair);
  background: rgba(13, 26, 51, 0.5);
  padding: 26px 24px;
  border-radius: var(--radius);
  transition: border-color 0.25s ease, transform 0.25s ease;
}
.step:hover { border-color: var(--hair-strong); transform: translateY(-3px); }
.step-no {
  display: inline-block;
  font-size: 12px;
  letter-spacing: 0.2em;
  color: var(--copper);
  border: 1px solid var(--copper-dim);
  background: var(--copper-dim);
  padding: 5px 10px;
  border-radius: 2px;
  margin-bottom: 16px;
}
.step h3 { margin-bottom: 8px; }
.step p { color: var(--muted); font-size: 14.5px; margin: 0; }

/* ============ Auth ============ */

.auth-wrap { display: flex; justify-content: center; }
.auth-card {
  width: 100%;
  max-width: 440px;
  border: 1px solid var(--hair-strong);
  background: rgba(13, 26, 51, 0.72);
  padding: 0 0 30px;
  border-radius: var(--radius);
  animation: viewIn 0.45s ease both;
}
.auth-card > *:not(.title-strip) { margin-left: 30px; margin-right: 30px; }
.title-strip {
  display: flex;
  justify-content: space-between;
  font-size: 10.5px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--faint);
  border-bottom: 1px solid var(--hair);
  padding: 13px 30px !important;
  margin: 0 0 26px !important;
}
.auth-card h2 { margin-bottom: 6px; }
.section-sub { margin-bottom: 24px; }
.auth-switch { margin-top: 20px; margin-bottom: 0; text-align: center; }

.field { display: block; margin-bottom: 16px; }
.field > span {
  display: block;
  font-family: var(--mono);
  font-size: 11.5px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 8px;
}
.field input, .field textarea, .newfile input {
  width: 100%;
  font-family: var(--font);
  font-size: 15px;
  color: var(--paper);
  background: rgba(10, 20, 40, 0.7);
  border: 1px solid var(--hair-strong);
  border-radius: var(--radius);
  padding: 12px 14px;
  outline: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
.field input::placeholder, .field textarea::placeholder, .newfile input::placeholder { color: var(--faint); }
.field input:focus, .field textarea:focus, .newfile input:focus {
  border-color: var(--copper);
  box-shadow: 0 0 0 3px var(--copper-dim);
}
.field textarea { resize: vertical; min-height: 76px; line-height: 1.6; }

.form-error {
  border: 1px solid var(--danger);
  background: rgba(224, 120, 120, 0.08);
  color: #f0a8a8;
  font-size: 14px;
  padding: 11px 14px;
  border-radius: var(--radius);
  margin-bottom: 18px;
}

/* ============ Dashboard ============ */

.dash-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 16px;
  margin-bottom: 26px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--hair);
}
.dash-head h2 { margin-bottom: 4px; }
.dash-head p { margin: 0; }
.dash-actions { display: flex; gap: 10px; flex: none; }

.dash-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}
.root-switch { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.segment {
  display: inline-flex;
  border: 1px solid var(--hair-strong);
  border-radius: var(--radius);
  overflow: hidden;
}
.segment button {
  font-family: var(--mono);
  font-size: 12px;
  padding: 8px 14px;
  background: transparent;
  border: none;
  color: var(--muted);
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease;
}
.segment button.active { background: var(--copper-dim); color: var(--copper-bright); }
.segment button + button { border-left: 1px solid var(--hair); }

.newfile { display: flex; gap: 10px; }
.newfile input { width: 220px; font-family: var(--mono); font-size: 13.5px; }
#newFileHint { margin-bottom: 26px; font-size: 12px; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(255px, 1fr));
  gap: 16px;
}
.file-card {
  position: relative;
  border: 1px solid var(--hair);
  background: rgba(13, 26, 51, 0.55);
  border-radius: var(--radius);
  padding: 22px 20px 18px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  transition: border-color 0.25s ease, transform 0.25s ease, box-shadow 0.25s ease;
  animation: cardIn 0.5s ease both;
}
.file-card:hover {
  border-color: var(--copper);
  transform: translateY(-3px);
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.35);
}
@keyframes cardIn {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: none; }
}
.file-sheet-no {
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.2em;
  color: var(--copper);
  text-transform: uppercase;
}
.file-name {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--faint);
  letter-spacing: 0.04em;
  overflow-wrap: anywhere;
}
.file-card h3 { margin: 0; font-size: 18px; }
.file-desc { color: var(--muted); font-size: 13.5px; margin: 0; flex: 1; }
.file-updated { font-family: var(--mono); font-size: 11px; color: var(--faint); }
.file-actions { display: flex; gap: 8px; margin-top: 10px; }
.file-actions .btn { flex: 1; text-align: center; }

.empty-note { margin-top: 8px; }

/* ============ Editor ============ */

.editor-page { max-width: 860px; }
.back-link {
  display: inline-block;
  font-size: 13px;
  letter-spacing: 0.1em;
  text-decoration: none;
  margin-bottom: 22px;
  color: var(--muted);
}
.back-link:hover { color: var(--copper-bright); }

.editor-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  padding-bottom: 20px;
  margin-bottom: 20px;
  border-bottom: 1px solid var(--hair);
}
.editor-filename {
  font-size: 12px;
  letter-spacing: 0.16em;
  color: var(--copper);
  margin-bottom: 8px;
  overflow-wrap: anywhere;
}
.editor-head h2 { margin-bottom: 4px; }
.editor-head p { margin: 0; }
.editor-save { display: flex; align-items: center; gap: 12px; flex: none; }
#saveStatus { font-size: 12px; }

#edArea {
  width: 100%;
  min-height: 340px;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.75;
  color: var(--paper);
  background-color: var(--ink-2);
  background-image: repeating-linear-gradient(transparent, transparent 34px, rgba(150, 180, 225, 0.05) 35px);
  border: 1px solid var(--hair-strong);
  border-radius: var(--radius);
  padding: 24px;
  resize: vertical;
  outline: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
#edArea:focus { border-color: var(--copper); box-shadow: 0 0 0 3px var(--copper-dim); }

/* AI red-line panel */
.ai-panel {
  margin-top: 28px;
  border: 1px solid var(--hair);
  border-left: 3px solid var(--copper);
  background: rgba(13, 26, 51, 0.55);
  border-radius: var(--radius);
  padding: 26px;
}
.ai-head h3 { margin-bottom: 6px; }
.ai-actions { display: flex; gap: 10px; margin: 18px 0 14px; flex-wrap: wrap; }

.ai-result {
  margin-top: 20px;
  border-top: 1px dashed var(--hair-strong);
  padding-top: 20px;
  animation: slideMarkup 0.4s ease both;
}
@keyframes slideMarkup {
  from { opacity: 0; transform: translateX(16px); }
  to { opacity: 1; transform: none; }
}
.ai-result-body {
  font-family: var(--mono);
  font-size: 13.5px;
  line-height: 1.7;
  color: var(--paper);
  background: rgba(210, 138, 76, 0.06);
  border: 1px solid rgba(210, 138, 76, 0.35);
  border-radius: var(--radius);
  padding: 18px;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 340px;
  overflow-y: auto;
  margin-bottom: 16px;
}
.ai-result-actions { display: flex; gap: 10px; flex-wrap: wrap; }

/* ============ Footer / toast ============ */

.site-footer {
  border-top: 1px solid var(--hair);
  padding: 22px 0;
  margin-top: auto;
}
.footer-inner {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%);
  background: var(--ink-3);
  border: 1px solid var(--hair-strong);
  border-left: 3px solid var(--copper);
  color: var(--paper);
  font-size: 14px;
  padding: 13px 20px;
  border-radius: var(--radius);
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.5);
  z-index: 100;
  max-width: calc(100vw - 48px);
  animation: toastIn 0.3s ease both;
}
.toast[hidden] { display: none; }
@keyframes toastIn {
  from { opacity: 0; transform: translate(-50%, 10px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

/* ============ Responsive ============ */

@media (max-width: 760px) {
  .wrap { padding-left: 18px; padding-right: 18px; }
  .view { padding: 28px 0 48px; }

  /* Landing */
  .sheet-frame { padding: 40px 20px 28px; }
  .hero-draw { display: none; }
  h1 { font-size: clamp(34px, 10vw, 44px); }
  .lede { font-size: 16.5px; }
  .hero-actions { flex-direction: column; align-items: stretch; }
  .hero-actions .btn { text-align: center; }
  .set-preview { margin-top: 40px; }
  .sheet-strip { grid-template-columns: repeat(4, 1fr); gap: 8px; }
  .mini-sheet { min-width: 0; font-size: 9px; padding: 14px 4px; }
  .steps { grid-template-columns: 1fr; gap: 14px; margin-top: 40px; }
  .step { padding: 22px 20px; }

  /* Header: the signed-in email + buttons overflowed the bar — hide the email */
  #headerUser { display: none; }
  .wordmark-text { font-size: 16px; }
  .header-actions { gap: 8px; }
  .header-inner { height: 58px; }

  /* Auth */
  .auth-card > *:not(.title-strip) { margin-left: 22px; margin-right: 22px; }
  .title-strip { padding: 12px 22px !important; }

  /* 16px inputs stop iOS Safari auto-zooming on focus */
  .field input, .field textarea, .newfile input { font-size: 16px; }

  /* Dashboard */
  .dash-head { flex-direction: column; align-items: flex-start; gap: 14px; }
  .dash-actions { width: 100%; display: flex; }
  .dash-actions .btn { flex: 1; text-align: center; }
  .segment button { padding: 10px 14px; }
  .newfile { width: 100%; }
  .newfile input { flex: 1; width: auto; }
  .grid { grid-template-columns: 1fr; gap: 14px; }
  .file-card { padding: 20px 18px 16px; }

  /* Editor */
  .editor-head { flex-direction: column; gap: 14px; }
  .editor-save { width: 100%; display: flex; }
  .editor-save .btn { flex: 1; }
  #edArea { padding: 18px; min-height: 300px; }
  .ai-panel { padding: 22px 18px; }
  .ai-actions .btn, .ai-result-actions .btn { flex: 1 1 40%; text-align: center; }

  /* Footer */
  .footer-inner { flex-direction: column; align-items: flex-start; }

  .btn { padding: 10px 18px; }
}

/* ============ Reduced motion ============ */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation: none !important;
    transition: none !important;
  }
  .hero-draw .draw { stroke-dashoffset: 0; }
}
