/* Tokyo Night Color Palette - Dark (default) */
:root {
  /* Background colors */
  --tn-bg: #1a1b26;
  --tn-bg-dark: #16161e;
  --tn-bg-highlight: #292e42;
  --tn-terminal-black: #414868;

  /* Foreground colors */
  --tn-fg: #c0caf5;
  --tn-fg-dark: #a9b1d6;
  --tn-fg-gutter: #3b4261;

  /* Accent colors */
  --tn-blue: #7aa2f7;
  --tn-cyan: #7dcfff;
  --tn-magenta: #bb9af7;
  --tn-purple: #9d7cd8;
  --tn-orange: #ff9e64;
  --tn-yellow: #e0af68;
  --tn-green: #9ece6a;
  --tn-teal: #73daca;
  --tn-red: #f7768e;

  /* UI colors */
  --tn-border: #29293d;
  --tn-selection: #364a82;

  /* Semantic mappings */
  --color-background: var(--tn-bg);
  --color-foreground: var(--tn-fg);
  --color-muted: var(--tn-fg-dark);
  --color-accent: var(--tn-blue);
  --color-accent-hover: var(--tn-cyan);
  --color-border: var(--tn-border);
  --color-code-bg: var(--tn-bg-dark);
  --color-selection: var(--tn-selection);

  /* Typography */
  --font-sans: 'IBM Plex Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-serif: 'IBM Plex Serif', Georgia, 'Times New Roman', serif;
  --font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, 'SF Mono', Menlo, monospace;

  /* Spacing */
  --spacing-xs: 0.25rem;
  --spacing-sm: 0.5rem;
  --spacing-md: 1rem;
  --spacing-lg: 1.5rem;
  --spacing-xl: 2rem;
  --spacing-2xl: 3rem;
  --spacing-3xl: 4rem;

  /* Layout */
  --max-width: 720px;
  --header-height: 4rem;

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

/* Tokyo Night Day (Light Mode) */
[data-theme="light"] {
  --tn-bg: #d5d6db;
  --tn-bg-dark: #e9e9ec;
  --tn-bg-highlight: #c4c5ca;
  --tn-terminal-black: #9699a3;

  --tn-fg: #343b58;
  --tn-fg-dark: #565a6e;
  --tn-fg-gutter: #9699a3;

  --tn-blue: #34548a;
  --tn-cyan: #0f4b6e;
  --tn-magenta: #5a4a78;
  --tn-purple: #5a4a78;
  --tn-orange: #965027;
  --tn-yellow: #8f5e15;
  --tn-green: #485e30;
  --tn-teal: #166775;
  --tn-red: #8c4351;

  --tn-border: #b4b5b9;
  --tn-selection: #b6bfe2;

  --color-background: var(--tn-bg);
  --color-foreground: var(--tn-fg);
  --color-muted: var(--tn-fg-dark);
  --color-accent: var(--tn-blue);
  --color-accent-hover: var(--tn-cyan);
  --color-border: var(--tn-border);
  --color-code-bg: var(--tn-bg-dark);
  --color-selection: var(--tn-selection);
}

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

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

body {
  font-family: var(--font-sans);
  font-size: 1rem;
  line-height: 1.7;
  color: var(--color-foreground);
  background-color: var(--color-background);
  min-height: 100vh;
}

::selection {
  background-color: var(--color-selection);
}

/* Container */
.container {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 var(--spacing-lg);
}

/* Site Header */
.site-header {
  padding: var(--spacing-xl) 0;
  border-bottom: 1px solid var(--color-border);
  margin-bottom: var(--spacing-2xl);
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: var(--spacing-md);
}

.header-left {
  display: flex;
  align-items: center;
}

.header-right {
  display: flex;
  align-items: center;
  gap: var(--spacing-lg);
  flex-wrap: wrap;
}

.site-header .site-title {
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--color-foreground);
  text-decoration: none;
  letter-spacing: -0.02em;
  display: inline-flex;
  align-items: center;
  gap: var(--spacing-sm);
}

