/* Book Writer — LivingWriter-inspired design system
   Light, airy, blue-accented, generous whitespace. */
:root {
  --primary: #3366ff;
  --primary-hover: #2a56e0;
  --primary-soft: #eaf0ff;
  --primary-soft-border: #d5e0ff;
  --bg: #ffffff;
  --bg-soft: #f8f9fa;
  --surface: #ffffff;
  --border: #e3e6ea;
  --border-strong: #dadce0;
  --text: #1a1a1b;
  --text-secondary: #444746;
  --text-muted: #5f6368;
  --text-faint: #8a9099;
  --ok: #1e8e3e;
  --ok-soft: #e6f4ea;
  --err: #d93025;
  --err-soft: #fce8e6;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05), 0 1px 3px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 3px 10px rgba(0, 0, 0, 0.07), 0 1px 3px rgba(0, 0, 0, 0.05);
  --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.12);
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Inter", "Helvetica Neue", Arial, sans-serif;
  --serif: Georgia, "Times New Roman", serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Code", Consolas, monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
button {
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  border-radius: var(--radius-sm);
  cursor: pointer;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  padding: 8px 16px;
  transition: background .15s ease, border-color .15s ease, color .15s ease, box-shadow .15s ease;
}
button:hover { background: var(--bg-soft); border-color: var(--text-faint); }
button:active { transform: translateY(0.5px); }
button:disabled { opacity: .55; cursor: not-allowed; transform: none; }
button.primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
  font-weight: 500;
  box-shadow: 0 1px 2px rgba(51, 102, 255, 0.3);
}
button.primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); color: #fff; }
button.ghost { background: transparent; border-color: transparent; color: var(--text-secondary); }
button.ghost:hover { background: var(--bg-soft); color: var(--text); }
button.soft {
  background: var(--primary-soft);
  border-color: var(--primary-soft-border);
  color: var(--primary);
}
button.soft:hover { background: var(--primary-soft); border-color: var(--primary); color: var(--primary-hover); }
input, textarea {
  font-family: inherit;
  font-size: 15px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  width: 100%;
  transition: border-color .15s ease, box-shadow .15s ease;
}
input:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(51, 102, 255, 0.15); }
::placeholder { color: var(--text-faint); }

.muted { color: var(--text-muted); font-size: 13px; }
.faint { color: var(--text-faint); font-size: 12px; }

/* ---------- login ---------- */
#login-wrap {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(180deg, #fafbfc 0%, #f1f3f6 100%);
  padding: 24px;
}
#login {
  width: 100%; max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow-lg);
  padding: 40px 36px 32px;
}
.brand-mark {
  width: 48px; height: 48px; border-radius: 12px;
  background: linear-gradient(135deg, #5f8bff, #3366ff 60%, #254cd8);
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 700; font-size: 22px;
  margin-bottom: 20px;
  box-shadow: 0 4px 10px rgba(51, 102, 255, 0.35);
}
#login h1 { font-size: 24px; font-weight: 700; letter-spacing: -0.01em; }
#login .sub { color: var(--text-muted); margin: 6px 0 24px; font-size: 14px; }
#login input { margin-bottom: 12px; }
#login .err, #login .note {
  min-height: 20px;
  font-size: 13px;
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  margin-bottom: 12px;
}
#login .err { color: var(--err); background: var(--err-soft); }
#login .note { color: var(--primary); background: var(--primary-soft); }
#login button.primary { width: 100%; padding: 11px; font-size: 15px; }

/* ---------- app shell ---------- */
#topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 12px;
  height: 60px; padding: 0 24px;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; cursor: pointer; font-size: 16px; font-weight: 700; color: var(--text); }
