/* Плашка первого экрана (first-screen-hint.js): нейрончик сидит в плашке слева, крупный и под
   наклоном, выглядывает из-за нижнего края, объясняет, как учить, а после
   старта ведёт по шагам 1–3. Десктоп — под рядом шагов, над редактором; телефон — над нижней
   панелью (в шагах — над кнопкой «Говорить»). Хвостик смотрит на цель (--fsh-caret-x из JS).
   Вид — как у .ext-paste-hint. */
.first-screen-hint {
  --fsh-caret-x: 50%;
  position: relative; width: 95%; box-sizing: border-box; display: flex; align-items: center; gap: 14px;
  margin: 2px 0 16px; padding: 12px 10px 12px 14px; padding-inline-start: 106px; border-radius: 14px;
  background: #fff; border: 1px solid #e3e2dc; box-shadow: 0 1px 3px rgba(0,0,0,.05);
  color: #1a1a1a; font-family: GolosUI, system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif; font-size: 14px; line-height: 1.4;
  animation: fsh-in .25s ease-out;
}
.first-screen-hint[hidden], .first-screen-hint [hidden] { display: none !important; }
@keyframes fsh-in { from { opacity: 0; transform: translateY(-4px); } }
.first-screen-hint::before {
  content: ''; position: absolute; top: -6px; left: var(--fsh-caret-x); width: 10px; height: 10px; margin-left: -6px;
  background: inherit; border: 1px solid; border-color: inherit; border-right: 0; border-bottom: 0; transform: rotate(45deg);
}

/* Нейрончик: сидит в левой части плашки (за край не вылезает), крупный и чуть наклонён, стоит низко:
   нижний край плашки срезает ступни и часть ног.
   Под наклоном края сглаживаем (geometricPrecision): crispEdges рисует повёрнутый пиксель-арт
   лесенкой. Глаза бегают (.neuron-eye из auth-styles.css), на новой реплике подпрыгивает.
   Наклон — через rotate, прыжок — через translate: не мешают друг другу. */
.first-screen-hint .fsh-neuron {
  position: absolute; top: 0; bottom: 0; inset-inline-start: 0; width: 100px; overflow: hidden;
  border-start-start-radius: 13px; border-end-start-radius: 13px; color: #2b2f36; pointer-events: none;
}
.first-screen-hint .fsh-neuron svg {
  position: absolute; bottom: -16px; inset-inline-start: 12px; display: block; width: 80px; height: auto;
  shape-rendering: geometricPrecision; rotate: -8deg; transform-origin: 50% 100%;
}
[dir="rtl"] .first-screen-hint .fsh-neuron svg { rotate: 8deg; }
/* Нейрончик смотрит на стих: на десктопе стих под плашкой — зрачки опущены к низу лица (2 единицы
   SVG), на телефоне стих над плашкой — подняты (см. медиазапрос). Влево-вправо бегают, как при чтении:
   translate складывается с анимацией бега глаз (она через transform). */
.first-screen-hint .fsh-neuron .neuron-eye { translate: 0 2px; }
.first-screen-hint .fsh-neuron.fsh-hop svg { animation: fsh-hop .45s ease-out; }
@keyframes fsh-hop { 30% { translate: 0 -5px; } 60% { translate: 0 0; } 80% { translate: 0 -2px; } }

