/* Layout and structure */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  font-size: 100%;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 1.125rem;
  line-height: 1.6;
  color: #1a1a1a;
  background: #fff;
}

.app {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* Sidebar: toggle + stepper (does not scroll with content) */
.sidebar {
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  width: 14rem;
  background: #f8f8f8;
  border-right: 1px solid #e8e8e8;
  transition: width 0.2s ease;
  overflow: hidden;
}

.app.menu-closed .sidebar {
  width: 2.5rem;
}

.menu-toggle {
  flex-shrink: 0;
  width: 2.5rem;
  height: 2.5rem;
  margin: 0.5rem 0 0 0.25rem;
  padding: 0;
  border: none;
  border-radius: 0.35rem;
  background: #e8e8e8;
  color: #333;
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.menu-toggle:hover {
  background: #ddd;
  color: #000;
}

.menu-toggle:focus {
  outline: 2px solid #1565c0;
  outline-offset: 2px;
}

/* Closed: show chevron right to open; open: show chevron left to close */
.app.menu-closed .menu-toggle::before {
  content: "›";
}

.app:not(.menu-closed) .menu-toggle::before {
  content: "‹";
}

/* Theme toggle at top of lesson menu */
.theme-toggle-wrap {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem 0.75rem;
  margin: 0 0.25rem 0 0;
  border-bottom: 1px solid #e8e8e8;
}

.app.menu-closed .theme-toggle-wrap {
  display: none;
}

.theme-toggle-label {
  font-size: 0.8rem;
  color: #666;
  font-weight: 500;
}

.theme-toggle {
  padding: 0.35rem 0.65rem;
  font-size: 0.8rem;
  font-family: inherit;
  border: 1px solid #ccc;
  border-radius: 0.35rem;
  background: #fff;
  color: #333;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.theme-toggle:hover {
  background: #f0f0f0;
  border-color: #999;
}

.theme-toggle:focus {
  outline: 2px solid #1565c0;
  outline-offset: 2px;
}

/* Stepper (lesson list) */
.stepper {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 0.5rem 0 2rem 1rem;
}

.app.menu-closed .stepper {
  display: none;
}

.stepper-item {
  display: block;
  padding: 0.6rem 1rem;
  margin-bottom: 0.25rem;
  color: #333;
  text-decoration: none;
  border-radius: 0.35rem;
  transition: background 0.15s ease, color 0.15s ease;
}

.stepper-item:hover {
  background: #eee;
  color: #000;
}

.stepper-item--active {
  background: #1a1a1a;
  color: #fff;
  font-weight: 600;
}

.stepper-item--active:hover {
  background: #333;
  color: #fff;
}

.stepper-item--done {
  position: relative;
}

.stepper-item--done::after {
  content: "";
  position: absolute;
  right: 1rem;
  top: 50%;
  transform: translateY(-50%);
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
  background: #2e7d32;
}

.stepper-item--done.stepper-item--active::after {
  background: #a5d6a7;
}

/* Main content */
.content {
  flex: 1;
  overflow: auto;
  padding: 3rem 2rem 4rem;
}

.content-panel {
  max-width: 70ch;
  margin: 0 auto;
}

.content-panel[hidden] {
  display: none !important;
}

/* Typography */
.content-panel h1 {
  font-size: 2rem;
  font-weight: 700;
  line-height: 1.25;
  margin: 0 0 1.5rem;
  color: #000;
}

.content-panel h2 {
  font-size: 1.5rem;
  font-weight: 600;
  margin: 2.5rem 0 1rem;
  padding-bottom: 0.35rem;
  border-bottom: 1px solid #e0e0e0;
  color: #111;
}

.content-panel h3 {
  font-size: 1.2rem;
  font-weight: 600;
  margin: 1.75rem 0 0.6rem;
  color: #222;
}

.content-panel p {
  margin: 0 0 1.25rem;
}

.content-panel ul,
.content-panel ol {
  margin: 0 0 1.25rem;
  padding-left: 1.5rem;
}

.content-panel li {
  margin-bottom: 0.4rem;
}

.content-panel li > ul,
.content-panel li > ol {
  margin-top: 0.4rem;
  margin-bottom: 0.4rem;
}

.content-panel strong {
  font-weight: 600;
}

.content-panel em {
  font-style: italic;
}

.content-panel hr {
  border: none;
  border-top: 1px solid #e0e0e0;
  margin: 2rem 0;
}

/* Links */
.content-panel a {
  color: #1565c0;
  text-decoration: none;
}

.content-panel a:hover {
  text-decoration: underline;
}

/* Code */
.content-panel code {
  font-family: ui-monospace, "Cascadia Code", "Source Code Pro", Menlo, Consolas, monospace;
  font-size: 0.9em;
  padding: 0.15em 0.4em;
  background: #f0f0f0;
  border-radius: 0.25rem;
  border: 1px solid #e0e0e0;
}

.content-panel pre {
  margin: 1.5rem 0;
  padding: 1.25rem 1.5rem;
  overflow: auto;
  background: #1a1a1a;
  border-radius: 0.4rem;
  border: 1px solid #333;
}

.content-panel pre code {
  padding: 0;
  background: none;
  border: none;
  color: #e0e0e0;
  font-size: 0.9rem;
  line-height: 1.5;
}

/* Tables */
.content-panel table {
  width: 100%;
  border-collapse: collapse;
  margin: 1.5rem 0;
  font-size: 1rem;
}

.content-panel th,
.content-panel td {
  padding: 0.6rem 1rem;
  text-align: left;
  border: 1px solid #e0e0e0;
}

.content-panel th {
  background: #f5f5f5;
  font-weight: 600;
}

.content-panel tbody tr:hover {
  background: #fafafa;
}

.content-panel table a {
  color: #1565c0;
}

/* Blockquote */
.content-panel blockquote {
  margin: 1.5rem 0;
  padding: 0.75rem 0 0.75rem 1.25rem;
  border-left: 4px solid #ccc;
  color: #444;
  background: #f9f9f9;
  border-radius: 0 0.25rem 0.25rem 0;
}

/* Lesson complete button */
.lesson-complete-wrap {
  margin-top: 2.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid #e0e0e0;
}

.lesson-complete-btn {
  display: inline-block;
  padding: 0.5rem 1rem;
  font-size: 0.95rem;
  font-family: inherit;
  color: #1565c0;
  background: transparent;
  border: 1px solid #1565c0;
  border-radius: 0.35rem;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s ease, color 0.15s ease;
}

.lesson-complete-btn:hover {
  background: #1565c0;
  color: #fff;
}

/* Chat widget */
.chat-widget {
  position: fixed;
  right: 1.5rem;
  bottom: 1.5rem;
  z-index: 1000;
  font-size: 1rem;
}

.chat-widget__toggle {
  width: 3.5rem;
  height: 3.5rem;
  border-radius: 50%;
  border: 1px solid #e0e0e0;
  background: #fff;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
  cursor: pointer;
  font-weight: 600;
  color: #333;
}

.chat-widget__toggle:hover {
  background: #f5f5f5;
}

.chat-widget__panel {
  position: absolute;
  right: 0;
  bottom: 3.75rem;
  width: 22rem;
  height: 28rem;
  min-width: 18rem;
  min-height: 20rem;
  max-width: min(42rem, 95vw);
  max-height: min(85vh, 36rem);
  background: #fff;
  border: 1px solid #e0e0e0;
  border-radius: 0.5rem;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.12);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.chat-widget__resize-handle {
  position: absolute;
  top: 0;
  left: 0;
  width: 1.5rem;
  height: 1.5rem;
  cursor: nwse-resize;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #999;
  font-size: 0.65rem;
  user-select: none;
}

.chat-widget__resize-handle::before {
  content: '';
  position: absolute;
  top: 0.35rem;
  left: 0.35rem;
  width: 0.5rem;
  height: 0.5rem;
  border-left: 2px solid currentColor;
  border-top: 2px solid currentColor;
}

.chat-widget__panel[hidden] {
  display: none !important;
}

.chat-widget__header {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid #e8e8e8;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 600;
}

.chat-widget__close {
  background: none;
  border: none;
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  color: #666;
  padding: 0 0.25rem;
}

.chat-widget__close:hover {
  color: #000;
}

.chat-widget__messages {
  flex: 1;
  overflow: auto;
  padding: 1rem;
  min-height: 8rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.chat-widget__msg {
  max-width: 95%;
  padding: 0.6rem 0.9rem;
  border-radius: 0.4rem;
  font-size: 0.95rem;
  line-height: 1.45;
}

.chat-widget__msg--user {
  align-self: flex-end;
  background: #1a1a1a;
  color: #fff;
}

.chat-widget__msg--assistant {
  align-self: flex-start;
  background: #f0f0f0;
  border: 1px solid #e0e0e0;
}

.chat-widget__msg--assistant p { margin: 0 0 0.5rem; }
.chat-widget__msg--assistant p:last-child { margin-bottom: 0; }
.chat-widget__msg--assistant code {
  font-size: 0.85em;
  background: rgba(0,0,0,0.06);
  padding: 0.1em 0.35em;
  border-radius: 0.2rem;
}
.chat-widget__msg--assistant pre { margin: 0.5rem 0; overflow: auto; }
.chat-widget__msg--assistant pre code { padding: 0.5rem; display: block; }
.chat-widget__msg--assistant a { color: #1565c0; }

.chat-widget__footer {
  padding: 0.75rem 1rem;
  border-top: 1px solid #e8e8e8;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: flex-end;
}

.chat-widget__input {
  flex: 1;
  min-width: 10rem;
  padding: 0.5rem 0.6rem;
  border: 1px solid #e0e0e0;
  border-radius: 0.35rem;
  font-family: inherit;
  font-size: 0.95rem;
  resize: none;
}

.chat-widget__send {
  padding: 0.5rem 1rem;
  background: #1a1a1a;
  color: #fff;
  border: none;
  border-radius: 0.35rem;
  cursor: pointer;
  font-weight: 600;
}

.chat-widget__send:hover {
  background: #333;
}

.chat-widget__send:disabled {
  background: #999;
  cursor: not-allowed;
}

.chat-widget__settings {
  padding: 0.75rem 1rem;
  border-top: 1px solid #e8e8e8;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.chat-widget__settings[hidden] {
  display: none !important;
}

.chat-widget__settings label { font-size: 0.9rem; color: #555; }
.chat-widget__settings input { padding: 0.4rem; font-family: inherit; }
.chat-widget__settings-btn { background: none; border: none; cursor: pointer; font-size: 1.1rem; padding: 0.25rem; }

/* ========== Dark theme ========== */
body.dark {
  background: #1a1a1a;
  color: #e0e0e0;
}

body.dark .sidebar {
  background: #252525;
  border-right-color: #333;
}

body.dark .menu-toggle {
  background: #333;
  color: #ccc;
}

body.dark .menu-toggle:hover {
  background: #404040;
  color: #fff;
}

body.dark .theme-toggle-wrap {
  border-bottom-color: #333;
}

body.dark .theme-toggle-label {
  color: #999;
}

body.dark .theme-toggle {
  background: #333;
  color: #ccc;
  border-color: #555;
}

body.dark .theme-toggle:hover {
  background: #404040;
  color: #fff;
  border-color: #666;
}

body.dark .stepper-item {
  color: #ccc;
}

body.dark .stepper-item:hover {
  background: #333;
  color: #fff;
}

body.dark .stepper-item--active {
  background: #e0e0e0;
  color: #1a1a1a;
}

body.dark .stepper-item--active:hover {
  background: #d0d0d0;
  color: #1a1a1a;
}

body.dark .stepper-item--done::after {
  background: #4caf50;
}

body.dark .stepper-item--done.stepper-item--active::after {
  background: #2e7d32;
}

body.dark .content {
  background: #1a1a1a;
}

body.dark .content-panel h1 {
  color: #f5f5f5;
}

body.dark .content-panel h2 {
  color: #eee;
  border-bottom-color: #404040;
}

body.dark .content-panel h3 {
  color: #e0e0e0;
}

body.dark .content-panel hr {
  border-top-color: #404040;
}

body.dark .content-panel a {
  color: #64b5f6;
}

body.dark .content-panel a:hover {
  color: #90caf9;
}

body.dark .content-panel code {
  background: #333;
  border-color: #444;
  color: #e0e0e0;
}

body.dark .content-panel pre {
  background: #0d0d0d;
  border-color: #333;
}

body.dark .content-panel pre code {
  color: #e0e0e0;
}

body.dark .content-panel th,
body.dark .content-panel td {
  border-color: #404040;
}

body.dark .content-panel th {
  background: #252525;
  color: #e0e0e0;
}

body.dark .content-panel tbody tr:hover {
  background: #252525;
}

body.dark .content-panel table a {
  color: #64b5f6;
}

body.dark .content-panel blockquote {
  border-left-color: #555;
  color: #b0b0b0;
  background: #252525;
}

body.dark .lesson-complete-wrap {
  border-top-color: #404040;
}

body.dark .lesson-complete-btn {
  color: #64b5f6;
  border-color: #64b5f6;
}

body.dark .lesson-complete-btn:hover {
  background: #64b5f6;
  color: #1a1a1a;
}

/* Chat widget dark */
body.dark .chat-widget__toggle {
  background: #252525;
  border-color: #444;
  color: #e0e0e0;
}

body.dark .chat-widget__toggle:hover {
  background: #333;
}

body.dark .chat-widget__panel {
  background: #252525;
  border-color: #444;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
}

body.dark .chat-widget__resize-handle {
  color: #666;
}

body.dark .chat-widget__header {
  border-bottom-color: #404040;
  color: #e0e0e0;
}

body.dark .chat-widget__close {
  color: #999;
}

body.dark .chat-widget__close:hover {
  color: #fff;
}

body.dark .chat-widget__msg--assistant {
  background: #333;
  border-color: #444;
  color: #e0e0e0;
}

body.dark .chat-widget__msg--assistant code {
  background: rgba(255, 255, 255, 0.1);
}

body.dark .chat-widget__msg--assistant a {
  color: #64b5f6;
}

body.dark .chat-widget__footer {
  border-top-color: #404040;
}

body.dark .chat-widget__input {
  background: #1a1a1a;
  border-color: #444;
  color: #e0e0e0;
}

body.dark .chat-widget__input::placeholder {
  color: #888;
}

body.dark .chat-widget__send {
  background: #404040;
  color: #fff;
}

body.dark .chat-widget__send:hover {
  background: #505050;
}

body.dark .chat-widget__send:disabled {
  background: #333;
  color: #666;
}

body.dark .chat-widget__settings {
  border-top-color: #404040;
}

body.dark .chat-widget__settings label {
  color: #999;
}

body.dark .chat-widget__settings input {
  background: #1a1a1a;
  border: 1px solid #444;
  color: #e0e0e0;
}
