/**
 * Lesson Theme CSS
 *
 * Theme-aware styles for lesson content display.
 * Uses VSCode CSS variables to respect user's theme.
 * Brand colors from Tenstorrent official design system (tt-ui).
 */

:root {
  /* VSCode theme variables (provided by VSCode) */
  --vscode-foreground: var(--vscode-editor-foreground);
  --vscode-background: var(--vscode-editor-background);

  /* Tenstorrent Official Brand Colors (from tt-ui/src/styles.css) */
  /* Teal - Primary brand color */
  --tt-teal-50: #e7f8fd;
  --tt-teal-100: #c6edfa;
  --tt-teal-200: #98daf0;
  --tt-teal-300: #63c7e9;
  --tt-teal-400: #3fb7de;
  --tt-teal-500: #3293b2;  /* Primary teal */
  --tt-teal-600: #2b6c82;
  --tt-teal-700: #205060;
  --tt-teal-800: #183d49;

  /* Purple - Secondary brand color */
  --tt-purple-50: #efedfd;
  --tt-purple-100: #dad5fb;
  --tt-purple-300: #8879ec;
  --tt-purple-500: #5347a4;
  --tt-purple-700: #342c63;

  /* Red - Error/Warning states */
  --tt-red-300: #f7856e;
  --tt-red-400: #fc502c;
  --tt-red-500: #d03a1b;
  --tt-red-700: #622e22;

  /* Yellow - Attention states */
  --tt-yellow-200: #ffd88a;
  --tt-yellow-400: #ffb71b;
  --tt-yellow-600: #82672b;

  /* Green - Success states */
  --tt-green-300: #87d4c6;
  --tt-green-400: #65b7a8;
  --tt-green-500: #499c8d;
  --tt-green-700: #28524a;

  /* Blue - Info states */
  --tt-blue-400: #4756e1;
  --tt-blue-500: #2f3ec6;
  --tt-blue-600: #2a3898;

  /* Sand - Warm neutrals */
  --tt-sand-100: #f4f1ec;
  --tt-sand-300: #bbb6aa;
  --tt-sand-500: #6c6960;
  --tt-sand-700: #32312f;

  /* Stone - Cool neutrals */
  --tt-stone-100: #e9edf1;
  --tt-stone-300: #98a3ae;
  --tt-stone-500: #4c5761;
  --tt-stone-700: #2b3036;

  /* Semantic color mapping (for easy use throughout) */
  --tt-primary: var(--tt-teal-500);
  --tt-primary-light: var(--tt-teal-400);
  --tt-primary-dark: var(--tt-teal-600);
  --tt-secondary: var(--tt-purple-500);
  --tt-accent: var(--tt-teal-300);
  --tt-success: var(--tt-green-500);
  --tt-warning: var(--tt-yellow-400);
  --tt-error: var(--tt-red-500);
  --tt-info: var(--tt-blue-500);

  /* Computed theme-aware colors */
  --tt-border: color-mix(in srgb, var(--vscode-foreground) 20%, transparent);
  --tt-hover-bg: color-mix(in srgb, var(--tt-primary) 10%, var(--vscode-background));
  --tt-code-bg: var(--vscode-textCodeBlock-background);
  --tt-muted: color-mix(in srgb, var(--vscode-foreground) 60%, transparent);

  /* Typography scale (inspired by tt-ui, adapted for web safety) */
  --tt-font-display: var(--vscode-font-family);  /* Fallback to VSCode font */
  --tt-font-interface: var(--vscode-font-family);
  --tt-font-mono: var(--vscode-editor-font-family, 'IBM Plex Mono', 'Consolas', monospace);
}

/* Base styles */
body {
  font-family: var(--vscode-font-family);
  font-size: var(--vscode-font-size);
  color: var(--vscode-foreground);
  background: var(--vscode-background);
  padding: 32px;
  margin: 0;
  line-height: 1.6;
}

.lesson-content {
  max-width: 900px;
  margin: 0 auto;
  padding: 32px;
}

/* Headers */
h1, h2, h3, h4, h5, h6 {
  color: var(--vscode-foreground);
  font-weight: 600;
  line-height: 1.3;
  margin-top: 24px;
  margin-bottom: 16px;
}

h1 {
  font-size: 2em;
  font-weight: 300;  /* Light weight for display typography (tt-ui style) */
  border-bottom: 2px solid var(--tt-primary);
  padding-bottom: 8px;
}

h1 strong, h1 b {
  font-weight: 500;  /* Medium weight for emphasis (tt-ui style) */
}

h2 {
  font-size: 1.6em;
  border-bottom: 1px solid var(--tt-border);
  padding-bottom: 6px;
}

h3 {
  font-size: 1.3em;
}

h4 {
  font-size: 1.1em;
}

/* Paragraphs */
p {
  margin: 16px 0;
}

