/* Loaded after legacy styles. Theme/avatar rules intentionally stay in their own modules. */
html.responsive-enabled { --responsive-vh: 100vh; }
@supports (height: 100dvh) { html.responsive-enabled { --responsive-vh: 100dvh; } }
html[data-responsive-shell="true"] body { min-width: 0; }
html[data-responsive-shell="true"] .container {
    max-height: none !important;
    min-width: 0;
    overflow: visible !important;
}
html[data-responsive-shell="true"] :is(.content-wrapper, .main-content, .post, .lesson-container, .sidebar) { min-width: 0; box-sizing: border-box; }
html[data-responsive-shell="true"] #board {
    width: var(--responsive-board-size, 100%) !important;
    height: var(--responsive-board-size, auto) !important;
    max-width: 100%;
    min-width: 0 !important;
    min-height: 0 !important;
    aspect-ratio: 1;
    flex: 0 0 auto;
    margin-inline: auto;
}
/* Wide desktop: retain the legacy two-column proportions and spacing. */
html[data-responsive-shell="true"][data-responsive-layout="wide"] .content-wrapper { flex-wrap: nowrap; }
html[data-responsive-shell="true"][data-responsive-layout="wide"] .main-content { flex-basis: 0; }
html[data-responsive-shell="true"][data-responsive-layout="wide"] .sidebar { flex-shrink: 0; max-width: 45%; }
html[data-responsive-shell="true"][data-responsive-layout="wide"] .container { height: var(--responsive-vh); }
html[data-responsive-shell="true"][data-responsive-layout="wide"] .dashboard { overflow-y: auto; max-height: calc(var(--responsive-vh) - 100px); }
html[data-responsive-shell="true"] :is(.chat-messages, .chat-messages-inner) { min-width: 0; overflow-wrap: anywhere; }
html[data-responsive-shell="true"] .chat-messages-inner { overflow-y: auto; }
/* Compact mode also applies to desktop MAX windows. No UA-dependent routing. */
html[data-responsive-shell="true"][data-responsive-layout="compact"] body { display: block; height: auto; min-height: var(--responsive-vh); overflow: auto; }
html[data-responsive-shell="true"][data-responsive-layout="compact"] .container { height: auto !important; min-height: var(--responsive-vh); width: 100%; }
html[data-responsive-shell="true"][data-responsive-layout="compact"] .content-wrapper { display: flex !important; flex-direction: column !important; flex-wrap: nowrap; height: auto !important; overflow: visible !important; gap: 12px; }
html[data-responsive-shell="true"][data-responsive-layout="compact"] :is(.main-content, .post, article.post, .lesson-container) {
    width: 100%; max-width: 100%; min-width: 0 !important; height: auto !important; max-height: none !important; overflow: visible !important; flex: 0 1 auto !important;
}
html[data-responsive-shell="true"][data-responsive-layout="compact"] .main-content { padding: 12px !important; }
html[data-responsive-shell="true"][data-responsive-layout="compact"] .post { margin: 0; }
html[data-responsive-shell="true"][data-responsive-layout="compact"] .sidebar {
    width: auto !important; max-width: none; height: auto !important; max-height: none !important;
    margin: 0 12px 16px !important; overflow: visible !important; flex: 0 1 auto;
}
html[data-responsive-shell="true"][data-responsive-layout="compact"] :is(.dashboard, .content-p) { width: 100%; max-width: 100%; min-width: 0; height: auto !important; max-height: none !important; overflow-x: auto; overflow-y: visible; }
html[data-responsive-shell="true"][data-responsive-layout="compact"] .menu { flex-wrap: wrap; height: auto; min-width: 0; gap: 8px; margin-bottom: 10px; }
html[data-responsive-shell="true"][data-responsive-layout="compact"] .menu-icon { flex-wrap: wrap; gap: 12px; }
html[data-responsive-shell="true"][data-responsive-layout="compact"] .chess-notation { position: relative; top: auto; transform: none; max-height: none !important; overflow: visible; margin-top: 12px; }
html[data-responsive-shell="true"][data-responsive-layout="compact"] .opponent-name { margin-top: 10px; } 
html[data-responsive-shell="true"][data-responsive-layout="compact"] .chat-input { width: 100%; max-width: 100%; margin: 8px 0; }
html[data-responsive-shell="true"][data-responsive-layout="compact"] .chat-messages { height: auto; min-height: 0; max-height: min(45vh, 360px); margin-top: 0; }
html[data-responsive-shell="true"][data-responsive-layout="compact"] .chat-messages-inner { max-height: min(45vh, 340px); }
html[data-responsive-shell="true"][data-responsive-layout="compact"] .move-navigation { flex-wrap: wrap; }
html[data-responsive-shell="true"][data-responsive-layout="compact"] .move-navigation .center-group { position: static; transform: none; order: 2; }
html[data-responsive-shell="true"][data-responsive-layout="compact"] :is(.table-container, .table-wrapper, .rating-table-container) { min-width: 0; max-width: 100%; overflow-x: auto; }
html[data-responsive-shell="true"][data-responsive-layout="compact"] :is(.profile-container, .stats-container, .grade-container, .chart-container) { min-width: 0; max-width: 100%; box-sizing: border-box; }
html[data-responsive-shell="true"][data-responsive-layout="compact"] :is(img, video) { max-width: 100%; }
/* Mobile templates remain on their current URL even in a roomy viewport. */
html[data-responsive-mobile="true"][data-responsive-layout="wide"] .lesson-container:has(> #board) {
    display: grid; grid-template-columns: minmax(0, 1.7fr) minmax(280px, 1fr); gap: 12px 24px; align-items: start;
}
html[data-responsive-mobile="true"][data-responsive-layout="wide"] .lesson-container:has(> #board) > * { grid-column: 2; min-width: 0; }
html[data-responsive-mobile="true"][data-responsive-layout="wide"] .lesson-container:has(> #board) > .menu { grid-column: 1 / -1; grid-row: 1; }
html[data-responsive-mobile="true"][data-responsive-layout="wide"] .lesson-container:has(> #board) > #board { grid-column: 1; grid-row: 2 / span 10; }
@media (prefers-reduced-motion: reduce) {
    html.responsive-enabled .content-wrapper { scroll-behavior: auto; }
}

/* Hidden popovers must not enlarge the document's scrollable area. */
html[data-responsive-shell="true"][data-responsive-layout="compact"] .menu .hidden { display: none !important; }
html[data-responsive-shell="true"][data-responsive-layout="compact"] .dropdown-menu { right: 0; max-width: calc(var(--responsive-vw) - 24px); min-width: min(220px, calc(var(--responsive-vw) - 24px)); box-sizing: border-box; }
html[data-responsive-shell="true"][data-responsive-layout="compact"] .stats-grid { flex-wrap: wrap; gap: 12px; margin: 0 12px; }
html[data-responsive-shell="true"][data-responsive-layout="compact"] .stats-right { flex: 1 1 100%; min-width: 0; }
html[data-responsive-shell="true"][data-responsive-layout="compact"] .stats-row { flex-wrap: wrap; gap: 12px; }
html[data-responsive-shell="true"][data-responsive-layout="compact"] .profile-header { flex-wrap: wrap; gap: 12px; padding-inline: 16px; }
html[data-responsive-shell="true"][data-responsive-layout="compact"] .month-scale { margin-inline: 12px; }
/* Standalone admin tables scroll locally, without changing their data or columns. */
html[data-responsive-page="admin"][data-responsive-layout="compact"] .table-responsive { overflow-x: auto; max-width: 100%; }
html[data-responsive-page="admin"][data-responsive-layout="compact"] .card-body { min-width: 0; }
html[data-responsive-page="admin"][data-responsive-layout="compact"] .input-group { flex-wrap: wrap; }

/* Keep scrolling (wheel, touch, keyboard) but do not draw its browser chrome. */
html.responsive-enabled,
html.responsive-enabled body,
html.responsive-enabled body * {
    scrollbar-width: none;
    -ms-overflow-style: none;
}
html.responsive-enabled::-webkit-scrollbar,
html.responsive-enabled body::-webkit-scrollbar,
html.responsive-enabled body *::-webkit-scrollbar {
    display: none;
    width: 0;
    height: 0;
}

/* Original mobile lesson order: header, avatar/info, board, task/stars, chat.
   Only compact lessons change; desktop nodes are restored to the sidebar. */
html[data-responsive-layout="compact"] .responsive-lesson-sidebar-empty { display: none !important; }
html[data-responsive-layout="compact"]:is([data-responsive-page="lesson"], [data-responsive-page="mobil"]) .main-content { padding: 10px !important; }
html[data-responsive-layout="compact"]:is([data-responsive-page="lesson"], [data-responsive-page="mobil"]) .lesson-container {
    display: flex;
    flex-direction: column;
    align-items: stretch;
}
html[data-responsive-layout="compact"]:is([data-responsive-page="lesson"], [data-responsive-page="mobil"]) .lesson-container > .chat-widget {
    width: 100%;
    height: auto !important;
    flex: 0 0 auto;
    margin: 0 0 10px;
}
html[data-responsive-layout="compact"]:is([data-responsive-page="lesson"], [data-responsive-page="mobil"]) .character-section {
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) !important;
    align-items: center;
    gap: 10px;
}
html[data-responsive-layout="compact"]:is([data-responsive-page="lesson"], [data-responsive-page="mobil"]) .character-info-block {
    margin-top: 0 !important;
    height: auto;
    min-width: 0;
}
html[data-responsive-layout="compact"]:is([data-responsive-page="lesson"], [data-responsive-page="mobil"]) .font-mob { font-size: 10px; }
html[data-responsive-layout="compact"]:is([data-responsive-page="lesson"], [data-responsive-page="mobil"]) .phone-signal { display: none; }
html[data-responsive-layout="compact"]:is([data-responsive-page="lesson"], [data-responsive-page="mobil"]) .lesson-container > .chess-notation { margin-top: 6px; }
html[data-responsive-layout="compact"]:is([data-responsive-page="lesson"], [data-responsive-page="mobil"]) #task-description { margin-top: 8px; }

/* Viewport-clamped popovers stay in the same DOM: existing click handlers survive.
   Fixed positioning avoids clipping by the dashboard's local scrolling panel. */
html[data-responsive-shell="true"] .menu [data-viewport-menu].hidden { display: none !important; }
html[data-responsive-shell="true"] .menu [data-viewport-menu] {
    position: fixed !important;
    left: var(--menu-left, 12px) !important;
    top: var(--menu-top, 48px) !important;
    right: auto !important;
    transform: none !important;
    margin: 0 !important;
    width: max-content;
    min-width: min(250px, var(--menu-available-width, calc(100vw - 24px))) !important;
    max-width: var(--menu-available-width, calc(100vw - 24px)) !important;
    max-height: var(--menu-available-height, calc(100vh - 24px));
    box-sizing: border-box;
    overflow: auto;
    overscroll-behavior: contain;
}
html[data-responsive-shell="true"] .menu [data-viewport-menu]::before { display: none; }
html[data-responsive-shell="true"] .menu :is(.piece-theme-options, .board-theme-options, .avatar-theme-options) {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
}
/* Dashboard pages use the same single-column shell as the compact lesson.
   Only tables/calendar/chart interiors scroll sideways, not the document. */
html[data-responsive-layout="compact"]:is([data-responsive-page="profile"], [data-responsive-page="mobil-profile"], [data-responsive-page="stat"], [data-responsive-page="mobil-stat"]) :is(.dashboard, .dashboard-mobile) {
    width: 100%; min-width: 0; max-width: 100%; box-sizing: border-box; overflow: visible;
}
html[data-responsive-layout="compact"] :is(.profile-info, .profile-name, .profile-school) { min-width: 0; overflow-wrap: anywhere; }
html[data-responsive-layout="compact"] .profile-name-actions { flex-wrap: wrap; }
html[data-responsive-layout="compact"] :is(.profile-edit-section, .lichess-block-section, .tactics-table-wrapper-disp) { margin-inline: 12px; padding: 12px; min-width: 0; }
html[data-responsive-layout="compact"] .tactics-table-wrapper { min-width: 0; max-width: 100%; }
html[data-responsive-layout="compact"] .tactics-scroll { max-width: 100%; }
html[data-responsive-layout="compact"] #levelsTable { min-width: 0; table-layout: fixed; overflow-wrap: anywhere; }
html[data-responsive-layout="compact"] #levelsTable :is(th, td) { padding: 10px 5px; }
html[data-responsive-layout="compact"] #lichess-block > div { flex-wrap: wrap; gap: 12px; }
html[data-responsive-layout="compact"] .month-scale { padding: 12px; box-sizing: border-box; min-width: 0; }
html[data-responsive-layout="compact"] :is(.month-header, .legend) { flex-wrap: wrap; gap: 10px; }
html[data-responsive-layout="compact"] .days-container { max-width: 100%; overflow-x: auto; }
html[data-responsive-layout="compact"] .day-column { flex: 1 0 18px; }
html[data-responsive-layout="compact"] :is(.stats-grid, .stats-right, .stats-overview) { min-width: 0; max-width: 100%; box-sizing: border-box; }
html[data-responsive-layout="compact"] .stats-overview { flex-wrap: wrap; justify-content: center; align-items: center; }
html[data-responsive-layout="compact"] .stats-row { justify-content: center; }
html[data-responsive-layout="compact"] .progress-stats { flex-wrap: wrap; gap: 12px; }
html[data-responsive-layout="compact"] .dop_stat { grid-template-columns: minmax(0, 1fr); margin-inline: 12px; }
html[data-responsive-layout="compact"] .dop_stat > * { min-width: 0; }
html[data-responsive-layout="compact"] .dop_stat_user_game { width: auto; margin-inline: 12px; }
html[data-responsive-layout="compact"] :is(.stat_user_game, .dop_stat_tactics) { min-width: 0; max-width: 100%; }
html[data-responsive-layout="compact"] .modal > div { box-sizing: border-box; max-width: calc(100vw - 24px) !important; max-height: calc(var(--responsive-vh) - 24px); overflow-y: auto; }
html[data-responsive-layout="compact"] .modal input { box-sizing: border-box; max-width: 100%; }

/* VK is embedded: respect the host viewport and mobile safe area without moving the page out of VK. */
html[data-vk-platform] { min-width: 0; }
html[data-vk-platform][data-responsive-shell="true"] body {
    display: block; height: auto; max-width: 100%; overflow: visible;
}
html[data-vk-platform="mobile"] body {
    --vk-safe-top: max(env(safe-area-inset-top, 0px), var(--vk-inset-top, 0px));
    --vk-safe-right: max(env(safe-area-inset-right, 0px), var(--vk-inset-right, 0px));
    --vk-safe-bottom: max(env(safe-area-inset-bottom, 0px), var(--vk-inset-bottom, 0px));
    --vk-safe-left: max(env(safe-area-inset-left, 0px), var(--vk-inset-left, 0px));
    box-sizing: border-box;
    padding: var(--vk-safe-top) var(--vk-safe-right) var(--vk-safe-bottom) var(--vk-safe-left);
    min-height: var(--responsive-vh);
    min-width: 0;
}
html[data-vk-platform="mobile"][data-responsive-shell="true"] .container {
    box-sizing: border-box;
    min-height: calc(var(--responsive-vh) - var(--vk-safe-top) - var(--vk-safe-bottom));
}
html[data-vk-platform="mobile"] .menu [data-viewport-menu] {
    max-width: min(var(--menu-available-width, 100vw), calc(100vw - var(--vk-safe-left) - var(--vk-safe-right) - 24px));
}
html[data-vk-platform="desktop"][data-responsive-layout="wide"][data-responsive-shell="true"] .container {
    height: auto;
    min-height: var(--responsive-vh);
}
@media (max-width: 1099px), (max-height: 649px) {
    html[data-vk-platform="desktop"][data-responsive-layout="wide"][data-responsive-shell="true"] .content-wrapper {
        display: flex; flex-direction: row; flex-wrap: nowrap; height: auto; overflow: visible;
    }
    html[data-vk-platform="desktop"][data-responsive-layout="wide"] .main-content { flex: 1 1 0; padding: 12px; }
    html[data-vk-platform="desktop"][data-responsive-layout="wide"] .sidebar {
        width: clamp(250px, 36vw, 400px); min-width: 0; margin: 12px 12px 12px 0; height: auto;
    }
    html[data-vk-platform="desktop"][data-responsive-layout="wide"] .dashboard { max-height: none; overflow: visible; }
    html[data-vk-platform="desktop"][data-responsive-layout="wide"][data-responsive-page="lesson"] .sidebar {
        justify-content: flex-start; gap: 12px;
    }
    html[data-vk-platform="desktop"][data-responsive-layout="wide"][data-responsive-page="lesson"] .chat-widget {
        height: auto; flex: 0 0 auto;
    }
    html[data-vk-platform="desktop"][data-responsive-layout="wide"][data-responsive-page="lesson"] .chess-notation {
        position: relative; top: auto; transform: none; margin-top: 0 !important;
    }
    html[data-vk-platform="desktop"][data-responsive-layout="wide"][data-responsive-page="lesson"] .character-info-block {
        height: auto; margin-top: 0; min-width: 0; overflow-wrap: anywhere;
    }
    html[data-vk-platform="desktop"] .menu, html[data-vk-platform="desktop"] .menu-icon { flex-wrap: wrap; row-gap: 8px; }
}
html[data-vk-platform] [data-vk-url] { cursor: pointer; }
#vk-login-status { text-align: center; overflow-wrap: anywhere; }
#vk-link-status {
    position: fixed; z-index: 1000000; inset-inline: 12px; bottom: 12px;
    margin-inline: auto; width: fit-content; max-width: calc(100% - 24px);
    box-sizing: border-box; padding: 8px 12px; border-radius: 8px; background: #242424; color: white;
}
