@font-face {
    font-family: "Nas";
    src: url("../fonts/Nas.ttf") format("truetype");
    font-display: swap;
}

@font-face {
    font-family: "BYekan";
    src: url("../fonts/BYekan.ttf") format("truetype");
    font-display: swap;
}

:root {
    --bg: #07090d;
    --panel: rgba(15, 18, 25, 0.88);
    --panel-edge: rgba(255, 255, 255, 0.075);
    --text: #f5f7fb;
    --muted: #8e98aa;
    --red: #ff202d;
    --red-hot: #ff3440;
    --green: #35d07f;
    --danger: #ff5b67;
    --shadow: 0 24px 70px rgba(0, 0, 0, 0.38);
}

* {
    box-sizing: border-box;
}

html,
body {
    width: 100%;
    height: 100%;
    min-height: 100%;
    margin: 0;
    overflow: hidden;
    background: var(--bg);
    color-scheme: dark;
}

body {
    font-family: "BYekan", Tahoma, Arial, sans-serif;
    color: var(--text);
    background:
        radial-gradient(circle at 50% 0%, rgba(76, 87, 110, 0.13), transparent 34%),
        radial-gradient(circle at 20% 92%, rgba(255, 32, 45, 0.03), transparent 25%),
        linear-gradient(180deg, #080a0f 0%, #05070a 100%);
}

body::before {
    content: "";
    position: fixed;
    inset: 0;
    pointer-events: none;
    opacity: .22;
    background-image:
        linear-gradient(rgba(255,255,255,.013) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255,255,255,.013) 1px, transparent 1px);
    background-size: 30px 30px;
    mask-image: linear-gradient(to bottom, black, transparent 72%);
}

.app-shell {
    width: min(100%, 980px);
    height: 100vh;
    height: 100svh;
    margin: 0 auto;
    padding:
        max(12px, env(safe-area-inset-top))
        16px
        max(10px, env(safe-area-inset-bottom));
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto auto;
    align-items: center;
    gap: clamp(12px, 2.2vh, 22px);
}

.brand-header {
    width: 100%;
    text-align: center;
    padding: clamp(34px, 5.8vh, 58px) 8px 0;
}

.eyebrow {
    color: var(--muted);
    font-family: "BYekan", Tahoma, Arial, sans-serif;
    font-size: 11px;
    margin-bottom: 13px;
}

.brand-header h1 {
    margin: 0;
    font-family: "Nas", Tahoma, Arial, sans-serif;
    font-weight: 700;
    font-size: clamp(21px, 4.4vw, 31px);
    line-height: 1.65;
    color: #f4c542;
    text-shadow: 0 0 14px rgba(244, 197, 66, .08);
}

.scale-panel {
    position: relative;
    width: 100%;
    align-self: center;
    padding: clamp(10px, 1.8vh, 16px);
    border: 1px solid var(--panel-edge);
    border-radius: 26px;
    background:
        linear-gradient(180deg, rgba(255,255,255,.035), rgba(255,255,255,.012)),
        var(--panel);
    box-shadow: var(--shadow);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    overflow: hidden;
}

.scale-panel::before {
    content: "";
    position: absolute;
    width: 40%;
    height: 1px;
    top: 0;
    right: 30%;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,.34), transparent);
}

.panel-top,
.panel-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 2px 4px;
    color: var(--muted);
    font-family: "BYekan", Tahoma, Arial, sans-serif;
}

.panel-top {
    margin-bottom: clamp(8px, 1.4vh, 12px);
}

.live-title {
    font-size: 12px;
    font-weight: 700;
}

.connection-pill {
    min-height: 30px;
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 0 11px;
    border-radius: 999px;
    font-size: 11px;
    border: 1px solid rgba(255,255,255,.06);
    background: rgba(255,255,255,.025);
    color: #c4c9d2;
}

.connection-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    display: inline-block;
    flex: 0 0 auto;
    background: var(--danger);
    box-shadow:
        0 0 0 4px rgba(255, 91, 103, 0.07),
        0 0 10px rgba(255, 91, 103, 0.20);
}

.connection-pill.online {
    color: #d9ffe9;
    border-color: rgba(53, 208, 127, .16);
    background: rgba(53, 208, 127, .055);
}

