/* Focus mode, "Объясни" (focus-explain.js): the "?" by a paragraph, underlined terms,
   the toolbar over a selection and the answer card. */

/* "?" in the left margin, out of the text flow: faint on touch screens, shown on hover or focus with a mouse. */
.prose .fx-explain-host { position: relative; }
.prose .fx-explain-q {
  position: absolute;
  top: 0.15em;
  left: -46px;
  z-index: 1;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 1px solid var(--line-strong);
  border-radius: 50%;
  background: var(--bg);
  color: var(--muted);
  font: 600 14px/1 var(--sans);
  font-style: normal;
  text-indent: 0;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  opacity: 0;
  transition: opacity 0.15s, color 0.15s, border-color 0.15s;
}
.prose .fx-explain-q::before { content: "?"; }
/* A bigger invisible area to hit with a finger. */
.prose .fx-explain-q::after { content: ""; position: absolute; inset: -8px; }
.prose blockquote.fx-explain-host > .fx-explain-q { left: -48px; }
.prose .fx-explain-host:hover > .fx-explain-q,
.prose .fx-explain-host:hover > li:first-child > .fx-explain-q,
.prose .fx-explain-q:focus-visible,
.prose .fx-explain-q[aria-expanded="true"] { opacity: 1; }
.prose .fx-explain-q:hover, .prose .fx-explain-q:focus-visible { color: var(--accent); border-color: var(--accent); }
@media (hover: none) {
  .prose .fx-explain-q { opacity: 0.45; }
}
/* Too little margin on the left: the "?" sits at the top right corner, in the gap above the block. */
@media (max-width: 820px) {
  .prose .fx-explain-q, .prose blockquote.fx-explain-host > .fx-explain-q {
    top: auto;
    bottom: calc(100% + 0.1em);
    left: auto;
    right: -6px;
    width: 22px;
    height: 22px;
    font-size: 12px;
  }
}

/* A term's first mention in a block. */
.prose .fx-term {
  text-decoration: underline dotted;
  text-decoration-color: color-mix(in srgb, var(--accent) 70%, transparent);
  text-decoration-thickness: 1.5px;
  text-underline-offset: 0.2em;
  cursor: help;
  border-radius: 2px;
}
.prose .fx-term:hover { text-decoration-color: var(--accent); }
.prose .fx-term:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* The toolbar over the selection. */
.fx-explain-bar {
  position: absolute;
  z-index: 45;
  display: flex;
  gap: 2px;
  padding: 4px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: var(--surface);
  box-shadow: 0 8px 28px rgb(0 0 0 / 0.55);
}
.fx-explain-bar button {
  padding: 8px 14px;
  border: 0;
  border-radius: 999px;
  background: none;
  color: var(--fg);
  font: 600 12px/1 var(--sans);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  white-space: nowrap;
  cursor: pointer;
}
.fx-explain-bar button:hover, .fx-explain-bar button:focus-visible { background: var(--accent); color: var(--bg); outline: none; }

/* The answer card: calm, beside the text; a bottom sheet on phones. */
.fx-explain-card {
  position: absolute;
  z-index: 45;
  max-width: calc(100vw - 32px);
  padding: 14px 18px 18px;
  border: 1px solid var(--line-strong);
  border-left: 2px solid var(--accent);
  border-radius: 4px;
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 12px 36px rgb(0 0 0 / 0.5);
  font: 16px/1.55 var(--sans);
  animation: fx-explain-in 0.16s ease-out;
}
.fx-explain-card:focus { outline: none; }
.fx-explain-head { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.fx-explain-tabs { display: flex; flex-wrap: wrap; gap: 4px; flex: 1; }
.fx-explain-tabs button {
  padding: 6px 10px;
  border: 1px solid transparent;
  border-radius: 999px;
  background: none;
  color: var(--muted);
  font: 600 11px/1 var(--sans);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: pointer;
}
.fx-explain-tabs button:hover { color: var(--fg); }
.fx-explain-tabs button[aria-selected="true"] { border-color: var(--accent); color: var(--accent); }
.fx-explain-close {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  margin: -4px -8px 0 0;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: none;
  color: var(--muted);
  cursor: pointer;
}
.fx-explain-close:hover { color: var(--fg); background: var(--bg); }
.fx-explain-body p { margin: 0 0 0.6em; }
.fx-explain-body p:last-child { margin-bottom: 0; }
.fx-explain-body .fx-explain-note { color: var(--muted); font-size: 14px; }
.fx-explain-body dl { margin: 0; }
.fx-explain-body dt { color: var(--fg); font-weight: 600; }
.fx-explain-body dd { margin: 0 0 0.7em; }
.fx-explain-body dd:last-child { margin-bottom: 0; }

.fx-explain-card.is-sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  max-width: none;
  max-height: 60vh;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 14px max(var(--gutter), env(safe-area-inset-right)) max(20px, env(safe-area-inset-bottom)) max(var(--gutter), env(safe-area-inset-left));
  border: 0;
  border-top: 2px solid var(--accent);
  border-radius: 14px 14px 0 0;
  font-size: 17px;
  animation-name: fx-explain-up;
  animation-duration: 0.2s;
}

@keyframes fx-explain-in { from { opacity: 0; transform: translateY(4px); } }
@keyframes fx-explain-up { from { transform: translateY(100%); } }
@media (prefers-reduced-motion: reduce) {
  .fx-explain-card, .fx-explain-card.is-sheet { animation: none; }
  .prose .fx-explain-q { transition: none; }
}
