.reader-topbar {
  position: relative;
  width: 100%;
  min-height: var(--reader-topbar-h);
  z-index: 10030;
  background: rgba(255, 255, 255, 0.92);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid rgba(215, 211, 255, 0.55);
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.08);
  padding: env(safe-area-inset-top, 0px) 10px 0;
  box-sizing: border-box;
  display: flex;
  align-items: center;
  overflow: visible;
  flex-shrink: 0;
}

.reader-topbar-row {
  width: 100%;
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr) max-content;
  align-items: center;
  gap: 8px;
  overflow: visible;
}

.reader-brand {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 6px;
}

.reader-logo {
  height: 40px;
  width: auto;
}

.reader-logo-lg { display: block; }
.reader-logo-sm { display: none; }
.reader-logo-lang { display: none; }

@media (max-width: 520px) {
  .reader-logo-lg { display: none; }
  .reader-logo-sm { display: block; }

  .reader-brand.is-lang-mode .reader-logo-sm { display: none; }
  .reader-brand.is-lang-mode .reader-logo-lang { display: block; }
}

.reader-logo-text {
  display: none;
  font-family: 'Nunito', system-ui, sans-serif;
  font-weight: 900;
  font-size: 20px;
  color: var(--brand-purple);
  letter-spacing: -0.5px;
}

.reader-logo-text span {
  color: #ff5c8a;
}

/* Actions pill container */
.reader-actions {
  grid-column: 3;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  justify-self: end;
  padding: 2px 4px;
  border-radius: 18px;
  background: rgba(245, 246, 255, 0.65);
  border: 1px solid rgba(215, 211, 255, 0.45);
  box-sizing: border-box;
  overflow: visible;
}

/* Base topbar button (play/sound/menu) */
.reader-topbar-btn {
  width: 44px;
  height: 44px;
  padding: 0;
  margin: 0;
  border: 0;
  cursor: pointer;
  background: transparent;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--ink);
  transition: transform 120ms ease, filter 120ms ease, opacity 160ms ease;
}

.reader-topbar-btn:hover {
  transform: translateY(-1px);
  filter: brightness(1.02);
}

.reader-topbar-btn:active {
  transform: translateY(0) scale(0.96);
}

.reader-topbar-btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgba(122, 114, 242, 0.22);
}

.reader-topbar-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.topbar-ico {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  pointer-events: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-user-drag: none;
}

/* Wraps for dropdowns */
.pause-wrap,
.sound-wrap,
.lang-switch-wrap {
  position: relative;
  display: inline-flex;
  align-items: center;
  flex: 0 0 auto;
}

/* Language button (special styling — white bordered pill) */
.reader-topbar-btn-lang {
  position: relative;
  width: auto;
  min-width: 48px;
  height: 38px;
  padding: 0 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.98), rgba(248, 246, 255, 0.96));
  border: 2px solid rgba(143, 136, 255, 0.9);
  box-shadow:
    0 0 0 3px rgba(155, 149, 255, 0.18),
    0 8px 18px rgba(20, 35, 90, 0.08),
    0 0 0 2px rgba(255, 255, 255, 0.72) inset;
  cursor: pointer;
  transition: transform 120ms ease, filter 120ms ease, box-shadow 140ms ease, border-color 140ms ease;
}

.reader-topbar-btn-lang:hover {
  transform: translateY(-1px);
  filter: brightness(1.015);
}

.reader-topbar-btn-lang:active {
  transform: scale(0.975);
}

.reader-topbar-btn-lang[aria-expanded="true"] {
  border-color: rgba(143, 136, 255, 1);
  box-shadow:
    0 0 0 3px rgba(155, 149, 255, 0.22),
    0 10px 20px rgba(122, 114, 242, 0.14),
    0 0 0 2px rgba(255, 255, 255, 0.76) inset;
}

.lang-switch-inner {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
}

.lang-switch-flag-slot {
  width: 24px;
  height: 24px;
  flex: 0 0 24px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.lang-switch-flag-slot img {
  width: 24px;
  height: 24px;
  display: block;
  object-fit: cover;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.98);
  box-shadow:
    0 6px 14px rgba(20, 35, 90, 0.12),
    0 0 0 2px rgba(255, 255, 255, 0.92);
}

.lang-switch-caret {
  font-size: 12px;
  color: rgba(109, 40, 217, 0.75);
  font-weight: 900;
  line-height: 1;
}

