/* ═══════════════════════════════════════════════════════════════
   zhug3.xyz — A minimal, reading-focused blog
   Design: Warm paper aesthetic with editorial typography
   ═══════════════════════════════════════════════════════════════ */

/* CSS Reset & Base */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* Design Tokens */
:root {
  /* Colors — Warm paper palette */
  --color-bg: #f8f6f1;
  --color-text: #1a1a1a;
  --color-muted: #666666;
  --color-accent: #E57A3A;
  --color-border: #e0ddd8;
  --color-hover: #c47428;

  /* Typography */
  --font-serif: 'Georgia', 'Times New Roman', serif;
  --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  --font-mono: 'SF Mono', 'Menlo', 'Monaco', monospace;

  /* Layout */
  --max-width: 640px;
  --padding-x: 24px;
  --header-height: 64px;

  /* Transitions */
  --transition-fast: 150ms ease;
  --transition-medium: 250ms ease;
}

/* Dark Mode */
[data-theme="dark"] {
  --color-bg: #161614;
  --color-text: #e8e6e1;
  --color-muted: #8a8a8a;
  --color-border: #2a2a28;
  --color-hover: #f09a42;
}

/* Base Styles */
html {
  font-size: 18px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

body {
  font-family: var(--font-sans);
  background: var(--color-bg);
  color: var(--color-text);
  line-height: 1.6;
  min-height: 100vh;
  transition: background var(--transition-medium), color var(--transition-medium);
}

/* Skip Link for Accessibility */
.skip-link {
  position: absolute;
  top: -100px;
  left: 0;
  padding: 8px 16px;
  background: var(--color-accent);
  color: white;
  z-index: 1000;
  transition: top var(--transition-fast);
}

.skip-link:focus {
  top: 0;
}

/* ═══════════════════════════════════════════════════════════════
   Header
   ═══════════════════════════════════════════════════════════════ */

.header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--color-bg);
  transition: background var(--transition-medium);
}