.brand .mark {
  width: 30px; height: 30px; border-radius: 8px;
  background: linear-gradient(135deg, #5f8bff, #3366ff);
  color: #fff; font-size: 15px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
}
.brand:hover { text-decoration: none; }
.brand .brand-name span { color: var(--primary); }
.topbar-book { display: flex; align-items: center; gap: 8px; color: var(--text-muted); font-size: 14px; }
.topbar-book .crumb-sep { color: var(--text-faint); }
.topbar-book strong { color: var(--text); font-weight: 600; }
#topbar .spacer { flex: 1; }

#layout { display: flex; min-height: calc(100vh - 60px); align-items: stretch; }

/* ---------- sidebar ---------- */
#sidebar {
  width: 240px; flex-shrink: 0;
  background: var(--bg-soft);
  border-right: 1px solid var(--border);
  padding: 20px 12px;
  display: flex; flex-direction: column;
  overflow-y: auto;
}
#sidebar h3 {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--text-faint); font-weight: 600;
  margin: 16px 10px 6px;
}
#sidebar h3:first-child { margin-top: 4px; }
#sidebar .item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; border-radius: var(--radius-sm);
  cursor: pointer; font-size: 14px; color: var(--text-secondary);
  transition: background .12s ease, color .12s ease;
  user-select: none;
}
#sidebar .item:hover { background: #eceef1; color: var(--text); }
#sidebar .item.active { background: var(--primary-soft); color: var(--primary); font-weight: 500; }
#sidebar .item .ico { width: 18px; height: 18px; flex-shrink: 0; opacity: .8; }
#sidebar .item.active .ico { opacity: 1; }
#sidebar .item .count { margin-left: auto; font-size: 12px; color: var(--text-faint); }
#sidebar .capture-panel { margin-top: auto; padding: 10px 4px 18px; }
#sidebar .capture-panel input { margin-bottom: 8px; background: var(--surface); }
#sidebar .capture-panel button { width: 100%; }

/* ---------- main ---------- */
#main { flex: 1; padding: 32px 40px 48px; overflow-y: auto; min-width: 0; }
.page-head { margin-bottom: 20px; }
.page-head h1 { font-size: 26px; font-weight: 700; letter-spacing: -0.01em; }
.page-head .sub { color: var(--text-muted); font-size: 14px; margin-top: 4px; }
.page-tools { display: flex; gap: 10px; }

