
/* --- Выдвижная шторка секундомера (только тач-устройства; см. media ниже) --- */
.mobile-lap-sheet {
    display: none;
    box-sizing: border-box;
    position: fixed;
    z-index: 900;
    left: 0;
    right: 0;
    bottom: 0;
    height: 50vh;
    height: 50dvh;
    background: transparent;
    border: none;
    border-radius: 0;
    box-shadow: none;
    transition: transform 0.18s ease-out;
    touch-action: none;
    display: flex;
    flex-direction: column;
}

.mobile-lap-sheet-handle-zone {
    height: 84px;
    flex: 0 0 84px;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    cursor: grab;
    user-select: none;
    padding-bottom: 6px;
    box-sizing: border-box;
    position: relative;
    /* Без preventDefault на touchmove (у React listener passive): блокируем скролл/жесты браузера здесь */
    touch-action: none;
}

.mobile-lap-sheet-handle-zone::before {
    content: "";
    position: absolute;
    bottom: 10px;
    left: 50%;
    transform: translateX(-50%);
    width: 132px;
    height: 34px;
    border: 1px solid rgba(210, 215, 230, 0.32);
    border-bottom: none;
    border-radius: 22px 22px 0 0;
    background: linear-gradient(
        to bottom,
        rgba(190, 200, 225, 0.2) 0%,
        rgba(190, 200, 225, 0.08) 55%,
        rgba(190, 200, 225, 0) 100%
    );
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
}

.mobile-lap-sheet-handle {
    width: 48px;
    height: 4px;
    border-radius: 999px;
    background: rgba(228, 234, 248, 0.72);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
    z-index: 1;
    transform: translateY(-10px);
}

.mobile-lap-sheet-handle-zone.is-expanded::before {
    bottom: 6px;
}

.mobile-lap-sheet-handle-zone.is-expanded .mobile-lap-sheet-handle {
    transform: translateY(-6px);
}

.mobile-lap-sheet-handle-zone.is-collapsed::before {
    bottom: 18px;
}

.mobile-lap-sheet-handle-zone.is-collapsed .mobile-lap-sheet-handle {
    transform: translateY(-18px);
}

.mobile-lap-timer-btn {
    display: flex;
    box-sizing: border-box;
    width: calc(50% - 6px);
    height: auto;
    flex: 1 1 auto;
    min-height: 0;
    margin: 0;
    padding: clamp(6px, 2vmin, 16px);
    border: 2px solid rgba(255, 255, 255, 0.38);
    border-radius: clamp(12px, 2.5vmin, 22px);
    background: rgba(11, 11, 11, 0.92);
    box-shadow: 0 4px 18px rgba(0, 0, 0, 0.55);
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    gap: clamp(4px, 1.2vmin, 12px);
    font-family: monospace, ui-monospace, monospace;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
    cursor: pointer;
    transform-origin: center center;
    transition:
        transform var(--btn-transition-duration, 0.22s) cubic-bezier(0.33, 1, 0.68, 1),
        box-shadow var(--btn-transition-duration, 0.22s) ease,
        border-color var(--btn-transition-duration, 0.22s) ease,
        background var(--btn-transition-duration, 0.22s) ease,
        filter var(--btn-transition-duration, 0.22s) ease;
}

.mobile-lap-timer-btn:hover {
    border-color: rgba(255, 255, 255, 0.62);
    background: rgba(20, 20, 20, 0.96);
    transform: scale(1.012);
    box-shadow: 0 8px 26px rgba(0, 0, 0, 0.62);
    filter: brightness(1.06);
}

.mobile-lap-timer-btn:active {
    transform: scale(0.985);
    border-color: rgba(255, 255, 255, 0.78);
    box-shadow: inset 0 7px 22px rgba(0, 0, 0, 0.68);
    filter: brightness(0.9);
    transition-duration: var(--btn-transition-press, 0.09s);
}

.mobile-lap-timer-btn:disabled,
.mobile-lap-timer-btn.mobile-lap-timer-btn--locked {
    opacity: 0.45;
    cursor: not-allowed;
    pointer-events: none;
    transform: none;
    filter: none;
    box-shadow: 0 4px 18px rgba(0, 0, 0, 0.55);
}

.mobile-lap-timers-row {
    display: flex;
    flex: 1 1 auto;
    min-height: 0;
    gap: 6px;
    padding: 0 6px 6px;
    box-sizing: border-box;
}

/* 2–4 stopwatch buttons: 2 columns × 1–2 rows */
.mobile-lap-timers-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-auto-rows: 1fr;
    gap: 6px;
    flex: 1 1 auto;
    min-height: 0;
    padding: 0 6px 6px;
    box-sizing: border-box;
    align-content: stretch;
}

