/* CSS переменные для повторяющихся значений */
:root {
    --primary: #00E5FF;
    --primary-glow: rgba(0, 229, 255, 0.3);
    --primary-glow-strong: rgba(0, 229, 255, 0.7);
    --danger: #FF3030;
    --danger-glow: rgba(255, 48, 48, 0.5);
    --danger-glow-strong: rgba(255, 48, 48, 0.8);
    --bg-dark: #1a1a2e;
    --text-white: #ffffff;
    --text-muted: rgba(255, 255, 255, 0.7);
    --border-radius: 1.5em;
}

/* Системный стек шрифтов (быстрая загрузка, родной вид на каждой ОС) */
html, body {
    height: 100%;
    margin: 0;
    padding: 0;
}
body {
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    align-items: center;
    text-align: center;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg-dark);
    background-image: url('background.jpg');
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    position: relative;
    min-height: 100vh;
    min-height: 100dvh;
    -webkit-overflow-scrolling: touch;
    color: var(--text-white);
    contain: layout style;
}
body::before {
    content: '';
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: linear-gradient(rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0.5));
    z-index: 0;
    pointer-events: none;
}

/* ===== Хедер ===== */
.header-fixed {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 60px;
    background: transparent;
    padding: 0 20px;
    box-sizing: border-box;
    position: relative;
    z-index: 10;
}

/* ===== Логотип ===== */
.logo-fixed {
    position: fixed;
    left: 15px;
    top: 15px;
    transform: none;
    width: 75px;
    height: auto;
    line-height: 0;
    z-index: 100;
    cursor: pointer;
    transition: transform 0.3s ease, width 0.3s ease, left 0.3s ease, top 0.3s ease;
}
@media (max-width: 1024px) {
    .logo-fixed { width: 65px; left: 12px; top: 12px; }
}
@media (max-width: 768px) {
    .logo-fixed { width: 55px; left: 10px; top: 10px; }
}
@media (max-width: 480px) {
    .logo-fixed { width: 50px; left: 8px; top: 8px; }
}
.logo-fixed:hover {
    transform: scale(1.15);
}
.logo-fixed a {
    display: block;
    width: 100%;
    height: auto;
}
.logo-fixed svg {
    display: block;
    width: 100%;
    height: auto;
    will-change: transform;
    transition: transform 0.3s ease, filter 0.3s ease;
    filter: drop-shadow(0 0 8px rgba(0, 136, 170, 0.6))
            drop-shadow(0 0 15px rgba(0, 136, 170, 0.4));
}
.logo-fixed:hover svg {
    filter: drop-shadow(0 0 12px rgba(255, 255, 255, 0.9))
            drop-shadow(0 0 20px rgba(255, 140, 0, 0.7))
            drop-shadow(0 0 35px rgba(255, 140, 0, 0.5));
}

/* ===== Заголовок ===== */
.main-title {
    margin: 0;
    font-size: clamp(1rem, 4vw, 1.8rem);
    color: #FFFFFF;
    font-family: "Open Sans", "Segoe UI", sans-serif;
    text-shadow: 0 0 12px rgba(255, 255, 255, 0.5);
    text-align: center;
    padding: 0 10px;
    line-height: 1.2;
    word-wrap: break-word;
    hyphens: auto;
}

#testWrapper {
    position: fixed;
    top: 100px;
    left: 50%;
    transform: translateX(-50%);
    width: 90%;
    max-width: 50em;
    max-height: calc(100vh - 170px);
    overflow-y: auto;
    background-color: transparent;
    border-radius: 1.5em;
    padding: 1em 0.8em;
    box-shadow: none;
    z-index: 1000;
    box-sizing: border-box;
}

#loading {
    width: 90%;
    max-width: 50em;
    background-color: transparent;
    border-radius: 1.5em;
    padding: 0.3em 0.8em;
    margin: 5px auto;
    box-shadow: none;
}