.connection-pill.online .connection-dot {
    background: var(--green);
    box-shadow:
        0 0 0 4px rgba(53, 208, 127, 0.08),
        0 0 14px rgba(53, 208, 127, .42);
    animation: onlinePulse 1.15s ease-in-out infinite;
}

@keyframes onlinePulse {
    0%, 100% {
        opacity: 1;
        transform: scale(1);
        box-shadow:
            0 0 0 4px rgba(53, 208, 127, 0.08),
            0 0 10px rgba(53, 208, 127, .35);
    }
    50% {
        opacity: .34;
        transform: scale(.82);
        box-shadow:
            0 0 0 8px rgba(53, 208, 127, 0.025),
            0 0 20px rgba(53, 208, 127, .55);
    }
}

.display-wrap {
    position: relative;
    overflow: hidden;
    border-radius: 19px;
    background:
        linear-gradient(180deg, rgba(255,255,255,.018), transparent 32%),
        #020304;
    border: 1px solid rgba(255,255,255,.055);
    box-shadow:
        inset 0 0 38px rgba(0,0,0,.88),
        inset 0 1px 0 rgba(255,255,255,.025);
    padding:
        clamp(18px, 4.2vh, 48px)
        clamp(10px, 3vw, 24px)
        clamp(10px, 1.8vh, 16px);
}

.display-wrap::after {
    content: "";
    position: absolute;
    inset: 0;
    pointer-events: none;
    background:
        linear-gradient(112deg, transparent 0 44%, rgba(255,255,255,.028) 48%, transparent 53%);
}

.display-glow {
    position: absolute;
    inset: 20% 8%;
    background:
        radial-gradient(ellipse at center, rgba(255, 25, 36, .10), transparent 67%);
    filter: blur(15px);
    pointer-events: none;
}

.digit-display {
    direction: ltr;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: clamp(5px, 1.6vw, 14px);
    width: 100%;
    isolation: isolate;
}

.digit {
    position: relative;
    width: min(14vw, 116px);
    height: min(20vh, 196px);
    min-height: 112px;
    max-height: 196px;
    filter: drop-shadow(0 0 8px rgba(255, 32, 45, .11));
}

.segment {
    position: absolute;
    background: rgba(255, 32, 45, .055);
    transition:
        background .085s linear,
        box-shadow .085s linear,
        opacity .085s linear;
    opacity: .74;
}

