:root {
  --pia-help-jade: var(--pia-jade, #10a37f);
  --pia-help-deep: var(--pia-jade-deep, #0b4f43);
  --pia-help-mint: var(--pia-mint, #d9f7eb);
  --pia-help-ink: var(--pia-ink, #0b1220);
  --pia-help-muted: var(--pia-muted, #607089);
  --pia-help-surface: #ffffff;
  --pia-help-line: #cfe7df;
  --pia-help-guide: #2563eb;
  --pia-help-guide-deep: #1746a2;
  --pia-help-guide-soft: #e8efff;
  --pia-help-guide-line: #9ab8f5;
  --pia-help-guide-ink: #ffffff;
  --pia-help-shadow: 0 24px 70px rgba(7, 51, 44, .24), 0 3px 12px rgba(7, 51, 44, .12);
}

html[data-reader-theme="night"] {
  --pia-help-surface: #102821;
  --pia-help-line: #2b5147;
  --pia-help-ink: #ecfbf6;
  --pia-help-muted: #a7c5bd;
  --pia-help-guide: #69a7ff;
  --pia-help-guide-deep: #d8e8ff;
  --pia-help-guide-soft: #142b50;
  --pia-help-guide-line: #3d66a4;
  --pia-help-guide-ink: #071a34;
  --pia-help-shadow: 0 24px 70px rgba(0, 0, 0, .55), 0 3px 12px rgba(0, 0, 0, .35);
}

.pia-help-anchor {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  margin-left: 8px;
  vertical-align: middle;
  line-height: 1;
}

/* En titulares el acceso a la ayuda va delante del texto, alineado con la primera línea. */
.pia-help-anchor.pia-heading-help {
  margin-right: 8px;
  margin-left: 0;
  vertical-align: middle;
}

.pia-help-anchor.is-inline {
  margin-left: auto;
  padding-left: 5px;
}

.rf-sections > .pia-help-anchor.pia-section-help {
  margin-left: 4px;
  padding-left: 0;
}

.pia-main-sections > .pia-help-anchor.pia-section-help {
  margin-left: 0;
  padding-left: 0;
}

.pia-help-trigger {
  width: 20px;
  height: 20px;
  min-width: 20px !important;
  min-height: 20px !important;
  flex: 0 0 auto;
  padding: 0;
  border: 1px solid color-mix(in srgb, var(--pia-help-guide) 50%, var(--pia-help-guide-line));
  border-radius: 7px;
  background: color-mix(in srgb, var(--pia-help-guide-soft) 88%, var(--pia-help-surface));
  color: var(--pia-help-guide-deep);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 2px 7px rgba(37, 99, 235, .15), inset 0 1px rgba(255, 255, 255, .8);
  transition: transform .16s ease, background .16s ease, color .16s ease, box-shadow .16s ease;
  -webkit-tap-highlight-color: transparent;
}

.pia-help-trigger:hover,
.pia-help-trigger:focus-visible {
  transform: translateY(-1px) scale(1.08);
  background: var(--pia-help-guide);
  color: var(--pia-help-guide-ink);
  box-shadow: 0 5px 14px rgba(37, 99, 235, .28);
  outline: none;
}

.pia-help-trigger:focus-visible {
  box-shadow: 0 0 0 3px rgba(37, 99, 235, .24), 0 5px 14px rgba(37, 99, 235, .26);
}

.pia-help-trigger svg {
  width: 11px;
  height: 11px;
  display: block;
  pointer-events: none;
}

.pia-help-trigger.is-open {
  background: var(--pia-help-guide-deep);
  border-color: var(--pia-help-guide-deep);
  color: var(--pia-help-guide-ink);
}

.pia-read-anchor {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  margin-right: 8px;
  margin-left: 0;
  vertical-align: middle;
  line-height: 1;
}

.pia-read-anchor.pia-heading-read {
  margin-right: 9px;
  vertical-align: .08em;
}

.pia-read-trigger {
  width: 24px;
  height: 24px;
  min-width: 24px !important;
  min-height: 24px !important;
  flex: 0 0 auto;
  padding: 0;
  border: 1px solid color-mix(in srgb, var(--pia-help-jade) 46%, var(--pia-help-line));
  border-radius: 999px;
  background: color-mix(in srgb, var(--pia-help-surface) 92%, var(--pia-help-mint));
  color: var(--pia-help-deep);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 2px 7px rgba(16, 163, 127, .14), inset 0 1px rgba(255, 255, 255, .75);
  transition: transform .16s ease, background .16s ease, color .16s ease, box-shadow .16s ease;
  -webkit-tap-highlight-color: transparent;
}

.pia-read-trigger:hover,
.pia-read-trigger:focus-visible,
.pia-read-trigger.is-open {
  transform: translateY(-1px) scale(1.06);
  border-color: var(--pia-help-jade);
  background: var(--pia-help-jade);
  color: #fff;
  box-shadow: 0 5px 14px rgba(16, 163, 127, .25);
  outline: none;
}

.pia-read-trigger.is-speaking {
  background: var(--pia-help-deep);
  border-color: var(--pia-help-deep);
  color: #fff;
  animation: pia-help-pulse 1.35s ease-in-out infinite;
}

.pia-read-trigger svg {
  width: 14px;
  height: 14px;
  display: block;
  pointer-events: none;
}

.pia-help-anchor.pia-toolbar-help .pia-help-trigger {
  border-color: color-mix(in srgb, var(--pia-help-guide) 48%, var(--pia-help-line)) !important;
  background: color-mix(in srgb, var(--pia-help-surface) 84%, var(--pia-help-guide-soft)) !important;
  color: var(--pia-help-guide-deep) !important;
}

.pia-help-anchor.pia-toolbar-help .pia-help-trigger:hover,
.pia-help-anchor.pia-toolbar-help .pia-help-trigger:focus-visible,
.pia-help-anchor.pia-toolbar-help .pia-help-trigger.is-open {
  background: var(--pia-help-guide) !important;
  color: var(--pia-help-guide-ink) !important;
}

.pia-help-dialog {
  position: fixed;
  z-index: 2147483300;
  width: min(392px, calc(100vw - 28px));
  max-height: min(78vh, 620px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--pia-help-line);
  border-radius: 17px;
  background: var(--pia-help-surface);
  color: var(--pia-help-ink);
  box-shadow: var(--pia-help-shadow);
  font-family: var(--pia-display, "Segoe UI", system-ui, -apple-system, Arial, sans-serif);
  font-size: 14px;
  line-height: 1.5;
  overscroll-behavior: contain;
  animation: pia-help-enter .17s ease-out both;
}

.pia-help-dialog[hidden] { display: none !important; }

@keyframes pia-help-enter {
  from { opacity: 0; transform: translateY(5px) scale(.985); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.pia-help-head {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  grid-template-areas: "voice heading close";
  align-items: center;
  column-gap: 9px;
  row-gap: 0;
  padding: 10px 10px 9px 12px;
  border-bottom: 1px solid var(--pia-help-line);
  background:
    radial-gradient(circle at 0 0, rgba(52, 211, 153, .22), transparent 13rem),
    linear-gradient(145deg, color-mix(in srgb, var(--pia-help-mint) 54%, var(--pia-help-surface)), var(--pia-help-surface));
  cursor: grab;
  user-select: none;
  touch-action: none;
}

.pia-help-head.is-dragging { cursor: grabbing; }

.pia-help-voice,
.pia-help-close {
  width: 32px;
  height: 32px;
  min-width: 32px !important;
  flex: 0 0 32px;
  padding: 0;
  border: 1px solid color-mix(in srgb, var(--pia-help-jade) 40%, var(--pia-help-line));
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--pia-help-surface);
  color: var(--pia-help-deep);
  cursor: pointer;
  transition: background .15s ease, color .15s ease, transform .15s ease;
}

.pia-help-voice { grid-area: voice; }
.pia-help-close { grid-area: close; }

.pia-help-voice svg,
.pia-help-close svg { width: 15px; height: 15px; pointer-events: none; }

.pia-help-voice:hover,
.pia-help-voice:focus-visible,
.pia-help-close:hover,
.pia-help-close:focus-visible {
  background: var(--pia-help-jade);
  color: #fff;
  outline: none;
}

.pia-help-voice.is-speaking {
  background: var(--pia-help-deep);
  color: #fff;
  animation: pia-help-pulse 1.35s ease-in-out infinite;
}

.pia-help-voice.is-paused {
  background: color-mix(in srgb, var(--pia-help-jade) 18%, var(--pia-help-surface));
  color: var(--pia-help-deep);
  animation: none;
}

@keyframes pia-help-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(16, 163, 127, .28); }
  50% { box-shadow: 0 0 0 7px rgba(16, 163, 127, 0); }
}

.pia-help-heading {
  grid-area: heading;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.pia-help-kicker {
  font-size: 10px;
  line-height: 1.2;
  letter-spacing: .09em;
  text-transform: uppercase;
  font-weight: 800;
  color: var(--pia-help-jade-deep, #087a61);
}

.pia-help-title {
  display: -webkit-box;
  margin: 0;
  overflow: hidden;
  color: var(--pia-help-ink);
  font-size: 15px;
  line-height: 1.25;
  font-weight: 800;
  text-overflow: clip;
  white-space: normal;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
}

.pia-help-dialog.is-content .pia-help-title {
  display: -webkit-box;
  overflow: hidden;
  white-space: normal;
  text-overflow: clip;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
  line-clamp: 3;
}

.pia-help-dialog.is-content .pia-help-text {
  white-space: pre-line;
}

.pia-help-close {
  font-size: 19px;
  line-height: 1;
}

.pia-help-body {
  overflow-y: auto;
  padding: 15px 17px 13px;
  overscroll-behavior: contain;
}

.pia-help-body p {
  margin: 0;
  color: var(--pia-help-ink);
  font-size: 14px;
  line-height: 1.6;
}

.pia-help-body .pia-help-hint {
  margin-top: 9px;
  color: var(--pia-help-muted);
  font-size: 11px;
  line-height: 1.4;
}

.pia-help-status {
  min-height: 22px;
  padding: 0 17px 10px;
  color: var(--pia-help-muted);
  font-size: 10.5px;
  line-height: 1.35;
}

.pia-help-status:empty { display: none; }

.pia-help-loading {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--pia-help-muted);
}

.pia-help-loading::before {
  content: "";
  width: 12px;
  height: 12px;
  border: 2px solid rgba(16, 163, 127, .22);
  border-top-color: var(--pia-help-jade);
  border-radius: 50%;
  animation: pia-help-spin .7s linear infinite;
}

@keyframes pia-help-spin { to { transform: rotate(360deg); } }

.pia-help-live {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

@media (max-width: 540px) {
  .pia-help-trigger { width: 23px; height: 23px; min-width: 23px !important; min-height: 23px !important; }
  .pia-help-trigger svg { width: 12px; height: 12px; }
  .pia-help-anchor { margin-left: 6px; }
  .pia-read-trigger { width: 22px; height: 22px; min-width: 22px !important; min-height: 22px !important; }
  .pia-read-trigger svg { width: 13px; height: 13px; }
  .pia-read-anchor.pia-heading-read { margin-right: 6px; }
  .pia-help-dialog {
    width: calc(100vw - 16px);
    max-height: 82vh;
    border-radius: 14px;
  }
  .pia-help-body { padding: 13px 14px 11px; }
  .pia-help-body p { font-size: 14px; }
  .pia-help-head { padding: 9px 9px 8px 10px; }
}

@media (prefers-reduced-motion: reduce) {
  .pia-help-dialog,
  .pia-help-trigger,
  .pia-help-voice,
  .pia-help-close { animation: none !important; transition: none !important; }
}

@media print {
  .pia-help-anchor,
  .pia-read-anchor,
  .pia-help-dialog,
  .pia-lang-control { display: none !important; }
}

.pia-lang-control {
  position: relative;
  display: inline-flex;
  align-items: center;
  flex: 0 0 auto;
}

.pia-lang-control.is-floating {
  position: fixed;
  top: 9px;
  right: 9px;
  z-index: 2147483200;
}

.pia-lang-toggle {
  display: inline-flex;
  height: 32px;
  align-items: center;
  gap: 5px;
  padding: 0 8px;
  border: 1px solid var(--pia-help-line);
  border-radius: 999px;
  background: color-mix(in srgb, var(--pia-help-surface) 88%, var(--pia-help-mint));
  color: var(--pia-help-ink);
  font: inherit;
  font-size: 10px;
  font-weight: 800;
  cursor: pointer;
  transition: border-color .15s ease, background .15s ease, color .15s ease;
}

.pia-lang-toggle:hover,
.pia-lang-toggle:focus-visible,
.pia-lang-control.is-open .pia-lang-toggle {
  border-color: var(--pia-help-jade);
  background: var(--pia-help-mint);
  color: var(--pia-help-deep);
  outline: none;
}

.pia-lang-toggle-flag {
  width: 22px;
  height: 16px;
  object-fit: cover;
  border-radius: 3px;
  box-shadow: 0 0 0 1px rgba(7, 51, 44, .14);
}

.pia-lang-toggle-caret { font-size: 10px; line-height: 1; opacity: .7; }

.pia-lang-popover {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 2147483250;
  width: min(332px, calc(100vw - 24px));
  max-width: min(332px, calc(100vw - 24px));
  max-height: min(72vh, 438px);
  left: auto;
  overflow: auto;
  padding: 10px;
  border: 1px solid var(--pia-help-line);
  border-radius: 14px;
  background: var(--pia-help-surface);
  color: var(--pia-help-ink);
  box-shadow: var(--pia-help-shadow);
  font-family: var(--pia-display, "Segoe UI", system-ui, -apple-system, Arial, sans-serif);
}

.pia-lang-popover[hidden] { display: none !important; }

html body .pia-lang-popover {
  max-width: min(332px, calc(100vw - 24px)) !important;
}

.pia-lang-popover-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  padding: 2px 4px 8px;
}

.pia-lang-popover-title { font-size: 12px; }
.pia-lang-popover-subtitle { color: var(--pia-help-muted); font-size: 9px; }

.pia-lang-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 3px;
}

.pia-lang-option {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 6px;
  padding: 6px;
  border: 1px solid transparent;
  border-radius: 9px;
  background: transparent;
  color: var(--pia-help-ink);
  font: inherit;
  font-size: 10px;
  text-align: left;
  cursor: pointer;
}

.pia-lang-option:hover,
.pia-lang-option:focus-visible,
.pia-lang-option.is-active {
  border-color: color-mix(in srgb, var(--pia-help-jade) 42%, var(--pia-help-line));
  background: color-mix(in srgb, var(--pia-help-mint) 60%, var(--pia-help-surface));
  outline: none;
}

.pia-lang-option img { width: 22px; height: 16px; flex: 0 0 22px; object-fit: cover; border-radius: 3px; }
.pia-lang-option span:not(.pia-lang-check) { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pia-lang-check { margin-left: auto; color: var(--pia-help-jade); font-size: 11px; opacity: 0; }
.pia-lang-option.is-active .pia-lang-check { opacity: 1; }

.pia-lang-voice {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin-bottom: 9px;
  padding: 1px 3px 9px;
  border-bottom: 1px solid var(--pia-help-line);
}

.pia-lang-voice-head {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 6px;
}

.pia-lang-voice-icon {
  width: 20px;
  height: 20px;
  flex: 0 0 20px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 1px solid color-mix(in srgb, var(--pia-help-jade) 34%, var(--pia-help-line));
  border-radius: 999px;
  background: var(--pia-help-surface);
  color: var(--pia-help-deep);
  cursor: pointer;
}

.pia-lang-voice-icon svg { width: 13px; height: 13px; display: block; }

.pia-lang-voice-icon:hover:not(:disabled),
.pia-lang-voice-icon:focus-visible {
  background: var(--pia-help-jade);
  color: #fff;
  outline: none;
}

.pia-lang-voice-icon:focus-visible { box-shadow: 0 0 0 2px color-mix(in srgb, var(--pia-help-jade) 55%, transparent); }
.pia-lang-voice-icon:disabled { cursor: default; opacity: .45; }

.pia-lang-voice-label {
  color: var(--pia-help-muted);
  font-size: 9px;
  font-weight: 800;
  letter-spacing: .06em;
  text-transform: uppercase;
}

.pia-lang-voice-hint {
  min-width: 0;
  max-width: 72%;
  margin-left: auto;
  color: var(--pia-help-muted);
  font-size: 10px;
  font-weight: 600;
  line-height: 1.3;
  text-align: right;
  white-space: normal;
}

.pia-lang-voice-hint[data-state="playing"] { color: var(--pia-help-jade); }

.pia-lang-voice.is-playing .pia-lang-voice-icon {
  border-color: var(--pia-help-jade);
  background: var(--pia-help-jade);
  color: #fff;
}

.pia-lang-voice-icon.is-playing:hover:not(:disabled),
.pia-lang-voice-icon.is-playing:focus-visible {
  background: var(--pia-help-deep);
  color: #fff;
}

.pia-lang-voice-select {
  width: 100%;
  min-width: 0;
  height: 30px;
  padding: 0 7px;
  border: 1px solid color-mix(in srgb, var(--pia-help-jade) 30%, var(--pia-help-line));
  border-radius: 8px;
  background: color-mix(in srgb, var(--pia-help-surface) 90%, var(--pia-help-mint));
  color: var(--pia-help-ink);
  font: inherit;
  font-size: 10px;
  font-weight: 650;
  text-overflow: ellipsis;
  cursor: pointer;
}

.pia-lang-voice-select:hover,
.pia-lang-voice-select:focus-visible {
  border-color: var(--pia-help-jade);
  background: var(--pia-help-mint);
  outline: none;
}

.pia-lang-voice-select:disabled { cursor: default; opacity: .78; }
.pia-lang-voice.is-empty .pia-lang-voice-select { color: var(--pia-help-muted); }

.pia-news-translate-status {
  position: fixed;
  left: 14px;
  bottom: 14px;
  z-index: 2147483150;
  max-width: min(360px, calc(100vw - 28px));
  padding: 8px 12px;
  border: 1px solid color-mix(in srgb, var(--pia-help-jade) 42%, transparent);
  border-radius: 999px;
  background: var(--pia-help-deep);
  color: #fff;
  box-shadow: 0 10px 28px rgba(7, 51, 44, .24);
  font-family: var(--pia-display, "Segoe UI", system-ui, -apple-system, Arial, sans-serif);
  font-size: 11px;
  font-weight: 700;
  line-height: 1.35;
}

.pia-news-translate-status[hidden] { display: none !important; }

@media (max-width: 640px) {
  .pia-lang-toggle { height: 30px; padding: 0 6px; }
  .pia-lang-toggle-code { display: none; }
  .pia-lang-grid { grid-template-columns: 1fr; }
  .pia-lang-popover {
    position: fixed;
    top: 62px;
    left: 8px;
    right: 8px;
    width: auto;
    max-width: none;
    max-height: 68vh;
  }
  html body .pia-lang-popover {
    left: 8px !important;
    right: 8px !important;
    width: auto !important;
    max-width: none !important;
  }
  .pia-news-translate-status { left: 9px; bottom: 9px; max-width: calc(100vw - 18px); }
}