/* CSS-спиннер вместо base64 PNG */
span.loadCircle {
    display: inline-block;
    width: 1em;
    height: 1em;
    vertical-align: middle;
    margin-right: 0.3em;
    border: 2px solid rgba(0, 229, 255, 0.3);
    border-top-color: #00E5FF;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}
@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(359deg); }
}

#startStopBtn {
    display: inline-block;
    margin: 0 auto;
    padding: 0;
    color: #00E5FF;
    background-color: rgba(0,0,0,0);
    border: 0.15em solid #00E5FF;
    border-radius: 0.3em;
    transition: all 0.3s;
    box-sizing: border-box;
    width: 8em;
    height: 3em;
    line-height: 2.7em;
    cursor: pointer;
    font-weight: bold;
    box-shadow: 0 0 1.5em rgba(0, 229, 255, 0.3);
    text-shadow: 0 0 0.5em rgba(0, 229, 255, 0.5);
    font-family: inherit;
    font-size: inherit;
}
#startStopBtn:focus-visible {
    outline: 2px solid #fff;
    outline-offset: 3px;
}
#startStopBtn:hover {
    background-color: #00E5FF;
    color: #111216;
    box-shadow: 0 0 2.5em rgba(0, 229, 255, 0.7);
    text-shadow: none;
}
#startStopBtn.running {
    background-color: #FF3030;
    border-color: #FF3030;
    color: #FFFFFF;
    box-shadow: 0 0 1.5em rgba(255, 48, 48, 0.5);
    text-shadow: none;
}
#startStopBtn.running:hover {
    background-color: #FF5555;
    border-color: #FF5555;
    box-shadow: 0 0 2.5em rgba(255, 48, 48, 0.8);
}
#startStopBtn.completed {
    background-color: #FFAA33;
    border-color: #FFAA33;
    color: #111216;
    box-shadow: 0 0 2em rgba(255, 170, 51, 0.7);
    text-shadow: none;
}
#startStopBtn.completed:hover {
    background-color: #FFCC00;
    border-color: #FFCC00;
    box-shadow: 0 0 2.5em rgba(255, 204, 0, 0.9);
}

#test {
    margin: 1em 0;
}

/* ===== Базовые стили для testArea ===== */
div.testArea {
    display: inline-block;
    width: 16em;
    max-width: 100%;
    height: 12.5em;
    position: relative;
    box-sizing: border-box;
    vertical-align: top;
    contain: layout style;
    margin: 0 auto;
}
div.testArea2 {
    display: flex !important;
    width: 14em;
    max-width: 100%;
    height: 7em;
    position: relative;
    box-sizing: border-box;
    text-align: center;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    contain: layout style;
    margin: 0 auto;
}
div.testArea div.testName,
div.testArea2 div.testName {
    font-size: 1.4em;
    color: #ffffff;
    text-shadow: 0 0 0.5em rgba(255, 255, 255, 0.4);
}
div.testArea div.testName {
    position: absolute;
    top: 0.1em;
    left: 0;
    width: 100%;
}
div.testArea2 div.testName {
    display: block;
    text-align: center;
}
div.testArea2 div.meterText {
    display: inline-flex;
    align-items: baseline;
    justify-content: center;
    font-size: 2.5em;
    font-weight: bold;
    color: #ffffff;
    text-shadow: 0 0 0.4em rgba(255, 255, 255, 0.6);
    margin: 0;
    white-space: nowrap;
}
div.testArea2 div.meterText span {
    display: inline;
}
div.testArea div.meterText {
    position: absolute;
    bottom: 1.55em;
    left: 0;
    width: 100%;
    font-size: 2.5em;
    z-index: 9;
    font-weight: bold;
}
div.testArea:nth-of-type(1) div.meterText {
    color: #00E5FF;
    text-shadow: 0 0 0.4em rgba(0, 229, 255, 0.6);
}
div.testArea:nth-of-type(2) div.meterText {
    color: #FFAA33;
    text-shadow: 0 0 0.4em rgba(255, 170, 51, 0.6);
}
div.meterText:empty:before {
    content: "0.00";
}
div.testArea div.unit,
div.testArea2 div.unit {
    font-size: 0.9em;
    color: rgba(255, 255, 255, 0.7);
}
div.testArea div.unit {
    position: absolute;
    bottom: 2em;
    left: 0;
    width: 100%;
    z-index: 9;
}
div.testArea canvas,
div.testArea2 canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
    /* Принудительные минимальные размеры для предотвращения схлопывания */
    min-width: 1px;
    min-height: 1px;
}
div.testGroup {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    gap: 1.5em;
    margin: 0 auto;
    width: 100%;
    max-width: 34em;
}