/* Pause + Sound menu (dropdowns) — matches reader card style */
.pause-menu,
.sound-menu {
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  width: 360px;
  max-width: calc(100vw - 24px);
  box-sizing: border-box;
  padding: 14px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.9);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(215, 211, 255, 0.75);
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.28);
  z-index: 10040;
  display: none;
  flex-direction: column;
  gap: 10px;
  transform-origin: top right;
}

.sound-menu { width: 320px; }

.pause-menu.open,
.sound-menu.open {
  display: flex;
  animation: pausePopIn 140ms ease-out;
}

@keyframes pausePopIn {
  from { opacity: 0; transform: scale(0.96) translateY(-4px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

.pause-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.pause-title {
  width: 100%;
  margin: 0;
  font-family: 'Nunito', sans-serif;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.01em;
  line-height: 1.15;
  color: rgba(31, 42, 68, 0.94);
}

.pause-accent {
  height: 5px;
  width: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, rgba(155, 149, 255, 0.88), rgba(122, 114, 242, 0.92));
  box-shadow: 0 10px 18px rgba(147, 98, 232, 0.16);
}

.pause-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.pause-btn {
  width: 100%;
  min-height: 68px;
  border: 1px solid rgba(215, 211, 255, 0.9);
  border-radius: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 14px;
  padding: 12px 14px;
  text-align: left;
  font-family: 'Nunito', sans-serif;
  transition: transform 120ms ease, box-shadow 180ms ease, border-color 180ms ease, background 180ms ease, opacity 140ms ease;
}

.pause-btn > * + * { margin-left: 14px; }

@supports (gap: 1px) {
  .pause-btn > * + * { margin-left: 0; }
}

.pause-btn:hover { transform: translateY(-1px); }
.pause-btn:active { transform: scale(0.985); opacity: 0.98; }

.pause-ico {
  width: 28px;
  height: 28px;
  flex: 0 0 28px;
  display: block;
  pointer-events: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-user-drag: none;
}

.pause-text-wrap {
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 3px;
  flex: 1 1 auto;
}

.pause-text-wrap > * + * { margin-top: 3px; }

@supports (gap: 1px) {
  .pause-text-wrap > * + * { margin-top: 0; }
}

.pause-text {
  font-size: 15px;
  font-weight: 700;
  line-height: 1.12;
  color: rgba(31, 42, 68, 0.94);
}

.pause-subtext {
  font-size: 12px;
  line-height: 1.25;
  color: rgba(31, 42, 68, 0.56);
  font-weight: 500;
}

.pause-btn-share {
  background: rgba(248, 244, 255, 0.94);
  border-color: rgba(226, 214, 255, 0.95);
  box-shadow: 0 10px 22px rgba(20, 35, 90, 0.08), 0 0 0 2px rgba(255, 255, 255, 0.68) inset;
}
.pause-btn-share:hover {
  background: rgba(251, 248, 255, 0.98);
  border-color: rgba(205, 188, 255, 0.96);
  box-shadow: 0 14px 26px rgba(20, 35, 90, 0.1), 0 0 0 2px rgba(255, 255, 255, 0.72) inset;
}
.pause-btn-share .pause-ico { filter: drop-shadow(0 6px 12px rgba(255, 56, 96, 0.14)); }

.pause-btn-soft {
  background: rgba(242, 240, 255, 0.94);
  border-color: rgba(215, 211, 255, 0.92);
  box-shadow: 0 10px 22px rgba(20, 35, 90, 0.08), 0 0 0 2px rgba(255, 255, 255, 0.68) inset;
}
.pause-btn-soft .pause-ico { filter: drop-shadow(0 6px 12px rgba(122, 114, 242, 0.14)); }

.pause-btn-danger {
  background: rgba(249, 244, 246, 0.94);
  border-color: rgba(232, 218, 223, 0.95);
  box-shadow: 0 10px 22px rgba(20, 35, 90, 0.08), 0 0 0 2px rgba(255, 255, 255, 0.68) inset;
}
.pause-btn-danger .pause-ico { filter: drop-shadow(0 6px 12px rgba(214, 67, 67, 0.12)); }

/* Language menu (fedu-style card) */
.lang-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: 320px;
  padding: 14px;
  border-radius: 22px;
  background:
    radial-gradient(circle at top left, rgba(244, 241, 255, 0.96), rgba(255, 255, 255, 0.97) 38%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.98), rgba(252, 252, 255, 0.97));
  border: 1px solid rgba(215, 211, 255, 0.88);
  box-shadow:
    0 24px 60px rgba(20, 35, 90, 0.18),
    0 10px 24px rgba(20, 35, 90, 0.08);
  z-index: 10040;
  display: none;
  flex-direction: column;
  gap: 12px;
}

