:root {
  --title: #0d0d0d;
  --body-copy: #3a3a3a;
  --muted: #6b6b6b;
  /* Internal nav links (everything the blog itself renders stays on-site):
     underlined, and deliberately a touch subtler than running body text
     rather than a loud "link blue". */
  --link-color: #565656;
  /* Accent used for buttons/switches/selection states — distinct from the
     text-link color above. */
  --accent: #2563eb;
  --border: #ececec;
  --bg: #ffffff;
  --max-width: 640px;
  --tag-simple-color: #52525b;
  --font-body: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
}

[data-theme="dark"] {
  --title: #f2f2f2;
  --body-copy: #d8d8d8;
  --muted: #9a9a9a;
  /* Kept more muted than body copy here too, even though that means a
     lower-luminance grey rather than a lighter one on a dark background —
     the point is that links recede slightly relative to body text either way. */
  --link-color: #a3a3a3;
  --accent: #5b8dfc;
  --border: #333333;
  --bg: #121212;
  --tag-simple-color: #b9b9c2;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
  background: var(--bg);
  color: var(--body-copy);
  font-family: var(--font-body);
  font-size: 19px;
  line-height: 1.6;
  min-height: 100%;
}

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

a { color: var(--link-color); text-decoration: underline; }
a:hover { color: var(--title); }

.ext-link {
  color: #2563eb;
  text-decoration: none;
}
.ext-link:hover { opacity: 0.85; }

.site-header {
  position: relative;
  max-width: var(--max-width);
  min-width: 0;
  margin: 0 auto;
  padding: 40px 20px 20px;
  text-align: center;
}

.site-title {
  display: inline-block;
  text-decoration: none;
}

.site-avatar {
  display: block;
  width: 95px;
  height: 95px;
  object-fit: cover;
  border-radius: 50%;
  margin: 0 auto;
}

.footer-admin-link.hidden { display: none; }

.feed, .admin-main {
  max-width: var(--max-width);
  min-width: 0;
  margin: 0 auto;
  padding: 0 20px 80px;
}

.post {
  padding: 32px 0;
  border-bottom: 1px solid var(--border);
}

.post:first-child { padding-top: 8px; }

.post:last-child { border-bottom: none; }

.post-title {
  font-size: 24px;
  font-weight: 600;
  margin: 0;
  color: var(--title);
  overflow-wrap: break-word;
  word-break: break-word;
}

.post-title a {
  color: var(--title);
  text-decoration: none;
}

.post-title a:hover { color: var(--accent); }

.tag-page-title { margin-bottom: 24px; font-size: 28px; text-align: center; font-weight: 400; color: var(--muted); }

.post-content p {
  margin: 0 0 16px;
  overflow-wrap: break-word;
  word-break: break-word;
}

.post-content blockquote {
  font-family: "Times New Roman", Times, serif;
  margin: 0 0 16px;
  padding-left: 18px;
  border-left: 4px solid var(--border);
  color: var(--muted);
  font-size:22px;
  overflow-wrap: break-word;
  word-break: break-word;
}

.yt-embed {
  position: relative;
  padding-bottom: 56.25%;
  height: 0;
  overflow: hidden;
  margin: 16px 0;
  border-radius: 8px;
  background: var(--border);
}

.yt-embed iframe {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  border: 0;
}

.post-image {
  max-width: 100%;
  border-radius: 6px;
  margin: 16px 0;
  display: block;
}

.post-image-link {
  display: block;
  cursor: zoom-in;
}

.lightbox-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 1000;
  cursor: zoom-out;
}

.lightbox-overlay.hidden { display: none; }

.lightbox-image {
  max-width: 100%;
  max-height: 100%;
  border-radius: 6px;
  cursor: default;
}

.post-meta {
  margin: 6px 0 16px;
  font-size: 14px;
  color: var(--muted);
}

.post-meta a { color: var(--muted); text-decoration: none; }

