/* Readable light/dark theme inspired by Lil'Log / PaperMod.
   - Default: follow OS prefers-color-scheme
   - Optional manual override via html[data-theme="light"|"dark"] + localStorage
   Loaded only on GitHub Pages / local Jekyll — not on github.com README. */

:root {
  --theme: #ffffff;
  --entry: #ffffff;
  --primary: #1e1e1e;
  --content: #1f1f1f;
  --secondary: #6c6c6c;
  --tertiary: #d6d6d6;
  --border: #eeeeee;
  --code-bg: #f5f5f5;
  --link: #0969da;
  --link-hover: #0550ae;
  --table-head: #f6f8fa;
  --table-stripe: #fafafa;
  --table-hover: #f0f4f8;
  --radius: 8px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu,
    Cantarell, "Open Sans", "Helvetica Neue", sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --toggle-bg: #f0f0f0;
  --toggle-fg: #1e1e1e;
  color-scheme: light;
}

/* System dark (unless user forced light) */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --theme: #1d1e20;
    --entry: #1d1e20;
    --primary: #dadadb;
    --content: #c4c4c5;
    --secondary: #9b9c9d;
    --tertiary: #414244;
    --border: #333333;
    --code-bg: #37383e;
    --link: #79b8ff;
    --link-hover: #a5d0ff;
    --table-head: #2e2e33;
    --table-stripe: #25262a;
    --table-hover: #303138;
    --toggle-bg: #2e2e33;
    --toggle-fg: #dadadb;
    color-scheme: dark;
  }
}

/* Manual overrides */
html[data-theme="light"] {
  --theme: #ffffff;
  --entry: #ffffff;
  --primary: #1e1e1e;
  --content: #1f1f1f;
  --secondary: #6c6c6c;
  --tertiary: #d6d6d6;
  --border: #eeeeee;
  --code-bg: #f5f5f5;
  --link: #0969da;
  --link-hover: #0550ae;
  --table-head: #f6f8fa;
  --table-stripe: #fafafa;
  --table-hover: #f0f4f8;
  --toggle-bg: #f0f0f0;
  --toggle-fg: #1e1e1e;
  color-scheme: light;
}

html[data-theme="dark"] {
  --theme: #1d1e20;
  --entry: #1d1e20;
  --primary: #dadadb;
  --content: #c4c4c5;
  --secondary: #9b9c9d;
  --tertiary: #414244;
  --border: #333333;
  --code-bg: #37383e;
  --link: #79b8ff;
  --link-hover: #a5d0ff;
  --table-head: #2e2e33;
  --table-stripe: #25262a;
  --table-hover: #303138;
  --toggle-bg: #2e2e33;
  --toggle-fg: #dadadb;
  color-scheme: dark;
}

html {
  background: var(--theme);
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--content);
  font-family: var(--font);
  background: var(--theme);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Full-width content shell */
body > .container-lg.markdown-body {
  max-width: none !important;
  width: 100% !important;
  margin: 0 !important;
  padding: 2rem 1.75rem 2.75rem !important;
  background: var(--entry);
  border: 0 !important;
  border-top: 1px solid var(--border) !important;
  border-radius: 0 !important;
  box-shadow: none !important;
}

.markdown-body {
  font-family: var(--font);
  font-size: 16px !important;
  line-height: 1.65 !important;
  color: var(--content) !important;
  word-wrap: break-word;
}

/* Brand header */
.markdown-body > table:first-of-type {
  display: block;
  width: 100%;
  margin: 0 0 1.25rem;
  border: 0 !important;
  background: transparent;
}

.markdown-body > table:first-of-type tr,
.markdown-body > table:first-of-type td {
  border: 0 !important;
  background: transparent !important;
  padding: 0 !important;
  vertical-align: middle !important;
}

.markdown-body > table:first-of-type img {
  display: block;
  width: 64px;
  height: 64px;
  border-radius: 8px;
  background: var(--entry);
  border: 1px solid var(--border);
  padding: 4px;
  box-sizing: border-box;
}

.markdown-body > table:first-of-type h1 {
  margin: 0 0 0 0.9rem !important;
  padding: 0 !important;
  border: 0 !important;
  font-size: 1.75rem !important;
  line-height: 1.25 !important;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--primary) !important;
}

.markdown-body > table:first-of-type + p {
  font-size: 1.05rem;
  line-height: 1.6;
  color: var(--secondary);
  max-width: 48em;
}

.markdown-body h1,
.markdown-body h2,
.markdown-body h3,
.markdown-body h4 {
  font-weight: 700;
  line-height: 1.3;
  letter-spacing: -0.015em;
  color: var(--primary) !important;
  border-bottom: none !important;
}

.markdown-body h2 {
  margin-top: 2rem !important;
  margin-bottom: 0.75rem !important;
  padding-bottom: 0.4rem !important;
  font-size: 1.35rem !important;
  border-bottom: 1px solid var(--border) !important;
}

