.fl-courseware,
.cw-overlay {
  --cw-bg: #11171d;
  --cw-panel: #182129;
  --cw-panel-2: #202b34;
  --cw-line: #34424d;
  --cw-text: #edf4f7;
  --cw-muted: #9fb0ba;
  --cw-accent: #32c6a6;
  --cw-warn: #f0b45a;
  color: var(--cw-text);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
}

.fl-courseware { min-height: 100%; background: var(--cw-bg); }

.fl-courseware *,
.cw-overlay * { box-sizing: border-box; }
.fl-courseware button,
.fl-courseware input,
.fl-courseware select,
.fl-courseware textarea,
.cw-overlay button,
.cw-overlay input,
.cw-overlay select,
.cw-overlay textarea { font: inherit; letter-spacing: 0; }

.cw-toolbar {
  min-height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--cw-line);
  background: #141c22;
}

.cw-toolbar h3 { margin: 0; font-size: 18px; letter-spacing: 0; }
.cw-toolbar__actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.cw-btn {
  min-height: 38px;
  border: 1px solid var(--cw-line);
  border-radius: 6px;
  padding: 8px 13px;
  background: var(--cw-panel-2);
  color: var(--cw-text);
  cursor: pointer;
}

.cw-btn:hover { border-color: #69808f; background: #273540; }
.cw-btn:focus-visible,
.cw-field:focus-visible { outline: 2px solid var(--cw-accent); outline-offset: 2px; }
.cw-btn--primary { border-color: #278c78; background: #1f765f; color: #fff; }
.cw-btn--primary:hover { background: #278c78; }
.cw-btn--danger { border-color: #8f5252; color: #ffd4d4; }
.cw-btn[disabled] { cursor: not-allowed; opacity: .55; }

.cw-layout {
  display: grid;
  grid-template-columns: minmax(230px, 280px) minmax(0, 1fr);
  min-height: min(720px, calc(100vh - 230px));
}

.cw-sidebar {
  border-right: 1px solid var(--cw-line);
  background: #141c22;
  overflow: auto;
}

.cw-deck {
  width: 100%;
  min-height: 78px;
  display: block;
  padding: 12px 14px;
  border: 0;
  border-bottom: 1px solid #29353e;
  background: transparent;
  color: var(--cw-text);
  text-align: left;
  cursor: pointer;
}

.cw-deck:hover,
.cw-deck.is-active { background: #20303a; }
.cw-deck.is-active { box-shadow: inset 3px 0 0 var(--cw-accent); }
.cw-deck__title { display: block; font-weight: 700; line-height: 1.35; }
.cw-deck__meta { display: flex; gap: 8px; margin-top: 7px; color: var(--cw-muted); font-size: 12px; }

.cw-main { min-width: 0; padding: 16px; overflow: auto; }
.cw-empty { min-height: 360px; display: grid; place-items: center; color: var(--cw-muted); text-align: center; }
.cw-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 14px; }
.cw-head h4 { margin: 0 0 5px; font-size: 20px; letter-spacing: 0; }
.cw-head p { margin: 0; color: var(--cw-muted); }

.cw-status {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 3px 8px;
  border: 1px solid #4f626e;
  border-radius: 4px;
  color: #c8d6dc;
  font-size: 12px;
  white-space: nowrap;
}
.cw-status--ready,
.cw-status--published { border-color: #2e8f77; color: #8ce5ce; }
.cw-status--failed { border-color: #9f5555; color: #ffb5b5; }
.cw-status--converting,
.cw-status--queued { border-color: #a77939; color: #ffd38a; }
.cw-current {
  display: inline-block;
  margin-left: 7px;
  padding: 2px 5px;
  border-radius: 3px;
  background: #26735f;
  color: #e6fff8;
  font-size: 11px;
}

.cw-public-link {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  margin-bottom: 12px;
  padding: 10px 12px;
  border: 1px solid var(--cw-line);
  border-radius: 6px;
  background: #141d23;
  color: var(--cw-muted);
  font-size: 12px;
}
.cw-public-link code {
  min-width: 0;
  overflow: hidden;
  color: var(--cw-text);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cw-upload {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: end;
  padding: 13px;
  border: 1px solid var(--cw-line);
  border-radius: 6px;
  background: var(--cw-panel);
  margin-bottom: 14px;
}

.cw-field-wrap { display: grid; gap: 6px; color: var(--cw-muted); font-size: 12px; }
.cw-field {
  width: 100%;
  min-height: 40px;
  border: 1px solid #40515d;
  border-radius: 5px;
  padding: 8px 10px;
  background: #10171c;
  color: var(--cw-text);
}
textarea.cw-field { resize: vertical; min-height: 78px; }
.cw-progress { grid-column: 1 / -1; height: 8px; border-radius: 4px; overflow: hidden; background: #0d1317; display: none; }
.cw-progress span { display: block; width: 0; height: 100%; background: var(--cw-accent); transition: width .2s ease; }

.cw-section { margin-top: 16px; }
.cw-section__title { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 0 0 9px; font-size: 15px; }
.cw-table-wrap { overflow: auto; border: 1px solid var(--cw-line); border-radius: 6px; }
.cw-table { width: 100%; border-collapse: collapse; min-width: 650px; }
.cw-table th,
.cw-table td { padding: 9px 10px; border-bottom: 1px solid #2d3a43; text-align: left; font-size: 13px; }
.cw-table th { background: #1b252d; color: var(--cw-muted); font-weight: 600; }
.cw-table tr:last-child td { border-bottom: 0; }
.cw-page-thumb { width: 92px; aspect-ratio: 16 / 9; object-fit: contain; background: #0b1014; border: 1px solid #34434d; }
.cw-actions { display: flex; gap: 6px; flex-wrap: wrap; }

.cw-overlay {
  position: fixed;
  inset: 0;
  z-index: 5200;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(4, 8, 11, .78);
}

.cw-dialog {
  width: min(680px, 100%);
  max-height: min(820px, calc(100vh - 36px));
  overflow: auto;
  border: 1px solid #52636e;
  border-radius: 7px;
  background: #182129;
  box-shadow: 0 24px 70px rgba(0, 0, 0, .45);
}
.cw-dialog__head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 16px; border-bottom: 1px solid var(--cw-line); }
.cw-dialog__head h4 { margin: 0; font-size: 17px; }
.cw-dialog__body { display: grid; grid-template-columns: 1fr 1fr; gap: 13px; padding: 16px; }
.cw-dialog__body .is-wide { grid-column: 1 / -1; }
.cw-dialog__foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--cw-line); }
.cw-message { min-height: 24px; color: var(--cw-muted); font-size: 13px; }

.cw-overlay--visual { padding: 10px; }
.cw-visual-editor {
  width: min(1480px, 100%);
  height: min(920px, calc(100dvh - 20px));
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  overflow: hidden;
  border: 1px solid #52636e;
  border-radius: 7px;
  background: #182129;
  box-shadow: 0 24px 70px rgba(0, 0, 0, .45);
}
.cw-visual-editor .cw-dialog__head small { display: block; margin-top: 3px; color: var(--cw-muted); }
.cw-visual-editor .cw-dialog__foot { align-items: center; }
.cw-visual-editor .cw-dialog__foot .cw-message { margin-right: auto; }
.cw-icon-btn { width: 40px; height: 40px; padding: 0; font-size: 22px; }
.cw-visual-layout { min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr) 310px; }
.cw-visual-workspace { min-width: 0; min-height: 0; display: grid; grid-template-rows: auto minmax(0, 1fr); border-right: 1px solid var(--cw-line); }
.cw-visual-toolbar { display: flex; gap: 8px; padding: 10px 12px; border-bottom: 1px solid var(--cw-line); background: #141d23; }
.cw-visual-toolbar .cw-btn b { min-width: 20px; color: #75dcc1; font-family: Georgia, serif; font-size: 15px; }
.cw-btn--danger { border-color: #7b4545; color: #ffc5c5; }
.cw-btn--danger:hover:not(:disabled) { background: #4c2929; }
.cw-visual-canvas { min-height: 0; display: grid; place-items: center; overflow: auto; padding: 12px; background: #0d1317; }
.cw-visual-stage {
  position: relative;
  width: min(100%, calc((100dvh - 190px) * var(--cw-slide-ratio)));
  flex: 0 0 auto;
  overflow: hidden;
  background: #fff;
  box-shadow: 0 8px 26px rgba(0, 0, 0, .38);
  container-type: size;
}
.cw-visual-stage > img { position: absolute; inset: 0; display: block; width: 100%; height: 100%; object-fit: fill; pointer-events: none; }
.cw-visual-layers { position: absolute; z-index: 2; inset: 0; overflow: hidden; }
.cw-source-object {
  position: absolute;
  z-index: 3;
  min-width: 0;
  min-height: 0;
  padding: 0;
  border: 1px dashed rgba(19, 167, 137, .38);
  border-radius: 2px;
  background: rgba(19, 167, 137, .025);
  cursor: text;
}
.cw-source-object:hover,
.cw-source-object:focus-visible { border-color: #13a789; background: rgba(19, 167, 137, .1); outline: 0; }
.cw-source-object.is-selected { border: 2px solid #13a789; background: rgba(19, 167, 137, .12); }
.cw-visual-overlay {
  position: absolute;
  z-index: 4;
  display: flex;
  align-items: center;
  min-width: 0;
  min-height: 0;
  padding: 0 .18em;
  overflow: hidden;
  border: 1px solid transparent;
  font-family: "Microsoft YaHei", "Noto Sans CJK SC", system-ui, sans-serif;
  line-height: 1.25;
  white-space: pre-wrap;
  cursor: move;
  touch-action: none;
}
.cw-visual-overlay.is-source-untouched { opacity: 0; pointer-events: none; }
.cw-visual-overlay__clean-patch { position: absolute; z-index: 0; max-width: none; max-height: none; pointer-events: none; }
.cw-visual-overlay__content,
.cw-visual-resize { position: relative; z-index: 1; }
.cw-visual-overlay:hover { border-color: rgba(23, 125, 103, .75); }
.cw-visual-overlay.is-selected { border-color: #13a789; outline: 2px solid rgba(19, 167, 137, .35); outline-offset: 1px; }
.cw-visual-overlay__content { display: block; width: 100%; min-width: 0; pointer-events: none; }
.cw-visual-overlay--formula { font-family: "STIX Two Math", "STIX Math", "Cambria Math", serif; line-height: 1; white-space: nowrap; }
.cw-visual-overlay--formula .katex-display { margin: 0; }
.cw-visual-overlay--formula .katex { font-size: 1em; }
.cw-visual-resize {
  position: absolute;
  right: 0;
  bottom: 0;
  width: 15px;
  height: 15px;
  border: 2px solid #fff;
  background: #16866f;
  cursor: nwse-resize;
  touch-action: none;
}
.cw-visual-inspector { min-height: 0; overflow: auto; display: grid; align-content: start; gap: 14px; padding: 14px; background: #182129; }
.cw-inspector-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; padding-bottom: 10px; border-bottom: 1px solid var(--cw-line); }
.cw-inspector-head strong { font-size: 16px; }
.cw-inspector-head span { overflow: hidden; color: var(--cw-muted); text-overflow: ellipsis; white-space: nowrap; font-size: 11px; }
.cw-visual-inspector textarea.cw-field { min-height: 118px; font-family: inherit; }
.cw-visual-overlay--formula + * { letter-spacing: 0; }
.cw-formula-examples { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 5px; }
.cw-formula-examples button { min-height: 32px; padding: 4px; border: 1px solid #40515d; border-radius: 4px; background: #10171c; color: #cbd8dd; cursor: pointer; }
.cw-formula-examples button:hover { border-color: #2ca78a; color: #fff; }
.cw-range { display: grid; grid-template-columns: minmax(0, 1fr) 36px; align-items: center; gap: 9px; }
.cw-range input { width: 100%; accent-color: #2ca78a; }
.cw-range output { color: #d8e6ea; text-align: right; font-variant-numeric: tabular-nums; }
.cw-inspector-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.cw-color { width: 100%; height: 40px; padding: 3px; border: 1px solid #40515d; border-radius: 5px; background: #10171c; }
.cw-check { display: flex; align-items: center; gap: 8px; color: var(--cw-muted); font-size: 12px; }
.cw-check input { width: 17px; height: 17px; accent-color: #2ca78a; }
.cw-field-wrap small { color: #7f919a; line-height: 1.4; }
.cw-visual-empty { min-height: 180px; display: grid; place-content: center; gap: 7px; color: var(--cw-muted); text-align: center; }
.cw-visual-empty strong { color: var(--cw-text); }
.cw-animation-order { display: grid; gap: 7px; margin: 0; padding: 0; list-style: none; }
.cw-animation-order li { display: grid; grid-template-columns: 30px minmax(0, 1fr) auto; align-items: center; gap: 8px; min-height: 46px; padding: 6px; border: 1px solid var(--cw-line); border-radius: 5px; background: #11191f; }
.cw-animation-order__number { display: grid; place-items: center; width: 28px; height: 28px; border-radius: 50%; background: #25333b; color: #72d7bb; font-variant-numeric: tabular-nums; }
.cw-animation-order__label { min-width: 0; overflow: hidden; color: var(--cw-text); text-overflow: ellipsis; white-space: nowrap; font-size: 12px; }
.cw-animation-order__actions { display: flex; gap: 4px; }
.cw-animation-order__actions button { display: grid; place-items: center; width: 30px; height: 30px; padding: 0; border: 1px solid #52636d; border-radius: 4px; background: #202c33; color: #e9f0f2; cursor: pointer; }
.cw-animation-order__actions button:disabled { opacity: .3; cursor: default; }

@media (max-width: 900px) {
  .cw-layout { grid-template-columns: 220px minmax(0, 1fr); }
  .cw-main { padding: 12px; }
  .cw-visual-layout { grid-template-columns: minmax(0, 1fr) 270px; }
}

@media (max-width: 700px) {
  .cw-layout { display: block; min-height: 0; }
  .cw-sidebar { border-right: 0; border-bottom: 1px solid var(--cw-line); display: flex; overflow-x: auto; }
  .cw-deck { min-width: 210px; border-right: 1px solid #29353e; }
  .cw-head { align-items: stretch; flex-direction: column; }
  .cw-upload { grid-template-columns: 1fr; }
  .cw-upload .cw-btn { width: 100%; }
  .cw-progress { grid-column: 1; }
  .cw-public-link { grid-template-columns: 1fr auto; }
  .cw-public-link > span { grid-column: 1 / -1; }
  .cw-dialog__body { grid-template-columns: 1fr; }
  .cw-dialog__body .is-wide { grid-column: 1; }
  .cw-overlay--visual { padding: 0; }
  .cw-visual-editor { width: 100%; height: 100dvh; border: 0; border-radius: 0; }
  .cw-visual-layout { grid-template-columns: 1fr; grid-template-rows: minmax(280px, 1fr) minmax(220px, .75fr); }
  .cw-visual-workspace { border-right: 0; border-bottom: 1px solid var(--cw-line); }
  .cw-visual-toolbar { overflow-x: auto; }
  .cw-visual-toolbar .cw-btn { flex: 0 0 auto; }
  .cw-visual-canvas { padding: 7px; }
  .cw-visual-stage { width: min(100%, calc((100dvh - 430px) * var(--cw-slide-ratio))); min-width: 260px; }
  .cw-visual-inspector { padding: 11px; }
  .cw-visual-editor .cw-dialog__foot { padding: 8px 10px max(8px, env(safe-area-inset-bottom)); }
  .cw-visual-editor .cw-dialog__foot .cw-message { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .cw-progress span { transition: none; }
}
