/* ===========================================================
   Legend Hub – Historian Overlay (Full CSS)
   2-column layout: Navigation | Main Content (with inline media)
   =========================================================== */

/* ----------- Variables & globals ----------- */
:root {
  --hist-side-gutter: clamp(12px, 2.2vw, 36px);
  --radius: 16px;
  --bg: #0e1116;
  --card: #181c24;
  --accent: #c9a227;
  --text: #e6edf3;
  --muted: #8b949e;
  --ring: #2a2f36;
}

/* ======= Card (wrapper) ======= */
.histCharacter-card {
  /* glassy block */
  border: 1px solid rgba(255,255,255,0.10);
  border-radius: 18px;
  padding: 14px;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);

  /* responsive chip grid */
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
}

/* ======= Item (button/chip) ======= */
.histCharacter-btn {
  box-sizing: border-box;    /* padding doesn’t break layout */
  width: 100%;               /* fill grid cell */
  padding: 14px 18px;        /* change freely; no overlap */
  border-radius: 999px;
  text-align: center;
  font-size: 0.9rem;
  font-weight: 500;
  color: #ffffff;

  background: rgba(0,0,0,4)!important;
  border: 1px solid rgba(255, 255, 255, 0.2)!important;

  cursor: pointer;
  transition: transform .15s ease, box-shadow .2s ease, background .2s, border-color .2s;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; /* long names safe */
}
.histCharacter-btn:hover {
  background: rgba(0,0,0,6)!important;
  border: 1px solid rgba(255, 255, 255, 0.4)!important;
  transform: translateY(-1px);
  box-shadow: 0 6px 16px rgba(0,0,0,.28);
}
.histCharacter-btn:active {
  transform: translateY(0);
  box-shadow: 0 3px 8px rgba(0,0,0,.22);
}

/* small screens: tighter columns */
@media (max-width: 640px) {
  .histCharacter-card { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }
  .histCharacter-btn { padding: 12px 14px; }
}


/* ----------- Overlay & sheet container ----------- */
#hist-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.15);
  backdrop-filter: blur(0.5px);
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s ease;
  z-index: 9998;
  display: none; /* important: truly removed when closed */
}
#hist-overlay.hist-open {
  display: block;
  opacity: 1;
  pointer-events: auto;
}

#hist-sheet {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  height: 100vh;
  max-height: 100vh;
  border-top-left-radius: var(--radius);
  border-top-right-radius: var(--radius);
  background: rgba(18, 18, 24, 0.75);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid rgba(255, 255, 255, 0.1) !important;
  box-shadow: 0 -12px 40px rgba(0,0,0,.35);
  transform: translateY(8px) translateZ(0);
  opacity: 0;
  transition: transform .25s ease, opacity .25s ease, height .12s ease;
  z-index: 9999;
  display: grid;
  grid-template-rows: 1fr; /* only content; header is inside and sticky */
  overflow: hidden;
  pointer-events: none;
  will-change: transform, opacity;
}
@supports (height: 100dvh) {
  #hist-sheet {
    height: 100dvh;
    max-height: 100dvh;
  }
}
#hist-sheet.hist-open {
  transform: translateY(0) translateZ(0);
  opacity: 1;
  pointer-events: auto;
}

#hist-sheet:not(.hist-open),
#hist-overlay:not(.hist-open) {
  pointer-events: none !important;
}

/* ----------- Historian container (scroll host) ----------- */
#historian-container {
  padding: var(--hist-side-gutter);
  height: 100%;
  overflow: auto;   /* scrolling lives here */
  display: block;
}

/* Keep lesson screens flexible and scrollable */
#historian-container.hist-lesson {
  display: flex;
  flex-direction: column;
  overflow: auto; /* container scrolls; topbar sticks */
}
#historian-container.hist-lesson > .hist-grid--wide {
  flex: 1 1 auto;
  min-height: 0;
  overflow: visible;
}
#historian-container.hist-compact #hist-tabbar {
  position: sticky;
  top: 52px;              /* sits just under #hist-topbar (adjust if your topbar height changes) */
  z-index: 25;
  background: rgba(0,0,0,0.4);
  border: 1px solid rgba(255, 255, 255, 0.2);
  padding-top: 6px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin: 6px 0 10px 0;
}

