/* ==========================================================================
   AI Agent Course Site - Handbook & Google-Docs-Style Anchored Comments
   ========================================================================== */

:root {
  --color-primary: #2563eb;
  --color-primary-hover: #1d4ed8;
  --color-primary-light: #eff6ff;
  --color-primary-border: #bfdbfe;

  --color-navy: #0f172a;
  --color-text: #1e293b;
  --color-text-muted: #64748b;
  --color-text-light: #94a3b8;
  --color-bg: #f8fafc;
  --color-surface: #ffffff;
  --color-surface-hover: #f1f5f9;
  --color-border: #e2e8f0;
  --color-border-subtle: #f1f5f9;

  /* Callout colors */
  --callout-ok-bg: #f0fdf4;
  --callout-ok-border: #86efac;
  --callout-fail-bg: #fef2f2;
  --callout-fail-border: #fca5a5;
  --callout-ai-bg: #f5f3ff;
  --callout-ai-border: #c4b5fd;
  --callout-help-bg: #fffbeb;
  --callout-help-border: #fcd34d;
  --callout-tip-bg: #fefce8;
  --callout-tip-border: #fde047;
  --callout-time-bg: #eff6ff;
  --callout-time-border: #93c5fd;
  --callout-warn-bg: #fff7ed;
  --callout-warn-border: #fdba74;

  /* Comment Highlight */
  --cmt-hl-bg: rgba(254, 240, 138, 0.5);
  --cmt-hl-hover: rgba(253, 224, 71, 0.75);
  --cmt-hl-active: rgba(250, 204, 21, 0.95);

  /* Code block */
  --code-bg: #0f172a;
  --code-head-bg: #1e293b;
  --code-text: #f1f5f9;

  /* Sizing */
  --toc-width: 220px;
  --content-max-width: 1100px;
  --margin-width: 280px;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.08), 0 2px 4px -2px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.1);
}

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

html {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  color: var(--color-text);
  background-color: var(--color-bg);
  line-height: 1.7;
  font-size: 16.5px;
  scroll-behavior: smooth;
  scroll-padding-top: 60px;
  -webkit-text-size-adjust: 100%;
}

body {
  min-height: 100vh;
  position: relative;
  overflow-x: hidden;
}

/* Accessibility skip link */
.skip-link {
  position: absolute;
  top: -40px;
  left: 16px;
  background: var(--color-primary);
  color: #fff;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  z-index: 10000;
  text-decoration: none;
  font-weight: 500;
  transition: top 0.2s;
}
.skip-link:focus {
  top: 16px;
}

/* Top bar for mobile / small screen */
.top-nav-bar {
  display: none;
  position: sticky;
  top: 0;
  z-index: 50;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--color-border);
  padding: 10px 16px;
  box-shadow: var(--shadow-sm);
}

.mobile-toc-toggle-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--color-surface-hover);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 6px 12px;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--color-text);
  cursor: pointer;
  max-width: 100%;
}
.mobile-toc-toggle-btn:hover {
  background: #e2e8f0;
}
.mobile-toc-toggle-btn .toc-current-label {
  color: var(--color-text-muted);
  font-weight: 400;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Three-column Layout */
.doc-layout {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  max-width: min(1760px, 100%);
  margin: 0 auto;
  padding: 24px 20px 80px;
  gap: 20px;
  position: relative;
}

/* ==========================================================================
   TOC Sidebar (Left)
   ========================================================================== */

.toc-sidebar {
  width: var(--toc-width);
  flex-shrink: 0;
  position: sticky;
  top: 24px;
  max-height: calc(100vh - 48px);
  overflow-y: auto;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 16px;
  box-shadow: var(--shadow-sm);
  scrollbar-width: thin;
}
.toc-sidebar::-webkit-scrollbar {
  width: 5px;
}
.toc-sidebar::-webkit-scrollbar-thumb {
  background: var(--color-border);
  border-radius: 4px;
}

.toc-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 12px;
  margin-bottom: 12px;
  border-bottom: 1px solid var(--color-border);
}
.toc-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--color-navy);
}
.toc-close-btn {
  display: none;
  background: none;
  border: none;
  font-size: 1.25rem;
  color: var(--color-text-muted);
  cursor: pointer;
  padding: 4px;
}

