:root {
  --bg: #f7f8f4;
  --surface: #ffffff;
  --sidebar: #eef2e9;
  --sidebar-deep: #e3eadc;
  --text: #1c2922;
  --muted: #6b766f;
  --line: #dce2da;
  --green: #194f3b;
  --green-2: #2e6b51;
  --green-pale: #e5eee6;
  --lime: #d8e9a8;
  --task-bg: #F3F1E6;
  --task-line: #dcd7c5;
  --shadow: 0 14px 40px rgba(36, 53, 43, .08);
  --font-sans: "DM Sans", system-ui, -apple-system, sans-serif;
  --font-serif: "Fraunces", Georgia, serif;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  color: var(--text);
  background: var(--bg);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.55;
}

button, textarea { font: inherit; }

.wrap {
  margin: 0 auto;
  display: flex;
  height: 100vh;
  box-sizing: border-box;
  --ls-width: 260px;
}

/* Sidebar */
.sidebar {
  width: 260px;
  flex: 0 0 260px;
  padding: 20px 16px 16px;
  background: var(--sidebar);
  border-right: 1px solid rgba(41,74,56,.08);
  display: flex;
  flex-direction: column;
  gap: 8px;
  transition: width 0.2s ease, flex 0.2s ease, margin 0.2s ease, padding 0.2s ease;
}

.sidebar.collapsed {
  width: 0;
  flex: 0 0 0;
  margin: 0;
  padding: 0;
  overflow: hidden;
}

.sidebar-toggle {
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 100;
  background: var(--green);
  color: #fff;
  border: none;
  border-radius: 10px;
  width: 36px;
  height: 36px;
  font-size: 18px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}


.sidebar-title {
  font-family: var(--font-serif);
  font-size: 22px;
  font-weight: 600;
  margin: 4px 0 16px;
  line-height: 1.2;
  letter-spacing: -0.5px;
  color: var(--green);
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.sidebar-header-actions {
  display: flex;
  gap: 6px;
  align-items: center;
}

.sidebar-header h2 {
  font-size: 12px;
  font-weight: 700;
  margin: 0;
  color: #8b958e;
  text-transform: uppercase;
  letter-spacing: 0.12em;
}

.import-btn {
  min-width: 0;
  height: 36px;
  padding: 0 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid #cbd7cb;
  border-radius: 12px;
  background: rgba(255,255,255,.7);
  color: var(--green);
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
  transition: .2s ease;
}

.import-btn:hover {
  background: #fff;
  border-color: #abc0ae;
  transform: translateY(-1px);
}

.new-conv-btn {
  min-width: 0;
  height: 36px;
  padding: 0 12px;
  display: flex;
  align-items: center;
  gap: 6px;
  border: 1px solid #cbd7cb;
  border-radius: 12px;
  background: rgba(255,255,255,.7);
  color: var(--green);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: .2s ease;
}

.new-conv-btn:hover {
  background: #fff;
  border-color: #abc0ae;
  transform: translateY(-1px);
}

.conversations-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
  overflow-y: auto;
  flex: 1;
}

.conversations-list li {
  position: relative;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 10px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 13px;
  color: #4b5a50;
  transition: background 0.12s;
  user-select: none;
}

.conversations-list li:hover {
  background: rgba(255,255,255,.5);
}

.conversations-list li.active {
  background: rgba(255,255,255,.5);
  color: var(--text);
  font-weight: 600;
}

