/* ========================================
   TiddlyWiki-Style Base CSS
   Software Manual Skill
   ======================================== */

/* ========== CSS Variables ========== */
:root {
  /* Light Theme */
  --bg-primary: #ffffff;
  --bg-secondary: #f8f9fa;
  --bg-tertiary: #e9ecef;
  --text-primary: #212529;
  --text-secondary: #495057;
  --text-muted: #6c757d;
  --border-color: #dee2e6;
  --accent-color: #0d6efd;
  --accent-hover: #0b5ed7;
  --success-color: #198754;
  --warning-color: #ffc107;
  --danger-color: #dc3545;
  --info-color: #0dcaf0;

  /* Layout */
  --sidebar-width: 280px;
  --header-height: 60px;
  --content-max-width: 900px;
  --spacing-xs: 0.25rem;
  --spacing-sm: 0.5rem;
  --spacing-md: 1rem;
  --spacing-lg: 1.5rem;
  --spacing-xl: 2rem;

  /* Typography */
  --font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --font-family-mono: 'SF Mono', Monaco, Consolas, 'Liberation Mono', 'Courier New', monospace;
  --font-size-sm: 0.875rem;
  --font-size-base: 1rem;
  --font-size-lg: 1.125rem;
  --font-size-xl: 1.25rem;
  --line-height: 1.6;

  /* Shadows */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.1);

  /* Transitions */
  --transition-fast: 150ms ease;
  --transition-base: 300ms ease;
}

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

html {
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-family);
  font-size: var(--font-size-base);
  line-height: var(--line-height);
  color: var(--text-primary);
  background-color: var(--bg-secondary);
}

/* ========== Layout ========== */
.wiki-container {
  display: flex;
  min-height: 100vh;
}

/* ========== Sidebar ========== */
.wiki-sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: var(--sidebar-width);
  height: 100vh;
  background-color: var(--bg-primary);
  border-right: 1px solid var(--border-color);
  overflow-y: auto;
  z-index: 100;
  display: flex;
  flex-direction: column;
  transition: transform var(--transition-base);
}

/* Logo Area */
.wiki-logo {
  padding: var(--spacing-lg);
  text-align: center;
  border-bottom: 1px solid var(--border-color);
}

.wiki-logo .logo-placeholder {
  width: 60px;
  height: 60px;
  margin: 0 auto var(--spacing-sm);
  background: linear-gradient(135deg, var(--accent-color), var(--info-color));
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-weight: bold;
  font-size: var(--font-size-xl);
}

.wiki-logo h1 {
  font-size: var(--font-size-lg);
  font-weight: 600;
  margin-bottom: var(--spacing-xs);
}

.wiki-logo .version {
  font-size: var(--font-size-sm);
  color: var(--text-muted);
}

/* Search */
.wiki-search {
  padding: var(--spacing-md);
  position: relative;
}