.lang-menu.open {
  display: flex;
}

.lang-menu-head {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
}

.lang-menu-title {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: rgba(31, 42, 68, 0.94);
  line-height: 1.15;
}

.lang-menu-accent {
  height: 5px;
  width: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, rgba(155, 149, 255, 0.88), rgba(122, 114, 242, 0.92));
  box-shadow: 0 10px 18px rgba(147, 98, 232, 0.16);
}

.lang-menu-sub {
  font-size: 12.5px;
  line-height: 1.35;
  color: rgba(31, 42, 68, 0.62);
}

.lang-menu-options {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.lang-option {
  width: 100%;
  min-height: 68px;
  border: 1px solid rgba(215, 211, 255, 0.9);
  border-radius: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 14px;
  padding: 12px 14px;
  text-align: left;
  background: rgba(242, 240, 255, 0.9);
  color: rgba(122, 114, 242, 0.98);
  box-shadow:
    0 10px 22px rgba(20, 35, 90, 0.08),
    0 0 0 2px rgba(255, 255, 255, 0.65) inset;
  transition: transform 120ms ease, box-shadow 180ms ease, border-color 180ms ease, background 180ms ease;
}

.lang-option:hover {
  transform: translateY(-1px);
}

.lang-option:active {
  transform: scale(0.985);
}

.lang-option.is-current {
  background:
    radial-gradient(circle at top left, rgba(245, 240, 255, 0.98), rgba(255, 255, 255, 0.98) 42%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.98), rgba(250, 247, 255, 0.97));
  border-color: rgba(155, 149, 255, 0.95);
  box-shadow:
    0 14px 28px rgba(122, 114, 242, 0.1),
    0 0 0 2px rgba(255, 255, 255, 0.72) inset;
}

.lang-option-flag {
  width: 34px;
  height: 34px;
  flex: 0 0 34px;
  display: block;
  object-fit: cover;
  border-radius: 999px;
  box-shadow:
    0 8px 18px rgba(20, 35, 90, 0.1),
    0 0 0 2px rgba(255, 255, 255, 0.88);
}

.lang-option-copy {
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 3px;
  flex: 1 1 auto;
}

.lang-option-title {
  font-size: 15px;
  font-weight: 700;
  line-height: 1.12;
  color: rgba(64, 58, 130, 0.98);
}

.lang-option-sub {
  font-size: 12px;
  line-height: 1.25;
  color: rgba(31, 42, 68, 0.56);
}

.lang-option-check {
  width: 18px;
  height: 18px;
  flex: 0 0 18px;
  border-radius: 999px;
  background: rgba(122, 114, 242, 0.96);
  box-shadow: 0 0 0 3px rgba(122, 114, 242, 0.12);
}

.menu-header {
  padding: 8px 12px 6px;
  font-family: 'Nunito', sans-serif;
  font-weight: 800;
  font-size: 14px;
  color: var(--ink);
}

.menu-header-sub {
  font-weight: 600;
  font-size: 12px;
  color: var(--ink-muted);
  margin-top: 2px;
}

.menu-divider {
  height: 1px;
  background: rgba(215, 211, 255, 0.55);
  margin: 6px 2px;
}

.menu-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 0;
  background: transparent;
  border-radius: 10px;
  cursor: pointer;
  text-align: left;
  color: var(--ink);
  font-family: 'Nunito', sans-serif;
  font-size: 14px;
  transition: background 120ms ease;
}

.menu-item:hover {
  background: rgba(109, 40, 217, 0.06);
}

.menu-item-flag {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  object-fit: cover;
  box-shadow: 0 4px 10px rgba(20, 35, 90, 0.12);
}

.menu-item-title {
  flex: 1;
  font-weight: 700;
}

.menu-item-sub {
  font-size: 12px;
  color: var(--ink-muted);
  font-weight: 500;
}

.menu-item-check {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid rgba(215, 211, 255, 0.8);
  flex-shrink: 0;
}

.menu-item-check.active {
  background: var(--brand-purple);
  border-color: var(--brand-purple);
  position: relative;
}