.site-header .site-title:hover {
  color: var(--color-accent);
}

/* Site Logo - Terminal Icon */
.site-logo {
  display: inline-flex;
  align-items: center;
  position: relative;
}

.site-logo svg {
  width: 24px;
  height: 24px;
  color: var(--tn-green);
  transition: color var(--transition-fast);
}

.site-header .site-title:hover .site-logo svg {
  color: var(--tn-cyan);
}

.site-logo .cursor {
  position: absolute;
  right: -2px;
  bottom: 4px;
  width: 8px;
  height: 2px;
  background-color: var(--tn-green);
  animation: blink 1s step-end infinite;
}

.site-header .site-title:hover .site-logo .cursor {
  background-color: var(--tn-cyan);
}

@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}

/* Header Actions */
.header-actions {
  display: flex;
  align-items: center;
  gap: var(--spacing-sm);
}

.search-toggle,
.theme-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  background: transparent;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  color: var(--color-muted);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.search-toggle:hover,
.theme-toggle:hover {
  background-color: var(--tn-bg-highlight);
  color: var(--color-foreground);
  border-color: var(--tn-terminal-black);
}

.theme-toggle .moon-icon {
  display: none;
}

/* Reading Progress Bar */
.reading-progress {
  position: fixed;
  top: 0;
  left: 0;
  width: 0%;
  height: 3px;
  background: linear-gradient(90deg, var(--tn-blue), var(--tn-purple), var(--tn-magenta));
  z-index: 1000;
  transition: width 50ms ease-out;
}

.site-header nav {
  display: flex;
  align-items: center;
  gap: var(--spacing-lg);
}

.site-header nav a {
  color: var(--color-muted);
  text-decoration: none;
  font-size: 0.9rem;
  transition: color var(--transition-fast);
}

.site-header nav a:hover {
  color: var(--color-accent);
}

/* Site Main */
.site-main {
  min-height: calc(100vh - 20rem);
}

/* Site Footer */
.site-footer {
  padding: var(--spacing-2xl) 0;
  margin-top: var(--spacing-3xl);
  border-top: 1px solid var(--color-border);
  color: var(--color-muted);
  font-size: 0.875rem;
}

/* Typography */
h1, h2, h3, h4, h5, h6 {
  font-weight: 600;
  line-height: 1.3;
  letter-spacing: -0.02em;
  color: var(--color-foreground);
}

h1 { font-size: 2.25rem; margin-bottom: var(--spacing-lg); }
h2 { font-size: 1.5rem; margin-top: var(--spacing-2xl); margin-bottom: var(--spacing-md); }
h3 { font-size: 1.25rem; margin-top: var(--spacing-xl); margin-bottom: var(--spacing-sm); }
h4 { font-size: 1.1rem; margin-top: var(--spacing-lg); margin-bottom: var(--spacing-sm); }

p {
  margin-bottom: var(--spacing-lg);
}

/* Links */
a {
  color: var(--color-accent);
  text-decoration: none;
  transition: color var(--transition-fast);
}

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

/* Lists */
ul, ol {
  margin-bottom: var(--spacing-lg);
  padding-left: var(--spacing-xl);
}

li {
  margin-bottom: var(--spacing-sm);
}

li::marker {
  color: var(--color-muted);
}

/* Blockquote */
blockquote {
  border-left: 3px solid var(--tn-purple);
  padding-left: var(--spacing-lg);
  margin: var(--spacing-lg) 0;
  color: var(--color-muted);
  font-style: italic;
}

blockquote p:last-child {
  margin-bottom: 0;
}

/* Horizontal Rule */
hr {
  border: none;
  border-top: 1px solid var(--color-border);
  margin: var(--spacing-2xl) 0;
}

