/* Erklara on YouTube: subtitle overlay, word popup, daily-limit notice and upgrade modal.
   Same palette as the popup ("Klar gold"). Change colours here only. */

#yt-german-overlay-container,
#de-hover-tooltip,
#de-upgrade-modal {
  --e-bg: rgba(12, 11, 10, 0.78);        /* caption background, see-through like YouTube's */
  --e-panel: #1c1b18;                    /* popups */
  --e-panel-2: #26241f;
  --e-line: rgba(255, 244, 222, 0.10);
  --e-line-strong: rgba(255, 244, 222, 0.18);
  --e-text: #ffffff;
  --e-text-2: #d9d4ca;                   /* translation line */
  --e-muted: #9a9488;
  --e-accent: #f5b841;
  --e-accent-hover: #ffc95e;
  --e-accent-ink: #1a1408;
  --e-accent-soft: rgba(245, 184, 65, 0.16);
  --e-ok: #7cc792;
  --e-danger: #ef7a6b;
  --e-der: #7fa8ff;
  --e-die: #f48a9b;
  --e-das: #7cc792;
  --e-font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-family: var(--e-font);
}

/* Hide YouTube's own captions while Erklara shows them (the DOM stays live for capture). */
body.erklara-enabled .ytp-caption-window-container,
body.erklara-enabled .caption-window,
body.erklara-enabled .ytp-caption-window-rollup,
body.erklara-enabled .ytp-caption-window-bottom {
  opacity: 0 !important;
  pointer-events: none !important;
}

/* ---------- Overlay position and size ---------- */
#yt-german-overlay-container {
  position: absolute;
  bottom: 64px;
  left: 50%;
  transform: translateX(-50%);
  width: 88%;
  z-index: 60;
  pointer-events: none;              /* only the caption itself takes the mouse */
  user-select: none;
  container-type: inline-size;
  --de-font-scale: 1;
  /* Grows with the player like YouTube's captions; the popup's size setting scales it. */
  --de-caption: clamp(calc(17px * var(--de-font-scale)), calc(2.9cqw * var(--de-font-scale)), calc(44px * var(--de-font-scale)));
}

.ytp-fullscreen #yt-german-overlay-container { bottom: 90px; }