.conversations-list li .conv-title {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.conversations-list li .conv-menu-btn {
  background: transparent;
  border: none;
  color: var(--text);
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  padding: 0 2px;
  line-height: 1;
  min-height: auto;
  display: none;
  letter-spacing: 1px;
  width: 24px;
  height: 24px;
  border-radius: 6px;
  align-items: center;
  justify-content: center;
}

.conversations-list li:hover .conv-menu-btn {
  display: inline-flex;
}

.conversations-list li .conv-menu-btn:hover {
  color: var(--green);
}

.conv-menu-dropdown {
  position: fixed;
  z-index: 200;
  background: #fff;
  border: 1px solid #ddd;
  border-radius: 10px;
  box-shadow: 0 6px 24px rgba(0,0,0,0.12);
  display: flex;
  flex-direction: column;
  min-width: 140px;
  padding: 5px;
}

.conv-menu-dropdown button {
  background: none;
  border: none;
  color: #333;
  font-size: 13px;
  padding: 8px 12px;
  border-radius: 6px;
  cursor: pointer;
  text-align: left;
  font-weight: 520;
  display: block;
  width: 100%;
}

.conv-menu-dropdown button:hover {
  background: #f1f1f1;
}

.conv-menu-dropdown button:last-child {
  color: #b00020;
}

.conv-menu-dropdown button:last-child:hover {
  background: #ffebee;
}

.sidebar-empty {
  font-size: 13px;
  color: #99a19c;
  padding: 10px 4px;
}

/* Main content area */
.card {
  flex: 1;
  min-width: 0;
  background: transparent;
  border-radius: 0;
  box-shadow: none;
  padding: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

h1 {
  font-family: var(--font-serif);
  font-size: clamp(34px, 4vw, 48px);
  margin: 0;
  line-height: 1.08;
  letter-spacing: -1.6px;
  font-weight: 600;
}

.muted {
  color: var(--muted);
  font-size: 13px;
}

label {
  font-weight: 600;
  display: block;
  margin: 12px 0 6px;
}

textarea {
  width: 100%;
  min-height: 48px;
  max-height: 160px;
  resize: vertical;
  padding: 13px 52px 13px 14px;
  border: 1px solid #cfd8cf;
  border-radius: 15px;
  background: var(--surface);
  box-shadow: 0 10px 34px rgba(42, 58, 48, .1);
  font-size: 15px;
  box-sizing: border-box;
  font-family: inherit;
  line-height: 1.45;
  color: var(--text);
}

.composer {
  flex: 1;
  position: relative;
  display: flex;
  align-items: flex-end;
}

.composer textarea {
  width: 100%;
}

.composer button {
  position: absolute;
  right: 6px;
  bottom: 6px;
  width: 32px;
  height: 32px;
  padding: 0;
  border-radius: 9px;
  background: var(--green);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  cursor: pointer;
  min-height: auto;
  transition: background 0.15s;
}

.composer button:hover {
  background: var(--green-2);
}

.composer button:disabled {
  opacity: .55;
  cursor: not-allowed;
}

textarea:focus {
  outline: none;
  border-color: #8fa995;
  box-shadow: 0 10px 34px rgba(42, 58, 48, .1), 0 0 0 3px rgba(63, 111, 82, .08);
}

textarea::placeholder {
  color: #9aa29c;
}

.row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: center;
  margin-top: 12px;
}

/* Default button — green accent */
button {
  border: 0;
  background: var(--green);
  color: #fff;
  padding: 10px 16px;
  border-radius: 16px;
  font-weight: 650;
  cursor: pointer;
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1.2;
}

button:disabled {
  opacity: .6;
  cursor: not-allowed;
}

select {
  font-size: 13px;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
}

.chat-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Scrollable messages area */
.messages-area {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  min-width: 0;
}

.messages-inner {
  max-width: 900px;
  margin: 0 auto;
  width: 100%;
  padding: 24px 18px 200px;
  height: 100%;
}

/* Right sidebar (practice exercise panel) */
.right-sidebar {
  box-sizing: border-box;
  background: var(--sidebar);
  border-left: 1px solid rgba(41,74,56,.08);
  padding: 10px;
  width: calc((100vw - var(--ls-width) - 16px) / 2);
  min-width: 260px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow: auto;
  transition: width 0.2s ease, margin 0.2s ease, padding 0.2s ease;
  position: relative;
}

.resize-grip {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 8px;
  cursor: col-resize;
  z-index: 10;
}

.resize-grip::before {
  content: "";
  position: absolute;
  left: 1px;
  top: 50%;
  transform: translateY(-50%);
  width: 4px;
  height: 36px;
  border-radius: 3px;
  background: #ccc;
  transition: background 0.15s;
}

.resize-grip:hover::before {
  background: #999;
}

.right-sidebar.collapsed {
  width: 0 !important;
  min-width: 0 !important;
  margin: 0;
  padding: 0;
  border: none;
  overflow: hidden;
  resize: none;
}

.right-sidebar-toggle {
  position: fixed;
  top: 12px;
  right: 12px;
  z-index: 100;
  background: var(--green);
  color: #fff;
  border: none;
  border-radius: 10px;
  width: 36px;
  height: 36px;
  font-size: 18px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.right-sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.right-sidebar-title {
  font-size: 12px;
  font-weight: 700;
  margin: 0;
  color: #8b958e;
  text-transform: uppercase;
  letter-spacing: 0.12em;
}

.right-sidebar-content {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.right-sidebar-input {
  flex-shrink: 0;
  border-top: 1px solid var(--line);
}

.right-sidebar-input .answer-input-area.visible {
  display: block;
  padding: 12px 14px 6px;
}

.right-sidebar-input .answer-input-area label {
  display: none;
}

.right-sidebar-welcome {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #99a19c;
  font-size: 13px;
  text-align: center;
  padding: 20px 0;
}

/* Sticky input bar at bottom — floating composer */
.input-bar {
  position: sticky;
  bottom: 0;
  padding: 12px 24px 14px;
  background: linear-gradient(0deg, var(--bg) 72%, rgba(247,248,244,0));
  z-index: 15;
}

.input-bar > .input-row,
.input-bar > .controls-row {
  max-width: 800px;
  margin-left: auto;
  margin-right: auto;
}

.input-row {
  display: flex;
  gap: 10px;
  align-items: flex-end;
}

.input-row textarea {
  flex: 1;
}

.input-row > button {
  align-self: stretch;
  min-width: 64px;
  padding: 10px 16px;
  border-radius: 12px;
  background: var(--green);
  color: white;
  font-weight: 650;
}

.input-row > button:hover {
  background: var(--green-2);
}

.input-row select {
  align-self: center;
}

.controls-row {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  align-items: center;
  margin-top: 10px;
  font-size: 13px;
}

.controls-row label {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0;
  font-weight: 520;
  font-size: 13px;
  color: var(--muted);
}

/* Section / answer boxes */
.section {
  margin-top: 16px;
}

.section h2 {
  font-size: 16px;
  margin: 0 0 8px;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 10px;
  border-radius: 99px;
  background: var(--green-pale);
  color: var(--green-2);
  text-transform: uppercase;
  letter-spacing: .08em;
  font-size: 11px;
  font-weight: 700;
}

.pill span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #61a16f;
}

details {
  margin-top: 10px;
}

details>summary {
  cursor: pointer;
  font-weight: 650;
}

.err {
  color: #b00020;
  white-space: pre-wrap;
  margin-top: 10px;
}

.sources {
  margin-top: 10px;
  font-size: 13px;
  color: #333;
}

.sources ul {
  margin: 8px 0 0;
  padding-left: 18px;
}

/* Source strip from mockup */
.source-strip {
  min-height: 53px;
  margin-top: 22px;
  padding: 8px 10px 8px 13px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: rgba(255,255,255,.65);
  display: flex;
  align-items: center;
  gap: 10px;
}

.source-summary {
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  font-size: 12px;
}

.source-summary strong {
  color: var(--green);
}

.source-chips {
  display: flex;
  align-items: center;
  gap: 5px;
  margin-left: auto;
}

.source-chip {
  height: 32px;
  padding: 0 9px 0 5px;
  display: flex;
  align-items: center;
  gap: 5px;
  border: 0;
  border-radius: 7px;
  background: #edf1eb;
  color: #59665d;
  white-space: nowrap;
  font-size: 11px;
  cursor: pointer;
}

.source-chip:hover {
  background: #e0e9df;
}

.source-chip span {
  width: 18px;
  height: 18px;
  display: grid;
  place-items: center;
  border-radius: 5px;
  background: var(--surface);
  color: var(--green);
  font-weight: 700;
}

.source-toggle {
  display: flex;
  align-items: center;
  gap: 3px;
  border: 0;
  background: transparent;
  color: var(--green);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
}

.source-toggle:hover {
  text-decoration: underline;
}

/* Compact source for inline */
.compact-source {
  min-height: 42px;
  margin-top: 17px;
  padding: 6px 8px;
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: rgba(255,255,255,.62);
  font-size: 11px;
}

.compact-source > span {
  width: 23px;
  height: 23px;
  display: grid;
  place-items: center;
  border-radius: 6px;
  background: var(--green-pale);
  color: var(--green);
  font-weight: 700;
}

.compact-source small {
  color: var(--muted);
}

.compact-source button {
  margin-left: auto;
  border: 0;
  background: transparent;
  color: var(--green);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  padding: 0;
  min-height: auto;
}

.compact-source button:hover {
  text-decoration: underline;
}

code {
  background: #f1f1f1;
  padding: 1px 5px;
  border-radius: 6px;
}

/* Topbar */
.topbar {
  height: 56px;
  flex: 0 0 56px;
  padding: 0 34px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  border-bottom: 1px solid var(--line);
  background: rgba(250, 251, 248, .88);
  backdrop-filter: blur(14px);
  z-index: 20;
  gap: 13px;
}

/* Markdown answer styling */
.answer {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
  background: rgba(255,255,255,.65);
  min-height: 24px;
}

.answer p {
  margin: 0 0 10px;
  line-height: 1.72;
  color: #334039;
}

.answer p:last-child {
  margin-bottom: 0;
}

.answer ul,
.answer ol {
  margin: 4px 0 10px;
  padding-left: 22px;
}

.answer li {
  margin-bottom: 4px;
  line-height: 1.5;
}

.answer h3,
.answer h4 {
  margin: 14px 0 6px;
  font-size: 15px;
}

.answer pre {
  background: #f1f1f1;
  padding: 10px;
  border-radius: 8px;
  overflow-x: auto;
}

.answer code {
  font-size: 13px;
}

.answer blockquote {
  border-left: 3px solid #ddd;
  margin: 8px 0;
  padding: 4px 12px;
  color: #555;
}

.answer strong {
  color: var(--text);
  font-weight: 650;
}

/* Thinking indicator */
.thinking {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: #8c9790;
  font-size: 14px;
}

.thinking-dots span {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #9aa29c;
  animation: dot-pulse 1.4s ease-in-out infinite;
}

.thinking-dots span:nth-child(2) {
  animation-delay: 0.2s;
}

.thinking-dots span:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes dot-pulse {
  0%, 80%, 100% {
    opacity: 0.3;
    transform: scale(0.8);
  }
  40% {
    opacity: 1;
    transform: scale(1);
  }
}

/* Cursor blink while streaming */
.streaming-cursor::after {
  content: "▊";
  animation: blink 0.7s step-end infinite;
  color: #999;
  margin-left: 1px;
}

@keyframes blink {
  50% {
    opacity: 0;
  }
}

/* Mode toggle */
.mode-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 400;
  color: #666;
  cursor: pointer;
}

.mode-toggle input[type="checkbox"] {
  margin: 0;
}

/* Chat conversation view */
.chat-container {
  margin-top: 16px;
  display: none;
}

.chat-container.visible {
  display: block;
}

.exercise-actions {
  display: none;
  align-items: center;
  gap: 10px;
  margin-top: 16px;
  padding-bottom: 8px;
}

.exercise-action-btn {
  height: 38px;
  padding: 0 16px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--surface);
  color: var(--muted);
  font-size: 13px;
  font-weight: 520;
  cursor: pointer;
  transition: .15s;
}