/* ----------- General look ----------- */
body.hist-focus {
  background: var(--bg);
  color: var(--text);
  font-family: Inter, system-ui, sans-serif;
  transition: background .4s ease;
  overflow: hidden; /* Prevent background scroll while sheet open */
}
.historian-container {
  position: relative;
  z-index: 1;
  width: calc(100vw - (var(--hist-side-gutter) * 2));
  max-width: none;
  margin: 0 auto;
  background: rgba(0,0,0,0.4);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: var(--radius);
  padding: 28px;
  box-shadow: 0 0 20px rgba(0,0,0,.15);
}

/* ----------- Edge-to-edge toggle ----------- */
body.hist-edge .historian-container {
  width: 100vw; max-width: none; margin: 0; border-radius: 0; box-shadow: none; padding-left: 24px; padding-right: 24px;
  background: rgba(255,255,255,.04);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}

/* ----------- Top bar (always visible) ----------- */
#hist-topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  background: #00000;

}

/* ----------- Basic components ----------- */
.hist-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 10px; }
.hist-title { color: var(--accent); margin: 0 0 8px; font-size: clamp(1.25rem, 2vw, 1.6rem); }
.hist-muted { color: var(--muted); }
.hist-card { 
  background: rgba(0,0,0,.6)!important;
  border: 1px solid rgba(255,255,255,0.2)!important;
  border-radius: var(--radius); 
  padding: 18px; 
  margin: 12px 0; 
}

.hist-btn {
  background:rgba(0,0,0,0.4);
  border: 1px solid rgba(255, 255, 255, 0.2);
  padding: 10px;
  border-radius: 999px;
  cursor: pointer;
  font-weight: 600;
  color: white;
  transition: box-shadow .2s, transform .15s;
}
.hist-btn:hover { background:rgba(0,0,0,0.6);
                border: 1px solid rgba(255, 255, 255, 0.4);}
.hist-ghost { background: transparent; color: inherit; border: 1px solid var(--ring); border-radius: 999px; padding: 8px 12px; cursor: pointer; }

/* ----------- Topbar button container - align back and close buttons ----------- */
#hist-topbar > div {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ----------- Lesson Hub Close Button (matches chat exit-chat-btn) ----------- */
.hist-close-btn {
  width: 32px;
  height: 32px;
  background-color: rgba(58,65,73, 0.5);
  border: 2px solid rgba(58,65,73, 0.7);
  border-radius: 50%;
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s ease;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  position: relative;
  overflow: hidden;
}

.hist-close-btn:hover {
  background-color: rgba(58,65,73, 0.7);
  border-color: rgba(58,65,73, 0.9);
  transform: scale(1.1);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

.hist-close-btn:active {
  transform: scale(0.95);
  transition: transform 0.1s ease;
}

.hist-close-btn i {
  font-size: 16px;
  color: white;
  position: relative;
  z-index: 1;
}

.hist-close-btn::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(255, 255, 255, 0.1);
  transform: scale(0);
  transition: transform 0.3s ease;
  border-radius: 50%;
  z-index: 0;
}

.hist-close-btn:hover::before {
  transform: scale(1);
}

.hist-input, .hist-field {
  padding: 10px; border-radius: 10px; border: 1px solid var(--ring); background: #101418; color: inherit;
}
.hist-input { flex: 1; }
.hist-field { width: 100%; }

/* ----------- Chat bubbles ----------- 
.hist-bubble { padding: 10px; border: 1px solid var(--ring); border-radius: 12px; }
.hist-bubble.user { background: rgba(255,255,255,.03); }
.hist-bubble.assistant { background: rgba(201,162,39,.08); }*/

