:root {
  --bg-primary: var(--bg, #161821);
  --bg-secondary: var(--bg, #161821);
  --bg-tertiary: color-mix(in srgb, var(--panel, #1e2132) 65%, var(--line, #3e445e) 35%);
  --bg-input: var(--bg-alt, #0f1117);
  --border: var(--line, #3e445e);
  --border-focus: var(--accent, #89b8c2);
  --text-primary: var(--text, #c6c8d1);
  --text-secondary: var(--text-bright, #d2d4de);
  --text-muted: var(--muted, #6b7089);
  --accent: var(--iceberg-cyan, #89b8c2);
  --accent-hover: var(--iceberg-blue, #84a0c6);
  --accent-dim: color-mix(in srgb, var(--iceberg-cyan, #89b8c2) 18%, transparent);
  --success: var(--iceberg-green, #b4be82);
  --warning: var(--iceberg-orange, #e2a478);
  --danger: var(--iceberg-red, #e27878);
  --radius: 8px;
  --font-sans: var(--font-base, "JetBrains Mono", "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif);
  --font-mono: var(--font-base, "JetBrains Mono", "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace);
}

*, *::before, *::after {
  box-sizing: border-box;
}

html {
  font-size: 15px;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-family: var(--font-sans);
  line-height: 1.7;
  text-autospace: normal;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

code, pre, kbd, samp {
  text-autospace: no-autospace;
}

.cjk-space {
  display: inline-block;
  width: 0.22em;
  pointer-events: none;
  user-select: none;
}

::selection {
  background: var(--text-primary);
  color: var(--bg-primary);
}

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

button, input {
  font: inherit;
  color: inherit;
}

.hidden {
  display: none !important;
}

/* Top Navigation Bar (matching /admin/) */
.topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--bg-primary);
}

.topbar-inner {
  max-width: 1180px;
  margin: 0 auto;
  padding: 10px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.site-brand {
  font-weight: 700;
  font-size: 16px;
  color: var(--text-secondary);
  white-space: nowrap;
  letter-spacing: 0.01em;
}
.site-brand:hover {
  color: var(--accent);
  text-decoration: none;
}

.nav-group {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.nav-link {
  padding: 5px 10px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
  border: 1px solid transparent;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}
.nav-link:hover {
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  text-decoration: none;
}
.nav-link.active {
  background: var(--accent-dim);
  border-color: color-mix(in srgb, var(--accent) 45%, transparent);
  color: var(--accent);
}

.search-trigger {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 5px 10px;
  border-radius: 6px;
  background: color-mix(in srgb, var(--panel, #1e2132) 55%, transparent);
  border: none;
  color: var(--text-primary);
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}
.search-trigger:hover {
  background: var(--bg-tertiary);
  color: var(--text-secondary);
}
.kbd-hint {
  font-family: var(--font-mono);
  font-size: 11px;
  padding: 1px 5px;
  border-radius: 4px;
  background: color-mix(in srgb, var(--bg-primary, #161821) 65%, transparent);
  border: none;
  color: var(--text-muted);
}

/* Main Page Grid */
.site-container {
  flex: 1;
  width: 100%;
  max-width: 1180px;
  margin: 0 auto;
  padding: 28px 20px 56px;
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  gap: 32px;
  align-items: start;
}

.site-container.has-toc {
  grid-template-columns: 220px minmax(0, 1fr) 220px;
}

/* Author Sidebar */
.author-card {
  position: sticky;
  top: 74px;
  padding: 0;
}

.author-header {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 12px;
}

.author-avatar-link {
  display: inline-block;
  border-radius: 50%;
  line-height: 0;
}

.author-avatar {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--border);
  transition: border-color 0.15s ease;
}
.author-avatar-link:hover .author-avatar {
  border-color: var(--accent);
}

.author-name {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  color: var(--text-secondary);
}

.author-bio {
  margin: 4px 0 0;
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.5;
}

.author-links {
  list-style: none;
  margin: 16px 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.author-links a {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-primary);
}
.author-links a:hover {
  color: var(--accent);
}
.author-icon {
  width: 15px;
  height: 15px;
  flex-shrink: 0;
  color: var(--text-muted);
  transition: color 0.15s ease;
}
.author-links a:hover .author-icon {
  color: var(--accent);
}

/* Main Content */
.main-content {
  min-width: 0;
}

.page-header {
  margin-bottom: 24px;
  padding-bottom: 0;
}

.page-title {
  margin: 0;
  font-size: 22px;
  font-weight: 700;
  color: var(--text-secondary);
  line-height: 1.35;
}

.page-subtitle {
  margin: 4px 0 0;
  font-size: 13px;
  color: var(--text-muted);
}

/* Post List */
.post-cards {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.post-card {
  display: grid;
  grid-template-columns: 100px minmax(0, 1fr);
  gap: 4px 20px;
  align-items: baseline;
  padding: 12px 14px;
  margin: 0 -14px;
  border-radius: 8px;
  cursor: pointer;
  transition: background-color 0.15s ease;
}
.post-card:hover {
  background: color-mix(in srgb, var(--panel, #1e2132) 55%, transparent);
}
.post-card:hover .post-card-title a {
  color: var(--accent);
}

.post-card-date {
  font-family: var(--font-mono);
  font-size: 12.5px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  line-height: 1.5;
}

.post-card-body {
  min-width: 0;
}

.post-card-title {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  line-height: 1.4;
}
.post-card-title a {
  color: var(--text-secondary);
}
.post-card-title a:hover {
  color: var(--accent);
  text-decoration: none;
}

.post-meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 12px;
  font-size: 12px;
  color: var(--text-muted);
}

.meta-mono {
  font-family: var(--font-mono);
}

.post-excerpt {
  margin: 6px 0 0;
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.6;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

.chip {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  font-size: 11.5px;
  font-family: var(--font-mono);
  background: var(--bg-input);
  border-radius: 5px;
  color: var(--text-muted);
}
a.chip:hover {
  color: var(--accent);
  text-decoration: none;
}
.chip.cat {
  color: var(--accent);
}

/* Pagination */
.pagination {
  margin-top: 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg-secondary);
  color: var(--text-primary);
  font-size: 13px;
  cursor: pointer;
  text-decoration: none;
}
.btn:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent);
  text-decoration: none;
}
.btn:disabled, .btn.disabled {
  opacity: 0.45;
  pointer-events: none;
}

/* Archives (Posts by Year / Category / Tag) */
.taxonomy-index {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 24px;
}

.taxonomy-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--bg-input);
  font-size: 12.5px;
  color: var(--text-primary);
}
.taxonomy-pill:hover, .taxonomy-pill.active {
  color: var(--accent);
  background: var(--accent-dim);
  text-decoration: none;
}
.taxonomy-count {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-muted);
}

.archive-group {
  margin-bottom: 28px;
}
.archive-group-title {
  margin: 0 0 10px;
  font-size: 16px;
  font-weight: 700;
  color: var(--text-secondary);
  scroll-margin-top: 74px;
}

.archive-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.archive-item {
  display: flex;
  align-items: baseline;
  gap: 16px;
  padding: 8px 12px;
  margin: 0 -12px;
  border-radius: 6px;
  cursor: pointer;
  transition: background-color 0.15s ease;
}
.archive-item:hover {
  background: color-mix(in srgb, var(--panel, #1e2132) 55%, transparent);
}
.archive-item:hover .archive-link {
  color: var(--accent);
}
.archive-date {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
}
.archive-link {
  font-weight: 600;
  font-size: 14px;
  color: var(--text-secondary);
}
.archive-link:hover {
  color: var(--accent);
}

/* Single Post View */
.article-card {
  padding: 0;
}

.article-header {
  padding-bottom: 0;
  margin-bottom: 28px;
}

.article-title {
  margin: 0 0 10px;
  font-size: 26px;
  font-weight: 700;
  line-height: 1.35;
  color: var(--text-secondary);
}

/* Sticky Table of Contents */
.toc-sidebar {
  position: sticky;
  top: 74px;
  padding: 0 0 0 12px;
  max-height: calc(100vh - 96px);
  overflow-y: auto;
}

.toc-inline {
  display: none;
  margin-bottom: 24px;
  padding: 0 0 0 12px;
}

.toc-title {
  margin: 0 0 10px;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.toc-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.toc-link {
  display: block;
  font-size: 12.5px;
  line-height: 1.45;
  color: var(--text-primary);
  padding: 2px 0;
}
.toc-link:hover {
  color: var(--accent);
  text-decoration: none;
}
.toc-level-3 { padding-left: 12px; font-size: 12px; color: var(--text-muted); }
.toc-level-4 { padding-left: 22px; font-size: 11.5px; color: var(--text-muted); }

/* Markdown Body */
.markdown-body {
  font-size: 15px;
  line-height: 1.8;
  color: var(--text-primary);
  word-wrap: break-word;
}

.markdown-body > *:first-child {
  margin-top: 0;
}

.markdown-body h1,
.markdown-body h2,
.markdown-body h3,
.markdown-body h4 {
  margin-top: 1.6em;
  margin-bottom: 0.65em;
  color: var(--text-secondary);
  font-weight: 700;
  line-height: 1.35;
  scroll-margin-top: 76px;
}

.markdown-body h2 {
  font-size: 1.35em;
  padding-bottom: 0.3em;
  border-bottom: 1px solid var(--border);
}

.markdown-body h3 {
  font-size: 1.15em;
}

.markdown-body p {
  margin: 0 0 1.1em;
}

.markdown-body ul,
.markdown-body ol {
  margin: 0 0 1.1em;
  padding-left: 1.6em;
}

.markdown-body li {
  margin: 0.25em 0;
}

.markdown-body code {
  font-family: var(--font-mono);
  font-size: 0.88em;
  background: var(--bg-input);
  border: 1px solid color-mix(in srgb, var(--border) 60%, transparent);
  padding: 1px 5px;
  margin-inline: 0.18em;
  border-radius: 4px;
}

.code-block-wrap {
  position: relative;
  margin: 1.1em 0;
}

.code-copy-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  padding: 2px 8px;
  font-size: 11px;
  font-family: var(--font-mono);
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-muted);
  cursor: pointer;
  opacity: 0.75;
  transition: opacity 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}
.code-block-wrap:hover .code-copy-btn {
  opacity: 1;
}
.code-copy-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.markdown-body pre {
  margin: 0;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 14px 16px;
  overflow-x: auto;
  line-height: 1.55;
}

.markdown-body pre code {
  background: transparent;
  border: none;
  padding: 0;
  margin-inline: 0;
  font-size: 13px;
}

.markdown-body blockquote {
  margin: 1.1em 0;
  padding: 8px 16px;
  border-left: 4px solid var(--accent);
  background: var(--bg-input);
  border-radius: 0 6px 6px 0;
  color: var(--text-primary);
}
.markdown-body blockquote > *:last-child {
  margin-bottom: 0;
}

.markdown-body img {
  max-width: 100%;
  height: auto;
  border-radius: 6px;
  border: 1px solid var(--border);
}

.markdown-body table {
  width: 100%;
  border-collapse: collapse;
  margin: 1.2em 0;
  font-size: 14px;
}
.markdown-body th,
.markdown-body td {
  border: 1px solid var(--border);
  padding: 8px 12px;
  text-align: left;
}
.markdown-body th {
  background: var(--bg-input);
  color: var(--text-secondary);
}

.markdown-body hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 1.8em 0;
}

/* highlight.js mapped to Iceberg CSS custom properties */
.hljs {
  background: var(--iceberg-bg-dark, #0f1117);
  color: var(--iceberg-fg, #c6c8d1);
}
.hljs-comment,
.hljs-quote {
  color: var(--iceberg-muted, #6b7089);
  font-style: italic;
}
.hljs-keyword,
.hljs-selector-tag,
.hljs-operator,
.hljs-title.class_,
.hljs-type {
  color: var(--iceberg-blue, #84a0c6);
}
.hljs-title,
.hljs-title.function_,
.hljs-built_in,
.hljs-attribute,
.hljs-attr,
.hljs-property,
.hljs-string,
.hljs-regexp,
.hljs-symbol,
.hljs-bullet,
.hljs-link {
  color: var(--iceberg-cyan, #89b8c2);
}
.hljs-subst,
.hljs-char.escape_ {
  color: var(--iceberg-purple, #a093c7);
}
.hljs-number,
.hljs-literal,
.hljs-meta,
.hljs-variable,
.hljs-template-variable {
  color: var(--iceberg-orange, #e2a478);
}
.hljs-deletion {
  color: var(--iceberg-red, #e27878);
  background: color-mix(in srgb, var(--iceberg-red, #e27878) 20%, transparent);
}
.hljs-addition {
  color: var(--iceberg-green, #b4be82);
  background: color-mix(in srgb, var(--iceberg-green, #b4be82) 20%, transparent);
}
.hljs-emphasis {
  font-style: italic;
}
.hljs-strong {
  font-weight: 700;
}

/* Post Footer: Share, Prev/Next, Related */
.article-footer {
  margin-top: 28px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.share-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.share-label {
  font-size: 12px;
  color: var(--text-muted);
  margin-right: 4px;
}

.post-nav {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.post-nav-card {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 4px 0;
}
.post-nav-card:hover .post-nav-title {
  color: var(--accent);
}
.post-nav-card:hover {
  text-decoration: none;
}
.post-nav-card.next {
  text-align: right;
}
.post-nav-label {
  font-size: 11px;
  color: var(--text-muted);
  font-family: var(--font-mono);
}
.post-nav-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
}

.related-section {
  margin-top: 28px;
}
.related-heading {
  margin: 0 0 12px;
  font-size: 15px;
  font-weight: 700;
  color: var(--text-secondary);
}
.related-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 16px;
}
.related-card {
  padding: 4px 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.related-card:hover .related-card-title {
  color: var(--accent);
}
.related-card:hover {
  text-decoration: none;
}
.related-card-title {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text-secondary);
  line-height: 1.4;
}
.related-card-date {
  font-size: 11.5px;
  font-family: var(--font-mono);
  color: var(--text-muted);
}

/* Search Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: color-mix(in srgb, var(--bg-input) 78%, transparent);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 64px 16px 16px;
  z-index: 1000;
}

.search-modal {
  width: 100%;
  max-width: 600px;
  background: var(--panel, #1e2132);
  border: none;
  border-radius: 10px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.6);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  max-height: 75vh;
}

.search-modal-head {
  padding: 14px 14px 6px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.search-modal-input {
  flex: 1;
  padding: 8px 12px;
  background: var(--bg-input);
  border: none;
  border-radius: 6px;
  outline: none;
  font-size: 14px;
  transition: background 0.15s ease;
}
.search-modal-input:focus {
  background: var(--bg-primary);
}

.search-modal-head .btn {
  border: none;
  background: transparent;
  color: var(--text-muted);
  transition: background 0.15s ease, color 0.15s ease;
}
.search-modal-head .btn:hover:not(:disabled) {
  background: var(--bg-tertiary);
  color: var(--text-secondary);
}

.search-results {
  padding: 8px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.search-result-item {
  display: block;
  padding: 10px 12px;
  border-radius: 6px;
  transition: background-color 0.15s ease;
}
.search-result-item:hover {
  background: color-mix(in srgb, var(--bg-tertiary) 65%, transparent);
  text-decoration: none;
}
.search-result-item:hover .search-result-title {
  color: var(--accent);
}
.search-result-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-secondary);
}
.search-result-snippet {
  margin-top: 3px;
  font-size: 12px;
  color: var(--text-muted);
}

.empty-state {
  padding: 28px 18px;
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
}

/* 404 Not Found */
.not-found {
  padding: 48px 0 32px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
}

.not-found-code {
  margin: 0;
  font-family: var(--font-mono);
  font-size: 56px;
  font-weight: 700;
  line-height: 1;
  letter-spacing: 0.04em;
  color: var(--accent);
  opacity: 0.85;
}

.not-found-title {
  margin: 14px 0 10px;
  font-size: 22px;
  font-weight: 700;
  color: var(--text-secondary);
}

.not-found-desc {
  margin: 0 0 24px;
  font-size: 14px;
  color: var(--text-muted);
  line-height: 1.75;
}

.not-found-path {
  display: inline-block;
  margin-bottom: 22px;
  padding: 3px 9px;
  border-radius: 5px;
  background: var(--bg-input);
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-muted);
  word-break: break-all;
}

.not-found-home-btn {
  background: color-mix(in srgb, var(--panel, #1e2132) 75%, transparent);
  color: var(--text-secondary);
  padding: 9px 16px;
  border-radius: 8px;
  font-size: 13.5px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  transition: background 0.15s ease, color 0.15s ease;
}
.not-found-home-btn:hover {
  background: var(--bg-tertiary);
  color: var(--accent);
  text-decoration: none;
}

.not-found-home-icon {
  width: 15px;
  height: 15px;
  flex-shrink: 0;
}

/* Site Footer */
.site-footer {
  background: var(--bg-secondary);
}

.site-footer-inner {
  max-width: 1180px;
  margin: 0 auto;
  padding: 18px 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  font-size: 12.5px;
  color: var(--text-muted);
}

/* Responsive Breakpoints */
@media (max-width: 1080px) {
  .site-container.has-toc {
    grid-template-columns: 200px minmax(0, 1fr);
  }
  .toc-sidebar {
    display: none;
  }
  .toc-inline {
    display: block;
  }
}

@media (max-width: 820px) {
  .site-container,
  .site-container.has-toc {
    grid-template-columns: minmax(0, 1fr);
    gap: 20px;
    padding: 20px 16px 40px;
  }
  .author-card {
    position: static;
  }
  .author-header {
    flex-direction: row;
    align-items: center;
  }
  .author-avatar {
    width: 56px;
    height: 56px;
  }
  .author-links {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 8px 16px;
  }
  .article-card {
    padding: 0;
  }
  .post-card {
    grid-template-columns: minmax(0, 1fr);
    padding: 10px 12px;
    margin: 0 -12px;
  }
  .article-title {
    font-size: 22px;
  }
  .post-nav {
    grid-template-columns: minmax(0, 1fr);
  }
  .post-nav-card.next {
    text-align: left;
  }
  .kbd-hint {
    display: none;
  }
}
