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

:root {
  --bg: #ffffff;
  --text: #1a1a1a;
  --text-muted: #666;
  --border: #e0e0e0;
  --link: #0066cc;
  --code-bg: #f5f5f5;
}

[data-theme='dark'] {
  --bg: #1a1d24;
  --text: #e4e6eb;
  --text-muted: #9ca3af;
  --border: #2d3139;
  --link: #60a5fa;
  --code-bg: #23262e;
}

html {
  transition: background-color 0.3s ease, color 0.3s ease;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
  max-width: 800px;
  margin: 0 auto;
  padding: 0 20px;
}

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

nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.logo {
  font-family: 'Monaco', 'Courier New', 'Consolas', monospace;
  font-weight: 600;
  font-size: 1.2rem;
  text-decoration: none;
  color: var(--text);
}

.nav-links {
  display: flex;
  gap: 20px;
  align-items: center;
}

.nav-links a {
  text-decoration: none;
  color: var(--text);
}

.nav-links a:hover {
  color: var(--link);
}

main {
  min-height: 60vh;
}

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

/* 首页样式 */
.hero {
  margin-bottom: 60px;
}

.hero h1 {
  font-size: 2.5rem;
  margin-bottom: 10px;
}

.subtitle {
  font-size: 1.2rem;
  color: var(--text-muted);
  margin-bottom: 20px;
}

.intro {
  font-size: 1.1rem;
  line-height: 1.8;
}

.tech-stack {
  margin-bottom: 60px;
}

.tech-stack h2 {
  margin-bottom: 20px;
}

.tech-stack ul {
  list-style-position: inside;
}

.tech-stack li {
  padding: 8px 0;
}

.recent-posts h2 {
  margin-bottom: 20px;
}

.view-all {
  display: inline-block;
  color: var(--link);
  text-decoration: none;
}

.view-all:hover {
  text-decoration: underline;
}

/* 文章列表样式 */
.posts-list h1 {
  margin-bottom: 40px;
}

.post-item {
  margin-bottom: 40px;
  padding-bottom: 40px;
  border-bottom: 1px solid var(--border);
}

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

.post-item h2 {
  margin-bottom: 8px;
}

.post-item h2 a {
  color: var(--text);
  text-decoration: none;
}

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

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

.post-item p {
  margin: 10px 0;
  color: var(--text-muted);
}