/* ----------- Markdown content styling ----------- */
#hist-lesson-article h1, .hist-bubble h1 { color: var(--accent); font-size: 2rem; margin: 1.5rem 0 1rem; font-weight: 700; }
#hist-lesson-article h2, .hist-bubble h2 { color: var(--accent); font-size: 1.6rem; margin: 1.3rem 0 0.9rem; font-weight: 600; }
#hist-lesson-article h3, .hist-bubble h3 { color: var(--text); font-size: 1.3rem; margin: 1.1rem 0 0.7rem; font-weight: 600; }
#hist-lesson-article blockquote, .hist-bubble blockquote { border-left: 4px solid var(--accent); padding-left: 1rem; margin: 1rem 0; font-style: italic; color: var(--muted); }
#hist-lesson-article ul, #hist-lesson-article ol, .hist-bubble ul, .hist-bubble ol { color: var(--text); }
#hist-lesson-article ul li, #hist-lesson-article ol li, .hist-bubble ul li, .hist-bubble ol li { margin-bottom: 0.4rem; }
#hist-lesson-article ul li::marker, .hist-bubble ul li::marker { color: var(--accent); }
#hist-lesson-article strong, .hist-bubble strong { color: var(--accent); font-weight: 600; }
#hist-lesson-article em, .hist-bubble em { color: var(--text); }

#hist-lesson-article { position: relative; isolation: isolate; }
#hist-lesson-article::after {
  content: ""; position: absolute; inset: -8px; border-radius: 16px; z-index: -1;
  background: radial-gradient(60% 60% at 50% 40%, rgba(201,162,39,.12), transparent 60%);
  animation: breathe 6s ease-in-out infinite;
}
@keyframes breathe { 0%,100% { opacity:.4; filter:blur(20px); } 50% { opacity:.9; filter:blur(26px); } }

/* ----------- Subtopic rail ----------- */
.hist-rail { 
  position: sticky; 
  top: 64px; 
  background: rgba(255,255,255,.06); 
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(255,255,255,.2) !important; 
  border-radius: var(--radius); 
  padding: 14px; 
}
.hist-rail h4 { margin: 0 0 8px; color: var(--accent); }
.hist-rail .rail-item { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 10px; border-radius: 10px; cursor: pointer; border: 1px solid transparent; }
.hist-rail .rail-item:hover { background: rgba(0,0,0,1)!important; border-color: rgba(255, 255, 255, 0.4)!important; }
.hist-rail .rail-item.active { background: rgba(201,162,39,.10); border-color: rgba(201,162,39,.25); }
#topic-stack .hist-rail { position: static; max-height: none; overflow: visible; }

/* ===========================================================
   WIDE GRID LAYOUT – 2 columns: rail | main content
   =========================================================== */
.hist-grid--wide { display: grid; grid-template-columns: 280px 1fr; gap: 24px; align-items: start; height: 100%; }
.hist-rail, .content-col { min-height: 0; max-height: 100%; overflow: auto; }
.content-col > .hist-card { height: auto; }
#hist-lesson-article { max-height: none; }

/* Inline media embedded within lesson text (placed by [MEDIA:n] markers) */
.inline-media-embed {
  margin: 20px 0;
  padding: 16px;
  background: rgba(255,255,255,.02);
  border: 1px solid rgba(255,255,255,.08);
  border-radius: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.inline-media-embed img {
  width: 100%;
  max-width: 600px;
  height: auto;
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,.1);
  margin: 0 auto;
  display: block;
}
.inline-media-embed video {
  width: 100%;
  max-width: 600px;
  height: auto;
  border-radius: 12px;
  margin: 0 auto;
  display: block;
}
.inline-media-embed iframe.hist-iframe {
  width: 100%;
  max-width: 600px;
  aspect-ratio: 16 / 9;
  border: 0;
  border-radius: 12px;
  margin: 0 auto;
  display: block;
}
.inline-media-embed figcaption {
  font-size: 0.9rem;
  color: var(--muted);
  text-align: center;
  font-style: italic;
  padding: 0 8px;
  line-height: 1.4;
}

