:root {
  --color-bg: #ffffff;
  --color-text: #1a1a1a;
  --color-text-secondary: #666666;
  --color-border: #e5e5e5;
  --color-link: #0066cc;
  --color-link-hover: #0052a3;

  --callout-blue: #3b82f6;
  --callout-green: #10b981;
  --callout-yellow: #f59e0b;
  --callout-red: #ef4444;
  --callout-purple: #8b5cf6;
  --callout-orange: #f97316;
  --callout-gray: #6b7280;
}

@media (prefers-color-scheme: dark) {
  :root {
    --color-bg: #1a1a1a;
    --color-text: #e5e5e5;
    --color-text-secondary: #a3a3a3;
    --color-border: #333333;
    --color-link: #66b3ff;
    --color-link-hover: #99ccff;
  }
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

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

.top-nav {
  background: #1a1a2e;
  border-bottom: 2px solid #2d2d4e;
  padding: 0 20px;
  height: 52px;
  display: flex;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.nav-inner {
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
}

.container {
  max-width: 900px;
  margin: 0 auto;
  padding: 32px 20px;
}

/* Page three-column layout */
.page-layout {
  display: flex;
  gap: 24px;
  max-width: 1500px;
  margin: 0 auto;
  padding: 24px 16px;
  align-items: flex-start;
}

.page-content {
  flex: 1;
  min-width: 0;
}

/* Page TOC */
.page-toc {
  width: 200px;
  flex-shrink: 0;
  position: sticky;
  top: 68px;
  max-height: calc(100vh - 80px);
  overflow-y: auto;
  padding-right: 16px;
  border-right: 1px solid var(--color-border);
  align-self: flex-start;
}

.toc-title {
  font-size: 0.75em;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-text-secondary);
  margin-bottom: 10px;
}

.toc-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.toc-item {
  margin-bottom: 4px;
}

.toc-item a {
  display: block;
  font-size: 0.85em;
  color: var(--color-text-secondary);
  text-decoration: none;
  line-height: 1.4;
  padding: 2px 0;
  transition: color 0.15s;
}

.toc-item a:hover {
  color: var(--color-link);
}

.toc-item a.active {
  color: var(--color-link);
  font-weight: 600;
}

.toc-h2 {
  padding-left: 0;
}

.toc-h3 {
  padding-left: 12px;
}

/* Page sidebar */
.page-sidebar {
  width: 240px;
  flex-shrink: 0;
  position: sticky;
  top: 68px;
  border-left: 1px solid var(--color-border);
  padding-left: 20px;
  min-height: 200px;
}

.sidebar-empty {
  color: var(--color-text-secondary);
  font-size: 0.8em;
  font-style: italic;
  margin: 4px 0;
}

.sidebar-section {
  margin-bottom: 24px;
  padding-bottom: 24px;
  border-bottom: 1px solid var(--color-border);
}

.sidebar-section:last-child {
  border-bottom: none;
  margin-bottom: 0;
}

.sidebar-title {
  font-size: 0.75em;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-text-secondary);
  margin-bottom: 10px;
}