/* Images */
img {
  max-width: 100%;
  height: auto;
  border-radius: 8px;
  margin: var(--spacing-lg) 0;
}

figure {
  margin: var(--spacing-xl) 0;
}

figure img {
  margin: 0;
}

figcaption {
  margin-top: var(--spacing-sm);
  font-size: 0.875rem;
  color: var(--color-muted);
  text-align: center;
}

/* Inline Code */
code {
  font-family: var(--font-mono);
  font-size: 0.875em;
  background-color: var(--color-code-bg);
  padding: 0.2em 0.4em;
  border-radius: 4px;
  color: var(--tn-cyan);
}

/* Code Blocks */
pre {
  font-family: var(--font-mono);
  font-size: 0.875rem;
  line-height: 1.6;
  background-color: var(--color-code-bg);
  border-radius: 8px;
  padding: var(--spacing-lg);
  margin: var(--spacing-lg) 0;
  overflow-x: auto;
  border: 1px solid var(--color-border);
}

pre code {
  background: none;
  padding: 0;
  border-radius: 0;
  color: inherit;
  font-size: inherit;
}

/* Remove border/margin from pre inside .highlight (syntax.css handles the wrapper) */
.highlight pre {
  border: none;
  margin: 0;
  border-radius: 0;
}

/* Copy Code Button */
.copy-code-button {
  position: absolute;
  top: 8px;
  right: 8px;
  padding: 6px;
  background-color: var(--tn-bg-highlight);
  border: 1px solid var(--color-border);
  border-radius: 6px;
  color: var(--color-muted);
  cursor: pointer;
  opacity: 0;
  transition: opacity var(--transition-fast), background-color var(--transition-fast), color var(--transition-fast);
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
}

.highlight:hover .copy-code-button {
  opacity: 1;
}

.copy-code-button:hover {
  background-color: var(--tn-terminal-black);
  color: var(--color-foreground);
}

.copy-code-button:active {
  transform: scale(0.95);
}

.copy-code-button .copy-icon,
.copy-code-button .check-icon {
  width: 16px;
  height: 16px;
}

.copy-code-button .check-icon {
  display: none;
  color: var(--tn-green);
}

.copy-code-button.copied .copy-icon {
  display: none;
}

.copy-code-button.copied .check-icon {
  display: block;
}

.copy-code-button.copied {
  opacity: 1;
  background-color: var(--tn-bg-highlight);
}

/* Tables */
table {
  width: 100%;
  border-collapse: collapse;
  margin: var(--spacing-lg) 0;
  font-size: 0.9rem;
}

th, td {
  padding: var(--spacing-sm) var(--spacing-md);
  text-align: left;
  border-bottom: 1px solid var(--color-border);
}

th {
  font-weight: 600;
  color: var(--color-foreground);
}

tr:hover {
  background-color: var(--tn-bg-highlight);
}

/* Table of Contents */
.toc {
  margin-bottom: var(--spacing-2xl);
  padding: var(--spacing-lg);
  background-color: var(--tn-bg-dark);
  border: 1px solid var(--color-border);
  border-radius: 8px;
}

.toc details {
  margin: 0;
}

.toc summary {
  cursor: pointer;
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--color-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  list-style: none;
  display: flex;
  align-items: center;
  gap: var(--spacing-sm);
}

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

.toc summary::before {
  content: '';
  width: 0;
  height: 0;
  border-left: 5px solid var(--tn-cyan);
  border-top: 4px solid transparent;
  border-bottom: 4px solid transparent;
  transition: transform var(--transition-fast);
}

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

.toc nav {
  margin-top: var(--spacing-md);
}

.toc ul {
  margin: 0;
  padding-left: var(--spacing-lg);
  list-style: none;
}

.toc > details > nav > ul {
  padding-left: 0;
}

.toc li {
  margin-bottom: var(--spacing-xs);
  line-height: 1.4;
}

.toc a {
  color: var(--color-muted);
  font-size: 0.9rem;
  text-decoration: none;
  transition: color var(--transition-fast);
}