/* Fallback media section for media not placed inline */
.inline-media-section { margin: 24px 0; }
.inline-media-section h3 { color: var(--accent); margin-bottom: 16px; font-size: 1.1rem; }
.inline-media-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 16px; }
.inline-media-grid .inline-media-embed { margin: 0; }
.hist-iframe { width: 100%; aspect-ratio: 16 / 9; border: 0; border-radius: 12px; background: rgba(255,255,255,.02); outline: 1px solid rgba(255,255,255,.08); }

#hist-lesson-article hr, .hist-bubble hr { border: 0; border-top: 1px solid var(--ring); margin: 1rem 0; opacity: .7; }
#hist-lesson-article, .hist-bubble.assistant, .hist-bubble.user { line-height: 1.55; }
#hist-lesson-article p, .hist-bubble p { margin: 0 0 0.85rem; }
#hist-lesson-article ul, #hist-lesson-article ol, .hist-bubble ul, .hist-bubble ol { margin: 0 0 0.85rem 1.25rem; padding-left: 1.1rem; }
#hist-lesson-article pre code, .hist-bubble pre code { display: block; padding: .75rem; border-radius: 8px; background: #0f1320; overflow-x: auto; font-size: .9rem; }
#hist-lesson-article code:not(pre code), .hist-bubble code:not(pre code) { padding: .1rem .35rem; border-radius: 6px; background: #0f1320; }
.katex-display { margin: 1rem 0; overflow-x: auto; }
.katex { font-size: 1.1em; }
.katex-display > .katex { display: block; text-align: center; }

/* ===========================================================
   RESPONSIVE BREAKPOINTS
   =========================================================== */
@media (max-width: 1199px) {
  .hist-grid--wide { grid-template-columns: 240px 1fr; }
}
@media (max-width: 900px) {
  .hist-grid--wide { grid-template-columns: 220px 1fr; gap: 16px; }
}

/* --- COMPACT MODE (<=768px): single-column with dropdown navigation --- */
#historian-container.hist-compact .hist-grid--wide { grid-template-columns: 1fr; height: auto; }
#historian-container.hist-compact .hist-rail { display: none; }
#historian-container.hist-compact .content-col { max-height: none; overflow: visible; }

/* Subtopic dropdown for compact mode */
.hist-subtopic-dropdown {
  margin-bottom: 16px;
  padding: 12px 16px;
  background: rgba(255,255,255,.05);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-radius: var(--radius);
  border: 1px solid rgba(255,255,255,.1) !important;
}
.hist-subtopic-dropdown label {
  display: block;
  margin-bottom: 8px;
  font-size: 0.85rem;
}
.hist-select {
  width: 100%;
  padding: 12px 16px;
  font-size: 1rem;
  background: rgba(255,255,255,.05);
  color: inherit;
  border: 1px solid var(--ring);
  border-radius: 12px;
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%23999' viewBox='0 0 16 16'%3E%3Cpath d='M8 11L3 6h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 16px center;
}
.hist-select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(201,162,39,.2);
}
.hist-select option {
  background: #1a1a1a;
  color: #fff;
  padding: 8px;
}

/* Ensure columns scroll in compact */
#historian-container.hist-compact .content-col {
  max-height: 100%;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}

/* Narrower than 768px uses compact mode */
@media (max-width: 768px) {
  .historian-container { width: 100%; padding: 16px; }
}

/* Ultra-wide */
@media (min-width: 1400px) {
  .hist-grid--wide { grid-template-columns: 300px 1fr; }
}
@media (min-width: 1800px) {
  .hist-grid--wide { grid-template-columns: 320px 1fr; }
}

/* ----------- Hide lesson section scrollbars (keep scrolling) ----------- */
.content-col::-webkit-scrollbar, #hist-lesson-article::-webkit-scrollbar { width: 0; height: 0; }
.content-col, #hist-lesson-article { scrollbar-width: none; -ms-overflow-style: none; }

