:root {
  --max-width: 760px;
  --color-text: #1a1a1a;
  --color-muted: #666;
  --color-bg: #fff;
  --color-bg-alt: #fafafa;
  --color-accent: #1a5fb4;
  --color-border: #e5e5e5;
  --color-tag-bg: #f0f4fa;
  --color-input-bg: #fff;
  font-size: 18px;
}

html[data-theme="dark"] {
  --color-text: #e8e8ea;
  --color-muted: #a0a0a8;
  --color-bg: #15161a;
  --color-bg-alt: #1c1d22;
  --color-accent: #6ba1e8;
  --color-border: #33343a;
  --color-tag-bg: #232531;
  --color-input-bg: #1c1d22;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
}

html { transition: background-color 0.15s ease; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--color-text);
  background: var(--color-bg);
  line-height: 1.6;
}

.wrap {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 1.25rem;
}

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

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

.site-header {
  border-bottom: 1px solid var(--color-border);
  padding: 1rem 0;
}
.site-header .wrap {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}
.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}
.logo {
  font-weight: 700;
  font-size: 1.25rem;
  color: var(--color-text);
}
.home-link {
  font-size: 0.85rem;
  padding: 0.3rem 0.7rem;
  border: 1px solid var(--color-border);
  border-radius: 999px;
  color: var(--color-text);
  text-decoration: none;
}
.home-link:hover { background: var(--color-tag-bg); text-decoration: none; }
.search-form input {
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  width: 220px;
  background: var(--color-input-bg);
  color: var(--color-text);
}
.theme-toggle {
  background: none;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  width: 2.4rem;
  height: 2.4rem;
  font-size: 1.1rem;
  cursor: pointer;
  line-height: 1;
}
.theme-toggle:hover { background: var(--color-tag-bg); }

.back-to-top {
  position: fixed;
  right: 1.25rem;
  bottom: 1.25rem;
  width: 3rem;
  height: 3rem;
  border-radius: 50%;
  border: 1px solid var(--color-border);
  background: var(--color-bg);
  color: var(--color-text);
  font-size: 1.25rem;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 50;
}
.back-to-top.is-visible {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}
.back-to-top:hover { background: var(--color-tag-bg); }

.back-home { margin-top: 1.5rem; }

main.wrap {
  padding-top: 2rem;
  padding-bottom: 3rem;
  min-height: 60vh;
}

.post-grid {
  display: grid;
  gap: 2.5rem;
}

.post-card {
  display: flex;
  gap: 1rem;
  align-items: flex-start;
}
.post-card__image {
  flex: 0 0 200px;
  width: 200px;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  border-radius: 8px;
  display: block;
}
.post-card__image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.post-card__body {
  flex: 1;
  min-width: 0;
}
.post-card__body h2 {
  margin: -0.2rem 0 0.25rem;
  font-size: 1.25rem;
  line-height: 1.2;
}
@media (max-width: 600px) {
  .post-card {
    flex-direction: column;
  }
  .post-card__image {
    width: 100%;
    flex-basis: auto;
  }
}
.post-card__subtitle {
  color: var(--color-muted);
  margin: 0 0 0.5rem;
}
.post-card__date {
  color: var(--color-muted);
  font-size: 0.8rem;
  margin: 0 0 0.5rem;
}

.tag-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.5rem;
}
.tag {
  background: var(--color-tag-bg);
  color: var(--color-accent);
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  font-size: 0.85rem;
}

.per-page-form {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 1.5rem;
  font-size: 0.85rem;
  color: var(--color-muted);
}
.per-page-form label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.per-page-form select {
  font-family: inherit;
  font-size: 0.9rem;
  padding: 0.3rem 0.5rem;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  background: var(--color-input-bg);
  color: var(--color-text);
}

.pagination {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 2.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--color-border);
}
.page-info { color: var(--color-muted); font-size: 0.9rem; }