.exercise-action-btn:hover {
  background: #f1f4ef;
  color: var(--text);
  border-color: #c4cec4;
}

.exercise-action-btn:disabled {
  opacity: .55;
  cursor: not-allowed;
}

.chat-scroll {
  max-height: none;
  overflow-y: visible;
  border: none;
  border-radius: 0;
  background: transparent;
  padding: 0;
}

.chat-scroll::-webkit-scrollbar {
  width: 6px;
}

.chat-scroll::-webkit-scrollbar-track {
  background: transparent;
}

.chat-scroll::-webkit-scrollbar-thumb {
  background: #ccc;
  border-radius: 3px;
}

.chat-bubble {
  margin-bottom: 12px;
  display: flex;
  flex-direction: column;
}

.single-question-bubble {
  margin-bottom: 16px;
}

.chat-bubble.user {
  align-items: flex-end;
}

.chat-bubble.assistant {
  align-items: flex-start;
}

.chat-bubble.assistant .assistant-row {
  display: grid;
  grid-template-columns: 36px minmax(0, 1fr);
  gap: 14px;
  align-items: start;
  width: 100%;
}

.assistant-body {
  min-width: 0;
}

.assistant-avatar {
  width: 36px;
  height: 36px;
  margin-top: 1px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  background: var(--green-pale);
  color: var(--green);
  font-size: 13px;
  font-weight: 700;
}