/* Guard layering */
.content-col { position: relative; z-index: 1; }

/* ----------- Quiz UI ----------- */
.quiz-toolbar { display: grid; grid-template-columns: auto 1fr auto; align-items: center; }
.quiz-list {
  display: flex; align-items: center; gap: 12px;
  padding: 6px;
  overflow-x: auto; overflow-y: hidden; white-space: nowrap;
  scroll-snap-type: x mandatory; -webkit-overflow-scrolling: touch;
}
.quiz-pill {
  width: 36px;                
  height: 36px;
  border: 1px solid var(--ring);
  background: rgba(255,255,255,.03);
  color: inherit;
  padding: 6px 10px;
  border-radius: 50%;
  cursor: pointer;
  scroll-snap-align: center;
  transition: transform .16s ease, background .16s ease, border-color .16s ease;
}
.quiz-pill.active {
  background: rgba(201,162,39,.12);
  border-color: rgba(201,162,39,.3);
  color: var(--accent);
  transform: scale(1.06);     /* subtle emphasis */
}
#quiz-prev,
#quiz-next,
#quiz-toggle {
  width: 36px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;

  border: 1px solid var(--ring);
  background: rgba(255,255,255,.03);
  color: inherit;
  border-radius: 50%;
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  transition: transform .16s ease, background .16s ease, border-color .16s ease;
}
.quiz-list::-webkit-scrollbar { height: 0; }
.quiz-pill { scroll-snap-align: center; }
.quiz-ok, .quiz-bad {
  margin-top: 6px; padding: 6px 10px; border-radius: 8px; display: inline-block; border: 1px solid var(--ring);
}
.quiz-ok { background: rgba(46, 204, 113, .12); }
.quiz-bad { background: rgba(231, 76, 60, .12); }
#quiz-card .quiz-controls { display: flex; align-items: center; gap: 8px; }

/* ----------- iOS smooth scroll on key panes ----------- */
.content-col, .engage-col, .media-col { -webkit-overflow-scrolling: touch; }


/* ===================== Bottom Expand/Collapse (Icon/Text, Smooth) ===================== */

/* Make the lesson rail a vertical stack so the button sits at the bottom */
#lesson-grid .hist-rail.rail-with-bottom-toggle {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* Minimal button: transparent, no extra BG — only icon + text */
#lesson-grid .rail-toggle-bottom {
  margin-top: auto;                    /* push to bottom */
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 6px;
  background: transparent;             /* ← no background */
  border: 0;                           /* ← no border */
  color: var(--accent);
  font-weight: 600;
  cursor: pointer;
}

/* Icon + text micro-interactions */
#lesson-grid .rail-toggle-bottom .chev {
  display: inline-block;
  transition: transform .18s ease;
}
#lesson-grid .rail-toggle-bottom .txt {
  display: inline-block;
  overflow: hidden;
  white-space: nowrap;
  max-width: 200px;
  opacity: 1;
  transform: translateX(0);
  transition: max-width .22s ease, opacity .18s ease, transform .18s ease;
}

/* Collapsed: icon only (text smoothly hides) */
#lesson-grid .hist-rail[data-rail="lesson"].hist-rail--collapsed .rail-toggle-bottom .txt {
  max-width: 0;
  opacity: 0;
  transform: translateX(-6px);
}

/* Optional: rotate chevron when expanded/collapsed */
#lesson-grid .hist-rail[data-rail="lesson"].hist-rail--collapsed .rail-toggle-bottom .chev {
  transform: rotate(180deg);
}

/* Hide everything in the lesson rail except the bottom button when collapsed */
#lesson-grid .hist-rail[data-rail="lesson"].hist-rail--collapsed > *:not(#rail-toggle-bottom) {
  display: none !important;
}

/* Grid: shrink only the lesson rail when collapsed (keeps main content) */
#lesson-grid.rail-collapsed { grid-template-columns: 52px 1fr !important; }