/* ---------- Caption card ---------- */
.yt-german-card {
  position: relative;
  width: fit-content;
  max-width: 100%;
  margin: 0 auto;
  padding: 0.25em 0.7em 0.3em;
  font-size: var(--de-caption);
  background: var(--e-bg);
  border-radius: 0.35em;
  color: var(--e-text);
  pointer-events: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.yt-german-body {
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
}

.yt-stream-wrapper { width: 100%; position: relative; display: flex; justify-content: center; }

.yt-stream-text {
  display: block;
  max-width: 100%;
  font-size: 1em;
  font-weight: 500;
  line-height: 1.3;
  letter-spacing: 0.005em;
  color: var(--e-text);
  text-align: center;
  overflow-wrap: anywhere;
  transform: translateY(0);
  transition: transform 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  will-change: transform;
}

.yt-german-placeholder { color: var(--e-muted); font-size: 0.6em; font-weight: 500; }

/* Translation: quieter than the German */
.yt-stream-translation {
  display: block;
  max-width: 100%;
  text-align: center;
  color: var(--e-text-2);
  font-size: max(12.5px, 0.7em);
  font-weight: 400;
  line-height: 1.3;
  margin-top: 0.15em;
  transition: filter 0.22s ease, opacity 0.22s ease;
}
.yt-stream-translation .yt-tr-w[hidden] { display: none !important; }
.yt-stream-translation.active-recall-blurred { filter: blur(0.3em); opacity: 0.5; cursor: pointer; }
.yt-stream-translation.active-recall-blurred:hover { filter: none !important; opacity: 1 !important; }

/* ---------- Words ---------- */
.de-word {
  display: inline;
  position: relative;
  cursor: pointer;
  padding: 0 0.06em;
  border-radius: 0.15em;
  color: inherit;
  transition: background-color 0.12s ease;
  -webkit-box-decoration-break: clone;
  box-decoration-break: clone;
}
/* Punctuation sits outside the underline (inline-block stops text-decoration). */
.de-punct { display: inline-block; }

.de-word:hover {
  background: var(--e-accent-soft);
  text-decoration: underline 0.08em var(--e-accent);
  text-underline-offset: 0.18em;
}

.de-word-stream { animation: deWordIn 0.2s cubic-bezier(0.16, 1, 0.3, 1) both; }
@keyframes deWordIn { from { opacity: 0; transform: translateY(0.12em); } to { opacity: 1; transform: none; } }

.de-word.de-word-context { color: var(--e-muted); }

/* A separable verb, reflexive verb or idiom hovered as one unit */
.de-word.de-word-linked-highlight {
  background: var(--e-accent-soft);
  text-decoration: underline 0.08em var(--e-accent);
  text-underline-offset: 0.18em;
}

/* Split separable verb: both parts underlined in gold and numbered */
.de-word.de-word-sep-part1,
.de-word.de-word-sep-part2 {
  text-decoration: underline 0.07em var(--e-accent);
  text-underline-offset: 0.2em;
}
.de-word.de-word-sep-part1::after,
.de-word.de-word-sep-part2::after {
  display: inline-block;             /* keeps the underline off the number */
  font-size: 0.48em;
  font-weight: 700;
  vertical-align: super;
  margin-left: 0.1em;
  color: var(--e-accent);
}
.de-word.de-word-sep-part1::after { content: '1'; }
.de-word.de-word-sep-part2::after { content: '2'; }

/* Fixed phrases and Nomen-Verb-Verbindungen: dotted gold underline (split verbs use a solid one) */
.de-word.de-word-phrase {
  text-decoration: underline dotted 0.08em var(--e-accent);
  text-underline-offset: 0.2em;
}

/* One short line: stehe¹ … auf² → aufstehen  get up · eine Entscheidung treffen  make a decision */
.yt-separable-verb-bar { font-size: max(11.5px, 0.6em); margin-top: 0.2em; }
.yt-sep-indicator-card {
  display: inline-flex;
  align-items: baseline;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.45em;
  color: var(--e-muted);
}
.yt-sep-item { display: inline-flex; align-items: baseline; gap: 0.45em; }
.yt-sep-dot { color: var(--e-muted); }
.yt-sep-parts { color: var(--e-text-2); }
.yt-sep-parts sup { color: var(--e-accent); font-weight: 700; font-size: 0.7em; margin-left: 0.05em; }
.yt-sep-sym { color: var(--e-muted); }
.yt-sep-full { color: var(--e-accent); font-weight: 600; }
.yt-sep-trans { color: var(--e-text-2); }

/* Controls: appear whenever the mouse is over the video (like YouTube's own controls),
   stay for a moment after it leaves, and hide while a word's popup is open. */
.yt-german-toolbar {
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translate(-50%, 4px);
  padding-bottom: 10px;              /* bridge so the mouse can travel up to the buttons */
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  font-size: 13px;
  opacity: 0;
  visibility: hidden;
  /* leaving: wait a moment before fading, so the buttons are easy to reach (and still clickable) */
  transition: opacity 0.2s ease 0.9s, transform 0.2s ease 0.9s, visibility 0s linear 1.1s;
}
.html5-video-player:not(.ytp-autohide):hover .yt-german-toolbar,
.yt-german-card:hover .yt-german-toolbar,
.yt-german-card:focus-within .yt-german-toolbar,
.yt-german-card.has-status .yt-german-toolbar {
  opacity: 1;
  transform: translate(-50%, 0);
  visibility: visible;
  transition-delay: 0s;
}
/* While a word is hovered its popup takes that space (keep this rule after the ones above) */
.yt-german-card:has(.de-word:hover) .yt-german-toolbar {
  opacity: 0;
  visibility: hidden;
  transition-delay: 0s;
}

.yt-toolbar-left,
.yt-toolbar-right {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 3px;
  background: rgba(20, 19, 17, 0.92);
  border: 1px solid var(--e-line);
  border-radius: 9px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.45);
}

/* Status only when something needs saying (working, no subtitles, limit) */
.yt-german-status-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 8px;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--e-text-2);
}
.yt-german-status-badge.ready { display: none; }
.yt-german-status-badge.working { color: var(--e-accent); }
.yt-german-status-badge.warn,
.yt-german-status-badge.error,
.yt-german-status-badge.limit { color: var(--e-danger); }
.sentence-counter { display: none !important; }