.chat-bubble-label {
  font-size: 11px;
  font-weight: 700;
  color: #8a958d;
  margin-bottom: 3px;
  padding: 0 6px;
  text-transform: uppercase;
  letter-spacing: .06em;
}

.chat-bubble-content {
  max-width: 610px;
  padding: 15px 19px;
  border-radius: 18px;
  font-size: 16px;
  line-height: 1.72;
}

.chat-bubble.user .chat-bubble-content {
  background: var(--green);
  color: #fff;
  border-radius: 18px 18px 4px 18px;
}

.message-meta {
  margin-top: 5px;
  color: #909a93;
  font-size: 11px;
}

.chat-bubble.assistant .chat-bubble-content {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 4px 18px 18px 18px;
  color: var(--text);
}

.chat-bubble-content p {
  margin: 0 0 8px;
}

.chat-bubble-content p:last-child {
  margin-bottom: 0;
}

.chat-bubble-content ul,
.chat-bubble-content ol {
  margin: 4px 0 8px;
  padding-left: 20px;
}

.chat-bubble-content li {
  margin-bottom: 3px;
}

.chat-bubble-meta {
  display: flex;
  gap: 6px;
  margin-top: 4px;
  padding: 0 6px;
}

.chat-bubble-meta .pill {
  margin-left: 0;
  font-size: 11px;
}