.mobile-lap-timers-grid .mobile-lap-timer-btn {
    width: 100%;
    flex: 1 1 auto;
    min-height: 0;
    margin: 0;
}

.mobile-lap-timer-btn-left {
    margin-left: 0;
}

.mobile-lap-timer-btn-right {
    margin-left: auto;
}

.mobile-lap-timer-center {
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 0;
    width: 100%;
    gap: clamp(6px, 1.4vmin, 12px);
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}

.mobile-lap-timer-reset-hint {
    font-size: clamp(9px, 2.4vmin, 15px);
    font-weight: 500;
    letter-spacing: 0.02em;
    color: #7a828e;
    line-height: 1.25;
    text-align: center;
    max-width: 100%;
    padding: 0 4px;
    box-sizing: border-box;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
    -webkit-user-drag: none;
    cursor: pointer;
    touch-action: manipulation;
}

.mobile-lap-timer-driver {
    font-size: clamp(12px, 3.2vmin, 22px);
    font-weight: 600;
    letter-spacing: 0.04em;
    color: #b8c0cc;
    line-height: 1.1;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    margin-top: clamp(8px, 2vmin, 18px);
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
    cursor: pointer;
}

.mobile-lap-timer-driver-input {
    width: 90%;
    box-sizing: border-box;
    background: rgba(0, 0, 0, 0.65);
    border: 1px solid rgba(255, 255, 255, 0.35);
    color: #b8b8b8;
    border-radius: 8px;
    font-size: clamp(12px, 3.2vmin, 22px);
    font-family: monospace, ui-monospace, monospace;
    padding: 6px 10px;
    margin-top: clamp(8px, 2vmin, 18px);
    outline: none;
}

.mobile-lap-timer-value {
    font-size: clamp(14px, 6.5vmin, 48px);
    font-weight: bold;
    color: #e8e8e8;
    line-height: 1.15;
    text-align: center;
    word-break: break-all;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}

/* Только «мобильный» ввод: тач; не показываем на ПК с мышью */
@media (pointer: coarse) {
    .mobile-lap-sheet {
        display: flex;
        flex-direction: column;
    }
}

@media (pointer: fine) and (min-width: 641px) {
    .mobile-lap-sheet,
    .mobile-lap-timer-btn {
        display: none !important;
    }
}

/*
 * Нормальный viewport (width=device-width): таблица больше не масштабируется с «виртуальной»
 * шириной ~980px — семь колонок дают min-content шире экрана. Фиксируем раскладку и имя с ellipsis.
 */
@media (max-width: 768px) {
    .container {
        max-width: 100%;
        box-sizing: border-box;
        overflow: visible;
    }

    .timing-table-wrap {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    #timing-table {
        table-layout: fixed;
        width: 100%;
        min-width: 0;
        border-collapse: collapse;
    }
}

/*
 * Альбом: широкие колонки под время (14% на круг при ~400px+ ширины хватает при 16px).
 */
@media (max-width: 768px) and (orientation: landscape) {
    #timing-table th:nth-child(1),
    #timing-table td:nth-child(1) {
        width: 7%;
        text-align: center;
    }

    #timing-table th:nth-child(2),
    #timing-table td:nth-child(2) {
        width: 6%;
    }

    #timing-table th:nth-child(3),
    #timing-table td:nth-child(3) {
        width: 31%;
        min-width: 0;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    #timing-table th:nth-child(4),
    #timing-table td:nth-child(4),
    #timing-table th:nth-child(5),
    #timing-table td:nth-child(5),
    #timing-table th:nth-child(6),
    #timing-table td:nth-child(6),
    #timing-table th:nth-child(7),
    #timing-table td:nth-child(7) {
        width: 14%;
        font-variant-numeric: tabular-nums;
        white-space: nowrap;
    }

    #timing-table td,
    #timing-table th {
        padding-left: 6px;
        padding-right: 6px;
    }
}

/*
 * Портрет: узкий экран — 14% на BEST/LAST с 16px = ~45px под «0:55.312», физически не влезает и рисуется поверх соседа.
 * Даём времени больше доли строки + моноширинный мелкий текст + клип в ячейке.
 */