.yt-action-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 30px;
  padding: 0 11px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--e-text-2);
  font: 600 13px var(--e-font);
  cursor: pointer;
  transition: background 0.12s ease, color 0.12s ease;
}
.yt-action-btn:hover { background: rgba(255, 255, 255, 0.08); color: var(--e-text); }
.yt-action-btn.active { color: var(--e-accent); }
.yt-action-btn.saved { color: var(--e-accent); }
.yt-icon-btn { width: 30px; padding: 0; justify-content: center; }
.yt-action-btn .kbd-hint { display: none; }
.dt-svg-icon { display: block; flex-shrink: 0; }

/* Free/PRO pill: only shown when the daily limit is reached */
.yt-pro-pill { display: none; }
.yt-pro-pill.limit {
  display: inline-flex;
  align-items: center;
  height: 22px;
  padding: 0 8px;
  margin-left: 2px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 700;
  color: var(--e-accent-ink);
  background: var(--e-accent);
  cursor: pointer;
}

/* ---------- Word popup ---------- */
#de-hover-tooltip {
  position: absolute;
  z-index: 999999;
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 160px;
  max-width: 320px;
  padding: 10px 12px 9px;
  background: var(--e-panel);
  border: 1px solid var(--e-line-strong);
  border-radius: 12px;
  box-shadow: 0 14px 36px rgba(0, 0, 0, 0.6);
  color: var(--e-text);
  font-size: 14px;
  line-height: 1.4;
  overflow-wrap: anywhere;
  pointer-events: auto;
  transform: translate(-50%, -100%);
  animation: deFadeAbove 0.14s cubic-bezier(0.16, 1, 0.3, 1);
}
/* Invisible bridge between popup and word so the mouse can move across */
#de-hover-tooltip::before {
  content: '';
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  height: 16px;
}
#de-hover-tooltip::after {
  content: '';
  position: absolute;
  top: 100%;
  left: var(--arrow-left, 50%);
  margin-left: -6px;
  border: 6px solid transparent;
  border-top-color: var(--e-panel);
  pointer-events: none;
}
#de-hover-tooltip.tooltip-below { transform: translate(-50%, 0); animation: deFadeBelow 0.14s cubic-bezier(0.16, 1, 0.3, 1); }
#de-hover-tooltip.tooltip-below::before { top: -16px; }
#de-hover-tooltip.tooltip-below::after { top: auto; bottom: 100%; border-top-color: transparent; border-bottom-color: var(--e-panel); }
@keyframes deFadeAbove { from { opacity: 0; transform: translate(-50%, calc(-100% - 5px)); } to { opacity: 1; transform: translate(-50%, -100%); } }
@keyframes deFadeBelow { from { opacity: 0; transform: translate(-50%, 5px); } to { opacity: 1; transform: translate(-50%, 0); } }

.de-tooltip-header { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 22px; }
.de-tooltip-badges { display: flex; gap: 5px; align-items: center; }
.de-type-pill {
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--e-muted);
}
.de-tooltip-controls { display: flex; gap: 2px; }
.de-control-btn {
  width: 26px;
  height: 26px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--e-muted);
  cursor: pointer;
  transition: background 0.12s ease, color 0.12s ease;
}
.de-control-btn:hover { background: var(--e-panel-2); color: var(--e-text); }
.de-control-btn.de-star-btn.active { color: var(--e-accent); }

.de-tooltip-de { font-size: 18px; font-weight: 700; letter-spacing: -0.01em; line-height: 1.25; }
.de-article { font-weight: 600; }
.de-gender-der { color: var(--e-der); }
.de-gender-die { color: var(--e-die); }
.de-gender-das { color: var(--e-das); }
.de-tooltip-en { font-size: 14.5px; color: var(--e-text-2); }
.de-flag-tag {
  display: inline-block;
  font-size: 9.5px;
  font-weight: 800;
  letter-spacing: 0.05em;
  color: var(--e-muted);
  border: 1px solid var(--e-line-strong);
  border-radius: 4px;
  padding: 0 4px;
  margin-right: 3px;
  vertical-align: 2px;
}
.de-tooltip-compound,
.de-tooltip-split { font-size: 12.5px; color: var(--e-muted); }
.de-tooltip-compound b,
.de-tooltip-split b { color: var(--e-text-2); font-weight: 600; }
.de-tooltip-context { display: none; }
.de-tooltip-footer {
  display: flex;
  justify-content: flex-end;
  margin-top: 3px;
  padding-top: 6px;
  border-top: 1px solid var(--e-line);
  font-size: 11px;
  color: var(--e-muted);
}
.de-kbd-hints kbd {
  display: inline-block;
  min-width: 16px;
  padding: 0 4px;
  margin: 0 3px 0 6px;
  border: 1px solid var(--e-line-strong);
  border-bottom-width: 2px;
  border-radius: 4px;
  font: 700 10px/14px var(--e-font);
  color: var(--e-text-2);
  text-align: center;
}
.de-loading-shimmer { color: var(--e-muted); animation: dePulse 1s ease-in-out infinite alternate; }
@keyframes dePulse { from { opacity: 0.5; } to { opacity: 1; } }