.header-inner {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 var(--padding-x);
  height: var(--header-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

/* Logo + Orange Dot */
.logo {
  display: flex;
  align-items: center;
  gap: 6px;
  text-decoration: none;
  color: var(--color-text);
  font-family: var(--font-sans);
  font-size: 1rem;
  font-weight: 500;
  letter-spacing: -0.01em;
}

.logo-dot {
  width: 10px;
  height: 10px;
  background: var(--color-accent);
  border-radius: 50%;
  flex-shrink: 0;
  order: -1;
}

/* Header Right Side */
.header-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Hamburger Menu */
.menu-toggle {
  background: none;
  border: none;
  cursor: pointer;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  transition: opacity var(--transition-fast);
}

.menu-toggle:hover {
  opacity: 0.7;
}

.menu-toggle span {
  display: block;
  width: 16px;
  height: 1.5px;
  background: var(--color-text);
  border-radius: 1px;
  transition: background var(--transition-medium);
}

/* Menu Overlay (mobile only) */
.menu-overlay {
  display: none;
}

@media (max-width: 640px) {
  .menu-overlay {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.3);
    opacity: 0;
    visibility: hidden;
    z-index: 99;
    transition: opacity var(--transition-medium), visibility var(--transition-medium);
  }

  .menu-overlay.open {
    opacity: 1;
    visibility: visible;
  }
}

/* Slide-in Menu Panel */
.menu {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 280px;
  max-width: 80vw;
  background: var(--color-bg);
  border-left: 1px solid var(--color-border);
  padding: 80px 24px 24px;
  transform: translateX(100%);
  visibility: hidden;
  transition:
    transform var(--transition-medium),
    visibility var(--transition-medium),
    background var(--transition-medium),
    border-color var(--transition-medium);
  z-index: 101;
  box-shadow: -4px 0 20px rgba(0, 0, 0, 0.1);
}

.menu.open {
  transform: translateX(0);
  visibility: visible;
}

.menu a {
  display: block;
  padding: 16px 0;
  color: var(--color-text);
  text-decoration: none;
  font-family: var(--font-sans);
  font-size: 1rem;
  border-bottom: 1px solid var(--color-border);
  transition: color var(--transition-fast), border-color var(--transition-medium);
}

.menu a:last-child {
  border-bottom: none;
}

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

/* Desktop: dropdown in blank space */
@media (min-width: 641px) {
  .menu {
    position: absolute;
    top: calc(var(--header-height) + 1px);
    right: calc((100vw - var(--max-width)) / 2);
    bottom: auto;
    width: auto;
    min-width: 160px;
    max-width: none;
    border-left: none;
    border: 1px solid var(--color-border);
    border-radius: 8px;
    padding: 8px 0;
    transform: translateY(-8px);
    opacity: 0;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
  }

  .menu.open {
    transform: translateY(0);
    opacity: 1;
  }

  .menu a {
    padding: 10px 16px;
    font-size: 0.875rem;
    border-bottom: none;
  }

  .menu a:hover {
    background: var(--color-border);
    color: var(--color-text);
  }
}

/* Dark Mode Toggle (Slider) */
.theme-switch {
  position: relative;
  display: inline-block;
  width: 36px;
  height: 18px;
  cursor: pointer;
}

.theme-checkbox {
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  opacity: 0;
  width: 0;
  height: 0;
  position: absolute;
  pointer-events: none;
}

.theme-slider {
  position: absolute;
  inset: 0;
  background: var(--color-border);
  border-radius: 18px;
  transition: background var(--transition-medium);
}

.theme-slider::before {
  content: '';
  position: absolute;
  width: 14px;
  height: 14px;
  left: 2px;
  top: 2px;
  background: var(--color-bg);
  border-radius: 50%;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
  transition: transform var(--transition-medium), background var(--transition-medium);
}

.theme-checkbox:checked + .theme-slider {
  background: var(--color-accent);
}

.theme-checkbox:checked + .theme-slider::before {
  transform: translateX(18px);
}

.theme-switch:hover .theme-slider {
  opacity: 0.9;
}

.theme-checkbox:focus-visible + .theme-slider {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
}

/* ═══════════════════════════════════════════════════════════════
   Main Content
   ═══════════════════════════════════════════════════════════════ */

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

main {
  padding: 72px 0 80px;
}

/* ═══════════════════════════════════════════════════════════════
   Post List (Archive View)
   ═══════════════════════════════════════════════════════════════ */

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

.post-item {
  display: flex;
  gap: 16px;
  padding: 16px 0;
  border-bottom: 1px solid var(--color-border);
  transition: border-color var(--transition-medium);
}

.post-item:first-child {
  padding-top: 0;
}

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

.post-number {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--color-muted);
  flex-shrink: 0;
  width: 44px;
  padding-top: 2px;
  transition: color var(--transition-medium);
}

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

.post-title {
  font-family: var(--font-serif);
  font-size: 1rem;
  font-weight: 600;
  line-height: 1.4;
  margin-bottom: 4px;
}

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

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

.post-excerpt {
  font-family: var(--font-sans);
  font-size: 0.8rem;
  color: var(--color-muted);
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
  overflow: hidden;
  transition: color var(--transition-medium);
}

/* Empty State */
.empty-state {
  text-align: center;
  padding: 80px 0;
  color: var(--color-muted);
  font-family: var(--font-sans);
  font-size: 0.95rem;
}

/* ═══════════════════════════════════════════════════════════════
   Single Post View
   ═══════════════════════════════════════════════════════════════ */

.post-view {
  display: none;
}

.post-view.active {
  display: block;
}

.post-view-header {
  margin-bottom: 32px;
}

.post-view-meta {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 16px;
  font-family: var(--font-sans);
  font-size: 0.875rem;
  color: var(--color-muted);
}

.post-view-number {
  font-family: var(--font-mono);
}

.post-view-date {
  display: none;
}

.post-view-title {
  font-family: var(--font-serif);
  font-size: 2.3rem;
  font-weight: 600;
  line-height: 1.3;
  letter-spacing: -0.02em;
  text-wrap: balance;
}

.post-view-subtitle {
  font-family: var(--font-sans);
  font-size: 1.15rem;
  font-weight: 400;
  line-height: 1.5;
  color: var(--color-muted);
  margin-top: 12px;
  text-wrap: balance;
}

