:root {
  --bg-main: #faf9f5;
  --bg-topbar: #fbfaf6;
  --bg-panel: rgba(255, 255, 255, 0.82);
  --bg-card: #fffdf9;
  --bg-input: #ffffff;
  --bg-hover: #f3ede5;
  --bg-soft-accent: #f6ebe5;
  --bg-user-bubble: #f3e3dc;
  --bg-code: #27231f;
  --text-main: #1f1b18;
  --text-secondary: #6b625a;
  --text-tertiary: #8d847b;
  --border-soft: rgba(122, 103, 89, 0.14);
  --border-strong: rgba(122, 103, 89, 0.22);
  --accent: #c97c60;
  --accent-strong: #b8694c;
  --accent-soft: rgba(201, 124, 96, 0.14);
  --shadow-panel: 0 18px 48px rgba(75, 54, 40, 0.08);
  --shadow-card: 0 10px 30px rgba(82, 60, 46, 0.06);
  --shadow-input: 0 10px 28px rgba(82, 60, 46, 0.08);
  --send-button-size: 34px;
  --send-button-icon-size: 20px;
  --composer-actions-right: 22px;
  --composer-textarea-right-padding: calc(var(--send-button-size) + var(--composer-actions-right) - 2px);
  --font-ui: "Avenir Next", "PingFang SC", "Hiragino Sans GB", "Noto Sans CJK SC", "Microsoft YaHei", sans-serif;
  --font-reading: "Charter", "Iowan Old Style", "Source Han Serif SC", "Noto Serif CJK SC", "Songti SC", serif;
}

* {
  box-sizing: border-box;
}

html {
  height: 100%;
}

body {
  margin: 0;
  min-height: 100%;
  font-family: var(--font-ui);
  color: var(--text-main);
  background:
    radial-gradient(circle at top, rgba(201, 124, 96, 0.07), transparent 28%),
    linear-gradient(180deg, #fcfbf7 0%, var(--bg-main) 22%, #f7f3ed 100%);
}

body,
button,
textarea {
  font: inherit;
}

button,
textarea {
  -webkit-tap-highlight-color: transparent;
}

.app-shell {
  display: grid;
  grid-template-columns: 308px minmax(0, 1fr);
  height: 100vh;
  overflow: hidden;
}

.sidebar {
  display: flex;
  flex-direction: column;
  height: 100vh;
  padding: 18px 16px 20px;
  background: linear-gradient(180deg, rgba(255, 253, 249, 0.96) 0%, rgba(248, 244, 238, 0.92) 100%);
  border-right: 1px solid var(--border-soft);
  box-shadow: inset -1px 0 0 rgba(255, 255, 255, 0.45);
}

.sidebar-body {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding-bottom: 20px;
}

.sidebar-overlay {
  display: none;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 16px;
}

.brand-lockup {
  min-width: 0;
  display: inline-flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  width: 44px;
  height: 44px;
  flex: 0 0 44px;
  display: block;
  border-radius: 13px;
  box-shadow: 0 8px 18px rgba(184, 105, 76, 0.16);
}

.brand-copy {
  min-width: 0;
}

.brand-name {
  color: var(--text-main);
  font-size: 18px;
  font-weight: 700;
  line-height: 1.15;
}

.brand-tagline {
  margin-top: 4px;
  overflow: hidden;
  color: var(--text-tertiary);
  font-size: 12px;
  line-height: 1.2;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.inline-brand-mark {
  width: 22px;
  height: 22px;
  flex: 0 0 22px;
  display: inline-block;
  border-radius: 7px;
  vertical-align: -0.28em;
}

.sidebar-close,
.nav-button,
.font-control-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border-soft);
  color: var(--text-secondary);
  background: rgba(255, 252, 247, 0.92);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.8);
}

.sidebar-close {
  display: none;
  width: 36px;
  height: 36px;
  padding: 0;
  border-radius: 12px;
}

.course-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.empty-courses {
  color: var(--text-secondary);
  font-size: 14px;
}

.empty-courses-brand {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 12px;
  background: rgba(255, 252, 247, 0.72);
  border: 1px solid rgba(134, 111, 93, 0.1);
  border-radius: 16px;
  line-height: 1.45;
}