/* ---------- books grid ---------- */
#grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 18px;
  margin-top: 8px;
}
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  cursor: pointer;
  transition: box-shadow .18s ease, border-color .18s ease, transform .18s ease;
  position: relative;
}
.card:hover { box-shadow: var(--shadow-md); border-color: var(--primary-soft-border); transform: translateY(-2px); }
.card .book-cover {
  width: 48px; height: 62px; border-radius: 7px;
  background: linear-gradient(150deg, #5f8bff, #3366ff 70%, #254cd8);
  box-shadow: 0 2px 6px rgba(51, 102, 255, 0.35);
  margin-bottom: 14px;
  display: flex; align-items: flex-end; justify-content: center;
  color: #fff; font-size: 16px; font-weight: 700; letter-spacing: .02em;
  padding-bottom: 7px;
}
.card .title { font-size: 16px; font-weight: 600; margin-bottom: 4px; }
.card .meta { color: var(--text-muted); font-size: 13px; }
.card .meta span { display: inline-flex; align-items: center; gap: 4px; }
.card .open-arrow {
  position: absolute; top: 22px; right: 18px;
  color: var(--text-faint); font-size: 18px;
  transition: color .15s ease, transform .15s ease;
}
.card:hover .open-arrow { color: var(--primary); transform: translateX(2px); }

/* ---------- file lists ---------- */
.filelist { display: grid; gap: 8px; margin-top: 8px; }
.file {
  display: flex; align-items: center; gap: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 18px;
  cursor: pointer;
  transition: box-shadow .15s ease, border-color .15s ease;
}
.file:hover { box-shadow: var(--shadow-sm); border-color: var(--primary-soft-border); }
.file .f-ico {
  width: 36px; height: 36px; border-radius: 9px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px;
}
.file .f-ico.char { background: #e8f0fe; color: #3366ff; }
.file .f-ico.loc { background: #e6f4ea; color: #1e8e3e; }
.file .f-ico.thm { background: #fef7e0; color: #b26a00; }
.file .f-ico.chap { background: #f3e8fd; color: #7627bb; }
.file .f-ico.idea { background: #fce8e6; color: #c5221f; }
.file .f-ico.plot { background: #e0f7fa; color: #00838f; }
.file .f-ico.note { background: #eceef1; color: #5f6368; }
.file .f-main { flex: 1; min-width: 0; }
.file .f-title { font-weight: 500; font-size: 14.5px; }
.file .f-meta { color: var(--text-faint); font-size: 12px; margin-top: 2px; }
.file .f-arrow { color: var(--text-faint); font-size: 16px; transition: color .15s ease, transform .15s ease; }
.file:hover .f-arrow { color: var(--primary); transform: translateX(2px); }
.filelist-note { color: var(--text-faint); font-size: 13px; margin: 4px 2px 14px; display: flex; gap: 6px; align-items: center; }

/* ---------- corkboard ---------- */
#cork {
  display: flex; flex-wrap: wrap; gap: 16px;
  padding: 8px 0 20px;
}
.note {
  width: 216px; min-height: 150px;
  background: #fff8e1;
  border: 1px solid #f0e2a8;
  border-radius: 4px;
  padding: 16px 16px 12px;
  cursor: grab;
  position: relative;
  box-shadow: var(--shadow-sm);
  transition: box-shadow .15s ease, transform .15s ease;
}
.note::before {
  content: "";
  position: absolute; top: 0; left: 50%;
  transform: translateX(-50%);
  width: 54px; height: 14px;
  background: rgba(180, 150, 60, 0.18);
  border-radius: 0 0 6px 6px;
}
.note.dragging { opacity: .45; cursor: grabbing; transform: rotate(1deg); }
.note:hover { box-shadow: var(--shadow-md); }
.note .nt { font-weight: 600; font-size: 14px; margin: 8px 0 6px; color: #3e3a20; }
.note .nn { color: #6b643f; font-size: 12.5px; line-height: 1.5; display: -webkit-box; -webkit-line-clamp: 5; -webkit-box-orient: vertical; overflow: hidden; }
.note .nd { margin-top: 10px; font-size: 11px; color: #a3965c; }

/* ---------- editor ---------- */
#editor { display: flex; flex-direction: column; height: calc(100vh - 150px); min-height: 420px; }
#editor .etitle { font-size: 18px; font-weight: 600; margin-bottom: 10px; word-break: break-word; }
#editor textarea {
  flex: 1;
  resize: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px 28px;
  font-family: var(--serif);
  font-size: 16px;
  line-height: 1.75;
  color: var(--text);
}
#editor .ebar { display: flex; align-items: center; gap: 12px; padding: 12px 2px 0; }

/* ---------- capture ---------- */
.capture-card {
  margin-top: 26px;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
}
.capture-card .cap-label {
  font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--text-muted); margin-bottom: 10px;
  display: flex; align-items: center; gap: 6px;
}
#capturebar { display: flex; gap: 10px; align-items: stretch; }
#capturebar input { flex: 1; background: var(--surface); min-height: 44px; }
#capturebar button { min-height: 44px; padding: 0 22px; white-space: nowrap; }
.cap-hint { color: var(--text-faint); font-size: 12.5px; margin-top: 10px; }

/* ---------- toast ---------- */
#toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  z-index: 99;
  padding: 12px 22px;
  border-radius: 999px;
  background: #202124;
  color: #fff;
  font-size: 14px;
  box-shadow: var(--shadow-lg);
  display: none;
  max-width: 480px;
  text-align: center;
}
#toast.show { display: block; animation: toastin .18s ease; }
#toast.ok { background: #202124; }
#toast.err { background: #b3261e; }
@keyframes toastin { from { opacity: 0; transform: translate(-50%, 8px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* ---------- empty states ---------- */
.empty {
  color: var(--text-muted);
  padding: 60px 20px;
  text-align: center;
  background: var(--bg-soft);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  margin-top: 8px;
}
.empty .e-ico { font-size: 34px; margin-bottom: 10px; opacity: .6; }
.empty .e-title { font-weight: 600; font-size: 15px; margin-bottom: 4px; color: var(--text-secondary); }
.empty .e-sub { font-size: 13px; color: var(--text-faint); }

.hidden { display: none; }