:root {
  --ink: #18202f;
  --muted: #667085;
  --line: #d7dee8;
  --panel: rgba(255, 255, 255, 0.96);
  --accent: #0f766e;
  --accent-dark: #0a5f59;
  --warm: #f59e0b;
  --shadow: 0 14px 36px rgba(30, 41, 59, 0.1);
  --tight-shadow: 0 8px 22px rgba(30, 41, 59, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: #eef3f9;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button {
  appearance: none;
  border: 0;
  font: inherit;
  cursor: pointer;
}

.app {
  width: min(1500px, calc(100% - 28px));
  margin: 0 auto;
  padding: 18px 0 28px;
}

.library-home {
  width: min(1280px, calc(100% - 28px));
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 18px;
  min-height: 64px;
  margin-bottom: 14px;
}

.library-home .topbar {
  align-items: flex-start;
}

.brand-link {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--accent-dark);
  font-size: 12px;
  font-weight: 850;
  letter-spacing: 0;
  text-decoration: none;
  text-transform: uppercase;
}

.brand-mark {
  width: 30px;
  height: 30px;
  border-radius: 7px;
  box-shadow: 0 6px 14px rgba(15, 118, 110, 0.18);
}

.brand-text {
  line-height: 1.1;
}

.home-summary {
  max-width: 1120px;
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 15px;
  font-weight: 720;
  line-height: 1.65;
  white-space: nowrap;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent-dark);
  font-size: 12px;
  font-weight: 850;
  text-transform: uppercase;
}

.brand-link + h1,
.eyebrow + h1 {
  margin-top: 6px;
}

h1,
h2 {
  margin: 0;
}

h1 {
  font-size: 30px;
  line-height: 1.1;
}

h2 {
  font-size: 18px;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.language-switcher {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.82);
  color: var(--muted);
  padding: 0 8px 0 12px;
  font-size: 12px;
  font-weight: 850;
  white-space: nowrap;
}

.language-switcher select {
  border: 0;
  background: transparent;
  color: var(--ink);
  font: inherit;
  outline: 0;
}

.library-button {
  min-height: 42px;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  padding: 0 15px;
  font-weight: 850;
}

.library-button:hover {
  background: var(--accent-dark);
}

#lesson-meta {
  color: var(--muted);
  max-width: 620px;
  font-size: 14px;
  font-weight: 750;
  text-align: right;
}

.choice,
.vocab-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
}

.course-overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: rgba(15, 23, 42, 0.38);
}

.course-overlay[hidden],
.course-drawer[hidden] {
  display: none;
}

.course-drawer {
  position: fixed;
  top: 0;
  right: 0;
  z-index: 21;
  width: min(440px, 100vw);
  height: 100vh;
  overflow: auto;
  border-left: 1px solid var(--line);
  background: #f8fbfd;
  box-shadow: -18px 0 45px rgba(15, 23, 42, 0.18);
  padding: 18px;
}

.drawer-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 14px;
}

.icon-button {
  width: 38px;
  height: 38px;
  border-radius: 8px;
  background: #e8eef6;
  color: var(--ink);
  font-size: 28px;
  font-weight: 500;
  line-height: 1;
}

.icon-button:hover {
  background: #dce6f2;
}

.lesson-list {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

.home-course-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(310px, 1fr));
  gap: 14px;
  align-items: stretch;
}

.difficulty-filter {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0 0 14px;
}

.difficulty-filter.compact {
  margin-bottom: 14px;
}

.difficulty-chip {
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--ink);
  padding: 0 12px;
  font-weight: 850;
}

.difficulty-chip.active,
.difficulty-chip:hover {
  border-color: var(--accent);
  background: #e7f7f4;
  color: var(--accent-dark);
}

.lesson-card,
.home-course-card {
  min-height: 112px;
  display: grid;
  gap: 7px;
  align-content: start;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 13px;
  text-align: left;
  text-decoration: none;
  box-shadow: inset 0 -1px 0 rgba(30, 41, 59, 0.04);
}

.lesson-card .theme-tags {
  margin-inline: 0;
}

.home-course-card {
  height: 100%;
  min-height: 360px;
  padding: 0;
  padding-bottom: 16px;
  overflow: hidden;
  gap: 9px;
  grid-template-rows: auto auto auto auto 1fr;
}

.lesson-card[hidden],
.home-course-card[hidden],
.empty-state[hidden] {
  display: none !important;
}

.empty-state {
  margin: 12px 0 0;
  color: var(--muted);
  font-weight: 800;
}