.toc a:hover {
  color: var(--tn-cyan);
}

/* Nested TOC levels */
.toc ul ul {
  margin-top: var(--spacing-xs);
}

.toc ul ul a {
  font-size: 0.85rem;
}

/* Post List */
.post-list {
  list-style: none;
  padding: 0;
}

.post-list-item {
  margin-bottom: var(--spacing-xl);
  padding-bottom: var(--spacing-xl);
  border-bottom: 1px solid var(--color-border);
}

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

.post-list-item h2 {
  margin-top: 0;
  margin-bottom: var(--spacing-sm);
  font-size: 1.25rem;
}

.post-list-item h2 a {
  color: var(--color-foreground);
}

.post-list-item h2 a:hover {
  color: var(--color-accent);
}

.post-meta {
  font-size: 0.875rem;
  color: var(--color-muted);
  margin-bottom: var(--spacing-sm);
}

.post-summary {
  color: var(--color-muted);
  margin-bottom: 0;
}

/* Single Post */
.post-header {
  margin-bottom: var(--spacing-2xl);
}

.post-header h1 {
  margin-bottom: var(--spacing-sm);
}

.post-content {
  margin-bottom: var(--spacing-2xl);
}

/* Tags */
.post-tags {
  display: flex;
  flex-wrap: wrap;
  gap: var(--spacing-sm);
  margin-top: var(--spacing-xl);
}

.tag {
  display: inline-block;
  padding: var(--spacing-xs) var(--spacing-sm);
  background-color: var(--tn-bg-highlight);
  color: var(--tn-magenta);
  border-radius: 4px;
  font-size: 0.8rem;
  text-decoration: none;
  transition: background-color var(--transition-fast);
}

.tag:hover {
  background-color: var(--color-selection);
  color: var(--tn-magenta);
}

/* Home Page Hero */
.hero {
  margin-bottom: var(--spacing-2xl);
  padding-bottom: var(--spacing-2xl);
  border-bottom: 1px solid var(--color-border);
}

.hero-description {
  font-family: var(--font-serif);
  font-size: 1.25rem;
  font-style: italic;
  color: var(--color-muted);
  margin: 0 0 var(--spacing-md) 0;
}

.hero-bio {
  font-size: 0.95rem;
  color: var(--color-foreground);
  margin: 0;
}

.section-title {
  font-size: 0.875rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-muted);
  margin-bottom: var(--spacing-lg);
}

/* Keyboard */
kbd {
  display: inline-block;
  padding: 0.15em 0.4em;
  font-family: var(--font-mono);
  font-size: 0.85em;
  color: var(--color-foreground);
  background-color: var(--tn-bg-highlight);
  border: 1px solid var(--color-border);
  border-radius: 4px;
  box-shadow: 0 1px 0 var(--tn-terminal-black);
}

/* Mark/Highlight */
mark {
  background-color: var(--tn-yellow);
  color: var(--tn-bg);
  padding: 0.1em 0.3em;
  border-radius: 2px;
}

/* Abbreviation */
abbr[title] {
  text-decoration: underline dotted var(--tn-cyan);
  cursor: help;
}

/* Definition List */
dl {
  margin-bottom: var(--spacing-lg);
}

dt {
  font-weight: 600;
  color: var(--tn-cyan);
  margin-top: var(--spacing-md);
}

dd {
  margin-left: var(--spacing-lg);
  color: var(--color-muted);
}

/* Footnotes */
.footnotes {
  margin-top: var(--spacing-3xl);
  padding-top: var(--spacing-xl);
  border-top: 1px solid var(--color-border);
  font-size: 0.9rem;
  color: var(--color-muted);
}

.footnotes ol {
  padding-left: var(--spacing-lg);
}

.footnotes li {
  margin-bottom: var(--spacing-sm);
}

.footnote-ref {
  font-size: 0.75em;
  vertical-align: super;
}