.course-group {
  overflow: hidden;
  background: rgba(255, 252, 247, 0.86);
  border: 1px solid var(--border-soft);
  border-radius: 18px;
  box-shadow: var(--shadow-card);
}

.course-button,
.lesson-button {
  width: 100%;
  text-align: left;
  color: var(--text-main);
  background: transparent;
  border: none;
  border-radius: 0;
  cursor: pointer;
  transition: background-color 140ms ease, color 140ms ease;
}

.course-button {
  padding: 14px 16px;
  font-weight: 700;
}

.course-button:hover,
.lesson-button:hover,
.lesson-button.active {
  background: var(--bg-soft-accent);
}

.lesson-list {
  display: none;
  border-top: 1px solid var(--border-soft);
}

.course-group.expanded .lesson-list {
  display: block;
}

.lesson-button {
  padding: 10px 16px 10px 26px;
  font-size: 14px;
  color: var(--text-secondary);
}

.lesson-button.active {
  color: var(--accent-strong);
}

.lesson-view {
  position: relative;
  min-width: 0;
  min-height: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: transparent;
}

.topbar {
  position: relative;
  z-index: 2;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 14px;
  padding: 14px 22px;
  background: rgba(251, 250, 246, 0.9);
  border-bottom: 1px solid var(--border-soft);
  backdrop-filter: blur(14px);
}

.nav-button {
  display: none;
  width: 42px;
  height: 42px;
  padding: 0;
  border-radius: 14px;
}

.lesson-title-group {
  min-width: 0;
}

.lesson-title-group h1 {
  margin: 0;
  overflow: hidden;
  font-size: 19px;
  font-weight: 700;
  line-height: 1.25;
  letter-spacing: 0.01em;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.font-controls {
  display: flex;
  gap: 8px;
}

.auth-status {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  width: 100%;
  padding: 12px 12px 12px 14px;
  border: 1px solid var(--border-soft);
  border-radius: 18px;
  background: rgba(255, 252, 247, 0.92);
  box-shadow: var(--shadow-card);
}

.auth-status.hidden {
  display: none;
}

.account-dock {
  padding-top: 12px;
  border-top: 1px solid rgba(122, 103, 89, 0.1);
}

.auth-status-copy {
  min-width: 0;
}

.auth-user-label {
  overflow: hidden;
  color: var(--text-main);
  font-size: 14px;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.auth-meta-label {
  margin-top: 4px;
  overflow: hidden;
  color: var(--text-secondary);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.auth-action-button {
  flex: 0 0 auto;
  min-width: 64px;
  padding: 8px 12px;
  border: 1px solid transparent;
  border-radius: 999px;
  color: #fffaf6;
  background: linear-gradient(180deg, var(--accent) 0%, var(--accent-strong) 100%);
  box-shadow: 0 8px 18px rgba(184, 105, 76, 0.18);
  font-size: 13px;
  font-weight: 700;
  transition: transform 140ms ease, box-shadow 140ms ease, opacity 140ms ease;
}

.auth-action-button:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 10px 22px rgba(184, 105, 76, 0.22);
}

.authing-guard-container {
  position: relative;
  z-index: 20;
}

.auth-gate-card {
  width: min(100%, 560px);
  margin: 72px auto 0;
  padding: 34px 30px;
  text-align: center;
  background: rgba(255, 252, 247, 0.92);
  border: 1px solid var(--border-soft);
  border-radius: 28px;
  box-shadow: var(--shadow-panel);
}

.auth-gate-logo {
  width: 74px;
  height: 74px;
  display: block;
  margin: 0 auto 20px;
  border-radius: 22px;
  box-shadow: 0 14px 32px rgba(184, 105, 76, 0.18);
}

.auth-gate-card h2 {
  margin: 0 0 12px;
  font-size: 30px;
  line-height: 1.2;
}

.auth-gate-card p {
  margin: 0;
  color: var(--text-secondary);
}

.auth-gate-login-button {
  margin-top: 22px;
  padding: 12px 18px;
  border-radius: 999px;
  color: #fffaf6;
  background: linear-gradient(180deg, var(--accent) 0%, var(--accent-strong) 100%);
  box-shadow: 0 12px 24px rgba(184, 105, 76, 0.2);
  font-weight: 700;
}

.auth-gate-login-button:hover:not(:disabled) {
  transform: translateY(-1px);
}

.font-control-button {
  width: 38px;
  height: 38px;
  padding: 0;
  border-radius: 14px;
  font-size: 19px;
  font-weight: 700;
  line-height: 1;
}

.sidebar-close:hover,
.nav-button:hover,
.font-control-button:hover:not(:disabled) {
  color: var(--accent-strong);
  background: #fffaf4;
  border-color: var(--border-strong);
}

button {
  border: none;
  cursor: pointer;
}

button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.lesson-box {
  --lesson-font-size: 16px;
  flex: 1;
  min-height: 0;
  overflow: auto;
  width: 100%;
  margin: 0;
  padding: 28px 28px 42px;
  background: transparent;
  border: none;
  border-radius: 0;
  box-shadow: none;
  font-family: var(--font-reading);
  font-size: var(--lesson-font-size);
  line-height: 1.82;
  box-sizing: border-box;
}

#lessonContent,
.lesson-flow-box {
  width: min(100%, 1080px);
  margin: 0 auto;
}

#lessonContent {
  padding: 0 10px;
}

.scroll-bottom-button {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(132px + env(safe-area-inset-bottom));
  z-index: 8;
  width: 34px;
  height: 34px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #2e2621;
  background: rgba(255, 253, 249, 0.94);
  border: 1px solid rgba(134, 111, 93, 0.14);
  border-radius: 999px;
  box-shadow:
    0 10px 24px rgba(82, 60, 46, 0.12),
    inset 0 1px 0 rgba(255, 255, 255, 0.82);
  backdrop-filter: blur(12px);
  transition:
    transform 160ms ease,
    opacity 160ms ease,
    box-shadow 160ms ease,
    background-color 160ms ease;
}

.scroll-bottom-button:hover {
  transform: translateX(-50%) translateY(-2px);
  background: #fffdf9;
  box-shadow:
    0 12px 28px rgba(82, 60, 46, 0.16),
    inset 0 1px 0 rgba(255, 255, 255, 0.86);
}

.scroll-bottom-button span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  line-height: 1;
  transform: translateY(-1px);
}

