:root {
  --primary-color: #2196f3;
  --secondary-color: #4caf50;
  --background: #f5f5f5;
  --surface: #ffffff;
  --text-primary: #212121;
  --text-secondary: #757575;
  --border-color: #e0e0e0;
  --code-bg: #f8f8f8;
  --shadow: 0 2px 4px rgba(0,0,0,0.1);
  --navbar-height: 56px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
  background: var(--background);
  color: var(--text-primary);
  line-height: 1.6;
}

/* Navigation Bar */
.navbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--navbar-height);
  background: var(--surface);
  box-shadow: var(--shadow);
  border-bottom: 1px solid var(--border-color);
  z-index: 100;
}

.navbar-content {
  height: 100%;
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 2rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.navbar-left {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.nav-back {
  color: var(--primary-color);
  text-decoration: none;
  font-weight: 500;
  transition: opacity 0.2s;
}

.nav-back:hover {
  opacity: 0.8;
}

.nav-separator {
  color: var(--border-color);
}

.nav-title {
  margin: 0;
  font-size: 1.125rem;
  font-weight: 500;
}

.navbar-right {
  display: flex;
  align-items: center;
}

.view-toggle-nav {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.875rem;
  color: var(--text-secondary);
}

/* Main Container */
.main-container {
  margin-top: var(--navbar-height);
  height: calc(100vh - var(--navbar-height));
  display: flex;
  flex-direction: column;
  background: var(--surface);
}

/* Description Bar */
.description-bar {
  padding: 1rem 2rem;
  background: var(--background);
  border-bottom: 1px solid var(--border-color);
  font-size: 0.875rem;
  color: var(--text-secondary);
  flex-shrink: 0;
}

/* Toggle Switch */
.switch {
  position: relative;
  display: inline-block;
  width: 48px;
  height: 24px;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #ccc;
  transition: .3s;
  border-radius: 24px;
}

.slider:before {
  position: absolute;
  content: "";
  height: 18px;
  width: 18px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  transition: .3s;
  border-radius: 50%;
}

input:checked + .slider {
  background-color: var(--primary-color);
}

input:checked + .slider:before {
  transform: translateX(24px);
}

/* Tabs */
.tabs {
  display: flex;
  gap: 0.5rem;
  padding: 0 2rem;
  border-bottom: 2px solid var(--border-color);
  background: var(--background);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  flex-shrink: 0;
}

.tab {
  padding: 0.75rem 1.5rem;
  background: none;
  border: none;
  border-bottom: 3px solid transparent;
  cursor: pointer;
  font-size: 0.875rem;
  color: var(--text-secondary);
  transition: all 0.2s;
  position: relative;
  bottom: -2px;
  white-space: nowrap;
}

.tab:hover {
  color: var(--text-primary);
  background: var(--surface);
}

.tab.active {
  color: var(--primary-color);
  border-bottom-color: var(--primary-color);
  font-weight: 500;
}

/* Tab Contents */
.tab-contents {
  flex: 1;
  overflow: hidden;
  min-height: 0;
  background: var(--surface);
}

.tab-content {
  height: 100%;
  display: flex;
  flex-direction: column;
  padding: 2rem;
  overflow-y: auto;
}

.tab-content.hidden {
  display: none;
}

/* Ensure original tab uses full height */
#tab-original {
  padding: 1rem;
}

#tab-original .diagram-container {
  flex: 1;
  min-height: 0;
  height: 100%;
}

/* Diagram and Code Containers */
.diagram-container {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 2rem;
  background: var(--code-bg);
  border-radius: 8px;
  border: 1px solid var(--border-color);
  flex: 1;
  min-height: 400px;
  position: relative;
}

/* Special handling for original tab diagrams */
#tab-original .diagram-container {
  min-height: 600px;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 1rem;
}

#tab-original .diagram-container img {
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: calc(100vh - 300px); /* Account for navbar, tabs, etc */
  object-fit: contain;
}

/* Special handling for multi-diagram displays in original tab */
#tab-original .diagram-container > div {
  display: flex;
  gap: 2rem;
  justify-content: center;
  align-items: flex-start;
  flex-wrap: wrap;
  width: 100%;
}

#tab-original .diagram-container > div > div {
  flex: 1;
  min-width: 400px;
  max-width: calc(50% - 1rem);
  text-align: center;
}

#tab-original .diagram-container > div h4 {
  margin: 0 0 1rem 0;
  font-size: 1.1rem;
  font-weight: 500;
  color: var(--text-primary);
}

#tab-original .diagram-container > div img {
  width: 100%;
  height: auto;
  max-height: calc(100vh - 350px);
  object-fit: contain;
}