.toc-list, .toc-sublist {
  list-style: none;
}
.toc-sublist {
  margin-left: 12px;
  padding-left: 8px;
  border-left: 2px solid var(--color-border-subtle);
  margin-top: 4px;
  margin-bottom: 4px;
}

.toc-item {
  margin-bottom: 4px;
}
.toc-item-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 4px;
  border-radius: var(--radius-sm);
  transition: background-color 0.15s;
}
.toc-item-row:hover {
  background: var(--color-surface-hover);
}

.toc-link {
  display: block;
  flex: 1;
  padding: 5px 8px;
  color: var(--color-text-muted);
  text-decoration: none;
  font-size: 0.84rem;
  line-height: 1.4;
  border-radius: var(--radius-sm);
  transition: color 0.15s, font-weight 0.15s;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.toc-link:hover {
  color: var(--color-primary);
}

.toc-h2-item > .toc-item-row > .toc-link {
  font-weight: 600;
  color: var(--color-text);
  font-size: 0.875rem;
}

.toc-item.is-active > .toc-item-row > .toc-link,
.toc-item.is-active > .toc-link {
  color: var(--color-primary);
  font-weight: 700;
  background: var(--color-primary-light);
}

.toc-collapse-btn {
  background: none;
  border: none;
  color: var(--color-text-light);
  cursor: pointer;
  padding: 4px 6px;
  font-size: 0.85rem;
  line-height: 1;
  border-radius: var(--radius-sm);
  transition: transform 0.2s, color 0.15s;
}
.toc-collapse-btn:hover {
  color: var(--color-navy);
}
.toc-collapse-btn[aria-expanded="false"] .toc-chevron {
  display: inline-block;
  transform: rotate(-90deg);
}

.toc-sublist.is-collapsed {
  display: none;
}

.toc-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.4);
  backdrop-filter: blur(2px);
  z-index: 90;
}

/* ==========================================================================
   Main Content Area (Center)
   ========================================================================== */

.doc-content {
  flex: 1 1 auto;
  width: 100%;
  max-width: var(--content-max-width);
  min-width: 0;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 36px 40px;
  box-shadow: var(--shadow-sm);
  position: relative;
}

/* Hero Header */
.hero-header {
  margin-bottom: 40px;
  padding-bottom: 24px;
  border-bottom: 2px solid var(--color-border);
}
.hero-title {
  font-size: 2.1rem;
  font-weight: 800;
  color: var(--color-navy);
  line-height: 1.25;
  margin-bottom: 12px;
  letter-spacing: -0.02em;
}
.hero-subtitle {
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--color-primary);
  line-height: 1.4;
  margin-bottom: 20px;
}
.hero-target {
  background: var(--color-primary-light);
  border-left: 4px solid var(--color-primary);
  padding: 16px 20px;
  border-radius: var(--radius-sm);
  margin-top: 16px;
  color: var(--color-navy);
  font-size: 0.95rem;
}
.hero-target p + p {
  margin-top: 8px;
}

/* Document Sections */
.doc-section {
  position: relative;
  margin-bottom: 32px;
}

/* Headings */
.doc-heading {
  color: var(--color-navy);
  font-weight: 700;
  line-height: 1.35;
  margin-top: 36px;
  margin-bottom: 16px;
  position: relative;
  display: flex;
  align-items: baseline;
  gap: 8px;
}
.doc-h2 {
  font-size: 1.5rem;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--color-border);
  margin-top: 44px;
}
.doc-h3 {
  font-size: 1.2rem;
  margin-top: 28px;
}
.doc-h4 {
  font-size: 1.05rem;
  margin-top: 20px;
}

.heading-anchor {
  text-decoration: none;
  color: var(--color-text-light);
  opacity: 0;
  font-size: 0.9em;
  transition: opacity 0.15s;
}
.doc-heading:hover .heading-anchor {
  opacity: 1;
}