.viewer-nav {
  position: fixed;
  right: 12px;
  bottom: calc(132px + env(safe-area-inset-bottom));
  z-index: 8;
  display: block;
}

.viewer-nav-button {
  min-width: 108px;
  min-height: 34px;
  padding: 0 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #2e2621;
  background: rgba(255, 253, 249, 0.94);
  border: 1px solid rgba(134, 111, 93, 0.14);
  border-radius: 28px;
  box-shadow:
    0 10px 24px rgba(82, 60, 46, 0.12),
    inset 0 1px 0 rgba(255, 255, 255, 0.82);
  backdrop-filter: blur(12px);
  transition:
    transform 160ms ease,
    box-shadow 160ms ease,
    background-color 160ms ease;
}

.viewer-nav-button:hover {
  transform: translateY(-2px);
  background: #fffdf9;
  box-shadow:
    0 12px 28px rgba(82, 60, 46, 0.16),
    inset 0 1px 0 rgba(255, 255, 255, 0.86);
}

.viewer-nav-button-label {
  font-size: 15px;
  font-weight: 600;
  line-height: 1;
}

.viewer-nav-menu {
  position: absolute;
  right: 0;
  bottom: calc(100% + 10px);
  width: min(280px, calc(100vw - 34px));
  max-height: min(46vh, 360px);
  padding: 8px;
  overflow: auto;
  background: rgba(255, 252, 248, 0.98);
  border: 1px solid rgba(134, 111, 93, 0.14);
  border-radius: 28px;
  box-shadow: 0 16px 40px rgba(74, 53, 40, 0.14);
  backdrop-filter: blur(14px);
}

.viewer-nav-menu-item {
  width: 100%;
  padding: 11px 12px;
  display: block;
  color: var(--text-main);
  text-align: left;
  background: transparent;
  border-radius: 14px;
  font-size: 14px;
  line-height: 1.45;
}

.viewer-nav-menu-item-h2 {
  font-weight: 600;
}

