/* Помодоро-таймер — плавающий виджет в правом нижнем углу.
   Самодостаточный модуль: подключается в кабинет и в читалку методички. */

:root {
  --pomo-work: #e8503a;
  --pomo-work-2: #ff7a59;
  --pomo-break: #1f9d6b;
  --pomo-break-2: #4fd6a0;
}

/* FAB живёт в правом стеке кабинета вместе с «?» опроса (bottom:124)
   и видео (bottom:72); занимает слот выше них (bottom:176), right:12 — как они. */
#pomoRoot {
  position: fixed;
  right: 12px;
  bottom: 176px;
  z-index: 1200;
  font-family: inherit;
  -webkit-user-select: none;
  user-select: none;
}

/* ── В методичке: не мешаем правому стеку (оглавление/ИИ-тьютор/zoomer) ──
   Их FAB-ы: toc bottom:24, rag(тьютор) bottom:76, zoomer bottom:128 (z-index 100),
   а их панели/оверлеи имеют z-index 101–102 и на мобилке закрывают почти весь
   экран. Поэтому: (1) садимся СЛОТОМ ВЫШЕ стека, (2) опускаем z-index НИЖЕ их
   панелей — чтобы открытое оглавление/тьютор перекрывало нас, а не наоборот. */
#pomoRoot.pomo-methodology {
  bottom: 132px;
  z-index: 95;
}
#pomoRoot.pomo-methodology #pomoFab { width: 28px; height: 28px; }
#pomoRoot.pomo-methodology #pomoFab .pomo-fab-emoji { font-size: 13px; }
@media (min-width: 732px) {
  /* выравниваемся по колонке контента, как toc-fab/rag-fab */
  #pomoRoot.pomo-methodology { right: calc(50vw - 350px + 12px); }
}

/* ---- Плавающая кнопка (FAB) ---- */
#pomoFab {
  position: relative;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  padding: 0;
  display: grid;
  place-items: center;
  color: #fff;
  background: transparent;
  box-shadow: 0 2px 8px rgba(0,0,0,0.16);
  /* по умолчанию приглушён — не перетягивает внимание; ярче на hover/при работе */
  opacity: .5;
  transition: transform .18s cubic-bezier(.22,1,.36,1), box-shadow .18s, opacity .2s;
  -webkit-tap-highlight-color: transparent;
}
#pomoFab:hover, #pomoFab:focus-visible { opacity: 1; transform: translateY(-1px) scale(1.03); box-shadow: 0 8px 20px rgba(0,0,0,0.26); }
#pomoFab:active { transform: scale(.96); }
#pomoRoot[data-running="1"] #pomoFab { opacity: .9; }   /* во время отсчёта — заметнее, но без свечения */

/* кольцо прогресса вокруг FAB рисуем conic-gradient */
#pomoFab .pomo-fab-ring {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background:
    conic-gradient(var(--pomo-fill) calc(var(--pomo-progress, 0) * 1turn), rgba(255,255,255,.22) 0);
  -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 5px), #000 calc(100% - 4px));
          mask: radial-gradient(farthest-side, transparent calc(100% - 5px), #000 calc(100% - 4px));
}
#pomoFab .pomo-fab-core {
  position: absolute;
  inset: 4px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: radial-gradient(circle at 35% 30%, var(--pomo-c2), var(--pomo-c1));
}
#pomoRoot[data-mode="work"]  { --pomo-c1: var(--pomo-work);  --pomo-c2: var(--pomo-work-2);  --pomo-fill: var(--pomo-work-2); }
#pomoRoot[data-mode="break"] { --pomo-c1: var(--pomo-break); --pomo-c2: var(--pomo-break-2); --pomo-fill: var(--pomo-break-2); }

#pomoFab .pomo-fab-emoji { font-size: 20px; line-height: 1; filter: drop-shadow(0 1px 1px rgba(0,0,0,.25)); }
/* мини-таймер показываем только когда мало места под текст не нужен — на FAB иконка */
#pomoFab .pomo-fab-time { display: none; }

/* во время отсчёта — едва заметная пульсация прозрачности, без яркого свечения */
#pomoRoot[data-running="1"] #pomoFab { animation: pomoBreathe 3s ease-in-out infinite; }
@keyframes pomoBreathe {
  0%,100% { opacity: .8; }
  50%     { opacity: 1; }
}

/* мини-счётчик помидоров на FAB */
#pomoFab .pomo-badge {
  position: absolute;
  top: -4px; right: -4px;
  min-width: 18px; height: 18px;
  padding: 0 4px;
  border-radius: 9px;
  background: #fff;
  color: #c23;
  font-size: 11px; font-weight: 800;
  display: grid; place-items: center;
  box-shadow: 0 2px 6px rgba(0,0,0,.25);
}
#pomoFab .pomo-badge[hidden] { display: none; }

