/* Course categories stay across the top and primary navigation stays across the bottom. */
.app-shell {
  padding: 0 0 calc(96px + env(safe-area-inset-bottom)) !important;
}

.page {
  padding-bottom: 38px;
}

.library-layout {
  grid-template-columns: minmax(0, 1fr) !important;
  align-items: stretch !important;
}

.course-sidebar {
  position: static !important;
  top: auto !important;
  width: 100%;
}

.course-group-list {
  display: grid !important;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  overflow: visible !important;
}

.course-group {
  width: 100% !important;
  min-width: 0;
  justify-content: space-between;
}

.tabbar {
  top: auto !important;
  left: 50% !important;
  right: auto !important;
  bottom: calc(10px + env(safe-area-inset-bottom)) !important;
  width: min(calc(100% - 20px), 720px) !important;
  grid-template-columns: repeat(5, minmax(0, 1fr)) !important;
  align-content: normal !important;
  gap: 2px !important;
  transform: translateX(-50%);
}

.tab {
  padding: 7px 2px !important;
}

.toast {
  bottom: calc(100px + env(safe-area-inset-bottom)) !important;
}

.update-banner {
  left: 16px !important;
  right: 16px !important;
}

@media (min-width: 720px) {
  .topbar {
    padding-left: 28px;
  }

  .page {
    padding: 30px 28px 52px;
  }

  .course-sidebar {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    align-items: center;
    column-gap: 18px;
    row-gap: 12px;
    padding: 16px 18px;
  }

  .course-sidebar h3 {
    margin: 0;
    white-space: nowrap;
  }

  .oxford-levels {
    grid-column: 1 / -1;
    margin-top: 0;
  }
}

@media (max-width: 560px) {
  .course-sidebar {
    padding: 12px;
  }

  .course-sidebar h3 {
    margin-bottom: 9px;
  }

  .course-group-list {
    gap: 6px;
  }

  .course-group {
    gap: 5px;
    padding: 9px 8px;
    font-size: 13px;
  }

  .course-group strong {
    min-width: 21px;
    padding: 0 4px;
  }
}

/* Song lesson v5: the Ball Song-style parent flow contains timing, lyrics, and games. */
.song-class-flow {
  display: grid;
  gap: 16px;
}

.song-class-flow > .content-feature-heading {
  margin-bottom: 0;
}

.song-class-flow > .timeline {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fafbff;
}