.segment.on {
    background: linear-gradient(180deg, var(--red-hot), #e90011);
    box-shadow:
        0 0 8px rgba(255, 32, 45, .72),
        0 0 20px rgba(255, 32, 45, .27);
    opacity: 1;
}

.segment.h {
    left: 18%;
    width: 64%;
    height: 9%;
    clip-path: polygon(10% 0, 90% 0, 100% 50%, 90% 100%, 10% 100%, 0 50%);
}

.segment.v {
    width: 15%;
    height: 39%;
    clip-path: polygon(50% 0, 100% 10%, 100% 90%, 50% 100%, 0 90%, 0 10%);
}

.segment.a { top: 2%; }
.segment.g { top: 45.5%; }
.segment.d { bottom: 2%; }

.segment.f { left: 3%; top: 7.5%; }
.segment.b { right: 3%; top: 7.5%; }
.segment.e { left: 3%; bottom: 7.5%; }
.segment.c { right: 3%; bottom: 7.5%; }

.digit.changed {
    animation: digitPulse .18s ease-out;
}

@keyframes digitPulse {
    0%   { transform: scale(.985); filter: brightness(.85); }
    55%  { transform: scale(1.012); filter: brightness(1.18); }
    100% { transform: scale(1); }
}

.unit-row {
    margin-top: clamp(7px, 1.3vh, 12px);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 9px;
    color: rgba(255,255,255,.45);
    font-family: "BYekan", Tahoma, Arial, sans-serif;
}

.unit {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 1px;
}

.unit-line {
    width: 22px;
    height: 1px;
    background: rgba(255,255,255,.11);
}

.panel-footer {
    margin-top: clamp(7px, 1.3vh, 11px);
    font-size: 10px;
    line-height: 1.65;
}

.logo-zone {
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    margin: 0;
}

.logo-card {
    width: min(42vw, 190px);
    min-height: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    border: 0;
    border-radius: 0;
    background: transparent;
}

.logo-card img {
    display: block;
    max-width: 100%;
    max-height: clamp(74px, 13vh, 112px);
    object-fit: contain;
    filter: drop-shadow(0 10px 22px rgba(0,0,0,.28));
}

.logo-fallback {
    direction: ltr;
    font-family: "BYekan", Tahoma, Arial, sans-serif;
    font-weight: 700;
    letter-spacing: 2px;
    color: rgba(255,255,255,.55);
    font-size: 18px;
}

.app-footer {
    padding: 0 0 2px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    color: rgba(255,255,255,.20);
    font-family: "BYekan", Tahoma, Arial, sans-serif;
    font-size: 9px;
}

.footer-dot {
    width: 4px;
    height: 4px;
    border-radius: 50%;
    background: rgba(255, 32, 45, .45);
}

@media (min-width: 700px) {
    .app-shell {
        padding-left: 28px;
        padding-right: 28px;
    }

    .scale-panel {
        border-radius: 31px;
    }

    .display-wrap {
        border-radius: 22px;
    }
}

@media (max-width: 560px) {
    .app-shell {
        padding-left: 10px;
        padding-right: 10px;
        gap: 10px;
    }

    .brand-header h1 {
        font-size: clamp(19px, 6.4vw, 26px);
    }

    .scale-panel {
        padding: 10px;
        border-radius: 21px;
    }

    .digit-display {
        gap: 4px;
    }

    .digit {
        width: 13.7vw;
        height: min(19vh, 150px);
        min-height: 94px;
    }

    .panel-footer {
        font-size: 9px;
    }

    .logo-card {
        width: min(42vw, 150px);
    }

    .logo-card img {
        max-height: 82px;
    }
}

@media (max-height: 720px) {
    .app-shell {
        gap: 8px;
        padding-top: 6px;
        padding-bottom: 6px;
    }

    .eyebrow {
        margin-bottom: 0;
        font-size: 10px;
    }

    .brand-header {
        padding-top: 24px;
    }

    .eyebrow {
        margin-bottom: 9px;
    }

    .brand-header h1 {
        font-size: clamp(19px, 4vw, 27px);
        line-height: 1.45;
    }

    .display-wrap {
        padding-top: 14px;
        padding-bottom: 8px;
    }

    .digit {
        height: min(17vh, 142px);
        min-height: 90px;
    }

    .logo-card img {
        max-height: 72px;
    }

    .panel-top {
        margin-bottom: 6px;
    }

    .panel-footer {
        margin-top: 6px;
    }

    .unit-row {
        margin-top: 5px;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: .01ms !important;
        transition-duration: .01ms !important;
    }
}


.connection-area {
    display: flex;
    align-items: center;
    gap: 8px;
}

.connect-btn {
    border: 1px solid rgba(244, 197, 66, .22);
    background: rgba(244, 197, 66, .06);
    color: #f4c542;
    min-height: 30px;
    padding: 0 12px;
    border-radius: 999px;
    font-family: "BYekan", Tahoma, Arial, sans-serif;
    font-size: 10px;
    cursor: pointer;
    transition: .16s ease;
}

.connect-btn:hover {
    border-color: rgba(244, 197, 66, .44);
    background: rgba(244, 197, 66, .10);
}

.connect-btn:active { transform: scale(.97); }
.connect-btn[disabled] { opacity: .55; cursor: wait; }
.connect-btn.connected { display: none; }

.serial-hint {
    display: none;
    margin-top: 7px;
    padding: 0 4px;
    color: rgba(255,255,255,.36);
    font-family: "BYekan", Tahoma, Arial, sans-serif;
    font-size: 9px;
    text-align: center;
    line-height: 1.7;
}

.serial-hint.show { display: block; }

@media (max-width: 560px) {
    .connection-area { gap: 5px; }
    .connect-btn {
        min-height: 28px;
        padding: 0 9px;
        font-size: 9px;
    }
}

@media (max-width: 410px) {
    .panel-top { align-items: flex-start; }
    .connection-area {
        flex-direction: column;
        align-items: flex-end;
        gap: 5px;
    }
}
