/* notepub — light/dark theme via CSS custom properties */

/* light (default) */
:root {
  --bg: #ffffff;
  --bg-elev: #f6f8fa;
  --bg-hover: #eef1f4;
  --fg: #1f2328;
  --fg-dim: #59636e;
  --accent: #0969da;
  --border: #d1d9e0;
  --code-bg: #fdf6e3;
  --code-fg: #1f2328;
  --blockquote-fg: #59636e;
  --tag-en-bg: #ddf4ff;
  --tag-en-fg: #0969da;
  --tag-zh-bg: #fbefff;
  --tag-zh-fg: #8250df;
  --mono: ui-monospace, "JetBrains Mono", "SF Mono", Menlo, monospace;
}

/* dark via explicit override */
:root[data-theme="dark"] {
  --bg: #0e1116;
  --bg-elev: #161b22;
  --bg-hover: #1f2630;
  --fg: #e6edf3;
  --fg-dim: #8b949e;
  --accent: #4493f8;
  --border: #30363d;
  --code-bg: #1f2630;
  --code-fg: #e6edf3;
  --blockquote-fg: #8b949e;
  --tag-en-bg: #1f3a5f;
  --tag-en-fg: #79c0ff;
  --tag-zh-bg: #3f2a4a;
  --tag-zh-fg: #d2a8ff;
}

/* dark via system pref when no explicit choice */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --bg: #0e1116;
    --bg-elev: #161b22;
    --bg-hover: #1f2630;
    --fg: #e6edf3;
    --fg-dim: #8b949e;
    --accent: #4493f8;
    --border: #30363d;
    --code-bg: #1f2630;
    --code-fg: #e6edf3;
    --blockquote-fg: #8b949e;
    --tag-en-bg: #1f3a5f;
    --tag-en-fg: #79c0ff;
    --tag-zh-bg: #3f2a4a;
    --tag-zh-fg: #d2a8ff;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Helvetica Neue", "Noto Sans CJK SC", sans-serif;
  font-size: 16px;
  line-height: 1.7;
  display: grid;
  grid-template-columns: 280px 1fr;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* sidebar */
.sidebar {
  background: var(--bg-elev);
  border-right: 1px solid var(--border);
  height: 100vh;
  overflow-y: auto;
  padding: 16px 12px;
  position: sticky;
  top: 0;
}
.sidebar header {
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.sidebar header a {
  color: var(--fg);
  font-weight: 600;
  font-size: 18px;
}

/* theme toggle */
.theme-toggle {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--fg-dim);
  border-radius: 6px;
  padding: 4px 8px;
  font-size: 12px;
  cursor: pointer;
  font-family: inherit;
  line-height: 1.3;
}
.theme-toggle:hover { background: var(--bg-hover); color: var(--fg); }

.tree details { margin: 6px 0; }
.tree summary {
  cursor: pointer;
  color: var(--fg-dim);
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 6px 4px;
  user-select: none;
}
.tree summary a.dir-link {
  color: var(--accent);
  text-decoration: none;
}
.tree summary a.dir-link::after {
  content: " ›";
  opacity: 0.6;
}
.tree summary a.dir-link:hover {
  text-decoration: underline;
}
.tree summary::-webkit-details-marker { color: var(--fg-dim); }
.tree ul { list-style: none; padding: 0 0 0 8px; margin: 0; }
.tree li {
  padding: 3px 0;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}
