/* ============ tokens ============ */
:root{
  --bg:#F5EDE1;
  --surface:#FBF5EC;
  --surface-2:#F0E5D6;
  --paper:#FBF5EC;
  --border:#E3D4C1;
  --ink:#3B2E27;
  --muted:#7A675C;
  --track:#EADCC9;
  --accent:#B3643F;
  --olive:#7B8555;
  --rose:#D9A79E;
  --danger:#A9453A;
  --nav-bg:rgba(251,245,236,.94);
  --shadow:0 8px 24px rgba(139,111,90,.09);
  --shadow-lg:0 18px 44px rgba(139,111,90,.18);
  --r-sm:12px; --r-md:18px; --r-lg:24px;
  --ui:'IBM Plex Sans Arabic',system-ui,-apple-system,'Segoe UI',sans-serif;
  --serif:'Amiri','Noto Naskh Arabic',serif;
}
[data-accent="olive"]{ --accent:#7B8555; --rose:#C9B58B; }
[data-accent="clay"]{ --accent:#B87C72; --rose:#D9A79E; }

[data-theme="dark"]{
  --bg:#241C18;
  --surface:#2E241F;
  --surface-2:#382C26;
  --paper:#2A211C;
  --border:#3E322B;
  --ink:#EADFD3;
  --muted:#B9A697;
  --track:#3B2F28;
  --nav-bg:rgba(46,36,31,.95);
  --danger:#E08A7B;
  --shadow:0 8px 24px rgba(0,0,0,.34);
  --shadow-lg:0 18px 44px rgba(0,0,0,.5);
}
[data-theme="dark"][data-accent="terracotta"]{ --accent:#D0824F; --rose:#C89A8E; }
[data-theme="dark"][data-accent="olive"]{ --accent:#9CA873; --rose:#C2B08A; }
[data-theme="dark"][data-accent="clay"]{ --accent:#D09A90; --rose:#C89A8E; }

/* ============ base ============ */
*,*::before,*::after{ box-sizing:border-box; }
html{ -webkit-text-size-adjust:100%; }
html,body{ margin:0; padding:0; }
body{
  font-family:var(--ui);
  background:var(--bg);
  color:var(--ink);
  min-height:100dvh;
  -webkit-font-smoothing:antialiased;
  overscroll-behavior-y:none;
  line-height:1.55;
}
body::after{
  content:"";
  position:fixed; inset:0; z-index:70; pointer-events:none;
  opacity:.035;
  background-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3'/%3E%3C/filter%3E%3Crect width='140' height='140' filter='url(%23n)'/%3E%3C/svg%3E");
}
[data-theme="dark"] body::after{ opacity:.06; }
h1,h2,h3,h4,p{ margin:0; }
button{ font:inherit; color:inherit; }
input,textarea,select{ font:inherit; color:inherit; }
img{ display:block; max-width:100%; }
.hidden{ display:none !important; }
.no-scroll{ overflow:hidden; }
.grow{ flex:1; }
.pad{ padding:0 18px 28px; }
::selection{ background:rgba(179,100,63,.22); }

/* ============ generic controls ============ */
.btn{
  display:inline-flex; align-items:center; justify-content:center; gap:8px;
  min-height:46px; padding:0 18px;
  border-radius:var(--r-sm); border:1px solid var(--border);
  background:var(--surface); color:var(--ink);
  font-weight:500; font-size:15px;
  cursor:pointer; -webkit-user-select:none; user-select:none;
  transition:transform .12s ease, background .18s ease, border-color .18s ease, opacity .18s;
  touch-action:manipulation;
}
.btn:active{ transform:scale(.975); }
.btn:focus-visible{ outline:2px solid var(--accent); outline-offset:2px; }
.btn.sm{ min-height:40px; padding:0 14px; font-size:14px; border-radius:11px; }
.btn svg{ width:18px; height:18px; flex:none; }
.btn-primary{
  background:var(--accent); color:#fff; border-color:transparent;
  box-shadow:0 8px 18px -8px rgba(179,100,63,.65);
}
[data-theme="dark"] .btn-primary{ color:#20160F; }
.btn-danger{ background:transparent; color:var(--danger); border-color:var(--danger); width:100%; margin-top:10px; }
.btn-ghost{ background:transparent; border-color:transparent; }
.btn:disabled{ opacity:.5; pointer-events:none; }

.icon-btn{
  width:44px; height:44px; flex:none;
  display:grid; place-items:center;
  border-radius:13px; border:1px solid var(--border);
  background:var(--surface); color:var(--ink);
  cursor:pointer; -webkit-user-select:none; user-select:none;
  transition:transform .12s ease, background .18s;
  touch-action:manipulation;
}
.icon-btn:active{ transform:scale(.94); }
.icon-btn:focus-visible{ outline:2px solid var(--accent); outline-offset:2px; }
.icon-btn svg{ width:20px; height:20px; }
.icon-btn.ghost{ border-color:transparent; background:transparent; }
.icon-btn.sm{ width:38px; height:38px; border-radius:11px; }
.icon-btn.sm svg{ width:18px; height:18px; }

.link-btn{
  background:none; border:0; padding:10px 6px; margin-top:4px;
  color:var(--muted); font-size:14px; cursor:pointer; text-decoration:underline;
  text-underline-offset:3px; text-decoration-thickness:1px;
}
.link-btn:active{ opacity:.6; }

.chip{
  display:inline-flex; align-items:center; gap:4px;
  font-size:11.5px; line-height:1; padding:6px 10px; border-radius:99px;
  background:rgba(217,167,158,.28); color:var(--ink);
  border:1px solid rgba(179,100,63,.18);
  white-space:nowrap;
}
.chip--light{ background:rgba(255,255,255,.82); color:#3B2E27; border-color:rgba(255,255,255,.6); }

.bar{ height:7px; border-radius:99px; background:var(--track); overflow:hidden; }
.bar i{
  display:block; height:100%; width:0%;
  border-radius:99px;
  background:linear-gradient(to left, var(--accent), var(--rose));
  transition:width .45s cubic-bezier(.22,.8,.3,1);
}
.bar.sm{ height:5px; }
.bar.xs{ height:5px; }

/* ============ layout ============ */
.app{ padding-bottom:96px; min-height:100dvh; }
.app-head{
  display:flex; align-items:flex-start; justify-content:space-between;
  gap:12px; padding:22px 18px 10px;
}
.eyebrow{ font-size:12px; color:var(--muted); letter-spacing:.01em; }
.page-title{
  font-family:var(--serif); font-weight:700; font-size:31px; line-height:1.25;
  margin-top:2px; letter-spacing:0;
}
.head-actions{ display:flex; gap:8px; }

/* ============ goal card ============ */
.goal-card{
  margin:6px 18px 20px; padding:16px 18px 15px;
  background:var(--surface); border:1px solid var(--border);
  border-radius:var(--r-md); box-shadow:var(--shadow);
}
.goal-card.done{ border-color:rgba(123,133,85,.5); }
.goal-row{ display:flex; align-items:flex-end; justify-content:space-between; gap:12px; margin-bottom:11px; }
.goal-label{ font-size:12.5px; color:var(--muted); }
.goal-num{ font-family:var(--serif); font-size:24px; font-weight:700; line-height:1.2; margin-top:2px; }
.goal-num span{ font-family:var(--ui); font-size:13px; font-weight:400; color:var(--muted); }
.goal-pct{ font-family:var(--serif); font-size:19px; color:var(--accent); font-weight:700; }
.goal-note{ font-size:12.5px; color:var(--muted); margin-top:10px; line-height:1.6; }

/* ============ shelf ============ */
.shelf{ display:flex; flex-direction:column; gap:12px; padding:0 18px; }
.novel-card{
  display:flex; gap:14px; align-items:stretch;
  padding:12px; background:var(--surface);
  border:1px solid var(--border); border-radius:var(--r-md);
  box-shadow:var(--shadow); cursor:pointer;
  transition:transform .16s ease, box-shadow .16s ease;
  -webkit-user-select:none; user-select:none;
}
.novel-card:active{ transform:scale(.985); }
.novel-card:focus-visible{ outline:2px solid var(--accent); outline-offset:2px; }
.cover{
  width:74px; height:102px; flex:none; border-radius:10px;
  object-fit:cover; overflow:hidden; position:relative;
  box-shadow:0 6px 14px -6px rgba(59,46,39,.55), inset 0 0 0 1px rgba(255,255,255,.16);
  background:var(--surface-2);
}
.cover--gen{
  display:grid; place-items:center;
  background:linear-gradient(160deg, var(--c,#B3643F), color-mix(in srgb, var(--c,#B3643F) 62%, #3B2E27));
  color:#fff; font-family:var(--serif); font-size:36px; font-weight:700;
  text-shadow:0 2px 10px rgba(0,0,0,.22);
}
.cover--gen::before{
  content:""; position:absolute; inset-inline-start:0; top:0; bottom:0; width:7px;
  background:rgba(0,0,0,.16);
}
.novel-info{ flex:1; min-width:0; display:flex; flex-direction:column; justify-content:center; gap:3px; }
.novel-top{ display:flex; align-items:center; justify-content:space-between; gap:8px; }
.novel-title{
  font-family:var(--serif); font-size:19px; font-weight:700; line-height:1.35;
  overflow:hidden; text-overflow:ellipsis; white-space:nowrap; min-width:0;
}
.novel-meta{ font-size:12.5px; color:var(--muted); }
.novel-meta.muted{ opacity:.85; }
.novel-info .bar{ margin-top:7px; }

.fab{
  position:fixed; inset-inline-start:20px; bottom:92px; z-index:35;
  width:56px; height:56px; border-radius:50%;
  border:0; background:var(--accent); color:#fff;
  display:grid; place-items:center; cursor:pointer;
  box-shadow:0 14px 28px -10px rgba(179,100,63,.85);
  transition:transform .16s ease;
}
[data-theme="dark"] .fab{ color:#20160F; }
.fab:active{ transform:scale(.92); }
.fab svg{ width:26px; height:26px; }

/* ============ empty states ============ */
.empty-state{
  text-align:center; padding:38px 22px;
  border:1px dashed var(--border); border-radius:var(--r-md);
  background:var(--surface); color:var(--muted);
  display:flex; flex-direction:column; align-items:center; gap:10px;
}
.empty-mark{
  width:56px; height:56px; border-radius:50%; display:grid; place-items:center;
  background:rgba(217,167,158,.26); color:var(--accent);
}
.empty-mark svg{ width:26px; height:26px; }
.empty-state h3{ font-family:var(--serif); font-size:20px; color:var(--ink); }
.empty-state p{ font-size:13.5px; line-height:1.7; max-width:30ch; }

/* ============ novel view ============ */
.novel-head{ display:flex; align-items:center; justify-content:space-between; padding:16px 18px 10px; }
.novel-head-actions{ display:flex; gap:8px; }
.novel-banner{
  position:relative; margin:4px 18px 0; height:168px;
  border-radius:var(--r-lg); overflow:hidden;
  box-shadow:var(--shadow); background:var(--surface-2);
}
.banner-img{ width:100%; height:100%; object-fit:cover; }
.banner-gen{ width:100%; height:100%; background:linear-gradient(150deg, var(--c,#B3643F), color-mix(in srgb, var(--c,#B3643F) 45%, #241C18)); }
.banner-scrim{ position:absolute; inset:0; background:linear-gradient(to top, rgba(28,20,16,.82) 4%, rgba(28,20,16,.18) 48%, rgba(28,20,16,0) 78%); }
.banner-text{ position:absolute; inset-inline:16px; bottom:14px; display:flex; flex-direction:column; gap:7px; align-items:flex-start; }
.banner-title{
  font-family:var(--serif); font-size:27px; font-weight:700; color:#fff; line-height:1.3;
  text-shadow:0 2px 14px rgba(0,0,0,.5); letter-spacing:0;
}
.synopsis{ font-size:14px; line-height:1.8; color:var(--muted); margin:14px 0 4px; }
.stat-row{ display:grid; grid-template-columns:repeat(3,1fr); gap:8px; margin:14px 0 12px; }
.stat{
  background:var(--surface); border:1px solid var(--border); border-radius:var(--r-sm);
  padding:10px 6px; text-align:center;
}
.stat b{ display:block; font-family:var(--serif); font-size:19px; line-height:1.2; }
.stat span{ font-size:11.5px; color:var(--muted); }
.quick-row{ display:grid; grid-template-columns:1fr 1fr; gap:10px; margin:16px 0 22px; }
.section-head{ display:flex; align-items:center; justify-content:space-between; margin:22px 0 12px; }
.section-head h2{ font-family:var(--serif); font-size:21px; font-weight:700; }
.search-box{
  display:flex; align-items:center; gap:8px;
  background:var(--surface); border:1px solid var(--border);
  border-radius:var(--r-sm); padding:0 12px; min-height:46px; margin-bottom:10px;
  color:var(--muted);
}
.search-box svg{ width:18px; height:18px; flex:none; }
.search-box input{
  flex:1; min-width:0; border:0; background:transparent; outline:none;
  font-size:15px; padding:12px 0; color:var(--ink);
}
.search-status{ font-size:12px; color:var(--muted); margin:0 2px 10px; min-height:0; }

.chapter-list{ display:flex; flex-direction:column; gap:8px; }
.chapter-row{
  display:flex; align-items:center; gap:4px;
  background:var(--surface); border:1px solid var(--border);
  border-radius:var(--r-sm); padding:4px 6px 4px 2px;
  transition:transform .18s ease, box-shadow .18s ease, opacity .18s;
  will-change:transform;
}
.chapter-row.dragging{ z-index:5; box-shadow:var(--shadow-lg); opacity:.97; }
.drag-handle{
  width:34px; height:44px; flex:none; border:0; background:transparent;
  color:var(--muted); display:grid; place-items:center; cursor:grab;
  touch-action:none; border-radius:9px; opacity:.7;
}
.drag-handle:active{ cursor:grabbing; opacity:1; }
.drag-handle svg{ width:18px; height:18px; }
.chapter-main{
  flex:1; min-width:0; display:flex; align-items:center; gap:11px;
  border:0; background:transparent; text-align:start; padding:9px 4px; cursor:pointer;
}
.chapter-num{
  width:28px; height:28px; flex:none; border-radius:50%;
  display:grid; place-items:center; font-size:12.5px; font-weight:600;
  background:rgba(217,167,158,.26); color:var(--accent);
}
.chapter-txt{ min-width:0; display:flex; flex-direction:column; gap:2px; }
.chapter-txt b{ font-family:var(--serif); font-size:16.5px; font-weight:700; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.chapter-txt small{ font-size:11.5px; color:var(--muted); }

/* ============ notebook ============ */
.nb-head{ padding:22px 18px 6px; }
.nb-title{ font-family:var(--serif); font-size:26px; font-weight:700; margin-top:2px; }
.tabs{
  display:flex; gap:6px; overflow-x:auto; padding:12px 18px 4px;
  scrollbar-width:none; -webkit-overflow-scrolling:touch;
}
.tabs::-webkit-scrollbar{ display:none; }
.tab{
  flex:none; min-height:40px; padding:0 15px; border-radius:99px;
  border:1px solid var(--border); background:var(--surface);
  font-size:13.5px; cursor:pointer; color:var(--muted);
  transition:background .18s, color .18s, border-color .18s;
}
.tab.on{ background:var(--accent); color:#fff; border-color:transparent; }
[data-theme="dark"] .tab.on{ color:#20160F; }
.nb-list{ display:flex; flex-direction:column; gap:10px; padding:14px 18px 28px; }

.ncard{
  display:flex; gap:12px; align-items:flex-start; width:100%; text-align:start;
  background:var(--surface); border:1px solid var(--border);
  border-radius:var(--r-md); padding:13px; cursor:pointer;
  box-shadow:var(--shadow); transition:transform .16s ease;
}
.ncard:active{ transform:scale(.985); }
.avatar{
  width:50px; height:50px; flex:none; border-radius:14px; overflow:hidden;
  display:grid; place-items:center;
  background:linear-gradient(150deg, rgba(217,167,158,.6), rgba(179,100,63,.35));
  color:#fff; font-family:var(--serif); font-size:22px; font-weight:700;
}
.avatar img{ width:100%; height:100%; object-fit:cover; }
.ncard-body{ flex:1; min-width:0; display:flex; flex-direction:column; gap:3px; }
.ncard-body b{ font-family:var(--serif); font-size:17px; font-weight:700; }
.ncard-body small{ font-size:12.5px; color:var(--muted); overflow:hidden; text-overflow:ellipsis; }
.ncard-note{ font-size:13px; color:var(--muted); font-style:normal; line-height:1.6; margin-top:4px; }
.thumb{
  width:56px; height:56px; border-radius:12px; object-fit:cover; flex:none;
  background:var(--surface-2); border:1px solid var(--border);
}

.event-list{ position:relative; display:flex; flex-direction:column; gap:10px; padding:14px 18px 28px; }
.event-item{ display:flex; align-items:flex-start; gap:2px; border-radius:var(--r-md); transition:transform .18s ease, opacity .18s; will-change:transform; }
.event-item.dragging{ z-index:5; box-shadow:var(--shadow-lg); }
.event-rail{ width:26px; flex:none; display:flex; flex-direction:column; align-items:center; padding-top:18px; }
.event-dot{ width:11px; height:11px; border-radius:50%; background:var(--accent); box-shadow:0 0 0 4px rgba(179,100,63,.16); }
.event-card{
  flex:1; min-width:0; text-align:start; cursor:pointer;
  background:var(--surface); border:1px solid var(--border);
  border-radius:var(--r-md); padding:12px 14px; box-shadow:var(--shadow);
}
.event-card b{ display:block; font-family:var(--serif); font-size:16.5px; }
.event-card small{ display:block; font-size:11.5px; color:var(--accent); margin-top:2px; }
.event-card p{ font-size:13px; color:var(--muted); line-height:1.65; margin-top:5px; }

.idea-card{
  position:relative; background:var(--surface); border:1px solid var(--border);
  border-radius:var(--r-md); padding:14px 16px; box-shadow:var(--shadow);
  border-inline-start:3px solid var(--rose);
}
.idea-card p{ font-size:14.5px; line-height:1.75; white-space:pre-wrap; word-break:break-word; }
.idea-card .idea-date{ font-size:11px; color:var(--muted); margin-top:8px; }

/* ============ publish ============ */
.pub-card{
  background:var(--surface); border:1px solid var(--border);
  border-radius:var(--r-md); padding:16px; box-shadow:var(--shadow); margin-bottom:12px;
}
.pub-card h3{ font-family:var(--serif); font-size:18px; margin-bottom:6px; }
.pub-card p{ font-size:13px; color:var(--muted); line-height:1.7; }
.pub-checks{ display:flex; flex-direction:column; gap:6px; margin-top:10px; }
.pub-check{
  display:flex; align-items:center; gap:10px; width:100%; text-align:start;
  padding:10px 12px; border-radius:11px; border:1px solid var(--border);
  background:transparent; cursor:pointer; font-size:14px;
}
.pub-check .box{
  width:20px; height:20px; flex:none; border-radius:6px; border:1.5px solid var(--border);
  display:grid; place-items:center; color:#fff;
}
.pub-check.on .box{ background:var(--accent); border-color:var(--accent); }
.pub-check .box svg{ width:13px; height:13px; opacity:0; }
.pub-check.on .box svg{ opacity:1; }
.pub-check span.t{ flex:1; min-width:0; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.pub-check small{ font-size:11.5px; color:var(--muted); }

/* ============ settings ============ */
.set-group{
  background:var(--surface); border:1px solid var(--border);
  border-radius:var(--r-md); box-shadow:var(--shadow);
  padding:14px 16px; margin-bottom:12px;
}
.set-group h3{ font-family:var(--serif); font-size:17px; margin-bottom:10px; }
.set-row{
  display:flex; align-items:center; justify-content:space-between; gap:12px;
  padding:9px 0; border-bottom:1px solid var(--border);
}
.set-row:last-child{ border-bottom:0; }
.set-row .lbl{ font-size:14px; }
.set-row .sub{ font-size:11.5px; color:var(--muted); margin-top:2px; line-height:1.5; }
.swatches{ display:flex; gap:8px; }
.swatch{
  border:1px solid var(--border); background:transparent; border-radius:12px;
  padding:7px 9px; display:flex; flex-direction:column; align-items:center; gap:5px;
  cursor:pointer; font-size:10.5px; color:var(--muted); min-width:62px;
}
.swatch i{ width:22px; height:22px; border-radius:50%; background:var(--c); display:block; }
.swatch.on{ border-color:var(--accent); color:var(--ink); box-shadow:0 0 0 2px rgba(179,100,63,.16); }
.seg{ display:flex; gap:4px; background:var(--surface-2); padding:4px; border-radius:12px; }
.seg button{
  border:0; background:transparent; padding:8px 14px; border-radius:9px;
  font-size:13.5px; cursor:pointer; color:var(--muted); min-height:38px;
}
.seg button.on{ background:var(--surface); color:var(--ink); box-shadow:0 2px 8px rgba(139,111,90,.14); }
.stepper{ display:flex; align-items:center; gap:8px; }
.stepper button{
  width:38px; height:38px; border-radius:11px; border:1px solid var(--border);
  background:var(--surface); cursor:pointer; font-size:16px;
}
.stepper span{ font-size:14px; min-width:44px; text-align:center; }
.time-input,.num-input,.text-input,.select-input{
  border:1px solid var(--border); background:var(--bg); color:var(--ink);
  border-radius:11px; padding:9px 11px; font-size:15px; min-height:42px;
}
.switch{
  width:50px; height:30px; border-radius:99px; border:1px solid var(--border);
  background:var(--track); position:relative; cursor:pointer; flex:none; padding:0;
  transition:background .2s;
}
.switch::after{
  content:""; position:absolute; top:2px; inset-inline-start:2px;
  width:24px; height:24px; border-radius:50%; background:var(--surface);
  box-shadow:0 2px 6px rgba(59,46,39,.25); transition:transform .2s ease;
}
.switch.on{ background:var(--accent); border-color:transparent; }
.switch.on::after{ transform:translateX(-20px); }
[dir="rtl"] .switch.on::after{ transform:translateX(-20px); }
.preview-line{
  padding:12px 14px; border-radius:12px; background:var(--paper);
  border:1px dashed var(--border); font-size:18px; line-height:1.9; margin-top:10px;
  color:var(--ink);
}
.about-note{ font-size:12.5px; color:var(--muted); line-height:1.8; }
.stack{ display:flex; flex-direction:column; gap:9px; }
.row-btns{ display:flex; gap:8px; flex-wrap:wrap; }
.row-btns .btn{ flex:1; min-width:130px; }

/* ============ bottom nav ============ */
.bottom-nav{
  position:fixed; inset-inline:0; bottom:0; z-index:40;
  display:grid; grid-template-columns:repeat(5,1fr); gap:1px;
  padding:7px 6px 10px;
  background:var(--nav-bg);
  -webkit-backdrop-filter:blur(14px); backdrop-filter:blur(14px);
  border-top:1px solid var(--border);
}
.nav-btn{
  border:0; background:transparent; cursor:pointer;
  display:flex; flex-direction:column; align-items:center; justify-content:center; gap:3px;
  min-height:52px; padding:6px 2px; border-radius:12px;
  color:var(--muted); font-size:10.5px;
  transition:color .16s, background .16s;
  -webkit-user-select:none; user-select:none;
}
.nav-btn svg{ width:21px; height:21px; }
.nav-btn.on{ color:var(--accent); background:rgba(217,167,158,.16); }
.nav-btn:active{ transform:scale(.96); }

/* ============ lock screen ============ */
.lock-screen{
  min-height:100dvh; display:flex; align-items:center; justify-content:center;
  padding:28px 20px 40px;
  background:
    radial-gradient(120% 80% at 50% -10%, rgba(217,167,158,.34), transparent 62%),
    var(--bg);
}
.lock-inner{ width:100%; max-width:340px; display:flex; flex-direction:column; align-items:center; }
.lock-mark{
  width:60px; height:60px; border-radius:50%;
  display:grid; place-items:center; color:var(--accent);
  background:rgba(217,167,158,.2); border:1px solid var(--border);
  margin-bottom:14px;
}
.lock-title{ font-family:var(--serif); font-size:32px; font-weight:700; letter-spacing:0; }
.lock-sub{ font-size:13.5px; color:var(--muted); margin-top:5px; text-align:center; }
.pin-dots{ display:flex; gap:12px; margin:24px 0 6px; direction:ltr; }
.pin-dot{
  width:13px; height:13px; border-radius:50%;
  border:1.5px solid var(--border); background:transparent;
  transition:transform .16s ease, background .16s ease, border-color .16s;
}
.pin-dot.on{ background:var(--accent); border-color:var(--accent); transform:scale(1.12); }
.lock-error{ min-height:20px; font-size:12.5px; color:var(--danger); margin:4px 0 4px; }
.shake{ animation:shake .42s ease; }
@keyframes shake{
  0%,100%{ transform:translateX(0) } 20%{ transform:translateX(-7px) }
  40%{ transform:translateX(6px) } 60%{ transform:translateX(-4px) } 80%{ transform:translateX(3px) }
}
.pin-pad{
  display:grid; grid-template-columns:repeat(3,1fr); gap:12px;
  width:100%; max-width:290px; margin-top:6px;
}
.pin-key{
  height:64px; border-radius:20px; cursor:pointer;
  border:1px solid var(--border); background:var(--surface); color:var(--ink);
  font-size:23px; font-family:var(--serif); font-weight:700;
  display:grid; place-items:center;
  transition:transform .1s ease, background .16s;
  -webkit-user-select:none; user-select:none;
  box-shadow:0 3px 10px rgba(139,111,90,.07);
}
.pin-key:active{ transform:scale(.94); background:var(--surface-2); }
.pin-key.ok{ background:var(--accent); color:#fff; border-color:transparent; }
[data-theme="dark"] .pin-key.ok{ color:#20160F; }
.pin-key.ghost{ background:transparent; border-color:transparent; box-shadow:none; cursor:default; }
.pin-key svg{ width:24px; height:24px; }

/* ============ editor ============ */
.editor{
  position:fixed; inset:0; z-index:60;
  display:flex; flex-direction:column;
  background:var(--paper);
  height:100dvh;
}
.editor-bar{
  display:flex; align-items:center; gap:6px;
  padding:8px 10px; min-height:56px;
  border-bottom:1px solid var(--border);
  background:var(--paper);
}
.editor-bar-mid{ flex:1; text-align:center; min-width:0; }
.save-state{ font-size:12px; color:var(--muted); }
.save-state.saving{ color:var(--accent); }
.editor-bar-end{ display:flex; gap:2px; }
.editor-tools{
  display:flex; align-items:center; gap:7px;
  padding:8px 10px; border-bottom:1px solid var(--border);
  overflow-x:auto; scrollbar-width:none; background:var(--surface);
}
.editor-tools::-webkit-scrollbar{ display:none; }
.tool-select{
  border:1px solid var(--border); background:var(--paper); color:var(--ink);
  border-radius:10px; padding:7px 9px; font-size:13px; min-height:38px; flex:none;
}
.tool-btn{
  flex:none; min-width:40px; height:38px; padding:0 10px;
  border:1px solid var(--border); background:var(--paper); color:var(--ink);
  border-radius:10px; font-size:13.5px; cursor:pointer;
  display:grid; place-items:center;
}
.tool-btn:active{ transform:scale(.95); }
.tool-btn.on{ background:var(--accent); color:#fff; border-color:transparent; }
[data-theme="dark"] .tool-btn.on{ color:#20160F; }
.editor-paper{
  flex:1; min-height:0; display:flex; flex-direction:column;
  padding:14px 20px 8px; overflow:hidden;
}
.ed-title{
  border:0; background:transparent; outline:none;
  font-family:var(--serif); font-size:23px; font-weight:700; color:var(--ink);
  padding:4px 0 10px; border-bottom:1px solid var(--border); margin-bottom:12px;
}
.ed-text{
  flex:1; min-height:0; width:100%; resize:none;
  border:0; background:transparent; outline:none; color:var(--ink);
  font-size:20px; line-height:1.95; letter-spacing:0;
  padding:2px 0 28px;
  overflow-y:auto;
}
.ed-text::placeholder{ color:var(--muted); opacity:.6; }
.editor-foot{
  display:flex; align-items:center; gap:12px;
  padding:10px 18px 14px; border-top:1px solid var(--border);
  background:var(--surface);
}
.foot-num{ font-size:11.5px; color:var(--muted); white-space:nowrap; }
.editor.focus .editor-bar,
.editor.focus .editor-tools,
.editor.focus .ed-title,
.editor.focus .editor-foot{ display:none; }
.editor.focus .editor-paper{ padding-top:44px; }
.focus-exit{
  position:fixed; inset-inline-start:50%; transform:translateX(50%);
  bottom:18px; z-index:61;
  border:1px solid var(--border); background:var(--surface); color:var(--muted);
  border-radius:99px; padding:10px 18px; font-size:12.5px; cursor:pointer;
  box-shadow:var(--shadow); min-height:44px;
}
[dir="rtl"] .focus-exit{ transform:translateX(50%); }

/* ============ sheet ============ */
.sheet{ position:fixed; inset:0; z-index:80; display:flex; align-items:flex-end; }
.sheet-backdrop{ position:absolute; inset:0; background:rgba(28,20,16,.44); -webkit-backdrop-filter:blur(3px); backdrop-filter:blur(3px); }
.sheet-panel{
  position:relative; width:100%; max-height:88dvh; overflow-y:auto;
  background:var(--surface); color:var(--ink);
  border-radius:var(--r-lg) var(--r-lg) 0 0;
  padding:10px 20px 24px;
  box-shadow:var(--shadow-lg);
  animation:sheetUp .28s cubic-bezier(.22,.9,.3,1);
}
@media (min-width:640px){
  .sheet{ align-items:center; justify-content:center; padding:24px; }
  .sheet-panel{ max-width:520px; border-radius:var(--r-lg); padding:20px 24px 24px; animation:sheetIn .24s ease-out; }
  .sheet-grab{ display:none; }
}
@keyframes sheetUp{ from{ transform:translateY(24px); opacity:.6 } to{ transform:translateY(0); opacity:1 } }
@keyframes sheetIn{ from{ transform:scale(.97); opacity:.5 } to{ transform:scale(1); opacity:1 } }
.sheet-grab{ width:42px; height:4px; border-radius:99px; background:var(--border); margin:0 auto 12px; }
.sheet-title{ font-family:var(--serif); font-size:21px; font-weight:700; margin-bottom:14px; }
.sheet-body{ display:flex; flex-direction:column; gap:12px; }
.field{ display:flex; flex-direction:column; gap:6px; }
.field > span{ font-size:12.5px; color:var(--muted); }
.field input, .field textarea, .field select{
  width:100%; border:1px solid var(--border); background:var(--bg); color:var(--ink);
  border-radius:12px; padding:12px 13px; font-size:15px; outline:none;
  transition:border-color .16s, box-shadow .16s;
}
.field input:focus, .field textarea:focus, .field select:focus{
  border-color:var(--accent); box-shadow:0 0 0 3px rgba(179,100,63,.14);
}
.field textarea{ resize:vertical; min-height:84px; line-height:1.7; }
.img-field{ display:flex; gap:12px; align-items:center; }
.img-preview{
  width:76px; height:96px; border-radius:12px; flex:none; overflow:hidden;
  border:1px dashed var(--border); background:var(--bg);
  display:grid; place-items:center; color:var(--muted); font-size:11px; text-align:center;
}
.img-preview img{ width:100%; height:100%; object-fit:cover; }
.img-actions{ display:flex; flex-direction:column; gap:7px; }
.sheet-actions{ display:flex; gap:9px; margin-top:18px; }
.sheet-actions .btn{ flex:1; }
.menu-list{ display:flex; flex-direction:column; gap:6px; }
.menu-item{
  display:flex; align-items:center; gap:11px; width:100%; text-align:start;
  padding:13px 14px; min-height:48px; border-radius:12px;
  border:1px solid var(--border); background:var(--bg); color:var(--ink);
  font-size:14.5px; cursor:pointer;
}
.menu-item svg{ width:18px; height:18px; color:var(--muted); flex:none; }
.menu-item.danger{ color:var(--danger); border-color:rgba(169,69,58,.35); }
.menu-item.danger svg{ color:var(--danger); }
.danger-text{ font-size:14px; line-height:1.8; color:var(--danger); }

/* ============ reader ============ */
.reader{
  position:fixed; inset:0; z-index:75; background:var(--paper);
  display:flex; flex-direction:column; height:100dvh;
}
.reader-bar{
  display:flex; align-items:center; gap:10px;
  padding:10px 14px; border-bottom:1px solid var(--border); background:var(--surface);
  font-size:13px; color:var(--muted);
}
.reader-body{
  flex:1; overflow-y:auto; padding:28px 22px 60px;
  max-width:70ch; margin:0 auto; width:100%;
}
.reader-body h1{ font-family:var(--serif); font-size:30px; line-height:1.4; margin-bottom:6px; }
.reader-body .r-meta{ font-size:12.5px; color:var(--muted); margin-bottom:22px; }
.reader-body h2{ font-family:var(--serif); font-size:21px; margin:34px 0 12px; padding-top:16px; border-top:1px solid var(--border); }
.reader-body p{ font-family:var(--serif); font-size:19px; line-height:2; margin-bottom:14px; color:var(--ink); }

/* ============ toast ============ */
.toast{
  position:fixed; inset-inline:0; bottom:110px; z-index:90;
  margin-inline:auto; width:max-content; max-width:86vw;
  background:var(--ink); color:var(--bg);
  padding:11px 18px; border-radius:99px; font-size:13px;
  box-shadow:var(--shadow-lg); pointer-events:none;
  opacity:0; transform:translateY(10px); transition:opacity .22s, transform .22s;
  text-align:center;
}
.toast.show{ opacity:1; transform:translateY(0); }

/* ============ print ============ */
.print-area{ display:none; }
@media print{
  body{ background:#fff !important; }
  body::after{ display:none !important; }
  body > *:not(.print-area){ display:none !important; }
  .print-area{ display:block !important; color:#1c1410; background:#fff; }
  .ms{ padding:0; font-family:'Amiri',serif; }
  .ms-cover{ text-align:center; padding:40px 0 30px; border-bottom:1px solid #ddd; margin-bottom:26px; }
  .ms-cover img{ max-height:280px; margin:0 auto 18px; border-radius:6px; }
  .ms-title{ font-size:34px; font-weight:700; margin-bottom:8px; }
  .ms-genre{ font-size:13px; color:#6b5b50; }
  .ms-synopsis{ font-size:14px; line-height:1.9; color:#4a3d34; max-width:56ch; margin:16px auto 0; }
  .ms-ch{ page-break-before:always; }
  .ms-ch:first-of-type{ page-break-before:auto; }
  .ms-ch h2{ font-size:22px; margin-bottom:16px; }
  .ms-ch p{ font-size:15px; line-height:2; margin-bottom:12px; text-align:justify; }
  @page{ margin:20mm 18mm; }
}

/* ============ small screens ============ */
@media (max-width:380px){
  .page-title{ font-size:27px; }
  .cover{ width:64px; height:90px; }
  .novel-title{ font-size:17.5px; }
  .banner-title{ font-size:23px; }
  .goal-num{ font-size:21px; }
  .pin-key{ height:58px; font-size:21px; }
  .btn{ padding:0 14px; }
}
@media (prefers-reduced-motion:reduce){
  *,*::before,*::after{ animation-duration:.001ms !important; transition-duration:.001ms !important; }
}

/* ============ icon picker ============ */
.icon-grid{ display:flex; flex-wrap:wrap; gap:8px; }
.icon-pick{
  width:48px; height:48px; border-radius:14px; cursor:pointer;
  border:1px solid var(--border); background:var(--bg); font-size:22px;
  display:grid; place-items:center;
  transition:transform .12s ease, border-color .16s ease, box-shadow .16s ease;
  -webkit-user-select:none; user-select:none;
}
.icon-pick:active{ transform:scale(.94); }
.icon-pick.on{ border-color:var(--accent); box-shadow:0 0 0 2px rgba(179,100,63,.2); }

/* ============ assistant ============ */
.ai-chat{
  display:flex; flex-direction:column; gap:10px;
  max-height:40dvh; overflow-y:auto; padding:12px 2px 4px; margin-top:4px;
  -webkit-overflow-scrolling:touch;
}
.ai-hello{ text-align:center; padding:16px 10px; color:var(--muted); }
.ai-mark{
  width:52px; height:52px; margin:0 auto 10px; border-radius:50%;
  display:grid; place-items:center; background:rgba(217,167,158,.24); color:var(--accent);
}
.ai-mark svg{ width:24px; height:24px; }
.ai-hello h3{ font-family:var(--serif); font-size:18px; color:var(--ink); margin-bottom:6px; }
.ai-hello p{ font-size:13px; line-height:1.75; max-width:34ch; margin:0 auto; }

.msg{
  max-width:88%; padding:11px 14px; border-radius:16px;
  font-size:14px; line-height:1.8; word-break:break-word;
}
.msg.user{ align-self:flex-end; background:var(--accent); color:#fff; }
[data-theme="dark"] .msg.user{ color:#20160F; }
.msg.assistant{ align-self:flex-start; background:var(--surface); border:1px solid var(--border); }
.msg.err{ border-color:var(--danger); color:var(--danger); background:transparent; }
.msg.typing{ display:flex; gap:5px; align-items:center; }
.msg.typing span{ width:6px; height:6px; border-radius:50%; background:var(--muted); animation:tdot 1s infinite; }
.msg.typing span:nth-child(2){ animation-delay:.15s; }
.msg.typing span:nth-child(3){ animation-delay:.3s; }
@keyframes tdot{ 0%,100%{ opacity:.3; transform:translateY(0); } 50%{ opacity:1; transform:translateY(-3px); } }

.ai-composer{ display:flex; gap:8px; align-items:flex-end; margin-top:8px; }
.ai-composer textarea{
  flex:1; min-width:0; border:1px solid var(--border); background:var(--surface);
  color:var(--ink); border-radius:14px; padding:11px 13px; font-size:15px;
  line-height:1.6; resize:none; outline:none; font-family:var(--ui);
}
.ai-composer textarea:focus{ border-color:var(--accent); box-shadow:0 0 0 3px rgba(179,100,63,.13); }
.ai-composer .btn{ flex:none; min-height:48px; font-size:14px; }

.ai-results{ display:flex; flex-direction:column; gap:7px; margin:8px 0 0; }
.ai-hit{
  display:flex; align-items:center; gap:10px; width:100%; text-align:start;
  background:var(--surface); border:1px solid var(--border); border-radius:12px;
  padding:10px 12px; cursor:pointer; font-size:13.5px; color:var(--ink);
}
.ai-hit .kind{
  font-size:11px; color:var(--accent); border:1px solid rgba(179,100,63,.3);
  border-radius:99px; padding:3px 8px; flex:none;
}
.ai-hit .label{ flex:1; min-width:0; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.ai-hit small{
  display:block; font-size:11px; color:var(--muted);
  overflow:hidden; text-overflow:ellipsis; white-space:nowrap; margin-top:2px;
}