/* ===== Guide Card ===== */
.guide-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 1.5rem;
  text-decoration: none;
  color: inherit;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  box-shadow: var(--shadow-sm);
  transition: transform var(--transition), box-shadow var(--transition), border-color var(--transition);
}
.guide-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-md); border-color: var(--color-primary); text-decoration: none; }
.guide-card-top { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; }
.guide-card-chapter {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--color-text-muted);
}
.guide-card-tag {
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.18rem 0.55rem;
  border-radius: 999px;
  border: 1px solid var(--color-border);
  background: transparent;
  color: var(--color-primary);
  cursor: pointer;
  transition: background var(--transition), color var(--transition), border-color var(--transition);
  line-height: 1.4;
}
.guide-card-tag:hover,
.guide-card-tag.active { background: var(--color-primary); color: #fff; border-color: var(--color-primary); }
.guide-card h3 { font-size: 1rem; line-height: 1.4; color: var(--color-text); }
.guide-card p { font-size: 0.875rem; color: var(--color-text-muted); margin: 0; flex: 1; }
.guide-card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: auto;
  padding-top: 0.75rem;
  border-top: 1px solid var(--color-border);
}
.guide-card-meta { display: flex; gap: 0.6rem; align-items: center; }
.difficulty-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
}
.dot-beginner { background: #22c55e; }
.dot-intermediate { background: #f59e0b; }
.dot-advanced { background: #ef4444; }
.read-time { font-size: 0.78rem; color: var(--color-text-muted); }
.guide-card-arrow { color: var(--color-primary); font-size: 1rem; }

/* ===== Callout Boxes ===== */
.callout {
  border-radius: var(--radius-sm);
  padding: 1rem 1.25rem;
  margin: 1.5rem 0;
  border-left: 4px solid;
  display: flex;
  gap: 0.75rem;
}
.callout-icon { font-size: 1.1rem; flex-shrink: 0; margin-top: 0.1rem; }
.callout-body { flex: 1; }
.callout-body p:last-child { margin-bottom: 0; }
.callout-body strong { display: block; margin-bottom: 0.25rem; font-size: 0.875rem; text-transform: uppercase; letter-spacing: 0.05em; }
.callout.tip { background: #f0fdf4; border-color: #22c55e; color: #166534; }
.callout.note { background: #eff6ff; border-color: #3b82f6; color: #1e40af; }
.callout.warn { background: #fffbeb; border-color: #f59e0b; color: #92400e; }
.callout.danger { background: #fef2f2; border-color: #ef4444; color: #991b1b; }

/* ===== Code Blocks ===== */
.code-block {
  background: #0f172a;
  border-radius: var(--radius-md);
  border: 1px solid #1e293b;
  margin: 1.5rem 0;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}
.code-block-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.6rem 1rem;
  background: rgba(255, 255, 255, 0.04);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}
.code-lang { font-size: 0.75rem; font-weight: 600; color: #64748b; font-family: var(--font-mono); text-transform: uppercase; letter-spacing: 0.08em; }
.copy-btn {
  background: rgba(255, 255, 255, 0.08);
  border: none;
  color: #94a3b8;
  font-size: 0.75rem;
  padding: 0.25rem 0.65rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-family: var(--font-body);
  transition: background var(--transition), color var(--transition);
}
.copy-btn:hover { background: rgba(255, 255, 255, 0.14); color: #e2e8f0; }
.copy-btn.copied { color: #22c55e; }
.code-block pre {
  margin: 0;
  padding: 1.25rem;
  overflow-x: auto;
}
.code-block code {
  background: none !important;
  padding: 0 !important;
  border: none;
  border-radius: 0;
  font-family: var(--font-mono);
  font-size: 0.875rem;
  line-height: 1.65;
  color: #e2e8f0;
}

/* ===== Table ===== */
.table-wrap { overflow-x: auto; margin: 1.5rem 0; border-radius: var(--radius-md); border: 1px solid var(--color-border); box-shadow: var(--shadow-sm); }
table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
thead th { background: #f3f4f6; color: var(--color-text); font-weight: 600; text-align: left; padding: 0.75rem 1rem; border-bottom: 1px solid var(--color-border); white-space: nowrap; }
tbody td { padding: 0.7rem 1rem; border-bottom: 1px solid var(--color-border); vertical-align: top; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: #f9fafb; }

/* ===== SVG Diagram ===== */
.diagram-svg { margin: 1.75rem auto; max-width: 860px; }
.diagram-svg svg { display: block; width: 100%; height: auto; }

/* ===== Excalidraw responsive height ===== */
@media (max-width: 480px) {
  .excalidraw-wrap { height: 300px !important; }
}

/* ===== Responsive ===== */
@media (max-width: 640px) {
  .code-block-header { flex-wrap: wrap; gap: 0.35rem; padding: 0.5rem 0.75rem; }
  .table-wrap { font-size: 0.8rem; }
}

/* ===== Scroll-to-top button ===== */
.scroll-top {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  width: 2.5rem;
  height: 2.5rem;
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, box-shadow var(--transition), transform var(--transition);
  z-index: 100;
  box-shadow: var(--shadow-md);
  color: var(--color-text-muted);
}
.scroll-top.visible { opacity: 1; pointer-events: auto; }
.scroll-top:hover { box-shadow: var(--shadow-lg); transform: translateY(-2px); color: var(--color-primary); }

/* ===== Footer Newsletter ===== */
.footer-newsletter { margin-bottom: 0.75rem; }
.footer-newsletter-label { font-size: 0.875rem; color: var(--color-text-muted); margin: 0 0 0.5rem; }
.footer-newsletter-row {
  display: flex;
  gap: 0;
  max-width: min(380px, 100%);
  margin: 0 auto;
  background: var(--color-surface);
  border: 1.5px solid var(--color-border-strong);
  border-radius: var(--radius-pill);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  transition: border-color var(--transition), box-shadow var(--transition);
}
.footer-newsletter-row:focus-within { border-color: var(--color-primary); box-shadow: 0 0 0 3px var(--color-primary-light); }
.footer-newsletter-row input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  padding: 0.55rem 1.1rem;
  font-size: 0.875rem;
  color: var(--color-text);
  font-family: var(--font-body);
}
.footer-newsletter-row button {
  background: var(--color-primary);
  color: #fff;
  border: none;
  padding: 0.55rem 1.25rem;
  font-size: 0.875rem;
  font-weight: 600;
  border-radius: var(--radius-pill);
  cursor: pointer;
  font-family: var(--font-body);
  white-space: nowrap;
  transition: background var(--transition);
  margin: 3px;
}
.footer-newsletter-row button:hover { background: #4338ca; }
.footer-newsletter-row button:disabled { opacity: 0.6; cursor: not-allowed; }
.footer-newsletter-msg { font-size: 0.78rem; margin-top: 0.5rem; min-height: 1.2em; }
.footer-newsletter-msg.ok { color: #166534; }
.footer-newsletter-msg.err { color: #991b1b; }

/* ===== Feedback Tab ===== */
.feedback-tab {
  display: block;
  position: fixed;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  writing-mode: vertical-rl;
  text-orientation: mixed;
  background: var(--color-primary);
  color: #fff;
  font-family: var(--font-body);
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  text-decoration: none;
  padding: 1rem 0.55rem;
  border-radius: var(--radius-sm) 0 0 var(--radius-sm);
  box-shadow: var(--shadow-md);
  z-index: 48;
  transition: background var(--transition), transform var(--transition), box-shadow var(--transition);
}
.feedback-tab:hover {
  background: #4338ca;
  transform: translateY(-50%) translateX(-3px);
  box-shadow: var(--shadow-lg);
  text-decoration: none;
}
@media (max-width: 767px) {
  .feedback-tab { font-size: 0.55rem; padding: 0.6rem 0.4rem; }
}
@media (max-width: 480px) {
  .feedback-tab { font-size: 0.55rem; padding: 0.6rem 0.4rem; }
  .notes-panel-toggle { right: 1rem; bottom: 4.5rem; }
  .scroll-top { right: 1rem; bottom: 1.25rem; }
}

/* ===== Text Highlight Mark ===== */
mark.text-highlight {
  background: #c4b5fd;
  color: #1e1b4b;
  cursor: pointer;
  padding: 0 2px;
  border-radius: 2px;
  transition: background 0.1s;
}
mark.text-highlight:hover { background: #a78bfa; }

/* ===== Selection Tooltip ===== */
.hl-tooltip {
  position: fixed;
  z-index: 9100;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  font-family: var(--font-body);
  font-size: 0.75rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.12s;
  min-width: 180px;
  max-width: min(340px, 90vw);
  overflow: hidden;
}
.hl-tooltip.visible { opacity: 1; pointer-events: auto; }
.hl-tooltip-actions {
  display: flex;
  align-items: center;
  padding: 0.35rem 0.5rem;
  gap: 0.25rem;
  border-bottom: 1px solid var(--color-border);
  background: #f9fafb;
}
.hl-btn {
  font-family: var(--font-body);
  font-size: 0.72rem;
  font-weight: 600;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 0.35rem 0.65rem;
  transition: background var(--transition), color var(--transition);
  background: transparent;
  color: var(--color-text-muted);
}
.hl-btn:hover { background: var(--color-bg); color: var(--color-text); }
.hl-btn-highlight { color: #fff; background: var(--color-primary); }
.hl-btn-highlight:hover { background: #4338ca; color: #fff; }
.hl-btn-note { color: var(--color-text); }
.hl-btn-translate { color: var(--color-text); }
.hl-close {
  font-family: var(--font-body);
  font-size: 0.8rem;
  border: none;
  background: transparent;
  cursor: pointer;
  padding: 0.3rem 0.4rem;
  color: var(--color-text-muted);
  border-radius: var(--radius-sm);
  margin-left: auto;
  line-height: 1;
  transition: background var(--transition), color var(--transition);
}
.hl-close:hover { background: var(--color-bg); color: var(--color-text); }
.hl-tooltip-expand {
  display: none;
  flex-direction: column;
  gap: 0.5rem;
  padding: 0.75rem;
  border-top: 1px solid var(--color-border);
}
.hl-textarea {
  font-family: var(--font-body);
  font-size: 0.8rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.6rem;
  resize: vertical;
  width: 100%;
  box-sizing: border-box;
  outline: none;
  min-height: 64px;
  color: var(--color-text);
  background: var(--color-surface);
  transition: border-color var(--transition), box-shadow var(--transition);
}
.hl-textarea:focus { border-color: var(--color-primary); box-shadow: 0 0 0 3px var(--color-primary-light); }
.hl-expand-actions { display: flex; gap: 0.5rem; }
.hl-btn-save { background: var(--color-primary); color: #fff; }
.hl-btn-save:hover { background: #4338ca; color: #fff; }
.hl-btn-cancel { color: var(--color-text-muted); }
.hl-btn-cancel:hover { color: var(--color-text); background: var(--color-bg); }
.hl-btn-ai { padding: 0.3rem 0.4rem; }
.hl-btn-ai:hover { background: var(--color-bg); }

/* Translate panel */
.hl-tooltip-translate-panel {
  display: none;
  flex-direction: column;
  gap: 0.5rem;
  padding: 0.75rem;
  border-top: 1px solid var(--color-border);
}
.hl-translate-controls { display: flex; gap: 0.4rem; align-items: center; }
.hl-lang-select {
  font-family: var(--font-body);
  font-size: 0.75rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  padding: 0.3rem 0.4rem;
  flex: 1;
  cursor: pointer;
  outline: none;
  color: var(--color-text);
}
.hl-lang-select:focus { border-color: var(--color-primary); box-shadow: 0 0 0 3px var(--color-primary-light); }
.hl-btn-do-translate { background: var(--color-primary); color: #fff; white-space: nowrap; }
.hl-btn-do-translate:hover { background: #4338ca; color: #fff; }
.hl-btn-do-translate:disabled { opacity: 0.5; cursor: not-allowed; }
.hl-translate-result {
  font-size: 0.8rem;
  line-height: 1.5;
  color: var(--color-text);
  min-height: 0;
  word-break: break-word;
}
.hl-translate-result:not(:empty) {
  padding: 0.5rem 0.6rem;
  background: var(--color-primary-light);
  border-left: 3px solid var(--color-primary);
  border-radius: var(--radius-sm);
}
.hl-translate-loading { color: var(--color-text-muted); font-style: italic; }
.hl-translate-error { color: #991b1b; }

/* Tooltip arrow caret */
.hl-tooltip::after {
  content: '';
  position: absolute;
  bottom: -7px;
  left: 50%;
  transform: translateX(-50%);
  border: 5px solid transparent;
  border-top-color: var(--color-border);
  border-bottom: none;
  pointer-events: none;
}
.hl-tooltip.hl-tooltip-below::after {
  bottom: auto;
  top: -7px;
  border-top: none;
  border-bottom: 5px solid var(--color-border);
  border-top-color: transparent;
}

/* ===== Note Popover (click a highlight) ===== */
.hl-popover {
  position: fixed;
  z-index: 9050;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  font-family: var(--font-body);
  font-size: 0.8rem;
  width: min(280px, 90vw);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.12s;
  overflow: hidden;
}
.hl-popover.visible { opacity: 1; pointer-events: auto; }
.hl-popover-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--color-border);
  background: #f9fafb;
}
.hl-popover-label {
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--color-text-muted);
}
.hl-popover-quote {
  margin: 0;
  padding: 0.6rem 0.75rem;
  border-left: 3px solid var(--color-primary);
  font-size: 0.78rem;
  color: var(--color-text-muted);
  font-style: italic;
  background: var(--color-primary-light);
  border-bottom: 1px solid var(--color-border);
}
.hl-popover-note {
  margin: 0;
  padding: 0.6rem 0.75rem;
  font-size: 0.8rem;
  color: var(--color-text);
}
.hl-popover-empty { color: var(--color-text-muted); font-style: italic; }
.hl-delete-btn {
  display: block;
  width: 100%;
  border: none;
  border-top: 1px solid var(--color-border);
  background: transparent;
  cursor: pointer;
  font-family: var(--font-body);
  font-size: 0.72rem;
  font-weight: 600;
  color: #991b1b;
  padding: 0.5rem 0.75rem;
  text-align: left;
  transition: background var(--transition);
}
.hl-delete-btn:hover { background: #fef2f2; }

/* ===== Notes Panel Toggle ===== */
.notes-panel-toggle {
  position: fixed;
  bottom: 5.5rem;
  right: 2rem;
  z-index: 150;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-pill);
  box-shadow: var(--shadow-md);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.45rem 0.85rem;
  font-family: var(--font-body);
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--color-text);
  white-space: nowrap;
  transition: box-shadow var(--transition), transform var(--transition), border-color var(--transition);
}
.notes-panel-toggle:hover {
  box-shadow: var(--shadow-lg);
  border-color: var(--color-primary);
  transform: translateY(-2px);
}
.notes-toggle-label { font-size: 0.75rem; }
.notes-toggle-count {
  background: var(--color-primary);
  color: #fff;
  border-radius: 999px;
  font-size: 0.6rem;
  min-width: 16px;
  height: 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
  font-weight: 700;
}
.notes-toggle-count:empty { display: none; }

/* ===== Notes Panel Slide-In ===== */
.notes-panel {
  position: fixed;
  top: 0;
  right: 0;
  height: 100%;
  width: 320px;
  max-width: 90vw;
  background: var(--color-surface);
  border-left: 1px solid var(--color-border);
  box-shadow: var(--shadow-lg);
  z-index: 9000;
  display: flex;
  flex-direction: column;
  transform: translateX(105%);
  transition: transform 0.22s ease;
  font-family: var(--font-body);
}
.notes-panel.open { transform: translateX(0); }
.notes-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--color-border);
  background: #f9fafb;
  flex-shrink: 0;
}
.notes-panel-title {
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--color-text-muted);
}
.notes-panel-close {
  border: none;
  background: transparent;
  cursor: pointer;
  font-size: 0.9rem;
  color: var(--color-text-muted);
  padding: 0.2rem 0.3rem;
  border-radius: var(--radius-sm);
  line-height: 1;
  transition: background var(--transition), color var(--transition);
}
.notes-panel-close:hover { background: var(--color-bg); color: var(--color-text); }
.notes-panel-body {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}
.notes-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 0.5rem;
  padding: 2rem 1rem;
  color: var(--color-text-muted);
  font-size: 0.8rem;
}
.notes-empty svg { opacity: 0.3; color: var(--color-text-muted); }
.notes-empty p { margin: 0; }
.note-item {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.note-item-quote {
  margin: 0;
  padding: 0.6rem 0.75rem;
  border-left: 3px solid var(--color-primary);
  font-size: 0.78rem;
  color: var(--color-text-muted);
  font-style: italic;
  background: var(--color-primary-light);
  border-bottom: 1px solid var(--color-border);
}
.note-item-text {
  margin: 0;
  padding: 0.6rem 0.75rem;
  font-size: 0.8rem;
  color: var(--color-text);
  border-bottom: 1px solid var(--color-border);
}
.note-item-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.4rem 0.75rem;
  background: #f9fafb;
}
.note-item-time {
  font-size: 0.68rem;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.note-item-delete {
  border: none;
  background: transparent;
  cursor: pointer;
  font-family: var(--font-body);
  font-size: 0.68rem;
  font-weight: 600;
  color: #991b1b;
  padding: 0.2rem 0.4rem;
  border-radius: var(--radius-sm);
  transition: background var(--transition);
}
.note-item-delete:hover { background: #fef2f2; }