#shareArea {
    width: 95%;
    max-width: 40em;
    margin: 0 auto;
    margin-top: 30px !important;
    background: rgba(20, 21, 26, 0.85);
    border: none;
    border-radius: 12px;
    padding: clamp(12px, 3vw, 20px);
    box-shadow: none;
    display: none;
}
#shareArea.show {
    display: block;
    border: 2px solid #00E5FF;
    box-shadow: 0 0 20px rgba(0, 229, 255, 0.25);
}
#shareArea h3 {
    color: #FF007F;
    text-shadow: 0 0 10px rgba(255, 0, 127, 0.6);
    font-size: 1.5em;
    margin-top: 0;
    text-align: center;
}
.result-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px 16px;
    margin: 20px 0;
    width: 100%;
}
.result-item {
    background: rgba(0,0,0,0.3);
    border-radius: 8px;
    padding: 8px 12px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    min-width: 0;
}
.result-label {
    font-weight: bold;
    color: #cccccc;
    white-space: nowrap;
    flex-shrink: 0;
}
.result-value {
    font-family: monospace;
    font-size: 1.2em;
    font-weight: bold;
    color: #00E5FF;
    text-align: right;
    word-break: break-word;
    flex-shrink: 1;
    min-width: 0;
}
.result-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: clamp(10px, 2vw, 15px);
    justify-content: center;
    margin-top: 15px;
}
.result-btn {
    background: transparent;
    border: 1px solid #00E5FF;
    color: #00E5FF;
    padding: clamp(8px, 1.5vw, 10px) clamp(12px, 2vw, 16px);
    border-radius: 30px;
    cursor: pointer;
    transition: 0.3s;
    font-weight: bold;
    min-width: clamp(100px, 20vw, 120px);
    touch-action: manipulation;
}
.result-btn:focus-visible {
    outline: 2px solid #fff;
    outline-offset: 2px;
}
.result-btn:hover {
    background: #00E5FF;
    color: #111216;
    box-shadow: 0 0 15px rgba(0,229,255,0.5);
}

#historyArea {
    margin-top: 30px;
    background: rgba(0,0,0,0.7);
    border-radius: 12px;
    padding: 0;
    border: 1px solid rgba(0,229,255,0.3);
    overflow: hidden;
}
.history-toggle {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    cursor: pointer;
    user-select: none;
    transition: background 0.2s;
}
.history-toggle:hover {
    background: rgba(0,229,255,0.1);
}
.history-toggle h4 {
    margin: 0;
    color: #FFAA33;
    text-shadow: 0 0 5px rgba(255,170,51,0.5);
    font-size: 1.1rem;
}
.history-arrow {
    color: #FFAA33;
    font-size: 1.2rem;
    transition: transform 0.3s ease;
}
.history-content {
    max-height: 500px;
    overflow: hidden;
    transition: max-height 0.4s ease, padding 0.3s ease, opacity 0.3s ease;
    padding: 0 16px 16px 16px;
    opacity: 1;
    scroll-behavior: auto;
}
#historyArea.collapsed .history-content {
    max-height: 0;
    padding: 0 16px;
    opacity: 0;
}
#historyArea.collapsed .history-arrow {
    transform: rotate(-90deg);
}
#historyArea h4 {
    color: #FFAA33;
    text-shadow: 0 0 5px rgba(255,170,51,0.5);
    margin: 0 0 10px 0;
    text-align: center;
}
#historyList {
    max-height: 200px;
    overflow-y: auto;
}
.history-item {
    background: rgba(255,255,255,0.15);
    margin: 8px 0;
    padding: 8px 12px;
    border-radius: 8px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
}
.history-time {
    font-size: 0.8em;
    color: #aaa;
}
.history-stats {
    font-family: monospace;
    font-size: 0.9em;
    color: #ddd;
}
.history-empty {
    text-align: center;
    color: #888;
    padding: 15px;
}
.history-controls {
    text-align: center;
    margin-top: 12px;
}
#clearHistoryBtn {
    padding: 6px 14px;
    border-color: #FFAA33;
    color: #FFAA33;
}
#clearHistoryBtn:focus-visible {
    outline: 2px solid #fff;
    outline-offset: 2px;
}
#clearHistoryBtn:hover {
    background: #FFAA33;
    color: #111216;
}