.viewer-nav-menu-item-h3 {
  padding-left: 24px;
  color: var(--text-secondary);
  font-size: 13px;
}

.viewer-nav-menu-item:hover {
  background: var(--bg-hover);
}

.feedback-button {
  position: fixed;
  left: 22px;
  bottom: calc(132px + env(safe-area-inset-bottom));
  z-index: 8;
  min-width: 74px;
  min-height: 34px;
  padding: 0 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #2e2621;
  background: rgba(255, 253, 249, 0.94);
  border: 1px solid rgba(134, 111, 93, 0.14);
  border-radius: 28px;
  box-shadow:
    0 10px 24px rgba(82, 60, 46, 0.12),
    inset 0 1px 0 rgba(255, 255, 255, 0.82);
  backdrop-filter: blur(12px);
  font-size: 15px;
  font-weight: 600;
  transition:
    transform 160ms ease,
    box-shadow 160ms ease,
    background-color 160ms ease;
}

.feedback-button:hover {
  transform: translateY(-2px);
  background: #fffdf9;
  box-shadow:
    0 12px 28px rgba(82, 60, 46, 0.16),
    inset 0 1px 0 rgba(255, 255, 255, 0.86);
}

.feedback-dialog {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 18px;
}

.feedback-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(39, 31, 25, 0.34);
  backdrop-filter: blur(3px);
}

.feedback-panel {
  position: relative;
  width: min(100%, 480px);
  padding: 22px;
  background: rgba(255, 252, 247, 0.98);
  border: 1px solid var(--border-soft);
  border-radius: 26px;
  box-shadow: 0 22px 60px rgba(49, 35, 25, 0.18);
}

.feedback-panel-header h2 {
  margin: 0;
  color: var(--text-main);
  font-size: 22px;
  line-height: 1.25;
}

.feedback-panel-header p {
  margin: 8px 0 16px;
  color: var(--text-secondary);
  font-size: 14px;
  line-height: 1.55;
}

.feedback-input {
  width: 100%;
  min-height: 132px;
  padding: 13px 14px;
  resize: vertical;
  color: var(--text-main);
  background: #fffdf9;
  border: 1px solid rgba(134, 111, 93, 0.16);
  border-radius: 18px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.7);
  font-size: 15px;
  line-height: 1.55;
}

.feedback-input:focus {
  outline: 2px solid rgba(201, 124, 96, 0.22);
  border-color: rgba(201, 124, 96, 0.34);
}

.feedback-status {
  min-height: 18px;
  margin-top: 10px;
  color: var(--text-secondary);
  font-size: 13px;
}

.feedback-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 14px;
}

.feedback-cancel-button,
.feedback-send-button {
  min-width: 76px;
  padding: 10px 16px;
  border-radius: 999px;
  font-weight: 700;
}

.feedback-cancel-button {
  color: var(--text-secondary);
  background: rgba(255, 255, 255, 0.78);
  border: 1px solid var(--border-soft);
}

.feedback-send-button {
  color: #fffaf6;
  background: linear-gradient(180deg, var(--accent) 0%, var(--accent-strong) 100%);
  box-shadow: 0 10px 20px rgba(201, 124, 96, 0.2);
}

.lesson-flow-box {
  margin-top: 18px;
  display: grid;
  gap: 14px;
}

.lesson-flow-card {
  padding: 20px 24px;
  background: linear-gradient(180deg, rgba(255, 252, 247, 0.98) 0%, rgba(250, 244, 236, 0.98) 100%);
  border: 1px solid rgba(134, 111, 93, 0.12);
  border-radius: 24px;
  box-shadow: var(--shadow-card);
}

.lesson-flow-card > :first-child {
  margin-top: 0;
}

.lesson-flow-card > :last-child {
  margin-bottom: 0;
}

.lesson-flow-card h2,
.lesson-flow-card h3,
.lesson-flow-card h4 {
  font-family: var(--font-ui);
}

.lesson-flow-tip {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 16px 18px;
  color: #6a5649;
  background: linear-gradient(180deg, rgba(252, 245, 236, 0.98) 0%, rgba(249, 240, 230, 0.98) 100%);
  border: 1px solid rgba(201, 124, 96, 0.16);
  border-radius: 18px;
  box-shadow: 0 10px 24px rgba(82, 60, 46, 0.06);
  font-family: var(--font-ui);
  font-size: 14px;
}