.chat-sources {
  font-size: 12px;
  color: #888;
  padding: 0 6px;
  margin-top: 2px;
}

.chat-clear {
  height: 32px;
  padding: 0 12px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: .2s;
}

.chat-clear:hover {
  background: var(--green-pale);
  color: var(--green);
  border-color: #abc0ae;
}

.chat-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.chat-header h2 {
  font-size: 16px;
  margin: 0;
}

.chat-turn-count {
  font-size: 12px;
  color: #999;
}

/* Single-question view */
#singleView {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* Cite superscript */
.cite {
  width: 17px;
  height: 17px;
  margin-left: 3px;
  display: inline-grid;
  place-items: center;
  border-radius: 5px;
  background: #dce9db;
  color: var(--green);
  font-size: 9px;
  font-style: normal;
  font-weight: 700;
  cursor: pointer;
  vertical-align: super;
}

/* Exercise section */
.exercise-btn {
  display: none;
}

.exercise-section {
  margin-top: 14px;
  display: none;
}

.exercise-section.visible {
  display: block;
}

.box-title {
  font-size: 16px;
  font-weight: 650;
  margin: 0 0 8px;
  line-height: 1.3;
}

details > summary.box-title {
  cursor: pointer;
  margin-bottom: 0;
}

.exercise-box {
  border: 1px solid var(--task-line);
  border-bottom: none;
  border-radius: 17px 17px 0 0;
  padding: 20px 24px 0;
  background: var(--task-bg);
  box-shadow: 0 12px 35px rgba(61, 58, 37, .06);
  overflow: hidden;
  margin-top: 12px;
}

.exercise-box p {
  margin: 0 0 10px;
  line-height: 1.65;
  color: #41483e;
}

.exercise-box p:last-child {
  margin-bottom: 0;
}

.exercise-box ul,
.exercise-box ol {
  margin: 4px 0 10px;
  padding-left: 22px;
}

.exercise-box li {
  margin-bottom: 4px;
  line-height: 1.5;
}

.exercise-box strong {
  font-weight: 650;
}

/* Truncated exercise wrapper */
.exercise-truncated {
  position: relative;
  overflow: hidden;
  max-height: 70px;
  transition: max-height 0.35s ease;
}

.exercise-truncated.expanded {
  max-height: none;
}

