:root {
  --reader-topbar-pad-x: 12px;
  --reader-topbar-pad-y: 6px;
  --topbar-height: 52px;
  --logo-h: 40px;
  --topbar-pad: 12px;

  --reader-ink: #25304a;
  --reader-surface: rgba(255, 255, 255, 0.96);
  --reader-line: rgba(214, 210, 245, 0.85);
  --reader-shadow-soft: 0 6px 18px rgba(35, 34, 84, 0.08);
}

@media (pointer: fine) and (min-width: 901px) {
  :root {
    --logo-h: 42px;
  }
}

@media (max-width: 520px) {
  :root {
    --logo-h: 28px;
    --topbar-pad: 8px;
  }
}

/* Topbar */
.reader-topbar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 10030;
  height: var(--topbar-height);
}

.reader-topbar-row {
  height: var(--topbar-height);
  width: 100%;
  min-width: 0;
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr) max-content;
  align-items: center;
  padding: 0;
  background: rgba(255, 255, 255, 0.92);
  border-bottom: 1px solid rgba(215, 211, 255, 0.55);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.12);
  overflow: visible;
  pointer-events: auto;
}

.reader-topbar-row-2,
.reader-title {
  display: none !important;
}

/* Logo */
.reader-brand {
  display: inline-flex;
  align-items: center;
  justify-self: start;
  min-width: max-content;
  padding-left: var(--topbar-pad);
}

.reader-logo {
  height: var(--logo-h);
  width: auto;
  display: block;
  object-fit: contain;
  user-select: none;
  -webkit-user-select: none;
  -webkit-user-drag: none;
}

.reader-logo-lg {
  display: block !important;
}

.reader-logo-sm {
  display: none !important;
}

.reader-logo-lang {
  display: none !important;
}

@media (max-width: 520px) {
  .reader-logo-lg {
    display: none !important;
  }

  .reader-logo-sm {
    display: block !important;
  }

  .reader-brand.is-lang-mode .reader-logo-lg {
    display: none !important;
  }

  .reader-brand.is-lang-mode .reader-logo-sm {
    display: none !important;
  }

  .reader-brand.is-lang-mode .reader-logo-lang {
    display: block !important;
  }

  .reader-brand.is-lang-mode .reader-logo-lang {
    height: var(--logo-h);
    width: auto;
  }
}

/* Actions group */
.reader-actions {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  justify-self: end;
  min-width: 0;
  max-width: 100%;
  flex-wrap: nowrap;
  overflow: visible;
  padding: 2px 4px;
  margin-right: var(--topbar-pad);
  border-radius: 18px;
  background: rgba(245, 246, 255, 0.65);
  border: 1px solid rgba(215, 211, 255, 0.45);
  box-sizing: border-box;
}

.reader-actions.has-lang-switch {
  gap: 6px;
}

/* Base buttons */
.reader-topbar-btn {
  width: 44px;
  height: 44px;
  padding: 0;
  margin: 0;
  border: 0;
  cursor: pointer;
  background: transparent !important;
  box-shadow: none !important;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition:
    transform 120ms ease,
    box-shadow 120ms ease,
    opacity 120ms ease,
    filter 120ms ease;
}

.reader-topbar-btn:hover {
  transform: translateY(-1px);
  filter: brightness(1.02);
}

.reader-topbar-btn:active {
  transform: translateY(0) scale(0.96);
  box-shadow: none;
}

.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;
  transform: none !important;
}

.topbar-ico {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  pointer-events: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-user-drag: none;
}

/* Wraps */
.pause-wrap,
.sound-wrap,
.lang-switch-wrap {
  position: relative;
  display: inline-flex;
  align-items: center;
  flex: 0 0 auto;
  z-index: 1110;
}

.sound-wrap,
.pause-wrap,
.lang-switch-wrap,
.reader-topbar-btn {
  flex: 0 0 auto;
}

.reader-topbar,
.reader-topbar-row,
.reader-actions,
.pause-wrap,
.sound-wrap,
.lang-switch-wrap {
  overflow: visible;
}

/* Language switch */
.lang-switch-wrap.hidden {
  display: none !important;
}

