:root {
  --blue: #4b50e6;
  --blue-dark: #3034ad;
  --blue-pale: #eceeff;
  --ink: #111832;
  --text: #4e5872;
  --muted: #8d96ad;
  --line: #e4e8f3;
  --surface: #fff;
  --background: #f4f6fc;
  --sidebar: #f8f9fd;
  --gold: #d6a840;
  --green: #21a868;
  --display: "Songti SC", "STSong", Georgia, serif;
  --sans: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  --mono: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  --topbar: 68px;
  --sidebar-w: 336px;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body { margin: 0; color: var(--text); background: var(--background); font-family: var(--sans); -webkit-font-smoothing: antialiased; }
body.dark {
  --ink: #f1f3ff;
  --text: #b9c0d6;
  --muted: #7d86a2;
  --line: #2b3149;
  --surface: #171c2d;
  --background: #0f1321;
  --sidebar: #141927;
  --blue-pale: #24294d;
}
button, a { font: inherit; color: inherit; }
button { cursor: pointer; }
a { text-decoration: none; }
img { display: block; max-width: 100%; }

.topbar { height: var(--topbar); position: fixed; inset: 0 0 auto; z-index: 100; padding: 0 22px; display: flex; align-items: center; border-bottom: 1px solid var(--line); background: color-mix(in srgb, var(--surface) 90%, transparent); backdrop-filter: blur(18px); }
.brand { display: flex; align-items: center; gap: 10px; min-width: calc(var(--sidebar-w) - 22px); }
.brand img { filter: drop-shadow(0 4px 9px rgba(75,80,230,.24)); }
.brand span { display: flex; flex-direction: column; line-height: 1; }
.brand b { color: var(--ink); font-size: 16px; }
.brand small { color: var(--muted); font-size: 8px; letter-spacing: .25em; margin-top: 5px; }
.topbar__course { display: flex; align-items: center; gap: 9px; font-size: 12px; color: var(--muted); }
.topbar__course b { color: var(--ink); font-size: 13px; font-weight: 600; }
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--green); box-shadow: 0 0 0 5px color-mix(in srgb, var(--green) 15%, transparent); }
.topbar__actions { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.icon-button, .mobile-menu { width: 38px; height: 38px; display: grid; place-items: center; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; }
.icon-button svg { width: 18px; fill: none; stroke: var(--text); stroke-width: 1.7; stroke-linecap: round; }
.console-link { padding: 10px 16px; border-radius: 999px; color: white; font-size: 12px; font-weight: 600; background: linear-gradient(135deg, #7378f0, var(--blue)); box-shadow: 0 8px 20px rgba(75,80,230,.2); }
.mobile-menu { display: none; gap: 4px; align-content: center; }
.mobile-menu span { width: 16px; height: 1.5px; background: var(--ink); }

.app-shell { display: grid; grid-template-columns: var(--sidebar-w) minmax(0,1fr); min-height: 100vh; padding-top: var(--topbar); }
.sidebar { position: fixed; top: var(--topbar); bottom: 0; left: 0; width: var(--sidebar-w); overflow-y: auto; padding: 30px 20px 24px; border-right: 1px solid var(--line); background: var(--sidebar); z-index: 50; }
.sidebar__head { display: flex; align-items: flex-end; gap: 15px; padding: 0 10px; }
.kicker { font: 500 10px var(--mono); color: var(--blue); letter-spacing: .14em; }
.sidebar__head h1 { margin: 8px 0 0; font: 700 25px/1.35 var(--display); color: var(--ink); letter-spacing: -.02em; }
.progress-ring { --progress: 0; margin-left: auto; flex: 0 0 auto; width: 61px; height: 61px; display: grid; place-items: center; border-radius: 50%; background: conic-gradient(var(--blue) calc(var(--progress)*1%), var(--line) 0); position: relative; }
.progress-ring::before { content: ""; position: absolute; inset: 5px; background: var(--sidebar); border-radius: inherit; }
.progress-ring span { position: relative; color: var(--ink); line-height: 1; }
.progress-ring b { font: 500 17px var(--mono); }
.progress-ring small { font: 500 9px var(--mono); color: var(--muted); }
.sidebar__meta { padding: 0 10px 22px; margin: 9px 0 20px; color: var(--muted); font-size: 11px; border-bottom: 1px solid var(--line); }
.sidebar-close { display: none; }

.chapter { margin-bottom: 8px; }
.chapter__toggle { width: 100%; border: 0; background: transparent; display: grid; grid-template-columns: 29px 1fr auto; gap: 9px; text-align: left; align-items: center; padding: 12px 9px; border-radius: 12px; }
.chapter__toggle:hover { background: color-mix(in srgb, var(--blue-pale) 65%, transparent); }
.chapter__no { font: 500 10px var(--mono); color: var(--blue); border-right: 1px solid var(--line); }
.chapter__toggle > span:nth-child(2) { display: flex; flex-direction: column; gap: 3px; }
.chapter__toggle b { font-size: 12px; color: var(--ink); }
.chapter__toggle small { font-size: 9px; color: var(--muted); }
.chapter__toggle i { font-style: normal; color: var(--muted); font-size: 11px; transition: transform .2s; }
.chapter:not(.is-open) .chapter__toggle i { transform: rotate(180deg); }
.chapter:not(.is-open) .chapter__lessons { display: none; }
.chapter__lessons { position: relative; margin-left: 22px; }
.chapter__lessons::before { content: ""; position: absolute; left: 9px; top: 0; bottom: 0; width: 1px; background: var(--line); }
.lesson { position: relative; width: 100%; border: 0; background: transparent; display: grid; grid-template-columns: 20px 1fr 22px; align-items: center; gap: 8px; text-align: left; padding: 11px 8px 11px 0; border-radius: 0 13px 13px 0; }
.lesson::before { content: ""; position: absolute; inset: 3px 0 3px -8px; z-index: -1; border-radius: 12px; opacity: 0; background: var(--surface); box-shadow: 0 4px 17px rgba(29,42,93,.06); }
.lesson:hover::before, .lesson.is-active::before { opacity: 1; }
.lesson.is-active::after { content: ""; position: absolute; left: -8px; top: 15px; bottom: 15px; width: 3px; border-radius: 3px; background: var(--blue); }
.lesson__state { width: 19px; height: 19px; display: grid; place-items: center; z-index: 1; border-radius: 50%; background: var(--sidebar); border: 1px solid var(--line); }
.lesson__state i { width: 5px; height: 5px; border-radius: 50%; background: var(--muted); }
.lesson.is-active .lesson__state { background: var(--blue); border-color: var(--blue); box-shadow: 0 0 0 4px var(--blue-pale); }
.lesson.is-active .lesson__state i { border-radius: 0; width: 0; height: 0; border-top: 3px solid transparent; border-bottom: 3px solid transparent; border-left: 5px solid white; background: transparent; margin-left: 1px; }
.lesson.is-complete .lesson__state { border-color: var(--green); background: var(--green); }
.lesson.is-complete .lesson__state i { width: 7px; height: 4px; background: transparent; border: 0 solid white; border-width: 0 0 1.5px 1.5px; border-radius: 0; transform: rotate(-45deg) translateY(-1px); }
.lesson__copy { display: flex; flex-direction: column; min-width: 0; gap: 4px; }
.lesson__copy b { color: var(--ink); font-size: 11px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lesson__copy small { color: var(--muted); font: 400 9px var(--mono); }
.lesson__play { color: var(--blue); font-size: 8px; opacity: 0; }
.lesson.is-active .lesson__play { opacity: 1; }
.sidebar__tip { margin: 24px 8px 0; padding: 13px; display: flex; gap: 10px; border-radius: 14px; background: var(--blue-pale); border: 1px solid color-mix(in srgb, var(--blue) 12%, var(--line)); }
.sidebar__tip > span { color: var(--blue); }
.sidebar__tip p { margin: 0; display: flex; flex-direction: column; gap: 4px; }
.sidebar__tip b { color: var(--ink); font-size: 10px; }
.sidebar__tip small { color: var(--muted); font-size: 9px; line-height: 1.6; }

.learning-area { grid-column: 2; min-width: 0; padding: 45px clamp(28px,5vw,80px) 0; }
.lesson-heading { max-width: 1160px; margin: 0 auto 24px; display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; }
.breadcrumb { display: flex; gap: 9px; color: var(--muted); font: 500 10px var(--mono); letter-spacing: .04em; }
.breadcrumb i { color: var(--line); }
.lesson-heading h2 { margin: 11px 0 0; color: var(--ink); font: 700 clamp(24px,3vw,34px)/1.3 var(--display); letter-spacing: -.025em; }
.complete-button { display: inline-flex; align-items: center; gap: 8px; padding: 10px 13px; border: 1px solid var(--line); background: var(--surface); color: var(--text); border-radius: 11px; white-space: nowrap; box-shadow: 0 5px 14px rgba(20,30,70,.04); }
.complete-button span { width: 20px; height: 20px; display: grid; place-items: center; border: 1px solid var(--line); border-radius: 6px; font-size: 10px; color: transparent; }
.complete-button b { font-size: 10px; }
.complete-button.is-complete { color: var(--green); border-color: color-mix(in srgb, var(--green) 30%, var(--line)); }
.complete-button.is-complete span { color: white; background: var(--green); border-color: var(--green); }

.video-frame { max-width: 1160px; margin: 0 auto; position: relative; padding: 6px; background: #10152b; border-radius: 20px; box-shadow: 0 28px 70px rgba(18,29,86,.2); }
.video-frame video { display: block; width: 100%; aspect-ratio: 16/9; background: #060a18; border-radius: 15px; object-fit: contain; }
.video-frame .tcp-skin { width: 100% !important; aspect-ratio: 16/9; height: auto !important; border-radius: 15px; overflow: hidden; }
.video-glow { position: absolute; inset: -8% 7% auto; height: 40%; background: var(--blue); opacity: .18; filter: blur(70px); z-index: -1; }
.video-status { position: absolute; inset: 6px; z-index: 8; display: none; place-content: center; justify-items: center; gap: 9px; padding: 24px; text-align: center; color: white; background: rgba(6,10,24,.88); border-radius: 15px; backdrop-filter: blur(10px); }
.video-status.is-visible { display: grid; }
.video-status b { font: 600 17px var(--display); }
.video-status small { color: rgba(255,255,255,.65); font-size: 10px; }
.video-status a, .video-status button { margin-top: 5px; padding: 9px 15px; border: 0; border-radius: 9px; color: white; background: var(--blue); font: 600 10px var(--sans); cursor: pointer; }
.video-status__spinner { width: 25px; height: 25px; border: 2px solid rgba(255,255,255,.2); border-top-color: white; border-radius: 50%; animation: video-spin .8s linear infinite; }
.video-status.is-error .video-status__spinner { display: none; }
@keyframes video-spin { to { transform: rotate(360deg); } }
.resume-toast { position: absolute; left: 50%; bottom: 62px; transform: translate(-50%,12px); border-radius: 999px; padding: 8px 13px; color: white; background: rgba(14,20,44,.86); font-size: 10px; backdrop-filter: blur(10px); opacity: 0; pointer-events: none; transition: .3s; }
.resume-toast.show { opacity: 1; transform: translate(-50%,0); }

.lesson-actions { max-width: 1160px; margin: 16px auto 0; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 16px; }
.lesson-actions button { border: 0; padding: 7px 0; background: transparent; display: grid; grid-template-columns: auto 1fr; gap: 1px 9px; text-align: left; align-items: center; color: var(--muted); }
.lesson-actions button > span { grid-row: 1/3; font-size: 18px; }
.lesson-actions button small { font-size: 9px; }
.lesson-actions button b { max-width: 260px; color: var(--ink); font-size: 10px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.lesson-actions button:last-child { margin-left: auto; grid-template-columns: 1fr auto; text-align: right; }
.lesson-actions button:last-child > span { grid-column: 2; }
.lesson-actions button:disabled { opacity: .35; cursor: default; }
.lesson-actions__hint { display: flex; gap: 8px; align-items: center; font-size: 9px; color: var(--muted); }
.lesson-actions__hint i { width: 5px; height: 5px; border-radius: 50%; background: var(--green); }

.lesson-notes { max-width: 1160px; margin: 40px auto 80px; border-top: 1px solid var(--line); }
.tabs { height: 59px; display: flex; align-items: stretch; gap: 28px; border-bottom: 1px solid var(--line); }
.tab { position: relative; border: 0; background: transparent; color: var(--muted); font-size: 11px; font-weight: 600; padding: 0; }
.tab.is-active { color: var(--blue); }
.tab.is-active::after { content: ""; position: absolute; left: 0; right: 0; bottom: -1px; height: 2px; background: var(--blue); }
.tab-panel { display: none; min-height: 170px; padding: 30px 0; grid-template-columns: 54px 1fr; gap: 25px; }
.tab-panel.is-active { display: grid; }
.note-index { width: 44px; height: 44px; display: grid; place-items: center; color: var(--blue); border: 1px solid var(--line); background: var(--surface); border-radius: 13px; font: 500 11px var(--mono); box-shadow: 0 5px 15px rgba(25,35,80,.05); }
.tab-panel h3 { color: var(--ink); font: 700 17px var(--display); margin: 2px 0 11px; }
.tab-panel p { max-width: 860px; font-size: 12px; line-height: 1.9; margin: 0; }
.tab-panel ul { margin: 0; padding: 0; list-style: none; display: grid; grid-template-columns: repeat(2,1fr); gap: 10px 30px; }
.tab-panel li { font-size: 11px; color: var(--text); }
.tab-panel li::before { content: "✓"; color: var(--green); margin-right: 9px; }
.resource-grid { display: flex; gap: 12px; }
.resource-grid a { min-width: 225px; display: grid; grid-template-columns: 34px 1fr; gap: 2px 10px; padding: 13px; border: 1px solid var(--line); border-radius: 13px; background: var(--surface); }
.resource-grid a > span { grid-row: 1/3; width: 34px; height: 34px; display: grid; place-items: center; border-radius: 9px; background: var(--blue-pale); color: var(--blue); font: 500 10px var(--mono); }
.resource-grid b { color: var(--ink); font-size: 10px; }
.resource-grid small { font-size: 8px; color: var(--muted); }

footer { margin: 0 calc(clamp(28px,5vw,80px)*-1); padding: 24px clamp(28px,5vw,80px); display: flex; align-items: center; border-top: 1px solid var(--line); background: var(--surface); font-size: 9px; color: var(--muted); }
.brand--footer { min-width: 0; }
footer p { margin: 0 auto; }
.sidebar-backdrop { display: none; }

@media (max-width: 980px) {
  :root { --sidebar-w: 310px; }
  .topbar__course { display: none; }
  .topbar .brand { min-width: 0; }
  .mobile-menu { display: grid; }
  .app-shell { display: block; }
  .sidebar { transform: translateX(-105%); transition: transform .28s ease; box-shadow: 20px 0 50px rgba(10,20,60,.18); }
  .sidebar.is-open { transform: none; }
  .sidebar-close { display: block; position: absolute; top: 10px; right: 12px; border: 0; background: transparent; color: var(--muted); font-size: 25px; }
  .sidebar-backdrop { position: fixed; inset: var(--topbar) 0 0; z-index: 40; background: rgba(10,15,35,.42); backdrop-filter: blur(2px); }
  .sidebar-backdrop.is-open { display: block; }
  .learning-area { padding-top: 35px; }
}

@media (max-width: 680px) {
  .topbar { padding: 0 13px; }
  .console-link { display: none; }
  .learning-area { padding: 25px 14px 0; }
  .lesson-heading { align-items: flex-start; }
  .lesson-heading h2 { font-size: 23px; }
  .complete-button b { display: none; }
  .video-frame { margin: 0 -14px; padding: 0; border-radius: 0; }
  .video-frame video { border-radius: 0; }
  .video-frame .tcp-skin { border-radius: 0; }
  .video-status { inset: 0; border-radius: 0; }
  .lesson-actions { grid-template-columns: 1fr 1fr; }
  .lesson-actions__hint { display: none; }
  .lesson-actions button b { max-width: 120px; }
  .tabs { gap: 20px; }
  .tab-panel { grid-template-columns: 1fr; }
  .note-index { display: none; }
  .tab-panel ul { grid-template-columns: 1fr; }
  .resource-grid { flex-direction: column; }
  .resource-grid a { min-width: 0; }
  footer { gap: 20px; }
  footer p { display: none; }
  footer > span { margin-left: auto; }
}

@media (max-width: 680px) {
  body { overscroll-behavior-y: none; }
  button, a { -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
  .topbar { padding-right: max(13px, env(safe-area-inset-right)); padding-left: max(13px, env(safe-area-inset-left)); }
  .icon-button, .mobile-menu { width: 44px; height: 44px; }
  .brand b { font-size: 14px; }
  .brand small { display: none; }
  .sidebar { width: min(88vw, 340px); padding-bottom: calc(24px + env(safe-area-inset-bottom)); }
  .lesson-heading { align-items: stretch; flex-direction: column; gap: 14px; margin-bottom: 18px; }
  .breadcrumb { overflow-x: auto; padding-bottom: 2px; white-space: nowrap; scrollbar-width: none; }
  .breadcrumb::-webkit-scrollbar, .tabs::-webkit-scrollbar { display: none; }
  .lesson-heading h2 { margin-top: 8px; font-size: clamp(21px, 6.2vw, 25px); }
  .complete-button { min-height: 44px; align-self: flex-start; padding: 9px 13px; }
  .complete-button b { display: block; font-size: 11px; }
  .video-frame video, .video-frame .tcp-skin { min-height: 0; }
  .video-status { padding: 18px; }
  .resume-toast { bottom: 18px; max-width: calc(100% - 28px); text-align: center; white-space: nowrap; }
  .lesson-actions { gap: 8px; margin-top: 12px; }
  .lesson-actions button { min-width: 0; min-height: 64px; padding: 10px 11px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); }
  .lesson-actions button:last-child { margin-left: 0; }
  .lesson-actions button b { max-width: none; overflow: hidden; display: -webkit-box; white-space: normal; line-height: 1.35; -webkit-box-orient: vertical; -webkit-line-clamp: 2; }
  .lesson-notes { margin-top: 28px; margin-bottom: 48px; }
  .tabs { height: 52px; gap: 24px; overflow-x: auto; overscroll-behavior-x: contain; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
  .tab { flex: 0 0 auto; min-height: 44px; white-space: nowrap; }
  .tab-panel { min-height: 140px; padding: 22px 0; }
  .tab-panel p { font-size: 13px; line-height: 1.8; }
  .resource-grid a { min-height: 64px; }
  footer { margin-top: 56px; padding-bottom: calc(24px + env(safe-area-inset-bottom)); }
}

@media (max-width: 390px) {
  .lesson-actions { grid-template-columns: 1fr; }
  .lesson-actions button:last-child { grid-template-columns: auto 1fr; text-align: left; }
  .lesson-actions button:last-child > span { grid-column: 1; grid-row: 1 / 3; }
}

@media (prefers-reduced-motion: reduce) { *,*::before,*::after { scroll-behavior: auto!important; transition: none!important; } }
