:root {
  --bg: #0f1117; --surface: #171a21; --surface-2: #1f232d; --border: #2a2f3a;
  --text: #e8eaf0; --muted: #9aa3b2;
  --brand: #7c6cff; --brand-2: #14b8a6;
  --ok: #22c55e; --info: #3b82f6; --warn: #f59e0b; --danger: #ef4444;
  --radius: 14px; --shadow: 0 8px 30px rgba(0,0,0,.30);
  --sidebar-w: 232px;
}
[data-theme="light"] {
  --bg: #f4f6fb; --surface: #ffffff; --surface-2: #eef1f8; --border: #dde3ee;
  --text: #131722; --muted: #5a6678;
  --shadow: 0 8px 30px rgba(30,50,90,.08);
}
* { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }
html { scroll-behavior: smooth; }
body { font-family: Inter, system-ui, sans-serif; background: var(--bg); color: var(--text); line-height: 1.55; transition: background .25s, color .25s; }
button, input, select, textarea { font-family: inherit; }
a { color: var(--brand); }

.skip-link { position: absolute; left: -999px; top: 0; background: var(--brand); color: #fff; padding: 8px 14px; border-radius: 8px; z-index: 100; }
.skip-link:focus { left: 12px; top: 12px; }

/* layout */
.app { display: grid; grid-template-columns: var(--sidebar-w) 1fr; min-height: 100vh; }
.sidebar { background: var(--surface); border-right: 1px solid var(--border); display: flex; flex-direction: column; padding: 18px 14px; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 900; font-size: 20px; padding: 6px 8px 18px; }
.brand-mark { font-size: 24px; }
.brand-accent { color: var(--brand); }
.nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.nav-item { display: flex; align-items: center; gap: 11px; width: 100%; text-align: left; background: none; border: none; color: var(--muted); font-size: 15px; font-weight: 600; padding: 11px 12px; border-radius: 10px; cursor: pointer; transition: .15s; }
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active { background: linear-gradient(135deg, var(--brand), var(--brand-2)); color: #fff; box-shadow: 0 6px 16px rgba(124,108,255,.3); }
.ni-ic { font-size: 16px; }
.sidebar-foot { display: flex; flex-direction: column; gap: 4px; border-top: 1px solid var(--border); padding-top: 12px; }
.ghost-btn { text-align: left; background: none; border: none; color: var(--muted); font-size: 13.5px; font-weight: 600; padding: 8px 10px; border-radius: 8px; cursor: pointer; }
.ghost-btn:hover { background: var(--surface-2); color: var(--text); }

.main { display: flex; flex-direction: column; min-width: 0; }
.topbar { display: flex; align-items: center; gap: 14px; padding: 16px clamp(16px,3vw,32px); border-bottom: 1px solid var(--border); position: sticky; top: 0; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(8px); z-index: 20; }
.topbar-title { font-size: 19px; font-weight: 800; flex: 1; }
.menu-btn { display: none; }

.view { padding: clamp(18px,3vw,30px); flex: 1; display: flex; flex-direction: column; gap: 18px; max-width: 1160px; width: 100%; }

/* buttons */
.btn { font-weight: 700; font-size: 14px; cursor: pointer; border: 1px solid transparent; border-radius: 10px; padding: 10px 18px; transition: transform .1s, box-shadow .2s, background .2s; }
.btn:active { transform: translateY(1px); }
.btn.sm { padding: 7px 12px; font-size: 13px; }
.btn-primary { background: linear-gradient(135deg, var(--brand), var(--brand-2)); color: #fff; box-shadow: 0 6px 18px rgba(124,108,255,.32); }
.btn-primary:hover { box-shadow: 0 8px 24px rgba(124,108,255,.45); }
.btn-ghost { background: var(--surface-2); color: var(--text); border-color: var(--border); }
.btn-ghost:hover { border-color: var(--brand); }
.btn-danger { background: var(--danger); color: #fff; }
.icon-btn { background: var(--surface-2); border: 1px solid var(--border); color: var(--text); width: 38px; height: 38px; border-radius: 9px; cursor: pointer; font-size: 15px; display: inline-grid; place-items: center; }
.icon-btn:hover { border-color: var(--brand); }
.icon-btn.sm { width: 30px; height: 30px; font-size: 13px; }
.link-btn { background: none; border: none; color: var(--brand); font-weight: 700; font-size: 13px; cursor: pointer; }
.link-btn:hover { text-decoration: underline; }

/* cards & grid */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; }
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.card-head h2, .section-h { font-size: 16px; font-weight: 800; }
.grid { display: grid; gap: 16px; }
.grid.stats { grid-template-columns: repeat(3, 1fr); }
.grid.two { grid-template-columns: 1fr 1fr; }

.greet h1 { font-size: clamp(24px,4vw,32px); font-weight: 900; letter-spacing: -.02em; }
.greet p { color: var(--muted); }

/* stat cards */
.stat-head { display: flex; align-items: center; justify-content: space-between; font-weight: 700; color: var(--muted); margin-bottom: 10px; }
.stat-head b { font-size: 24px; color: var(--text); font-weight: 900; }
.stat-head b small { font-size: 14px; color: var(--muted); font-weight: 600; }
.donut-row { display: flex; align-items: center; gap: 16px; }
.chart-donut { width: 84px; height: 84px; flex: none; }
.legend { list-style: none; display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--muted); }
.legend i { display: inline-block; width: 9px; height: 9px; border-radius: 3px; margin-right: 7px; }
.next-dl { display: flex; flex-direction: column; gap: 6px; }
.next-dl b { font-size: 16px; }
.next-dl small { color: var(--muted); }
.muted-text { color: var(--muted); font-size: 13.5px; }

/* progress */
.progress { height: 9px; background: var(--surface-2); border-radius: 6px; overflow: hidden; margin: 8px 0; }
.progress.big { height: 13px; }
.progress span { display: block; height: 100%; background: linear-gradient(90deg, var(--brand), var(--brand-2)); border-radius: 6px; transition: width .5s ease; }

/* charts */
.chart-bar { width: 100%; height: 120px; }

/* mini list */
.mini-list, .dl-list { list-style: none; display: flex; flex-direction: column; gap: 8px; }
.mini-list li { display: flex; align-items: center; gap: 10px; font-size: 14px; }
.mini-title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dtype { font-size: 15px; }

/* pills & badges */
.pill { font-size: 11.5px; font-weight: 700; padding: 3px 9px; border-radius: 20px; white-space: nowrap; }
.pill.ok { background: color-mix(in srgb, var(--ok) 18%, transparent); color: var(--ok); }
.pill.info { background: color-mix(in srgb, var(--info) 18%, transparent); color: var(--info); }
.pill.warn { background: color-mix(in srgb, var(--warn) 20%, transparent); color: var(--warn); }
.pill.danger { background: color-mix(in srgb, var(--danger) 18%, transparent); color: var(--danger); }
.pill.muted { background: var(--surface-2); color: var(--muted); }
.badge { font-size: 11.5px; font-weight: 700; padding: 3px 10px; border-radius: 20px; background: color-mix(in srgb, var(--c) 18%, transparent); color: var(--c); }

/* toolbar (library) */
.toolbar { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.search { flex: 1; min-width: 220px; background: var(--surface); border: 1px solid var(--border); color: var(--text); border-radius: 10px; padding: 11px 14px; font-size: 14px; }
.search:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(124,108,255,.18); }
.chips { display: flex; gap: 7px; flex-wrap: wrap; }
.chip { background: var(--surface); border: 1px solid var(--border); color: var(--muted); border-radius: 20px; padding: 8px 14px; font-size: 13px; font-weight: 600; cursor: pointer; }
.chip:hover { color: var(--text); }
.chip.active { background: var(--brand); border-color: var(--brand); color: #fff; }

/* paper grid */
.paper-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.paper { display: flex; flex-direction: column; gap: 8px; padding: 16px; }
.paper-top { display: flex; align-items: center; justify-content: space-between; }
.paper-acts { display: flex; gap: 5px; }
.paper-title { font-size: 15.5px; font-weight: 800; line-height: 1.35; }
.paper-meta { color: var(--muted); font-size: 13px; }
.stars { color: var(--warn); font-size: 14px; letter-spacing: 1px; }
.star { color: var(--border); }
.star.on { color: var(--warn); }
.stars-edit .star { cursor: pointer; font-size: 22px; }
.tags { display: flex; flex-wrap: wrap; gap: 5px; }
.tag { font-size: 11.5px; background: var(--surface-2); color: var(--muted); padding: 2px 9px; border-radius: 12px; }
.paper-notes { font-size: 13px; color: var(--muted); border-left: 2px solid var(--border); padding-left: 10px; }
.cycle { margin-top: auto; align-self: flex-start; background: none; border: 1px dashed var(--border); color: var(--muted); font-size: 12.5px; font-weight: 600; padding: 6px 11px; border-radius: 8px; cursor: pointer; }
.cycle:hover { border-color: var(--brand); color: var(--brand); }

/* deadlines */
.section-h { margin-top: 4px; }
.section-h .count { color: var(--muted); font-weight: 600; font-size: 13px; }
.dl { display: flex; align-items: center; gap: 12px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; box-shadow: var(--shadow); }
.dl.is-done { opacity: .6; }
.dl.is-done .dl-title { text-decoration: line-through; }
.check { width: 26px; height: 26px; flex: none; border-radius: 50%; border: 2px solid var(--border); background: none; color: #fff; cursor: pointer; font-size: 13px; font-weight: 900; }
.check.on { background: var(--ok); border-color: var(--ok); }
.dl-main { flex: 1; min-width: 0; }
.dl-title { font-weight: 700; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.dl-main small { color: var(--muted); }
.dl-acts { display: flex; gap: 5px; }

/* chapters */
.chapter { padding: 12px 0; border-bottom: 1px solid var(--border); }
.chapter:last-child { border-bottom: none; }
.chapter-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; font-weight: 600; font-size: 14px; margin-bottom: 4px; }
.chapter-acts { display: flex; align-items: center; gap: 8px; }
.log-row { display: flex; gap: 10px; }
.log-row input { flex: 1; }

/* forms */
.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 12px; font-size: 13.5px; font-weight: 600; }
.field.inline { flex-direction: row; align-items: center; justify-content: space-between; margin-top: 14px; }
.field.inline input { width: 110px; }
.field input, .field select, .field textarea { background: var(--bg); border: 1px solid var(--border); color: var(--text); border-radius: 9px; padding: 10px 12px; font-size: 14px; font-weight: 500; }
.field input:focus, .field select:focus, .field textarea:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(124,108,255,.18); }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.hint { font-size: 12.5px; color: var(--muted); font-weight: 500; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 14px; }

/* modal */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.55); display: grid; place-items: center; padding: 18px; z-index: 50; animation: fade .15s ease; }
.modal { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; box-shadow: var(--shadow); width: 100%; max-width: 480px; max-height: 90vh; overflow: auto; animation: pop .18s ease; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 20px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--surface); }
.modal-head h2 { font-size: 17px; }
.modal-body { padding: 20px; }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.98); } }