.exercise-gradient-mask {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 60px;
  background: linear-gradient(to bottom, transparent, var(--bg));
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.exercise-truncated.expanded .exercise-gradient-mask {
  opacity: 0;
}

.exercise-toggle-box {
  display: none;
  align-items: center;
  justify-content: flex-start;
  min-height: 38px;
  padding: 0 24px;
  border: 1px solid var(--task-line);
  border-top: none;
  border-radius: 0 0 17px 17px;
  background: var(--task-bg);
  margin-top: 0;
}

.exercise-truncated.overflowing:not(.expanded) + .exercise-toggle-box,
.exercise-truncated.expanded + .exercise-toggle-box {
  display: flex;
}

.exercise-expand-btn {
  display: inline-flex;
  height: 28px;
  padding: 0;
  border: none;
  border-radius: 0;
  background: none;
  color: var(--green);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  align-items: center;
  gap: 4px;
  position: static;
}

.exercise-expand-btn:hover {
  color: var(--green-2);
}

/* Right sidebar chat scroll area */
.right-chat-scroll {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
  padding: 10px 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* Chat bubbles in right sidebar (reuse center chat styles) */
.right-chat-scroll .chat-bubble {
  margin-bottom: 6px;
}

.right-chat-scroll .chat-bubble.user {
  align-self: flex-end;
}

.right-chat-scroll .chat-bubble.assistant {
  align-self: flex-start;
}

/* Answer reveal (toggleable, outside chat flow) */
.answer-reveal {
  flex-shrink: 0;
  margin: 8px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255,255,255,.65);
  overflow: hidden;
}

.answer-reveal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
  background: var(--green-pale);
}

.answer-reveal-header span {
  font-size: 12px;
  font-weight: 700;
  color: var(--green);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.answer-reveal-close {
  height: 24px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
}

.answer-reveal-body {
  padding: 12px 14px;
  font-size: 14px;
  line-height: 1.65;
  color: #41483e;
}

.answer-reveal-body p {
  margin: 0 0 8px;
}

.answer-reveal-body p:last-child {
  margin-bottom: 0;
}

.exercise-truncated.expanded .exercise-gradient-mask {
  opacity: 0;
}

.answer-input-area {
  margin-top: 12px;
  display: none;
}

.answer-input-area.visible {
  display: block;
}

.answer-input-area label {
  font-size: 14px;
  margin: 0 0 6px;
}

.answer-input {
  min-height: 70px;
}

.submit-answer-btn,
.show-answer-btn,
.new-exercise-btn,
.hint-btn,
.generate-task-button {
  height: 40px;
  padding: 0 15px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid #aec0af;
  border-radius: 9px;
  background: var(--surface);
  color: var(--green);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 3px 10px rgba(23,74,55,.04);
  transition: .2s;
}

.submit-answer-btn:hover,
.show-answer-btn:hover,
.new-exercise-btn:hover,
.hint-btn:hover,
.generate-task-button:hover {
  background: var(--green);
  color: white;
  border-color: var(--green);
  transform: translateY(-1px);
}

.submit-answer-btn:disabled,
.show-answer-btn:disabled,
.new-exercise-btn:disabled,
.hint-btn:disabled,
.generate-task-button:disabled,
.generate-task-button.loading {
  opacity: .55;
  cursor: not-allowed;
  transform: none;
}

.generated-answer-box {
  margin-top: 12px;
  display: none;
}

.generated-answer-box.visible {
  display: block;
}

.assessment-box,
.hint-box {
  margin-top: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px;
  background: rgba(255,255,255,.65);
  display: none;
}

.assessment-box.visible,
.hint-box.visible {
  display: block;
}

/* Right sidebar sticky input overrides */
.right-sidebar-input .answer-input-area .composer textarea {
  min-height: 48px;
  max-height: 160px;
  padding: 13px 52px 13px 14px;
  font-size: 15px;
  line-height: 1.45;
  box-shadow: 0 10px 34px rgba(42, 58, 48, .1);
  background: var(--surface);
  border-radius: 15px;
}

.right-sidebar-actions {
  justify-content: flex-end;
  margin-top: 8px;
  gap: 16px;
  flex-wrap: wrap;
  align-items: center;
}

.right-sidebar-actions .submit-answer-btn,
.right-sidebar-actions .show-answer-btn,
.right-sidebar-actions .hint-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
  height: auto;
  padding: 7px 14px;
  border: 1px solid #aec0af;
  border-radius: 9px;
  background: var(--surface);
  color: var(--green-2);
  font-size: 13px;
  font-weight: 600;
  box-shadow: none;
  cursor: pointer;
}