.lesson-card:hover,
.home-course-card:hover {
  border-color: #8bc7bf;
  background: #f3fbfa;
}

.lesson-card.active {
  border-color: var(--accent);
  background: #e7f7f4;
  box-shadow: inset 0 0 0 2px rgba(15, 118, 110, 0.18);
}

.lesson-card-title {
  font-size: 17px;
  font-weight: 850;
  line-height: 1.18;
}

.home-course-card .lesson-card-title,
.home-course-card .lesson-card-meta,
.home-course-card .theme-tags,
.home-course-card .course-description {
  margin-inline: 13px;
}

.lesson-card-meta {
  color: var(--muted);
  font-size: 13px;
  font-weight: 750;
  line-height: 1.35;
}

.course-thumb {
  position: relative;
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  background: #dfe7ef;
}

.course-thumb img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}

.course-level {
  position: absolute;
  left: 10px;
  bottom: 10px;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.82);
  color: #fff;
  padding: 5px 9px;
  font-size: 12px;
  font-weight: 850;
}

.theme-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.theme-tag {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border: 1px solid #b9dcd7;
  border-radius: 999px;
  background: #e7f7f4;
  color: var(--accent-dark);
  padding: 2px 8px;
  font-size: 12px;
  font-weight: 850;
  line-height: 1.2;
}

.course-description {
  display: -webkit-box;
  color: #344054;
  font-size: 13px;
  font-weight: 720;
  line-height: 1.48;
  margin-bottom: 2px;
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 4;
}

.pagination {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin: 16px 0 0;
}

.page-button {
  min-width: 38px;
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 0 12px;
  font-weight: 850;
}

.page-button.active,
.page-button:hover:not(:disabled) {
  border-color: var(--accent);
  background: #e7f7f4;
  color: var(--accent-dark);
}

.page-button:disabled {
  cursor: default;
  opacity: 0.48;
}

.pagination-count {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.lesson-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.58fr) minmax(360px, 0.72fr);
  gap: 16px;
  align-items: start;
}

.video-column,
.study-column {
  display: grid;
  gap: 18px;
  align-content: start;
}

.panel,
.video-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--tight-shadow);
  padding: 16px;
}

.video-panel {
  padding: 0;
  overflow: hidden;
  background: #111827;
}

.video-frame iframe,
#youtube-player,
#youtube-player iframe {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
  height: auto;
  min-height: 0;
  border: 0;
}

#youtube-player,
#youtube-player iframe {
  max-width: 100% !important;
}

.video-frame > iframe,
.video-frame iframe[width] {
  width: 100% !important;
  max-width: 100% !important;
  height: auto !important;
}

.player-loading {
  aspect-ratio: 16 / 9;
  display: grid;
  place-items: center;
  color: #f8fafc;
  font-weight: 800;
}

.subtitle-panel {
  border: 1px solid #1c2a3a;
  border-radius: 8px;
  background: #101926;
  color: #f8fafc;
  box-shadow: var(--shadow);
  padding: 18px 20px 20px;
}

.video-summary {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  padding: 12px 14px;
  box-shadow: var(--shadow);
}

.video-summary p {
  margin: 0;
  color: #344054;
  font-size: 14px;
  font-weight: 750;
  line-height: 1.55;
}

.subtitle-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

#subtitle-time {
  font-weight: 900;
  color: #a7f3d0;
}

.subtitle-actions {
  display: flex;
  gap: 8px;
}

.subtitle-actions button {
  min-height: 36px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 8px;
  padding: 0 12px;
  color: #fff;
  background: rgba(255, 255, 255, 0.08);
  font-weight: 800;
}

.big-subtitle {
  min-height: 112px;
  display: grid;
  align-items: center;
  font-size: clamp(24px, 2.25vw, 35px);
  line-height: 1.22;
  font-weight: 850;
}

.subtitle-vocab {
  display: none;
}

.subtitle-vocab span {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  border-radius: 999px;
  padding: 0 11px;
  color: #111827;
  background: #a7f3d0;
  font-weight: 850;
}

.term-pack {
  display: inline-block;
  white-space: nowrap;
}

.inline-term {
  display: inline;
  color: #facc15;
  font-size: 1.1em;
  font-weight: 950;
  line-height: 1;
  text-shadow: 0 2px 16px rgba(250, 204, 21, 0.28);
}

.inline-zh {
  display: inline;
  margin-left: 6px;
  color: #facc15;
  font-size: 0.5em;
  font-weight: 900;
  vertical-align: baseline;
}

