:root {
  --ink: #1c1633;
  --ink-soft: #4a4468;
  --muted: #7b7595;
  --line: #e7e3f2;
  --bg: #faf8ff;
  --card: #ffffff;
  --brand: #6c4cf0;
  --brand-dark: #563bc4;
  --brand-soft: #efeaff;
  --accent: #e23a6e;
  --ok: #1f9d6b;
  --warn: #c9871f;
  --danger: #d13b3b;
  --radius: 14px;
  --shadow: 0 2px 8px rgba(40, 20, 90, 0.06), 0 12px 30px rgba(40, 20, 90, 0.07);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --serif: "Georgia", "Times New Roman", serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .4em; }
.serif { font-family: var(--serif); }

/* buttons */
.btn {
  display: inline-flex; align-items: center; gap: 8px; justify-content: center;
  font: inherit; font-weight: 600; cursor: pointer;
  padding: 11px 20px; border-radius: 10px; border: 1px solid transparent;
  background: var(--brand); color: #fff; transition: background .15s, transform .05s;
}
.btn:hover { background: var(--brand-dark); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.secondary { background: #fff; color: var(--ink); border-color: var(--line); }
.btn.secondary:hover { background: #f6f4fb; }
.btn.ghost { background: transparent; color: var(--brand); }
.btn.ghost:hover { background: var(--brand-soft); }
.btn.danger { background: var(--danger); }
.btn.small { padding: 7px 13px; font-size: 13px; border-radius: 8px; }
.btn.block { width: 100%; }

/* forms */
label { display: block; font-size: 13px; font-weight: 600; color: var(--ink-soft); margin: 0 0 5px; }
input, select, textarea {
  width: 100%; font: inherit; color: var(--ink);
  padding: 10px 12px; border: 1px solid var(--line); border-radius: 9px; background: #fff;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand-soft); border-color: var(--brand); }
textarea { resize: vertical; min-height: 84px; }
.field { margin-bottom: 14px; }
.row { display: flex; gap: 12px; flex-wrap: wrap; }
.row > * { flex: 1; min-width: 140px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.pill { display: inline-block; font-size: 12px; font-weight: 600; padding: 3px 10px; border-radius: 999px; background: var(--brand-soft); color: var(--brand-dark); }
.pill.ok { background: #e2f6ee; color: var(--ok); }
.pill.warn { background: #fbf0da; color: var(--warn); }
.pill.muted { background: #f0eef6; color: var(--muted); }
.pill.danger { background: #fbe4e4; color: var(--danger); }

.muted { color: var(--muted); }
.center { text-align: center; }
.stack > * + * { margin-top: 14px; }

/* ---------- landing ---------- */
.nav {
  display: flex; align-items: center; justify-content: space-between;
  max-width: 1080px; margin: 0 auto; padding: 20px 24px;
}
.logo { font-family: var(--serif); font-weight: 700; font-size: 22px; color: var(--ink); }
.logo b { color: var(--brand); }
.hero { max-width: 860px; margin: 40px auto 0; padding: 0 24px; text-align: center; }
.hero h1 { font-family: var(--serif); font-size: clamp(34px, 6vw, 58px); letter-spacing: -.5px; }
.hero p.lead { font-size: clamp(17px, 2.4vw, 21px); color: var(--ink-soft); max-width: 640px; margin: 0 auto 28px; }
.hero .cta-row { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }
.section { max-width: 1080px; margin: 0 auto; padding: 56px 24px; }
.grid { display: grid; gap: 20px; }
.grid.cols-3 { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); }
.feature { padding: 22px; }
.feature .ico { font-size: 26px; }
.feature h3 { font-size: 17px; margin-top: 10px; }
.feature p { color: var(--ink-soft); font-size: 14.5px; margin: 0; }
.price { padding: 24px; text-align: center; position: relative; }
.price.hot { border-color: var(--brand); box-shadow: 0 0 0 2px var(--brand-soft), var(--shadow); }
.price .amt { font-size: 40px; font-weight: 800; font-family: var(--serif); }
.price .amt span { font-size: 15px; font-weight: 500; color: var(--muted); }
.price ul { list-style: none; padding: 0; margin: 16px 0; text-align: left; font-size: 14px; }
.price li { padding: 5px 0 5px 26px; position: relative; color: var(--ink-soft); }
.price li::before { content: "✓"; color: var(--ok); position: absolute; left: 4px; font-weight: 700; }
.footer { border-top: 1px solid var(--line); margin-top: 40px; }
.footer .section { padding: 30px 24px; color: var(--muted); font-size: 14px; display: flex; justify-content: space-between; flex-wrap: wrap; gap: 10px; }

/* ---------- auth ---------- */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.auth-card { width: 100%; max-width: 400px; padding: 32px; }

/* ---------- app shell ---------- */
.app { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.side { border-right: 1px solid var(--line); background: #fff; padding: 18px 14px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.side .logo { display: block; padding: 4px 8px 16px; font-size: 20px; }
.side nav a { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 9px; color: var(--ink-soft); font-weight: 500; font-size: 14.5px; }
.side nav a:hover { background: #f6f4fb; text-decoration: none; }
.side nav a.active { background: var(--brand-soft); color: var(--brand-dark); font-weight: 600; }
.side .pen-select { margin: 6px 0 14px; }
.side .up { margin-top: auto; }
.side-foot { position: sticky; bottom: 0; padding-top: 14px; margin-top: 14px; border-top: 1px solid var(--line); font-size: 13px; }
.main { padding: 26px 30px; max-width: 1100px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head h1 { font-size: 24px; margin: 0; font-family: var(--serif); }

.book-grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
.book-card { padding: 14px; cursor: pointer; display: flex; flex-direction: column; gap: 8px; }
.book-card:hover { border-color: var(--brand); }
.book-cover { aspect-ratio: 2/3; border-radius: 8px; background: linear-gradient(135deg, var(--brand-soft), #d9ccff); display: grid; place-items: center; overflow: hidden; }
.book-cover img { width: 100%; height: 100%; object-fit: cover; }
.book-cover .ph { font-family: var(--serif); color: var(--brand-dark); padding: 12px; text-align: center; font-size: 15px; }

.content-list { display: grid; gap: 14px; }
.content-item { display: grid; grid-template-columns: 120px 1fr auto; gap: 16px; padding: 14px; align-items: start; }
.content-item .thumb { width: 120px; height: 120px; border-radius: 8px; background: #f0eef6; object-fit: cover; }
.content-item .cap { font-size: 14px; white-space: pre-wrap; }
.content-item .acts { display: flex; flex-direction: column; gap: 6px; }

.gen-layout { display: grid; grid-template-columns: 1fr 420px; gap: 24px; align-items: start; }
.preview-canvas { width: 100%; border-radius: 12px; background: #f0eef6; box-shadow: var(--shadow); }
.variant { padding: 12px; border: 1px solid var(--line); border-radius: 10px; margin-bottom: 10px; cursor: pointer; font-size: 14px; }
.variant:hover { border-color: var(--brand); }
.variant.sel { border-color: var(--brand); background: var(--brand-soft); }
.tag { display: inline-block; font-size: 12px; color: var(--brand-dark); margin-right: 6px; }

.modal-bg { position: fixed; inset: 0; background: rgba(28,22,51,.45); display: grid; place-items: center; padding: 20px; z-index: 50; }
.modal { width: 100%; max-width: 560px; max-height: 90vh; overflow-y: auto; padding: 26px; }
.modal h2 { font-family: var(--serif); }

.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 11px 20px; border-radius: 10px; font-size: 14px; z-index: 100; box-shadow: var(--shadow); }
.toast.err { background: var(--danger); }
.toast.ok { background: var(--ok); }

.empty { text-align: center; padding: 50px 20px; color: var(--muted); }
.empty .big { font-size: 40px; margin-bottom: 10px; }
.stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px,1fr)); gap: 14px; margin-bottom: 22px; }
.stat { padding: 16px; }
.stat .n { font-size: 30px; font-weight: 800; font-family: var(--serif); }
.stat .l { font-size: 13px; color: var(--muted); }
.spinner { display: inline-block; width: 16px; height: 16px; border: 2px solid var(--brand-soft); border-top-color: var(--brand); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading { display: grid; place-items: center; padding: 60px; }

@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; }
  .side { position: static; height: auto; display: flex; flex-direction: column; }
  .side nav { display: flex; flex-wrap: wrap; }
  .gen-layout { grid-template-columns: 1fr; }
  .content-item { grid-template-columns: 90px 1fr; }
  .content-item .acts { grid-column: 1 / -1; flex-direction: row; flex-wrap: wrap; }
}