/* Section comment badge */
.section-cmt-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: #fef08a;
  color: #854d0e;
  font-size: 0.75rem;
  font-weight: 700;
  padding: 1px 7px;
  border-radius: 9999px;
  margin-left: 8px;
  vertical-align: middle;
  border: 1px solid #fde047;
}

/* Typography elements */
.doc-p {
  margin-bottom: 16px;
  font-size: 1rem;
  color: var(--color-text);
}

.doc-divider {
  border: none;
  border-top: 1px solid var(--color-border);
  margin: 32px 0;
}

/* Callouts */
.callout {
  padding: 14px 18px;
  border-radius: var(--radius-sm);
  margin-bottom: 16px;
  border-left: 4px solid transparent;
  font-size: 0.95rem;
}
.callout-ok {
  background: var(--callout-ok-bg);
  border-left-color: var(--callout-ok-border);
}
.callout-fail {
  background: var(--callout-fail-bg);
  border-left-color: var(--callout-fail-border);
}
.callout-ai {
  background: var(--callout-ai-bg);
  border-left-color: var(--callout-ai-border);
}
.callout-help {
  background: var(--callout-help-bg);
  border-left-color: var(--callout-help-border);
}
.callout-tip {
  background: var(--callout-tip-bg);
  border-left-color: var(--callout-tip-border);
}
.callout-time {
  background: var(--callout-time-bg);
  border-left-color: var(--callout-time-border);
}
.callout-warn {
  background: var(--callout-warn-bg);
  border-left-color: var(--callout-warn-border);
}

/* Callout-tinted lists */
.callout-list {
  padding: 14px 24px 14px 36px;
  border-radius: var(--radius-sm);
  margin-bottom: 16px;
  border-left: 4px solid transparent;
}
.callout-list.callout-ok {
  background: var(--callout-ok-bg);
  border-left-color: var(--callout-ok-border);
}
.callout-list.callout-fail {
  background: var(--callout-fail-bg);
  border-left-color: var(--callout-fail-border);
}

/* Standard Lists */
.doc-list {
  margin-bottom: 16px;
  padding-left: 24px;
}
.doc-list li {
  margin-bottom: 6px;
  font-size: 0.98rem;
}
.doc-list li > ul,
.doc-list li > ol {
  margin-top: 6px;
  margin-bottom: 6px;
  padding-left: 20px;
}

/* Blockquotes */
.doc-blockquote {
  border-left: 4px solid var(--color-border);
  padding: 12px 18px;
  background: var(--color-bg);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  margin-bottom: 16px;
  color: var(--color-text-muted);
}
.doc-blockquote p {
  margin-bottom: 8px;
}
.doc-blockquote p:last-child {
  margin-bottom: 0;
}

/* Code Blocks */
.code-wrap {
  position: relative;
  background: var(--code-bg);
  border-radius: var(--radius-md);
  margin-bottom: 20px;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  border: 1px solid rgba(255, 255, 255, 0.08);
}
.code-wrap.prompt {
  border: 1.5px solid #8b5cf6;
  box-shadow: 0 0 15px rgba(139, 92, 246, 0.15);
}
/* Prompt blocks wrap long lines; command/code blocks keep horizontal scroll */
.code-wrap.prompt pre {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  overflow-x: hidden;
}
.code-wrap.prompt pre code {
  white-space: inherit;
  overflow-wrap: inherit;
}

.code-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--code-head-bg);
  padding: 8px 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}
.code-head .lang {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.75rem;
  text-transform: uppercase;
  color: var(--color-text-light);
  letter-spacing: 0.05em;
  font-weight: 600;
}
.code-wrap.prompt .code-head .lang::after {
  content: " · 提示词";
  color: #a78bfa;
}

.copy-btn {
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: #f1f5f9;
  border-radius: var(--radius-sm);
  padding: 4px 10px;
  font-size: 0.75rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
}
.copy-btn:hover {
  background: rgba(255, 255, 255, 0.2);
}
.copy-btn.copied {
  background: #10b981;
  border-color: #10b981;
  color: #fff;
}

pre {
  padding: 16px 20px;
  overflow-x: auto;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: 0.88rem;
  line-height: 1.6;
  color: var(--code-text);
  tab-size: 2;
}
code {
  font-family: inherit;
  font-size: inherit;
}