#ipArea {
    margin-top: 25px !important;
    margin-bottom: 15px;
    text-align: center;
    width: 100%;
    display: block;
}
#ip {
    font-weight: bold;
    color: rgba(255, 255, 255, 0.85);
    font-size: 1.1em;
    text-shadow: 0 0 8px rgba(255, 255, 255, 0.3);
}

/* Копирайт */
.copyright {
    margin-top: 15px;
    margin-bottom: 10px;
    font-size: 0.85rem;
    color: rgba(255, 255, 255, 0.6);
    text-align: center;
    text-shadow: 0 0 6px rgba(255, 255, 255, 0.2);
    display: block;
    width: 100%;
}

*,
*::before,
*::after {
    box-sizing: border-box;
}
html {
    scroll-behavior: auto;
}
body {
    overflow-x: hidden;
}

/* ===== Анимации видимости ===== */
div.visible {
    visibility: visible;
    opacity: 1;
}
div.hidden {
    visibility: hidden;
    opacity: 0;
}
@keyframes fadeIn {
    0% { opacity: 0; }
    100% { opacity: 1; }
}
@keyframes fadeOut {
    0% { opacity: 1; }
    100% { opacity: 0; }
}

/* ===== АДАПТАЦИЯ ПО ВСЕ УСТРОЙСТВА ===== */

/* Планшеты (до 1024px) */
@media all and (max-width: 64em) {
    body { font-size: 0.95rem; }
    #testWrapper, #loading {
        width: 95%;
        padding: 0.6em 0.5em;
        margin-top: 10px;
    }
    #testWrapper {
        top: 85px;
        max-height: calc(100vh - 105px);
    }
    .main-title { font-size: clamp(1.1rem, 3.5vw, 1.6rem); }
    .logo-fixed { width: 50px; }
    div.testArea { width: 14em; height: 11em; }
    div.testArea2 { width: 12em; height: 6em; }
    div.testArea div.meterText,
    div.testArea2 div.meterText { font-size: 2rem; }
    div.testArea2 div.unit { font-size: 0.5em; }
    div.testGroup {
        gap: 1.5em;
    }
    .result-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 1em;
    }
    .result-btn {
        min-width: 8em;
    }
    #loading {
        padding: 0.25em 0.6em;
        margin: 5px auto;
    }
    #loading p {
        font-size: 0.8rem;
    }
    span.loadCircle {
        width: 0.9em;
        height: 0.9em;
        border-width: 2px;
    }
}