.song-parent-copy {
  padding: 16px;
  border: 1px solid #dcdff4;
  border-radius: 14px;
  background: linear-gradient(145deg, #f8f9ff, #fff);
}

.song-parent-copy p {
  margin: 0;
  color: var(--ink);
}

.song-flow-submodules {
  display: grid;
  gap: 12px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.song-flow-submodule {
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 14px;
}

.song-flow-submodule h3 {
  margin: 0 0 10px;
  font-size: 16px;
}

.song-flow-editor {
  display: grid;
  gap: 9px;
  margin: 0;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 16px;
}

.song-flow-editor legend {
  padding: 0 7px;
  color: var(--primary-dark);
  font-weight: 850;
}

.song-flow-editor textarea {
  min-height: 132px;
  margin-bottom: 8px;
}

.editable-section-title {
  width: fit-content;
  max-width: 100%;
  border-radius: 7px;
  cursor: text;
  text-decoration: underline dotted rgba(73, 84, 214, 0.42);
  text-underline-offset: 5px;
  transition: background-color 0.18s ease, box-shadow 0.18s ease;
}

.editable-section-title:hover,
.editable-section-title:focus-visible {
  background: #f1f3ff;
  outline: none;
  box-shadow: 0 0 0 5px #f1f3ff;
}

.editable-section-title.is-editing {
  min-width: 8rem;
  padding: 4px 7px;
  background: #fff;
  box-shadow: 0 0 0 2px var(--primary);
  text-decoration: none;
}

/* Selection learning helper: pronunciation, Chinese translation, IPA and meanings. */
.selection-helper {
  position: fixed;
  z-index: 1200;
  width: min(420px, calc(100vw - 24px));
  max-height: min(70vh, 560px);
  overflow: auto;
  padding: 17px;
  border: 1px solid #d9def5;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.98);
  box-shadow: 0 20px 55px rgba(31, 42, 103, 0.23);
  color: var(--ink);
  overscroll-behavior: contain;
}

.selection-helper[hidden] {
  display: none;
}

.selection-helper-head,
.selection-helper-actions,
.selection-helper-meta,
.selection-meaning h4 {
  display: flex;
  align-items: center;
}

.selection-helper-head {
  justify-content: space-between;
  gap: 14px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.selection-helper-kicker {
  display: block;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.06em;
}

.selection-helper-head h3 {
  margin: 0;
  overflow-wrap: anywhere;
  font-size: 22px;
  line-height: 1.25;
}

.selection-helper-actions {
  flex: 0 0 auto;
  gap: 7px;
}

.selection-helper-actions button {
  display: grid;
  width: 36px;
  height: 36px;
  padding: 0;
  place-items: center;
  border: 1px solid #dbe0f7;
  border-radius: 11px;
  background: #f4f6ff;
  color: var(--primary-dark);
  font: inherit;
  font-size: 18px;
  cursor: pointer;
}

.selection-helper-actions button:hover,
.selection-helper-actions button:focus-visible {
  border-color: var(--primary);
  outline: none;
  background: #eaedff;
}

.selection-helper-meta {
  flex-wrap: wrap;
  gap: 8px;
  margin: 13px 0;
}

.selection-kind,
.selection-phonetic {
  padding: 4px 9px;
  border-radius: 999px;
  background: #eef1ff;
  color: var(--primary-dark);
  font-size: 13px;
  font-weight: 750;
}

.selection-phonetic {
  background: #f3f4f8;
  color: #3d4667;
  font-family: Georgia, "Times New Roman", serif;
  font-weight: 600;
}

.selection-translation {
  display: grid;
  gap: 5px;
  padding: 13px 14px;
  border-radius: 13px;
  background: linear-gradient(135deg, #eef1ff, #f8f9ff);
}

.selection-translation span,
.selection-alternatives strong {
  color: var(--muted);
  font-size: 12px;
}

.selection-translation strong {
  font-size: 18px;
  line-height: 1.5;
}

.selection-alternatives {
  margin-top: 12px;
}

.selection-alternatives p {
  margin: 4px 0 0;
  line-height: 1.55;
}

.selection-meanings {
  margin-top: 15px;
  padding-top: 13px;
  border-top: 1px solid var(--line);
}

.selection-meanings > h4 {
  margin: 0 0 9px;
  font-size: 14px;
}

.selection-meaning + .selection-meaning {
  margin-top: 12px;
}

.selection-meaning h4 {
  gap: 7px;
  margin: 0 0 5px;
  color: var(--primary-dark);
  font-size: 14px;
}

.selection-meaning h4 span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.selection-meaning ol {
  margin: 0;
  padding-left: 21px;
}

.selection-meaning li + li {
  margin-top: 7px;
}

.selection-meaning p {
  margin: 0;
  line-height: 1.45;
}

.selection-meaning small {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  line-height: 1.4;
}

.selection-helper-tip,
.selection-helper-error {
  margin: 13px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.selection-helper-error {
  padding: 11px 12px;
  border-radius: 11px;
  background: #fff6e8;
  color: #7e5618;
  font-size: 13px;
}

.selection-helper-loading {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 72px;
  color: var(--muted);
}

.selection-helper-loading span {
  width: 22px;
  height: 22px;
  border: 3px solid #dfe3fa;
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: selection-helper-spin 0.75s linear infinite;
}

@keyframes selection-helper-spin {
  to { transform: rotate(360deg); }
}

@media (max-width: 640px) {
  .selection-helper {
    right: 10px;
    bottom: calc(76px + env(safe-area-inset-bottom));
    left: 10px !important;
    top: auto !important;
    width: auto;
    max-height: 56vh;
    border-radius: 20px;
  }
}
