:root,
[data-theme="dark"] {
  --bg: #0e1218;
  --bg-image: none;
  --panel: #161c26;
  --card: #1c2430;
  --line: #2a3444;
  --sep: #3d4a5c;
  --text: #e8eef6;
  --muted: #8b98ab;
  --accent: #3d9cf0;
  --accent-2: #e36a6a;
  --on-accent: #041018;
  --ok: #3ecf8e;
  --warn: #e6b84d;
  --bad: #e36a6a;
  --input: #10161f;
  --well: #10161f;
  --overlay: rgba(4, 8, 14, .72);
  --chip: #10161f;
  --brand-logo-bg: #05070b;
  --shadow: none;
  --blur: 0px;
  --primary-bg: var(--accent);
  --radius: 12px;
  --ui-font: "Segoe UI", system-ui, sans-serif;
  --display-font: Unbounded, "Segoe UI", sans-serif;
  --mono: ui-monospace, "Cascadia Mono", Consolas, monospace;
}

[data-theme="light"] {
  --bg: #eef5fb;
  --bg-image: linear-gradient(145deg, #e8f1fa 0%, #f4f7fb 42%, #f7eef0 100%);
  --panel: rgba(255, 255, 255, 0.55);
  --card: rgba(255, 255, 255, 0.72);
  --line: rgba(20, 33, 43, 0.12);
  --sep: rgba(20, 33, 43, 0.12);
  --text: #14212b;
  --muted: #5b6b76;
  --accent: #004684;
  --accent-2: #e3000f;
  --on-accent: #ffffff;
  --ok: #1f7a4c;
  --warn: #a16207;
  --bad: #b42318;
  --input: rgba(255, 255, 255, 0.78);
  --well: rgba(255, 255, 255, 0.58);
  --overlay: rgba(20, 33, 43, .38);
  --chip: rgba(215, 232, 248, 0.78);
  --brand-logo-bg: #ffffff;
  --shadow: 0 18px 50px rgba(20, 33, 43, 0.08);
  --blur: 22px;
  --primary-bg: linear-gradient(180deg, #0a5fa8, #004684);
  --radius: 16px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background-color: var(--bg);
  background-image: var(--bg-image);
  background-attachment: fixed;
  color: var(--text);
  font: 14px/1.45 var(--ui-font);
  color-scheme: dark;
}

html[data-theme="light"],
html[data-theme="light"] body { color-scheme: light; }

.hidden { display: none !important; }

button {
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 12px;
  cursor: pointer;
  font: inherit;
}

button.primary {
  background: var(--primary-bg);
  border-color: var(--accent);
  color: var(--on-accent);
  font-weight: 600;
}

button.ghost { background: transparent; }
button:hover { filter: brightness(1.08); }
button:disabled { opacity: .45; cursor: wait; filter: none; }

input, select, textarea {
  background: var(--input);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  font: inherit;
}

.muted { color: var(--muted); margin: 4px 0 0; }

.app {
  display: flex;
  height: 100vh;
  height: 100dvh;
  min-height: 0;
  overflow: hidden;
}

.app.auth-blur { visibility: hidden; }

.sidebar {
  width: 300px;
  flex: 0 0 300px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 16px 14px;
  background: var(--panel);
  border-right: 1px solid var(--line);
  backdrop-filter: blur(var(--blur));
  height: 100vh;
  height: 100dvh;
  min-height: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 2px 2px 16px;
  border-bottom: 1px solid var(--line);
}

.brand-logo {
  width: 64px;
  height: 64px;
  flex: 0 0 64px;
  object-fit: contain;
  border-radius: 50%;
  background: var(--brand-logo-bg);
  box-shadow:
    0 0 0 1px color-mix(in srgb, var(--accent) 35%, transparent),
    0 0 20px color-mix(in srgb, var(--accent) 18%, transparent);
}

.brand-title {
  font-family: var(--display-font);
  font-weight: 600;
  font-size: 15px;
  letter-spacing: .03em;
  line-height: 1.15;
}

.brand-title span { color: var(--accent); }

.search-wrap input {
  width: 100%;
  height: 38px;
  padding: 0 12px;
  outline: none;
}

.search-wrap input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent);
}