/* Keep the rail footprint tight when collapsed */
#lesson-grid.rail-collapsed .hist-rail[data-rail="lesson"] {
  padding: 8px;
  width: 52px;
  min-width: 52px;
}
/* --- Compact always stays 1 column (even when collapsed) --- */
#historian-container.hist-compact #lesson-grid,
#historian-container.hist-compact #lesson-grid.rail-collapsed {
  grid-template-columns: 1fr !important;
}

/* In compact, don't constrain the rail to 52px when collapsed */
#historian-container.hist-compact #lesson-grid.rail-collapsed .hist-rail[data-rail="lesson"] {
  width: auto; min-width: 0; padding: 8px 0;
}

/* Keep the button small and anchored near the bottom in compact */
#historian-container.hist-compact #lesson-grid .hist-rail.rail-with-bottom-toggle {
  display: block; /* stack naturally */
}
#historian-container.hist-compact #lesson-grid #rail-toggle-bottom {
  position: sticky; bottom: 8px; /* stays reachable when scrolling */
}

/* --- Only shrink the first column on NON-compact layouts --- */
#historian-container:not(.hist-compact) #lesson-grid.rail-collapsed {
  grid-template-columns: 52px 1fr !important;
}

/* Smoothen the feel: rail itself eases when collapsing */
#lesson-grid .hist-rail[data-rail="lesson"] {
  transition: width .22s ease, padding .22s ease, max-height .22s ease;
}

/* Text fade/slide is already smooth; keep it here for clarity */
#lesson-grid .rail-toggle-bottom .txt {
  transition: max-width .22s ease, opacity .18s ease, transform .18s ease;
}

/* Collapsed: still hide rail children except the bottom button */
#lesson-grid .hist-rail[data-rail="lesson"].hist-rail--collapsed > *:not(#rail-toggle-bottom) {
  display: none !important;
}

/* ===========================================================
   CLEAN STYLE PATCH – Remove all thin divider lines RIdone V1
   =========================================================== */

/* Remove global borders that draw lines */
*, *::before, *::after {
  border: none !important;
  outline: none !important;
}

.engage-col .hist-card#hist-chat-card,
.hist-chat-card {
  display: flex;
  flex-direction: column;
  gap: 12px;
  height: 100%;
  min-height: 320px;
}

/* Scrollable chat window */
#hist-chat-log {
  flex: 1 1 auto;
  overflow: auto;
  padding: 12px;
  border-radius: var(--radius);
  background: linear-gradient(180deg, rgba(255,255,255,0.02), rgba(255,255,255,0.005));
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.04);
}

/* Sticky composer */
.hist-chat-composer {
  position: sticky;
  bottom: 0;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: end;
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--ring);
  border-radius: calc(var(--radius) + 6px);
  background: rgba(24,28,36,0.85);
  backdrop-filter: blur(6px);
}

/* Composer controls */
.hist-chat-icon,
.hist-chat-send {
  appearance: none;
  border: 1px solid var(--ring);
  background: rgba(255,255,255,0.03);
  border-radius: 12px;
  padding: 8px 10px;
  line-height: 1;
  cursor: pointer;
  transition: transform .16s ease, background .16s ease, border-color .16s ease, opacity .16s ease;
}
.hist-chat-icon:hover,
.hist-chat-send:hover {
  background: rgba(255,255,255,0.06);
  border-color: rgba(255,255,255,0.16);
  transform: translateY(-1px);
}
.hist-chat-send.is-sending { opacity: .7; cursor: default; }

/* Multiline textarea (auto-grow) */
#hist-chat-input {
  resize: none;
  min-height: 44px;
  max-height: 160px;
  padding: 10px 12px;
  border: 1px solid var(--ring);
  border-radius: 14px;
  background: rgba(255,255,255,0.02);
  color: var(--text);
  font: inherit;
  line-height: 1.35;
  outline: none;
}
#hist-chat-input:focus {
  border-color: rgba(201,162,39,.35);
  box-shadow: 0 0 0 3px rgba(201,162,39,.12);
}

