* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --ink: #0e1726;
  --accent: #f97316;
  --accent-dark: #ea580c;
  --muted: #64748b;
  --line: #e2e8f0;
  --bg: #f1f5f9;
  --card: #fff;
  --danger: #dc2626;
}

html, body { min-height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  color: var(--ink);
  background: var(--bg);
}

a { color: inherit; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.pad { padding: 16px; }
.error { color: var(--danger); }
.ok { color: #15803d; font-weight: 600; }

/* ---- top bar ---- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 20px;
  background: var(--ink);
  color: #fff;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 15px;
  font-weight: 700;
  white-space: nowrap;
  text-decoration: none;
  color: #fff;
}

.brand-mark { display: inline-flex; flex-direction: column; gap: 2px; }
.brand-mark i { display: block; height: 3px; border-radius: 2px; background: var(--accent); }
.brand-mark i:nth-child(1) { width: 8px; }
.brand-mark i:nth-child(2) { width: 12px; }
.brand-mark i:nth-child(3) { width: 16px; }
.brand-mark.big { gap: 5px; }
.brand-mark.big i { height: 7px; border-radius: 4px; }
.brand-mark.big i:nth-child(1) { width: 20px; }
.brand-mark.big i:nth-child(2) { width: 30px; }
.brand-mark.big i:nth-child(3) { width: 40px; }

.search { flex: 1; max-width: 520px; }
.search input {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  font: inherit;
}
.search input::placeholder { color: #94a3b8; }
.search input:focus { outline: 2px solid var(--accent); border-color: transparent; }

.user { margin-left: auto; display: flex; align-items: center; gap: 12px; white-space: nowrap; font-size: 13px; }
.user-name { color: #cbd5e1; }
.demo-pill { background: rgba(249, 115, 22, 0.18); color: #fdba74; padding: 4px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.link-btn { border: 0; background: none; color: #cbd5e1; font: inherit; cursor: pointer; text-decoration: underline; }

/* ---- buttons & inputs ---- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  text-decoration: none;
}
.btn:hover { background: #f8fafc; }
.btn:disabled { opacity: 0.55; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-dark); }

.icon-btn {
  border: 0;
  background: none;
  width: 32px;
  height: 32px;
  border-radius: 6px;
  font-size: 18px;
  line-height: 1;
  color: var(--muted);
  cursor: pointer;
}
.icon-btn:hover { background: var(--bg); color: var(--ink); }

.input {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font: inherit;
  font-size: 15px;
  background: #fff;
}
.input:focus { outline: 2px solid var(--accent); border-color: transparent; }

.field { display: block; margin-top: 18px; }
.field > span { display: block; font-weight: 600; margin-bottom: 6px; }
.folder-row { display: flex; align-items: center; gap: 12px; }
.folder-label { flex: 1; padding: 9px 12px; background: #fff; border: 1px solid var(--line); border-radius: 8px; }

/* ---- pages ---- */
.page { max-width: 1040px; margin: 0 auto; padding: 24px 20px 48px; }
.page.narrow { max-width: 620px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.page-title { font-size: 24px; font-weight: 700; margin-bottom: 6px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.page-foot { margin-top: 28px; font-size: 12px; color: var(--muted); }

.crumbs { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; font-size: 18px; font-weight: 700; }
.crumbs a { text-decoration: none; }
.crumbs a:hover { text-decoration: underline; }
.crumbs .sep { color: #94a3b8; font-weight: 400; }
.crumbs.small { font-size: 14px; margin-bottom: 10px; }
.guide-view > .crumbs { font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 10px; }

/* ---- library list ---- */
.item-list { background: var(--card); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.item-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px 10px 16px;
  border-top: 1px solid var(--line);
  text-decoration: none;
}
.item-row:first-child { border-top: 0; }
.item-row:hover { background: #f8fafc; }
.item-main { flex: 1; min-width: 0; display: flex; align-items: center; gap: 12px; text-decoration: none; }
.item-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-row.result .item-title { display: block; }
.item-meta { color: var(--muted); font-size: 12px; white-space: nowrap; }
.item-sub, .item-snippet { display: block; color: var(--muted); font-size: 12px; margin-top: 2px; }
.item-snippet { color: #334155; }
mark { background: #fed7aa; color: inherit; border-radius: 2px; }

.ico { flex: 0 0 auto; display: inline-flex; }
.ico.folder { color: #f59e0b; }
.ico.guide { color: var(--accent); }

.empty-state { text-align: center; padding: 48px 20px; }
.empty-state h2 { font-size: 18px; margin-bottom: 8px; }
.empty-state p { color: var(--muted); margin-bottom: 16px; max-width: 460px; margin-left: auto; margin-right: auto; }

/* ---- dropdown menu ---- */
.menu {
  position: absolute;
  z-index: 50;
  width: 180px;
  padding: 6px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 10px 30px rgba(15, 23, 42, 0.15);
}
.menu-item { display: block; width: 100%; text-align: left; padding: 8px 10px; border: 0; background: none; border-radius: 6px; font: inherit; cursor: pointer; }
.menu-item:hover { background: var(--bg); }
.menu-item.danger { color: var(--danger); }

/* ---- modal ---- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(15, 23, 42, 0.45);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 10vh 16px 16px;
}
.modal { width: 100%; max-width: 480px; background: #fff; border-radius: 14px; box-shadow: 0 20px 50px rgba(15, 23, 42, 0.3); padding: 18px 20px 20px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.modal-head h2 { font-size: 17px; }
.modal-text p { margin-bottom: 12px; line-height: 1.5; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.picker-list { max-height: 320px; overflow-y: auto; border: 1px solid var(--line); border-radius: 10px; }
.picker-row { display: flex; align-items: center; gap: 10px; width: 100%; padding: 10px 12px; border: 0; border-top: 1px solid var(--line); background: none; font: inherit; text-align: left; cursor: pointer; }
.picker-row:first-child { border-top: 0; }
.picker-row:hover { background: #f8fafc; }

/* ---- toast & banner ---- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 70;
  transform: translate(-50%, 20px);
  opacity: 0;
  transition: all 0.2s;
  background: var(--ink);
  color: #fff;
  padding: 10px 16px;
  border-radius: 10px;
  font-weight: 600;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: var(--danger); }

.banner { padding: 10px 16px; display: flex; align-items: center; gap: 12px; }
.banner.error { background: #fee2e2; color: #7f1d1d; }

.progress { height: 8px; background: var(--line); border-radius: 999px; overflow: hidden; margin-top: 18px; }
.progress .bar { height: 100%; width: 0; background: var(--accent); transition: width 0.2s; }

.facts { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 16px 0; }
.facts dt { font-weight: 600; }

/* ---- sign-in ---- */
.signin { max-width: 380px; margin: 14vh auto 0; text-align: center; display: flex; flex-direction: column; align-items: center; gap: 12px; }
.signin h1 { font-size: 26px; }
.signin p { color: var(--muted); margin-bottom: 8px; }

/* ---- guide viewer ---- */
.guide-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; margin-bottom: 24px; }
.steps { list-style: none; display: flex; flex-direction: column; gap: 28px; }
.step { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 18px; scroll-margin-top: 70px; }
.step-head { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.step-head h2 { font-size: 17px; }
.step-head .num {
  flex: 0 0 auto;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}
.step-shot { display: block; width: 100%; height: auto; border-radius: 8px; border: 1px solid var(--line); }
.step-note-text { margin-top: 12px; line-height: 1.55; white-space: pre-wrap; }

@media (max-width: 640px) {
  .topbar { flex-wrap: wrap; padding: 10px 16px; }
  .search { order: 3; flex-basis: 100%; max-width: none; }
  .page { padding: 16px 16px 40px; }
  .item-meta { display: none; }
  .step { padding: 12px; }
}

/* =================================================================
   Editor (body.editor-mode): full-height layout, no page scroll
   ================================================================= */
body.editor-mode { height: 100vh; overflow: hidden; display: flex; flex-direction: column; }
body.editor-mode #app, body.editor-mode .view { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.editor { flex: 1; min-height: 0; display: flex; flex-direction: column; }

.editor-bar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 16px;
  background: #fff;
  border-bottom: 1px solid var(--line);
}

.guide-title {
  flex: 1;
  min-width: 0;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 16px;
  font-weight: 700;
  font-family: inherit;
}
.guide-title:focus { outline: 2px solid var(--accent); border-color: transparent; }
.save-state { font-size: 12px; color: var(--muted); white-space: nowrap; }

.layout { flex: 1; display: flex; min-height: 0; }

.sidebar {
  width: 232px;
  flex: 0 0 auto;
  background: #fff;
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.sidebar-head {
  padding: 12px 14px 8px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.step-list { flex: 1; overflow-y: auto; padding: 0 10px 12px; }

.step-card {
  border: 2px solid transparent;
  border-radius: 10px;
  padding: 8px;
  margin-bottom: 8px;
  cursor: pointer;
  background: #f8fafc;
}
.step-card:hover { background: #f1f5f9; }
.step-card.active { border-color: var(--accent); background: #fff7ed; }

.step-card img, .step-card .no-shot { width: 100%; border-radius: 6px; display: block; background: #e2e8f0; }
.step-card .no-shot { aspect-ratio: 16 / 10; display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 11px; }

.step-card .card-row { display: flex; align-items: center; gap: 6px; margin-top: 6px; }
.step-card .card-num {
  flex: 0 0 auto;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}
.step-card .card-desc { flex: 1; min-width: 0; font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.step-card .card-btns { display: flex; gap: 2px; }
.step-card .card-btns button { border: 0; background: none; color: #94a3b8; cursor: pointer; font-size: 12px; padding: 2px 4px; border-radius: 4px; line-height: 1; }
.step-card .card-btns button:hover { color: var(--ink); background: var(--line); }
.step-card .card-btns button.del:hover { color: #ef4444; background: #fee2e2; }

.workspace { flex: 1; min-width: 0; display: flex; flex-direction: column; padding: 14px 18px; gap: 10px; overflow: hidden; }
.step-fields { flex: 0 0 auto; }
.step-desc-row { display: flex; align-items: center; gap: 10px; }

.badge-num {
  flex: 0 0 auto;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}

.step-desc { flex: 1; padding: 9px 12px; border: 1px solid var(--line); border-radius: 8px; font-size: 15px; font-weight: 600; font-family: inherit; background: #fff; }
.step-note { width: 100%; margin-top: 8px; padding: 8px 12px; border: 1px solid var(--line); border-radius: 8px; font-size: 13px; font-family: inherit; background: #fff; resize: vertical; }
.step-desc:focus, .step-note:focus { outline: 2px solid var(--accent); border-color: transparent; }

.toolbar { flex: 0 0 auto; display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.tool-group { display: flex; align-items: center; gap: 4px; background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 4px; }
.tool {
  min-width: 34px;
  height: 34px;
  border: 0;
  border-radius: 7px;
  background: none;
  font-size: 15px;
  font-family: inherit;
  color: var(--ink);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.tool:hover { background: var(--bg); }
.tool.active { background: var(--ink); color: #fff; }
.tool.wide { padding: 0 10px; font-size: 13px; }

.swatch { width: 24px; height: 24px; border: 2px solid transparent; border-radius: 50%; cursor: pointer; padding: 0; }
.swatch.active { border-color: var(--ink); box-shadow: inset 0 0 0 2px #fff; }

.canvas-wrap {
  flex: 1;
  min-height: 0;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  position: relative;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 16px;
}

#stage { max-width: 100%; border-radius: 6px; box-shadow: 0 2px 12px rgba(15, 23, 42, 0.12); cursor: crosshair; touch-action: none; }
#stage.select-mode { cursor: default; }

.text-input {
  position: absolute;
  z-index: 5;
  border: 2px solid var(--accent);
  border-radius: 6px;
  padding: 4px 8px;
  font-size: 16px;
  font-weight: 700;
  font-family: inherit;
  background: rgba(255, 255, 255, 0.95);
  min-width: 160px;
}