.diagram-container img {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
  cursor: zoom-in;
  transition: transform 0.2s;
}

.diagram-container img:hover {
  transform: scale(1.02);
}

/* Tooltip hint for clickable images */
.diagram-container::after {
  content: "Click to enlarge";
  position: absolute;
  bottom: 0.5rem;
  right: 0.5rem;
  background: rgba(0, 0, 0, 0.8);
  color: white;
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
  font-size: 0.75rem;
  opacity: 0;
  transition: opacity 0.2s;
  pointer-events: none;
}

.diagram-container:hover::after {
  opacity: 1;
}

.code-container {
  background: var(--code-bg);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  overflow: hidden;
  flex: 1;
  display: flex;
  flex-direction: column;
}

.code-header {
  background: var(--background);
  padding: 0.5rem 1rem;
  font-size: 0.75rem;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
}

.copy-button {
  background: none;
  border: 1px solid var(--border-color);
  padding: 0.25rem 0.75rem;
  border-radius: 4px;
  font-size: 0.75rem;
  cursor: pointer;
  color: var(--text-secondary);
  transition: all 0.2s;
}

.copy-button:hover {
  background: var(--surface);
  color: var(--text-primary);
}

.copy-button.copied {
  color: var(--secondary-color);
  border-color: var(--secondary-color);
}

pre {
  margin: 0;
  padding: 1rem;
  overflow: auto;
  font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
  font-size: 0.875rem;
  line-height: 1.5;
  flex: 1;
}

code {
  font-family: inherit;
}

.hidden {
  display: none !important;
}

/* Home page styles */
.home-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 2rem;
}

.home-header {
  text-align: center;
  padding: 3rem 0;
}

.home-header h1 {
  font-size: 2.5rem;
  margin-bottom: 1rem;
}

.home-header p {
  font-size: 1.25rem;
  color: var(--text-secondary);
  max-width: 600px;
  margin: 0 auto;
}

.samples-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 1.5rem;
  margin-top: 3rem;
}

.sample-card {
  background: var(--surface);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 1.5rem;
  text-decoration: none;
  color: inherit;
  transition: all 0.2s;
  box-shadow: var(--shadow);
}

.sample-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(0,0,0,0.15);
  border-color: var(--primary-color);
}

.sample-card h3 {
  margin: 0 0 0.5rem 0;
  color: var(--primary-color);
}

.sample-card p {
  margin: 0;
  color: var(--text-secondary);
  font-size: 0.875rem;
}

/* Modal/Lightbox Styles */
.modal {
  display: none;
  position: fixed;
  z-index: 1000;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  overflow: auto;
  background-color: rgba(0, 0, 0, 0.9);
  animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal-content {
  position: relative;
  margin: 2rem auto;
  padding: 0;
  width: 90%;
  max-width: 1200px;
  height: calc(100vh - 4rem);
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-content img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  background: white;
  border-radius: 8px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

.modal-close {
  position: absolute;
  top: 1rem;
  right: 2rem;
  color: #f1f1f1;
  font-size: 2rem;
  font-weight: bold;
  cursor: pointer;
  background: rgba(0, 0, 0, 0.5);
  width: 3rem;
  height: 3rem;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.modal-close:hover,
.modal-close:focus {
  background: rgba(0, 0, 0, 0.8);
  transform: scale(1.1);
}

.modal-caption {
  position: absolute;
  bottom: 1rem;
  left: 50%;
  transform: translateX(-50%);
  color: #f1f1f1;
  text-align: center;
  padding: 0.5rem 1rem;
  background: rgba(0, 0, 0, 0.7);
  border-radius: 4px;
  font-size: 0.875rem;
}

/* Responsive */
@media (max-width: 768px) {
  .navbar-content {
    padding: 0 1rem;
  }
  
  .nav-title {
    font-size: 1rem;
  }
  
  .nav-back {
    font-size: 0.875rem;
  }
  
  .description-bar {
    padding: 0.75rem 1rem;
  }
  
  .tabs {
    padding: 0 1rem;
  }
  
  .tab {
    padding: 0.5rem 1rem;
    font-size: 0.813rem;
  }
  
  .tab-content {
    padding: 1rem;
  }
  
  .diagram-container {
    padding: 1rem;
  }
  
  #tab-original .diagram-container > div {
    flex-direction: column;
  }
  
  #tab-original .diagram-container > div > div {
    max-width: 100%;
    min-width: auto;
  }
  
  .modal-content {
    width: 95%;
    margin: 1rem auto;
    height: calc(100vh - 2rem);
  }
  
  .modal-close {
    top: 0.5rem;
    right: 0.5rem;
  }
}