.tags {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

.tag {
  background: var(--code-bg);
  padding: 4px 12px;
  border-radius: 4px;
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* 文章详情样式 */
.post-header {
  margin-bottom: 40px;
}

.post-header h1 {
  margin-bottom: 10px;
  font-size: 2.2rem;
}

.post-header time {
  color: var(--text-muted);
}

.post-content {
  line-height: 1.8;
}

.post-content h2 {
  margin: 40px 0 20px;
  font-size: 1.8rem;
}

.post-content h3 {
  margin: 30px 0 15px;
  font-size: 1.4rem;
}

.post-content p {
  margin: 15px 0;
}

.post-content ul,
.post-content ol {
  margin: 15px 0;
  padding-left: 30px;
}

.post-content li {
  margin: 8px 0;
}

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

.post-content a:hover {
  text-decoration: underline;
}

.post-content code {
  background: var(--code-bg);
  padding: 2px 6px;
  border-radius: 3px;
  font-family: 'Monaco', 'Courier New', monospace;
  font-size: 0.9em;
}

.post-content pre {
  background: #1e1e1e;
  color: #d4d4d4;
  padding: 20px;
  border-radius: 6px;
  overflow-x: auto;
  margin: 20px 0;
}

.post-content pre code {
  background: none;
  padding: 0;
  color: inherit;
  font-size: 0.9rem;
}

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

/* Dark theme adjustments */
[data-theme='dark'] .post-content pre {
  background: #1e2129;
  border: 1px solid var(--border);
}

[data-theme='dark'] .post-content code {
  color: var(--text);
}

[data-theme='dark'] {
  color-scheme: dark;
}

[data-theme='dark'] header {
  border-bottom-color: var(--border);
}

[data-theme='dark'] footer {
  border-top-color: var(--border);
}
/* GMP 可视化器 - 紧凑左右布局 */
.gmp-visualizer {
  width: 100%;
  max-width: 1100px;
  margin: 20px auto;
  padding: 16px;
  background: var(--code-bg);
  border-radius: 12px;
  border: 1px solid var(--border);
}

/* 场景选择器 - 顶部标签 */
.scenario-selector {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.scenario-btn {
  padding: 6px 14px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 500;
  transition: all 0.2s;
}

.scenario-btn:hover {
  border-color: var(--link);
}

.scenario-btn.active {
  background: var(--link);
  color: white;
  border-color: var(--link);
}

/* 主布局：左右分栏 */
.gmp-main-layout {
  display: grid;
  grid-template-columns: 1fr 280px;
  gap: 16px;
}

/* 左侧面板 */
.gmp-left-panel {
  display: flex;
  flex-direction: column;
}

/* 场景信息 - 紧凑 */
.scenario-info {
  margin-bottom: 12px;
  padding: 10px 14px;
  background: var(--bg);
  border-radius: 6px;
  border-left: 3px solid var(--link);
}

.scenario-info h3 {
  margin: 0 0 4px 0;
  color: var(--link);
  font-size: 1rem;
}

.step-desc {
  margin: 0;
  color: var(--text);
  font-size: 0.9rem;
}

/* 可视化区域 - 紧凑 */
.visualization-area {
  padding: 16px;
  background: var(--bg);
  border-radius: 8px;
  flex: 1;
}

/* 全局队列 */
.global-queue-container {
  margin-bottom: 20px;
}

.global-queue-container h4 {
  margin: 0 0 8px 0;
  color: var(--text);
  font-size: 0.9rem;
}

.global-queue {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  min-height: 44px;
  padding: 8px;
  background: var(--code-bg);
  border-radius: 6px;
  border: 2px dashed var(--border);
  align-items: center;
}

/* Goroutine 块 - 紧凑 */
.goroutine {
  padding: 5px 12px;
  border-radius: 5px;
  color: white;
  font-weight: 600;
  font-size: 0.8rem;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  min-width: 40px;
  text-align: center;
}

.empty-hint {
  color: var(--text-muted);
  font-style: italic;
  font-size: 0.85rem;
}

/* Processor 容器 */
.processors-container {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px;
}

.processor-block {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* Processor - 紧凑 */
.processor {
  padding: 10px;
  background: var(--code-bg);
  border-radius: 6px;
  border: 2px solid var(--link);
}

.processor-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.processor-header h4 {
  margin: 0;
  color: var(--link);
  font-size: 0.95rem;
}

.bound-machine {
  padding: 2px 8px;
  background: var(--link);
  color: white;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 600;
}

.local-queue {
  margin-top: 6px;
}

.queue-label {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.queue-items {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  min-height: 36px;
  padding: 6px;
  background: var(--bg);
  border-radius: 5px;
  align-items: center;
}

/* Machine - 紧凑 */
.machine {
  padding: 10px;
  background: var(--code-bg);
  border-radius: 6px;
  border: 2px solid #34d399;
}

.machine.blocked {
  border-color: #f87171;
  opacity: 0.7;
}

.machine-label {
  font-weight: 600;
  color: #34d399;
  margin-bottom: 6px;
  font-size: 0.95rem;
}

.machine.blocked .machine-label {
  color: #f87171;
}

.machine-status {
  min-height: 32px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.blocked-badge {
  padding: 2px 6px;
  background: #f87171;
  color: white;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 600;
}

.executing-g {
  padding: 5px 10px;
  border-radius: 5px;
  color: white;
  font-weight: 600;
  font-size: 0.8rem;
  flex: 1;
  text-align: center;
}

.idle {
  color: var(--text-muted);
  font-style: italic;
  font-size: 0.85rem;
}

.standalone-machine {
  margin-top: 12px;
}

/* 右侧控制面板 */
.gmp-right-panel {
  display: flex;
  flex-direction: column;
}

.controls-vertical {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 14px;
  background: var(--bg);
  border-radius: 8px;
  height: 100%;
}

.progress-info {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.85rem;
}

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

.progress-num {
  font-weight: 600;
  color: var(--text);
}

.progress-bar {
  height: 6px;
  background: var(--code-bg);
  border-radius: 3px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--link);
  border-radius: 3px;
  transition: width 0.3s ease;
}

.control-buttons {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.ctrl-btn {
  padding: 8px 12px;
  background: var(--link);
  color: white;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 500;
  transition: all 0.2s;
  text-align: center;
}

.ctrl-btn:hover:not(:disabled) {
  opacity: 0.9;
}

.ctrl-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.ctrl-btn.play-btn {
  background: #10b981;
}

.ctrl-btn.reset-btn {
  background: var(--text-muted);
}

.speed-control {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 10px;
  background: var(--code-bg);
  border-radius: 6px;
}

.speed-control label {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.speed-control input {
  width: 100%;
}

.speed-control span {
  text-align: center;
  font-weight: 600;
  color: var(--text);
  font-size: 0.85rem;
}

.scenario-desc-panel {
  padding: 10px;
  background: var(--code-bg);
  border-radius: 6px;
  flex: 1;
}

.scenario-desc-panel h4 {
  margin: 0 0 6px 0;
  font-size: 0.85rem;
  color: var(--text);
}

.scenario-desc-panel p {
  margin: 0;
  font-size: 0.8rem;
  color: var(--text-muted);
  line-height: 1.5;
}

/* 响应式 - 小屏幕变成上下布局 */
@media (max-width: 768px) {
  .gmp-visualizer {
    padding: 12px;
  }

  .gmp-main-layout {
    grid-template-columns: 1fr;
  }

  .gmp-right-panel {
    order: -1;
  }

  .controls-vertical {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 8px;
  }

  .control-buttons {
    flex-direction: row;
    flex-wrap: wrap;
    flex: 1;
  }

  .ctrl-btn {
    flex: 1;
    min-width: 80px;
  }

  .processors-container {
    grid-template-columns: 1fr;
  }

  .scenario-selector {
    flex-direction: column;
  }

  .scenario-btn {
    width: 100%;
  }
}

/* ==================== Table of Contents ==================== */
.toc {
  position: fixed;
  left: 16px;
  top: 50%;
  transform: translateY(-50%);
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.toc.visible {
  opacity: 1;
  pointer-events: auto;
}

/* Trigger button */
.toc-trigger {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  transition: all 0.2s ease;
}

.toc-trigger:hover {
  color: var(--link);
  border-color: var(--link);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
}

.toc-icon {
  width: 18px;
  height: 18px;
}

/* Panel */
.toc-panel {
  position: absolute;
  left: 48px;
  top: 50%;
  transform: translateY(-50%) scale(0.95);
  width: 240px;
  max-height: 60vh;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
  opacity: 0;
  visibility: hidden;
  transition: all 0.2s ease;
  overflow: hidden;
}

.toc-panel.open {
  opacity: 1;
  visibility: visible;
  transform: translateY(-50%) scale(1);
}

.toc-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--code-bg);
}

.toc-title {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text);
}

.toc-close {
  width: 24px;
  height: 24px;
  border: none;
  background: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  border-radius: 4px;
  transition: all 0.15s;
}

.toc-close:hover {
  background: var(--border);
  color: var(--text);
}

.toc-close svg {
  width: 14px;
  height: 14px;
}

.toc-content {
  padding: 8px 0;
  overflow-y: auto;
  max-height: calc(60vh - 44px);
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.toc-content::-webkit-scrollbar {
  width: 4px;
}

.toc-content::-webkit-scrollbar-track {
  background: transparent;
}

.toc-content::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 2px;
}

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

.toc-item {
  margin: 0;
}

.toc-link {
  display: block;
  padding: 6px 14px;
  font-size: 0.8rem;
  color: var(--text-muted);
  text-decoration: none;
  border-left: 2px solid transparent;
  transition: all 0.15s ease;
  line-height: 1.4;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.toc-link:hover {
  color: var(--text);
  background: var(--code-bg);
}

.toc-link.active {
  color: var(--link);
  border-left-color: var(--link);
  background: rgba(96, 165, 250, 0.08);
}

/* h3 indent */
.toc-h3 .toc-link {
  padding-left: 24px;
  font-size: 0.75rem;
}

/* Mobile: bottom-right floating button */
@media (max-width: 768px) {
  .toc {
    left: auto;
    right: 16px;
    top: auto;
    bottom: 16px;
    transform: none;
  }

  .toc-trigger {
    width: 44px;
    height: 44px;
    border-radius: 22px;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.15);
  }

  .toc-icon {
    width: 20px;
    height: 20px;
  }

  .toc-panel {
    left: auto;
    right: 0;
    top: auto;
    bottom: 56px;
    transform: translateY(10px) scale(0.95);
    width: calc(100vw - 32px);
    max-width: 300px;
    max-height: 50vh;
  }

  .toc-panel.open {
    transform: translateY(0) scale(1);
  }

  .toc-link {
    padding: 10px 14px;
    font-size: 0.85rem;
  }

  .toc-h3 .toc-link {
    padding-left: 24px;
    font-size: 0.8rem;
  }
}

/* Dark mode */
[data-theme='dark'] .toc-trigger {
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

[data-theme='dark'] .toc-panel {
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}

[data-theme='dark'] .toc-link.active {
  background: rgba(96, 165, 250, 0.12);
}