.first-screen-hint .fsh-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.first-screen-hint .fsh-title { font-size: 15px; font-weight: 700; }
.first-screen-hint.is-coach .fsh-title { font-size: 13px; font-weight: 600; color: #8a8a85; }
.first-screen-hint .fsh-text { margin: 0; color: #444; }
.first-screen-hint.is-coach .fsh-text { color: #1a1a1a; }

.first-screen-hint .fsh-act { flex: none; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.first-screen-hint .fsh-start {
  flex: none; margin: 0; padding: 10px 20px; border: 0; border-radius: 999px; background: #1a1a1a; color: #fff;
  font: inherit; font-weight: 600; white-space: nowrap; cursor: pointer;
}
.first-screen-hint .fsh-start:hover { background: #333; }
.first-screen-hint .fsh-own {
  margin: 0; padding: 2px 4px; border: 0; background: none; color: #666; font: inherit; font-size: 13px;
  text-decoration: underline; text-underline-offset: 3px; cursor: pointer; white-space: nowrap;
}
.first-screen-hint .fsh-own:hover { color: #1a1a1a; background: none; }
.first-screen-hint .fsh-x {
  align-self: flex-start; flex: none; display: grid; place-items: center; box-sizing: border-box; width: 28px; height: 28px;
  margin: -4px -2px 0 -6px; padding: 0; border: 0; border-radius: 50%; background: none; color: #777; cursor: pointer;
}
.first-screen-hint .fsh-x:hover { background: rgba(0,0,0,.06); color: #1a1a1a; }
.first-screen-hint .fsh-x svg { width: 16px; height: 16px; }
.first-screen-hint button:focus-visible { outline: 2px solid var(--ui-focus, #2563eb); outline-offset: 2px; }

/* Шаг 1, пока видно вступление: оранжевая точка (цвет «антенны» нейрончика) с затухающей пульсацией. */
#transform.fsh-target { position: relative; }
#transform.fsh-target::after {
  content: ''; position: absolute; top: 6px; inset-inline-end: 6px; width: 8px; height: 8px; border-radius: 50%;
  background: #FF5816; animation: fsh-pulse 1.6s ease-out 4;
}
@keyframes fsh-pulse { from { box-shadow: 0 0 0 0 rgba(255, 88, 22, .55); } to { box-shadow: 0 0 0 9px rgba(255, 88, 22, 0); } }

/* Праздничная карточка (script.js → mountHolidayTeaser) стоит под редактором. В режимах шагов
   текст короче, и она всплывала посреди упражнения, поэтому показываем её только в «Прочти».
   script.js переключает #output-area только через style.display = 'block' | 'none'. */
#output-area[style*="block"] ~ .holiday-teaser { display: none; }

/* Новичок на десктопе: шторка свёрнута с первого кадра. html.fsh-no-sidebar ставит inline-скрипт
   в <head> главных страниц, first-screen-hint.js сворачивает настоящую шторку и снимает класс.
   Повторяет body.sidebar-collapsed / .history-sidebar.collapsed, чтобы макет не прыгал. */
@media (min-width: 769px) {
  html.fsh-no-sidebar body { padding-left: 0; }
  html.fsh-no-sidebar[dir="rtl"] body { padding-right: 0; }
  html.fsh-no-sidebar .history-sidebar:not(.open) { transform: translateX(-320px); }
  html.fsh-no-sidebar[dir="rtl"] .history-sidebar:not(.open) { transform: translateX(320px); }
  html.fsh-no-sidebar body:not(.is-authed) #title { padding-left: 28px; }
}

@media (max-width: 600px) {
  .first-screen-hint {
    position: fixed; z-index: 3; left: 12px; right: 12px; bottom: calc(var(--fsh-bottom, 73px) + 10px);
    width: auto; margin: 0; display: grid; grid-template-columns: 64px minmax(0, 1fr) auto; align-items: start;
    gap: 10px 12px; padding: 14px 10px 12px 14px; box-shadow: 0 6px 24px rgba(0,0,0,.12); animation-name: fsh-in-up;
  }
  @keyframes fsh-in-up { from { opacity: 0; transform: translateY(6px); } }
  .first-screen-hint::before { top: auto; bottom: -6px; transform: rotate(225deg); }
  /* первая колонка на всю высоту — под нейрончика: он, как на десктопе, выглядывает из-за нижнего
     края. Стих на телефоне над плашкой — нейрончик смотрит вверх. */
  .first-screen-hint .fsh-neuron { width: 92px; }
  .first-screen-hint .fsh-neuron svg { bottom: -16px; inset-inline-start: 6px; width: 82px; }
  .first-screen-hint .fsh-neuron .neuron-eye { translate: 0 -2px; }
  .first-screen-hint .fsh-body { grid-column: 2; grid-row: 1; }
  .first-screen-hint .fsh-x { grid-column: 3; grid-row: 1; margin: -6px -2px 0 0; }
  /* вступление: кнопка второй строкой правее нейрончика, под ней ссылка «свой текст» */
  .first-screen-hint .fsh-act { grid-column: 2 / -1; grid-row: 2; align-items: stretch; }
  .first-screen-hint .fsh-start { padding: 12px 20px; }
  /* шаги: «Дальше» справа в строке заголовка, текст — под ним */
  .first-screen-hint.is-coach { grid-template-columns: 64px minmax(0, 1fr) auto auto; align-items: center; row-gap: 6px; }
  .first-screen-hint.is-coach .fsh-body { display: contents; }
  .first-screen-hint.is-coach .fsh-title { grid-column: 2; grid-row: 1; }
  .first-screen-hint.is-coach .fsh-act { grid-column: 3; grid-row: 1; }
  .first-screen-hint.is-coach .fsh-start { padding: 7px 14px; font-size: 13px; }
  .first-screen-hint.is-coach .fsh-x { grid-column: 4; grid-row: 1; margin: -4px -2px 0 0; }
  .first-screen-hint.is-coach .fsh-text { grid-column: 2 / -1; grid-row: 2; }
  /* текст не прячется под плашкой: даём редактору отступ снизу на её высоту */
  body.fsh-on #input-area, body.fsh-on #output-area { padding-bottom: var(--fsh-space, 70px); }
  /* открытая шторка-панель — поверх, плашку не показываем */
  body.sidebar-drawer-open .first-screen-hint { display: none; }
}
/* Поэтапное появление у новичка: блоки первого экрана выплывают из лёгкого размытия по очереди сверху
   вниз с шагом в 1 с, когда стих уже в редакторе. Заголовок и ряд шагов — один этап. html.fsh-new ставит inline-скрипт в <head>; first-screen-hint.js
   при первом показе плашки добавляет fsh-go и после каскада снимает оба класса (иначе анимация
   повторялась бы при каждом показе блока). До своей очереди блоки прозрачны и не ловят клики, но место
   держат — макет не прыгает. Если плашка так и не показалась, через 3 с всё проявится само
   (fsh-failsafe; JS делает то же). Без анимации — сразу. */
@media (prefers-reduced-motion: no-preference) {
  html.fsh-new #title, html.fsh-new #toggle-buttons, html.fsh-new #first-screen-hint, html.fsh-new #input-area,
  html.fsh-new #clear-undo-btn, html.fsh-new #editor-store-badges, html.fsh-new .holiday-teaser {
    opacity: 0; pointer-events: none; animation: fsh-failsafe 0s linear 3s forwards;
  }
  html.fsh-new.fsh-go #title, html.fsh-new.fsh-go #toggle-buttons, html.fsh-new.fsh-go #first-screen-hint,
  html.fsh-new.fsh-go #input-area, html.fsh-new.fsh-go #clear-undo-btn, html.fsh-new.fsh-go #editor-store-badges,
  html.fsh-new.fsh-go .holiday-teaser {
    animation: fsh-stage .8s cubic-bezier(.16, 1, .3, 1) var(--fsh-d, 0s) both;
  }
  /* десктоп: заголовок с рядом шагов → плашка → стих → значки */
  html.fsh-new #title, html.fsh-new #toggle-buttons { --fsh-d: 0s; }
  html.fsh-new #first-screen-hint { --fsh-d: 1s; }
  html.fsh-new #input-area, html.fsh-new #clear-undo-btn { --fsh-d: 2s; }
  html.fsh-new #editor-store-badges, html.fsh-new .holiday-teaser { --fsh-d: 3s; }
  /* телефон: стих сверху → плашка → нижняя панель шагов */
  @media (max-width: 600px) {
    html.fsh-new #input-area, html.fsh-new #clear-undo-btn { --fsh-d: 0s; }
    html.fsh-new #first-screen-hint { --fsh-d: 1s; }
    html.fsh-new #toggle-buttons { --fsh-d: 2s; }
  }
}
/* плашка уже проявилась каскадом — своё появление (fsh-in) не повторяем */
.first-screen-hint.fsh-staged { animation: none; }
@keyframes fsh-stage {
  from { opacity: 0; transform: translateY(8px); filter: blur(6px); pointer-events: none; }
  to { opacity: 1; transform: none; filter: none; pointer-events: auto; }
}
@keyframes fsh-failsafe { to { opacity: 1; pointer-events: auto; } }

@media (prefers-reduced-motion: reduce) {
  .first-screen-hint, .first-screen-hint .fsh-neuron.fsh-hop svg, #transform.fsh-target::after { animation: none; }
}

/* Тёмная тема — из токенов ui-kit.css (как шторка). Через #id: auth-styles.css красит все кнопки
   правилом [data-theme-resolved="dark"] button:not(…):not(…), классов не хватает, чтобы его перебить. */
[data-theme-resolved="dark"] #first-screen-hint { background: var(--ui-surface, #1f2937); border-color: var(--ui-border, #374151); color: var(--ui-text, #f9fafb); }
[data-theme-resolved="dark"] #first-screen-hint .fsh-neuron { color: #94a3b8; }
[data-theme-resolved="dark"] #first-screen-hint .fsh-text { color: #cbd5e1; }
[data-theme-resolved="dark"] #first-screen-hint.is-coach .fsh-text { color: var(--ui-text, #f9fafb); }
[data-theme-resolved="dark"] #first-screen-hint.is-coach .fsh-title { color: var(--ui-text-muted, #9ca3af); }
[data-theme-resolved="dark"] #first-screen-hint .fsh-start { background: var(--ui-primary, #f9fafb); color: var(--ui-on-primary, #111827); }
[data-theme-resolved="dark"] #first-screen-hint .fsh-start:hover { background: #fff; }
[data-theme-resolved="dark"] #first-screen-hint .fsh-own { background: none; color: #9ca3af; }
[data-theme-resolved="dark"] #first-screen-hint .fsh-own:hover { color: #fff; }
[data-theme-resolved="dark"] #first-screen-hint .fsh-x { background: none; color: #cbd5e1; }
[data-theme-resolved="dark"] #first-screen-hint .fsh-x:hover { background: var(--ui-hover, #374151); color: #fff; }
