:root {
  --bg: #0e1116;
  --surface: #161b22;
  --border: #30363d;
  --text: #e6edf3;
  --muted: #8b949e;
  --accent: #4ade80;
  --accent-dim: #22c55e;
  --link: #79c0ff;
  --code-bg: #1f242c;
  --max-width: 760px;
  --max-width-admin: 1100px;
  --danger: #f87171;
}

body.admin main {
  max-width: var(--max-width-admin);
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.6;
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

header {
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

header .inner {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 1rem 1.25rem;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 1.25rem;
}

header .brand {
  font-weight: 700;
  font-size: 1.25rem;
  color: var(--accent);
  text-decoration: none;
  letter-spacing: 0.02em;
  display: inline-flex;
  align-items: center;
}
.brand-logo {
  height: 28px;
  width: auto;
  display: block;
}

header nav {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  margin-right: auto;
}
.header-search input {
  background: var(--code-bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.3rem 0.55rem;
  font-size: 0.9rem;
  width: 140px;
}
.header-search input:focus { outline: 1px solid var(--accent); width: 200px; }

.search-form {
  display: flex;
  gap: 0.5rem;
  margin: 1rem 0 1.5rem;
}
.search-form input[type="search"] {
  flex: 1;
  background: var(--code-bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.55rem 0.7rem;
  font-size: 1rem;
}
mark { background: rgba(74, 222, 128, 0.25); color: inherit; padding: 0 2px; border-radius: 2px; }

header nav a {
  color: var(--muted);
  text-decoration: none;
  font-size: 0.95rem;
}

header nav a:hover,
header nav a.active {
  color: var(--text);
}

main {
  flex: 1;
  max-width: var(--max-width);
  width: 100%;
  margin: 0 auto;
  padding: 2rem 1.25rem 3rem;
}

h1, h2, h3 {
  line-height: 1.25;
  margin-top: 2rem;
  margin-bottom: 0.75rem;
}

h1 {
  font-size: 2rem;
  margin-top: 0.5rem;
}

h2 {
  font-size: 1.4rem;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.35rem;
}

h3 {
  font-size: 1.1rem;
  color: var(--accent);
}

a {
  color: var(--link);
}

p, ul, ol {
  margin: 0.75rem 0;
}

ul, ol {
  padding-left: 1.5rem;
}

li + li {
  margin-top: 0.25rem;
}

code {
  background: var(--code-bg);
  padding: 0.1em 0.35em;
  border-radius: 4px;
  font-size: 0.92em;
  font-family: "SF Mono", Menlo, Consolas, monospace;
}

pre {
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.85rem 1rem;
  overflow-x: auto;
  font-size: 0.9rem;
}

pre code {
  background: transparent;
  padding: 0;
}

.lede {
  font-size: 1.1rem;
  color: var(--muted);
}

.callout {
  border-left: 3px solid var(--accent-dim);
  background: var(--surface);
  padding: 0.75rem 1rem;
  margin: 1.25rem 0;
  border-radius: 0 6px 6px 0;
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
  margin: 1.5rem 0;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem 1.1rem;
}

.card h3 {
  margin-top: 0;
}

.card p {
  color: var(--muted);
  font-size: 0.95rem;
  margin-bottom: 0;
}

table {
  width: 100%;
  border-collapse: collapse;
  margin: 1rem 0;
  font-size: 0.95rem;
}

th, td {
  text-align: left;
  padding: 0.55rem 0.7rem;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

th {
  background: var(--surface);
  color: var(--muted);
  font-weight: 600;
}

footer {
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.85rem;
  text-align: center;
  padding: 1.25rem;
}

.muted { color: var(--muted); }
.small { font-size: 0.85rem; }

/* Home feed -------------------------------------------------------------- */

.post-list {
  list-style: none;
  padding: 0;
  margin: 1.25rem 0 0;
}
.post-list li {
  padding: 1.1rem 0;
  border-bottom: 1px solid var(--border);
}
.post-list-title {
  font-size: 1.2rem;
  font-weight: 600;
  text-decoration: none;
  color: var(--text);
}
.post-list-title:hover { color: var(--accent); }
.post-meta {
  color: var(--muted);
  font-size: 0.85rem;
  margin: 0.2rem 0 0.4rem;
}
.post-excerpt { color: var(--muted); margin: 0.25rem 0 0; }
.tag-link { color: var(--muted); text-decoration: none; }
.tag-link:hover { color: var(--accent); }
.post-tags { display: flex; flex-wrap: wrap; gap: 0.4rem; margin: 1.5rem 0 0; }
.tag-pill {
  display: inline-block;
  padding: 0.15rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  font-size: 0.85rem;
  text-decoration: none;
}
.tag-pill:hover { color: var(--text); border-color: var(--muted); }

.content img { max-width: 100%; height: auto; }
.content blockquote {
  border-left: 3px solid var(--accent-dim);
  background: var(--surface);
  padding: 0.6rem 1rem;
  margin: 1rem 0;
  color: var(--muted);
}
.content hr { border: 0; border-top: 1px solid var(--border); margin: 2rem 0; }

.toc {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem 1rem;
  margin: 1rem 0 1.75rem;
  font-size: 0.92rem;
}
.toc-label {
  color: var(--muted);
  text-transform: uppercase;
  font-size: 0.75rem;
  letter-spacing: 0.04em;
  margin-bottom: 0.3rem;
}
.toc ul { list-style: none; padding: 0; margin: 0; }
.toc li { padding: 0.15rem 0; }
.toc-l3 { padding-left: 1.25rem; }
.toc a { color: var(--link); text-decoration: none; }
.toc a:hover { text-decoration: underline; }

/* Footnotes (marked-footnote) ------------------------------------------- */
.content .footnotes {
  margin-top: 2.5rem;
  font-size: 0.9rem;
  border-top: 1px solid var(--border);
  padding-top: 1rem;
}
.content .footnotes ol { padding-left: 1.25rem; color: var(--muted); }
.content sup a { text-decoration: none; }

/* Heading anchors (from marked-gfm-heading-id) */
.content h2, .content h3 { scroll-margin-top: 1rem; }

/* Admin ------------------------------------------------------------------ */

.admin-section { margin-top: 2.25rem; }
.admin-section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
}
.admin-section-head h2 { margin: 0; border: 0; padding: 0; }

.pill {
  display: inline-block;
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  font-size: 0.78rem;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--muted);
}
.pill-published {
  color: var(--accent);
  border-color: var(--accent-dim);
}

.btn {
  display: inline-block;
  padding: 0.4rem 0.85rem;
  font-size: 0.95rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  text-decoration: none;
  cursor: pointer;
}
.btn:hover { border-color: var(--muted); }
.btn-primary {
  background: var(--accent-dim);
  border-color: var(--accent-dim);
  color: #0b1410;
  font-weight: 600;
}
.btn-primary:hover { background: var(--accent); border-color: var(--accent); }
.btn-secondary { /* default */ }
.btn-danger {
  color: var(--danger);
  border-color: rgba(248, 113, 113, 0.4);
  background: transparent;
}
.btn-danger:hover { background: rgba(248, 113, 113, 0.08); }

.flash {
  margin: 1rem 0;
  padding: 0.6rem 0.9rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
}
.flash-ok { border-color: var(--accent-dim); color: var(--accent); }
.flash-err { border-color: rgba(248, 113, 113, 0.4); color: var(--danger); }

.editor {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  margin-top: 1rem;
}
.editor label {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.9rem;
  color: var(--muted);
}
.editor label.inline {
  flex-direction: row;
  align-items: center;
  gap: 0.5rem;
  color: var(--text);
}
.editor input[type="text"],
.editor input[type="number"],
.editor select,
.editor textarea {
  background: var(--code-bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.55rem 0.7rem;
  font-size: 0.95rem;
  font-family: inherit;
}
.editor textarea {
  font-family: "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.9rem;
  line-height: 1.5;
  resize: vertical;
  min-height: 320px;
}

.editor-split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}
@media (max-width: 900px) {
  .editor-split { grid-template-columns: 1fr; }
}
.editor-pane { display: flex; flex-direction: column; gap: 0.3rem; }
.editor-pane-label {
  font-size: 0.9rem;
  color: var(--muted);
}
.preview {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.85rem 1rem;
  min-height: 320px;
  overflow-x: auto;
}
.preview > :first-child { margin-top: 0; }
.preview > :last-child { margin-bottom: 0; }

.form-actions {
  display: flex;
  gap: 0.6rem;
  margin-top: 0.5rem;
  flex-wrap: wrap;
}
.form-actions .btn-danger { margin-left: auto; }

.preview-link {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.55rem 0.75rem;
  margin: 0.5rem 0 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}
.preview-link input {
  background: var(--code-bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.3rem 0.5rem;
  font-family: "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.85rem;
}

/* Theme editor ----------------------------------------------------------- */

.theme-presets {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 0.6rem;
  margin: 1rem 0 1.5rem;
}
.preset-card {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem;
  font: inherit;
  color: var(--text);
  cursor: pointer;
  text-align: left;
}
.preset-card:hover { border-color: var(--muted); }
.preset-card:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.preset-swatches {
  display: flex;
  gap: 4px;
  height: 28px;
}
.preset-swatches span {
  flex: 1;
  border-radius: 4px;
  border: 1px solid rgba(0, 0, 0, 0.18);
}
.preset-name {
  font-size: 0.95rem;
  font-weight: 500;
}

/* Images ----------------------------------------------------------------- */

.image-upload {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin: 1rem 0 1.5rem;
  padding: 0.85rem;
  border: 1px dashed var(--border);
  border-radius: 8px;
  background: var(--surface);
}
.image-upload input[type="file"] { color: var(--text); }

.image-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 0.85rem;
}
.image-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.image-card img {
  width: 100%;
  height: 140px;
  object-fit: cover;
  background: var(--code-bg);
  display: block;
}
.image-meta {
  padding: 0.6rem 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.85rem;
}
.image-name {
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.image-actions {
  display: flex;
  gap: 0.35rem;
  align-items: center;
}
.image-actions input {
  flex: 1;
  background: var(--code-bg);
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.25rem 0.4rem;
  font-family: "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.78rem;
  min-width: 0;
}
.btn.small { padding: 0.2rem 0.5rem; font-size: 0.8rem; }

.theme-mode {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.85rem 1rem;
  margin: 1rem 0;
}
.theme-mode h2 { margin-top: 0; border: 0; padding: 0; font-size: 1.1rem; }
.theme-mode-row {
  display: flex;
  align-items: end;
  flex-wrap: wrap;
  gap: 0.75rem;
}
.theme-mode-row label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  color: var(--muted);
  font-size: 0.85rem;
}
.theme-mode-row select {
  background: var(--code-bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.4rem 0.5rem;
  font-size: 0.95rem;
}

.mode-toggle {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.05rem 0.45rem;
  color: var(--muted);
  font: inherit;
  font-size: 0.8rem;
  cursor: pointer;
}
.mode-toggle:hover { color: var(--text); }

.theme-form { margin-top: 1rem; }
.theme-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 0.6rem;
  margin-bottom: 1rem;
}
.theme-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.55rem 0.75rem;
  cursor: pointer;
}
.theme-row input[type="color"] {
  width: 38px;
  height: 38px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: transparent;
  cursor: pointer;
}
.theme-row-body { display: flex; flex-direction: column; gap: 0.1rem; min-width: 0; }
.theme-row-label { color: var(--text); font-size: 0.95rem; }
.theme-row code { background: transparent; padding: 0; }
