/**
 * Мобильная адаптация страниц /taskN/ — минимализм, dock, Pyodide и Calc.
 */

/* ——— Immersive overlay ——— */
.mobile-immersive-hint {
  position: fixed;
  inset: 0;
  z-index: 220;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: rgba(8, 10, 14, 0.78);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

.mobile-immersive-hint[hidden] {
  display: none;
}

.mobile-immersive-hint__card {
  width: min(100%, 20rem);
  padding: 1.35rem 1.25rem 1.15rem;
  border-radius: 16px;
  border: 1px solid rgba(5, 184, 125, 0.28);
  background: linear-gradient(175deg, rgba(28, 33, 38, 0.98) 0%, rgba(18, 22, 28, 0.98) 100%);
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.45);
  text-align: center;
}

[data-theme="light"] .mobile-immersive-hint__card {
  background: linear-gradient(175deg, rgba(255, 255, 255, 0.98) 0%, rgba(248, 252, 250, 0.98) 100%);
  border-color: rgba(5, 184, 125, 0.22);
}

.mobile-immersive-hint__icon {
  margin: 0 0 0.5rem;
  font-size: 2rem;
  line-height: 1;
  color: var(--green);
  animation: task-mobile-rotate-hint 2.4s ease-in-out infinite;
}

.mobile-immersive-hint__title {
  margin: 0 0 0.35rem;
  font-family: var(--font-heading);
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--white);
}

.mobile-immersive-hint__text {
  margin: 0 0 1rem;
  font-size: 0.8125rem;
  line-height: 1.45;
  color: var(--text-muted);
}

.mobile-immersive-hint__btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  margin-bottom: 0.45rem;
  padding: 0.65rem 1rem;
  border: none;
  border-radius: 12px;
  font-family: inherit;
  font-size: 0.9375rem;
  font-weight: 600;
  color: #fff;
  cursor: pointer;
  background: var(--green);
  box-shadow: 0 6px 20px rgba(5, 184, 125, 0.35);
}

.mobile-immersive-hint__dismiss {
  display: block;
  width: 100%;
  padding: 0.45rem;
  border: none;
  border-radius: 8px;
  font-family: inherit;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  background: transparent;
}

@keyframes task-mobile-rotate-hint {
  0%, 100% { transform: rotate(0deg); }
  35% { transform: rotate(-90deg); }
  70% { transform: rotate(-90deg); }
}

@media (prefers-reduced-motion: reduce) {
  .mobile-immersive-hint__icon {
    animation: none;
  }
}

/* ——— Duolingo-like dock ——— */
.task-mobile-dock {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 180;
  display: flex;
  align-items: stretch;
  gap: 0.35rem;
  padding: 0.35rem 0.45rem max(0.35rem, env(safe-area-inset-bottom, 0px));
  border-top: 1px solid rgba(5, 184, 125, 0.22);
  background: linear-gradient(180deg, rgba(18, 22, 28, 0.94) 0%, rgba(12, 16, 22, 0.98) 100%);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.35);
}

.task-mobile-dock[hidden] {
  display: none;
}

[data-theme="light"] .task-mobile-dock {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.96) 0%, rgba(248, 252, 250, 0.98) 100%);
  border-top-color: rgba(5, 184, 125, 0.18);
  box-shadow: 0 -6px 24px rgba(26, 36, 48, 0.08);
}

.task-mobile-dock__btn {
  flex: 1 1 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.15rem;
  min-height: 3rem;
  padding: 0.35rem 0.25rem;
  border: 1px solid transparent;
  border-radius: 12px;
  font-family: inherit;
  font-size: 0.6875rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--text-muted);
  cursor: pointer;
  background: transparent;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.task-mobile-dock__btn--active {
  color: #ecfdf5;
  border-color: rgba(5, 184, 125, 0.45);
  background: linear-gradient(180deg, rgba(5, 184, 125, 0.28) 0%, rgba(5, 184, 125, 0.12) 100%);
  box-shadow: 0 0 18px rgba(5, 184, 125, 0.18);
}