.post h1 {
  margin-bottom: 0.25rem;
  font-size: 2rem;
  line-height: 1.2;
}
.post__subtitle {
  color: var(--color-muted);
  font-size: 1.15rem;
  margin-top: 0;
}
.post__meta {
  color: var(--color-muted);
  font-size: 0.9rem;
}
.post__cover img {
  width: 100%;
  height: auto;
  border-radius: 8px;
  margin: 1rem 0;
}
.post__body img {
  max-width: 100%;
  height: auto;
  border-radius: 6px;
}
.post__body code {
  background: var(--color-tag-bg);
  color: var(--color-text);
  padding: 0.15em 0.4em;
  border-radius: 4px;
  font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", Menlo, monospace;
  font-size: 0.88em;
}
.post__body code.code-multiline {
  display: block;
  white-space: pre;
  overflow-x: auto;
  padding: 1rem;
  border-radius: 0 0 8px 8px;
  line-height: 1.6;
}
.code-block--inline {
  position: relative;
  margin: 1.5rem 0;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  background: var(--color-tag-bg);
}
.code-block-btns {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.3rem;
  padding: 0.3rem 0.4rem;
  border-bottom: 1px solid var(--color-border);
}
.code-block-label {
  margin-right: auto;
  font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", Menlo, monospace;
  font-size: 0.7rem;
  color: var(--color-muted);
  padding-left: 0.2rem;
}
.code-block-btns button {
  position: static !important;
  background: var(--color-input-bg);
  color: var(--color-text);
  border: 1px solid var(--color-border);
  border-radius: 4px;
  padding: 0.15rem 0.45rem;
  font-size: 0.7rem;
  cursor: pointer;
  line-height: 1.4;
}
.code-block-btns button:hover { background: var(--color-tag-bg); }
.post__body { margin-top: 1.5rem; }
.post__body h2, .post__body h3 { margin-top: 2rem; }

.toc {
  border: 1px solid var(--color-border);
  background: var(--color-bg-alt);
  border-radius: 8px;
  padding: 1rem 1.25rem;
  margin: 1.5rem 0;
}
.toc-title {
  margin: 0 0 0.5rem;
  font-weight: 700;
  font-size: 0.9rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--color-muted);
}
.toc ul {
  margin: 0;
  padding-left: 1.1rem;
  list-style: disc;
}
.toc li {
  margin: 0.3rem 0;
  font-size: 0.95rem;
}
.toc li.toc-level-3 { margin-left: 1rem; list-style: circle; }
.toc li.toc-level-4 { margin-left: 2rem; list-style: square; }
.toc a { text-decoration: none; }
.toc a:hover { text-decoration: underline; }

.code-block {
  position: relative;
  margin: 1.5rem 0;
}
.code-block-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: #13131f;
  border-radius: 8px 8px 0 0;
  padding: 0.35rem 0.75rem;
  font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", Menlo, monospace;
}
.code-block-filename {
  flex: 1;
  font-size: 0.8rem;
  color: #aaa;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.code-download-btn {
  background: rgba(255, 255, 255, 0.08);
  color: #ccc;
  border: 1px solid rgba(255, 255, 255, 0.18);
  padding: 0.2rem 0.55rem;
  border-radius: 4px;
  font-size: 0.75rem;
  cursor: pointer;
  white-space: nowrap;
}
.code-download-btn:hover { background: rgba(255, 255, 255, 0.18); color: #fff; }
.code-block pre {
  background: #1e1e2e;
  color: #f1f1f6;
  padding: 1rem;
  border-radius: 8px;
  overflow-x: auto;
  font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", Menlo, monospace;
  font-size: 0.85rem;
  line-height: 1.6;
}
.code-block-header + pre { border-radius: 0 0 8px 8px; margin-top: 0; }
.code-block pre code { font-family: inherit; }
.code-block .code-copy-btn {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.25);
  padding: 0.3rem 0.7rem;
  border-radius: 6px;
  font-size: 0.75rem;
  cursor: pointer;
}
.code-block-header .code-copy-btn { position: static; }
.code-block .code-copy-btn:hover { background: rgba(255, 255, 255, 0.2); }
pre.has-line-numbers { counter-reset: line; }
pre.has-line-numbers .code-line {
  display: block;
  padding-left: 0.25rem;
}
pre.has-line-numbers .code-line::before {
  counter-increment: line;
  content: counter(line);
  display: inline-block;
  width: 2em;
  margin-right: 1em;
  color: #888;
  text-align: right;
  user-select: none;
}

.comments {
  margin-top: 3rem;
  padding-top: 2rem;
  border-top: 1px solid var(--color-border);
}
.comment {
  padding: 1rem 0;
  border-bottom: 1px solid var(--color-border);
}
.comment__meta {
  margin: 0 0 0.25rem;
  font-size: 0.85rem;
  color: var(--color-muted);
}
.comment__meta strong { color: var(--color-text); margin-right: 0.5rem; }
.comment__body { margin: 0; white-space: pre-wrap; }
.comments__empty { color: var(--color-muted); }
.comment-form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  max-width: 500px;
  margin-top: 1rem;
}
.comment-form label { display: flex; flex-direction: column; gap: 0.35rem; font-weight: 600; }
.comment-form input, .comment-form textarea {
  font-family: inherit;
  font-size: 1rem;
  padding: 0.5rem;
  border: 1px solid var(--color-border);
  border-radius: 6px;
}
.comment-form button[type="submit"] {
  align-self: flex-start;
  background: var(--color-accent);
  color: #fff;
  border: none;
  padding: 0.6rem 1.5rem;
  border-radius: 6px;
  cursor: pointer;
}
.captcha-row { display: flex; align-items: center; gap: 0.5rem; }
.captcha-row img { border-radius: 6px; border: 1px solid var(--color-border); }
.captcha-row .captcha-input { flex: 1; }
#captcha-refresh {
  background: var(--color-input-bg);
  color: var(--color-text);
  border: 1px solid var(--color-border);
  border-radius: 6px;
  width: 2.2rem;
  height: 2.2rem;
  cursor: pointer;
  font-size: 1rem;
}