/* Мобильные (до 768px) */
@media all and (max-width: 48em) {
    body {
        font-size: 0.85rem;
        padding: 0.2em;
        touch-action: manipulation;
        -webkit-tap-highlight-color: transparent;
        justify-content: flex-start !important;
    }
    .header-fixed {
        height: 50px;
        padding: 0 10px;
    }
    .logo-fixed {
        width: 45px;
        left: 10px;
    }
    .main-title { 
        font-size: clamp(1rem, 4vw, 1.3rem);
        padding: 0 5px;
    }
    #testWrapper {
        position: relative;
        top: 0;
        left: auto;
        transform: none;
        width: 100%;
        max-width: 100%;
        max-height: none;
        overflow-y: visible;
        margin: 0;
        margin-top: 5px;
        margin-bottom: 10px;
        padding: 0.8em 0.5em;
    }
    #loading {
        margin: 5px auto 8px;
        width: 95%;
        padding: 0.25em 0.5em;
    }
    #loading p {
        font-size: 0.75rem;
    }
    span.loadCircle {
        width: 0.85em;
        height: 0.85em;
        border-width: 2px;
        margin-right: 0.25em;
    }
    #startStopBtn {
        width: 8em;
        height: 2.8em;
        font-size: 1rem;
        line-height: 2.6em;
        margin: 5px auto;
    }
    div.testGroup {
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 1em;
        margin: 0 auto;
    }
    div.testArea,
    div.testArea2 {
        width: 100%;
        max-width: 18em;
        margin: 0 auto;
    }
    div.testArea { height: 11em; }
    div.testArea2 { height: 5.5em; }
    div.testArea div.meterText,
    div.testArea2 div.meterText { font-size: 2.2rem; }
    div.testArea2 div.unit { font-size: 0.55em; }
    div.testArea div.testName,
    div.testArea2 div.testName { font-size: 0.95rem; }
    div.testArea div.unit,
    div.testArea2 div.unit { font-size: 0.85rem; }
    div.testArea canvas {
        max-width: 100%;
    }
    .result-grid {
        grid-template-columns: 1fr;
        gap: 8px;
    }
    .result-item {
        padding: 10px 12px;
        font-size: 0.85rem;
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
        gap: 8px;
    }
    .result-label {
        font-size: 0.85rem;
    }
    .result-value {
        font-size: clamp(0.9rem, 2.5vw, 1.1rem);
        text-align: right;
    }
    .result-buttons {
        flex-wrap: wrap;
        gap: 10px;
    }
    .result-btn {
        flex: 1 1 auto;
        min-width: 110px;
        padding: 10px 16px;
        font-size: 0.85rem;
    }
    #shareArea {
        padding: 12px;
        margin-top: 1em;
    }
    #shareArea h3 { font-size: 1.1rem; }
    #historyArea {
        padding: 0.6em;
        margin-top: 1em;
    }
    .history-item {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.4em;
        padding: 0.6em 0.8em;
        font-size: 0.85rem;
    }
    .history-time { font-size: 0.75rem; }
    .history-stats { font-size: 0.8rem; }
    #ip { font-size: 0.9rem; }
}

/* Пейзажная ориентация на мобильных — оптимизация результатов */
@media all and (max-width: 48em) and (orientation: landscape) {
    body { font-size: 0.85rem; }
    .header-fixed { height: 45px; }
    .logo-fixed {
        width: 40px;
    }
    .main-title { font-size: 1.2rem; }
    #testWrapper {
        margin-top: 10px;
        padding: 0.6em 0.5em;
    }
    div.testGroup {
        flex-direction: row;
        flex-wrap: wrap;
        justify-content: center;
        gap: 1em;
    }
    div.testArea {
        max-width: 13em;
        height: 9em;
        margin: 0 auto;
    }
    div.testArea2 {
        max-width: 11em;
        height: 4.5em;
        margin: 0 auto;
    }
    div.testArea div.meterText,
    div.testArea2 div.meterText { font-size: 1.6rem; }
    div.testArea2 div.unit { font-size: 0.55em; }
    /* Результаты в 2 колонки в ландшафте */
    .result-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
    }
    .result-item {
        padding: 8px 10px;
    }
    .result-label {
        font-size: 0.8rem;
    }
    .result-value {
        font-size: 0.95rem;
    }
    .result-buttons {
        gap: 12px;
    }
    #shareArea {
        padding: 10px 15px;
        max-width: 50em;
    }
}