.side-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
  min-height: 0;
  overflow: auto;
}

.tree-section { margin: 6px 0 10px; }
.tree-section-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
  font-weight: 700;
  padding: 6px 8px 4px;
}
.tree-folder-title {
  width: 100%;
  text-align: left;
  background: transparent;
  border: 0;
  color: var(--muted);
  font-weight: 600;
  padding: 6px 8px;
}
.tree-children { padding-left: 10px; }
.tree-page {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  text-align: left;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 6px 8px;
  color: var(--text);
}
.tree-page.active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
  font-weight: 600;
}
.tree-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex: 0 0 8px;
  background: var(--sep);
}
.tree-dot.studied { background: var(--ok); }
.tree-dot.questions { background: var(--warn); }
.tree-dot.unclear { background: var(--bad); }
.tree-page.active .tree-dot { box-shadow: 0 0 0 2px color-mix(in srgb, var(--on-accent) 35%, transparent); }

.search-results {
  flex: 1;
  min-height: 0;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.search-hit {
  text-align: left;
  width: 100%;
  background: var(--card);
  padding: 8px 10px;
}
.search-hit b { display: block; margin-bottom: 4px; }
.search-hit span { color: var(--muted); font-size: 12px; }

.side-foot { border-top: 1px solid var(--line); padding-top: 10px; }
.side-foot .muted { font-size: 11px; line-height: 1.5; }
.dash-btn { width: 100%; margin-bottom: 8px; }

.main-col {
  flex: 1;
  min-width: 0;
  min-height: 0;
  height: 100%;
  display: flex;
  flex-direction: column;
}

.top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 24px 12px;
  border-bottom: 1px solid var(--line);
  gap: 16px;
}

.menu-btn {
  display: none;
  width: 42px;
  height: 42px;
  flex: 0 0 42px;
}
.top-right { display: flex; align-items: center; gap: 10px; margin-left: auto; }

h1 {
  margin: 0;
  font-size: 20px;
  letter-spacing: .04em;
  font-family: var(--display-font);
}

.tagline { margin: 4px 0 0; max-width: 72ch; font-size: 12px; }

.theme-toggle {
  width: 42px;
  height: 42px;
  padding: 0;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--card);
}
.theme-toggle svg { width: 20px; height: 20px; display: none; }
html:not([data-theme="light"]) .theme-toggle .ico-sun { display: block; }
html[data-theme="light"] .theme-toggle .ico-moon { display: block; }

.user-menu-wrap { position: relative; }
.user-avatar {
  width: 42px;
  height: 42px;
  padding: 0;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: linear-gradient(145deg, var(--accent), #0a5fa8);
  color: var(--on-accent);
  border: 2px solid color-mix(in srgb, var(--accent) 40%, transparent);
  font-weight: 700;
  font-size: 14px;
}
.user-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  width: 220px;
  padding: 12px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  z-index: 20;
}
.user-menu-name { font-weight: 600; }
.user-menu-role { color: var(--muted); font-size: 12px; margin: 2px 0 10px; }
.user-menu button { width: 100%; }

main {
  padding: 18px 24px 40px;
  flex: 1;
  min-height: 0;
  overflow: auto;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px 22px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}

.auth-screen {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  background-color: var(--bg);
  background-image: var(--bg-image);
}
.auth-screen.hidden { display: none; }
.auth-card {
  width: min(420px, 92vw);
  padding: 36px 32px 30px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
  text-align: center;
}
.auth-card .brand-logo { margin: 0 auto 14px; }
.auth-card form { display: grid; gap: 16px; text-align: left; margin-top: 28px; }
.auth-card label { margin: 0; font-size: 12px; font-weight: 600; letter-spacing: .04em; color: var(--muted); }
.auth-card input {
  display: block;
  width: 100%;
  margin-top: 7px;
  height: 48px;
  padding: 0 16px;
  font-size: 16px;
  border-radius: 12px;
  outline: none;
}
.auth-card input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 28%, transparent);
}
.auth-card button.primary { width: 100%; height: 50px; margin-top: 6px; border-radius: 12px; font-size: 16px; }
.auth-error { min-height: 1.2em; margin: 14px 0 0; color: var(--bad); font-size: 13px; }