.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)
  ) !important;
  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;
  transition:
    transform 120ms ease,
    filter 120ms ease,
    box-shadow 140ms ease,
    border-color 140ms ease,
    background 140ms ease,
    opacity 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:focus-visible {
  outline: none;
  box-shadow:
    0 0 0 3px rgba(122, 114, 242, 0.22),
    0 8px 18px rgba(20, 35, 90, 0.08),
    0 0 0 2px rgba(255, 255, 255, 0.66) inset;
}

.reader-topbar-btn-lang[aria-expanded="true"] {
  background: linear-gradient(
    180deg,
    rgba(255, 255, 255, 0.99),
    rgba(244, 241, 255, 0.98)
  ) !important;
  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 {
  min-width: 0;
  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:empty {
  width: 0;
  height: 0;
  flex-basis: 0;
  overflow: hidden;
}

.lang-switch-flag {
  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 {
  width: 14px;
  height: 14px;
  flex: 0 0 14px;
  display: none;
  position: relative;
}

.lang-switch-caret::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 48%;
  width: 7px;
  height: 7px;
  border-right: 2px solid rgba(122, 114, 242, 0.92);
  border-bottom: 2px solid rgba(122, 114, 242, 0.92);
  transform: translate(-50%, -50%) rotate(45deg);
  border-radius: 1px;
}

.reader-topbar-btn-lang.is-switchable {
  cursor: pointer;
}

.reader-topbar-btn-lang.is-switchable .lang-switch-caret {
  display: inline-block;
}

.reader-topbar-btn-lang.is-static {
  cursor: default;
}

@media (max-width: 520px) {
  .reader-topbar-btn {
    width: 38px;
    height: 38px;
  }

  .reader-actions {
    gap: 4px;
    padding: 2px 3px;
  }

  .reader-actions.has-lang-switch {
    gap: 3px;
    margin-right: 8px;
  }

  .reader-topbar-btn-lang {
    height: 34px;
    border-width: 2px;
    box-shadow:
      0 0 0 2px rgba(155, 149, 255, 0.16),
      0 6px 14px rgba(20, 35, 90, 0.08),
      0 0 0 2px rgba(255, 255, 255, 0.72) inset;
  }

  .lang-switch-flag-slot,
  .lang-switch-flag {
    width: 20px;
    height: 20px;
    flex-basis: 20px;
  }

  .lang-switch-caret {
    width: 12px;
    height: 12px;
    flex-basis: 12px;
  }

  .lang-switch-caret::before {
    width: 6px;
    height: 6px;
  }
}

@media (min-width: 521px) and (max-width: 900px) {
  .reader-brand.is-lang-mode .reader-logo-lang {
    height: 30px;
  }
}

.dict-coach {
  position: fixed;
  inset: 0;
  z-index: 11050;
  pointer-events: none;
}

.dict-coach.hidden {
  display: none !important;
}

.dict-coach-card {
  position: fixed;
  left: 0;
  top: 0;
  right: auto;
  width: min(320px, calc(100vw - 24px));
  padding: 18px 18px 16px;
  border-radius: 22px;
  border: 1px solid rgba(215, 211, 255, 0.95);
  background:
    radial-gradient(
      circle at top left,
      rgba(244, 241, 255, 0.98),
      rgba(255, 255, 255, 0.985) 42%
    ),
    linear-gradient(
      180deg,
      rgba(255, 255, 255, 0.985),
      rgba(252, 252, 255, 0.985)
    );
  box-shadow:
    0 24px 64px rgba(20, 35, 90, 0.18),
    0 10px 28px rgba(20, 35, 90, 0.08);
  pointer-events: auto;
}

.dict-coach-card::before {
  content: "";
  position: absolute;
  top: -8px;
  right: var(--dict-coach-arrow-right, 56px);
  width: 16px;
  height: 16px;
  background: rgba(255, 255, 255, 0.985);
  border-top: 1px solid rgba(215, 211, 255, 0.95);
  border-left: 1px solid rgba(215, 211, 255, 0.95);
  transform: rotate(45deg);
}

.dict-coach-close {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 34px;
  height: 34px;
  border: 1px solid rgba(215, 211, 255, 0.95);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.9);
  color: rgba(31, 42, 68, 0.75);
  font-size: 16px;
  font-weight: 900;
  line-height: 1;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition:
    transform 120ms ease,
    box-shadow 160ms ease,
    border-color 160ms ease,
    background 160ms ease;
}

.dict-coach-close:active {
  transform: scale(0.97);
}

@media (hover: hover) and (pointer: fine) {
  .dict-coach-close:hover {
    background: rgba(255, 255, 255, 0.98);
    border-color: rgba(155, 149, 255, 0.7);
    box-shadow: 0 10px 22px rgba(20, 35, 90, 0.08);
  }
}

.dict-coach-kicker {
  font-size: 15px;
  font-weight: 750;
  letter-spacing: 0.15px;
  color: #7c3aed;
  margin-bottom: 10px;
  line-height: 1.1;
}

.dict-coach-title {
  font-size: 16px;
  font-weight: 750;
  line-height: 1.08;
  color: rgba(31, 42, 68, 0.96);
  padding-right: 42px;
  max-width: 100%;
}

.dict-coach-desc {
  margin-top: 10px;
  font-size: 14px;
  line-height: 1.42;
  color: rgba(31, 42, 68, 0.72);
  max-width: 300px;
}

.dict-coach-actions {
  display: flex;
  gap: 10px;
  margin-top: 18px;
  flex-wrap: wrap;
}

.dict-coach-btn {
  min-height: 42px;
  padding: 0 16px;
  border-radius: 999px;
  border: 1px solid rgba(215, 211, 255, 0.95);
  font-size: 14px;
  font-weight: 750;
  cursor: pointer;
  transition:
    transform 120ms ease,
    box-shadow 160ms ease,
    border-color 160ms ease,
    background 160ms ease;
}

.dict-coach-btn:active {
  transform: scale(0.98);
}

.dict-coach-btn--primary {
  background: linear-gradient(180deg, #8b5cf6, #7c3aed);
  border-color: rgba(124, 58, 237, 0.7);
  color: #fff;
  box-shadow: 0 12px 24px rgba(124, 58, 237, 0.22);
}

.dict-coach-btn--ghost {
  background: rgba(255, 255, 255, 0.92);
  color: rgba(31, 42, 68, 0.88);
}

@media (hover: hover) and (pointer: fine) {
  .dict-coach-btn--primary:hover {
    box-shadow: 0 16px 30px rgba(124, 58, 237, 0.28);
  }

  .dict-coach-btn--ghost:hover {
    background: rgba(255, 255, 255, 0.98);
    border-color: rgba(155, 149, 255, 0.7);
  }
}

.dict-toast {
  position: fixed;
  left: 50%;
  bottom: max(18px, env(safe-area-inset-bottom, 0px) + 12px);
  transform: translateX(-50%);
  z-index: 11060;
  width: min(420px, calc(100vw - 24px));
  padding: 12px 14px;
  border-radius: 18px;
  border: 1px solid rgba(215, 211, 255, 0.95);
  background: rgba(255, 255, 255, 0.96);
  box-shadow:
    0 18px 42px rgba(20, 35, 90, 0.16),
    0 8px 20px rgba(20, 35, 90, 0.08);
}

.dict-toast.hidden {
  display: none !important;
}

.dict-toast-title {
  font-size: 14px;
  font-weight: 900;
  color: rgba(31, 42, 68, 0.96);
}

.dict-toast-text {
  margin-top: 4px;
  font-size: 13px;
  line-height: 1.35;
  color: rgba(31, 42, 68, 0.72);
}

@media (max-width: 640px) {
  .dict-coach-card {
    left: 0;
    top: 0;
    right: auto;
    width: min(300px, calc(100vw - 28px));
    padding: 16px 16px 14px;
    border-radius: 20px;
  }

  .dict-coach-kicker {
    font-size: 13px;
    margin-bottom: 8px;
  }

  .dict-coach-title {
    font-size: 15px;
    padding-right: 38px;
  }

  .dict-coach-desc {
    margin-top: 8px;
    font-size: 12.5px;
    line-height: 1.38;
    max-width: 100%;
  }

  .dict-coach-actions {
    margin-top: 14px;
    gap: 8px;
  }

  .dict-coach-btn {
    min-height: 40px;
    padding: 0 14px;
    font-size: 13px;
  }

  .dict-coach-close {
    width: 32px;
    height: 32px;
    font-size: 15px;
  }
}