/* Inline code span */
:not(pre) > code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  background: rgba(15, 23, 42, 0.06);
  color: #0f172a;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.86em;
}

/* Mermaid Blocks */
pre.mermaid {
  background: #ffffff;
  color: #0f172a;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 20px;
  margin-bottom: 20px;
  text-align: center;
  overflow-x: auto;
}
pre.mermaid.render-failed {
  background: var(--code-bg);
  color: var(--code-text);
  text-align: left;
}

/* Tables */
.table-wrap {
  width: 100%;
  overflow-x: auto;
  margin-bottom: 20px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
}
.doc-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 0.95rem;
}
.doc-table th {
  background: var(--color-surface-hover);
  color: var(--color-navy);
  font-weight: 600;
  padding: 12px 16px;
  border-bottom: 1px solid var(--color-border);
}
.doc-table td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--color-border-subtle);
  vertical-align: top;
}
.doc-table th:first-child,
.doc-table td:first-child {
  white-space: nowrap;
  min-width: 7.5em;
  width: 1%;
  overflow-wrap: normal;
  word-break: keep-all;
}
.doc-table tr:last-child td {
  border-bottom: none;
}
.doc-table tr:hover td {
  background: rgba(241, 245, 249, 0.5);
}

/* Links */
.doc-content a {
  color: var(--color-primary);
  text-decoration: underline;
  text-underline-offset: 3px;
  transition: color 0.15s;
}
.doc-content a:hover {
  color: var(--color-primary-hover);
}

/* Footer */
.doc-footer {
  margin-top: 60px;
  padding-top: 24px;
  border-top: 1px solid var(--color-border);
  font-size: 0.875rem;
  color: var(--color-text-muted);
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
}

/* ==========================================================================
   Google Docs Style Inline Highlights & Floating Buttons
   ========================================================================== */

mark.cmt-hl {
  background-color: var(--cmt-hl-bg);
  color: inherit;
  border-radius: 2px;
  padding: 1px 2px;
  cursor: pointer;
  transition: background-color 0.2s, box-shadow 0.2s;
}
mark.cmt-hl.is-hovered {
  background-color: var(--cmt-hl-hover);
}
mark.cmt-hl.is-active {
  background-color: var(--cmt-hl-active);
  box-shadow: 0 0 0 2px rgba(234, 179, 8, 0.5);
}

/* Selection floating comment button */
.selection-comment-btn {
  position: absolute;
  z-index: 1000;
  background: var(--color-navy);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 9999px;
  padding: 6px 14px;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  gap: 6px;
  transform: translate(-50%, -100%) translateY(-8px);
  animation: fadeInPop 0.15s ease-out;
}
.selection-comment-btn:hover {
  background: #1e293b;
  transform: translate(-50%, -100%) translateY(-10px);
}

/* Block hover comment button */
.block-comment-btn {
  position: absolute;
  z-index: 999;
  background: #ffffff;
  color: var(--color-text);
  border: 1px solid var(--color-border);
  border-radius: 50%;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.82rem;
  cursor: pointer;
  box-shadow: var(--shadow-md);
  transition: transform 0.15s, background-color 0.15s;
}
.block-comment-btn:hover {
  background: var(--color-primary-light);
  color: var(--color-primary);
  border-color: var(--color-primary-border);
  transform: scale(1.1);
}

@keyframes fadeInPop {
  from { opacity: 0; transform: translate(-50%, -100%) translateY(0); }
  to { opacity: 1; transform: translate(-50%, -100%) translateY(-8px); }
}

/* ==========================================================================
   Comment Margin (Desktop >= 900px)
   ========================================================================== */

.comment-margin {
  width: var(--margin-width);
  flex-shrink: 0;
  position: relative;
  min-height: 400px;
}

