:root {
  --ink: #10131a;
  --ink-surface: #181c25;
  --ink-surface-2: #1f2430;
  --parchment: #f2ead8;
  --parchment-line: #d8cbaa;
  --text-primary: #eae7dd;
  --text-muted: #8b93a3;
  --gold: #c9973f;
  --gold-soft: rgba(201, 151, 63, 0.15);
  --red: #e5484d;
  --amber: #d4952e;
  --green: #4caf7d;
  --unknown: #6b7280;

  --font-display: "Source Serif 4", serif;
  --font-body: "Inter", sans-serif;
  --font-mono: "JetBrains Mono", monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--ink);
  color: var(--text-primary);
  font-family: var(--font-body);
  scroll-behavior: smooth;
}

#bg-canvas-container {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  opacity: 0.55;
}
#bg-canvas-container canvas {
  display: block;
}

.grain-overlay {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 1;
  opacity: 0.035;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

.topbar {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: baseline;
  gap: 14px;
  padding: 28px 6vw 20px;
  border-bottom: 1px solid rgba(201, 151, 63, 0.18);
}

.brand { display: flex; align-items: baseline; gap: 8px; }
.brand-mark {
  font-family: var(--font-display);
  font-size: 1.6rem;
  color: var(--gold);
}
.brand-name {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.35rem;
  letter-spacing: 0.01em;
}
.brand-tagline {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.wrap { max-width: 920px; margin: 0 auto; padding: 0 6vw 100px; position: relative; z-index: 2; }

.hero { padding: 64px 0 40px; max-width: 640px; }
.hero h1 {
  font-family: var(--font-display);
  font-size: clamp(2rem, 4.5vw, 3rem);
  font-weight: 700;
  line-height: 1.15;
  margin: 0 0 18px;
}
.hero h1 em { font-style: italic; color: var(--gold); }
.hero-sub {
  color: var(--text-muted);
  font-size: 1.02rem;
  line-height: 1.6;
  margin: 0;
}

/* ---- 3D tilt wrapper ---- */
.tilt-wrapper {
  perspective: 1400px;
}
.tilt-wrapper .folder-body {
  transform-style: preserve-3d;
  transition: transform 0.15s ease-out, box-shadow 0.15s ease-out;
  will-change: transform;
  box-shadow: 0 20px 50px -20px rgba(0, 0, 0, 0.5);
}

/* ---- folder / tabs ---- */
.folder { margin-top: 20px; }
.folder-tabs { display: flex; gap: 2px; }
.tab {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  letter-spacing: 0.03em;
  padding: 12px 22px 10px;
  background: var(--ink-surface);
  color: var(--text-muted);
  border: none;
  border-radius: 10px 10px 0 0;
  cursor: pointer;
  transition: color 0.15s ease, background 0.15s ease;
}
.tab.active { background: var(--parchment); color: #2a2314; font-weight: 500; }
.tab:not(.active):hover { color: var(--text-primary); }

.folder-body {
  background: var(--parchment);
  border-radius: 0 12px 12px 12px;
  padding: 36px;
  color: #2a2314;
}

.upload-zone {
  border: 1.5px dashed var(--parchment-line);
  border-radius: 8px;
  padding: 48px 24px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.upload-zone:hover, .upload-zone.dragover {
  border-color: var(--gold);
  background: rgba(201, 151, 63, 0.06);
}
.upload-icon { font-size: 1.8rem; color: var(--gold); margin-bottom: 8px; }
.upload-title { font-family: var(--font-display); font-size: 1.15rem; font-weight: 600; margin: 4px 0; }
.upload-sub { color: #6b5f45; font-size: 0.85rem; margin: 0 0 18px; }

.btn-outline, .btn-primary {
  font-family: var(--font-body);
  font-size: 0.85rem;
  font-weight: 600;
  padding: 10px 20px;
  border-radius: 6px;
  cursor: pointer;
  border: none;
  transition: transform 0.1s ease, opacity 0.15s ease;
}
.btn-outline {
  background: transparent;
  border: 1.5px solid #2a2314;
  color: #2a2314;
}
.btn-outline:hover { background: #2a2314; color: var(--parchment); }
.btn-primary { background: var(--gold); color: #201705; }
.btn-primary:hover { opacity: 0.88; }
.btn-primary:active, .btn-outline:active { transform: scale(0.97); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

.upload-status {
  margin-top: 14px;
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: #6b5f45;
  min-height: 1.2em;
}
.upload-status.success { color: #3f7d52; }
.upload-status.error { color: #a63a3a; }

/* ---- workspace ---- */
.workspace { margin-top: 40px; }
.workspace-tabs { display: flex; gap: 24px; border-bottom: 1px solid rgba(201,151,63,0.2); margin-bottom: 28px; }
.wtab {
  background: none; border: none; color: var(--text-muted);
  font-family: var(--font-body); font-size: 0.9rem; font-weight: 500;
  padding: 10px 2px 14px; cursor: pointer; border-bottom: 2px solid transparent;
}
.wtab.active { color: var(--text-primary); border-bottom-color: var(--gold); }

.panel-head {
  display: flex; align-items: center; justify-content: space-between; gap: 20px;
  margin-bottom: 24px;
}
.panel-head p { color: var(--text-muted); font-size: 0.9rem; margin: 0; max-width: 480px; }

.scan-results { display: flex; flex-direction: column; gap: 16px; }

/* ---- clause card + notary stamp ---- */
.clause-card {
  position: relative;
  background: var(--ink-surface);
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: 10px;
  padding: 22px 24px;
  overflow: hidden;
}
.clause-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.clause-label { font-family: var(--font-display); font-size: 1.05rem; margin: 0; font-weight: 600; }
.clause-why { color: var(--text-muted); font-size: 0.82rem; margin: 6px 0 12px; font-style: italic; }
.clause-answer { font-size: 0.92rem; line-height: 1.55; margin: 0; }
.clause-meta {
  margin-top: 12px; font-family: var(--font-mono); font-size: 0.72rem;
  color: var(--text-muted); display: flex; gap: 14px;
}

.severity-pill {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 4px 10px;
  border-radius: 999px;
  white-space: nowrap;
}
.severity-pill.red { background: rgba(229,72,77,0.15); color: var(--red); }
.severity-pill.amber { background: rgba(212,149,46,0.15); color: var(--amber); }
.severity-pill.green { background: rgba(76,175,125,0.15); color: var(--green); }
.severity-pill.unknown { background: rgba(107,114,128,0.15); color: var(--unknown); }

.stamp-layer {
  position: absolute; top: 14px; right: 20px;
  pointer-events: none;
}
.stamp {
  font-family: var(--font-mono);
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  border: 2px solid;
  border-radius: 4px;
  padding: 3px 8px;
  transform: rotate(-8deg) scale(1.6);
  opacity: 0;
  text-transform: uppercase;
}
.stamp.verified { border-color: var(--green); color: var(--green); }
.stamp.flagged { border-color: var(--red); color: var(--red); }
.stamp.review { border-color: var(--unknown); color: var(--unknown); }

@keyframes stampIn {
  0%   { opacity: 0; transform: rotate(-8deg) scale(2.4); }
  60%  { opacity: 1; transform: rotate(-8deg) scale(0.92); }
  100% { opacity: 1; transform: rotate(-8deg) scale(1); }
}
.stamp.animate { animation: stampIn 0.45s ease-out forwards; }

/* ---- chat ---- */
.chat-log {
  display: flex; flex-direction: column; gap: 14px;
  min-height: 200px; max-height: 420px; overflow-y: auto;
  padding-right: 4px; margin-bottom: 16px;
}
.chat-hint { color: var(--text-muted); font-size: 0.85rem; font-style: italic; }
.chat-bubble {
  background: var(--ink-surface); border-radius: 10px; padding: 14px 18px;
  font-size: 0.9rem; line-height: 1.55; max-width: 85%;
}
.chat-bubble.user { align-self: flex-end; background: var(--gold-soft); }
.chat-bubble .meta { font-family: var(--font-mono); font-size: 0.68rem; color: var(--text-muted); margin-top: 8px; }

.chat-input-row { display: flex; gap: 10px; }
.chat-input-row input {
  flex: 1; background: var(--ink-surface); border: 1px solid rgba(255,255,255,0.08);
  border-radius: 8px; padding: 12px 16px; color: var(--text-primary); font-family: var(--font-body);
  font-size: 0.9rem;
}
.chat-input-row input:focus { outline: none; border-color: var(--gold); }

.spinner-text { font-family: var(--font-mono); font-size: 0.8rem; color: var(--gold); }

@media (max-width: 600px) {
  .topbar { flex-direction: column; gap: 4px; }
  .panel-head { flex-direction: column; align-items: flex-start; }
}