/* Base styles */
:root {
  --color-text: #333;
  --color-text-muted: #666;
  --color-bg: #fff;
  --color-border: #e0e0e0;
  --color-link: #0066cc;
  --color-link-hover: #004499;
  --max-width: 720px;
  --container-width: 80%;
  --container-max-width: 1200px;
  --content-ratio: 0.7;
  --sidenote-ratio: 0.3;
}

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

html {
  height: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.7;
  color: var(--color-text);
  background: var(--color-bg);
  min-height: 100%;
  display: flex;
  flex-direction: column;
}

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

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

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

/* Header */
.site-header {
  border-bottom: 1px solid var(--color-border);
}

.header-inner {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-top: 1rem;
  padding-bottom: 1rem;
}

.header-left {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.header-ticker {
  font-size: 0.75rem;
  color: var(--color-text-muted);
  max-width: 400px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.header-ticker .ticker-label {
  color: var(--color-text-muted);
}

.header-ticker .ticker-item {
  display: none;
  opacity: 0;
  transition: opacity 0.5s ease-in-out;
}

.header-ticker .ticker-item.active {
  display: inline;
  opacity: 1;
}

.header-ticker .ticker-item.fade-out {
  opacity: 0;
}

@media (max-width: 600px) {
  .js-enabled .header-ticker {
    display: none;
  }
}

@media (max-width: 480px) {
  .site-nav {
    display: none;
  }

  .container {
    width: 100%;
  }
}

.site-title {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--color-text);
}

.site-title:hover {
  color: var(--color-link);
  text-decoration: none;
}

.site-nav a {
  margin-left: 1.5rem;
}

/* Main content */
main {
  flex: 1;
  padding: 2rem 0;
}

/* Profile section */
.profile {
  text-align: center;
  margin-top: 2rem;
  margin-bottom: 3rem;
  padding-bottom: 2rem;
  border-bottom: 1px solid var(--color-border);
}

.avatar {
  width: 120px;
  height: 120px;
  border-radius: 50%;
  margin-bottom: 1rem;
}

.profile h1 {
  font-size: 1.5rem;
  margin-bottom: 0.5rem;
}

.bio {
  color: var(--color-text-muted);
}

.profile-links {
  display: flex;
  justify-content: center;
  gap: 1rem;
  margin-top: 1rem;
}

.profile-link {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--color-border);
  color: var(--color-text);
  transition: background 0.2s, color 0.2s;
}

.profile-link:hover {
  background: var(--color-link);
  color: #fff;
  text-decoration: none;
}

.profile-link svg {
  width: 20px;
  height: 20px;
}

/* Post list */
.posts {
  margin-bottom: 3rem;
}

.posts h2 {
  font-size: 1.25rem;
  margin-bottom: 1rem;
}

.post-list {
  list-style: none;
}

.post-list li {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1rem;
  margin-bottom: 0.5rem;
}

.post-list a {
  font-weight: 500;
}

.post-list time {
  font-size: 0.875rem;
  color: var(--color-text-muted);
  white-space: nowrap;
}

/* Post page */
.post-header {
  margin-top: 2rem;
  margin-bottom: 2rem;
}

.post-header h1 {
  font-size: 2rem;
  line-height: 1.3;
  margin-bottom: 0.5rem;
}

.post-header time {
  color: var(--color-text-muted);
  font-size: 0.875rem;
}

.post-content {
  position: relative;
}

.post-content h2 {
  font-size: 1.5rem;
  margin-top: 2rem;
  margin-bottom: 1rem;
}

.post-content h3 {
  font-size: 1.25rem;
  margin-top: 1.5rem;
  margin-bottom: 0.75rem;
}

.post-content p {
  margin-bottom: 1rem;
}

.post-content ul,
.post-content ol {
  margin-bottom: 1rem;
  padding-left: 1.5rem;
}

.post-content li {
  margin-bottom: 0.25rem;
}

.post-content blockquote {
  border-left: 3px solid var(--color-border);
  padding-left: 1rem;
  margin: 1rem 0;
  color: var(--color-text-muted);
}

.post-content pre {
  background: #f5f5f5;
  padding: 1rem;
  overflow-x: auto;
  border-radius: 4px;
  margin-bottom: 1rem;
}

.post-content code {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  font-size: 0.875rem;
}

.post-content p code {
  background: #f5f5f5;
  padding: 0.125rem 0.25rem;
  border-radius: 2px;
}

.post-content img {
  max-width: 100%;
  height: auto;
}

.sidenote-ref {
  font-size: 0.75rem;
  vertical-align: super;
  color: var(--color-link);
  cursor: pointer;
}

/* Sidenotes (inline) - hidden by default, shown by JS on large screens */
.sidenote {
  display: none;
}

/* Header ticker - hidden by default, shown by JS */
.header-ticker {
  display: none;
}

.js-enabled .header-ticker {
  display: block;
}

/* Footnotes section at bottom - shown on small screens */
.footnotes {
  display: block;
  margin-top: 3rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--color-border);
}

.footnotes h2 {
  font-size: 1.25rem;
  margin-bottom: 1rem;
}

.footnotes ol {
  list-style: none;
  padding: 0;
}

.footnotes li {
  font-size: 0.875rem;
  color: var(--color-text-muted);
  margin-bottom: 0.5rem;
  padding-left: 1.5rem;
  position: relative;
}

.footnotes .fn-num {
  position: absolute;
  left: 0;
  color: var(--color-link);
}

