* { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --bg: #ded9d0;
  --ink: #2a2d3a;
  --muted: #8a8f9c;
  --line: #e6e4dd;
  --accent: #4f6df5;
  --danger: #d64545;
  --paper: #fdfcf7;
  --rule: #c9d6e8;
  --margin-line: #f0b9b9;
  --cover: #17181c;
  --line-h: 36px;
  --hand: 'Patrick Hand', 'Segoe Print', cursive;
}
html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: radial-gradient(ellipse at 50% 30%, #eae6de 0%, var(--bg) 70%);
  color: var(--ink);
  overflow: hidden;
}
.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 13px; }
.error { color: var(--danger); font-size: 13px; margin-top: 8px; }

/* ---------- Login ---------- */
#login-screen {
  position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  font-family: 'Inter', -apple-system, sans-serif; overflow: hidden;
}
.login-bg {
  position: absolute; inset: 0;
  background: #101219;
}
.login-bg::before {
  content: ''; position: absolute; inset: -40%;
  background:
    radial-gradient(circle at 22% 28%, rgba(79,109,245,.32) 0%, transparent 42%),
    radial-gradient(circle at 78% 22%, rgba(232,52,126,.2) 0%, transparent 40%),
    radial-gradient(circle at 68% 82%, rgba(39,192,232,.18) 0%, transparent 45%),
    radial-gradient(circle at 28% 78%, rgba(155,107,242,.2) 0%, transparent 40%);
  animation: drift 22s ease-in-out infinite alternate;
}
@keyframes drift {
  from { transform: translate(-2%, -2%) scale(1); }
  to { transform: translate(2%, 3%) scale(1.07); }
}
.login-shell {
  position: relative; z-index: 1; display: flex; width: min(860px, 92vw);
  border-radius: 22px; overflow: hidden;
  box-shadow: 0 40px 90px rgba(0,0,0,.55), 0 0 0 1px rgba(255,255,255,.06);
  backdrop-filter: blur(18px);
}
.login-brand {
  flex: 1.05; padding: 56px 48px; color: #eceef4;
  background: linear-gradient(150deg, rgba(30,33,46,.92), rgba(16,18,25,.94));
  display: flex; flex-direction: column; justify-content: center; position: relative;
}
.lb-mark { display: flex; gap: 7px; margin-bottom: 26px; }
.lb-ring {
  width: 26px; height: 12px; border-radius: 7px; display: inline-block;
  border: 2.5px solid #8f97ad; background: linear-gradient(180deg,#c9cdd8,#7f8699);
}
.login-brand h1 {
  font-family: 'Caveat', cursive; font-size: 58px; line-height: 1; margin-bottom: 14px;
  background: linear-gradient(92deg, #fff, #aab6ff);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.lb-tag { color: #8d94a8; font-size: 15px; line-height: 1.65; }
.lb-tabs { display: flex; gap: 8px; margin-top: 38px; }
.lb-tabs span { width: 34px; height: 9px; border-radius: 5px; opacity: .85; }
.lb-tabs span:nth-child(1) { background: #f5d90a; }
.lb-tabs span:nth-child(2) { background: #f5820a; }
.lb-tabs span:nth-child(3) { background: #e8347e; }
.lb-tabs span:nth-child(4) { background: #27c0e8; }
.lb-tabs span:nth-child(5) { background: #9b6bf2; }
.login-card {
  flex: 1; padding: 56px 46px; background: rgba(250,250,252,.98);
}
.login-card h2 { font-size: 24px; font-weight: 700; letter-spacing: -.3px; }
.lc-sub { color: var(--muted); font-size: 13.5px; margin: 6px 0 26px; }
.lc-label {
  display: block; font-size: 11.5px; font-weight: 600; text-transform: uppercase;
  letter-spacing: .8px; color: #7a8095; margin: 16px 0 6px;
}
.login-card input {
  width: 100%; padding: 12px 14px; font-size: 15px; font-family: inherit;
  border: 1.5px solid #e2e3ea; border-radius: 10px; background: #fff;
  transition: border-color .15s, box-shadow .15s;
}
.login-card input:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3.5px rgba(79,109,245,.16);
}
.lc-btn {
  width: 100%; margin-top: 26px; padding: 13px; font-size: 15px; font-weight: 600;
  font-family: inherit; color: #fff; border: none; border-radius: 10px; cursor: pointer;
  background: linear-gradient(135deg, #5b78ff, #4356e0);
  box-shadow: 0 8px 20px rgba(79,109,245,.35);
  transition: transform .12s, box-shadow .12s, filter .12s;
}
.lc-btn:hover { transform: translateY(-1px); filter: brightness(1.06); box-shadow: 0 11px 24px rgba(79,109,245,.42); }
.lc-btn:active { transform: translateY(0); }
@media (max-width: 700px) {
  .login-shell { flex-direction: column; width: min(420px, 94vw); }
  .login-brand { padding: 36px 34px 28px; }
  .login-brand h1 { font-size: 44px; }
  .lb-tabs { margin-top: 20px; }
  .login-card { padding: 34px; }
}

/* ---------- Buttons ---------- */
.btn {
  border: 1px solid var(--line); background: #fff; color: var(--ink);
  padding: 8px 14px; border-radius: 8px; font-size: 13.5px; cursor: pointer;
}
.btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn.primary:hover { filter: brightness(1.07); }
.btn.danger { color: var(--danger); border-color: #f0caca; }
.btn.small { padding: 5px 10px; font-size: 12.5px; }
.btn.full { width: 100%; }
.ghost-btn {
  background: none; border: none; cursor: pointer; color: var(--muted);
  font-size: 13px; padding: 2px 5px; border-radius: 5px; opacity: .55;
}
.ghost-btn:hover { opacity: 1; background: rgba(0,0,0,.06); }

/* ---------- Layout ---------- */
#app { height: 100vh; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 22px;
}
.tb-spacer { flex: 1; }
.nb-switch { display: flex; gap: 6px; align-items: center; }
#nb-select {
  padding: 6px 10px; border: 1px solid #cdc9bd; border-radius: 8px;
  background: #fff; font-size: 13px; font-weight: 600; color: var(--ink);
  max-width: 220px; cursor: pointer;
}
.cover-edit { color: #7d8394; font-size: 17px; vertical-align: middle; margin-left: 6px; }
.cover-edit:hover { background: rgba(255,255,255,.12); color: #fff; }
.tab.assigned-tab { background: linear-gradient(180deg, #3a4056, #2b2f3d); }
.tab.assigned-tab .tab-label { color: #dfe4f5; }
.assigned-src {
  font-size: 11px; font-family: 'Inter', -apple-system, sans-serif;
  color: var(--muted); white-space: nowrap;
}
.book-wrap {
  flex: 1; display: flex; justify-content: center; align-items: center;
  padding: 0 60px 26px; min-height: 0;
}

/* ---------- Book ---------- */
.book {
  position: relative; width: min(860px, 100%); height: 100%; max-height: 92vh;
  display: flex;
  filter: drop-shadow(0 24px 30px rgba(0,0,0,.35));
}
.spiral {
  width: 40px; flex-shrink: 0; display: flex; flex-direction: column;
  justify-content: space-evenly; align-items: center; z-index: 5;
  margin-right: -20px;
}
.ring {
  width: 34px; height: 14px; border: 3px solid #b9bec9;
  border-radius: 8px; background: linear-gradient(180deg,#f2f4f8,#c9cdd6);
  box-shadow: inset 0 1px 2px rgba(255,255,255,.8), 0 2px 3px rgba(0,0,0,.35);
}

.sheet {
  position: relative; flex: 1; border-radius: 6px 16px 16px 6px;
  overflow: hidden; display: flex; flex-direction: column;
  background: var(--paper);
  border: 1px solid #d8d4c8;
}

/* ---------- Cover ---------- */
.cover {
  position: absolute; inset: 0; background:
    radial-gradient(ellipse at 30% 20%, #26282f 0%, var(--cover) 60%);
  color: #eceef4; display: flex; z-index: 2;
}
.cover-inner {
  flex: 1; display: flex; flex-direction: column; align-items: center;
  justify-content: center; padding: 40px 60px; text-align: center;
}
.cover-band {
  width: 120px; height: 6px; border-radius: 3px; margin-bottom: 22px;
  background: linear-gradient(90deg,#f5d90a,#f5820a,#e8347e,#27c0e8,#9b6bf2);
}
.cover-title {
  font-family: 'Caveat', var(--hand);
  font-size: 64px; letter-spacing: 1px; margin-bottom: 4px;
}
.cover-sub { color: #9aa0b0; font-size: 14px; margin-bottom: 26px; }
.toc { width: 100%; max-width: 420px; max-height: 42vh; overflow-y: auto; text-align: left; }
.toc-row {
  display: flex; align-items: center; gap: 10px; padding: 9px 12px;
  border-radius: 8px; cursor: pointer; font-size: 15px; color: #d6d9e2;
}
.toc-row:hover { background: rgba(255,255,255,.08); }
.toc-dot { width: 12px; height: 12px; border-radius: 3px; flex-shrink: 0; }
.toc-row .toc-count { margin-left: auto; font-size: 12px; color: #7d8394; }
.cover-hint { margin-top: 26px; font-size: 13px; color: #6d7383; }

/* ---------- Paper page ---------- */
.paper {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  background: var(--paper); z-index: 1; padding-bottom: 54px;
}
.paper-head {
  padding: 20px 34px 8px 58px; display: flex; align-items: baseline;
  justify-content: space-between; gap: 10px; flex-shrink: 0;
}
.crumb {
  font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: 1px;
}
.page-name-wrap { display: flex; align-items: center; gap: 4px; }
.page-name { font-family: var(--hand); font-size: 26px; color: #33405e; }

.lines-area {
  flex: 1; overflow-y: auto; min-height: 0;
  background:
    linear-gradient(to right, transparent 44px, var(--margin-line) 44px, var(--margin-line) 46px, transparent 46px),
    repeating-linear-gradient(to bottom, transparent 0, transparent calc(var(--line-h) - 1px), var(--rule) calc(var(--line-h) - 1px), var(--rule) var(--line-h));
  padding: 0 34px 0 58px;
}
#task-list { list-style: none; }
.task-line {
  min-height: var(--line-h); display: flex; align-items: flex-start; gap: 10px;
  font-family: var(--hand); font-size: 19px;
}
.task-line.clickable { cursor: pointer; }
.task-line.clickable:hover .title { color: var(--accent); }
.task-line input[type="checkbox"] {
  width: 17px; height: 17px; accent-color: var(--accent); cursor: pointer; flex-shrink: 0;
  margin-top: calc((var(--line-h) - 17px) / 2);
}
.task-line .title {
  flex: 1; min-width: 0; overflow-wrap: break-word;
  color: #2c3550; line-height: var(--line-h);
}
.task-line .badge, .task-line .t-btn { margin-top: calc((var(--line-h) - 22px) / 2); }
.task-line .notes-hint { font-size: 14px; opacity: .6; }
.task-line.done .title { text-decoration: line-through; color: #9aa2b5; }
.badge {
  font-size: 11px; font-family: -apple-system, sans-serif;
  padding: 2px 8px; border-radius: 20px; background: #e9edfd; color: var(--accent);
  white-space: nowrap;
}
.badge.hidden-badge { background: #fdeaea; color: var(--danger); }
.badge.due-badge { background: #f0ede4; color: #7a7460; }
.badge.due-badge.overdue { background: #fdeaea; color: var(--danger); font-weight: 700; }
.status-chip {
  font-size: 11px; font-family: -apple-system, sans-serif; font-weight: 700;
  padding: 3px 9px; border-radius: 20px; border: none; cursor: pointer;
  white-space: nowrap; flex-shrink: 0;
  margin-top: calc((var(--line-h) - 22px) / 2);
}
.status-chip.st-pending { background: #e7e9f0; color: #6a7185; }
.status-chip.st-onit { background: #fff0cc; color: #a5720a; }
.status-chip.st-done { background: #d9f2e0; color: #1e8f4d; }
.status-chip:hover { filter: brightness(.95); }
.t-btn {
  background: none; border: none; cursor: pointer; font-size: 13px;
  color: var(--muted); padding: 3px 5px; border-radius: 5px; opacity: 0;
}
.task-line:hover .t-btn { opacity: .8; }
.t-btn:hover { opacity: 1 !important; background: rgba(0,0,0,.06); }

.add-line { height: var(--line-h); align-items: center; }
.add-line .add-mark { color: var(--muted); font-size: 16px; width: 17px; text-align: center; }
.add-line input {
  flex: 1; border: none; background: transparent; outline: none;
  font-family: var(--hand); font-size: 19px; color: #2c3550;
}
.add-line input::placeholder { color: #b5bccb; }
.add-line select {
  border: 1px solid var(--line); background: #fff; border-radius: 6px;
  font-size: 12px; padding: 3px 6px; color: var(--muted); max-width: 130px;
}

.empty-chapter {
  flex: 1; display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 10px; text-align: center;
}
.empty-chapter h2 { font-family: var(--hand); font-size: 34px; color: #33405e; }

/* ---------- Bottom nav ---------- */
.page-nav {
  position: absolute; bottom: 0; left: 0; right: 0; height: 48px;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  background: rgba(250,249,243,.92); border-top: 1px solid #e8e4d8;
  backdrop-filter: blur(4px); z-index: 6;
}
.nav-btn {
  border: 1px solid #ddd9cc; background: #fff; color: #4a5168;
  min-width: 38px; height: 32px; border-radius: 8px; cursor: pointer; font-size: 14px;
}
.nav-btn:hover:not(:disabled) { background: #f2f0e8; }
.nav-btn:disabled { opacity: .35; cursor: default; }
.nav-btn.wide { padding: 0 12px; }
.nav-label { font-size: 13px; color: var(--muted); min-width: 150px; text-align: center; }

/* ---------- Chapter tabs ---------- */
.tabs {
  position: absolute; right: -46px; top: 34px; bottom: 60px;
  display: flex; flex-direction: column; gap: 10px; width: 46px; z-index: 4;
  overflow: visible;
}
.tab {
  width: 46px; flex: 0 1 74px; min-height: 40px; max-height: 74px;
  border-radius: 0 10px 10px 0; cursor: pointer; position: relative;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 2px 3px 6px rgba(0,0,0,.28);
  transition: transform .15s ease;
  border: none; padding: 0;
}
.tab:hover { transform: translateX(4px); }
.tab.active { transform: translateX(6px); box-shadow: 3px 4px 9px rgba(0,0,0,.35); }
.tab .tab-label {
  writing-mode: vertical-rl; font-size: 12px; font-weight: 700; color: rgba(0,0,0,.65);
  max-height: 62px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  pointer-events: none; letter-spacing: .5px;
}
.tab.light .tab-label { color: rgba(255,255,255,.92); }
.tab.add-tab {
  background: #efece2; border: 1px dashed #b9b4a4; box-shadow: none;
  color: #8a8574; font-size: 17px; flex: 0 0 40px;
}
.tab.add-tab:hover { background: #e7e3d5; }

/* ---------- Modal ---------- */
#modal-backdrop {
  position: fixed; inset: 0; background: rgba(20,22,30,.45);
  display: flex; align-items: center; justify-content: center; z-index: 50;
}
.modal {
  background: #fff; border-radius: 14px; padding: 24px;
  width: 440px; max-width: 92vw; max-height: 84vh; overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,.25);
}
.modal h3 { margin-bottom: 16px; }
.modal label { display: block; font-size: 12.5px; color: var(--muted); margin: 12px 0 4px; }
.modal input, .modal select, .modal textarea {
  width: 100%; padding: 9px 11px; border: 1px solid var(--line);
  border-radius: 8px; font-size: 14px;
}
.modal textarea { resize: vertical; min-height: 70px; }
.modal .row { display: flex; gap: 8px; justify-content: flex-end; margin-top: 20px; }
.check-row { display: flex; align-items: center; gap: 8px; padding: 6px 0; font-size: 14px; }
.check-row input { width: auto; }
.user-row {
  display: flex; align-items: center; gap: 8px; padding: 8px 0;
  border-bottom: 1px solid var(--line); font-size: 14px;
}
.user-row .u-name { flex: 1; }
.user-row .u-role { font-size: 11px; color: var(--muted); }

/* ---------- Mobile ---------- */
@media (max-width: 760px) {
  .book-wrap { padding: 0 8px 60px 4px; }
  .tabs { right: -38px; width: 38px; }
  .tab { width: 38px; }
  .cover-title { font-size: 44px; }
  .cover-inner { padding: 24px; }
  .paper-head { padding: 14px 16px 6px 40px; }
  .lines-area { padding: 0 16px 0 40px; }
  .spiral { width: 26px; margin-right: -13px; }
  .ring { width: 22px; height: 11px; }
  body { overflow: auto; }
}