/* Back Link */
.back-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-sans);
  font-size: 0.875rem;
  color: var(--color-muted);
  text-decoration: none;
  margin-bottom: 32px;
  transition: color var(--transition-fast);
}

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

.back-link svg {
  width: 16px;
  height: 16px;
}

/* ═══════════════════════════════════════════════════════════════
   Post Content (Markdown)
   ═══════════════════════════════════════════════════════════════ */

.post-body {
  font-family: var(--font-sans);
  font-size: 1rem;
  line-height: 1.7;
}

.post-body > * + * {
  margin-top: 1.5em;
}

.post-body h1,
.post-body h2,
.post-body h3,
.post-body h4 {
  font-weight: 600;
  line-height: 1.3;
  margin-top: 2em;
}

.post-body h1 { font-size: 1.75rem; }
.post-body h2 { font-size: 1.4rem; }
.post-body h3 { font-size: 1.2rem; }
.post-body h4 { font-size: 1rem; }

.post-body p {
  margin: 0;
}

.post-body a {
  color: var(--color-text);
  text-decoration: underline;
  text-decoration-color: var(--color-accent);
  text-underline-offset: 2px;
  transition: text-decoration-color var(--transition-fast);
}

.post-body a:hover {
  text-decoration-color: var(--color-text);
}

.post-body strong {
  font-weight: 600;
}

.post-body em {
  font-style: italic;
}

.post-body blockquote {
  border-left: 3px solid var(--color-accent);
  padding-left: 20px;
  margin-left: 0;
  color: var(--color-muted);
  font-style: italic;
}

.post-body ul,
.post-body ol {
  padding-left: 1.5em;
}

.post-body li {
  margin: 0.5em 0;
}

.post-body code {
  font-family: var(--font-mono);
  font-size: 0.875em;
  background: var(--color-border);
  padding: 2px 6px;
  border-radius: 4px;
  transition: background var(--transition-medium);
}

.post-body pre {
  background: var(--color-border);
  padding: 16px 20px;
  border-radius: 8px;
  overflow-x: auto;
  transition: background var(--transition-medium);
}

.post-body pre code {
  background: none;
  padding: 0;
}

.post-body img {
  max-width: 100%;
  height: auto;
  border-radius: 4px;
}

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

/* ═══════════════════════════════════════════════════════════════
   Footer
   ═══════════════════════════════════════════════════════════════ */

.footer {
  padding: 24px 0;
  margin-top: 48px;
}

.footer-inner {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 var(--padding-x);
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-family: var(--font-sans);
  font-size: 0.8rem;
  color: var(--color-muted);
}

.footer a {
  color: var(--color-muted);
  text-decoration: none;
  transition: color var(--transition-fast);
}

.footer a:hover {
  color: var(--color-text);
}

/* ═══════════════════════════════════════════════════════════════
   Loading State
   ═══════════════════════════════════════════════════════════════ */

.loading {
  display: flex;
  justify-content: center;
  padding: 48px 0;
}

.loading::after {
  content: '';
  width: 24px;
  height: 24px;
  border: 2px solid var(--color-border);
  border-top-color: var(--color-accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ═══════════════════════════════════════════════════════════════
   Responsive
   ═══════════════════════════════════════════════════════════════ */

@media (max-width: 640px) {
  :root {
    --padding-x: 20px;
  }

  html {
    font-size: 17px;
  }

  .post-item {
    flex-direction: column;
    gap: 8px;
  }

  .post-number {
    width: auto;
  }

  .post-view-title {
    font-size: 1.85rem;
  }
}

/* ═══════════════════════════════════════════════════════════════
   Print Styles
   ═══════════════════════════════════════════════════════════════ */

@media print {
  .header,
  .menu,
  .back-link,
  .footer {
    display: none;
  }

  body {
    background: white;
    color: black;
  }

  .post-body a {
    text-decoration: none;
  }

  .post-body a::after {
    content: " (" attr(href) ")";
    font-size: 0.8em;
    color: #666;
  }
}