.sidebar-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.sidebar-links {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.sidebar-link {
  display: block;
  font-size: 0.875em;
  color: var(--color-link);
  text-decoration: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-link:hover {
  color: var(--color-link-hover);
  text-decoration: underline;
}

.property-item {
  display: flex;
  flex-direction: column;
  margin-bottom: 8px;
  font-size: 0.875em;
}

.property-key {
  font-weight: 600;
  color: var(--color-text-secondary);
  font-size: 0.85em;
  text-transform: capitalize;
}

.property-value {
  color: var(--color-text);
  margin-top: 2px;
  word-break: break-word;
}

header {
  margin-bottom: 40px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--color-border);
}

header h1 {
  font-size: 2.5em;
  margin-bottom: 10px;
}

.site-title {
  font-size: 1em;
  font-weight: 700;
  text-decoration: none;
  color: #e8e8f0;
  letter-spacing: -0.01em;
}

.site-title:hover {
  color: #ffffff;
}

.description {
  color: var(--color-text-secondary);
  font-size: 1.1em;
}

main {
  margin-bottom: 60px;
}

article h1 {
  font-size: 2em;
  margin-bottom: 10px;
}

.date {
  color: var(--color-text-secondary);
  font-size: 0.9em;
  margin-bottom: 20px;
}

.tags {
  margin-bottom: 20px;
}

.tag {
  display: inline-block;
  background: var(--color-border);
  padding: 4px 12px;
  border-radius: 16px;
  font-size: 0.85em;
  margin-right: 8px;
  margin-bottom: 8px;
}

.content {
  margin-top: 30px;
}

.content h1,
.content h2,
.content h3,
.content h4,
.content h5,
.content h6 {
  margin-top: 1.5em;
  margin-bottom: 0.5em;
}

.content p {
  margin-bottom: 1em;
}

.content a {
  color: var(--color-link);
  text-decoration: none;
}

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

.content ul,
.content ol {
  margin-left: 2em;
  margin-bottom: 1em;
}

.content li {
  margin-bottom: 0.5em;
}

.content pre {
  background: var(--color-border);
  padding: 16px;
  border-radius: 8px;
  overflow-x: auto;
  margin-bottom: 1em;
}

.content code {
  font-family: "SF Mono", Monaco, "Cascadia Code", "Roboto Mono", Consolas, "Courier New", monospace;
  font-size: 0.9em;
}

.content blockquote {
  border-left: 4px solid var(--color-border);
  padding-left: 16px;
  margin: 1em 0;
  color: var(--color-text-secondary);
}

.content img {
  max-width: 100%;
  height: auto;
  border-radius: 8px;
  margin: 1em 0;
  cursor: zoom-in;
}

.lightbox {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 1000;
  align-items: center;
  justify-content: center;
}

.lightbox.active { display: flex; }

.lightbox-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.85);
}

.lightbox-img {
  position: relative;
  z-index: 1;
  max-width: 90vw;
  max-height: 85vh;
  object-fit: contain;
  border-radius: 8px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}

.lightbox-caption {
  position: absolute;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1;
  color: rgba(255,255,255,0.8);
  font-size: 0.9rem;
  white-space: nowrap;
}

.lightbox-close {
  position: absolute;
  top: 1rem;
  right: 1.5rem;
  z-index: 1;
  background: none;
  border: none;
  color: white;
  font-size: 2rem;
  cursor: pointer;
  line-height: 1;
  opacity: 0.7;
}

.lightbox-close:hover { opacity: 1; }

.content table {
  border-collapse: collapse;
  width: 100%;
  margin: 1em 0;
}

.content th,
.content td {
  border: 1px solid var(--color-border);
  padding: 8px 12px;
  text-align: left;
}

.content th {
  background: var(--color-border);
  font-weight: 600;
}

.callout {
  padding: 16px;
  margin: 1em 0;
  border-radius: 8px;
  background: rgba(59, 130, 246, 0.1);
}

/* Collapsible callout (<details>/<summary>) */
details.callout {
  padding: 0;
}

details.callout summary.callout-title {
  padding: 12px 16px;
  cursor: pointer;
  font-weight: 600;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 8px;
  border-radius: 8px;
  user-select: none;
}

details.callout[open] summary.callout-title {
  border-radius: 8px 8px 0 0;
}

details.callout summary.callout-title::before {
  content: '▶';
  font-size: 0.7em;
  transition: transform 0.2s;
  flex-shrink: 0;
}

details.callout[open] summary.callout-title::before {
  transform: rotate(90deg);
}

details.callout summary::-webkit-details-marker {
  display: none;
}

.callout-body {
  padding: 0 16px 16px;
}

.page-list ul {
  list-style: none;
  margin: 0;
}

.page-list li {
  margin-bottom: 20px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--color-border);
}

.page-list li:last-child {
  border-bottom: none;
}

.page-list a {
  font-size: 1.2em;
  font-weight: 600;
  color: var(--color-link);
  text-decoration: none;
}

.page-list a:hover {
  color: var(--color-link-hover);
}

.page-list p {
  margin-top: 8px;
  color: var(--color-text-secondary);
}

.page-list .date {
  display: inline-block;
  margin-top: 8px;
  font-size: 0.85em;
}