/* Scrollable button strip inside right sidebar */
.right-sidebar-scroll {
  display: flex;
  flex-wrap: nowrap;
  gap: 16px;
  align-items: center;
  overflow-x: auto;
  width: 100%;
  scrollbar-width: thin;
  -webkit-overflow-scrolling: touch;
}
.right-sidebar-scroll::-webkit-scrollbar {
  height: 8px;
}
.right-sidebar-scroll::-webkit-scrollbar-track {
  background: #eef2e9;
  border-radius: 4px;
}
.right-sidebar-scroll::-webkit-scrollbar-thumb {
  background: #aec0af;
  border-radius: 4px;
}
.right-sidebar-scroll .submit-answer-btn,
.right-sidebar-scroll .show-answer-btn,
.right-sidebar-scroll .hint-btn {
  white-space: nowrap;
  flex-shrink: 0;
}

.right-sidebar-actions .submit-answer-btn:disabled,
.right-sidebar-actions .show-answer-btn:disabled,
.right-sidebar-actions .hint-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  background: var(--surface);
  border-color: var(--line);
  color: #999;
}

.right-sidebar-actions .submit-answer-btn:hover:not(:disabled),
.right-sidebar-actions .show-answer-btn:hover:not(:disabled),
.right-sidebar-actions .hint-btn:hover:not(:disabled) {
  background: var(--green-pale);
  border-color: #aec0af;
  transform: none;
  color: var(--green);
}

.assessment-box p {
  margin: 0 0 10px;
  line-height: 1.6;
}

.assessment-box p:last-child {
  margin-bottom: 0;
}

.assessment-box strong {
  font-weight: 650;
}

/* Answer actions bar */
.answer-actions {
  margin-top: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.feedback-actions {
  display: flex;
  gap: 2px;
}

.feedback-actions button {
  width: 29px;
  height: 29px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: #8c9790;
  cursor: pointer;
  padding: 0;
  min-height: auto;
}

.feedback-actions button:hover {
  background: var(--green-pale);
  color: var(--green);
}

/* RAG indicator */
.rag-indicator {
  display: flex;
  align-items: center;
  gap: 5px;
  color: #77827a;
  font-size: 11px;
}

.rag-indicator span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #5e9e70;
}

/* Debug box */
.debug-box {
  margin-top: 16px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--bg);
}

.debug-box summary {
  cursor: pointer;
  padding: 10px 14px;
  font-size: 13px;
  color: #555;
}

.debug-log {
  margin: 0;
  padding: 0 14px 14px;
  max-height: 220px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 12px;
  line-height: 1.5;
  color: #333;
}

/* Constrain assistant bubble content so wide math can't stretch the page */
.chat-bubble.assistant .chat-bubble-content,
.answer,
.exercise-box,
.generated-answer-box,
.assessment-box,
.hint-box {
  min-width: 0;
  max-width: 100%;
  word-break: break-word;
  overflow-wrap: break-word;
}

/* Display math: constrain width, scroll locally, match text size */
.exercise-box mjx-container[display="true"],
.assessment-box mjx-container[display="true"],
.hint-box mjx-container[display="true"],
.chat-bubble-content mjx-container[display="true"],
.generated-answer-box mjx-container[display="true"],
.right-sidebar-content mjx-container[display="true"],
.answer mjx-container[display="true"] {
  width: 100% !important;
  max-width: 100% !important;
  min-width: 0 !important;
  display: block;
  font-size: 1em !important;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: thin;
  scrollbar-color: #c5c5c5 transparent;
}

/* Status badge */
#status {
  font-size: 13px;
  color: #8c9790;
}