/* ---- Modern bubbles ---- */
.hist-bubble {
  --bubble-w: min(72ch, 92%);
  max-width: var(--bubble-w);
  width: fit-content;
  padding: 10px 12px;
  border-radius: 18px;
  border: 1px solid rgba(255,255,255,0.06);
  background: rgba(255,255,255,0.03);
  box-shadow: 0 2px 12px rgba(0,0,0,0.25);
  word-wrap: break-word;
  overflow-x: hidden;
}
.hist-bubble + .hist-bubble { margin-top: 8px; }

.hist-bubble.user {
  margin-left: auto;
  border-color: rgba(201,162,39,.28);
  background: linear-gradient(180deg, rgba(201,162,39,.20), rgba(201,162,39,.12));
  color: var(--text);
}
.hist-bubble.assistant {
  margin-right: auto;
  background: linear-gradient(180deg, rgba(255,255,255,.05), rgba(255,255,255,.02));
}
.hist-bubble.typing { margin-right: auto; }

/* Markdown inside bubbles */
.hist-bubble h1, .hist-bubble h2, .hist-bubble h3 { margin: 0 0 .3em; }
.hist-bubble p { margin: .4em 0; }
.hist-bubble code {
  background: rgba(255,255,255,.06);
  border: 1px solid rgba(255,255,255,.08);
  border-radius: 6px;
  padding: .1em .35em;
}
.hist-bubble pre code {
  display: block;
  padding: 10px;
  border-radius: 10px;
  overflow-x: auto;
}

/* Small screens */
@media (max-width: 900px) {
  #hist-chat-log { padding: 10px; }
  .hist-chat-composer { grid-template-columns: auto 1fr auto; }
}

/* No extra thin separators in chat */
#hist-chat-log .separator { display: none; }

/* ===========================================================
   Skeleton Loading - Modern Shimmer Animation
   =========================================================== */

/* Shimmer animation keyframes */
@keyframes skeleton-shimmer {
  0% {
    background-position: -200% 0;
  }
  100% {
    background-position: 200% 0;
  }
}

@keyframes skeleton-pulse {
  0%, 100% {
    opacity: 0.4;
  }
  50% {
    opacity: 0.7;
  }
}

@keyframes skeleton-fade-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Skeleton container */
.hist-skeleton-container {
  display: flex;
  flex-direction: column;
  gap: 20px;
  padding: 24px;
  animation: skeleton-fade-in 0.3s ease-out;
}

/* Skeleton loading header with status text */
.hist-skeleton-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
}

.hist-skeleton-status {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 500;
}

.hist-skeleton-dot {
  width: 8px;
  height: 8px;
  background: var(--accent);
  border-radius: 50%;
  animation: skeleton-pulse 1.2s ease-in-out infinite;
}

.hist-skeleton-dot:nth-child(2) { animation-delay: 0.2s; }
.hist-skeleton-dot:nth-child(3) { animation-delay: 0.4s; }

/* Base skeleton element */
.skeleton {
  background: linear-gradient(
    90deg,
    rgba(255, 255, 255, 0.04) 0%,
    rgba(255, 255, 255, 0.08) 20%,
    rgba(255, 255, 255, 0.12) 40%,
    rgba(255, 255, 255, 0.08) 60%,
    rgba(255, 255, 255, 0.04) 100%
  );
  background-size: 200% 100%;
  animation: skeleton-shimmer 1.8s ease-in-out infinite;
  border-radius: 8px;
}

/* Skeleton shapes */
.skeleton-text {
  height: 16px;
  border-radius: 4px;
}

.skeleton-text.short { width: 40%; }
.skeleton-text.medium { width: 65%; }
.skeleton-text.long { width: 85%; }
.skeleton-text.full { width: 100%; }

.skeleton-title {
  height: 28px;
  width: 50%;
  border-radius: 6px;
  margin-bottom: 8px;
}

.skeleton-subtitle {
  height: 20px;
  width: 35%;
  border-radius: 4px;
}