.post-tags {
  margin-top: 16px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.tag-pill {
  display: inline-block;
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 400;
  text-decoration: none;
}

.tag-pill:hover { opacity: 0.85; }

.tag-pill-simple {
  background: transparent;
  border: 1px solid var(--muted);
  color: var(--tag-simple-color);
}

/* Feed/tag-list post cards: keep tags to one row. Overflowing pills are
   trimmed client-side (see renderTagOverflowScript in layout.js), which
   also appends the "..." pill below. */
.post-tags-feed {
  flex-wrap: nowrap;
  overflow: hidden;
  white-space: nowrap;
}

.tag-pill-more {
  background: var(--border);
  color: var(--muted);
  flex-shrink: 0;
  text-decoration: none;
}

/* Related posts */
.related-posts {
  margin-top: 56px;
}

.related-posts-title {
  font-size: 15px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  font-weight: 600;
  margin: 0 0 4px;
}

.related-posts-grid {
  display: flex;
  flex-direction: column;
}

.related-posts-grid .post:first-child { padding-top: 24px; }

.empty { color: var(--muted); padding: 40px 0; }

.post-single { padding-top: 8px; border-bottom: none; }

.site-footer {
  max-width: var(--max-width);
  min-width: 0;
  margin: 0 auto;
  margin-top: auto;
  padding: 20px;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
  font-style: none;
  text-decoration: none;
}

.site-footer a {
  text-decoration: none;
}

/* Admin */
.hidden { display: none !important; }

.login-box {
  max-width: 320px;
  margin: 80px auto 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.login-box input {
  padding: 12px 14px;
  font-size: 16px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-family: inherit;
  background: var(--bg);
  color: var(--body-copy);
}

.composer {
  padding: 20px 0 40px;
}

.composer-top-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}

.composer-top-row #titleInput { margin-bottom: 0; }

.composer textarea,
.composer input[type="text"] {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 12px 14px;
  font-family: inherit;
  font-size: 17px;
  margin-bottom: 10px;
  resize: vertical;
  background: var(--bg);
  color: var(--body-copy);
}

.composer textarea::placeholder,
.composer input::placeholder {
  color: var(--body-copy);
  opacity: 0.65;
}

.formatting-tips {
  margin-top: 20px;
  padding: 16px 18px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
}

.formatting-tips h3 {
  margin: 0 0 10px;
  font-size: 15px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.formatting-tips ul {
  margin: 0;
  padding-left: 18px;
  font-size: 14px;
  color: var(--body-copy);
}

.formatting-tips li { margin-bottom: 6px; }

.formatting-tips code {
  background: var(--border);
  border-radius: 3px;
  padding: 1px 4px;
  font-size: 13px;
}

.image-preview {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
}

.tag-field {
  margin-bottom: 10px;
}

.tag-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
}

.tag-pill-btn {
  border: none;
  border-radius: 999px;
  padding: 5px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  opacity: 0.4;
  box-shadow: 0 0 0 2px transparent;
  transition: opacity 0.15s ease, box-shadow 0.15s ease;
}

.tag-pill-btn.selected {
  opacity: 1;
  box-shadow: 0 0 0 2px currentColor;
}

.tag-pill-btn-simple {
  background: transparent !important;
  color: var(--tag-simple-color) !important;
  border: 1px solid var(--muted) !important;
}

.thumb {
  position: relative;
  width: 80px;
  height: 80px;
  border-radius: 6px;
  overflow: hidden;
  background: var(--border);
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  text-align: center;
}

.thumb img { width: 100%; height: 100%; object-fit: cover; }

.remove-thumb {
  position: absolute;
  top: 2px;
  right: 2px;
  background: rgba(0,0,0,0.6);
  color: #fff;
  border: none;
  border-radius: 50%;
  width: 20px;
  height: 20px;
  cursor: pointer;
  line-height: 1;
  padding: 0;
}

.composer-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
}

.composer-actions-left,
.composer-actions-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.icon-btn, .publish-btn, button {
  font-family: inherit;
  cursor: pointer;
}