/* ---- Панель ---- */
#pomoPanel {
  position: absolute;
  right: 0;
  bottom: 56px;
  width: 268px;
  background: var(--surface, #fff);
  color: var(--text, #1c1c1e);
  border: 1px solid var(--border, #e6e6ea);
  border-radius: 18px;
  box-shadow: 0 18px 48px rgba(0,0,0,0.26);
  padding: 16px 16px 14px;
  transform-origin: bottom right;
  transition: opacity .2s ease, transform .22s cubic-bezier(.22,1,.36,1);
}
#pomoPanel[hidden] {
  display: block;
  opacity: 0;
  transform: scale(.9) translateY(8px);
  pointer-events: none;
}

.pomo-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.pomo-title { font-weight: 700; font-size: 14px; display: flex; align-items: center; gap: 6px; }
.pomo-close { border: none; background: transparent; cursor: pointer; font-size: 18px; line-height: 1; color: var(--muted, #8a8a8e); padding: 4px; border-radius: 8px; }
.pomo-close:hover { background: rgba(0,0,0,.06); }

/* режимы */
.pomo-tabs { display: flex; gap: 6px; background: rgba(0,0,0,.05); padding: 4px; border-radius: 12px; margin-bottom: 14px; }
.pomo-tab {
  flex: 1; border: none; cursor: pointer; padding: 7px 0; border-radius: 9px;
  font-size: 12.5px; font-weight: 600; color: var(--muted, #6b6b70); background: transparent;
  transition: background .15s, color .15s, box-shadow .15s;
}
.pomo-tab.active { background: var(--surface, #fff); color: var(--text, #1c1c1e); box-shadow: 0 1px 4px rgba(0,0,0,.12); }

/* циферблат */
.pomo-dial { position: relative; width: 188px; height: 188px; margin: 0 auto 12px; }
.pomo-dial svg { transform: rotate(-90deg); display: block; }
.pomo-track { fill: none; stroke: rgba(0,0,0,.08); stroke-width: 12; }
.pomo-prog  { fill: none; stroke: var(--pomo-fill); stroke-width: 12; stroke-linecap: round; transition: stroke-dashoffset .9s linear, stroke .3s; }
.pomo-dial-center {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
}
.pomo-time { font-size: 42px; font-weight: 800; font-variant-numeric: tabular-nums; letter-spacing: 1px; }
.pomo-mode-label { font-size: 12px; font-weight: 600; color: var(--muted, #8a8a8e); margin-top: 2px; text-transform: uppercase; letter-spacing: .5px; }

/* кнопки управления */
.pomo-controls { display: flex; align-items: center; justify-content: center; gap: 10px; }
.pomo-btn {
  border: none; cursor: pointer; border-radius: 12px; font-weight: 700; font-size: 14px;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  transition: transform .12s, filter .15s, background .15s;
}
.pomo-btn:active { transform: scale(.95); }
.pomo-primary {
  flex: 1; height: 46px;
  color: #fff;
  background: linear-gradient(135deg, var(--pomo-c2), var(--pomo-c1));
  box-shadow: 0 6px 16px var(--pomo-fill);
}
.pomo-primary:hover { filter: brightness(1.05); }
.pomo-ghost {
  width: 46px; height: 46px; flex: 0 0 auto;
  background: rgba(0,0,0,.06); color: var(--text, #444); font-size: 18px;
}
.pomo-ghost:hover { background: rgba(0,0,0,.1); }

.pomo-foot {
  margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--border, #eee);
  display: flex; align-items: center; justify-content: space-between; font-size: 12px; color: var(--muted, #8a8a8e);
}
.pomo-count { display: flex; align-items: center; gap: 4px; font-weight: 600; }
.pomo-reset-day { border: none; background: transparent; cursor: pointer; color: var(--muted, #a0a0a4); font-size: 11px; text-decoration: underline; padding: 2px; }

/* история — мини-спарклайн за 7 дней */
.pomo-hist { margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--border, #eee); }
.pomo-hist[hidden] { display: none; }
.pomo-hist-head { display: flex; align-items: baseline; justify-content: space-between; font-size: 11px; color: var(--muted, #8a8a8e); margin-bottom: 8px; }
.pomo-hist-head > span:first-child { font-weight: 600; text-transform: uppercase; letter-spacing: .4px; }
.pomo-hist-meta { font-weight: 600; }
.pomo-hist-bars { display: flex; align-items: flex-end; justify-content: space-between; gap: 5px; height: 44px; }
.pomo-hbar-wrap { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; }
.pomo-hbar-track { width: 100%; flex: 1; display: flex; align-items: flex-end; }
.pomo-hbar { width: 100%; min-height: 2px; border-radius: 3px 3px 0 0; background: linear-gradient(var(--pomo-c2), var(--pomo-c1)); transition: height .3s; }
.pomo-hbar-lbl { font-size: 9px; color: var(--muted, #a0a0a4); margin-top: 3px; }

/* всплеск-частицы при завершении */
.pomo-burst { position: fixed; pointer-events: none; z-index: 9400; will-change: transform, opacity; font-size: 18px; }

/* мобилка */
@media (max-width: 520px) {
  /* остаёмся в общем правом стеке (right:12), панель ужимаем по ширине экрана */
  #pomoPanel {
    width: calc(100vw - 24px);
    max-width: 300px;
    /* Высокий слот FAB (bottom:176) + полная высота панели выталкивали её шапку
       с пресетами времени (25/5, 50/10, 15/3) за верх экрана — на телефоне они
       прятались под адресной строкой и были недоступны. Клампим высоту по
       динамическому вьюпорту (dvh учитывает адресную строку) и скроллим внутри. */
    max-height: calc(100vh - 248px);
    max-height: calc(100dvh - 248px);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
  }
}

/* тёмная тема, если на странице задан data-theme="dark" или prefers */
@media (prefers-color-scheme: dark) {
  #pomoPanel { --pomo-shadow: rgba(0,0,0,.5); }
}