.margin-header {
  position: sticky;
  top: 24px;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--color-bg);
  padding: 10px 0;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--color-border);
}
.margin-header-left {
  display: flex;
  align-items: center;
  gap: 8px;
}
.margin-title {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--color-navy);
}
.comment-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--color-border);
  color: var(--color-text);
  font-size: 0.75rem;
  font-weight: 700;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 10px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  padding: 6px 12px;
  line-height: 1.2;
  border: 1px solid transparent;
}
.btn-sm {
  padding: 5px 10px;
  font-size: 0.8rem;
}
.btn-xs {
  padding: 3px 8px;
  font-size: 0.75rem;
}
.btn-outline {
  background: var(--color-surface);
  border-color: var(--color-border);
  color: var(--color-text);
}
.btn-outline:hover {
  background: var(--color-surface-hover);
  border-color: var(--color-text-light);
}
.btn-primary {
  background: var(--color-primary);
  color: #fff;
}
.btn-primary:hover {
  background: var(--color-primary-hover);
}
.btn-secondary {
  background: var(--color-surface-hover);
  border-color: var(--color-border);
  color: var(--color-text);
}
.btn-secondary:hover {
  background: #e2e8f0;
}

/* Margin cards container */
.margin-cards {
  position: relative;
  width: 100%;
}

/* Comment Cards */
.comment-card {
  position: absolute;
  left: 0;
  width: 100%;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  transition: border-color 0.2s, box-shadow 0.2s, top 0.25s ease-out;
}
.comment-card:hover {
  border-color: #cbd5e1;
  box-shadow: var(--shadow-md);
}
.comment-card.is-active {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.2), var(--shadow-md);
}
.comment-card.is-general {
  border-left: 3px solid var(--color-primary);
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 6px;
  gap: 8px;
}
.card-author {
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--color-navy);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.card-time {
  font-size: 0.72rem;
  color: var(--color-text-light);
  flex-shrink: 0;
}

.card-quote {
  font-size: 0.8rem;
  color: var(--color-text-muted);
  border-left: 2px solid #cbd5e1;
  padding-left: 8px;
  margin-bottom: 8px;
  font-style: italic;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  line-height: 1.4;
}
.card-quote.orphaned {
  color: #94a3b8;
  border-left-color: #e2e8f0;
}

.card-body {
  font-size: 0.88rem;
  color: var(--color-text);
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}

/* Orphaned Section */
.orphaned-section, .drawer-orphaned-section {
  margin-top: 40px;
  padding-top: 16px;
  border-top: 1px dashed var(--color-border);
}
.orphaned-heading {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--color-text-muted);
  margin-bottom: 12px;
}
.orphaned-cards, .drawer-orphaned-cards {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.orphaned-cards .comment-card {
  position: static;
  width: 100%;
  opacity: 0.85;
}

/* ==========================================================================
   Comment Composer
   ========================================================================== */

.comment-composer {
  background: var(--color-surface);
  border: 1px solid var(--color-primary-border);
  border-radius: var(--radius-md);
  padding: 16px;
  box-shadow: var(--shadow-lg);
  margin-bottom: 20px;
  animation: fadeInPop 0.15s ease-out;
}
.composer-title {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--color-navy);
  margin-bottom: 10px;
}
.composer-quote {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  background: var(--color-bg);
  border-left: 3px solid var(--color-primary);
  padding: 6px 10px;
  border-radius: 4px;
  margin-bottom: 12px;
  font-size: 0.8rem;
  color: var(--color-text-muted);
}
.quote-text {
  flex: 1;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  line-height: 1.4;
}
.quote-clear {
  background: none;
  border: none;
  color: var(--color-text-light);
  cursor: pointer;
  padding: 2px;
  font-size: 0.8rem;
}
.quote-clear:hover {
  color: var(--color-text);
}

.form-group {
  margin-bottom: 10px;
}
.form-group label {
  display: block;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--color-text);
  margin-bottom: 4px;
}
.form-group .required {
  color: #ef4444;
}
.form-group .label-hint {
  font-size: 0.72rem;
  font-weight: normal;
  color: var(--color-text-light);
}