.menu-item-check.active::after {
  content: '';
  position: absolute;
  left: 4px;
  top: 1px;
  width: 5px;
  height: 9px;
  border: solid white;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

.menu-item-icon {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  color: #fff;
  flex-shrink: 0;
}

.menu-item-icon.share { background: linear-gradient(135deg, #8b5cf6, #6d28d9); }
.menu-item-icon.return { background: linear-gradient(135deg, #38bdf8, #0ea5e9); }
.menu-item-icon.exit { background: linear-gradient(135deg, #f43f5e, #be123c); }

.menu-item-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
}

@media (max-width: 600px) {
  .reader-topbar {
    padding: 0 8px;
  }
  .reader-logo {
    height: 28px;
  }
  .reader-topbar-btn {
    width: 38px;
    height: 38px;
  }
  .reader-topbar-btn-lang {
    min-width: 44px;
    height: 34px;
    padding: 0 6px;
  }
  .lang-switch-flag-slot,
  .lang-switch-flag-slot img {
    width: 20px;
    height: 20px;
    flex-basis: 20px;
  }
  .lang-menu,
  .pause-menu,
  .sound-menu {
    min-width: 200px;
  }
}

/* Mobile: pin dropdowns to viewport (not their anchor button) for reliable placement. */
@media (max-width: 520px) {
  .lang-menu,
  .pause-menu,
  .sound-menu {
    position: fixed;
    top: calc(var(--reader-topbar-h) + 10px);
    right: 8px;
    left: auto;
    max-width: none;
    transform: none;
    width: min(320px, calc(100vw - 16px));
  }
}

/* ============ Sound menu — volume slider ============ */
.sound-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.volume-title {
  font-family: 'Nunito', system-ui, sans-serif;
  font-weight: 800;
  font-size: 14px;
  color: rgba(31, 42, 68, 0.85);
  padding: 0 4px;
}

.vol-track {
  position: relative;
  width: 100%;
  height: 46px;
  display: flex;
  align-items: center;
  --pad-l: 16px;
  --pad-r: 16px;
  padding-left: var(--pad-l);
  padding-right: var(--pad-r);
  box-sizing: border-box;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.55);
  border: 2px solid rgba(255, 255, 255, 1);
  box-shadow: 0 14px 28px rgba(0, 0, 0, 0.1), 0 0 0 2px rgba(255, 255, 255, 0.4) inset;
  --fill: 100;
}

.vol-track::before {
  content: "";
  position: absolute;
  left: var(--pad-l);
  right: var(--pad-r);
  top: 50%;
  transform: translateY(-50%);
  height: 12px;
  border-radius: 999px;
  width: calc((100% - (var(--pad-l) + var(--pad-r))) * (var(--fill) / 100));
  background: linear-gradient(90deg,
    rgba(120, 200, 255, 0.8),
    rgba(155, 149, 255, 0.88),
    rgba(122, 114, 242, 0.92),
    rgba(101, 92, 255, 0.92),
    rgba(255, 170, 210, 0.65));
  box-shadow: 0 10px 18px rgba(147, 98, 232, 0.14), 0 0 18px rgba(147, 98, 232, 0.1);
  pointer-events: none;
}

.vol-slider {
  width: 100%;
  min-width: 0;
  max-width: 100%;
  height: 30px;
  background: transparent;
  -webkit-appearance: none;
  appearance: none;
  outline: none;
  padding: 0;
  margin: 0;
}

.vol-slider::-webkit-slider-runnable-track {
  height: 12px;
  border-radius: 999px;
  background: rgba(120, 120, 160, 0.14);
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.65) inset;
}

.vol-slider::-moz-range-track {
  height: 12px;
  border-radius: 999px;
  background: rgba(120, 120, 160, 0.14);
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.65) inset;
}

.vol-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 28px;
  height: 28px;
  margin-top: -8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.98);
  border: 2px solid rgba(255, 255, 255, 0.78);
  box-shadow:
    0 14px 24px rgba(0, 0, 0, 0.16),
    0 0 0 4px rgba(255, 255, 255, 0.55) inset,
    0 0 18px rgba(122, 114, 242, 0.22);
  cursor: pointer;
  position: relative;
  z-index: 3;
  transition: transform 120ms ease, box-shadow 120ms ease;
}

.vol-slider::-moz-range-thumb {
  width: 28px;
  height: 28px;
  border: 2px solid rgba(255, 255, 255, 0.78);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.98);
  box-shadow:
    0 14px 24px rgba(0, 0, 0, 0.16),
    0 0 0 4px rgba(255, 255, 255, 0.55) inset,
    0 0 18px rgba(122, 114, 242, 0.22);
  cursor: pointer;
  transition: transform 120ms ease, box-shadow 120ms ease;
}

.vol-slider:active::-webkit-slider-thumb { transform: scale(1.06); }
.vol-slider:active::-moz-range-thumb { transform: scale(1.06); }