.prose { font-size: 15px; line-height: 1.65; max-width: 78ch; }
.prose h1, .prose h2, .prose h3 {
  font-family: var(--display-font);
  line-height: 1.25;
  margin: 1.3em 0 .5em;
}
.prose h1 { font-size: 26px; margin-top: 0; }
.prose h2 { font-size: 18px; }
.prose h3 { font-size: 16px; }
.prose p, .prose ul, .prose ol, .prose table { margin: 0 0 1em; }
.prose a { color: var(--accent); }
.prose code, .prose pre {
  font-family: var(--mono);
  background: var(--well);
  border-radius: 6px;
}
.prose code { padding: 1px 5px; font-size: 13px; }
.prose pre { padding: 12px 14px; overflow: auto; }
.prose pre code { padding: 0; background: none; }
.prose table { width: 100%; border-collapse: collapse; font-size: 13px; }
.prose th, .prose td { border: 1px solid var(--line); padding: 7px 9px; text-align: left; vertical-align: top; }
.prose th { background: var(--well); }
.prose blockquote {
  margin: 0 0 1em;
  padding: 8px 14px;
  border-left: 3px solid var(--accent);
  color: var(--muted);
}

.attachments { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0 18px; }
.attachments a {
  color: var(--text);
  text-decoration: none;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 10px;
  background: var(--well);
  font-size: 13px;
}

.pager { display: flex; justify-content: space-between; gap: 12px; margin: 8px 0 18px; }
.pager a { color: var(--accent); text-decoration: none; max-width: 46%; }
.pager .next { margin-left: auto; text-align: right; }

.progress-box {
  border-top: 1px solid var(--line);
  padding-top: 16px;
  margin-top: 8px;
}
.progress-label {
  margin: 0 0 6px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--muted);
  font-weight: 700;
}
.progress-actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0; }
.progress-actions button.ok { border-color: var(--ok); }
.progress-actions button.warn { border-color: var(--warn); }
.progress-actions button.bad { border-color: var(--bad); }
.progress-actions button.active.ok { background: var(--ok); color: #041018; }
.progress-actions button.active.warn { background: var(--warn); color: #041018; }
.progress-actions button.active.bad { background: var(--bad); color: #fff; }
.progress-form { display: grid; gap: 10px; max-width: 560px; }
.progress-form textarea { width: 100%; padding: 10px 12px; resize: vertical; }
.progress-form-actions { display: flex; gap: 8px; }

.dash-grid { display: grid; gap: 10px; }
.dash-user {
  width: 100%;
  text-align: left;
  padding: 14px 16px;
  display: grid;
  gap: 8px;
}
.dash-user.active { border-color: var(--accent); }
.dash-user-top { display: flex; justify-content: space-between; gap: 12px; align-items: baseline; }
.dash-bars { display: flex; flex-wrap: wrap; gap: 8px; }
.dash-chip {
  font-size: 12px;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--chip);
  border: 1px solid var(--line);
}
.dash-chip.bad { border-color: var(--bad); color: var(--bad); }
.detail-page { display: flex; justify-content: space-between; gap: 12px; padding: 6px 0; border-bottom: 1px solid var(--line); }
.feedback-item { padding: 10px 0; border-bottom: 1px solid var(--line); }
.feedback-item .meta { color: var(--muted); font-size: 12px; }

@media (max-width: 860px) {
  .sidebar {
    position: fixed;
    z-index: 40;
    transform: translateX(-110%);
    transition: transform .2s ease;
  }
  .sidebar.open { transform: none; }
  .menu-btn { display: grid; place-items: center; }
  main { padding: 14px 14px 32px; }
  .card { padding: 16px; }
}