.post__gallery {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 0.75rem;
  margin: 1.5rem 0;
}
.post__gallery img { width: 100%; border-radius: 6px; }

.site-footer {
  border-top: 1px solid var(--color-border);
  padding: 1.5rem 0;
  color: var(--color-muted);
  font-size: 0.85rem;
}

/* Admin */
body.admin { background: var(--color-bg-alt); color: var(--color-text); }
.admin-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 1.5rem 0;
}
.admin-nav-sep { color: var(--color-border); margin: 0 0.4rem; }
.post-search {
  width: 100%;
  max-width: 320px;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  margin-bottom: 1rem;
  display: block;
  background: var(--color-input-bg);
  color: var(--color-text);
}
.admin-table { width: 100%; border-collapse: collapse; }
.admin-table th, .admin-table td {
  text-align: left;
  padding: 0.5rem;
  border-bottom: 1px solid var(--color-border);
}
.button {
  display: inline-block;
  background: var(--color-accent);
  color: #fff;
  padding: 0.5rem 1rem;
  border-radius: 6px;
  text-decoration: none;
  border: none;
  cursor: pointer;
  font-family: inherit;
  font-size: 1rem;
  line-height: 1.4;
  vertical-align: middle;
}
.link-danger {
  background: none;
  border: none;
  color: #c0392b;
  cursor: pointer;
  padding: 0;
}
.post-form { display: flex; flex-direction: column; gap: 1rem; max-width: 700px; }
.post-form label { display: flex; flex-direction: column; gap: 0.35rem; font-weight: 600; }
.post-form input, .post-form textarea, .post-form select {
  font-family: inherit;
  font-size: 1rem;
  padding: 0.5rem;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  background: var(--color-input-bg);
  color: var(--color-text);
}
#editor-body {
  min-height: 32rem;
  resize: vertical;
}
.post-form button {
  align-self: flex-start;
  background: var(--color-accent);
  color: #fff;
  border: none;
  padding: 0.6rem 1.5rem;
  border-radius: 6px;
  cursor: pointer;
}
.form-actions {
  display: flex;
  gap: 0.75rem;
  align-items: stretch;
  flex-wrap: wrap;
  padding-top: 0.5rem;
  border-top: 1px solid var(--color-border);
  margin-top: 0.5rem;
}
.form-actions .button,
.form-actions button {
  flex: 1;
  height: 2.75rem;
  white-space: nowrap;
  text-align: center;
  padding: 0 1rem;
  border-radius: 6px;
  font-size: 0.9rem;
  font-family: inherit;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.button-secondary {
  background: var(--color-bg-alt) !important;
  color: var(--color-text) !important;
  border: 1px solid var(--color-border) !important;
  text-decoration: none;
}
.button-danger {
  background: #c0392b !important;
  color: #fff !important;
  border: none !important;
  cursor: pointer;
}
.thumb { width: 120px; border-radius: 6px; margin: 0.5rem 0.5rem 0 0; }
.editor-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-bottom: 0.35rem;
}
.editor-toolbar button {
  align-self: auto;
  background: var(--color-input-bg);
  color: var(--color-text);
  border: 1px solid var(--color-border);
  padding: 0.35rem 0.65rem;
  border-radius: 6px;
  font-size: 0.85rem;
  cursor: pointer;
}
.editor-toolbar button:hover { background: var(--color-tag-bg); }
.editor-toolbar__right { margin-left: auto; }
#editor-body.no-wrap {
  white-space: pre;
  overflow-x: auto;
}
.hint { font-size: 0.8rem; color: var(--color-muted); font-weight: 400; margin: 0; }
.current-gallery { display: flex; flex-wrap: wrap; }
.error { color: #c0392b; }
.success { color: #1e8449; }
.admin-login { max-width: 320px; margin-top: 4rem; }
.admin-login form { display: flex; flex-direction: column; gap: 1rem; }