/* Очень маленькие экраны (до 360px) */
@media all and (max-width: 22.5em) {
    body { font-size: 0.75rem; }
    .main-title { 
        font-size: clamp(0.9rem, 5vw, 1.1rem);
        padding: 0 3px;
    }
    .logo-fixed { width: 35px; }
    #startStopBtn {
        width: 7em;
        height: 2.5em;
        font-size: 0.9rem;
        line-height: 2.3em;
    }
    div.testArea {
        max-width: 15em;
        height: 10em;
    }
    div.testArea2 {
        max-width: 14em;
        height: 5em;
    }
    div.testArea div.meterText,
    div.testArea2 div.meterText { font-size: 1.8rem; }
    div.testArea div.testName,
    div.testArea2 div.testName { font-size: 0.85rem; }
}

/* Предпочтение уменьшенного движения (доступность) */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
    .logo-fixed svg animate {
        animation-duration: 0.01ms !important;
    }
}

/* ===== Адаптация копирайта ===== */
@media all and (max-width: 64em) {
    .copyright {
        font-size: 0.8rem;
        margin-top: 12px;
        margin-bottom: 6px;
    }
}

@media all and (max-width: 48em) {
    .copyright {
        font-size: 0.75rem;
        margin-top: 10px;
        margin-bottom: 5px;
    }
}

@media all and (max-width: 22.5em) {
    .copyright {
        font-size: 0.7rem;
        margin-top: 8px;
        margin-bottom: 5px;
    }
}

/* ===== ДОПОЛНИТЕЛЬНЫЕ УЛУЧШЕНИЯ АДАПТИВНОСТИ ===== */

/* Крупные планшеты и небольшие десктопы (до 1440px) */
@media all and (max-width: 90em) {
    body { font-size: 1rem; }
    #testWrapper { max-width: 45em; }
    div.testArea { width: 15em; height: 11.5em; }
    div.testArea2 { width: 13em; height: 6.5em; }
    .main-title { font-size: clamp(1.1rem, 3vw, 1.5rem); }
}

/* Safe-area insets для iPhone X+ и современных Android */
#testWrapper {
    padding-left: env(safe-area-inset-left, 10px);
    padding-right: env(safe-area-inset-right, 10px);
}

body {
    padding-bottom: env(safe-area-inset-bottom, 0);
}

/* Увеличенная кнопка для мобильных (минимум 50px для touch) */
@media all and (max-width: 48em) {
    #startStopBtn {
        height: 3.2em;
        min-height: 50px;
    }
    
    /* История с отступом снизу */
    #historyArea {
        margin-bottom: 20px;
    }
    .history-content {
        padding: 12px;
    }
}

/* Ландшафт на планшетах и телефонах — оптимизация */
@media all and (max-width: 70em) and (orientation: landscape) {
    body {
        font-size: 0.8rem;
    }
    .header-fixed {
        height: 45px;
    }
    #testWrapper {
        padding: 0.5em 0.3em;
        max-height: calc(100vh - 50px);
    }
    div.testGroup {
        gap: 0.8em;
    }
    div.testArea {
        max-width: 12em;
        height: 8em;
    }
    div.testArea2 {
        max-width: 10em;
        height: 4em;
    }
    div.testArea div.meterText,
    div.testArea2 div.meterText {
        font-size: 1.6rem;
    }
    .main-title {
        font-size: 1.1rem;
        padding: 0 5px;
    }
    /* Результаты в ландшафте */
    .result-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
    }
    .result-item {
        padding: 8px 10px;
    }
    .result-value {
        font-size: 0.95rem;
    }
    #shareArea {
        padding: 10px 15px;
        max-width: 50em;
    }
}

/* Очень маленькие экраны (< 320px) — адаптация результатов */
@media all and (max-width: 20em) {
    span.loadCircle {
        width: 0.75em;
        height: 0.75em;
        border-width: 1.5px;
    }
    .main-title {
        font-size: clamp(0.85rem, 5vw, 1rem);
    }
    /* Результаты для экстремально маленьких экранов */
    .result-grid {
        grid-template-columns: 1fr;
    }
    .result-item {
        padding: 8px 10px;
        gap: 6px;
    }
    .result-label {
        font-size: 0.75rem;
    }
    .result-value {
        font-size: 0.85rem;
    }
    .result-btn {
        min-width: 100px;
        padding: 8px 12px;
        font-size: 0.75rem;
    }
    #shareArea {
        padding: 10px;
        width: 98%;
    }
}