.footnote-backref {
  margin-left: var(--spacing-xs);
}

/* Task Lists */
ul:has(input[type="checkbox"]) {
  list-style: none;
  padding-left: 0;
}

input[type="checkbox"] {
  margin-right: var(--spacing-sm);
  accent-color: var(--tn-green);
}

/* Nested Blockquotes */
blockquote blockquote {
  margin-left: var(--spacing-md);
  border-left-color: var(--tn-cyan);
}

blockquote blockquote blockquote {
  border-left-color: var(--tn-green);
}

/* Search Modal */
.search-modal {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: none;
}

.search-modal.active {
  display: block;
}

.search-modal-backdrop {
  position: absolute;
  inset: 0;
  background-color: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
}

.search-modal-content {
  position: relative;
  max-width: 600px;
  margin: 10vh auto 0;
  background-color: var(--tn-bg-dark);
  border: 1px solid var(--color-border);
  border-radius: 12px;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
  overflow: hidden;
}

.search-input-wrapper {
  display: flex;
  align-items: center;
  padding: var(--spacing-md) var(--spacing-lg);
  border-bottom: 1px solid var(--color-border);
  gap: var(--spacing-md);
}

.search-input-wrapper .search-icon {
  color: var(--color-muted);
  flex-shrink: 0;
}

.search-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  font-size: 1rem;
  font-family: var(--font-sans);
  color: var(--color-foreground);
}

.search-input::placeholder {
  color: var(--color-muted);
}

.search-kbd {
  padding: 0.2em 0.5em;
  font-size: 0.75rem;
  background-color: var(--tn-bg-highlight);
  border: 1px solid var(--color-border);
  border-radius: 4px;
  color: var(--color-muted);
}

.search-results {
  max-height: 400px;
  overflow-y: auto;
  padding: var(--spacing-sm);
}

.search-hint,
.search-no-results {
  padding: var(--spacing-lg);
  text-align: center;
  color: var(--color-muted);
  font-size: 0.9rem;
}

.search-result-item {
  display: block;
  padding: var(--spacing-md) var(--spacing-lg);
  border-radius: 8px;
  text-decoration: none;
  transition: background-color var(--transition-fast);
}

.search-result-item:hover {
  background-color: var(--tn-bg-highlight);
}

.search-result-title {
  display: block;
  font-weight: 500;
  color: var(--color-foreground);
  margin-bottom: var(--spacing-xs);
}

.search-result-description {
  display: block;
  font-size: 0.875rem;
  color: var(--color-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Code Block Filename */
.code-filename {
  display: flex;
  align-items: center;
  padding: var(--spacing-sm) var(--spacing-lg);
  background-color: var(--tn-terminal-black);
  border-bottom: 1px solid var(--color-border);
  border-radius: 8px 8px 0 0;
  margin-bottom: -1px;
}

.code-filename-text {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--color-muted);
}

.highlight.has-filename pre {
  border-radius: 0 0 8px 8px;
}

.highlight.has-filename {
  border-radius: 8px;
  overflow: hidden;
}

/* Responsive */
@media (max-width: 640px) {
  html {
    font-size: 15px;
  }

  h1 { font-size: 1.75rem; }
  h2 { font-size: 1.35rem; }
  h3 { font-size: 1.15rem; }

  .container {
    padding: 0 var(--spacing-md);
  }

  .site-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .header-right {
    width: 100%;
    justify-content: space-between;
  }

  .site-header nav {
    gap: var(--spacing-md);
  }

  .site-header nav a {
    margin-right: 0;
  }

  pre {
    padding: var(--spacing-md);
    border-radius: 0;
    margin-left: calc(-1 * var(--spacing-md));
    margin-right: calc(-1 * var(--spacing-md));
  }

  .search-modal-content {
    margin: 5vh var(--spacing-md) 0;
    border-radius: 8px;
  }
}