.wiki-search input {
  width: 100%;
  padding: var(--spacing-sm) var(--spacing-md);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  font-size: var(--font-size-sm);
  background-color: var(--bg-secondary);
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.wiki-search input:focus {
  outline: none;
  border-color: var(--accent-color);
  box-shadow: 0 0 0 3px rgba(13, 110, 253, 0.15);
}

.search-results {
  position: absolute;
  top: 100%;
  left: var(--spacing-md);
  right: var(--spacing-md);
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  box-shadow: var(--shadow-lg);
  max-height: 400px;
  overflow-y: auto;
  z-index: 200;
}

.search-result-item {
  display: block;
  padding: var(--spacing-sm) var(--spacing-md);
  text-decoration: none;
  color: var(--text-primary);
  border-bottom: 1px solid var(--border-color);
  transition: background-color var(--transition-fast);
}

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

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

.result-title {
  font-weight: 600;
  margin-bottom: var(--spacing-xs);
}

.result-excerpt {
  font-size: var(--font-size-sm);
  color: var(--text-secondary);
}

.result-excerpt mark {
  background-color: var(--warning-color);
  padding: 0 2px;
  border-radius: 2px;
}

.no-results {
  padding: var(--spacing-md);
  text-align: center;
  color: var(--text-muted);
}

/* Tags */
.wiki-tags {
  padding: var(--spacing-md);
  display: flex;
  flex-wrap: wrap;
  gap: var(--spacing-xs);
  border-bottom: 1px solid var(--border-color);
}

.wiki-tags .tag {
  padding: var(--spacing-xs) var(--spacing-sm);
  font-size: var(--font-size-sm);
  border: 1px solid var(--border-color);
  border-radius: 20px;
  background: var(--bg-secondary);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.wiki-tags .tag:hover {
  border-color: var(--accent-color);
  color: var(--accent-color);
}

.wiki-tags .tag.active {
  background-color: var(--accent-color);
  border-color: var(--accent-color);
  color: white;
}

/* Table of Contents */
.wiki-toc {
  flex: 1;
  padding: var(--spacing-md);
  overflow-y: auto;
}

.wiki-toc h3 {
  font-size: var(--font-size-sm);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: var(--spacing-md);
}

.wiki-toc ul {
  list-style: none;
}

.wiki-toc li {
  margin-bottom: var(--spacing-xs);
}

.wiki-toc a {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--spacing-sm);
  color: var(--text-secondary);
  text-decoration: none;
  border-radius: 6px;
  font-size: var(--font-size-sm);
  transition: all var(--transition-fast);
}

.wiki-toc a:hover {
  background-color: var(--bg-secondary);
  color: var(--accent-color);
}

/* ========== Main Content ========== */
.wiki-content {
  flex: 1;
  margin-left: var(--sidebar-width);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Header */
.content-header {
  position: sticky;
  top: 0;
  background-color: var(--bg-primary);
  border-bottom: 1px solid var(--border-color);
  padding: var(--spacing-sm) var(--spacing-lg);
  display: flex;
  align-items: center;
  justify-content: space-between;
  z-index: 50;
}

.sidebar-toggle {
  display: none;
  flex-direction: column;
  gap: 4px;
  padding: var(--spacing-sm);
  background: none;
  border: none;
  cursor: pointer;
}

.sidebar-toggle span {
  display: block;
  width: 20px;
  height: 2px;
  background-color: var(--text-primary);
  transition: transform var(--transition-fast);
}

.header-actions {
  display: flex;
  gap: var(--spacing-sm);
}

.header-actions button {
  padding: var(--spacing-xs) var(--spacing-sm);
  font-size: var(--font-size-sm);
  border: 1px solid var(--border-color);
  border-radius: 4px;
  background: var(--bg-primary);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.header-actions button:hover {
  border-color: var(--accent-color);
  color: var(--accent-color);
}

/* Tiddler Container */
.tiddler-container {
  flex: 1;
  max-width: var(--content-max-width);
  margin: 0 auto;
  padding: var(--spacing-lg);
  width: 100%;
}

/* ========== Tiddler (Content Block) ========== */
.tiddler {
  background-color: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  margin-bottom: var(--spacing-lg);
  box-shadow: var(--shadow-sm);
  transition: box-shadow var(--transition-fast);
}

.tiddler:hover {
  box-shadow: var(--shadow-md);
}

.tiddler-header {
  padding: var(--spacing-md) var(--spacing-lg);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--spacing-sm);
}

.tiddler-title {
  display: flex;
  align-items: center;
  gap: var(--spacing-sm);
  font-size: var(--font-size-xl);
  font-weight: 600;
  margin: 0;
}

.collapse-toggle {
  background: none;
  border: none;
  font-size: var(--font-size-sm);
  color: var(--text-muted);
  cursor: pointer;
  padding: var(--spacing-xs);
  transition: transform var(--transition-fast);
}

.tiddler.collapsed .collapse-toggle {
  transform: rotate(-90deg);
}

.tiddler-meta {
  display: flex;
  gap: var(--spacing-sm);
  flex-wrap: wrap;
}

.difficulty-badge {
  padding: var(--spacing-xs) var(--spacing-sm);
  font-size: 0.75rem;
  font-weight: 500;
  border-radius: 4px;
  text-transform: uppercase;
}

.difficulty-badge.beginner {
  background-color: #d1fae5;
  color: #065f46;
}

.difficulty-badge.intermediate {
  background-color: #fef3c7;
  color: #92400e;
}

.difficulty-badge.advanced {
  background-color: #fee2e2;
  color: #991b1b;
}

.tag-badge {
  padding: var(--spacing-xs) var(--spacing-sm);
  font-size: 0.75rem;
  background-color: var(--bg-tertiary);
  color: var(--text-secondary);
  border-radius: 4px;
}

.tiddler-content {
  padding: var(--spacing-lg);
}

.tiddler.collapsed .tiddler-content {
  display: none;
}

/* ========== Content Typography ========== */
.tiddler-content h1,
.tiddler-content h2,
.tiddler-content h3,
.tiddler-content h4 {
  margin-top: var(--spacing-lg);
  margin-bottom: var(--spacing-md);
  font-weight: 600;
}

.tiddler-content h1 { font-size: 1.75rem; }
.tiddler-content h2 { font-size: 1.5rem; }
.tiddler-content h3 { font-size: 1.25rem; }
.tiddler-content h4 { font-size: 1.125rem; }

.tiddler-content p {
  margin-bottom: var(--spacing-md);
}

/* Lists - Enhanced Styling */
.tiddler-content ul,
.tiddler-content ol {
  margin: var(--spacing-md) 0;
  padding-left: var(--spacing-xl);
}

.tiddler-content ul {
  list-style: none;
}

.tiddler-content ul > li {
  position: relative;
  margin-bottom: var(--spacing-sm);
  padding-left: 8px;
}

.tiddler-content ul > li::before {
  content: "•";
  position: absolute;
  left: -16px;
  color: var(--accent-color);
  font-weight: bold;
}

.tiddler-content ol {
  list-style: none;
  counter-reset: item;
}

.tiddler-content ol > li {
  position: relative;
  margin-bottom: var(--spacing-sm);
  padding-left: 8px;
  counter-increment: item;
}

.tiddler-content ol > li::before {
  content: counter(item) ".";
  position: absolute;
  left: -24px;
  color: var(--accent-color);
  font-weight: 600;
}

/* Nested lists */
.tiddler-content ul ul,
.tiddler-content ol ol,
.tiddler-content ul ol,
.tiddler-content ol ul {
  margin: var(--spacing-xs) 0;
}

.tiddler-content ul ul > li::before {
  content: "◦";
}

.tiddler-content ul ul ul > li::before {
  content: "▪";
}

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

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

/* Inline Code - Red Highlight */
.tiddler-content code {
  font-family: var(--font-family-mono);
  font-size: 0.875em;
  padding: 2px 6px;
  background-color: #fff5f5;
  color: #c92a2a;
  border-radius: 4px;
  border: 1px solid #ffc9c9;
}

/* Code Blocks - Dark Background */
.tiddler-content pre {
  position: relative;
  margin: var(--spacing-md) 0;
  padding: 0;
  background-color: #1e2128;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid #3d4450;
}

.tiddler-content pre::before {
  content: attr(data-language);
  display: block;
  padding: 8px 16px;
  background-color: #2d333b;
  color: #8b949e;
  font-size: 0.75rem;
  font-family: var(--font-family);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid #3d4450;
}

.tiddler-content pre code {
  display: block;
  padding: var(--spacing-md);
  background: none;
  color: #e6edf3;
  font-size: var(--font-size-sm);
  line-height: 1.6;
  overflow-x: auto;
  border: none;
}

.copy-code-btn {
  position: absolute;
  top: 6px;
  right: 12px;
  padding: 4px 10px;
  font-size: 0.7rem;
  background-color: #3d4450;
  color: #8b949e;
  border: 1px solid #4d5566;
  border-radius: 4px;
  cursor: pointer;
  opacity: 0;
  transition: all var(--transition-fast);
}

.copy-code-btn:hover {
  background-color: #4d5566;
  color: #e6edf3;
}

.tiddler-content pre:hover .copy-code-btn {
  opacity: 1;
}

/* Tables - Blue Header Style */
.tiddler-content table {
  width: 100%;
  margin: var(--spacing-md) 0;
  border-collapse: collapse;
  border: 1px solid #dee2e6;
  border-radius: 8px;
  overflow: hidden;
}

.tiddler-content th {
  padding: 12px 16px;
  background: linear-gradient(135deg, #1971c2, #228be6);
  color: white;
  font-weight: 600;
  text-align: left;
  border: none;
  border-bottom: 2px solid #1864ab;
}

.tiddler-content td {
  padding: 10px 16px;
  border: 1px solid #e9ecef;
  text-align: left;
}

.tiddler-content tbody tr:nth-child(odd) {
  background-color: #f8f9fa;
}

.tiddler-content tbody tr:nth-child(even) {
  background-color: #ffffff;
}

.tiddler-content tbody tr:hover {
  background-color: #e7f5ff;
}

/* Screenshots */
.screenshot {
  margin: var(--spacing-lg) 0;
  text-align: center;
}

.screenshot img {
  max-width: 100%;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  box-shadow: var(--shadow-md);
}

.screenshot figcaption {
  margin-top: var(--spacing-sm);
  font-size: var(--font-size-sm);
  color: var(--text-muted);
  font-style: italic;
}

.screenshot-placeholder {
  padding: var(--spacing-xl);
  background-color: var(--bg-tertiary);
  border: 2px dashed var(--border-color);
  border-radius: 8px;
  color: var(--text-muted);
  text-align: center;
}

/* ========== Footer ========== */
.wiki-footer {
  padding: var(--spacing-lg);
  text-align: center;
  color: var(--text-muted);
  font-size: var(--font-size-sm);
  border-top: 1px solid var(--border-color);
  background-color: var(--bg-primary);
}

/* ========== Theme Toggle ========== */
.theme-toggle {
  position: fixed;
  bottom: var(--spacing-lg);
  right: var(--spacing-lg);
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: none;
  background-color: var(--bg-primary);
  box-shadow: var(--shadow-lg);
  cursor: pointer;
  font-size: 1.5rem;
  z-index: 100;
  transition: transform var(--transition-fast);
}

.theme-toggle:hover {
  transform: scale(1.1);
}

[data-theme="light"] .moon-icon { display: inline; }
[data-theme="light"] .sun-icon { display: none; }
[data-theme="dark"] .moon-icon { display: none; }
[data-theme="dark"] .sun-icon { display: inline; }

/* ========== Back to Top ========== */
.back-to-top {
  position: fixed;
  bottom: calc(var(--spacing-lg) + 60px);
  right: var(--spacing-lg);
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background-color: var(--accent-color);
  color: white;
  font-size: 1.25rem;
  cursor: pointer;
  opacity: 0;
  visibility: hidden;
  transition: all var(--transition-fast);
  z-index: 100;
}

.back-to-top.visible {
  opacity: 1;
  visibility: visible;
}

.back-to-top:hover {
  background-color: var(--accent-hover);
}

/* ========== Responsive ========== */
@media (max-width: 1024px) {
  .wiki-sidebar {
    transform: translateX(-100%);
  }

  .wiki-sidebar.open {
    transform: translateX(0);
  }

  .wiki-content {
    margin-left: 0;
  }

  .sidebar-toggle {
    display: flex;
  }
}

@media (max-width: 640px) {
  .tiddler-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .header-actions {
    display: none;
  }

  .wiki-tags {
    overflow-x: auto;
    flex-wrap: nowrap;
    padding-bottom: var(--spacing-md);
  }
}

/* ========== Print Styles ========== */
@media print {
  .wiki-sidebar,
  .theme-toggle,
  .back-to-top,
  .content-header,
  .collapse-toggle,
  .copy-code-btn {
    display: none !important;
  }

  .wiki-content {
    margin-left: 0;
  }

  .tiddler {
    break-inside: avoid;
    box-shadow: none;
    border: 1px solid #ccc;
  }

  .tiddler.collapsed .tiddler-content {
    display: block;
  }

  .tiddler-content pre {
    background-color: #f5f5f5 !important;
    color: #333 !important;
  }
}