/* Поддержка складных устройств (Foldable) */
@media (spanning: single-fold) {
    #testWrapper {
        max-width: 90vw;
    }
}

/* iPad Portrait (768px — 1024px) */
@media all and (min-width: 48em) and (max-width: 64em) and (orientation: portrait) {
    #testWrapper {
        width: 90%;
        max-width: 40em;
    }
    div.testArea {
        width: 13em;
        height: 10em;
    }
    div.testArea2 {
        width: 11em;
        height: 5.5em;
    }
    .testGroup {
        gap: 1.2em;
    }
}

/* Увеличенный контраст для ярких условий (солнце) */
@media all and (max-width: 48em) {
    .meterText {
        text-shadow: 0 0 0.6em rgba(255, 255, 255, 0.8);
    }
    .result-value {
        color: #00FFFF;
        text-shadow: 0 0 4px rgba(0, 255, 255, 0.6);
    }
}

/* Tach-устройства: убираем hover-эффекты */
@media (hover: none) and (pointer: coarse) {
    .logo-fixed:hover {
        transform: none;
    }
    .logo-fixed:hover svg {
        filter: drop-shadow(0 0 8px rgba(0, 136, 170, 0.6))
                drop-shadow(0 0 15px rgba(0, 136, 170, 0.4));
    }
    #startStopBtn:hover {
        background-color: rgba(0,0,0,0);
        color: #00E5FF;
        box-shadow: 0 0 1.5em rgba(0, 229, 255, 0.3);
        text-shadow: 0 0 0.5em rgba(0, 229, 255, 0.5);
    }
    .result-btn:hover {
        background: transparent;
        color: #00E5FF;
        box-shadow: none;
    }
}

/* Стили для печати */
@media print {
    body {
        background: white !important;
        color: black !important;
        min-height: auto;
    }
    body::before {
        display: none;
    }
    .header-fixed,
    .logo-fixed,
    #loading,
    #startStopBtn,
    #shareArea,
    #historyArea,
    .disclaimer,
    .copyright {
        display: none !important;
    }
    #testWrapper {
        position: static;
        width: 100%;
        max-width: 100%;
        transform: none;
        background: transparent;
        box-shadow: none;
    }
    div.testArea,
    div.testArea2 {
        display: block !important;
        width: 100% !important;
        max-width: 100% !important;
        height: auto !important;
        page-break-inside: avoid;
        margin-bottom: 1em;
    }
    div.testArea canvas,
    div.testArea2 canvas {
        display: none;
    }
    div.testArea div.meterText,
    div.testArea2 div.meterText {
        position: static !important;
        font-size: 1.5rem !important;
        color: black !important;
        text-shadow: none !important;
    }
    div.testArea div.unit,
    div.testArea2 div.unit {
        position: static !important;
    }
    .result-grid {
        grid-template-columns: 1fr 1fr !important;
    }
    .result-item {
        background: #f0f0f0 !important;
        border: 1px solid #ccc !important;
    }
    .result-value {
        color: black !important;
        text-shadow: none !important;
    }
    #ip {
        color: black !important;
        text-shadow: none !important;
    }
}

/* iPad Pro 12.9" (1002px) — промежуточный брейкпоинт */
@media all and (min-width: 62.75em) and (max-width: 64em) {
    #testWrapper {
        max-width: 48em;
    }
    div.testArea {
        width: 15.5em;
        height: 12em;
    }
    div.testArea2 {
        width: 13.5em;
        height: 6.5em;
    }
}

/* Максимальная ширина контейнера для огромных экранов */
@media all and (min-width: 80em) {
    #testWrapper {
        max-width: 55em;
    }
}