/* Post navigation (prev/next) */
.post-nav {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  margin-top: 3rem;
  margin-bottom: 3rem;
  padding-top: 2rem;
  border-top: 1px solid var(--color-border);
}

.post-nav a {
  display: flex;
  flex-direction: column;
  flex: 1;
  padding: 1rem 1.25rem;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  transition: border-color 0.2s, background 0.2s;
}

.post-nav a:hover {
  border-color: var(--color-link);
  background: rgba(0, 102, 204, 0.05);
  text-decoration: none;
}

.post-nav a span {
  font-size: 0.75rem;
  color: var(--color-text-muted);
  margin-bottom: 0.25rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.post-nav .prev {
  text-align: left;
}

.post-nav .next {
  text-align: right;
}

.post-nav .placeholder {
  flex: 1;
}

/* Small screens: stack nav buttons vertically */
@media (max-width: 600px) {
  .post-nav {
    flex-direction: column;
  }

  .post-nav a,
  .post-nav .placeholder {
    width: 100%;
    flex: none;
  }

  .post-nav .next {
    text-align: left;
  }

  .post-nav .placeholder {
    display: none;
  }
}

/* Post layout - 2 column on large screens */
.post-layout {
  display: block;
}

.post-main {
  width: 100%;
}

.post-sidebar {
  display: none;
}

/* Sidenote number styling */
.sidenote-num {
  color: var(--color-link);
  font-weight: 500;
  margin-right: 0.25rem;
}

/* Large screens: 7:3 layout with sidenotes (only when JS enabled) */
@media (min-width: 900px) {
  .post-layout {
    display: flex;
    gap: 2rem;
  }

  .post-main {
    flex: 7;
    min-width: 0;
  }

  .post-sidebar {
    display: block;
    flex: 3;
    padding-top: 0;
  }

  .post-sidebar {
    position: relative;
    border-left: 1px solid var(--color-border);
    padding-left: 2rem;
  }

  /* Sidenotes only shown when JS is enabled */
  .js-enabled .sidenote {
    position: absolute;
    display: block;
    font-size: 0.875rem;
    color: var(--color-text-muted);
    line-height: 1.5;
    /* top is set by JS */
  }

  /* Hide footnotes on large screens only when JS is enabled */
  .js-enabled .footnotes {
    display: none;
  }

  /* Hide empty sidebar when JS is disabled */
  html:not(.js-enabled) .post-sidebar {
    display: none;
  }

  html:not(.js-enabled) .post-main {
    flex: 1;
  }
}

/* Page styles */
.page h1 {
  font-size: 2rem;
  margin-bottom: 1.5rem;
}

.page-content p {
  margin-bottom: 1rem;
}

/* 404 Error page */
.error-page {
  text-align: center;
  padding: 4rem 1rem;
}

.error-page h1 {
  font-size: 6rem;
  font-weight: 700;
  color: var(--color-text-muted);
  margin-bottom: 1rem;
}

.error-page p {
  font-size: 1.25rem;
  color: var(--color-text-muted);
  margin-bottom: 2rem;
}

.error-page a {
  display: inline-block;
  padding: 0.75rem 1.5rem;
  background: var(--color-link);
  color: #fff;
  border-radius: 4px;
}

.error-page a:hover {
  background: var(--color-link-hover);
  text-decoration: none;
}

/* Micro posts page */
.micro-page {
  margin-top: 2rem;
}

.micro-page h1 {
  font-size: 1.5rem;
  margin-bottom: 1.5rem;
}

.micro-posts {
  display: flex;
  flex-direction: column;
}

.micro-post {
  display: flex;
  gap: 0.75rem;
  padding: 1rem;
  border: 1px solid var(--color-border);
  border-bottom: none;
}

.micro-post:first-child {
  border-radius: 8px 8px 0 0;
}

.micro-post:last-child {
  border-bottom: 1px solid var(--color-border);
  border-radius: 0 0 8px 8px;
}

.micro-post:only-child {
  border-radius: 8px;
  border-bottom: 1px solid var(--color-border);
}

.micro-avatar {
  flex-shrink: 0;
}

.micro-avatar img {
  width: 48px;
  height: 48px;
  border-radius: 50%;
}

.micro-body {
  flex: 1;
  min-width: 0;
}

.micro-header {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  margin-bottom: 0.25rem;
}

.micro-name {
  font-weight: 700;
}

.micro-header time {
  font-size: 0.875rem;
  color: var(--color-text-muted);
}

.micro-content {
  line-height: 1.6;
}

/* Small screens: stack name and time vertically */
@media (max-width: 480px) {
  .micro-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 0;
  }

  .micro-header time {
    font-size: 0.75rem;
  }

  .micro-post {
    padding: 1rem 0.25rem;
    border-left: none;
    border-right: none;
    border-radius: 0 !important;
  }

  .micro-posts {
    margin-left: -0.25rem;
    margin-right: -0.25rem;
  }
}

/* Latest micro posts on index */
.latest-micro {
  margin-bottom: 3rem;
}

.latest-micro h2 {
  display: flex;
  align-items: baseline;
  gap: 1rem;
  font-size: 1.25rem;
  margin-bottom: 1rem;
}

.latest-micro h2 .more-link {
  font-size: 0.875rem;
  font-weight: normal;
}

/* Footer */
.site-footer {
  border-top: 1px solid var(--color-border);
  padding: 0.5rem 0;
  text-align: center;
}

.footer-links {
  margin-bottom: 0.5rem;
}

.footer-links a {
  margin: 0 0.75rem;
}

.copyright {
  font-size: 0.875rem;
  color: var(--color-text-muted);
}