.tree li a {
  flex: 1;
  color: var(--fg);
  padding: 4px 8px;
  border-radius: 6px;
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tree li a:hover { background: var(--bg-hover); text-decoration: none; }
.tree li a.active { background: var(--bg-hover); color: var(--accent); }

.langs { display: inline-flex; gap: 3px; flex-shrink: 0; }
.lang {
  font-size: 10px;
  padding: 1px 5px;
  border-radius: 3px;
  font-family: var(--mono);
  background: var(--border);
  color: var(--fg-dim);
}
.lang-en { background: var(--tag-en-bg); color: var(--tag-en-fg); }
.lang-zh { background: var(--tag-zh-bg); color: var(--tag-zh-fg); }

/* main */
main {
  padding: 32px 48px;
  max-width: none;
  overflow-x: hidden;
}
main.welcome {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: flex-start;
  padding: 80px;
}
main.welcome h1 { font-size: 48px; margin: 0 0 16px; }
main.welcome p { color: var(--fg-dim); }
main.welcome .meta { font-size: 13px; margin-top: 24px; }

.toolbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 16px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}
.toolbar h1 { margin: 0; font-size: 28px; flex: 1; }
.controls { display: flex; gap: 8px; flex-wrap: wrap; }
.btn {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  color: var(--fg);
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}
.btn:hover { background: var(--bg-hover); text-decoration: none; }

/* rendered article */
.rendered {
  max-width: 820px;
}
.rendered h1, .rendered h2, .rendered h3, .rendered h4 {
  margin: 1.6em 0 0.6em;
  line-height: 1.3;
}
.rendered h1 { font-size: 28px; }
.rendered h2 { font-size: 22px; padding-bottom: 6px; border-bottom: 1px solid var(--border); }
.rendered h3 { font-size: 18px; }
.rendered p { margin: 0.8em 0; }
.rendered code {
  font-family: var(--mono);
  background: var(--code-bg);
  color: var(--code-fg);
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 90%;
}
.rendered pre {
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px 16px;
  overflow-x: auto;
  font-size: 13px;
  line-height: 1.5;
}
.rendered pre code { background: transparent; padding: 0; font-size: inherit; }
.rendered blockquote {
  margin: 1em 0;
  padding: 8px 16px;
  border-left: 3px solid var(--accent);
  color: var(--blockquote-fg);
  background: var(--bg-elev);
}
.rendered img { max-width: 100%; border-radius: 6px; }
.rendered table {
  border-collapse: collapse;
  margin: 1em 0;
  width: 100%;
}
.rendered th, .rendered td {
  border: 1px solid var(--border);
  padding: 8px 12px;
  text-align: left;
}
.rendered th { background: var(--bg-elev); }
.rendered hr { border: none; border-top: 1px solid var(--border); margin: 2em 0; }
.rendered ul, .rendered ol { padding-left: 1.6em; }
.rendered li { margin: 0.3em 0; }

/* source view */
.source {
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px 20px;
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
  overflow-x: auto;
}
.source code { color: var(--code-fg); }

/* mobile: hamburger drawer */
.menu-toggle {
  display: none;
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 30;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 8px;
  width: 40px;
  height: 40px;
  font-size: 20px;
  cursor: pointer;
  color: var(--fg);
  align-items: center;
  justify-content: center;
}
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 20;
}

@media (max-width: 768px) {
  body {
    grid-template-columns: 1fr;
    font-size: 15px;
  }
  .menu-toggle { display: flex; }
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 80vw;
    max-width: 320px;
    height: 100vh;
    max-height: none;
    z-index: 25;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    box-shadow: 2px 0 12px rgba(0,0,0,0.2);
  }
  body.sidebar-open .sidebar { transform: translateX(0); }
  body.sidebar-open .sidebar-backdrop { display: block; }
  .sidebar header { padding-left: 48px; }

  main {
    padding: 56px 16px 32px;
    overflow-x: hidden;
  }
  main.welcome { padding: 80px 24px 32px; }
  main.welcome h1 { font-size: 32px; }

  .toolbar { padding-bottom: 12px; margin-bottom: 16px; }
  .toolbar h1 { font-size: 22px; line-height: 1.3; }
  .controls .btn { padding: 5px 10px; font-size: 12px; }

  .rendered { max-width: 100%; }
  .rendered h1 { font-size: 24px; }
  .rendered h2 { font-size: 19px; }
  .rendered h3 { font-size: 16px; }
  .rendered pre { font-size: 12px; padding: 10px 12px; }
  .rendered table { font-size: 13px; display: block; overflow-x: auto; }
  .rendered ul, .rendered ol { padding-left: 1.2em; }

  .source { font-size: 12px; padding: 12px 14px; }
}
