/* ==========================================
   Guide Styles — Lighter derivative of
   the lesson slide CSS design system
   ========================================== */

/* ==========================================
   DESIGN TOKENS (from lesson CSS)
   ========================================== */

:root {
  /* --- Typography --- */
  --font-sans: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'SF Mono', Monaco, 'Cascadia Code', monospace;

  /* --- Colors: Neutrals (Tailwind Slate) --- */
  --color-text: #0f172a;
  --color-text-secondary: #475569;
  --color-text-muted: #64748b;
  --color-text-subtle: #94a3b8;
  --color-text-inverse: #fff;

  --color-bg: #fff;
  --color-bg-subtle: #f1f5f9;
  --color-bg-muted: #f8fafc;

  --color-border: #cbd5e1;
  --color-border-light: #e2e8f0;
  --color-border-strong: #0f172a;

  /* --- Colors: Info (Tailwind Blue) --- */
  --color-info: #3b82f6;
  --color-info-dark: #1e40af;
  --color-info-bg: #eff6ff;
  --color-info-bg-dark: #dbeafe;

  /* --- Colors: Success (Tailwind Green) --- */
  --color-success: #22c55e;
  --color-success-bg: #f0fdf4;

  /* --- Colors: Warning (Tailwind Amber) --- */
  --color-warning: #f59e0b;
  --color-warning-bg: #fffbeb;

  /* --- Colors: Accent (Tailwind Purple) --- */
  --color-accent: #7e22ce;
  --color-accent-bg: #faf5ff;

  /* --- Focus --- */
  --color-focus: #3b82f6;
  --focus-ring: 0 0 0 2px var(--color-bg), 0 0 0 4px var(--color-focus);

  /* --- Shadows --- */
  --shadow-sm: 0 4px 12px rgba(15, 23, 42, 0.15);
  --shadow-md: 0 2px 8px rgba(15, 23, 42, 0.08);

  /* --- Border Radius --- */
  --radius-sm: 3px;
  --radius-md: 4px;
  --radius-lg: 8px;
  --radius-xl: 12px;

  /* --- Easing --- */
  --ease-out: cubic-bezier(0.25, 1, 0.5, 1);

  /* --- Layout --- */
  --guide-max-width: 720px;
}

/* ==========================================
   RESET & BASE
   ========================================== */

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

html {
  scroll-behavior: smooth;
  scroll-padding-top: 24px;
}

body {
  font-family: var(--font-sans);
  font-size: 1rem;
  line-height: 1.7;
  color: var(--color-text);
  background-color: var(--color-bg-muted);
  -webkit-font-smoothing: antialiased;
}

img {
  display: block;
  max-width: 100%;
}

/* ==========================================
   MAIN CONTENT
   ========================================== */

.guide-main {
  max-width: var(--guide-max-width);
  margin: 0 auto;
  padding: 48px 24px 96px;
}

/* ==========================================
   TYPOGRAPHY
   ========================================== */

h1 {
  font-size: 2rem;
  font-weight: 700;
  line-height: 1.2;
  margin-bottom: 8px;
  color: var(--color-text);
}

.guide-subtitle {
  font-size: 1.1rem;
  color: var(--color-text-secondary);
  margin-bottom: 32px;
}

h2 {
  font-size: 1.5rem;
  font-weight: 700;
  line-height: 1.3;
  margin-top: 56px;
  margin-bottom: 16px;
  padding-bottom: 8px;
  border-bottom: 2px solid var(--color-border-light);
  color: var(--color-text);
}

h3 {
  font-size: 1.15rem;
  font-weight: 600;
  line-height: 1.4;
  margin-top: 32px;
  margin-bottom: 12px;
  color: var(--color-text);
}

h4 {
  font-size: 1rem;
  font-weight: 600;
  margin-top: 24px;
  margin-bottom: 8px;
}

p {
  margin-bottom: 16px;
}

strong {
  font-weight: 600;
}

em {
  font-style: italic;
}

/* ==========================================
   LINKS
   ========================================== */

a {
  color: var(--color-info);
  text-decoration: underline;
  text-underline-offset: 2px;
}

a:hover {
  color: var(--color-info-dark);
}

a:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
  border-radius: var(--radius-sm);
}

/* ==========================================
   LISTS
   ========================================== */