.form-input, .form-textarea {
  width: 100%;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  font-size: 0.85rem;
  font-family: inherit;
  color: var(--color-text);
  background: #fff;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.form-input:focus, .form-textarea:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}
.form-textarea {
  resize: vertical;
  min-height: 60px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.form-error {
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: #b91c1c;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  font-size: 0.78rem;
  margin-bottom: 10px;
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 12px;
}

/* Toast */
.toast-notice {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--color-navy);
  color: #fff;
  padding: 10px 20px;
  border-radius: 9999px;
  font-size: 0.88rem;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  z-index: 10000;
  animation: fadeInPop 0.2s ease-out;
}

/* ==========================================================================
   Mobile Bottom Drawer (< 900px)
   ========================================================================== */

.mobile-comments-fab {
  display: none;
  position: fixed;
  bottom: 24px;
  right: 20px;
  z-index: 80;
  background: var(--color-navy);
  color: #fff;
  border: none;
  border-radius: 9999px;
  padding: 10px 18px;
  font-size: 0.9rem;
  font-weight: 600;
  box-shadow: var(--shadow-lg);
  cursor: pointer;
  align-items: center;
  gap: 8px;
  transition: transform 0.15s, background-color 0.15s;
}
.mobile-comments-fab:hover {
  background: #1e293b;
  transform: scale(1.03);
}
.fab-badge {
  background: #3b82f6;
  color: #fff;
  font-size: 0.75rem;
  border-radius: 9999px;
  padding: 1px 7px;
  min-width: 18px;
  text-align: center;
}

.drawer-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
  backdrop-filter: blur(2px);
  z-index: 95;
}

.comment-drawer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  max-height: 75vh;
  background: var(--color-surface);
  border-top-left-radius: var(--radius-lg);
  border-top-right-radius: var(--radius-lg);
  box-shadow: 0 -10px 25px -5px rgba(0, 0, 0, 0.15);
  z-index: 100;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: slideUp 0.25s ease-out;
}

@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

.drawer-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 20px;
  border-bottom: 1px solid var(--color-border);
  background: var(--color-surface);
  flex-shrink: 0;
}
.drawer-header-left {
  display: flex;
  align-items: center;
  gap: 8px;
}
.drawer-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--color-navy);
}
.drawer-close-btn {
  background: none;
  border: none;
  font-size: 1.25rem;
  color: var(--color-text-muted);
  cursor: pointer;
  padding: 4px;
}

