/*
 * Единый адаптивный слой проекта.
 * Загружается последним и согласует уже существующие стили страниц.
 */

html {
  min-width: 320px;
  background: var(--paper-100);
  -webkit-text-size-adjust: 100%;
}

body {
  min-width: 320px;
  overflow-x: hidden;
}

img,
video,
canvas,
svg {
  max-width: 100%;
}

.app > main,
.page,
.page > *,
.card,
.modal,
.data-table-shell {
  min-width: 0;
}

.data-table-shell,
.stat-matrix-scroll,
.journal-shell {
  overscroll-behavior-inline: contain;
  scrollbar-width: thin;
}

/* На десктопе данные остаются обычными колонками таблицы. */
.journal-lesson-copy,
.journal-lesson-meta {
  display: contents;
}

/* Явные колонки сохраняют порядок журнала учителя на десктопе. */
.journal-table-grid .journal-date { grid-column: 1; grid-row: 1; }
.journal-table-grid .journal-subject { grid-column: 2; grid-row: 1; }
.journal-table-grid .journal-topic { grid-column: 3; grid-row: 1; }
.journal-table-grid .journal-type { grid-column: 4; grid-row: 1; }
.journal-table-grid .journal-group { grid-column: 5; grid-row: 1; }
.journal-table-grid .journal-count { grid-column: 6; grid-row: 1; }
.journal-table-grid .journal-open { grid-column: 7; grid-row: 1; }

.student-journal-row .journal-date { grid-column: 1; grid-row: 1; }
.student-journal-row .journal-subject { grid-column: 2; grid-row: 1; }
.student-journal-row .journal-topic { grid-column: 3; grid-row: 1; }
.student-journal-row .journal-type { grid-column: 4; grid-row: 1; }
.student-journal-row .student-journal-grade { grid-column: 5; grid-row: 1; }
.student-journal-row .student-journal-attendance { grid-column: 6; grid-row: 1; }

.student-journal-open {
  display: none;
}

