/* ============ Paper Plane Studio — workbench UI ============ */
:root {
  --paper: #f6f1e7;
  --paper-deep: #ece5d4;
  --ink: #22303f;
  --ink-soft: #5d6a77;
  --line: #d8cfba;
  --valley: #1a5bab;
  --mountain: #cd2430;
  --accent: #e05b2b;
  --mat: #1c4e94;
  --ok: #2fa36b;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: "Work Sans", -apple-system, "Segoe UI", sans-serif;
  background: var(--paper);
  color: var(--ink);
  overflow: hidden;
}

/* Auth gate: the editor exists only for signed-in users.
   auth.js toggles body.signed-in after Clerk resolves the session. */
#app { display: none; flex-direction: column; height: 100vh; }
body.signed-in #app { display: flex; }
body.signed-in #landing { display: none; }

/* ---------- landing ---------- */
#landing {
  position: fixed; inset: 0; overflow-y: auto; z-index: 30;
  /* army woodland camo tile (inline SVG) under the workbench grid */
  background:
    linear-gradient(rgba(255,255,255,0.05) 1px, transparent 1px) 0 0 / 20px 20px,
    linear-gradient(90deg, rgba(255,255,255,0.05) 1px, transparent 1px) 0 0 / 20px 20px,
    linear-gradient(rgba(255,255,255,0.09) 1.5px, transparent 1.5px) 0 0 / 100px 100px,
    linear-gradient(90deg, rgba(255,255,255,0.09) 1.5px, transparent 1.5px) 0 0 / 100px 100px,
    url("data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20width='480'%20height='480'%3E%3Cfilter%20id='c'%20x='0'%20y='0'%20width='100%25'%20height='100%25'%20color-interpolation-filters='sRGB'%3E%3CfeTurbulence%20type='fractalNoise'%20baseFrequency='0.011'%20numOctaves='3'%20seed='11'%20stitchTiles='stitch'/%3E%3CfeGaussianBlur%20stdDeviation='2'/%3E%3CfeColorMatrix%20values='1%200%200%200%200%201%200%200%200%200%201%200%200%200%200%200%200%200%200%201'/%3E%3CfeComponentTransfer%3E%3CfeFuncR%20type='discrete'%20tableValues='0.341%200.239%200.341%200.557%200.318%200.341%200.239%200.184'/%3E%3CfeFuncG%20type='discrete'%20tableValues='0.388%200.29%200.388%200.537%200.267%200.388%200.29%200.227'/%3E%3CfeFuncB%20type='discrete'%20tableValues='0.247%200.169%200.247%200.357%200.192%200.247%200.169%200.133'/%3E%3C/feComponentTransfer%3E%3C/filter%3E%3Crect%20width='480'%20height='480'%20filter='url(%23c)'/%3E%3C/svg%3E") 0 0 / 480px 480px,
    #57633f;
}
.land-wrap {
  max-width: 1080px; margin: 0 auto;
  padding: clamp(16px, 3.5vw, 36px) clamp(18px, 4vw, 44px) clamp(28px, 5vw, 56px);
  display: flex; flex-direction: column; gap: clamp(30px, 5.5vw, 62px);
}
.land-head {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  background: transparent; border-bottom: 0; padding: 0;
}
.land-head .wordmark { color: #fdfdfa; }
.land-head .wordmark em { color: var(--accent); }
.land-head .tagline { color: #d4d2ac; }
.land-signin {
  border: 1.5px solid rgba(253,253,250,0.65); background: transparent; color: #e8eefa;
  font: inherit; font-size: 13px; font-weight: 600;
  padding: 8px 16px; border-radius: 7px; cursor: pointer;
}
.land-signin:hover { background: #fdfdfa; color: var(--ink); border-color: #fdfdfa; }

.land-hero {
  display: grid; grid-template-columns: minmax(0, 7fr) minmax(0, 5fr);
  gap: clamp(22px, 4vw, 48px); align-items: center;
}
.hero-sheet {
  background: var(--paper); border: 2px solid var(--ink); border-radius: 4px;
  box-shadow: 7px 7px 0 rgba(24, 28, 12, 0.55);
  transform: rotate(-0.5deg);
  padding: clamp(24px, 4vw, 46px) clamp(22px, 3.6vw, 44px);
}
.hero-sheet h1 {
  font-family: "Bungee", "Arial Black", sans-serif; font-weight: 400;
  font-size: clamp(30px, 4.6vw, 54px); line-height: 1.06;
  margin: 0 0 16px; color: var(--ink); letter-spacing: 0.5px;
}
.hero-sheet h1 span { color: var(--accent); }
.hero-sub { margin: 0 0 24px; font-size: clamp(14px, 1.5vw, 16.5px); line-height: 1.6; color: var(--ink-soft); max-width: 46ch; }
.hero-sub b { color: var(--ink); }
.hero-cta { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; margin-bottom: 22px; }
button.primary.big { font-size: 16px; padding: 13px 28px; box-shadow: 0 3px 0 #a83e17; }
.hero-alt {
  border: 0; background: none; cursor: pointer; font: inherit; font-size: 13.5px; font-weight: 600;
  color: var(--ink-soft); text-decoration: underline; text-underline-offset: 3px; padding: 6px 2px;
}
.hero-alt:hover { color: var(--ink); }
.hero-chips { display: flex; gap: 7px; flex-wrap: wrap; list-style: none; margin: 0; padding: 14px 0 0; border-top: 1px dashed var(--line); }
.hero-chips li {
  border: 1.5px solid var(--line); border-radius: 20px; background: #fdfdfa;
  font-size: 12px; font-weight: 600; color: var(--ink-soft); padding: 4.5px 12px;
}

.hero-art { position: relative; min-height: 340px; }
.art-sheet {
  display: block; width: min(72%, 300px); margin: 34px auto 0;
  border: 2px solid var(--ink); border-radius: 3px;
  box-shadow: 7px 7px 0 rgba(24, 28, 12, 0.55);
  transform: rotate(2.4deg);
  background: #fdfdfa;
}
.art-flight { position: absolute; inset: -18px 0 auto -14px; width: 108%; pointer-events: none; }

.land-steps { display: grid; grid-template-columns: repeat(3, 1fr); gap: clamp(14px, 2.4vw, 26px); }
.step-card {
  background: #fdfdfa; border: 1.5px solid var(--ink); border-radius: 8px;
  box-shadow: 4px 4px 0 rgba(24, 28, 12, 0.5);
  transform: rotate(var(--tilt, 0deg));
  padding: 20px 20px 22px;
}
.step-n {
  display: inline-flex; align-items: center; justify-content: center;
  width: 26px; height: 26px; border-radius: 50%; background: var(--ink); color: #fff;
  font-size: 13px; font-weight: 800; margin-bottom: 12px;
}
.step-card h3 { margin: 0 0 8px; font-size: 16.5px; color: var(--ink); }
.step-card p { margin: 0; font-size: 13px; line-height: 1.55; color: var(--ink-soft); }

.land-foot { color: #c9c7a2; font-size: 12px; line-height: 1.6; max-width: 62ch; }
.land-legend { display: flex; gap: 18px; margin-bottom: 10px; font-size: 11.5px; color: #dedbb8; }
.land-legend i { display: inline-block; width: 26px; border-top: 3px dashed #8fb4ec; vertical-align: middle; margin-right: 6px; }
.land-legend .m i { border-top-style: dotted; border-top-color: #ef8a93; }
.land-foot b { color: #efeeda; }

/* load-in: sheets settle onto the mat */
@media (prefers-reduced-motion: no-preference) {
  .hero-sheet, .hero-art, .step-card, .land-foot {
    opacity: 0; transform: translateY(14px);
    animation: landSettle 0.7s cubic-bezier(0.22, 1, 0.36, 1) forwards;
  }
  .hero-sheet { animation-delay: 0.05s; }
  .hero-art { animation-delay: 0.18s; }
  .land-steps .step-card:nth-child(1) { animation-delay: 0.3s; }
  .land-steps .step-card:nth-child(2) { animation-delay: 0.38s; }
  .land-steps .step-card:nth-child(3) { animation-delay: 0.46s; }
  .land-foot { animation-delay: 0.55s; }
}
@keyframes landSettle {
  to { opacity: 1; transform: translateY(0) rotate(var(--tilt, 0deg)); }
}
.hero-sheet { --tilt: -0.5deg; }
.hero-art { --tilt: 0deg; }

@media (max-width: 860px) {
  .land-hero { grid-template-columns: 1fr; }
  .hero-art { min-height: 0; margin-top: -6px; }
  .art-flight { inset: -30px 0 auto 0; width: 100%; }
  .land-steps { grid-template-columns: 1fr; }
}

/* ---------- header ---------- */
header {
  display: flex; align-items: center; gap: 18px;
  padding: 10px 22px;
  background: var(--paper);
  border-bottom: 2px solid var(--ink);
}
.wordmark {
  font-family: "Bungee", "Arial Black", sans-serif;
  font-size: 21px; letter-spacing: 0.5px; line-height: 1;
  color: var(--ink); white-space: nowrap;
}
.wordmark em { font-style: normal; color: var(--accent); }
.tagline { font-size: 12px; color: var(--ink-soft); margin-top: 2px; }
.head-mid { flex: 1; display: flex; align-items: baseline; gap: 10px; min-width: 0; }
#planeName { font-weight: 800; font-size: 16px; white-space: nowrap; }
#planeTags { display: flex; gap: 5px; }
.tag { font-size: 10px; font-weight: 700; color: #fff; padding: 2.5px 7px; border-radius: 3px; letter-spacing: 0.4px; }
.tag-easy { background: #3f9d46; } .tag-hard { background: #ef7d1a; }
.tag-med { background: #e0a10b; } .tag-expert { background: #c62828; }
.tag-dist { background: #1c56a8; } .tag-time { background: #123f7c; }
.tag-acro { background: #7b3fa0; } .tag-deco { background: #0f8b8d; }

.seg { display: inline-flex; border: 1.5px solid var(--ink); border-radius: 7px; overflow: hidden; background: #fff; }
.seg button {
  border: 0; background: transparent; padding: 7px 13px; cursor: pointer;
  font: inherit; font-size: 12.5px; font-weight: 600; color: var(--ink-soft);
}
.seg button + button { border-left: 1.5px solid var(--ink); }
.seg button.active { background: var(--ink); color: #fff; }

button.primary {
  border: 0; background: var(--accent); color: #fff; cursor: pointer;
  font: inherit; font-weight: 800; font-size: 14px;
  padding: 10px 22px; border-radius: 8px;
  box-shadow: 0 2px 0 #a83e17;
}
button.primary:active { transform: translateY(1px); box-shadow: 0 1px 0 #a83e17; }
#resetBtn {
  border: 1.5px solid var(--line); background: transparent; color: var(--ink-soft);
  font: inherit; font-size: 12px; padding: 7px 12px; border-radius: 7px; cursor: pointer;
}
#resetBtn.danger { border-color: var(--mountain); color: var(--mountain); font-weight: 700; }

#authControls { display: flex; align-items: center; }
#authControls[hidden] { display: none; }
#signInBtn {
  border: 1.5px solid var(--ink); background: #fff; color: var(--ink);
  font: inherit; font-size: 12.5px; font-weight: 700;
  padding: 7px 14px; border-radius: 7px; cursor: pointer;
}
#signInBtn:hover { background: var(--ink); color: #fff; }
#userButton { display: flex; align-items: center; }

/* ---------- layout ---------- */
main { flex: 1; display: flex; min-height: 0; }

/* ---------- sidebar ---------- */
aside {
  width: 292px; flex-shrink: 0; overflow-y: auto;
  background: var(--paper); border-right: 2px solid var(--ink);
  padding: 14px 16px 24px;
}
aside h3 {
  font-size: 11px; letter-spacing: 1.6px; text-transform: uppercase;
  color: var(--ink-soft); margin: 20px 0 8px; font-weight: 800;
}
aside h3:first-child { margin-top: 2px; }

.plane-cards {
  display: grid; gap: 4px;
  max-height: 262px; overflow-y: auto; padding-right: 4px;
  border-bottom: 1px dashed var(--line); padding-bottom: 6px;
}
.plane-cards button {
  display: flex; align-items: center; gap: 9px; text-align: left;
  border: 1.5px solid var(--line); border-radius: 8px; background: #fff;
  padding: 5px 9px; cursor: pointer; font: inherit; color: var(--ink);
}
.plane-cards button.active { border-color: var(--ink); box-shadow: 2px 2px 0 var(--ink); }
.plane-cards svg { width: 24px; height: 24px; flex-shrink: 0; color: var(--ink); }
.plane-cards button.active svg { color: var(--accent); }
.plane-cards .pc-name { font-weight: 700; font-size: 12.5px; }
.plane-cards .pc-sub { font-size: 10px; color: var(--ink-soft); }

.chip-row { display: flex; flex-wrap: wrap; gap: 5px; }
.chip-row button {
  border: 1.5px solid var(--line); background: #fff; border-radius: 20px;
  padding: 4.5px 11px; font: inherit; font-size: 12px; cursor: pointer; color: var(--ink);
}
.chip-row button.active { background: var(--ink); border-color: var(--ink); color: #fff; }

.field { display: flex; align-items: center; gap: 8px; font-size: 12.5px; margin: 7px 0; color: var(--ink-soft); }
.field input[type="range"] { flex: 1; accent-color: var(--accent); }
.field input[type="color"] { width: 34px; height: 26px; border: 1.5px solid var(--line); border-radius: 5px; padding: 1px; background: #fff; cursor: pointer; }
.field input[type="text"], .field select {
  flex: 1; font: inherit; font-size: 12.5px; padding: 6px 8px;
  border: 1.5px solid var(--line); border-radius: 6px; background: #fff; color: var(--ink);
}
.field span { min-width: 38px; text-align: right; font-variant-numeric: tabular-nums; }

.color-pair { display: flex; gap: 14px; }

#shapeGrid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 5px; }
.shape-btn {
  border: 1.5px solid var(--line); background: #fff; border-radius: 8px;
  padding: 6px 2px 4px; cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 2px;
}
.shape-btn:hover { border-color: var(--ink); }
.shape-btn svg { width: 26px; height: 26px; }
.shape-btn span { font-size: 9px; color: var(--ink-soft); }

.add-text-row { display: flex; gap: 6px; }
.add-text-row input { flex: 1; font: inherit; font-size: 13px; padding: 7px 9px; border: 1.5px solid var(--line); border-radius: 6px; }
.add-text-row button {
  border: 1.5px solid var(--ink); background: var(--ink); color: #fff;
  font: inherit; font-size: 12.5px; font-weight: 700; border-radius: 6px; padding: 0 13px; cursor: pointer;
}

#inspector {
  border: 1.5px solid var(--line); border-radius: 8px; background: #fff; padding: 10px 12px;
  font-size: 12.5px;
}
#inspector.empty { color: var(--ink-soft); border-style: dashed; background: transparent; }
#inspector.empty p { margin: 2px 0; line-height: 1.5; }
.insp-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; }
.insp-row { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 8px; }
button.mini {
  border: 1.5px solid var(--line); background: #fff; border-radius: 6px;
  font: inherit; font-size: 11px; padding: 4px 8px; cursor: pointer; color: var(--ink);
}
button.mini:hover { border-color: var(--ink); }
button.mini.danger { border-color: var(--mountain); color: var(--mountain); font-weight: 700; }

.toggles label { display: flex; align-items: center; gap: 8px; font-size: 12.5px; margin: 6px 0; cursor: pointer; }
.toggles input { accent-color: var(--accent); }

.legend { display: flex; gap: 14px; font-size: 11px; color: var(--ink-soft); margin-top: 8px; }
.legend i { display: inline-block; width: 26px; height: 0; border-top: 3px dashed var(--valley); vertical-align: middle; margin-right: 5px; }
.legend .m i { border-top-style: dotted; border-top-color: var(--mountain); }
.legend .c i { border-top-style: dotted; border-top-color: #666c76; }

.credit { font-size: 10.5px; color: var(--ink-soft); line-height: 1.5; margin-top: 22px; border-top: 1px solid var(--line); padding-top: 10px; }

/* ---------- canvas / cutting mat ---------- */
#canvasArea {
  flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: center;
  background:
    linear-gradient(rgba(255,255,255,0.055) 1px, transparent 1px) 0 0 / 20px 20px,
    linear-gradient(90deg, rgba(255,255,255,0.055) 1px, transparent 1px) 0 0 / 20px 20px,
    linear-gradient(rgba(255,255,255,0.1) 1.5px, transparent 1.5px) 0 0 / 100px 100px,
    linear-gradient(90deg, rgba(255,255,255,0.1) 1.5px, transparent 1.5px) 0 0 / 100px 100px,
    var(--mat);
  position: relative;
}
.side-tabs { display: flex; gap: 6px; margin-top: 14px; }
.side-tabs button {
  border: 0; border-radius: 7px 7px 0 0; padding: 8px 18px; cursor: pointer;
  font: inherit; font-size: 12.5px; font-weight: 700;
  background: rgba(255,255,255,0.22); color: #dbe6f5;
}
.side-tabs button.active { background: #fdfdfa; color: var(--ink); }

#sheet {
  background: #fdfdfa;
  box-shadow: 0 14px 34px rgba(6, 20, 46, 0.5);
  touch-action: none;
  display: block;
}
#sheet .item { cursor: grab; }
#sheet [data-handle] { cursor: pointer; }
#sheet [data-handle="scale"] { cursor: nwse-resize; }

#hintNote {
  position: absolute; bottom: 52px; left: 50%; transform: translateX(-50%);
  background: rgba(10, 28, 60, 0.85); color: #d9f2e4; font-size: 12px;
  padding: 7px 14px; border-radius: 20px; max-width: 70%; text-align: center;
  pointer-events: none;
}
.canvas-foot {
  position: absolute; bottom: 0; left: 0; right: 0;
  display: flex; align-items: center; justify-content: space-between;
  padding: 6px 16px; background: rgba(8, 24, 52, 0.55); color: #c8d6ec; font-size: 11.5px;
}
.canvas-foot .legend { color: #c8d6ec; margin: 0; }
details.fold-steps { position: absolute; top: 12px; right: 14px; max-width: 340px; }
details.fold-steps summary {
  cursor: pointer; background: #fdfdfa; border: 1.5px solid var(--ink);
  padding: 7px 13px; border-radius: 8px; font-size: 12.5px; font-weight: 700;
  list-style: none; box-shadow: 2px 2px 0 rgba(6,20,46,0.6); display: inline-block; float: right;
}
details.fold-steps ol {
  clear: both; background: #fdfdfa; border: 1.5px solid var(--ink); border-radius: 10px;
  margin: 8px 0 0; padding: 12px 16px; font-size: 12px; line-height: 1.5;
  list-style: none; box-shadow: 2px 2px 0 rgba(6,20,46,0.6);
}
details.fold-steps li { margin: 5px 0; }
details.fold-steps li.video { color: var(--ink-soft); border-top: 1px dashed var(--line); padding-top: 7px; margin-top: 9px; }

/* ---------- print panel ---------- */
#printPanel, #paywallPanel, #savePanel, #designsPanel {
  position: fixed; inset: 0; display: none; z-index: 40;
  background: rgba(15, 26, 40, 0.55);
}
#printPanel.open, #paywallPanel.open, #savePanel.open, #designsPanel.open { display: flex; align-items: flex-start; justify-content: center; }
.paywall-error { color: var(--mountain); font-size: 12.5px; font-weight: 600; margin: 0 0 14px; }
#paywallPerks { margin: 0 0 18px; padding: 0; list-style: none; font-size: 13.5px; line-height: 1.45; }
#paywallPerks li { padding: 7px 0 7px 30px; position: relative; border-bottom: 1px dashed var(--line); }
#paywallPerks li::before {
  content: attr(data-n); position: absolute; left: 0; top: 7px;
  width: 20px; height: 20px; border-radius: 50%; background: var(--ok); color: #fff;
  font-size: 11px; font-weight: 700; display: flex; align-items: center; justify-content: center;
}
.print-card {
  margin-top: 7vh; width: min(520px, 92vw); background: var(--paper);
  border: 2px solid var(--ink); border-radius: 14px; padding: 22px 26px;
  box-shadow: 6px 6px 0 rgba(10, 20, 35, 0.4);
}
.print-card h2 { margin: 0 0 4px; font-size: 19px; }
.print-card p.sub { margin: 0 0 14px; color: var(--ink-soft); font-size: 13px; }
.print-card ul { margin: 0 0 18px; padding: 0; list-style: none; font-size: 13.5px; line-height: 1.45; }
.print-card li { padding: 7px 0 7px 30px; position: relative; border-bottom: 1px dashed var(--line); }
.print-card li::before {
  content: attr(data-n); position: absolute; left: 0; top: 7px;
  width: 20px; height: 20px; border-radius: 50%; background: var(--ink); color: #fff;
  font-size: 11px; font-weight: 700; display: flex; align-items: center; justify-content: center;
}
.print-actions { display: flex; gap: 10px; justify-content: flex-end; }
.print-actions .ghost {
  border: 1.5px solid var(--ink); background: transparent; color: var(--ink);
  font: inherit; font-weight: 600; padding: 9px 18px; border-radius: 8px; cursor: pointer;
}

/* ---------- saved designs ---------- */
button.head-btn {
  border: 1.5px solid var(--line); background: transparent; color: var(--ink-soft);
  font: inherit; font-size: 12px; padding: 7px 12px; border-radius: 7px; cursor: pointer;
}
button.head-btn:hover { border-color: var(--ink); color: var(--ink); }
button.head-btn.flash { border-color: var(--ok); color: var(--ok); font-weight: 700; }
.save-name { display: block; font-size: 12.5px; font-weight: 600; color: var(--ink-soft); margin: 0 0 16px; }
.save-name input {
  display: block; width: 100%; margin-top: 5px; box-sizing: border-box;
  border: 1.5px solid var(--line); border-radius: 8px; padding: 9px 12px;
  font: inherit; font-size: 14px; color: var(--ink); background: #fff;
}
.save-name input:focus { outline: none; border-color: var(--accent); }
.designs-list { margin: 0 0 18px; max-height: 46vh; overflow-y: auto; }
.designs-empty { color: var(--ink-soft); font-size: 13px; margin: 6px 0 10px; }
.design-row {
  display: flex; align-items: center; gap: 8px;
  padding: 9px 2px; border-bottom: 1px dashed var(--line);
}
.design-row.open-now { background: rgba(63, 157, 70, 0.07); }
.design-info { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.design-info b { font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.design-meta { font-size: 11.5px; color: var(--ink-soft); }
.design-open-tag {
  display: inline-block; margin-left: 7px; padding: 1px 7px; border-radius: 9px;
  background: var(--ok); color: #fff; font-size: 9.5px; font-weight: 700;
  letter-spacing: 0.4px; text-transform: uppercase; vertical-align: 2px;
}

/* ---------- print ---------- */
#print-root { display: none; }
@media print {
  #app, #printPanel, #paywallPanel, #savePanel, #designsPanel, #landing { display: none !important; }
  body { overflow: visible; background: #fff; }
  #print-root { display: block; }
  .page {
    overflow: hidden; page-break-after: always; break-after: page;
  }
  .page svg {
    display: block;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
}