.icon-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 8px 16px;
  color: var(--body-copy);
  font-size: 14px;
}

.publish-btn {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 999px;
  padding: 10px 22px;
  font-size: 15px;
  font-weight: 600;
  text-decoration: none;
}

.publish-btn:disabled { opacity: 0.6; cursor: default; }

.error { color: #d33; font-size: 14px; margin-top: 8px; min-height: 1em; }

.section-header {
  font-size: 15px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin: 30px 0 10px;
  font-weight: 600;
}

.post-list { margin-top: 6px; }

.admin-post {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
}

.admin-post:last-child { border-bottom: none; }

.admin-post-title {
  font-weight: 600;
  color: var(--title);
  text-decoration: underline;
  text-decoration-color: var(--border);
}

.admin-post-title:hover { text-decoration-color: currentColor; }

.admin-post-meta {
  font-size: 13px;
  color: var(--muted);
  margin-top: 4px;
}

.admin-post-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.icon-action-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
}

.icon-action-btn.edit-btn:hover { color: var(--accent); border-color: var(--accent); }
.icon-action-btn.delete-btn:hover { color: #d33; border-color: #d33; }

/* Styling section */
.styling-section {
  margin-top: 20px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0;
}

.toggle-label { font-size: 15px; color: var(--body-copy); }

.toggle-switch {
  position: relative;
  width: 44px;
  height: 24px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--border);
  padding: 0;
  cursor: pointer;
  flex-shrink: 0;
}

.toggle-switch[aria-checked="true"] {
  background: var(--accent);
  border-color: var(--accent);
}

.toggle-knob {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  transition: left 0.15s ease;
}

.toggle-switch[aria-checked="true"] .toggle-knob { left: 22px; }

.field-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 10px 0;
}

.field-label {
  font-size: 14px;
  color: var(--muted);
}

.field-input {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 12px;
  font-family: inherit;
  font-size: 15px;
  background: var(--bg);
  color: var(--body-copy);
}

.field-input::placeholder { color: var(--muted); opacity: 0.75; }

.settings-save-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding-top: 14px;
}

.settings-save-row .publish-btn {
  padding: 8px 20px;
  font-size: 14px;
}

.settings-save-status {
  font-size: 14px;
  color: var(--muted);
}

.settings-save-status.success { color: var(--accent); }

/* Manage Tags overlay */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 50;
}

.overlay-panel {
  background: var(--bg);
  border-radius: 10px;
  width: 100%;
  max-width: 480px;
  max-height: 80vh;
  overflow-y: auto;
  padding: 20px 24px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.25);
}

.overlay-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.overlay-header h3 {
  margin: 0;
  font-size: 18px;
  color: var(--title);
}

.overlay-close {
  background: none;
  border: none;
  font-size: 22px;
  line-height: 1;
  color: var(--muted);
  padding: 0;
}

.overlay-close:hover { color: var(--title); }

.manage-tags-table {
  width: 100%;
  border-collapse: collapse;
}

.manage-tags-table th {
  text-align: left;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  padding: 6px 4px;
  border-bottom: 1px solid var(--border);
}

.manage-tags-table td {
  padding: 10px 4px;
  border-bottom: 1px solid var(--border);
  font-size: 15px;
  vertical-align: middle;
}

.manage-tags-table tr:last-child td { border-bottom: none; }

.manage-tags-name {
  display: flex;
  align-items: center;
  gap: 8px;
}

.manage-tags-swatch {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}

.manage-tags-delete {
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  cursor: pointer;
}

.manage-tags-delete:hover { color: #d33; border-color: #d33; }

.manage-tags-empty {
  padding: 20px 0;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
}

@media (max-width: 480px) {
  html, body { font-size: 17px; }
  .post-title { font-size: 21px; }
  .post-single .post-title { font-size: 26px; }
  .tag-page-title { font-size: 27px; }
  .site-header { padding: 28px 16px 16px; }
  .feed, .admin-main { padding: 0 16px 60px; }
}