[data-theme="light"] .task-mobile-dock__btn--active {
  color: #047857;
  background: linear-gradient(180deg, rgba(5, 184, 125, 0.16) 0%, rgba(5, 184, 125, 0.08) 100%);
}

.task-mobile-dock__btn--immersive {
  flex: 0 0 3.25rem;
}

.task-mobile-dock__icon {
  font-size: 1.05rem;
  line-height: 1;
}

.task-mobile-dock__label {
  line-height: 1.1;
}

@media (max-width: 768px) and (pointer: coarse) {
  /* Фон и sidebar */
  body.task-mobile-mode .canvas-bg {
    display: none;
  }

  body.task-mobile-mode .task-sidebar__panel {
    width: min(88vw, var(--sidebar-width));
  }

  body.task-mobile-mode .task-sidebar__toggle {
    display: inline-flex;
  }

  body.task-mobile-mode .page.task-solve-page:not(.libreoffice-task9-page) {
    display: flex;
    flex-direction: column;
    min-height: 100dvh;
    overflow: hidden;
  }

  body.task-mobile-mode .page.task-solve-page:not(.libreoffice-task9-page) .header--task {
    flex-shrink: 0;
  }

  body.task-mobile-mode .page.task-solve-page:not(.libreoffice-task9-page) .footer {
    display: none;
  }

  body.task-mobile-mode.task-mobile-pane-statement .page.task-solve-page:not(.libreoffice-task9-page) > .main,
  body.task-mobile-mode.task-mobile-pane-statement .page.task-solve-page:not(.libreoffice-task9-page) > .task-solve-main {
    display: none !important;
  }

  body.task-mobile-mode.task-mobile-pane-trainer .page.task-solve-page:not(.libreoffice-task9-page) > .task-solve__right {
    display: none !important;
  }

  body.task-mobile-mode.task-mobile-pane-statement .page.task-solve-page:not(.libreoffice-task9-page) > .task-solve__right,
  body.task-mobile-mode.task-mobile-pane-trainer .page.task-solve-page:not(.libreoffice-task9-page) > .main,
  body.task-mobile-mode.task-mobile-pane-trainer .page.task-solve-page:not(.libreoffice-task9-page) > .task-solve-main {
    flex: 1 1 auto;
    min-height: 0;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* Отступ под dock */
  body.task-mobile-mode.libreoffice-page-task9 .neuroege-hf-task-root,
  body.task-mobile-mode .page.task-solve-page {
    padding-bottom: calc(3.85rem + env(safe-area-inset-bottom, 0px));
    box-sizing: border-box;
  }

  /* Компактная шапка */
  body.task-mobile-mode .header--task-hf {
    padding: 0.25rem 0.35rem;
  }

  body.task-mobile-mode .header--task-hf .hf-task-layout-grid__split {
    display: none;
  }

  body.task-mobile-mode .header--task-hf .hf-task-layout-grid {
    grid-template-columns: minmax(0, 1fr) !important;
  }

  body.task-mobile-mode .header--task-hf .hf-task-layout-grid__right--dual-toolbar {
    display: none;
  }

  /* Одна колонка в portrait */
  body.task-mobile-mode.libreoffice-page-task9 .libreoffice-task9-page.task-solve-page {
    grid-template-columns: minmax(0, 1fr) !important;
    grid-template-rows: minmax(0, 1fr) !important;
  }

  body.task-mobile-mode .libreoffice-task9-col-resizer,
  body.task-mobile-mode #hf-task-header-col-split {
    display: none !important;
  }

  body.task-mobile-mode.task-mobile-pane-statement .libreoffice-task9-page .task-solve-main,
  body.task-mobile-mode.task-mobile-pane-statement .task-solve-page > .main.task-solve-main {
    display: none !important;
  }

  body.task-mobile-mode.task-mobile-pane-trainer .libreoffice-task9-page .task-solve__right,
  body.task-mobile-mode.task-mobile-pane-trainer .task-solve-page > .task-solve__right {
    display: none !important;
  }

  body.task-mobile-mode.task-mobile-pane-statement .libreoffice-task9-page .task-solve__right,
  body.task-mobile-mode.task-mobile-pane-trainer .libreoffice-task9-page .task-solve-main {
    grid-column: 1 / -1 !important;
    grid-row: 1 !important;
    min-height: 0;
    height: 100%;
    padding-left: 0.35rem;
    padding-right: 0.35rem;
  }

  /* Панель действий — горизонтальный скролл, крупнее tap-targets */
  body.task-mobile-mode .libreoffice-hf-answer-actions-row--premium .libreoffice-hf-answer-actions-row__row {
    flex-wrap: nowrap;
    gap: 0.35rem;
    padding-bottom: 0.2rem;
  }

  body.task-mobile-mode .libreoffice-hf-action-btn {
    min-height: 2.35rem;
    padding: 0.42rem 0.75rem;
    font-size: 0.75rem;
  }

  /* Python / Pyodide */
  body.task-mobile-mode .python-sandbox__toolbar-btn,
  body.task-mobile-mode .python-sandbox__run-btn {
    min-height: 2.35rem;
    min-width: 2.35rem;
    padding: 0.4rem 0.65rem;
  }

  body.task-mobile-mode .python-sandbox .CodeMirror {
    font-size: 0.8125rem;
    line-height: 1.45;
  }

  body.task-mobile-mode .python-sandbox__console {
    font-size: 0.75rem;
    max-height: 28vh;
  }

  body.task-mobile-mode .python-sandbox__split-shell {
    min-height: 0;
  }

  body.task-mobile-mode #sandbox-view {
    min-height: 0;
  }

  /* Таблица Calc / Univer */
  body.task-mobile-mode .libreoffice-sheet-calc-mount,
  body.task-mobile-mode .univer-colibre-mount,
  body.task-mobile-mode #hyperformula-root {
    min-height: 0 !important;
  }

  body.task-mobile-mode .libreoffice-sheet-calc-container .univer-libre-toolbar,
  body.task-mobile-mode .libreoffice-sheet-calc-container .univer-libre-menu-bar {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  body.task-mobile-mode .libreoffice-sheet-calc-container .univer-libre-toolbar button,
  body.task-mobile-mode .libreoffice-sheet-calc-container .univer-libre-menu-bar button {
    min-height: 2rem;
    min-width: 2rem;
  }

  /* AI chat FAB — выше dock */
  body.task-mobile-mode .neuroege-ai-chat__fab {
    bottom: calc(4.25rem + env(safe-area-inset-bottom, 0px)) !important;
  }

  /* Landscape: две колонки, dock только «Экран» */
  @media (orientation: landscape) {
    body.task-mobile-mode .task-mobile-dock__btn[data-task-mobile-pane] {
      display: none;
    }

    body.task-mobile-mode .task-mobile-dock__btn--immersive {
      flex: 1 1 auto;
      flex-direction: row;
      gap: 0.45rem;
      font-size: 0.8125rem;
    }

    body.task-mobile-mode.libreoffice-page-task9 .libreoffice-task9-page.task-solve-page {
      grid-template-columns: minmax(0, 40fr) 4px minmax(0, 60fr) !important;
    }

    body.task-mobile-mode .libreoffice-task9-page .task-solve__right,
    body.task-mobile-mode .libreoffice-task9-page .task-solve-main {
      display: flex !important;
    }

    body.task-mobile-mode.libreoffice-page-task9 .neuroege-hf-task-root {
      padding-bottom: calc(3.1rem + env(safe-area-inset-bottom, 0px));
    }

    body.task-mobile-mode .header--task-hf .hf-task-layout-grid__right--dual-toolbar {
      display: flex;
    }

    body.task-mobile-mode .header--task-hf .hf-task-layout-grid {
      grid-template-columns: minmax(0, 1fr) 4px minmax(0, 1fr) !important;
    }

    body.task-mobile-mode .header--task-hf .hf-task-layout-grid__split {
      display: block;
    }
  }
}

@media (max-width: 768px) and (pointer: coarse) and (orientation: portrait) {
  body.task-mobile-mode .hf-variants-shell__toggle-text {
    font-size: 0.65rem;
  }
}