.inline-tail {
  display: inline;
  color: #f8fafc;
  font-size: 0.92em;
  font-weight: 850;
}

.section-head {
  margin-bottom: 14px;
}

.summary {
  margin: 0;
  color: #344054;
  line-height: 1.65;
  font-size: 16px;
}

.choice-grid,
.vocab-list {
  display: grid;
  gap: 10px;
}

.vocab-section,
.vocab-list-inner {
  display: grid;
  gap: 10px;
}

.vocab-section-title,
.vocab-accordion summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  color: var(--accent-dark);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.vocab-section-title small,
.vocab-accordion summary small {
  min-width: 24px;
  height: 22px;
  display: inline-grid;
  place-items: center;
  border-radius: 999px;
  background: #e7f7f4;
  color: var(--accent-dark);
  font-size: 12px;
  font-weight: 900;
}

.vocab-accordion {
  display: grid;
  gap: 10px;
  border-top: 1px solid var(--line);
  padding-top: 10px;
}

.vocab-accordion summary {
  cursor: pointer;
  list-style: none;
}

.vocab-accordion summary::-webkit-details-marker {
  display: none;
}

.vocab-accordion summary::after {
  content: "+";
  width: 24px;
  height: 24px;
  display: inline-grid;
  place-items: center;
  border-radius: 999px;
  background: #edf6f5;
  color: var(--accent-dark);
  font-size: 16px;
  line-height: 1;
}

.vocab-accordion[open] summary::after {
  content: "-";
}

.choice {
  min-height: 46px;
  padding: 11px 13px;
  text-align: left;
  line-height: 1.38;
  box-shadow: inset 0 -1px 0 rgba(30, 41, 59, 0.04);
}

.choice:hover,
.vocab-card:hover {
  border-color: #8bc7bf;
  background: #f3fbfa;
}

.choice.selected,
.vocab-card.selected {
  border-color: var(--accent);
  background: #e7f7f4;
  box-shadow: inset 0 0 0 2px rgba(15, 118, 110, 0.18);
}

.vocab-card.active-word {
  border-color: #f59e0b;
  background: #fff7ed;
  box-shadow: inset 0 0 0 2px rgba(245, 158, 11, 0.22);
}

.vocab-card {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 3px 9px;
  padding: 8px 11px;
  text-align: left;
}

.vocab-main {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  flex-wrap: wrap;
}

.vocab-card strong {
  font-size: 16px;
  line-height: 1.1;
}

.vocab-card span {
  align-self: start;
  color: var(--ink);
  font-weight: 800;
}

.vocab-card small {
  grid-column: 1 / -1;
  color: var(--muted);
  line-height: 1.22;
  font-size: 12px;
}

.vocab-meta {
  color: var(--accent-dark);
  font-size: 12px;
  font-weight: 850;
  white-space: nowrap;
}

.sound-button {
  width: 24px;
  height: 24px;
  display: inline-grid;
  place-items: center;
  border-radius: 999px;
  background: #edf6f5;
  color: var(--accent-dark);
}

.sound-button:hover {
  background: #d5f0ec;
}

.sound-button svg {
  width: 15px;
  height: 15px;
  fill: currentColor;
}

.sound-button svg path:nth-child(n + 2) {
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
}

.study-column {
  position: sticky;
  top: 16px;
  max-height: calc(100vh - 32px);
  overflow: auto;
  padding-right: 2px;
}

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  transform: translateY(20px);
  opacity: 0;
  pointer-events: none;
  background: #111827;
  color: #fff;
  border-radius: 8px;
  padding: 12px 14px;
  box-shadow: var(--shadow);
  transition: 0.2s ease;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

@media (max-width: 980px) {
  .home-summary {
    white-space: normal;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .top-actions {
    justify-content: flex-start;
  }

  .lesson-grid {
    grid-template-columns: 1fr;
  }

  .study-column {
    position: static;
    max-height: min(46vh, 420px);
    overflow: auto;
    overscroll-behavior: contain;
  }

  .big-subtitle {
    font-size: 26px;
    min-height: 96px;
  }
}

@media (max-width: 560px) {
  .app {
    width: min(100% - 20px, 1480px);
    padding: 14px 0;
  }

  h1 {
    font-size: 26px;
  }

  .panel {
    padding: 14px;
  }

  .subtitle-panel {
    padding: 14px;
  }

  .subtitle-top {
    align-items: flex-start;
    flex-direction: column;
  }

  .big-subtitle {
    font-size: 22px;
  }
}