.markdown-body h3 {
  margin-top: 1.35rem !important;
  font-size: 1.15rem !important;
  color: var(--primary) !important;
}

.markdown-body p,
.markdown-body li {
  color: var(--content);
  font-size: 16px;
  line-height: 1.65;
}

.markdown-body li + li {
  margin-top: 0.4rem;
}

.markdown-body strong {
  color: var(--primary);
  font-weight: 600;
}

.markdown-body a {
  color: var(--link) !important;
  text-decoration: none;
  border-bottom: 1px solid transparent;
}

.markdown-body a:hover {
  color: var(--link-hover) !important;
  text-decoration: underline;
}

.markdown-body hr {
  height: 0;
  margin: 1.75rem 0;
  border: 0;
  border-top: 1px solid var(--border);
  background: none;
}

.markdown-body table:not(:first-of-type) {
  width: 100%;
  margin: 1rem 0 1.35rem;
  border-collapse: separate;
  border-spacing: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  display: table;
}

.markdown-body table:not(:first-of-type) th,
.markdown-body table:not(:first-of-type) td {
  padding: 0.65rem 0.85rem !important;
  border: 0 !important;
  border-bottom: 1px solid var(--border) !important;
  font-size: 15px !important;
  color: var(--content) !important;
  background: var(--entry) !important;
  /* Match header and body cells (browsers default th to center) */
  text-align: left !important;
  vertical-align: top !important;
}

.markdown-body table:not(:first-of-type) th[align="right"],
.markdown-body table:not(:first-of-type) td[align="right"] {
  text-align: right !important;
}

.markdown-body table:not(:first-of-type) th[align="center"],
.markdown-body table:not(:first-of-type) td[align="center"] {
  text-align: center !important;
}

.markdown-body table:not(:first-of-type) tr:last-child td {
  border-bottom: 0 !important;
}

.markdown-body table:not(:first-of-type) th {
  background: var(--table-head) !important;
  color: var(--primary) !important;
  font-weight: 600;
  font-size: 13px !important;
  text-transform: none;
  letter-spacing: 0;
}

.markdown-body table:not(:first-of-type) tr:nth-child(even) td {
  background: var(--table-stripe) !important;
}

.markdown-body table:not(:first-of-type) tr:hover td {
  background: var(--table-hover) !important;
}

.markdown-body code {
  font-family: var(--mono);
  font-size: 0.9em;
  background: var(--code-bg);
  border: 1px solid var(--border);
  color: var(--primary);
  border-radius: 4px;
  padding: 0.12em 0.4em;
}

.markdown-body ol li::marker,
.markdown-body ul li::marker {
  color: var(--secondary);
}

.footer {
  border-top-color: var(--border) !important;
  color: var(--secondary) !important;
  font-size: 13px !important;
}

.footer a {
  color: var(--link) !important;
}

.markdown-body > p,
.markdown-body > ul,
.markdown-body > ol,
.markdown-body > h2,
.markdown-body > h3,
.markdown-body > hr,
.markdown-body > table:not(:first-of-type) {
  max-width: 48rem;
}

/* Theme toggle (fixed corner, like Lil'Log top-link) */
#theme-toggle {
  position: fixed;
  bottom: 1.25rem;
  right: 1.25rem;
  z-index: 100;
  width: 2.5rem;
  height: 2.5rem;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--toggle-bg);
  color: var(--toggle-fg);
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.12);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.12s ease, background 0.15s ease;
}

#theme-toggle:hover {
  transform: scale(1.06);
}

#theme-toggle:focus {
  outline: 2px solid var(--link);
  outline-offset: 2px;
}

#theme-toggle .icon-sun,
#theme-toggle .icon-moon {
  display: none;
}

/* Show moon when light (click to go dark); sun when dark (click to go light) */
html:not([data-theme="dark"]) #theme-toggle .icon-moon {
  display: inline;
}

html[data-theme="dark"] #theme-toggle .icon-sun {
  display: inline;
}

/* When following system (no data-theme), still show the right icon */
@media (prefers-color-scheme: dark) {
  html:not([data-theme="light"]):not([data-theme="dark"]) #theme-toggle .icon-moon {
    display: none;
  }
  html:not([data-theme="light"]):not([data-theme="dark"]) #theme-toggle .icon-sun {
    display: inline;
  }
}

@media (max-width: 700px) {
  body > .container-lg.markdown-body {
    padding: 1.25rem 1rem 2rem !important;
  }

  .markdown-body {
    font-size: 16px !important;
  }

  .markdown-body > table:first-of-type h1 {
    font-size: 1.35rem !important;
  }

  .markdown-body > table:first-of-type img {
    width: 52px;
    height: 52px;
  }

  #theme-toggle {
    bottom: 1rem;
    right: 1rem;
  }
}