ul, ol {
  margin-bottom: 16px;
  padding-left: 24px;
}

li {
  margin-bottom: 6px;
}

li > ul,
li > ol {
  margin-top: 6px;
  margin-bottom: 0;
}

/* ==========================================
   INLINE CODE
   ========================================== */

:not(pre) > code {
  font-family: var(--font-mono);
  font-size: 0.88em;
  padding: 2px 6px;
  background-color: var(--color-bg-subtle);
  border: 1px solid var(--color-border-light);
  border-radius: var(--radius-sm);
  color: var(--color-accent);
  word-break: break-word;
}

/* ==========================================
   CODE BLOCKS
   ========================================== */

pre {
  margin-bottom: 16px;
  border-radius: var(--radius-lg);
  overflow-x: auto;
}

pre code {
  font-family: var(--font-mono);
  font-size: 0.88rem;
  line-height: 1.6;
  tab-size: 2;
}

/* ==========================================
   TABLES
   ========================================== */

table {
  width: 100%;
  margin-bottom: 16px;
  border-collapse: collapse;
  font-size: 0.92rem;
}

th, td {
  padding: 10px 14px;
  text-align: left;
  border-bottom: 1px solid var(--color-border-light);
}

th {
  font-weight: 600;
  background-color: var(--color-bg-subtle);
  border-bottom: 2px solid var(--color-border);
}

td code {
  font-size: 0.85em;
}

tbody tr:hover {
  background-color: var(--color-bg-muted);
}

/* ==========================================
   HORIZONTAL RULE (section separator)
   ========================================== */

hr {
  border: none;
  height: 1px;
  background-color: var(--color-border-light);
  margin: 48px 0;
}

/* ==========================================
   DETAILS / SUMMARY (progressive disclosure)
   ========================================== */

details {
  background: var(--color-bg);
  border: 2px solid var(--color-info);
  border-radius: var(--radius-lg);
  overflow: hidden;
  margin-bottom: 12px;
}

details summary {
  padding: 12px 20px;
  background: var(--color-info);
  color: var(--color-text-inverse);
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
  list-style: none;
}

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

details summary:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}

details summary::before {
  content: "▶";
  display: inline-block;
  margin-right: 8px;
  font-size: 0.75em;
  transition: transform 0.25s var(--ease-out);
}

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

details[open] > :not(summary) {
  animation: detailsReveal 0.3s var(--ease-out);
}

@keyframes detailsReveal {
  from { opacity: 0; }
}

details > :not(summary) {
  padding-left: 20px;
  padding-right: 20px;
}

details > :not(summary):first-of-type {
  padding-top: 16px;
}

details > :not(summary):last-child {
  padding-bottom: 16px;
}

details pre {
  margin-left: -20px;
  margin-right: -20px;
  border-radius: 0;
}

details ul,
details ol {
  padding-left: 44px;
}

/* ==========================================
   CHECKLIST (interactive, localStorage-persisted)
   ========================================== */

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

.checklist li {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 6px 0;
}

.checklist input[type="checkbox"] {
  flex-shrink: 0;
  width: 18px;
  height: 18px;
  accent-color: var(--color-success);
  cursor: pointer;
}

.checklist label {
  cursor: pointer;
}

.checklist li:has(input:checked) label {
  text-decoration: line-through;
  color: var(--color-text-muted);
}

/* ==========================================
   TOC (collapsible table of contents)
   ========================================== */

.toc-trigger {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 48px;
  height: 48px;
  border: none;
  border-radius: 50%;
  background: var(--color-info);
  color: var(--color-text-inverse);
  font-size: 1.25rem;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  transition: background-color 0.15s var(--ease-out);
}

.toc-trigger:hover {
  background: var(--color-info-dark);
}

.toc-trigger:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring), var(--shadow-sm);
}

.toc-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.4);
  z-index: 200;
  display: none;
  opacity: 0;
  transition: opacity 0.2s var(--ease-out);
}

.toc-overlay.open {
  display: block;
  opacity: 1;
}

.toc-panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 320px;
  max-width: 85vw;
  background: var(--color-bg);
  box-shadow: var(--shadow-sm);
  z-index: 201;
  display: none;
  flex-direction: column;
  overflow-y: auto;
  padding: 24px;
}