/* toast */
.toast-host { position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 10px; z-index: 80; }
.toast { background: var(--surface); border: 1px solid var(--border); border-left: 3px solid var(--ok); border-radius: 10px; padding: 12px 16px; font-size: 14px; font-weight: 600; box-shadow: var(--shadow); animation: slidein .25s ease; }
.toast.danger { border-left-color: var(--danger); }
.toast.hide { opacity: 0; transform: translateX(20px); transition: .3s; }
@keyframes slidein { from { opacity: 0; transform: translateX(20px); } }

/* empty state */
.empty { text-align: center; padding: 50px 20px; margin: auto; max-width: 460px; }
.empty-ic { font-size: 52px; margin-bottom: 12px; }
.empty h3 { font-size: 21px; font-weight: 800; margin-bottom: 8px; }
.empty p { color: var(--muted); margin-bottom: 20px; }
.empty-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

/* footer */
.footer { border-top: 1px solid var(--border); margin-top: auto; }
.footer-inner { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding: 18px clamp(16px,3vw,32px); color: var(--muted); font-size: 13.5px; }
.footer-links a { color: var(--muted); text-decoration: none; margin: 0 3px; }
.footer-links a:hover { color: var(--brand); }
.footer-bottom { border-top: 1px solid var(--border); text-align: center; padding: 12px; color: var(--muted); font-size: 12.5px; }

/* responsive */
@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: 0; top: 0; z-index: 60; width: 260px; transform: translateX(-100%); transition: transform .25s ease; }
  .sidebar.open { transform: translateX(0); box-shadow: var(--shadow); }
  .menu-btn { display: inline-grid; }
  .grid.stats, .grid.two { grid-template-columns: 1fr; }
}
@media (max-width: 480px) {
  .row2 { grid-template-columns: 1fr; }
  .toast-host { left: 16px; right: 16px; bottom: 16px; }
}