/* Toast */
.toast {
  position: fixed;
  z-index: 100;
  left: 50%;
  bottom: 25px;
  transform: translate(-50%, 15px);
  padding: 10px 15px;
  border-radius: 9px;
  background: #20342a;
  color: white;
  font-size: 13px;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: .25s;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* Suggestions below composer */
.suggestions {
  display: flex;
  gap: 7px;
  margin-bottom: 7px;
  padding-left: 4px;
}

.suggestions button {
  padding: 7px 11px;
  border: 1px solid var(--line);
  border-radius: 99px;
  background: rgba(255,255,255,.9);
  color: #657169;
  font-size: 11px;
  cursor: pointer;
  min-height: auto;
}

.suggestions button:hover {
  color: var(--green);
  border-color: #b7c6b7;
}

/* Disclaimer */
.disclaimer {
  margin-top: 7px;
  margin-bottom: 0;
  text-align: center;
  color: #a0a7a2;
  font-size: 10px;
}

/* Exercise bubble rendered inside chat stream */
.chat-bubble.assistant.exercise-bubble .chat-bubble-content {
  background: #FBFAF4;
  border: 1px solid #e5e1cd;
}

.exercise-bubble .exercise-full {
  color: #41483e;
  background: #F3F1E6;
  border-radius: 11px;
  padding: 14px 16px;
  font-size: 15px;
  line-height: 1.65;
  margin-bottom: 12px;
}

.exercise-bubble .exercise-full p {
  margin: 0 0 8px;
}

.exercise-bubble .exercise-full p:last-child {
  margin-bottom: 0;
}

.exercise-bubble .exercise-card-btn {
  height: 38px;
  padding: 0 16px;
  display: inline-flex;
  align-items: center;
  align-self: flex-start;
  gap: 8px;
  border: 1px solid #aec0af;
  border-radius: 9px;
  background: var(--surface);
  color: var(--green);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: .2s;
}

.exercise-bubble .exercise-card-btn:hover {
  background: var(--green);
  color: white;
  border-color: var(--green);
  transform: translateY(-1px);
}

/* Answer bubble inside exercise chat */
.answer-bubble-content {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 4px 18px 18px 18px;
  padding: 10px 16px 14px;
  font-size: 16px;
  line-height: 1.72;
  color: var(--text);
}

.answer-bubble-content .answer-bubble-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 6px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--line);
}

.answer-bubble-content .answer-bubble-header span {
  font-size: 12px;
  font-weight: 700;
  color: var(--green);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.answer-toggle-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
  height: auto;
  padding: 7px 14px;
  border: 1px solid #aec0af;
  border-radius: 9px;
  background: var(--surface);
  color: var(--green);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: 0.2s;
}

.answer-toggle-btn:hover {
  background: var(--green-pale);
  border-color: #aec0af;
  transform: none;
  color: var(--green);
}

.exercise-card-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.exercise-adjust-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  border-top: 1px solid #e5e1cd;
  border-bottom: 1px solid #e5e1cd;
  padding-top: 10px;
  padding-bottom: 10px;
}

.exercise-adjust-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  white-space: nowrap;
}

.exercise-adjust-row .segmented {
  height: 32px;
  padding: 2px;
  display: inline-flex;
  border-radius: 8px;
  background: #ebe9df;
}

.exercise-adjust-row .segmented button {
  padding: 0 10px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: #777a72;
  font-size: 11px;
  font-weight: 520;
  cursor: pointer;
  transition: .15s;
  min-height: auto;
}

.exercise-adjust-row .segmented button:hover {
  color: var(--text);
}

.exercise-adjust-row .segmented button.active {
  background: var(--surface);
  color: var(--green);
  font-weight: 700;
  box-shadow: 0 1px 4px rgba(45, 50, 41, .1);
}

/* === Mobile overlay sidebars === */
@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 200;
    width: min(320px, 85vw) !important;
    flex: none;
    transform: translateX(0);
    pointer-events: auto;
  }

  .sidebar.collapsed {
    width: min(320px, 85vw) !important;
    flex: none;
    transform: translateX(-100%);
    pointer-events: none;
  }

  .right-sidebar {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    z-index: 200;
    width: min(320px, 85vw) !important;
    min-width: auto !important;
    flex: none;
    transform: translateX(0);
    pointer-events: auto;
  }

  .right-sidebar.collapsed {
    width: min(320px, 85vw) !important;
    min-width: auto !important;
    flex: none;
    transform: translateX(100%);
    pointer-events: none;
  }

  .resize-grip {
    display: none;
  }

  .sidebar-toggle,
  .right-sidebar-toggle {
    z-index: 300;
  }
}