.toc-panel.open {
  display: flex;
}

.toc-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.toc-panel-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--color-text);
}

.toc-close {
  width: 32px;
  height: 32px;
  border: none;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--color-text-secondary);
  font-size: 1.25rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

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

.toc-close:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}

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

.toc-list li {
  margin-bottom: 2px;
}

.toc-list a {
  display: block;
  padding: 8px 12px;
  border-radius: var(--radius-md);
  color: var(--color-text-secondary);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 500;
  transition: background-color 0.15s var(--ease-out), color 0.15s var(--ease-out);
}

.toc-list a:hover {
  background: var(--color-bg-subtle);
  color: var(--color-text);
}

.toc-list a:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}

/* ==========================================
   COLOPHON (header + footer chrome)
   ========================================== */

.guide-chrome {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--color-text-subtle);
  padding: 12px 24px;
  display: flex;
  justify-content: space-between;
}

.guide-chrome-footer {
  justify-content: flex-start;
}

/* ==========================================
   CODE BLOCK: copy button + language label
   ========================================== */

pre {
  position: relative;
}

.code-copy {
  position: absolute;
  top: 8px;
  right: 8px;
  padding: 4px 10px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.1);
  color: var(--color-text-subtle);
  font-family: var(--font-sans);
  font-size: 0.72rem;
  font-weight: 500;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s var(--ease-out), background-color 0.15s var(--ease-out);
}

pre:hover .code-copy,
.code-copy:focus-visible {
  opacity: 1;
}

.code-copy:hover {
  background: rgba(255, 255, 255, 0.2);
  color: var(--color-text-inverse);
}

.code-copy:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}

.code-copy.copied {
  background: var(--color-success);
  color: var(--color-text-inverse);
  border-color: var(--color-success);
  opacity: 1;
}

/* Language label */
pre[class*="language-"]::before {
  content: attr(data-lang);
  position: absolute;
  top: 8px;
  left: 12px;
  font-family: var(--font-mono);
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-text-subtle);
  opacity: 0.6;
}

/* ==========================================
   SECTION HEADING
   ========================================== */

h2 {
  scroll-margin-top: 24px;
}

/* ==========================================
   TOC: active section indicator
   ========================================== */

.toc-list a.active {
  background: var(--color-info-bg);
  color: var(--color-info-dark);
  font-weight: 600;
}

/* ==========================================
   TOC: keyboard shortcut hint
   ========================================== */

.toc-shortcut {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--color-text-muted);
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid var(--color-border-light);
}

kbd {
  display: inline-block;
  padding: 2px 6px;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  background: var(--color-bg-subtle);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  box-shadow: 0 1px 0 var(--color-border);
}

/* ==========================================
   FIGMA REFERENCES (top section)
   ========================================== */

.figma-links {
  background: var(--color-info-bg);
  border: 1px solid var(--color-info);
  border-radius: var(--radius-lg);
  padding: 16px 20px;
  margin-bottom: 24px;
}

.figma-links ul {
  margin-bottom: 0;
}

/* ==========================================
   RESPONSIVE
   ========================================== */

@media (max-width: 600px) {
  .guide-main {
    padding: 32px 16px 80px;
  }

  h1 {
    font-size: 1.6rem;
  }

  h2 {
    font-size: 1.3rem;
    margin-top: 40px;
  }

  h3 {
    font-size: 1.05rem;
  }

  table {
    font-size: 0.82rem;
  }

  th, td {
    padding: 8px 10px;
  }

  details summary {
    padding: 10px 16px;
    font-size: 0.9rem;
  }

  details > :not(summary) {
    padding-left: 16px;
    padding-right: 16px;
  }

  details pre {
    margin-left: -16px;
    margin-right: -16px;
  }
}

/* ==========================================
   PRINT
   ========================================== */

@media print {
  .toc-trigger,
  .toc-overlay,
  .toc-panel,
  .code-copy {
    display: none !important;
  }

  /* Force all details open on print (JS handles the attribute) */
  details {
    border: 1px solid var(--color-border);
  }

  details summary {
    background: var(--color-bg-subtle);
    color: var(--color-text);
  }
}

/* ==========================================
   REDUCED MOTION
   ========================================== */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }

  html {
    scroll-behavior: auto;
  }
}
