/* Navigation layout only; lesson, audio and typing controllers stay intact.
   Three clear groups: the brand, one segmented trainer navigation, and a
   tools cluster (language, repeat, settings, theme, home). The lesson title
   gets its own line below. */
header.topbar {
  display: grid; grid-template-columns: auto minmax(0, 1fr) auto;
  grid-template-areas: "brand nav tools" "title title title";
  height: auto; min-height: 68px; padding: 10px 24px; gap: 8px 20px;
  align-items: center;
}
header.topbar .brand-logo { grid-area: brand; margin: 0; min-height: 44px; }
header.topbar .topbar-nav { grid-area: nav; justify-self: start; }
header.topbar .topbar-right { grid-area: tools; }
header.topbar .topbar-center { grid-area: title; }
header.topbar :is(button,a,summary):focus-visible { outline: 3px solid #ffdf66; outline-offset: 3px; }

/* Trainer navigation: one segmented control, the active section is white */
header.topbar .topbar-nav {
  display: inline-flex; align-items: center; gap: 2px; padding: 4px;
  max-width: 100%; overflow-x: auto; border-radius: 999px;
  background: rgba(4, 28, 56, 0.24); scrollbar-width: none;
}
header.topbar .topbar-nav::-webkit-scrollbar { display: none; }
header.topbar .topbar-nav .nav-btn {
  box-sizing: border-box; min-height: 38px; padding: 8px 18px;
  border: 1px solid transparent; border-radius: 999px;
  background: transparent; color: #fff; font: inherit; font-size: .9rem;
  font-weight: 600; line-height: 1.3; letter-spacing: .01em; white-space: nowrap;
  text-decoration: none; display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer; transition: background-color .16s, color .16s;
}
header.topbar .topbar-nav .nav-btn:hover { background: rgba(255, 255, 255, 0.16); }
header.topbar .topbar-nav .nav-btn.active { background: #fff; color: #17466b; }

/* Tools cluster: quiet outlined buttons of one height */
header.topbar .topbar-right { display: flex; align-items: center; justify-content: flex-end; gap: 8px; min-width: 0; flex-wrap: wrap; }
header.topbar .topbar-right :is(.nav-btn, .lang-dropdown-btn, .toolbar-settings > summary) {
  box-sizing: border-box; min-height: 40px; padding: 8px 14px;
  border: 1px solid rgba(255, 255, 255, 0.5); border-radius: 10px;
  background: rgba(255, 255, 255, 0.06); color: #fff; font: inherit; font-size: .875rem;
  font-weight: 600; line-height: 1.3; text-decoration: none; white-space: nowrap;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  cursor: pointer; transition: background-color .16s, border-color .16s;
}
header.topbar .topbar-right :is(.nav-btn, .lang-dropdown-btn, .toolbar-settings > summary):hover { background: rgba(255, 255, 255, 0.18); border-color: rgba(255, 255, 255, 0.85); }
header.topbar .topbar-right .nav-btn[aria-pressed='true'] { background: #fff; color: #17466b; border-color: #fff; }
header.topbar .theme-toggle { width: 40px; min-width: 40px; padding: 8px; flex-shrink: 0; }
header.topbar .theme-icon-sun { display: none; }
html[data-theme='dark'] header.topbar .theme-icon-moon { display: none; }
html[data-theme='dark'] header.topbar .theme-icon-sun { display: block; }
header.topbar .toolbar-sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

/* Lesson title line, only while a lesson is open */
header.topbar .topbar-center { font-weight: 600; font-size: .95rem; letter-spacing: .01em; opacity: .95; }
header.topbar .topbar-center:empty { display: none; }

/* Settings menu */
header.topbar .toolbar-settings { position: relative; }
header.topbar .toolbar-settings > summary { list-style: none; }
header.topbar .toolbar-settings > summary::-webkit-details-marker { display: none; }
header.topbar .toolbar-settings-panel {
  position: absolute; right: 0; top: calc(100% + 10px); z-index: 300;
  width: 260px; max-width: calc(100vw - 32px); padding: 8px;
  display: grid; gap: 6px; background: var(--bg-secondary);
  border: 1px solid var(--border-color); border-radius: 14px;
  box-shadow: 0 12px 32px #071b3b33;
}
header.topbar .toolbar-settings:not([open]) .toolbar-settings-panel { display: none; }
header.topbar .toolbar-settings-panel .nav-btn {
  width: 100%; justify-content: flex-start; min-height: 40px; padding: 8px 12px;
  border: 1px solid transparent; border-radius: 10px; background: transparent; color: var(--text-primary);
  font: inherit; font-size: .875rem; font-weight: 600; display: inline-flex; align-items: center; gap: 8px; cursor: pointer;
}
header.topbar .toolbar-settings-panel .nav-btn:hover { background: var(--accent-blue-light); color: var(--accent-blue); }
header.topbar .toolbar-settings-panel [aria-pressed='true']::after { content: '✓'; margin-left: auto; }

/* Two lines: brand and tools first, the navigation below */
@media (max-width: 1240px) {
  header.topbar { grid-template-columns: auto minmax(0, 1fr); grid-template-areas: "brand tools" "nav nav" "title title"; gap: 10px 16px; }
  header.topbar .topbar-nav { width: 100%; justify-content: flex-start; box-sizing: border-box; }
  header.topbar .topbar-nav .nav-btn { flex: 1 1 auto; }
}
@media (max-width: 700px) {
  header.topbar { grid-template-columns: minmax(0, 1fr); grid-template-areas: "brand" "nav" "tools" "title"; padding: 10px 12px; position: relative; }
  header.topbar .topbar-nav { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); border-radius: 16px; overflow: visible; }
  header.topbar .topbar-nav .nav-btn { white-space: normal; border-radius: 12px; }
  header.topbar .topbar-right { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 40px; }
  header.topbar .lang-dropdown-wrap { grid-column: 1 / -1; }
  header.topbar :is(.lang-dropdown-btn, .toolbar-settings > summary) { width: 100%; }
  header.topbar .home-link { grid-column: 1 / -1; }
  header.topbar .lang-menu { left: 0; right: auto; max-width: 100%; }
  header.topbar .topbar-right .nav-btn { white-space: normal; }
}
@media (prefers-reduced-motion: reduce) {
  header.topbar :is(.nav-btn, .lang-dropdown-btn, summary) { transition: none; }
}