.onboarding-viewer {
  max-width: 860px;
  margin: 0 auto;
  color: var(--text-secondary);
}

.onboarding-viewer h2 {
  margin-top: 0;
  margin-bottom: 16px;
  font-family: var(--font-ui);
  font-size: 2em;
  line-height: 1.3;
  letter-spacing: 0;
  color: var(--text-main);
}

.onboarding-viewer p {
  font-size: 1.02em;
}

.onboarding-start {
  margin-bottom: 30px;
}

.onboarding-start p {
  max-width: 680px;
  margin-bottom: 18px;
  color: var(--text-secondary);
}

.onboarding-starter-row {
  margin-top: 18px;
}

.onboarding-more {
  margin: 26px 0 34px;
}

.onboarding-more summary {
  width: fit-content;
  cursor: pointer;
  font-family: var(--font-ui);
  font-size: 15px;
  color: #7a5a4a;
  list-style-position: inside;
}

.onboarding-more-content {
  margin-top: 18px;
}

.onboarding-topic-group h4 {
  margin: 0 0 12px;
  font-family: var(--font-ui);
  font-size: 18px;
  line-height: 1.5;
  color: var(--text-main);
}

.onboarding-topic-group + .onboarding-topic-group {
  margin-top: 16px;
}

.onboarding-chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.onboarding-chip {
  border-radius: 999px;
  font-family: var(--font-ui);
  transition:
    transform 140ms ease,
    background-color 140ms ease,
    border-color 140ms ease,
    color 140ms ease,
    box-shadow 140ms ease;
}

.onboarding-chip {
  padding: 10px 14px;
  color: #604f44;
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid rgba(134, 111, 93, 0.14);
  box-shadow: 0 6px 16px rgba(82, 60, 46, 0.05);
  font-size: 14px;
  line-height: 1.2;
}

.onboarding-chip:hover,
.onboarding-chip.is-selected {
  color: #fff8f3;
  background: linear-gradient(180deg, var(--accent) 0%, var(--accent-strong) 100%);
  border-color: rgba(184, 105, 76, 0.36);
  box-shadow: 0 10px 22px rgba(201, 124, 96, 0.18);
}

.onboarding-chip:hover {
  transform: translateY(-1px);
}

.lesson-inline-chip {
  display: inline-flex;
  vertical-align: baseline;
  margin: 0 0.18em;
  padding: 0.5em 0.9em;
  font-size: 0.92em;
  line-height: 1.1;
}

.onboarding-feedback {
  margin: 18px 0 26px;
  padding: 0 0 0 16px;
  color: #5f4c40;
  border-left: 3px solid rgba(201, 124, 96, 0.42);
}

.onboarding-about {
  margin-top: 34px;
  padding-top: 26px;
  border-top: 1px solid rgba(134, 111, 93, 0.14);
}

.onboarding-about h2 {
  font-size: 1.45em;
}

.lesson-box h1,
.lesson-box h2,
.lesson-box h3,
.lesson-box h4,
.lesson-box h5,
.lesson-box h6 {
  margin: 1em 0 0.45em;
  color: #27211d;
  line-height: 1.3;
}

.lesson-box h1:first-child,
.lesson-box h2:first-child,
.lesson-box h3:first-child,
.lesson-box p:first-child {
  margin-top: 0;
}

.lesson-box [data-checkpoint-anchor="true"] {
  scroll-margin-top: 26px;
}

.lesson-box .checkpoint-anchor-flash {
  background: linear-gradient(180deg, rgba(201, 124, 96, 0.18) 0%, rgba(201, 124, 96, 0.03) 100%);
  border-radius: 12px;
  box-shadow: 0 0 0 6px rgba(201, 124, 96, 0.08);
  transition: background 220ms ease, box-shadow 220ms ease;
}

.lesson-box p,
.lesson-box ul,
.lesson-box ol,
.lesson-box blockquote,
.lesson-box pre {
  margin: 0 0 0.9em;
}

.lesson-box hr {
  margin: 1.8em 0;
  border: none;
  border-top: 1px solid rgba(127, 109, 93, 0.18);
}