footer {
  text-align: center;
  padding: 20px 0;
  color: var(--color-text-secondary);
  font-size: 0.9em;
  border-top: 1px solid var(--color-border);
}

@media (max-width: 1100px) {
  .page-toc {
    display: none;
  }
}

@media (max-width: 900px) {
  .page-layout {
    flex-direction: column;
  }

  .page-sidebar {
    width: 100%;
    position: static;
    border-top: 1px solid var(--color-border);
    border-left: none;
    padding-top: 24px;
    padding-left: 0;
    margin-top: 24px;
  }
}

.tag-list h2 {
  margin-bottom: 20px;
}

/* Hierarchical tag tree */
.tag-tree {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.tag-tree-row {
  display: flex;
  flex-direction: column;
}

.tag-tree-children {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-left: 20px;
  margin-top: 4px;
}

.tag-tree-item {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  background: transparent;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  font-size: 0.875em;
  color: var(--color-text);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  user-select: none;
  width: fit-content;
}

.tag-tree-item:hover {
  background: var(--color-border);
  border-color: var(--color-text-secondary);
}

.tag-tree-connector {
  color: var(--color-text-secondary);
  font-size: 0.85em;
  margin-right: 2px;
}

.tag-tree-name {
  flex: 1;
}

.tag-count {
  display: inline-block;
  background: var(--color-text-secondary);
  color: var(--color-bg);
  border-radius: 5px;
  padding: 1px 7px;
  font-size: 0.75em;
  font-weight: 600;
  min-width: 22px;
  text-align: center;
}

/* Flat tag list on index page */
.tag-flat-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.tag-flat-item {
  display: inline-block;
  padding: 6px 12px;
  background: transparent;
  border: 1px solid var(--color-border);
  border-radius: 20px;
  font-size: 0.875em;
  font-weight: 500;
  color: var(--color-text);
  text-decoration: none;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.tag-flat-item:hover {
  background: var(--color-border);
  border-color: var(--color-text-secondary);
  color: var(--color-text);
}

/* Tag page */
.tag-page-header {
  margin-bottom: 40px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--color-border);
}

.back-link {
  display: inline-block;
  font-size: 0.9em;
  color: var(--color-text-secondary);
  text-decoration: none;
  margin-bottom: 16px;
}

.back-link:hover {
  color: var(--color-text);
}

.tag-page-title {
  font-size: 2em;
  margin-bottom: 6px;
}

.tag-hash {
  color: var(--color-text-secondary);
  font-weight: 400;
}

.tag-page-count {
  color: var(--color-text-secondary);
  font-size: 0.95em;
}

.tag-page-list {
  list-style: none;
  margin: 0;
}

.tag-page-item {
  display: flex;
  align-items: baseline;
  gap: 12px;
  padding: 14px 0;
  border-bottom: 1px solid var(--color-border);
}

.tag-page-item:last-child {
  border-bottom: none;
}

.tag-page-link {
  font-size: 1.05em;
  font-weight: 600;
  color: var(--color-link);
  text-decoration: none;
  flex: 1;
}

.tag-page-link:hover {
  color: var(--color-link-hover);
  text-decoration: underline;
}

/* Sidebar tag links */
.sidebar-tags .tag {
  text-decoration: none;
  color: var(--color-text);
  transition: background 0.15s, border-color 0.15s;
  cursor: pointer;
}

.sidebar-tags .tag:hover {
  background: var(--color-text-secondary);
  color: var(--color-bg);
}

/* Recent Uploads Section */
.recent-uploads {
  margin-bottom: 32px;
}

.recent-uploads h2 {
  font-size: 1.1em;
  font-weight: 600;
  margin-bottom: 12px;
  color: var(--color-text);
}

.recent-uploads-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.recent-upload-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  text-decoration: none;
  color: var(--color-text);
  background: var(--color-bg);
  font-size: 0.85em;
  transition: background 0.15s, border-color 0.15s;
  overflow: hidden;
}

.recent-upload-btn:hover {
  background: var(--color-border);
  border-color: var(--color-link);
}

.recent-upload-num {
  flex-shrink: 0;
  font-weight: 700;
  color: var(--color-text-secondary);
  font-size: 0.9em;
}

.recent-upload-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