@media (max-width: 1100px) {
  .page {
    padding-right: 22px;
    padding-left: 22px;
  }

  .filters-panel,
  .filters-panel-wide,
  .stat-controls,
  .student-stat-toolbar {
    gap: 12px;
  }

  .drawer-overview,
  .stat-tiles {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .reader-tools {
    gap: 10px;
  }
}

@media (min-width: 721px) and (max-width: 1100px) {
  .app {
    grid-template-columns: 76px minmax(0, 1fr);
  }

  .sidebar {
    z-index: 20;
    width: 76px;
    padding-inline: 10px;
  }

  .sidebar-brand {
    justify-content: center;
    padding-inline: 0;
  }

  .sidebar-brand img {
    width: 46px;
    height: 46px;
  }

  .sidebar-brand > div,
  .sidebar-item span:not(.sidebar-item-count),
  .sidebar-item-count,
  .sidebar-profile > a:first-child > div {
    display: none;
  }

  .sidebar-item {
    justify-content: center;
    min-height: 48px;
    padding-inline: 0;
  }

  .sidebar-profile {
    flex-direction: column;
    justify-content: center;
    gap: 6px;
    padding: 8px 0;
  }

  .sidebar-profile > a:first-child {
    flex: 0 0 auto;
  }

  .sidebar-logout {
    width: 38px;
    height: 32px;
  }

  .profile-layout,
  .lesson-live-grid,
  .waiting-room-workspace,
  .student-list-layout {
    grid-template-columns: minmax(0, 1fr);
  }
}

@media (max-width: 720px) {
  :root {
    --mobile-nav-height: 72px;
    --mobile-page-gutter: 12px;
  }

  html {
    background: var(--paper-50);
  }

  body {
    background: var(--paper-50);
  }

  button {
    font-size: 16px;
  }

  button,
  a,
  summary,
  label {
    -webkit-tap-highlight-color: transparent;
  }

  .app {
    display: block;
    min-height: 100dvh;
  }

  .app > main {
    min-height: 100dvh;
    padding-bottom: calc(var(--mobile-nav-height) + env(safe-area-inset-bottom));
  }

  /* Нижняя навигация как у мобильного приложения. */
  .sidebar {
    position: fixed;
    z-index: 100;
    inset: auto 0 0;
    display: block;
    width: 100%;
    height: calc(var(--mobile-nav-height) + env(safe-area-inset-bottom));
    padding: 6px max(6px, env(safe-area-inset-right)) env(safe-area-inset-bottom) max(6px, env(safe-area-inset-left));
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(21, 20, 18, 0.98);
    box-shadow: 0 -10px 30px rgba(20, 18, 14, 0.14);
    backdrop-filter: blur(18px);
  }

  .sidebar-brand,
  .sidebar-profile,
  .sidebar-spacer,
  .sidebar-item-count {
    display: none;
  }

  .sidebar-menu {
    display: flex;
    flex-direction: row;
    align-items: stretch;
    gap: 2px;
    width: 100%;
    height: 60px;
    overflow-x: auto;
    overflow-y: hidden;
    scroll-snap-type: x proximity;
    scrollbar-width: none;
  }

  .sidebar-menu::-webkit-scrollbar,
  .segmented::-webkit-scrollbar,
  .stepper::-webkit-scrollbar,
  .scene-tabs::-webkit-scrollbar {
    display: none;
  }

  .sidebar-item {
    position: relative;
    display: flex;
    flex: 1 1 48px;
    flex-direction: column;
    justify-content: center;
    gap: 4px;
    min-width: 48px;
    height: 60px;
    padding: 4px 2px;
    border-radius: 13px;
    scroll-snap-align: center;
    color: var(--text-on-ink-3);
    font-size: 9px;
    font-weight: 600;
    line-height: 1.05;
    text-align: center;
  }

  .sidebar-item span:not(.sidebar-item-count) {
    display: block;
    width: 100%;
    max-height: 18px;
    overflow: hidden;
    white-space: normal;
  }

  .sidebar-item svg {
    width: 21px;
    height: 21px;
    stroke-width: 1.9;
  }

  .sidebar-item:hover {
    background: transparent;
  }

  .sidebar-item.active {
    background: rgba(215, 174, 70, 0.13);
    color: var(--gold-500);
    font-weight: 700;
  }

  .sidebar-item.active::before {
    position: absolute;
    top: -6px;
    left: 50%;
    width: 28px;
    height: 3px;
    border-radius: 0 0 4px 4px;
    background: var(--gold-500);
    content: "";
    transform: translateX(-50%);
  }

  /* Компактная верхняя строка. */
  .topbar {
    position: sticky;
    z-index: 50;
    top: 0;
    height: 56px;
    flex-wrap: nowrap;
    padding: 0 max(12px, env(safe-area-inset-right)) 0 max(12px, env(safe-area-inset-left));
    background: rgba(255, 255, 255, 0.94);
    box-shadow: 0 1px 0 var(--hairline);
  }

  .topbar-day {
    min-width: 0;
    gap: 9px;
  }

  .topbar-cal {
    flex-basis: 34px;
    width: 34px;
    height: 34px;
    border-radius: 11px;
  }

  .topbar-dayinfo,
  .topbar-date-main,
  .topbar-lessons-sub {
    min-width: 0;
  }

  .topbar-date-main,
  .topbar-lessons-sub {
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .topbar-date-main {
    font-size: 13px;
  }

  .topbar-lessons-sub {
    font-size: 10.5px;
  }

  .topbar-right {
    flex: 0 0 auto;
  }

  .notification-bell {
    width: 40px;
    height: 40px;
    background: var(--paper-100);
  }

  .notifications-menu {
    position: fixed;
    top: 62px;
    right: 8px;
    left: 8px;
    width: auto;
    max-height: calc(100dvh - 150px);
    border-radius: 18px;
  }

  .notifications-list {
    max-height: calc(100dvh - 285px);
  }

  /* Общая геометрия страниц и карточек. */
  .page,
  .profile-page,
  .repetition-page {
    width: 100%;
    padding: 18px var(--mobile-page-gutter) 26px;
  }

  .page-head,
  .lesson-head,
  .notes-page-head,
  .student-profile-main,
  .student-stat-toolbar,
  .filter-actions,
  .stat-controls,
  .drawer-card-head {
    align-items: stretch;
    flex-direction: column;
  }

  .page-head {
    gap: 14px;
    margin-bottom: 18px;
  }

  .page-title,
  .page-head h1,
  .lesson-head h1 {
    font-size: clamp(25px, 8vw, 32px);
    line-height: 1.05;
  }

  .page-sub {
    max-width: 36rem;
    font-size: 12.5px;
    line-height: 1.5;
  }

  .page-head-actions,
  .lesson-head-actions,
  .filter-actions {
    display: flex;
    width: 100%;
    gap: 8px;
  }

  .page-head-actions > .btn,
  .lesson-head-actions > .btn,
  .filter-actions > .btn,
  .form-actions > .btn {
    flex: 1 1 auto;
    justify-content: center;
  }

  .btn,
  .input,
  select.input {
    min-height: 44px;
  }

  .btn-sm {
    min-height: 40px;
  }

  .card,
  .student-profile,
  .drawer-card,
  .profile-card,
  .schedule-card,
  .filters-panel,
  .filters-panel-wide {
    border-radius: 16px;
  }

  .card,
  .drawer-card,
  .student-profile {
    padding: 16px;
  }

  .filters-panel,
  .filters-panel-wide,
  .filter-row,
  .stat-filters {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    width: 100%;
  }

  .filters-panel .input,
  .filters-panel-wide .input,
  .filter-row .input,
  .stat-filters .input,
  .stat-filters select {
    width: 100%;
    min-width: 0;
  }

  /* Журнал: компактные фильтры без длинной вертикальной колонки. */
  .filters-panel {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    padding: 12px;
    margin-bottom: 14px;
    border-radius: 14px;
  }

  .filters-panel .filter-search-row,
  .filters-panel:not(.filters-panel--student) > .filter-field:last-of-type,
  .filters-panel .filter-actions {
    grid-column: 1 / -1;
  }

  .student-list-page .filters-panel > .filter-field:last-of-type {
    grid-column: auto;
  }

  .filters-panel .filter-field {
    gap: 4px;
  }

  .filters-panel .filter-field > span {
    font-size: 11px;
  }

  .filters-panel .input,
  .filters-panel .btn {
    min-height: 40px;
  }

  .filters-panel .input {
    padding-right: 10px;
    padding-left: 10px;
    font-size: 14px;
  }

  .filters-panel .filter-actions {
    flex-direction: row;
  }

  .filters-panel .filter-actions .btn {
    min-width: 0;
    padding-right: 12px;
    padding-left: 12px;
  }

  .filters-panel .filter-actions .btn-secondary {
    flex-grow: 0.7;
  }

  .segmented,
  .student-list-tabs,
  .student-stat-tabs,
  .stat-subtabs,
  .stat-period,
  .completed-tabs,
  .scene-tabs {
    display: flex;
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    overscroll-behavior-inline: contain;
    scrollbar-width: none;
  }

  .segmented > *,
  .student-list-tabs > *,
  .student-stat-tabs > *,
  .stat-subtabs > *,
  .stat-period > * {
    flex: 1 0 max-content;
    min-height: 40px;
    white-space: nowrap;
  }

  .data-table-shell,
  .journal-shell,
  .stat-matrix-scroll {
    width: calc(100% + 2 * var(--mobile-page-gutter));
    margin-inline: calc(-1 * var(--mobile-page-gutter));
    overflow-x: auto;
    border-right: 0;
    border-left: 0;
    border-radius: 0;
  }

  /* Таблицы статистики показывают все значения сразу, без горизонтальной прокрутки. */
  .stats-body .stat-matrix-scroll {
    width: 100%;
    margin-inline: 0;
    overflow-x: visible;
  }

  .stats-body .stat-matrix {
    min-width: 0;
    table-layout: fixed;
  }

  .stats-body .stat-matrix th,
  .stats-body .stat-matrix td {
    padding: 8px 3px;
  }

  .stats-body .stat-matrix th {
    overflow: hidden;
    font-size: 0;
    white-space: nowrap;
  }

  .stats-body .stat-matrix th::after {
    color: var(--text-3);
    font-size: 8px;
    line-height: 1;
  }

  .stats-body .stat-matrix th:first-child,
  .stats-body .stat-matrix td:first-child {
    width: 38%;
  }

  .stats-body .stat-matrix th:first-child::after { content: "Ученик"; }
  .stats-body [data-stat-table="overview"] th:nth-child(2)::after { content: "Балл"; }
  .stats-body [data-stat-table="overview"] th:nth-child(3)::after { content: "Посещ."; }
  .stats-body [data-stat-table="overview"][data-has-repetition="true"] th:nth-child(4)::after { content: "Повторы"; }
  .stats-body [data-stat-table="overview"][data-has-repetition="true"] th:nth-child(5)::after,
  .stats-body [data-stat-table="overview"][data-has-repetition="false"] th:nth-child(4)::after { content: "Итог"; }
  .stats-body [data-stat-table="grades"] th:nth-child(2)::after { content: "Урок"; }
  .stats-body [data-stat-table="grades"] th:nth-child(3)::after { content: "Тест"; }
  .stats-body [data-stat-table="grades"] th:nth-child(4)::after { content: "Экз."; }
  .stats-body [data-stat-table="grades"] th:nth-child(5)::after { content: "Ср. балл"; }
  .stats-body [data-stat-table="attendance"] th:nth-child(2)::after,
  .stats-body [data-stat-table="repetition"] th:nth-child(2)::after { content: "Вовремя"; }
  .stats-body [data-stat-table="attendance"] th:nth-child(3)::after,
  .stats-body [data-stat-table="repetition"] th:nth-child(3)::after { content: "Опозд."; }
  .stats-body [data-stat-table="attendance"] th:nth-child(4)::after,
  .stats-body [data-stat-table="repetition"] th:nth-child(4)::after { content: "Пропуск"; }

  .stats-body .stat-matrix .ava {
    display: none;
  }

  .stats-body .stat-matrix .who {
    gap: 0;
  }

  .stats-body .stat-matrix .who b {
    overflow-wrap: anywhere;
    font-size: 11px;
    line-height: 1.15;
  }

  .stats-body .stat-matrix .who small {
    margin-top: 2px;
    overflow-wrap: anywhere;
    font-size: 8px;
    line-height: 1.15;
  }

  .stats-body .stat-matrix .cell {
    min-width: 0;
    padding: 3px 5px;
    font-size: 10px;
  }

  .stats-body .stat-matrix td .cnt {
    font-size: 12px;
  }

  .drawer-chart-canvas.is-sparse {
    height: 150px;
  }

  .student-statistics-page .drawer-overview,
  .students-drawer-panel .drawer-overview {
    grid-template-columns: repeat(auto-fit, minmax(86px, 1fr));
    gap: 6px;
  }

  .stat-counts {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .data-table-head,
  .data-table-row {
    min-width: 680px;
  }

  /* На телефоне журнал остаётся таблицей, только с сокращённым набором колонок. */
  .journal-shell .data-table-head {
    display: grid;
    grid-template-columns: 68px minmax(0, 1fr) 72px 14px;
    gap: 8px;
    min-width: 0;
    padding: 8px 10px;
    font-size: 9px;
  }

  .journal-shell .data-table-head > :nth-child(1) { grid-column: 1; }
  .journal-shell .data-table-head > :nth-child(2) { grid-column: 2; }
  .journal-shell .data-table-head > :nth-child(4) { grid-column: 3; }
  .journal-shell .data-table-head > :nth-child(7) { grid-column: 4; }

  .journal-shell .data-table-head > :nth-child(3),
  .journal-shell .data-table-head > :nth-child(5),
  .journal-shell .data-table-head > :nth-child(6) {
    display: none;
  }

  .journal-shell {
    display: block;
    width: 100%;
    margin: 0;
    overflow: hidden;
    border: 1px solid var(--hairline);
    border-radius: 12px;
    background: var(--paper-0);
  }

  .journal-shell .journal-table-grid.data-table-row {
    display: grid;
    gap: 4px 8px;
    min-width: 0;
    min-height: 58px;
    padding: 10px;
    border: 0;
    border-bottom: 1px solid var(--hairline);
    border-radius: 0;
    background: var(--paper-0);
  }

  .journal-shell .journal-table-grid.data-table-row:last-child {
    border-bottom: 0;
  }

  .journal-shell .journal-table-grid.data-table-row {
    grid-template-columns: 68px minmax(0, 1fr) 72px 14px;
    align-items: center;
  }

  .journal-date {
    grid-column: 1;
    grid-row: 1;
    color: var(--text-2);
    font-size: 12px;
    white-space: nowrap;
  }

  .journal-lesson-copy {
    display: flex;
    grid-column: 1;
    grid-row: 2;
    align-items: baseline;
    min-width: 0;
    gap: 5px;
  }

  .journal-subject {
    flex: 0 0 auto;
    font-size: 14px;
    line-height: 1.25;
  }

  .journal-topic {
    overflow: hidden;
    color: var(--text-2);
    font-size: 12px;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .journal-topic:not(:empty)::before {
    content: "· ";
  }

  .journal-shell .journal-lesson-copy {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, auto));
    grid-column: 2;
    grid-row: 1;
    align-content: center;
    justify-content: start;
    gap: 1px 4px;
    text-align: left;
  }

  .journal-shell .journal-group {
    grid-column: 2;
    grid-row: 1;
    overflow: hidden;
    color: var(--text-1);
    font-size: 13px;
    font-weight: 600;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .journal-shell .journal-subject {
    grid-column: 1;
    grid-row: 1;
    overflow: hidden;
    font-size: 13px;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .journal-shell .journal-subject::after {
    margin-left: 4px;
    content: "—";
  }

  .journal-shell .journal-topic {
    grid-column: 1 / -1;
    grid-row: 2;
    font-size: 10px;
  }

  .journal-shell .journal-topic:empty {
    display: none;
  }

  .journal-shell .journal-topic:not(:empty)::before {
    content: none;
  }

  .journal-shell .journal-type,
  .student-journal-row .journal-type {
    grid-row: 1;
    justify-self: end;
  }

  .journal-shell .journal-type {
    grid-column: 3;
    align-self: center;
    justify-self: center;
  }

  .student-journal-row .journal-type {
    grid-column: 2;
  }

  .journal-lesson-meta {
    display: flex;
    grid-column: 2;
    grid-row: 2;
    align-items: center;
    justify-content: flex-end;
    gap: 7px;
    white-space: nowrap;
  }

  .journal-group,
  .journal-count {
    color: var(--text-2);
    font-size: 11px;
  }

  .journal-shell .journal-group {
    flex: 0 0 auto;
  }

  .journal-shell .journal-lesson-meta {
    display: none;
  }

  .journal-count::after {
    content: " уч.";
  }

  .journal-shell .journal-open {
    grid-column: 4;
    grid-row: 1;
    align-self: center;
  }

  /* Мобильная таблица учеников без горизонтальной прокрутки. */
  .data-table-scroll:has(.student-list-table) {
    width: 100%;
    margin: 0;
    overflow: hidden;
    border: 1px solid var(--hairline);
    border-radius: 12px;
  }

  .student-list-table {
    display: block;
    width: 100%;
    min-width: 0;
    margin: 0;
    overflow: hidden;
    border: 0;
    border-radius: 0;
    background: var(--paper-0);
  }

  .student-list-table .student-list-grid {
    grid-template-columns: minmax(96px, 1.4fr) minmax(78px, 1fr) 46px 50px;
    gap: 6px;
    min-width: 0;
  }

  .student-list-table .data-table-head {
    display: grid;
    padding: 9px 8px;
    font-size: 9px;
  }

  .student-list-table .data-table-head > :first-child,
  .student-list-grid.data-table-row > :first-child {
    display: none;
  }

  .student-list-table .data-table-head > :nth-child(3),
  .student-list-table .data-table-head > :nth-child(4),
  .student-list-table .data-table-head > :nth-child(5) {
    font-size: 0;
  }

  .student-list-table .data-table-head > :nth-child(3)::after {
    content: "Группа · предмет";
  }

  .student-list-table .data-table-head > :nth-child(4)::after {
    content: "Балл";
  }

  .student-list-table .data-table-head > :nth-child(5)::after {
    content: "Посещ.";
  }

  .student-list-table .data-table-head > :nth-child(3)::after,
  .student-list-table .data-table-head > :nth-child(4)::after,
  .student-list-table .data-table-head > :nth-child(5)::after {
    font-size: 9px;
  }

  .student-list-table .student-list-grid.data-table-row {
    display: grid;
    align-items: center;
    padding: 10px 8px;
    border: 0;
    border-bottom: 1px solid var(--hairline);
    border-radius: 0;
    background: var(--paper-0);
  }

  .student-list-table .student-list-grid.data-table-row:last-child {
    border-bottom: 0;
  }

  .student-list-grid.data-table-row > :nth-child(2) {
    grid-column: 1;
    grid-row: 1;
  }

  .student-list-grid.data-table-row > :nth-child(3) {
    grid-column: 2;
    grid-row: 1;
  }

  .student-list-grid.data-table-row > :nth-child(4),
  .student-list-grid.data-table-row > :nth-child(5) {
    display: block;
    min-height: 0;
    padding: 0;
    background: transparent;
    font-size: 12px;
    text-align: center;
  }

  .student-list-grid.data-table-row > :nth-child(4) {
    grid-column: 3;
    grid-row: 1;
  }

  .student-list-grid.data-table-row > :nth-child(5) {
    grid-column: 4;
    grid-row: 1;
  }

  .student-list-table .student-table-person strong {
    font-size: 13px;
  }

  .student-list-table .student-table-person {
    gap: 7px;
  }

  .student-list-table .student-table-person .ava {
    width: 30px;
    height: 30px;
    font-size: 10px;
  }

  .student-list-table .student-table-groups {
    display: grid;
    gap: 2px;
  }

  .student-list-table .student-table-groups > span {
    display: block;
    padding: 0;
    background: transparent;
    font-size: 10px;
    line-height: 1.25;
    white-space: normal;
  }

  /* Журнал ученика остаётся в прежнем карточном виде. */
  .student-journal-shell {
    display: grid;
    width: 100%;
    margin: 0;
    gap: 8px;
    overflow: visible;
    border: 0;
    background: transparent;
  }

  .student-journal-head {
    display: none;
  }

  .student-journal-row {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto 18px;
    gap: 4px 10px;
    min-width: 0;
    padding: 10px 12px;
    border: 1px solid var(--hairline);
    border-radius: 12px;
    background: var(--paper-0);
    column-gap: 14px;
    align-items: center;
  }

  .student-journal-row .journal-lesson-copy {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, auto));
    grid-column: 2;
    grid-row: 1;
    align-content: center;
    justify-content: center;
    gap: 1px 4px;
    min-width: 0;
    padding-left: 2px;
    text-align: center;
  }

  .student-journal-row .journal-subject {
    grid-column: 1;
    grid-row: 1;
    overflow: hidden;
    font-size: 13px;
    line-height: 1.2;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .student-journal-row .journal-subject::after {
    margin-left: 4px;
    content: "—";
  }

  .student-journal-row .journal-type {
    grid-column: 2;
    grid-row: 1;
    justify-self: start;
  }

  .student-journal-row .journal-topic {
    grid-column: 1 / -1;
    grid-row: 2;
    font-size: 10px;
  }

  .student-journal-row .journal-topic:not(:empty)::before {
    content: none;
  }

  .student-journal-row .journal-topic:empty {
    display: none;
  }

  .student-journal-row .student-journal-grade {
    grid-column: 1;
    grid-row: 1;
    width: 28px;
    height: 28px;
  }

  .student-journal-row .student-journal-attendance {
    display: none;
  }

  .student-journal-row .journal-lesson-meta {
    display: grid;
    grid-column: 3;
    grid-row: 1;
    justify-items: end;
  }

  .student-journal-open {
    display: block;
    grid-column: 4;
    grid-row: 1;
    align-self: center;
  }

  .student-journal-row .journal-lesson-meta .pill {
    gap: 4px;
    padding: 3px 6px;
    font-size: 10px;
  }

  /* Модальные окна на телефоне открываются снизу. */
  .modal-backdrop {
    align-items: flex-end;
    padding: 0;
  }

  .modal {
    width: 100%;
    max-width: none;
    max-height: 92dvh;
    margin: 0;
    overflow-y: auto;
    border-radius: 22px 22px 0 0;
  }

  .modal-head,
  .create-modal-head {
    position: sticky;
    z-index: 2;
    top: 0;
    background: var(--paper-0);
  }

  .modal-actions,
  .create-modal-actions {
    position: sticky;
    bottom: 0;
    display: flex;
    gap: 8px;
    background: var(--paper-0);
  }

  .modal-actions .btn,
  .create-modal-actions .btn {
    flex: 1;
    justify-content: center;
  }

  /* Расписание и состояния урока. */
  .week-strip {
    overflow-x: auto;
    overscroll-behavior-inline: contain;
    scrollbar-width: none;
  }

  .schedule-row {
    border-radius: 14px;
  }

  .planned-lesson-notice,
  .waiting-lesson-room,
  .completed-lesson-room {
    border-radius: 18px;
  }

  .planned-countdown-grid {
    gap: 5px;
  }

  .completed-summary,
  .drawer-overview,
  .stat-tiles {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  /* Ученики и статистика. */
  .student-profile {
    gap: 14px;
    padding: 16px;
  }

  .student-profile-main {
    gap: 12px;
  }

  .student-profile-id h1 {
    font-size: 25px;
  }

  .student-profile-subjects {
    gap: 8px;
    padding-top: 14px;
  }

  .student-profile-subject {
    flex-basis: 100%;
    padding: 9px;
  }

  .student-stat-toolbar-label {
    display: none;
  }

  .stat-controls {
    padding: 10px;
  }

  .stat-hero-body {
    align-items: flex-start;
  }

  .stat-hero-metrics {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    width: 100%;
    gap: 10px;
  }

  .stat-hero-metrics > * {
    padding: 10px;
    border-radius: 11px;
    background: rgba(255, 255, 255, 0.6);
  }

  .stat-counts {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px;
  }

  .stat-counts > div {
    padding: 11px 9px;
  }

  .stat-counts small {
    font-size: 10px;
  }

  .stat-counts b {
    font-size: 20px;
  }

  .stat-status-legend {
    flex-wrap: wrap;
    gap: 8px 12px;
  }

  .stat-alert-row {
    align-items: flex-start;
    flex-wrap: wrap;
  }

  .stat-alert-row .stat-rank-name {
    flex-basis: calc(100% - 52px);
  }

  /* Профиль, заметки и повторы. */
  .profile-page {
    padding-bottom: 26px;
  }

  .profile-hero {
    gap: 16px;
    padding: 18px;
    border-radius: 18px;
  }

  .profile-card {
    padding: 16px;
  }

  .profile-photo-edit {
    align-items: flex-start;
    gap: 14px;
  }

  .notes-grid {
    gap: 10px;
  }

  .note-arc {
    min-height: 150px;
    border-radius: 16px;
  }

  .modal-backdrop:has(.note-modal) {
    padding: 0;
  }

  .modal.note-modal {
    width: 100%;
    height: 92dvh;
    border-radius: 22px 22px 0 0;
  }

  .note-modal-actions .btn span {
    display: none;
  }

  .repetition-board {
    overflow: hidden;
    border-radius: 18px;
  }

  /* Коран: инструменты остаются доступными, не вылезая за экран. */
  .quran-main {
    min-height: 100dvh;
  }

  .reader-tools {
    position: sticky;
    z-index: 30;
    top: 0;
    gap: 8px;
    padding: 8px 10px;
  }

  .reader-tools-left,
  .reader-tools-right {
    min-width: 0;
  }

  .reader-tools-right .seg {
    overflow-x: auto;
    scrollbar-width: none;
  }

  .reader-tools-right .seg button,
  .reader-tools-right .seg a {
    min-height: 40px;
    white-space: nowrap;
  }

  .surah-picker-panel {
    position: fixed;
    top: 58px;
    right: 8px;
    left: 8px;
    width: auto;
    max-height: calc(100dvh - 150px);
  }

  .ayah-block {
    border-radius: 16px;
  }

  .ayah-block-head {
    align-items: flex-start;
  }

  .ayah-block-main-actions,
  .ayah-block-side-actions {
    flex-wrap: wrap;
  }

  /* Домашняя работа: широкие панели становятся лентой карточек. */
  .hw-page,
  .ho-scroll,
  .hc-scroll {
    padding-right: var(--mobile-page-gutter);
    padding-left: var(--mobile-page-gutter);
  }

  .hw-filters,
  .hw-create-grid,
  .hc-grid,
  .ht-stats-grid,
  .ht-grade-inner {
    grid-template-columns: minmax(0, 1fr);
  }

  .ho-bar,
  .hc-bar {
    gap: 8px;
    padding-inline: 12px;
  }

  .ho-crumb,
  .hc-crumb,
  .ho-bar-div,
  .hc-bar-div {
    display: none;
  }

  .ht-row.head {
    display: none;
  }

  .ht-row {
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 10px;
    padding: 14px;
  }

  .ht-status-cell,
  .ht-grade-cell,
  .ht-comment {
    grid-column: 1;
  }

  .ht-action {
    grid-column: 2;
    grid-row: 1 / span 3;
    align-self: center;
  }
}

/* iPhone увеличивает страницу при фокусе, если текст в поле меньше 16px.
   !important нужен здесь потому, что стили отдельных страниц точнее селектора input. */
@media (max-width: 720px), (hover: none) and (pointer: coarse) {
  input,
  select,
  textarea,
  [contenteditable="true"] {
    font-size: 16px !important;
  }
}

/* Комната урока не использует обычное меню, для неё отдельная мобильная оболочка. */
@media (min-width: 641px) and (max-width: 900px) {
  .room-with-comms .room-topbar {
    gap: 8px;
    padding: 8px 12px;
  }

  .room-with-comms .room-back {
    width: 38px;
    height: 38px;
    padding: 0;
    justify-content: center;
    flex: 0 0 38px;
  }

  .room-with-comms .room-title {
    padding-left: 0;
  }

  .room-with-comms .room-actions .btn {
    display: inline-flex;
    min-height: 38px;
    padding: 0 13px;
    white-space: nowrap;
  }
}

@media (max-width: 640px) {
  .room,
  .room-with-comms {
    min-height: 100dvh;
  }

  .room-with-comms {
    --comms-edge: 5px;
    --comms-rail-width: 54px;
    --comms-panel-width: calc(100vw - 64px);
    padding-right: 62px;
  }

  .room-with-comms .room-topbar {
    min-height: 54px;
    margin-right: -62px;
    padding: 6px 10px;
  }

  .room-brand,
  .room-divider,
  .room-lesson-meta {
    display: none;
  }

  .room-topbar-left,
  .room-topbar-right {
    gap: 6px;
  }

  .room-back,
  .room-icon-btn,
  .room-end-btn {
    min-width: 40px;
    min-height: 40px;
  }

  .room-end-btn span,
  .room-back span {
    display: none;
  }

  .room-timer {
    min-width: 74px;
  }

  .room-body {
    min-height: calc(100dvh - 54px);
  }

  .scene-tabs {
    min-height: 46px;
    padding-inline: 8px;
  }

  .scene-tab {
    flex: 1 0 max-content;
    min-height: 44px;
    padding-inline: 12px;
  }

  .scene-canvas {
    min-height: calc(100dvh - 100px);
  }

  .lesson-comms-rail {
    top: 59px;
    bottom: 5px;
    border-radius: 15px;
  }

  .lesson-comms-tab {
    width: 44px;
    min-height: 44px;
  }

  .lesson-comms-person,
  .lesson-comms-rail .lesson-comms-more {
    width: 38px;
    height: 38px;
    flex-basis: 38px;
  }

  .lesson-comms-own-mic {
    width: 44px;
    height: 44px;
    flex-basis: 44px;
  }

  .lesson-comms-panel {
    max-height: calc(100dvh - 64px);
    border-radius: 16px 0 0 16px;
  }

  .board-tools-dock {
    right: 8px;
    bottom: 8px;
    left: 8px;
    width: auto;
  }

  .board-tools {
    max-width: calc(100vw - 82px);
    overflow-x: auto;
    scrollbar-width: none;
  }

  .board-pages {
    max-width: calc(100vw - 86px);
  }

  .scene-canvas[data-layout="split"] {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: repeat(2, minmax(240px, 1fr));
  }

  .scene-canvas[data-layout="split"] .workspace-gutter {
    width: 100%;
    height: 8px;
    cursor: row-resize;
  }
}

@media (max-width: 420px) {
  .topbar-lessons-sub {
    display: none;
  }

  .topbar-dayinfo {
    gap: 0;
  }

  .page,
  .profile-page,
  .repetition-page {
    padding-top: 14px;
  }

  .completed-summary,
  .stat-tiles {
    grid-template-columns: minmax(0, 1fr);
  }

  .stat-counts {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .planned-countdown-unit strong {
    font-size: 25px;
  }

  .planned-countdown-unit span {
    font-size: 7.5px;
  }

  .reader-tools {
    align-items: stretch;
    flex-direction: column;
  }

  .surah-picker-panel {
    top: 104px;
  }

  .player-track-top {
    gap: 6px;
  }
}

/* Полноценная мобильная оболочка идущего урока. */
@media (max-width: 640px) {
  .room.room-with-comms {
    --lesson-mobile-bar-height: 66px;
    box-sizing: border-box;
    width: 100%;
    height: 100dvh;
    min-height: 0;
    padding-right: 0;
    padding-bottom: calc(var(--lesson-mobile-bar-height) + env(safe-area-inset-bottom) + var(--safe-bottom-gap, 0px));
  }

  .room-with-comms .room-topbar {
    display: grid;
    grid-template-columns: 40px minmax(0, 1fr) auto;
    gap: 7px;
    width: 100%;
    height: 58px;
    min-height: 58px;
    margin-right: 0;
    padding: 6px 8px;
  }

  .room-with-comms .room-back {
    display: grid;
    place-items: center;
    width: 40px;
    min-width: 40px;
    height: 40px;
    min-height: 40px;
    padding: 0;
    background: rgba(255, 255, 255, 0.06);
  }

  .room-with-comms .room-back svg {
    width: 19px;
    height: 19px;
  }

  .room-with-comms .room-title {
    min-width: 0;
    padding: 0;
  }

  .room-with-comms .room-title h1 {
    font-size: 13px;
    line-height: 1.2;
  }

  .room-with-comms .room-actions {
    display: flex;
    min-width: 0;
    gap: 5px;
  }

  /* Старые стили скрывали эту кнопку на планшете и телефоне. */
  .room-with-comms .room-actions .btn {
    display: inline-flex;
    min-width: 0;
    min-height: 38px;
    height: 38px;
    padding: 0 10px;
    border-radius: 10px;
    font-size: 10.5px;
    line-height: 1;
    white-space: nowrap;
  }

  .room-with-comms .room-actions .btn svg {
    width: 15px;
    height: 15px;
  }

  .room-with-comms .room-actions .btn span {
    display: inline;
  }

  .room-with-comms .lesson-live-join-form .btn {
    max-width: 116px;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .room-with-comms .room-timer {
    min-width: 66px;
    min-height: 38px;
    justify-content: center;
    gap: 5px;
    padding: 0 8px;
    font-size: 10.5px;
  }

  .room-with-comms .room-timer svg {
    width: 13px;
    height: 13px;
  }

  .room-with-comms .room-body {
    min-height: 0;
    padding: 5px;
  }

  .room-with-comms .scene {
    border-radius: 13px;
    clip-path: inset(0 round 13px);
  }

  .room-with-comms .scene-tabs {
    min-height: 45px;
    gap: 2px;
    padding: 0 49px 0 5px;
    /* 4 вкладки (Сцена·Видео·Журнал·Заметки) не влезают на узкий экран — даём прокрутку. */
    overflow-x: auto;
    scrollbar-width: none;
  }

  .room-with-comms .scene-tabs::-webkit-scrollbar {
    display: none;
  }

  .room-with-comms .scene:has([data-scene-panel="scene"]:not([hidden])) .scene-focus-toggle,
  .room-with-comms .scene:has([data-scene-panel="video"]:not([hidden])) .scene-focus-toggle {
    display: grid;
    width: 37px;
    height: 37px;
  }

  .room-with-comms .scene-tab {
    flex: 1 0 max-content;
    min-height: 44px;
    padding: 9px 10px;
    font-size: 11.5px;
  }

  .room-with-comms .scene-tab-divider {
    margin-inline: 1px;
  }

  /* Разделение экрана на телефоне слишком тесное; вкладки остаются доступны сверху. */
  .room-with-comms .workspace-controls {
    display: none;
  }

  .room-with-comms .scene-canvas {
    min-height: 0;
  }

  .room-with-comms [data-scene-panel="scene"] {
    padding: 0;
  }

  .room-with-comms .live-panel,
  .room-with-comms .live-panel-wide {
    width: calc(100% - 16px);
    margin: 12px auto 18px;
  }

  /* Журнал урока становится набором карточек учеников. */
  :is(.room-with-comms, .completed-journal-panel) .jt-panel {
    margin-block: 12px 18px;
  }

  :is(.room-with-comms, .completed-journal-panel) .jt-head {
    flex-wrap: nowrap;
    align-items: center;
    gap: 8px;
    margin-bottom: 10px;
  }

  :is(.room-with-comms, .completed-journal-panel) .jt-title {
    font-size: 19px;
    white-space: nowrap;
  }

  :is(.room-with-comms, .completed-journal-panel) .jt-stats {
    width: auto;
    margin-left: auto;
    gap: 4px;
    overflow: visible;
    border: 0;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
  }

  :is(.room-with-comms, .completed-journal-panel) .jt-stat {
    flex: 0 0 auto;
    min-width: 0;
    padding: 6px 8px;
    border: 1px solid var(--hairline);
    border-radius: 10px;
    background: var(--paper-0);
  }

  :is(.room-with-comms, .completed-journal-panel) .jt-stat + .jt-stat {
    border-left: 1px solid var(--hairline);
  }

  :is(.room-with-comms, .completed-journal-panel) .jt-stat-copy small {
    display: none;
  }

  :is(.room-with-comms, .completed-journal-panel) .jt-stat-icon {
    display: grid;
    width: 20px;
    height: 20px;
  }

  :is(.room-with-comms, .completed-journal-panel) .jt-stat-icon svg {
    width: 11px;
    height: 11px;
  }

  :is(.room-with-comms, .completed-journal-panel) .jt-stat-copy strong {
    font-size: 12px;
  }

  :is(.room-with-comms, .completed-journal-panel) .jt-table {
    display: grid;
    gap: 8px;
    overflow: visible;
    border: 0;
    background: transparent;
    box-shadow: none;
  }

  :is(.room-with-comms, .completed-journal-panel) .jt-thead {
    display: none;
  }

  :is(.room-with-comms, .completed-journal-panel) .jt-tbody {
    display: grid;
    min-width: 0;
    gap: 8px;
  }

  :is(.room-with-comms, .completed-journal-panel) .jt-row {
    overflow: visible;
    border: 1px solid var(--hairline);
    border-radius: 13px;
    background: var(--paper-0);
    box-shadow: var(--shadow-1);
  }

  :is(.room-with-comms, .completed-journal-panel) .jt-cells {
    grid-template-columns: minmax(0, 1fr) auto 50px;
    gap: 9px 10px;
    min-width: 0;
    min-height: 0;
    padding: 10px 11px;
  }

  :is(.room-with-comms, .completed-journal-panel) .jt-student::before,
  :is(.room-with-comms, .completed-journal-panel) .jt-att::before,
  :is(.room-with-comms, .completed-journal-panel) .jt-grade::before {
    display: block;
    margin-bottom: 5px;
    color: var(--text-3);
    font-size: 8.5px;
    font-weight: 700;
    letter-spacing: 0.05em;
    line-height: 1;
    text-transform: uppercase;
  }

  :is(.room-with-comms, .completed-journal-panel) .jt-student::before {
    content: "Ученица";
    grid-column: 1 / -1;
  }

  :is(.room-with-comms, .completed-journal-panel) .jt-att::before {
    content: "Присутствие";
  }

  :is(.room-with-comms, .completed-journal-panel) .jt-grade::before {
    content: "Оценка";
  }

  :is(.room-with-comms, .completed-journal-panel) .jt-student {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    grid-column: 1;
    grid-row: 1;
    align-content: start;
    gap: 6px 8px;
  }

  :is(.room-with-comms, .completed-journal-panel) .jt-grade {
    grid-column: 3;
    grid-row: 1;
    flex-direction: column;
    align-items: flex-end;
    justify-content: flex-start;
  }

  :is(.room-with-comms, .completed-journal-panel) .jt-att {
    grid-column: 2;
    grid-row: 1;
    text-align: center;
  }

  :is(.room-with-comms, .completed-journal-panel) .jt-comment {
    grid-column: 1 / -1;
    grid-row: 2;
  }

  :is(.room-with-comms, .completed-journal-panel) .jt-comment-details > summary {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
    gap: 8px;
    min-height: 34px;
    padding: 7px 9px;
    border: 1px solid var(--hairline);
    border-radius: 9px;
    background: var(--paper-50);
    cursor: pointer;
  }

  :is(.room-with-comms, .completed-journal-panel) .jt-comment-summary-title {
    color: var(--text-2);
    font-size: 10px;
    font-weight: 700;
  }

  :is(.room-with-comms, .completed-journal-panel) .jt-comment-preview {
    min-width: 0;
    overflow: hidden;
    color: var(--text-3);
    font-size: 11px;
    text-align: right;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  :is(.room-with-comms, .completed-journal-panel) .jt-comment-details > summary svg {
    width: 13px;
    height: 13px;
    color: var(--text-3);
    transition: transform var(--dur-2) var(--ease);
  }

  :is(.room-with-comms, .completed-journal-panel) .jt-comment-details[open] > summary svg {
    transform: rotate(180deg);
  }

  :is(.room-with-comms, .completed-journal-panel) .jt-comment-field {
    display: none !important;
    padding-top: 7px;
  }

  :is(.room-with-comms, .completed-journal-panel) .jt-comment-details[open] .jt-comment-field {
    display: block !important;
  }

  :is(.room-with-comms, .completed-journal-panel) .jt-save {
    grid-column: 3;
    grid-row: 2;
    z-index: 1;
    align-self: end;
    justify-self: end;
    padding: 0 9px 9px 0;
    pointer-events: none;
  }

  :is(.room-with-comms, .completed-journal-panel) .jt-save:not(:has(.jt-save-indicator)) {
    display: none;
  }

  :is(.room-with-comms, .completed-journal-panel) .jt-comment-input {
    width: 100%;
    min-height: 36px;
    padding-block: 7px;
    padding-right: 32px;
    font-size: 16px;
  }

  :is(.room-with-comms, .completed-journal-panel) .jt-gp-btn {
    height: 36px;
  }

  :is(.room-with-comms, .completed-journal-panel) .jt-gp-val {
    min-width: 32px;
    height: 32px;
    font-size: 16px;
  }

  :is(.room-with-comms, .completed-journal-panel) .jt-sessions-drop {
    width: min(236px, calc(100vw - 24px));
  }

  /* Редактор заметок занимает весь полезный экран. */
  .room-with-comms .lndoc {
    padding: 7px;
  }

  .room-with-comms .lndoc-page {
    border-radius: 13px;
  }

  .room-with-comms .lndoc-surface .ql-toolbar.ql-snow {
    display: flex;
    flex-wrap: wrap;
    gap: 2px;
    overflow: visible;
    padding: 6px 8px;
  }

  .room-with-comms .lndoc-surface .ql-toolbar .ql-formats {
    flex: 0 0 auto;
    margin-right: 2px;
  }

  .room-with-comms .lndoc-surface .ql-toolbar .ql-picker.ql-expanded {
    z-index: 11;
  }

  .room-with-comms .lndoc-surface .ql-editor,
  .room-with-comms .lndoc-textarea {
    padding: 18px 16px 24px;
    font-size: 16px;
  }

  /* Связь превращается в нижнюю панель мобильного приложения. */
  .room-with-comms .lesson-comms-rail {
    top: auto;
    right: 0;
    /* Поднимаем на зазор адресной панели, чтобы прижаться к видимому низу. */
    bottom: var(--safe-bottom-gap, 0px);
    left: 0;
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 3px;
    width: 100%;
    height: calc(var(--lesson-mobile-bar-height) + env(safe-area-inset-bottom));
    padding: 5px 8px max(5px, env(safe-area-inset-bottom));
    border-right: 0;
    border-bottom: 0;
    border-left: 0;
    border-radius: 18px 18px 0 0;
    box-shadow: 0 -12px 34px rgba(14, 14, 13, 0.22);
  }

  .room-with-comms .lesson-comms-tab {
    flex: 1 1 0;
    width: auto;
    min-width: 0;
    min-height: 54px;
    height: 54px;
    padding: 4px 2px;
    border-radius: 13px;
  }

  .room-with-comms .lesson-comms-tab.is-active,
  .room-with-comms .lesson-comms-tab.is-active:active {
    box-shadow: 0 -5px 18px rgba(232, 185, 35, 0.16);
    transform: translateY(-2px);
  }

  .room-with-comms .lesson-comms-tab.has-notification:not(.is-active) {
    box-shadow: inset 0 3px 0 var(--gold-500);
  }

  .room-with-comms .lesson-comms-tab small {
    font-size: 8.5px;
  }

  .room-with-comms .lesson-comms-separator,
  .room-with-comms .lesson-comms-people {
    display: none;
  }

  .room-with-comms .lesson-comms-own-mic {
    flex: 0 0 50px;
    width: 50px;
    height: 50px;
    margin: 0 0 0 3px;
  }

  /* Участники, чат и настройки открываются нижней карточкой над панелью. */
  .room-with-comms .lesson-comms-panel {
    top: auto;
    right: 6px;
    bottom: calc(var(--lesson-mobile-bar-height) + env(safe-area-inset-bottom) + var(--safe-bottom-gap, 0px) + 6px);
    left: 6px;
    width: auto;
    max-height: calc(100dvh - 142px - env(safe-area-inset-bottom));
    border-radius: 20px;
    opacity: 0;
    transform: translateY(14px) scale(0.99);
    transform-origin: center bottom;
  }

  .room-with-comms .lesson-comms-panel.is-open {
    opacity: 1;
    transform: translateY(0) scale(1);
  }

  .room-with-comms .lesson-comms-panel[data-active-view="voice"],
  .room-with-comms .lesson-comms-panel[data-active-view="chat"] {
    height: min(62dvh, 520px);
  }

  .room-with-comms .lesson-comms-panel[data-active-view="voice"] .lesson-comms-view,
  .room-with-comms .lesson-comms-panel[data-active-view="voice"] .lesson-voice-list {
    height: 100%;
    max-height: none;
  }

  .room-with-comms .lesson-comms-head {
    min-height: 60px;
    padding: 9px 12px;
  }

  .room-with-comms .lesson-voice-list {
    padding-inline: 10px;
  }

  .room-with-comms .lesson-voice-person {
    min-height: 56px;
  }

  .room-with-comms .lesson-comms-chat .lesson-chat-feed {
    padding: 10px;
  }

  .room-with-comms .lesson-comms-chat .lesson-chat-form {
    padding: 8px;
  }

  .room-with-comms .lesson-comms-chat .lesson-chat-tool,
  .room-with-comms .lesson-comms-chat .lesson-chat-send {
    width: 42px;
    height: 42px;
  }

  /* Инструменты доски раскрываются одной прокручиваемой строкой. */
  .room-with-comms .board-tools-dock {
    inset: 0;
    width: auto;
  }

  .room-with-comms .board-tools-trigger {
    top: 6px;
    left: 6px;
    width: 42px;
    height: 42px;
  }

  .room-with-comms .board-tools {
    top: 6px;
    right: 6px;
    left: 54px;
    width: auto;
    max-width: none;
    min-height: 42px;
    padding-block: 3px;
    flex-wrap: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: none;
  }

  .room-with-comms .board-tools::-webkit-scrollbar {
    display: none;
  }

  .room-with-comms .board-tool {
    width: 38px;
    height: 38px;
  }

  .room-with-comms .board-tool-popover {
    max-width: calc(100vw - 24px);
  }

  .room-with-comms .board-viewport {
    padding: 54px 8px 58px;
  }

  .room-with-comms .board-pages {
    left: 6px;
    bottom: 6px;
    max-width: calc(100% - 130px);
  }

  .room-with-comms .board-zoom {
    right: 6px;
    bottom: 6px;
  }

  /* Если split был сохранён раньше, на телефоне панели идут одна под другой. */
  .room-with-comms .scene-canvas[data-layout="split"] {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: repeat(2, minmax(0, 1fr));
  }

  .room-with-comms .scene-canvas[data-layout="split"] [data-slot="left"] {
    grid-column: 1;
    grid-row: 1;
  }

  .room-with-comms .scene-canvas[data-layout="split"] [data-slot="right"] {
    grid-column: 1;
    grid-row: 2;
  }

  .room-with-comms .scene-canvas[data-layout="split"] .workspace-gutter {
    display: none;
  }

  /* Экран входа в уже начавшийся урок. */
  .lesson-live-entry-page {
    min-height: 100dvh;
    grid-template-rows: 58px minmax(0, 1fr);
  }

  .lesson-live-entry-page .room-topbar {
    min-height: 58px;
    padding: 7px 10px;
  }

  .lesson-live-entry-page .room-back {
    width: 40px;
    height: 40px;
    padding: 0;
    background: rgba(255, 255, 255, 0.06);
  }

  .lesson-live-entry-page .room-status {
    padding: 8px 10px;
    font-size: 10.5px;
  }

  .lesson-live-entry-main {
    align-items: start;
    padding: 12px;
  }

  .lesson-live-entry-card {
    border-radius: 19px;
  }

  .lesson-live-entry-content {
    padding: 22px 18px 24px;
  }

  .lesson-live-entry-content h2 {
    margin-top: 10px;
    font-size: 26px;
  }

  .lesson-live-entry-details {
    display: grid;
    gap: 9px;
    margin: 19px 0;
  }

  .lesson-live-entry-form,
  .lesson-live-entry-form .btn {
    width: 100%;
  }

  .lesson-live-entry-form .btn {
    justify-content: center;
  }

  .lesson-live-entry-timer {
    min-height: 132px;
    padding: 22px;
  }

  .lesson-live-entry-timer strong {
    margin-block: 9px 5px;
    font-size: 36px;
  }
}

/* На телефоне в альбомной ориентации лист остаётся в центре, а инструменты
   занимают одну верхнюю строку и не отнимают половину невысокой сцены. */
@media (orientation: landscape) and (max-height: 560px) and (pointer: coarse) {
  .room.room-with-comms {
    --comms-edge: 0px;
    --comms-rail-width: 64px;
    height: 100dvh;
    min-height: 0;
    padding-right: var(--comms-rail-width);
    padding-bottom: 0;
  }

  .room-with-comms .room-topbar {
    margin-right: calc(var(--comms-rail-width) * -1);
    padding-right: calc(var(--comms-rail-width) + 10px);
  }

  .room-with-comms .lesson-comms-rail {
    top: 0;
    right: 0;
    bottom: 0;
    left: auto;
    width: var(--comms-rail-width);
    height: auto;
    flex-direction: column;
    gap: 3px;
    padding: 6px 5px;
    border-top: 0;
    border-right: 0;
    border-bottom: 0;
    border-radius: 0;
  }

  .room-with-comms .lesson-comms-tab {
    flex: 0 0 auto;
    width: 100%;
    min-width: 0;
    min-height: 50px;
    height: auto;
    padding: 4px 2px;
    border-radius: 10px;
  }

  .room-with-comms .lesson-comms-own-mic {
    flex: 0 0 48px;
    width: 48px;
    height: 48px;
    margin: auto auto 0;
  }

  .room-with-comms .lesson-comms-panel {
    top: 6px;
    right: calc(var(--comms-rail-width) - 6px);
    bottom: 6px;
    left: auto;
    width: min(var(--comms-panel-width), calc(100vw - var(--comms-rail-width) - 12px));
    height: auto;
    max-height: none;
    border-radius: 18px 0 0 18px;
    transform: translateX(12px) scale(0.99);
    transform-origin: right center;
  }

  .room-with-comms .lesson-comms-panel.is-open {
    transform: translateX(0) scale(1);
  }

  .room-with-comms .lesson-comms-panel[data-active-view="chat"] {
    height: auto;
  }

  .room-with-comms .lesson-comms-panel > .lesson-comms-view,
  .room-with-comms .lesson-voice-list {
    height: 100%;
    max-height: none;
  }

  .room-with-comms [data-scene-panel="scene"] {
    padding: 0;
  }

  .room-with-comms .workspace-controls {
    display: none;
  }

  .room-with-comms .scene-tabs {
    padding-right: 50px;
  }

  .room-with-comms .scene:has([data-scene-panel="scene"]:not([hidden])) .scene-focus-toggle,
  .room-with-comms .scene:has([data-scene-panel="video"]:not([hidden])) .scene-focus-toggle {
    top: 6px;
    right: 7px;
    display: grid;
  }

  .room-with-comms .board-tools-dock {
    inset: 0;
    width: auto;
  }

  .room-with-comms .board-tools-trigger {
    top: 6px;
    left: 6px;
    width: 40px;
    height: 40px;
  }

  .room-with-comms .board-tools {
    top: 6px;
    right: 6px;
    left: 52px;
    width: auto;
    max-width: none;
    min-height: 40px;
    padding-block: 2px;
    flex-wrap: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: none;
  }

  .room-with-comms .board-tools::-webkit-scrollbar {
    display: none;
  }

  .room-with-comms .board-viewport {
    padding: 50px 8px;
  }

  .room-with-comms .board-pages {
    bottom: 6px;
  }

  .room-with-comms .board-zoom {
    right: 6px;
    bottom: 6px;
  }
}

@media (hover: none) and (pointer: coarse) {
  /* Инпут чата — 16px во ВСЕХ чатах (и в ожидании), иначе iOS при фокусе зумит
     страницу вместо того, чтобы просто поднять контент над клавиатурой. */
  .lesson-chat-input-wrap input {
    font-size: 16px;
  }

  /* Долгое нажатие открывает меню действий — не даём браузеру выделять текст. */
  .lesson-chat-message {
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
  }

  /* Действия показываем прямо на сообщении (как на десктопе), кнопки крупнее под палец. */
  .lesson-chat-message-actions button {
    width: 34px;
    height: 34px;
  }

  .btn,
  .sidebar-item,
  .notification-bell,
  .scene-tab,
  .ayah-action,
  .reader-back,
  .quran-saved-shortcut,
  .board-tool,
  .board-compact-action {
    touch-action: manipulation;
  }
}

/* Бургер вместо боковой/нижней навигации на планшетах и телефонах. */
.mobile-menu-toggle,
.mobile-menu-close,
.mobile-menu-backdrop,
.mobile-page-title {
  display: none;
}

@media (max-width: 1100px) {
  body.mobile-menu-is-open {
    overflow: hidden;
  }

  .app {
    display: block;
    min-height: 100dvh;
  }

  .app > main {
    min-height: 100dvh;
    padding-bottom: 0;
  }

  .topbar {
    position: sticky;
    z-index: 90;
    top: 0;
    height: 60px;
    padding: 0 max(16px, env(safe-area-inset-right)) 0 max(16px, env(safe-area-inset-left));
  }

  .topbar-day {
    display: none;
  }

  .mobile-menu-toggle,
  .mobile-menu-close {
    display: grid;
    place-items: center;
    width: 40px;
    height: 40px;
    padding: 0;
    border: 0;
    border-radius: 11px;
    cursor: pointer;
  }

  .mobile-menu-toggle {
    background: var(--paper-100);
    color: var(--text-1);
  }

  .mobile-menu-toggle svg,
  .mobile-menu-close svg {
    width: 22px;
    height: 22px;
  }

  .mobile-menu-close {
    flex: 0 0 36px;
    width: 36px;
    height: 36px;
    margin-left: auto;
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-on-ink-1);
  }

  .sidebar {
    position: fixed;
    z-index: 120;
    inset: 0 auto 0 0;
    display: flex;
    flex-direction: column;
    width: min(320px, calc(100vw - 48px));
    height: 100dvh;
    padding: max(20px, env(safe-area-inset-top)) 14px max(16px, env(safe-area-inset-bottom));
    border: 0;
    background: var(--ink-900);
    box-shadow: 18px 0 50px rgba(14, 14, 13, 0.28);
    transform: translateX(-105%);
    transition: transform var(--dur-3) var(--ease);
  }

  body.mobile-menu-is-open .sidebar {
    transform: translateX(0);
  }

  .sidebar-brand {
    display: flex;
    justify-content: flex-start;
    padding: 4px 8px 18px;
  }

  .sidebar-brand img {
    width: 50px;
    height: 50px;
  }

  .sidebar-brand > div,
  .sidebar-item span:not(.sidebar-item-count),
  .sidebar-profile > a:first-child > div,
  .sidebar-spacer,
  .sidebar-profile {
    display: flex;
  }

  .sidebar-brand > div,
  .sidebar-profile > a:first-child > div {
    flex-direction: column;
  }

  .sidebar-spacer {
    flex: 1;
  }

  .sidebar-menu {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 4px;
    width: 100%;
    height: auto;
    overflow: visible;
  }

  .sidebar-item {
    display: flex;
    flex: 0 0 auto;
    flex-direction: row;
    justify-content: flex-start;
    gap: 12px;
    width: 100%;
    min-width: 0;
    height: auto;
    min-height: 44px;
    padding: 10px 12px;
    border-radius: 8px;
    color: var(--text-on-ink-2);
    font-size: 14px;
    text-align: left;
  }

  .sidebar-item span:not(.sidebar-item-count) {
    width: auto;
    max-height: none;
    overflow: visible;
    white-space: nowrap;
  }

  .sidebar-item svg {
    width: 18px;
    height: 18px;
  }

  .sidebar-item:hover {
    background: var(--ink-800);
  }

  .sidebar-item.active {
    background: var(--gold-500);
    color: var(--ink-900);
  }

  .sidebar-item.active::before {
    display: none;
  }

  .sidebar-profile {
    flex-direction: row;
    justify-content: flex-start;
    gap: 12px;
    padding: 10px;
  }

  .sidebar-profile > a:first-child {
    flex: 1;
  }

  .sidebar-logout {
    width: 32px;
    height: 32px;
  }

  .mobile-menu-backdrop {
    position: fixed;
    z-index: 110;
    inset: 0;
    width: 100%;
    height: 100%;
    padding: 0;
    border: 0;
    background: rgba(14, 14, 13, 0.48);
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--dur-3) var(--ease);
  }

  body.mobile-menu-is-open .mobile-menu-backdrop {
    display: block;
    opacity: 1;
    pointer-events: auto;
  }
}

@media (max-width: 720px) {
  .topbar {
    height: 56px;
    padding-right: max(12px, env(safe-area-inset-right));
    padding-left: max(12px, env(safe-area-inset-left));
  }

  .notifications-menu {
    max-height: calc(100dvh - 78px);
  }

  .mobile-page-title {
    display: block;
    min-width: 0;
    margin-left: 12px;
    overflow: hidden;
    color: var(--text-1);
    font-family: var(--font-serif);
    font-size: 17px;
    font-weight: 600;
    line-height: 1;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  /* Название уже находится в topbar — не повторяем его крупным блоком. */
  .page-head-copy {
    display: none;
  }

  .page-head {
    margin-bottom: 24px;
  }

  /* Компактная общая строка переключателя и основного действия. */
  .page-head-actions {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: stretch;
  }

  .page-head-actions > .segmented {
    min-width: 0;
    overflow: hidden;
  }

  .page-head-actions > .segmented > * {
    flex: 1 1 0;
    min-width: 0;
    min-height: 36px;
    padding-inline: 7px;
    font-size: 12px;
  }

  .page-head-actions > .btn {
    flex: none;
    min-width: max-content;
    height: 44px;
    padding-inline: 12px;
    font-size: 13px;
    white-space: nowrap;
  }

  .week-calendar .calendar-head {
    gap: 12px;
    margin-bottom: 12px;
    padding: 2px 2px 12px;
  }

  .week-calendar .calendar-head h2 {
    font-size: 18px;
  }

  .wk-row {
    display: block;
    border-radius: 10px;
  }

  .wk-row-date {
    justify-content: flex-start;
    flex-direction: row;
    gap: 8px;
    padding: 9px 12px;
    border-right: 0;
    border-bottom: 1px solid var(--hairline);
    background: transparent;
  }

  .wk-agenda {
    gap: 8px;
  }

  .wk-row.is-empty {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    align-items: center;
  }

  .wk-row.is-empty .wk-row-date {
    padding: 9px 12px;
    border-bottom: 0;
  }

  .wk-row-day {
    order: -1;
    width: 26px;
    height: 26px;
    font-size: 16px;
  }

  .wk-row-events {
    padding: 4px 12px 7px;
  }

  .wk-row.is-empty .wk-row-events {
    align-items: flex-end;
    padding: 9px 12px;
  }

  .wk-event {
    grid-template-columns: 52px minmax(0, 1fr) auto;
    column-gap: 8px;
    padding: 10px 0;
  }

  .wk-event-time {
    font-size: 14px;
  }

  .wk-event-title {
    font-size: 13.5px;
  }

  .wk-event-meta {
    font-size: 11.5px;
  }

  .wk-row-none {
    font-size: 11.5px;
  }

  .wk-event-go {
    display: none;
  }

  .page-head-copy-only {
    display: none;
    margin-bottom: 0;
  }

  .hw-wrap > .hw-head,
  .repetition-board > .repetition-board-header {
    display: none;
  }

  .modal.create-lesson-modal {
    padding: 20px 16px 16px;
  }

  .create-lesson-modal .create-modal-head {
    margin-bottom: 16px;
  }

  .create-lesson-modal .create-modal-head h2 {
    font-size: 25px;
  }

  .create-lesson-modal .create-form {
    gap: 12px;
  }

  .create-lesson-modal .cf-row {
    gap: 12px;
  }

  .create-lesson-modal .cf-field {
    gap: 6px;
  }

  .create-lesson-modal .create-modal-foot {
    margin-top: 16px;
    padding-top: 14px;
  }

  .create-lesson-modal .create-modal-foot > div {
    width: 100%;
  }

  .create-lesson-modal .create-modal-foot .btn {
    flex: 1;
  }

  /* Компактные карточки расписания: вся карточка остаётся ссылкой. */
  .lessons-section,
  .lessons-section-today {
    margin-bottom: 30px;
  }

  .lessons-section .section-head {
    gap: 10px;
    margin-bottom: 14px;
  }

  .lessons-section .section-head h2 {
    font-size: 20px;
  }

  .lessons-list {
    gap: 14px;
  }

  .lesson-row {
    grid-template-columns: max-content minmax(0, 1fr) auto;
    gap: 8px;
    padding: 22px 12px;
    border-radius: 12px;
  }

  .lesson-row-time {
    grid-column: 1;
    display: flex;
    align-items: flex-start;
    flex-direction: column;
    justify-content: center;
    min-width: 58px;
    padding-right: 8px;
    border-right: 1px solid var(--hairline);
  }

  .lesson-row-time strong,
  .lesson-row-time .lesson-row-clock {
    font-size: 20px;
  }

  .lesson-row-time--running .lesson-row-clock {
    font-size: 18px;
  }

  .lesson-row-time .lesson-row-live {
    margin-top: 4px;
    font-size: 11px;
  }

  .lesson-row > div:nth-child(2) {
    grid-column: 2;
    display: flex;
    flex-direction: column;
    justify-content: center;
    min-width: 0;
  }

  .lesson-row > div:nth-child(3),
  .lesson-row-meta {
    display: none;
  }

  .lesson-row-badges {
    order: 2;
    flex-wrap: wrap;
    gap: 6px;
    margin: 4px 0 0;
  }

  .lesson-row:has(.lesson-row-time--running) .pill-live {
    display: none;
  }

  .lesson-row .pill,
  .lesson-row .type-pill {
    padding: 4px 7px;
    font-size: 10px;
    white-space: nowrap;
  }

  .lesson-row-title {
    order: 1;
    margin: 0;
    overflow: hidden;
    font-size: 16px;
    line-height: 1.2;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .lesson-row-title span {
    font-size: 14px;
  }

  .lesson-row > .btn {
    grid-column: 3;
    align-self: center;
    min-width: 0;
    min-height: 36px;
    padding: 7px 10px;
    font-size: 12px;
    white-space: nowrap;
  }

  .lesson-row > .btn svg {
    width: 14px;
    height: 14px;
  }

  .lesson-row > .btn-secondary {
    min-height: 32px;
    padding: 5px 8px;
    gap: 4px;
    font-size: 11px;
  }

  .lesson-row > .btn-secondary svg {
    width: 12px;
    height: 12px;
  }
}
/* Три состояния урока на телефоне используют один спокойный каркас. */
@media (max-width: 720px) {
  .teacher-lesson-state--planned,
  .teacher-lesson-state--waiting,
  .teacher-lesson-state--completed {
    display: block;
    padding: 12px 12px 32px;
  }

  .planned-lesson-notice,
  .waiting-lesson-room,
  .completed-lesson-room {
    align-items: stretch;
    width: 100%;
    min-height: 0;
    padding: 18px 14px;
    border-top-width: 2px;
    border-radius: 14px;
  }

  .planned-notice-head,
  .waiting-room-head,
  .completed-room-head {
    width: 100%;
    max-width: none;
    box-sizing: border-box;
    padding-right: 42px;
    text-align: left;
  }

  .planned-notice-head h1,
  .waiting-room-head h1,
  .completed-room-head h1 {
    font-size: 24px;
    line-height: 1.18;
    overflow-wrap: anywhere;
  }

  .planned-notice-head .lesson-topic,
  .waiting-room-head .lesson-topic,
  .completed-room-head .lesson-topic {
    margin-top: 5px;
    font-family: var(--font-sans);
    font-size: 13px;
    line-height: 1.35;
  }

  .completed-room-head h1 {
    font-size: 21px;
  }

  .completed-room-head .lesson-topic {
    margin-top: 3px;
    font-size: 12px;
  }

  .teacher-lesson-state .planned-notice-statuses {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 4px;
    width: 100%;
    margin: 20px 0 0;
    overflow: visible;
  }

  .planned-notice-statuses .step {
    align-items: center;
    flex-direction: column;
    gap: 6px;
    min-width: 0;
    padding: 0 2px 9px;
  }

  .planned-notice-statuses .step-dot {
    width: 21px;
    height: 21px;
    font-size: 9px;
  }

  .planned-notice-statuses .step-name {
    max-width: 100%;
    overflow: hidden;
    font-size: 10px;
    text-overflow: ellipsis;
  }

  .planned-countdown {
    min-height: 0;
    padding: 26px 0 20px;
  }

  .planned-countdown-grid {
    gap: 0;
  }

  .planned-countdown-unit {
    padding: 14px 3px 12px;
  }

  .planned-countdown-unit strong {
    font-size: 28px;
    letter-spacing: -0.06em;
  }

  .planned-countdown-unit span {
    margin-top: 6px;
    font-size: 9px;
    letter-spacing: 0;
  }

  .planned-countdown-date {
    gap: 6px;
    margin-top: 13px;
    font-size: 11px;
  }

  .lesson-transition-action,
  .lesson-transition-action .btn,
  .waiting-timerbar-controls,
  .waiting-timer-action,
  .waiting-timer-start {
    width: 100%;
  }

  /* КРИТИЧНО: на страницах с закреплённой снизу кнопкой убираем анимацию появления
     у main. У .app>main стоит `animation: page-enter … both`, а остаточный transform
     от fill-mode:both делает main containing block — тогда position:fixed внутри
     считается от main, а не от экрана, и кнопка скроллится/исчезает. Без анимации
     main никогда не containing block → кнопка ведёт себя как плеер/голосовуха. */
  .app > main:has(.waiting-timer-start),
  .app > main:has(.lesson-transition-action) {
    animation: none;
  }

  /* Учитель: кнопку старта закрепляем у самого низа экрана. Раньше её выталкивало
     под сгиб (шапка + этапы + таймер), приходилось листать вниз, чтобы подтвердить.
     :has() ограничивает фикс ролью учителя — у ученицы тут пассивная подсказка.
     Нижней навигации на этих страницах нет (sidebar = левый drawer), поэтому
     прижимаем к низу; --safe-bottom-gap компенсирует адресную панель браузера. */
  .waiting-timerbar-controls:has(.waiting-timer-start) {
    position: fixed;
    left: 0;
    right: 0;
    bottom: var(--safe-bottom-gap, 0px);
    z-index: 40;
    box-sizing: border-box;
    width: auto;
    margin-top: 0;
    padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
    background: var(--paper-0);
    border-top: 1px solid var(--hairline);
    box-shadow: 0 -8px 24px rgba(14, 14, 13, 0.1);
  }

  .waiting-timerbar-controls:has(.waiting-timer-start) .waiting-timer-start {
    min-height: 46px;
  }

  /* Резерв места под закреплённую панель — чтобы она не перекрывала чат снизу. */
  .lesson-waiting-page:has(.waiting-timer-start) {
    padding-bottom: calc(84px + env(safe-area-inset-bottom) + var(--safe-bottom-gap, 0px));
  }

  /* Запланированный (учитель): «Открыть ожидание» тоже закрепляем внизу экрана.
     Кнопка теперь всегда под рукой, а не в середине блока отсчёта. */
  .teacher-lesson-state--planned .lesson-transition-action {
    position: fixed;
    left: 0;
    right: 0;
    bottom: var(--safe-bottom-gap, 0px);
    z-index: 40;
    box-sizing: border-box;
    margin: 0;
    padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
    background: var(--paper-0);
    border-top: 1px solid var(--hairline);
    box-shadow: 0 -8px 24px rgba(14, 14, 13, 0.1);
  }

  .teacher-lesson-state--planned .lesson-transition-action .btn {
    min-height: 46px;
  }

  .teacher-lesson-state--planned:has(.lesson-transition-action) {
    padding-bottom: calc(84px + env(safe-area-inset-bottom) + var(--safe-bottom-gap, 0px));
  }

  .planned-roster {
    padding: 18px 0 4px;
    text-align: left;
  }

  .planned-roster-head,
  .waiting-roster-head {
    align-items: center;
    justify-content: space-between;
    flex-direction: row;
    gap: 10px;
    text-align: left;
  }

  .planned-roster-head span,
  .waiting-roster-head > span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .planned-roster > .planned-roster-list {
    justify-content: flex-start;
    flex-wrap: nowrap;
    gap: 10px;
    max-height: none;
    padding: 5px 0 8px;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: none;
  }

  .planned-roster > .planned-roster-list::-webkit-scrollbar {
    display: none;
  }

  .planned-roster > .planned-roster-list .planned-roster-person {
    min-width: 72px;
    font-size: 11px;
  }

  .waiting-room-timerbar {
    width: 100%;
    margin-top: 20px;
    padding: 14px 0 18px;
  }

  .waiting-timerbar-context {
    flex-wrap: wrap;
    gap: 5px;
  }

  .waiting-room-workspace {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 0;
    margin-top: 16px;
  }

  .waiting-room-tabs {
    display: none;
  }

  .waiting-roster-head {
    padding: 14px 4px 8px;
  }

  .waiting-room-roster .planned-roster-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 7px;
    padding: 8px 0 14px;
  }

  .waiting-room-roster .waiting-person {
    align-items: center;
    justify-content: flex-start;
    flex-direction: row;
    gap: 9px;
    min-height: 58px;
    padding: 8px;
    border: 1px solid var(--hairline);
    border-radius: 10px;
    text-align: left;
  }

  .waiting-room-roster .waiting-person .ava {
    width: 36px;
    height: 36px;
  }

  .waiting-roster-person-copy b {
    font-size: 11px;
  }

  .teacher-lesson-state--waiting .lesson-chat-panel.lesson-waiting-card {
    height: 360px;
    border-top: 1px solid var(--hairline);
    border-left: 0;
  }

  .completed-room-meta {
    justify-content: flex-start;
    flex-wrap: wrap;
    gap: 5px 7px;
    margin-top: 7px;
    font-size: 10px;
  }

  .completed-room-meta strong,
  .completed-room-meta-dot {
    display: none;
  }

  .completed-summary,
  .completed-summary-compact {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    width: 100%;
    margin-top: 18px;
  }

  .completed-summary-item {
    justify-content: center;
    padding: 12px 7px;
    text-align: center;
  }

  .completed-summary-item > span:last-child {
    align-items: center;
  }

  .completed-summary-item + .completed-summary-item {
    border-left: 0;
  }

  .completed-summary-item:nth-child(even) {
    border-left: 1px solid var(--hairline);
  }

  .completed-summary-item:nth-child(n + 3) {
    border-top: 1px solid var(--hairline);
  }

  .completed-summary-icon {
    width: 28px;
    height: 28px;
  }

  .completed-summary-item small {
    font-size: 10px;
  }

  .completed-summary-item strong {
    font-size: 13px;
  }

  .completed-workspace {
    width: calc(100% + 28px);
    margin-top: 18px;
    margin-right: -14px;
    margin-left: -14px;
  }

  .completed-workspace-head {
    padding: 0 8px;
  }

  .completed-tabs {
    width: 100%;
    overflow: hidden;
  }

  .completed-tab {
    min-width: 0;
    min-height: 44px;
    gap: 5px;
    padding: 9px 5px;
    font-size: 11px;
  }

  .completed-panel {
    padding: 16px 12px 20px;
  }

  .completed-journal-panel .jt-head {
    display: none;
  }

  .completed-journal-panel .jt-panel {
    width: 100%;
    margin: 0;
  }
}

/* Мобильный чат: больше места под историю, свайп на ответ и долгое нажатие на действия. */
@media (max-width: 640px) {
  .room-with-comms .lesson-comms-panel[data-active-view="chat"] {
    height: calc(100dvh - 142px - env(safe-area-inset-bottom));
    max-height: calc(100dvh - 142px - env(safe-area-inset-bottom));
  }

  .room-with-comms .lesson-comms-chat .lesson-chat-feed {
    padding: 10px 8px 14px;
  }

  .lesson-chat-message {
    max-width: 91%;
  }

  .lesson-chat-message-body {
    padding: 9px 11px 7px;
  }

  .lesson-chat-message-text {
    font-size: 13px;
    line-height: 1.42;
  }

  .lesson-chat-compose-row {
    gap: 7px;
  }

  .lesson-chat-composer-context {
    grid-template-columns: 25px minmax(0, 1fr) 30px;
    gap: 6px;
  }
}

@media (hover: none) and (pointer: coarse) {
  .lesson-chat-message-body {
    touch-action: pan-y;
  }

  .lesson-chat-message.is-gesture-tracking .lesson-chat-message-body {
    -webkit-touch-callout: none;
    user-select: none;
  }

  .lesson-chat-message-actions {
    display: none;
  }
}

/* На телефоне видеосетка живёт во вкладке «Видео» панели общения. */
@media (max-width: 640px) {
  .room-with-comms .lesson-video-session-toggle {
    width: 38px;
    min-width: 38px;
    height: 38px;
    min-height: 38px;
    padding: 0;
  }

  .room-with-comms .lesson-video-session-toggle span {
    display: none;
  }

  .lesson-video-grid {
    grid-template-columns: repeat(auto-fit, minmax(140px, 210px));
    justify-content: center;
    gap: 6px;
    padding: 7px;
  }

  .lesson-video-tile {
    aspect-ratio: 4 / 3;
    border-radius: 10px;
  }

  .lesson-video-fallback .ava {
    width: 44px;
    height: 44px;
    font-size: 12px;
  }

  .scene-video-controls {
    flex-wrap: nowrap;
    gap: 6px;
    padding: 7px 8px;
    font-size: 10px;
  }

  .scene-video-controls .lesson-video-camera,
  .scene-video-controls .lesson-video-screen,
  .scene-video-controls .lesson-video-switch-camera {
    width: 36px;
    height: 36px;
    flex: 0 0 36px;
  }

  .scene-video-camera-label {
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .scene-video-count,
  .scene-video-hd-note {
    display: none;
  }

  .scene-video-hd-wrap {
    flex: 0 0 auto;
    margin-left: 0;
  }

  .scene-video-hd {
    gap: 5px;
  }

  .scene-video-hd-track {
    width: 32px;
    height: 18px;
  }

  .scene-video-hd-track::after {
    width: 14px;
    height: 14px;
  }

  .scene-video-hd input:checked + .scene-video-hd-track::after {
    transform: translateX(14px);
  }

  .scene-video-hd-text {
    font-size: 9px;
  }

  /* Предупреждение компактнее — на телефоне оно съедало много места. */
  .lesson-video-notice {
    margin: 6px 8px 0;
    padding: 7px 8px;
    gap: 6px;
    font-size: 10px;
  }

  .lesson-video-notice-close {
    width: 22px;
    height: 22px;
  }
}

@media (orientation: landscape) and (max-height: 560px) and (pointer: coarse) {
  .lesson-video-grid {
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  }
}