.drawer-content {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px 40px;
  scrollbar-width: thin;
}
.drawer-cards {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.drawer-cards .comment-card {
  position: static;
  width: 100%;
}

/* ==========================================================================
   Responsive Breakpoints
   ========================================================================== */

/* Mid desktop: prioritize content width between TOC and comment rail */
@media (min-width: 900px) and (max-width: 1399px) {
  :root {
    --toc-width: 200px;
    --margin-width: 260px;
    --content-max-width: 960px;
  }
  .doc-layout {
    gap: 16px;
    padding-left: 12px;
    padding-right: 12px;
  }
  .doc-content {
    padding: 32px 28px;
  }
  .toc-link { font-size: 0.8rem; }
}

/* Wide desktop: grow content column */
@media (min-width: 1400px) {
  :root {
    --toc-width: 230px;
    --content-max-width: 1040px;
    --margin-width: 300px;
  }
  .doc-layout {
    max-width: 1680px;
    gap: 28px;
  }
}
@media (min-width: 1600px) {
  :root {
    --content-max-width: 1120px;
    --margin-width: 320px;
  }
  .doc-layout {
    max-width: 1840px;
    gap: 32px;
  }
}
@media (min-width: 1900px) {
  :root {
    --content-max-width: 1200px;
  }
}

/* Tablet & Smaller Desktop (< 1100px): TOC becomes drawer */
@media (max-width: 1099px) {
  .top-nav-bar {
    display: block;
  }
  .toc-sidebar {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 290px;
    max-height: 100vh;
    z-index: 100;
    border-radius: 0;
    border-right: 1px solid var(--color-border);
    border-top: none;
    border-bottom: none;
    animation: slideRight 0.2s ease-out;
  }
  .toc-sidebar.is-open {
    display: block;
  }
  .toc-overlay.is-open {
    display: block;
  }
  .toc-close-btn {
    display: block;
  }
}

@keyframes slideRight {
  from { transform: translateX(-100%); }
  to { transform: translateX(0); }
}

/* Mobile & Small Tablet (< 900px): Comment margin disappears, drawer mode */
@media (max-width: 899px) {
  .doc-layout {
    padding: 12px 12px 80px;
    gap: 0;
  }
  .doc-content {
    padding: 24px 20px;
    border-radius: var(--radius-sm);
  }
  .comment-margin {
    display: none;
  }
  .mobile-comments-fab {
    display: inline-flex;
  }
  .hero-title {
    font-size: 1.6rem;
  }
  .hero-subtitle {
    font-size: 1.05rem;
  }
}

/* Narrow mobile (390px or less): No horizontal scroll */
@media (max-width: 440px) {
  html {
    font-size: 15px;
  }
  .doc-content {
    padding: 20px 14px;
  }
  pre {
    padding: 12px 14px;
    font-size: 0.82rem;
  }
  .code-head {
    padding: 6px 12px;
  }
}

/* Comment count badge text comes from data-count so it does not affect anchor offsets */
.section-cmt-count::after { content: attr(data-count); }

/* Desktop composer floats next to its passage */
.comment-margin { align-self: stretch; }
.margin-composer-slot.is-floating {
  position: absolute;
  left: 0;
  right: 0;
  z-index: 30;
}
.margin-composer-slot.is-floating .comment-composer {
  box-shadow: 0 12px 32px rgba(15, 23, 42, 0.18);
}

/* Long URLs must wrap on narrow screens */
.doc-content { min-width: 0; }
.doc-content p, .doc-content li, .doc-content blockquote { overflow-wrap: anywhere; }
.doc-content td, .doc-content th { overflow-wrap: break-word; word-break: normal; }


/* Heading toolbar: 复制本步 */
.doc-heading {
  position: relative;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 8px 12px;
}
.doc-heading .heading-text { flex: 1 1 auto; min-width: 0; }
.step-copy-btn {
  flex: 0 0 auto;
  margin-left: auto;
  background: #f1f5f9;
  border: 1px solid var(--color-border);
  color: var(--color-navy);
  border-radius: 9999px;
  padding: 4px 12px;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.step-copy-btn:hover {
  background: var(--color-primary-light);
  border-color: var(--color-primary-border);
  color: var(--color-primary);
}
.step-copy-btn.copied {
  background: #10b981;
  border-color: #10b981;
  color: #fff;
}
.step-block {
  position: relative;
  border: 1px dashed transparent;
  border-radius: var(--radius-md);
  padding: 4px 8px 8px;
  margin: 0 -8px 12px;
  transition: border-color 0.15s, background 0.15s;
}
.step-block:hover {
  border-color: #cbd5e1;
  background: rgba(241, 245, 249, 0.45);
}
.step-block > .step-copy-btn {
  position: absolute;
  top: 6px;
  right: 8px;
  z-index: 2;
}

/* Diagram wrap + zoom button */
.diagram-wrap {
  position: relative;
  margin-bottom: 20px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: #fff;
  overflow: hidden;
}
.diagram-wrap .diagram-toolbar {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 8px 10px;
  background: #f8fafc;
  border-bottom: 1px solid var(--color-border-subtle);
}
.diagram-zoom-btn {
  background: #fff;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 4px 10px;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  color: var(--color-navy);
}
.diagram-zoom-btn:hover {
  background: var(--color-primary-light);
  border-color: var(--color-primary-border);
  color: var(--color-primary);
}
.diagram-wrap pre.mermaid {
  margin: 0;
  border: none;
  border-radius: 0;
}

/* SVG / diagram lightbox */
.diagram-lightbox {
  position: fixed;
  inset: 0;
  z-index: 2000;
  background: rgba(15, 23, 42, 0.72);
  display: none;
  flex-direction: column;
}
.diagram-lightbox.is-open { display: flex; }
.diagram-lightbox-toolbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  background: rgba(15, 23, 42, 0.92);
  color: #fff;
}
.diagram-lightbox-toolbar .lb-title {
  font-size: 0.9rem;
  font-weight: 600;
}
.diagram-lightbox-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.diagram-lightbox-actions button {
  background: rgba(255,255,255,0.12);
  border: 1px solid rgba(255,255,255,0.2);
  color: #fff;
  border-radius: var(--radius-sm);
  padding: 6px 12px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
}
.diagram-lightbox-actions button:hover {
  background: rgba(255,255,255,0.22);
}
.diagram-lightbox-stage {
  flex: 1 1 auto;
  overflow: hidden;
  cursor: grab;
  touch-action: none;
  position: relative;
}
.diagram-lightbox-stage.is-dragging { cursor: grabbing; }
.diagram-lightbox-canvas {
  position: absolute;
  top: 50%;
  left: 50%;
  transform-origin: center center;
  will-change: transform;
  user-select: none;
}
.diagram-lightbox-canvas svg {
  max-width: none !important;
  height: auto;
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 20px 50px rgba(0,0,0,0.35);
  padding: 24px;
}
@media (max-width: 899px) {
  .step-copy-btn { font-size: 0.72rem; padding: 3px 10px; }
  .doc-heading { gap: 6px; }
}


/* ==========================================================================
   Back to top
   ========================================================================== */

.back-to-top {
  position: fixed;
  bottom: 28px;
  right: 28px;
  z-index: 82;
  width: 44px;
  height: 44px;
  border: 1px solid var(--color-border);
  border-radius: 9999px;
  background: #fff;
  color: var(--color-navy);
  font-size: 1.25rem;
  font-weight: 700;
  line-height: 1;
  box-shadow: var(--shadow-lg);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transform: translateY(10px);
  transition: opacity 0.2s ease, transform 0.2s ease, background-color 0.15s, color 0.15s;
}
.back-to-top.is-visible {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}
.back-to-top:hover {
  background: var(--color-navy);
  color: #fff;
  border-color: var(--color-navy);
}
.back-to-top:focus-visible {
  outline: 2px solid #3b82f6;
  outline-offset: 3px;
}
/* Sit above the mobile comments FAB; stay clear of bottom drawer chrome */
@media (max-width: 899px) {
  .back-to-top {
    bottom: 88px;
    right: 20px;
  }
}


/* —— Teacher edition —— */
.teacher-banner {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  flex-wrap: wrap;
  gap: 10px 16px;
  align-items: center;
  padding: 10px 16px;
  background: #1e3a5f;
  color: #e2e8f0;
  font-size: 0.9rem;
}
.teacher-banner strong { color: #fde68a; }
.teacher-banner-link {
  color: #93c5fd;
  text-decoration: none;
  font-weight: 600;
}
.teacher-banner-link:hover { text-decoration: underline; }
.teacher-block {
  margin: 16px 0;
  padding: 12px 14px 14px;
  border: 2px dashed #c4b5fd;
  border-radius: 12px;
  background: #f5f3ff;
  position: relative;
}
.teacher-badge {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  color: #5b21b6;
  background: #ddd6fe;
  border-radius: 999px;
  padding: 2px 10px;
  margin-bottom: 8px;
}
body.edition-teacher .doc-footer::after {
  content: " · 老师版（需登录）";
}


/* Student edition: collapsed AI reference packs */
details.ai-ref {
  margin: 0.75rem 0 1.25rem;
  padding: 0.4rem 0.75rem 0.75rem;
  border: 1px dashed var(--border, #c9cdd3);
  border-radius: 10px;
  background: color-mix(in srgb, var(--bg-soft, #f6f7f9) 80%, transparent);
  color: var(--muted, #667);
  font-size: 0.92rem;
}
details.ai-ref > summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--muted, #556);
  list-style: none;
}
details.ai-ref > summary::-webkit-details-marker { display: none; }
details.ai-ref > summary::before {
  content: "▸ ";
  color: var(--accent, #4f46e5);
}
details.ai-ref[open] > summary::before { content: "▾ "; }
details.ai-ref .ai-ref-label { margin: 0.5rem 0 0.25rem; }
details.ai-ref .code-wrap { margin: 0.5rem 0; }
body.edition-student .code-wrap:not(.prompt):not(.ai-ref-code) {
  /* non-prompt code should be rare on student page */
}