.lesson-box ul,
.lesson-box ol {
  padding-left: 1.45em;
}

.lesson-box blockquote {
  margin-left: 0;
  padding-left: 1.05em;
  color: var(--text-secondary);
  border-left: 3px solid rgba(201, 124, 96, 0.42);
}

.lesson-box code {
  padding: 0.12em 0.34em;
  background: rgba(201, 124, 96, 0.1);
  border-radius: 6px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  font-size: 0.92em;
}

.lesson-box pre {
  overflow: auto;
  padding: 14px 16px;
  color: #f7f3ee;
  background: var(--bg-code);
  border-radius: 14px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

.lesson-box pre code {
  padding: 0;
  color: inherit;
  background: transparent;
}

.lesson-box a {
  color: var(--accent-strong);
  text-decoration-color: rgba(201, 124, 96, 0.45);
  text-decoration-thickness: 0.08em;
  text-underline-offset: 0.18em;
}

.lesson-table-wrap {
  margin: 0 0 0.95em;
  overflow-x: auto;
}

.lesson-table {
  width: 100%;
  min-width: 520px;
  border-collapse: collapse;
  background: rgba(255, 252, 247, 0.98);
  border: 1px solid rgba(134, 111, 93, 0.14);
  border-radius: 12px;
}

.lesson-table th,
.lesson-table td {
  padding: 0.62em 0.74em;
  text-align: left;
  vertical-align: top;
  line-height: 1.5;
  border-right: 1px solid rgba(134, 111, 93, 0.08);
  border-bottom: 1px solid rgba(134, 111, 93, 0.1);
}

.lesson-table th:last-child,
.lesson-table td:last-child {
  border-right: none;
}

.lesson-table thead th {
  font-family: var(--font-ui);
  color: #342d28;
  background: #f7efe8;
  font-weight: 700;
}

.lesson-table tbody tr:last-child td {
  border-bottom: none;
}

.lesson-dialogue {
  margin: 2em 0 0;
}

.lesson-dialogue + .lesson-dialogue {
  margin-top: 2.25em;
}

.lesson-dialogue-turn {
  display: flex;
  margin: 0 0 1.2em;
}

.lesson-dialogue-turn-user {
  justify-content: flex-end;
}

.lesson-dialogue-turn-agent {
  justify-content: flex-start;
}

.lesson-dialogue-message {
  max-width: min(100%, 860px);
}

.lesson-dialogue-message-user {
  width: fit-content;
  max-width: min(72%, 480px);
}

.lesson-dialogue-message-agent {
  width: 100%;
}

.lesson-dialogue-content > :last-child {
  margin-bottom: 0;
}

.lesson-dialogue-message-user .lesson-dialogue-content {
  padding: 0.82em 1.02em;
  color: #332722;
  background: linear-gradient(180deg, #f6e7e0 0%, var(--bg-user-bubble) 100%);
  border: 1px solid rgba(201, 124, 96, 0.22);
  border-radius: 20px 20px 8px 20px;
  box-shadow: 0 8px 24px rgba(112, 77, 55, 0.08);
}

.lesson-dialogue-message-user .lesson-dialogue-content p,
.lesson-dialogue-message-user .lesson-dialogue-content ul,
.lesson-dialogue-message-user .lesson-dialogue-content ol,
.lesson-dialogue-message-user .lesson-dialogue-content blockquote,
.lesson-dialogue-message-user .lesson-dialogue-content pre {
  margin-bottom: 0.7em;
}

.lesson-dialogue-message-user .lesson-dialogue-content blockquote {
  color: #5f5147;
  border-left-color: rgba(201, 124, 96, 0.5);
}

.lesson-dialogue-message-agent .lesson-dialogue-content {
  padding: 0;
  background: transparent;
}

.lesson-dialogue-message-agent .lesson-dialogue-content h1,
.lesson-dialogue-message-agent .lesson-dialogue-content h2,
.lesson-dialogue-message-agent .lesson-dialogue-content h3,
.lesson-dialogue-message-agent .lesson-dialogue-content h4,
.lesson-dialogue-message-agent .lesson-dialogue-content h5,
.lesson-dialogue-message-agent .lesson-dialogue-content h6 {
  margin-top: 0.9em;
}

.lesson-dialogue-message-agent .lesson-dialogue-content h1:first-child,
.lesson-dialogue-message-agent .lesson-dialogue-content h2:first-child,
.lesson-dialogue-message-agent .lesson-dialogue-content h3:first-child,
.lesson-dialogue-message-agent .lesson-dialogue-content p:first-child {
  margin-top: 0;
}

.composer {
  display: grid;
  gap: 10px;
  width: min(100%, 980px);
  margin: 0 auto;
  padding: 14px 22px calc(18px + env(safe-area-inset-bottom));
  background: transparent;
}

.composer-input-row {
  display: block;
  align-items: end;
  position: relative;
  padding: 16px 22px 16px;
  background: rgba(255, 255, 255, 0.98);
  border: 1px solid rgba(134, 111, 93, 0.12);
  border-radius: 34px;
  box-shadow:
    0 14px 34px rgba(82, 60, 46, 0.09),
    inset 0 1px 0 rgba(255, 255, 255, 0.7);
}

.composer-input-row textarea {
  width: 100%;
  min-height: 34px;
  height: 34px;
  max-height: 180px;
  padding: 5px var(--composer-textarea-right-padding) 5px 2px;
  resize: none;
  box-sizing: border-box;
  color: var(--text-main);
  background: transparent;
  border: none;
  box-shadow: none;
  font-size: 16px;
  line-height: 1.4;
  overflow-y: auto;
}

.composer-input-row textarea::placeholder {
  color: #988e85;
}

.composer-input-row textarea:focus {
  outline: none;
}

.composer-input-row button {
  min-height: var(--send-button-size);
}

.composer-actions {
  display: flex;
  flex-direction: row;
  justify-content: flex-end;
  align-items: center;
  gap: 8px;
  position: absolute;
  right: var(--composer-actions-right);
  top: 50%;
  bottom: auto;
  transform: translateY(-50%);
}

.send-button-shell {
  width: var(--send-button-size);
  height: var(--send-button-size);
  flex: 0 0 var(--send-button-size);
  min-width: var(--send-button-size);
  max-width: var(--send-button-size);
  min-height: var(--send-button-size);
  max-height: var(--send-button-size);
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  align-self: flex-end;
  box-sizing: border-box;
  border-radius: 50%;
  position: relative;
  overflow: hidden;
  background: #d9d3cc;
  box-shadow: none;
  transition: transform 140ms ease, box-shadow 140ms ease, background-color 140ms ease;
}

.send-button-shell.is-active {
  background: linear-gradient(180deg, var(--accent) 0%, var(--accent-strong) 100%);
  box-shadow: 0 8px 18px rgba(201, 124, 96, 0.22);
}

.send-button-shell.is-active:hover {
  transform: translateY(-1px);
}

.send-button-shell.is-disabled {
  background: #d7d1ca;
}

.send-button {
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  appearance: none;
  -webkit-appearance: none;
  background: transparent;
  border: none;
  border-radius: 0;
  box-shadow: none;
  cursor: pointer;
}

.send-button:disabled {
  cursor: default;
}

.send-button-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  color: #fff7f2;
  font-size: var(--send-button-icon-size);
  line-height: 1;
  transform: translateY(-1px);
  pointer-events: none;
}

.send-button-shell.is-disabled .send-button-icon {
  color: #f6f1eb;
}

.composer-status {
  grid-column: 1 / -1;
  min-height: 16px;
  color: var(--text-secondary);
  font-size: 12px;
}

.composer-status.is-thinking {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.composer-status-logo {
  width: 16px;
  height: 16px;
  flex: 0 0 16px;
  border-radius: 5px;
}

.composer-status-text,
.composer-status-dots,
.lesson-flow-tip-text,
.lesson-flow-tip-dots {
  display: inline-block;
}

.status-dots {
  width: 6ch;
  overflow: hidden;
  white-space: nowrap;
  animation: status-dots 1.4s steps(7, end) infinite;
}

@keyframes status-dots {
  0% {
    width: 0;
  }

  100% {
    width: 6ch;
  }
}

@media (prefers-reduced-motion: reduce) {
  .status-dots {
    width: 6ch;
    animation: none;
  }
}

.hidden {
  display: none !important;
}

@media (max-width: 760px) {
  .app-shell {
    display: block;
  }

  .sidebar {
    position: fixed;
    z-index: 20;
    top: 0;
    bottom: 0;
    left: 0;
    width: min(86vw, 320px);
    transform: translateX(-100%);
    transition: transform 160ms ease;
    border-right: 1px solid var(--border-soft);
  }

  .app-shell.sidebar-open .sidebar {
    transform: translateX(0);
  }

  .sidebar-close {
    display: inline-flex;
  }

  .brand-mark {
    width: 40px;
    height: 40px;
    flex-basis: 40px;
    border-radius: 12px;
  }

  .brand-name {
    font-size: 17px;
  }

  .brand-tagline {
    font-size: 11px;
  }

  .sidebar-overlay {
    position: fixed;
    inset: 0;
    z-index: 10;
    display: none;
    background: rgba(40, 30, 22, 0.28);
    backdrop-filter: blur(2px);
  }

  .app-shell.sidebar-open .sidebar-overlay {
    display: block;
  }

  .topbar {
    grid-template-columns: auto minmax(0, 1fr) auto;
    padding: 10px 12px;
  }

  .nav-button {
    display: inline-flex;
  }

  .lesson-title-group h1 {
    font-size: 16px;
  }

  .topbar-actions {
    gap: 8px;
  }

  .auth-status {
    padding: 12px;
    border-radius: 16px;
  }

  .account-dock {
    padding-top: 10px;
    padding-bottom: calc(env(safe-area-inset-bottom) + 4px);
  }

  .auth-meta-label {
    white-space: normal;
  }

  .auth-gate-card h2 {
    font-size: 24px;
  }

  .auth-gate-logo {
    width: 62px;
    height: 62px;
    margin-bottom: 16px;
    border-radius: 18px;
  }

  .font-controls {
    gap: 6px;
  }

  .font-control-button {
    width: 34px;
    height: 34px;
    border-radius: 12px;
  }

  .lesson-box {
    width: 100%;
    min-height: 0;
    margin-top: 0;
    padding: 16px 12px 26px;
  }

  #lessonContent,
  .lesson-flow-box {
    width: 100%;
  }

  #lessonContent {
    padding: 0 8px;
  }

  .scroll-bottom-button {
    bottom: calc(120px + env(safe-area-inset-bottom));
    width: 32px;
    height: 32px;
  }

  .scroll-bottom-button span {
    font-size: 18px;
  }

  .lesson-flow-card {
    padding: 18px 16px;
    border-radius: 20px;
  }

  .lesson-box [data-checkpoint-anchor="true"] {
    scroll-margin-top: 42px;
  }

  .onboarding-viewer {
    margin-top: 0;
  }

  .onboarding-viewer h2 {
    margin-bottom: 14px;
    font-size: 1.5em;
    line-height: 1.3;
  }

  .onboarding-topic-group h4 {
    font-size: 15px;
  }

  .onboarding-chip-row {
    gap: 8px;
  }

  .onboarding-chip {
    padding: 9px 12px;
    font-size: 13px;
  }

  .lesson-dialogue-message-user {
    max-width: min(84%, 360px);
  }

  .composer {
    width: calc(100% - 12px);
    padding: 10px 6px calc(10px + env(safe-area-inset-bottom));
  }

  .composer-input-row {
    padding: 12px 14px;
    border-radius: 24px;
    --send-button-size: 32px;
    --send-button-icon-size: 18px;
    --composer-actions-right: 14px;
  }

  .composer-input-row textarea {
    min-height: 32px;
    height: 32px;
    max-height: 144px;
    font-size: 15px;
  }

  .composer-actions {
    right: 14px;
    top: 50%;
    bottom: auto;
  }

  .send-button {
    width: 100%;
    height: 100%;
  }

  .viewer-nav {
    bottom: calc(120px + env(safe-area-inset-bottom));
  }

  .viewer-nav-button {
    min-width: 96px;
    min-height: 32px;
    padding: 0 16px;
  }

  .viewer-nav-button-label {
    font-size: 14px;
  }

  .viewer-nav-menu {
    bottom: calc(100% + 8px);
    width: min(240px, calc(100vw - 28px));
    max-height: min(42vh, 320px);
  }

}