@media (max-width: 768px) and (orientation: portrait) {
    #timing-table td,
    #timing-table th {
        box-sizing: border-box;
        padding: 6px 2px !important;
    }

    #timing-table th:nth-child(1),
    #timing-table td:nth-child(1) {
        width: 6%;
        text-align: center;
    }

    #timing-table th:nth-child(2),
    #timing-table td:nth-child(2) {
        width: 5%;
    }

    #timing-table th:nth-child(3),
    #timing-table td:nth-child(3) {
        width: 19%;
        min-width: 0;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        font-size: 10px;
        line-height: 1.2;
        font-weight: 600;
    }

    #timing-table th:nth-child(4),
    #timing-table td:nth-child(4),
    #timing-table th:nth-child(5),
    #timing-table td:nth-child(5) {
        width: 21%;
        font-family: ui-monospace, "Cousine", monospace;
        font-size: 10px;
        font-weight: 600;
        letter-spacing: -0.03em;
        font-variant-numeric: tabular-nums;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: clip;
        text-align: center;
        padding-left: 2px;
        padding-right: 2px;
    }

    #timing-table th:nth-child(6),
    #timing-table td:nth-child(6),
    #timing-table th:nth-child(7),
    #timing-table td:nth-child(7) {
        width: 14%;
        font-family: ui-monospace, "Cousine", monospace;
        font-size: 10px;
        font-weight: 600;
        letter-spacing: -0.03em;
        font-variant-numeric: tabular-nums;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: clip;
        text-align: center;
        padding-left: 2px;
        padding-right: 2px;
    }

    #timing-table thead th {
        font-size: 7px;
        letter-spacing: 0.02em;
        line-height: 1.1;
    }

    #timing-table tbody td {
        overflow: hidden;
        vertical-align: middle;
    }

    /* Модалка кругов */
    .laps-table-container {
        zoom: 0.82;
    }
}

/* На мобилках кнопки могут не влезть в ряд с заголовком, 
   поэтому добавим небольшую правку */
@media (max-width: 600px) {
    .header-row {
        flex-direction: column;
        gap: 15px;
    }
    .header-buttons {
        width: 100%;
        justify-content: center;
    }
}





@media (max-width: 600px) {
    .modal-content {
        width: 100%;
        /* Use dvh to account for the address bar changing size */
        max-height: 80dvh; 
        border-radius: 15px 15px 0 0;
        display: flex;
        flex-direction: column;
    }
    
    .laps-table-container {
        /* This prevents "ghost" scrolling issues on iOS */
        -webkit-overflow-scrolling: touch;
    }
}


@media (max-width: 600px) {
    .modal-content {
        width: 100%;
        /* Use dvh to account for the address bar changing size */
        max-height: 80dvh; 
        border-radius: 15px 15px 0 0;
        display: flex;
        flex-direction: column;
    }
    
    .laps-table-container {
        /* This prevents "ghost" scrolling issues on iOS */
        -webkit-overflow-scrolling: touch;
    }
}

/* --- Mobile Responsiveness --- */
@media (max-width: 600px) {
    /* Не раздуваем все td: в узкой #timing-table 16px даёт наложение цифр.
       Масштаб — zoom на таблицах (см. max-width: 768px). Модалка: page1_modal.css + zoom на .laps-table-container. */

    /* Bottom Sheet Style for Mobile */
    .modal {
        align-items: flex-end;
    }

    .modal-content {
        width: 100%;
        max-height: 80vh;
        border-radius: 15px 15px 0 0;
    }
}


/* Адаптив: на узких экранах выносим дату в отдельную строку, если не влезает */
@media (max-width: 650px) {
    .input-date {
        flex: 1;
        font-size: 16px; /* Предотвращает зум при клике в iOS */
    }
    .header-buttons {
        gap: 8px;
    }
    .date-selector {
        margin-right: 5px;
    }
}

/* Портрет: шторка секундомера ниже меню профиля (portal 1100) */
@media (max-width: 768px) and (orientation: portrait) {
    .mobile-lap-sheet {
        z-index: 850;
    }

    .mobile-lap-sheet.mobile-lap-sheet--slots-3,
    .mobile-lap-sheet.mobile-lap-sheet--slots-4 {
        height: 58dvh;
    }

    .header-row.profile-menu-open {
        z-index: 960;
    }
}

/* Финальный override: в портрете модалка всегда видна в пределах экрана */
@media (max-width: 768px) and (orientation: portrait) {
    .modal {
        position: fixed !important;
        inset: 0 !important;
        top: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        left: 0 !important;
        width: 100vw !important;
        height: 100vh !important;
        height: 100dvh !important;
        min-height: 100dvh !important;
        justify-content: flex-end !important;
        align-items: stretch !important;
        padding: 0 !important;
        overflow: hidden;
    }

    .modal-content {
        position: fixed !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        width: 100vw !important;
        max-width: 100vw !important;
        height: 82vh !important;
        height: 82dvh !important;
        max-height: 82dvh !important;
        margin: 0 !important;
        padding-bottom: env(safe-area-inset-bottom, 0px);
        border-radius: 16px 16px 0 0 !important;
        transform: none !important;
        overflow: hidden !important;
    }
}