/* Links */
a {
  color: var(--vscode-textLink-foreground);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

/* Lists */
ul, ol {
  padding-left: 32px;
  margin: 16px 0;
  line-height: 1.8;
}

li {
  margin: 12px 0;
  padding-left: 8px;
}

li::marker {
  color: var(--tt-primary);
}

/* Code blocks */
pre {
  background: var(--tt-code-bg);
  border: 1px solid var(--tt-border);
  border-radius: 4px;
  padding: 16px;
  overflow-x: auto;
  margin: 16px 0;
  /* Explicit whitespace control — VSCode webview can override user-agent pre styles */
  white-space: pre;
  word-break: normal;
  overflow-wrap: normal;
  font-family: var(--vscode-editor-font-family, monospace);
  font-size: var(--vscode-font-size);
  line-height: 1.5;
}

pre code {
  background: transparent;
  padding: 0;
  border: none;
  /* Inherit pre's whitespace settings rather than code's inline defaults */
  white-space: inherit;
  font-size: inherit;
  line-height: inherit;
}

/* Inline code */
code {
  background: var(--tt-code-bg);
  border: 1px solid var(--tt-border);
  border-radius: 3px;
  padding: 2px 6px;
  font-family: var(--vscode-editor-font-family, monospace);
  font-size: 0.9em;
}

/* Command buttons - Official brand styling */
.tt-command-button {
  /* Clean solid background with official teal */
  background: var(--tt-primary);
  color: white;

  /* Subtle border for definition */
  border: 2px solid var(--tt-primary-dark);
  padding: 12px 24px;
  border-radius: 6px;
  cursor: pointer;

  font-family: var(--tt-font-interface);
  font-size: 1rem;
  font-weight: 600;  /* Semibold (tt-ui interface weight) */
  line-height: 120%;  /* Interface line-height from tt-ui */
  transition: all 0.2s ease;
  margin: 12px 12px 12px 0;
  display: inline-block;
  text-align: center;
  min-width: 120px;

  /* Subtle elevation shadow */
  box-shadow:
    0 2px 4px rgba(0, 0, 0, 0.15),
    0 1px 2px rgba(0, 0, 0, 0.1);

  /* Subtle text shadow for readability */
  text-shadow: 0 1px 1px rgba(0, 0, 0, 0.15);
}

/* Inline command links - appear as subtle text links within flowing text */
/* Only apply to buttons that are NOT the sole content of their paragraph */
p .tt-command-button:not(:only-child),
li .tt-command-button,
strong .tt-command-button,
em .tt-command-button {
  /* Reset button styling for inline appearance */
  background: transparent;
  border: none;
  padding: 0;
  margin: 0;
  min-width: 0;
  box-shadow: none;
  text-shadow: none;
  display: inline;
  text-align: inherit;

  /* Style as inline link */
  color: var(--tt-primary);
  font-weight: 600;
  font-size: inherit;
  line-height: inherit;
  text-decoration: none;
  border-bottom: 1px solid var(--tt-primary);

  /* Smooth transition */
  transition: all 0.15s ease;
}

p .tt-command-button:not(:only-child):hover,
li .tt-command-button:hover,
strong .tt-command-button:hover,
em .tt-command-button:hover {
  /* Subtle hover effect */
  color: var(--tt-primary-light);
  border-bottom-color: var(--tt-primary-light);
  background: transparent;
  transform: none;
  box-shadow: none;
}

p .tt-command-button:not(:only-child):active,
li .tt-command-button:active,
strong .tt-command-button:active,
em .tt-command-button:active {
  /* Subtle active state */
  color: var(--tt-primary-dark);
  border-bottom-color: var(--tt-primary-dark);
  background: transparent;
  transform: none;
  box-shadow: none;
}

.tt-command-button:hover {
  /* Lighter teal on hover */
  background: var(--tt-primary-light);
  border-color: var(--tt-primary);

  /* Gentle lift */
  transform: translateY(-2px);

  /* Enhanced shadow on hover */
  box-shadow:
    0 4px 8px rgba(50, 147, 178, 0.25),
    0 2px 4px rgba(0, 0, 0, 0.15);
}

.tt-command-button:active {
  /* Darker on press */
  background: var(--tt-primary-dark);
  border-color: var(--tt-teal-700);

  /* Return to baseline */
  transform: translateY(0);

  /* Inset shadow for pressed effect */
  box-shadow:
    inset 0 2px 4px rgba(0, 0, 0, 0.2),
    0 1px 2px rgba(0, 0, 0, 0.1);
}

/* Blockquotes */
blockquote {
  border-left: 4px solid var(--tt-primary);
  background: var(--tt-hover-bg);
  padding: 12px 16px;
  margin: 16px 0;
  border-radius: 0 4px 4px 0;
}

blockquote p:first-child {
  margin-top: 0;
}

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

/* Tables */
table {
  border-collapse: collapse;
  width: 100%;
  margin: 16px 0;
}

th, td {
  border: 1px solid var(--tt-border);
  padding: 8px 12px;
  text-align: left;
}

th {
  background: var(--tt-hover-bg);
  font-weight: 600;
}

tr:hover {
  background: var(--tt-hover-bg);
}

/* Hardware config callouts */
.hardware-config {
  border-left: 4px solid var(--tt-primary);
  background: var(--tt-hover-bg);
  padding: 16px;
  margin: 16px 0;
  border-radius: 0 4px 4px 0;
}

.hardware-config h4 {
  margin-top: 0;
  color: var(--tt-primary);
}

.hardware-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.hardware-chip {
  background: var(--tt-primary);
  color: white;
  padding: 6px 14px;  /* More vertical padding for symmetry */
  border-radius: 16px;  /* Larger radius for smoother pill shape */
  font-size: 0.875rem;  /* Interface-14 from tt-ui */
  font-weight: 600;  /* Semibold for badges */
  line-height: 1;  /* Line-height of 1 for perfect vertical centering */
  display: inline-flex;  /* Flex for perfect centering */
  align-items: center;
  justify-content: center;
  white-space: nowrap;
}

/* Prerequisites checklist */
.prerequisites {
  background: var(--tt-hover-bg);
  border: 1px solid var(--tt-border);
  border-radius: 4px;
  padding: 16px;
  margin: 16px 0;
}

.prerequisites h4 {
  margin-top: 0;
}

.checklist {
  list-style: none;
  padding: 0;
}

.checklist li {
  display: flex;
  align-items: center;
  margin: 8px 0;
}

.checklist input[type="checkbox"] {
  margin-right: 8px;
}

/* Status badges */
.status-badge {
  display: inline-flex;  /* Flex for perfect centering */
  align-items: center;
  justify-content: center;
  padding: 6px 12px;  /* Symmetrical padding */
  border-radius: 14px;  /* Smooth pill shape */
  font-size: 0.75rem;  /* Interface-12 from tt-ui */
  font-weight: 600;  /* Semibold for badges */
  line-height: 1;  /* Perfect vertical centering */
  margin: 4px;
  white-space: nowrap;
}

.status-validated {
  background: var(--tt-success);
  color: white;
}

.status-draft {
  background: var(--tt-info);
  color: white;
}

.status-blocked {
  background: var(--tt-error);
  color: white;
}

/* Lesson navigation */
.lesson-nav {
  display: flex;
  justify-content: space-between;
  margin-top: 48px;
  padding-top: 24px;
  border-top: 1px solid var(--tt-border);
}

.nav-prev, .nav-next {
  background: var(--vscode-button-background);
  color: var(--vscode-button-foreground);
  border: none;
  padding: 10px 20px;
  border-radius: 4px;
  cursor: pointer;
  font-family: var(--vscode-font-family);
  font-size: var(--vscode-font-size);
  transition: background 0.2s ease;
}

.nav-prev:hover, .nav-next:hover {
  background: var(--vscode-button-hoverBackground);
}

/* Responsive design */
@media (max-width: 768px) {
  .lesson-content {
    padding: 16px;
  }

  h1 {
    font-size: 1.8em;
  }

  h2 {
    font-size: 1.4em;
  }

  .hardware-grid {
    flex-direction: column;
  }

  .lesson-nav {
    flex-direction: column;
    gap: 12px;
  }
}

/* Horizontal rules */
hr {
  border: none;
  border-top: 1px solid var(--tt-border);
  margin: 32px 0;
}

/* Images */
img {
  max-width: 100%;
  height: auto;
  border-radius: 4px;
  margin: 16px 0;
}

/* Warning callouts */
.warning {
  background: color-mix(in srgb, var(--tt-warning) 10%, var(--vscode-background));
  border-left: 4px solid var(--tt-warning);
  padding: 16px;
  margin: 16px 0;
  border-radius: 0 4px 4px 0;
}

/* Error callouts */
.error {
  background: color-mix(in srgb, var(--tt-error) 10%, var(--vscode-background));
  border-left: 4px solid var(--tt-error);
  padding: 16px;
  margin: 16px 0;
  border-radius: 0 4px 4px 0;
}

/* Info callouts */
.info {
  background: color-mix(in srgb, var(--tt-info) 10%, var(--vscode-background));
  border-left: 4px solid var(--tt-info);
  padding: 16px;
  margin: 16px 0;
  border-radius: 0 4px 4px 0;
}

/* Success callouts */
.success {
  background: color-mix(in srgb, var(--tt-success) 10%, var(--vscode-background));
  border-left: 4px solid var(--tt-success);
  padding: 16px;
  margin: 16px 0;
  border-radius: 0 4px 4px 0;
}

/* Mermaid diagram styling */
.mermaid {
  background: var(--tt-code-bg);
  border: 1px solid var(--tt-border);
  border-radius: 4px;
  padding: 16px;
  margin: 16px 0;
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 200px;
  white-space: pre;  /* CRITICAL: Preserve newlines for mermaid syntax */
}

.mermaid svg {
  max-width: 100%;
  height: auto;
}

/* ── Light-mode overrides ──────────────────────────────────────────────────
 * lesson-theme.css loads after lesson-web-vars.css, so light-mode variable
 * overrides must live here to win the cascade.
 *
 * --tt-muted uses color-mix at 60% above, which renders as mid-grey (~#777)
 * on a white background — not readable enough. Override to near-black so
 * secondary text (section sub-headings, card descriptions, etc.) is legible.
 * ────────────────────────────────────────────────────────────────────────── */
@media (prefers-color-scheme: light) {
  :root {
    --tt-muted: #2a2a2a;
  }
}