/* ---------- Daily limit notice (inside the caption card) ---------- */
.yt-daily-limit-overlay {
  display: flex;
  justify-content: center;
  padding: 6px 4px;
  font-size: 13px;
  text-align: center;
}
.limit-inner { display: flex; flex-direction: column; align-items: center; gap: 4px; max-width: 520px; }
.limit-badge {
  font-size: 10.5px;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--e-accent);
}
.limit-title { font-size: 16px; font-weight: 700; }
.limit-desc { font-size: 12.5px; color: var(--e-text-2); margin: 0; }
.limit-actions { display: flex; gap: 8px; margin-top: 6px; }
.btn-limit-upgrade,
.btn-upgrade-primary {
  border: 0;
  border-radius: 8px;
  background: var(--e-accent);
  color: var(--e-accent-ink);
  font: 700 12.5px var(--e-font);
  padding: 7px 14px;
  cursor: pointer;
}
.btn-limit-upgrade:hover,
.btn-upgrade-primary:hover { background: var(--e-accent-hover); }
.btn-limit-key,
.btn-key-activate {
  border: 1px solid var(--e-line-strong);
  border-radius: 8px;
  background: var(--e-panel-2);
  color: var(--e-text);
  font: 600 12px var(--e-font);
  padding: 7px 12px;
  cursor: pointer;
}
.btn-limit-key:hover,
.btn-key-activate:hover { border-color: rgba(255, 244, 222, 0.3); }

/* ---------- Upgrade modal ---------- */
#de-upgrade-modal {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 1000000;
  width: 90%;
  max-width: 400px;
  padding: 22px;
  background: var(--e-panel);
  border: 1px solid var(--e-line-strong);
  border-radius: 16px;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.7);
  color: var(--e-text);
  animation: deModalIn 0.2s cubic-bezier(0.16, 1, 0.3, 1) both;
}
@keyframes deModalIn { from { opacity: 0; transform: translate(-50%, -47%) scale(0.97); } to { opacity: 1; transform: translate(-50%, -50%) scale(1); } }
.upgrade-modal-card { display: flex; flex-direction: column; align-items: center; text-align: center; }
.upgrade-badge {
  font-size: 10.5px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--e-accent);
  margin-bottom: 6px;
}
.upgrade-modal-title { font-size: 20px; font-weight: 700; letter-spacing: -0.02em; margin: 0 0 6px; }
.upgrade-modal-desc { font-size: 13px; color: var(--e-text-2); line-height: 1.45; margin: 0 0 14px; }
.upgrade-perks {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
  padding: 12px 14px;
  margin-bottom: 14px;
  background: var(--e-panel-2);
  border-radius: 10px;
  text-align: left;
}
.upgrade-perk { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--e-text); }
.upgrade-perk svg { color: var(--e-accent); }
.upgrade-actions { width: 100%; }
.btn-upgrade-primary { width: 100%; padding: 10px 16px; font-size: 13.5px; }
.upgrade-key-box {
  width: 100%;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--e-line);
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.key-box-label { font-size: 11.5px; color: var(--e-muted); }
.key-input-row { display: flex; gap: 6px; }
.key-input {
  flex: 1;
  min-width: 0;
  padding: 7px 10px;
  background: var(--e-panel-2);
  border: 1px solid var(--e-line-strong);
  border-radius: 8px;
  color: var(--e-text);
  font: 12px ui-monospace, "SF Mono", Menlo, monospace;
  outline: none;
}
.key-input:focus { border-color: var(--e-accent); }
.key-feedback { font-size: 11.5px; min-height: 16px; }
.key-feedback.success { color: var(--e-ok); }
.key-feedback.error { color: var(--e-danger); }
.btn-modal-dismiss {
  margin-top: 12px;
  border: 0;
  background: transparent;
  color: var(--e-muted);
  font: 12px var(--e-font);
  cursor: pointer;
}
.btn-modal-dismiss:hover { color: var(--e-text-2); }