/* Skeleton card (for topic chips) */
.skeleton-card {
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius);
  padding: 18px;
  position: relative;
  overflow: hidden;
}

.skeleton-card::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(
    90deg,
    transparent 0%,
    rgba(255, 255, 255, 0.03) 50%,
    transparent 100%
  );
  background-size: 200% 100%;
  animation: skeleton-shimmer 1.8s ease-in-out infinite;
}

/* Skeleton chip (for topic buttons) */
.skeleton-chip {
  height: 44px;
  border-radius: 999px;
  background: linear-gradient(
    90deg,
    rgba(255, 255, 255, 0.03) 0%,
    rgba(255, 255, 255, 0.06) 20%,
    rgba(255, 255, 255, 0.08) 40%,
    rgba(255, 255, 255, 0.06) 60%,
    rgba(255, 255, 255, 0.03) 100%
  );
  background-size: 200% 100%;
  animation: skeleton-shimmer 1.8s ease-in-out infinite;
  border: 1px solid rgba(255, 255, 255, 0.06);
}

/* Topic grid skeleton */
.skeleton-topic-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
}

/* Skeleton content block (for lesson text) */
.skeleton-content-block {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.skeleton-paragraph {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* Lesson skeleton layout */
.skeleton-lesson-layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: 24px;
}

.skeleton-lesson-main {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.skeleton-lesson-sidebar {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* Skeleton media placeholder */
.skeleton-media {
  width: 100%;
  height: 180px;
  border-radius: 12px;
  background: linear-gradient(
    135deg,
    rgba(255, 255, 255, 0.02) 0%,
    rgba(255, 255, 255, 0.05) 50%,
    rgba(255, 255, 255, 0.02) 100%
  );
  background-size: 200% 200%;
  animation: skeleton-shimmer 2s ease-in-out infinite;
  border: 1px solid rgba(255, 255, 255, 0.06);
  display: flex;
  align-items: center;
  justify-content: center;
}

.skeleton-media-icon {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.04);
  animation: skeleton-pulse 1.5s ease-in-out infinite;
}

/* Skeleton nav items (for subtopic rail) */
.skeleton-nav-item {
  height: 40px;
  border-radius: 10px;
  margin-bottom: 8px;
}

/* Staggered animation delays for natural feel */
.skeleton-chip:nth-child(1), .skeleton-nav-item:nth-child(1) { animation-delay: 0s; }
.skeleton-chip:nth-child(2), .skeleton-nav-item:nth-child(2) { animation-delay: 0.1s; }
.skeleton-chip:nth-child(3), .skeleton-nav-item:nth-child(3) { animation-delay: 0.2s; }
.skeleton-chip:nth-child(4), .skeleton-nav-item:nth-child(4) { animation-delay: 0.3s; }
.skeleton-chip:nth-child(5), .skeleton-nav-item:nth-child(5) { animation-delay: 0.4s; }
.skeleton-chip:nth-child(6), .skeleton-nav-item:nth-child(6) { animation-delay: 0.5s; }
.skeleton-chip:nth-child(7) { animation-delay: 0.6s; }
.skeleton-chip:nth-child(8) { animation-delay: 0.7s; }

.skeleton-text:nth-child(1) { animation-delay: 0s; }
.skeleton-text:nth-child(2) { animation-delay: 0.1s; }
.skeleton-text:nth-child(3) { animation-delay: 0.15s; }
.skeleton-text:nth-child(4) { animation-delay: 0.2s; }
.skeleton-text:nth-child(5) { animation-delay: 0.25s; }

/* Responsive adjustments */
@media (max-width: 640px) {
  .skeleton-topic-grid {
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  }
  .skeleton-chip {
    height: 40px;
  }
  .skeleton-media {
    height: 140px;
  }
}

/* Button spinner for inline loading states */
@keyframes btn-spinner-rotate {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

.hist-btn-spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  margin-right: 8px;
  border: 2px solid rgba(255, 255, 255, 0.2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: btn-spinner-rotate 0.8s linear infinite;
  vertical-align: middle;
}

