/* ==========================================================================
   I. ĐỊNH DẠNG CƠ BẢN & KHUNG GIAO DIỆN CHUNG (CYBERPUNK BASE)
   ========================================================================== */
:root {
    --accent-color: #fdba74;
    --accent-strong: #f97316;
    --text-color: #ffedd5;
    --muted-color: #94a3b8;
    --icon-size: 64px;
    --flag-size: 32px;
    --icon-column-width: 80px;
    --icon-gap: 12px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    background-color: #050302;
    color: #f8fafc;
    font-family: 'Oxanium', sans-serif;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    padding: 15px;
    overflow-y: auto;
    position: relative;
}

#matrix-canvas {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
}

.wrapper {
    width: 100%;
    max-width: 560px;
    display: flex;
    flex-direction: column;
    gap: 15px;
    position: relative;
    z-index: 2;
}

.block {
    background: rgba(15, 8, 3, 0.8);
    border-radius: 16px;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(249, 115, 22, 0.3);
    box-shadow: 0 15px 35px rgba(0, 0, 0, 0.8);
    padding: 1.5rem;
    text-align: center;
    width: 100%;
    overflow: hidden;
}

/* ==========================================================================
   II. PHẦN 1: ĐỒNG HỒ ĐIỆN TỬ LED REALTIME
   ========================================================================== */
.greeting {
    font-size: 0.85rem;
    font-weight: 700;
    color: #fdba74;
    text-transform: uppercase;
    letter-spacing: 0.15em;
    margin-bottom: 0.2rem;
}

.clock {
    font-family: 'LED Digital 7', monospace;
    font-size: 3.2rem;
    color: #f97316;
    text-shadow: 0 0 15px rgba(249, 115, 22, 0.7);
    line-height: 1.1;
    letter-spacing: 2px;
    transition: color 0.3s ease, text-shadow 0.3s ease;
}

.date {
    font-size: 0.95rem;
    color: #ea580c;
    letter-spacing: 0.05em;
    margin-top: 0.4rem;
    font-weight: 600;
}

.lunar-date {
    font-size: 0.8rem;
    color: #f97316;
    letter-spacing: 0.05em;
    margin-top: 0.3rem;
    font-weight: 500;
    opacity: 0.85;
}

/* ==========================================================================
   III. PHẦN 2: LƯỚI THÔNG SỐ THIẾT BỊ PHẦN CỨNG
   ========================================================================== */
.info-title {
    font-size: 0.85rem;
    color: #f97316;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    font-weight: 700;
    margin-bottom: 1rem;
    border-bottom: 1px dashed rgba(249, 115, 22, 0.3);
    padding-bottom: 0.5rem;
}

.info-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
}

.info-card {
    background: rgba(0, 0, 0, 0.6);
    border: 1px solid rgba(249, 115, 22, 0.1);
    border-radius: 10px;
    padding: 12px;
    text-align: left;
    display: flex;
    flex-direction: column;
    justify-content: center;
    overflow: hidden;
    min-width: 0;
}

.info-card.full-width {
    grid-column: span 2;
}

.info-label {
    font-size: 0.7rem;
    color: #94a3b8;
    text-transform: uppercase;
    margin-bottom: 4px;
    letter-spacing: 0.05em;
    font-weight: 600;
}

.info-value {
    font-size: 0.85rem;
    font-weight: 600;
    color: #ffedd5;
    font-family: 'Space Mono', monospace;
    word-break: break-all;
    line-height: 1.3;
    display: flex;
    align-items: center;
}

/* ==========================================================================
   IV. THỜI TIẾT HIỆN TẠI (CARD MỚI)
   ========================================================================== */
.weather-card {
    align-items: stretch;
    gap: 8px;
    min-height: 92px;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.weather-layout {
    display: grid;
    grid-template-columns: var(--icon-column-width) 1fr;
    align-items: center;
    gap: var(--icon-gap);
    width: 100%;
}

.weather-icon-box {
    display: flex;
    align-items: center;
    justify-content: center;
}

.weather-text-box {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 0;
    justify-content: center;
    align-items: center;
    text-align: center;
}

.weather-condition {
    color: #fdba74;
    font-size: 0.9rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.weather-icon {
    width: var(--icon-size);
    height: var(--icon-size);
    flex-shrink: 0;
    object-fit: contain;
    display: block;
    filter: drop-shadow(0 0 12px rgba(253, 186, 116, 0.45));
}

.weather-icon-placeholder,
.flag-3d-box img.emoji.placeholder {
    width: var(--icon-size);
    height: var(--icon-size);
    object-fit: contain;
    display: block;
    border-radius: 50%;
}

.weather-main-row {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    flex-wrap: wrap;
}

.weather-main {
    font-size: 1.15rem;
    font-weight: 700;
    color: #fef3c7;
    font-family: 'Space Mono', monospace;
}

.weather-meta {
    font-size: 0.78rem;
    color: #cbd5e1;
    line-height: 1.4;
}

.weather-last-update-row {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    flex-wrap: wrap;
}

.weather-last-update {
    font-size: 0.7rem;
    color: #fb923c;
    line-height: 1.3;
    opacity: 0.9;
}

.weather-copy-btn {
    background: transparent;
    border: none;
    color: #ffedd5;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    padding: 0;
    font-size: 0.95rem;
    line-height: 1;
    transition: transform 0.2s ease, opacity 0.2s ease;
}

.weather-copy-btn:hover {
    transform: translateY(-1px);
    opacity: 0.9;
}

.weather-copy-btn:active {
    transform: scale(0.96);
}

.weather-loading,
.weather-empty {
    font-size: 0.78rem;
    color: #94a3b8;
    font-style: italic;
}

/* ==========================================================================
   V. HIỆU ỨNG QUỐC KỲ KHỐI LỒI GƯƠNG 3D
   ========================================================================== */
.flag-3d-box {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    vertical-align: middle;
    margin-right: 8px;
    border-radius: 50%;
    width: var(--flag-size);
    height: var(--flag-size);
    padding: 0;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.5), inset 0 -1px 2px rgba(0, 0, 0, 0.4);
    flex-shrink: 0;
}

.flag-3d-box::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    background: radial-gradient(circle at 35% 35%, rgba(255, 255, 255, 0.5) 0%, rgba(255, 255, 255, 0) 60%),
        linear-gradient(to bottom, rgba(255, 255, 255, 0.15), rgba(0, 0, 0, 0.25));
    pointer-events: none;
}

.info-value img.emoji,
.v4-val-box img.emoji,
.v6-val-box img.emoji {
    height: 100%;
    width: 100%;
    object-fit: cover;
    object-position: center;
    border-radius: 50%;
    display: block;
    filter: saturate(1.2) brightness(0.95);
}

/* ==========================================================================
   V. PHẦN 3: BẢNG MẠNG TẦNG XẾP LỚP KHÔNG GIAN RỘNG (STACK LAYOUT)
   ========================================================================== */
.network-stack-container {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.net-stack-row {
    display: flex;
    flex-direction: column;
    gap: 6px;
    width: 100%;
}

.stack-title {
    text-align: center;
    color: #94a3b8;
    padding-left: 0;
    font-size: 0.7rem;
}

.stack-values {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
}

.v4-val-box,
.v6-val-box {
    color: #ffedd5;
    font-family: 'Space Mono', monospace;
    font-size: 0.85rem;
    font-weight: 600;
    text-align: left;
    justify-content: flex-start;
    word-break: break-all;
    display: flex;
    align-items: center;
}

#v4-ip::before {
    content: "IPv4";
    font-size: 0.65rem;
    color: #fb923c;
    font-weight: 700;
    display: inline-flex;
    align-items: center;

    /* Thiết kế dạng hình oval (viên thuốc) */
    background: rgba(251, 146, 60, 0.1);
    padding: 3px 8px;
    /* Tăng nhẹ độ rộng hai bên để dáng oval cân đối */
    border-radius: 100px;
    /* Bo tròn hoàn toàn hai đầu */
    border: 1px solid rgba(251, 146, 60, 0.25);
    margin-right: 8px;

    transform: translateY(-1px);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

#v6-ip::before {
    content: "IPv6";
    font-size: 0.65rem;
    color: #a78bfa;
    font-weight: 700;
    display: inline-flex;
    align-items: center;

    /* Thiết kế dạng hình oval (viên thuốc) đồng bộ với v4 */
    background: rgba(167, 139, 250, 0.1);
    /* Màu nền tím nhạt 10% trong suốt */
    padding: 3px 8px;
    border-radius: 100px;
    border: 1px solid rgba(167, 139, 250, 0.25);
    margin-right: 8px;

    transform: translateY(-1px);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Khung nội dung đồng bộ cho các block thông số */
.metric-content {
    width: 100%;
    min-width: 0;
    display: flex;
    align-items: center;
    justify-content: flex-start;
}

/* Khung chứa vị trí địa lý theo kiểu 2 cột: icon trái, text phải */
.geo-layout {
    display: grid !important;
    grid-template-columns: var(--icon-column-width) 1fr;
    align-items: center;
    gap: var(--icon-gap);
    width: 100% !important;
}

.geo-icon-box {
    display: flex;
    align-items: center;
    justify-content: center;
}

.geo-layout .flag-3d-box {
    margin-right: 0 !important;
    width: var(--flag-size);
    height: var(--flag-size);
}

.geo-text-box {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
    align-items: center;
    text-align: center;
}

.geo-title {
    font-weight: 700;
    color: #ffedd5;
    font-size: 0.86rem;
    line-height: 1.3;
}

.geo-coords {
    font-size: 0.74rem;
    color: #94a3b8;
    font-family: 'Space Mono', monospace;
    text-align: center;
}

/* Nút kích hoạt bản đồ emoji ở bảng mạng */
.map-trigger-btn {
    cursor: pointer;
    margin-left: 6px;
    display: inline-block;
    transition: transform 0.2s ease, filter 0.2s ease;
}

.map-trigger-btn:hover {
    transform: scale(1.2);
    filter: drop-shadow(0 0 8px #f97316) brightness(1.2);
}

/* Lớp nền đen mờ bao phủ toàn màn hình khi mở Popup */
.map-popup-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(5, 3, 2, 0.75);
    /* Làm tối hậu cảnh */
    backdrop-filter: blur(8px);
    /* Làm mờ các khối chữ Matrix phía sau */
    -webkit-backdrop-filter: blur(8px);
    z-index: 999;
    /* Đẩy lên tầng cao nhất trên cùng */
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 15px;
    opacity: 0;
    pointer-events: none;
    /* Mặc định ẩn hoàn toàn */
    transition: opacity 0.3s ease;
    /* Hiệu ứng hiện hình mượt mà */
}

/* Khi kích hoạt mở Popup */
.map-popup-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

/* Khung hộp nội dung bản đồ (Biến đổi từ .block gốc của bạn) */
.map-popup-content {
    max-width: 600px;
    width: 100%;
    position: relative;
    transform: scale(0.8);
    /* Hiệu ứng phóng từ nhỏ ra to khi mở */
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.map-popup-overlay.active .map-popup-content {
    transform: scale(1);
}

/* Nút đóng dấu X màu cam neon sát viền phải */
.map-close-btn {
    position: absolute;
    top: 12px;
    right: 15px;
    background: none;
    border: none;
    color: #f97316;
    font-size: 1.1rem;
    cursor: pointer;
    z-index: 10;
    transition: color 0.2s, transform 0.2s;
}

.map-close-btn:hover {
    color: #fdba74;
    transform: scale(1.2);
}

/* Ép khung kính Iframe bản đồ */
.map-popup-content iframe {
    border: 1px solid rgba(249, 115, 22, 0.3) !important;
    border-radius: 12px;
    background: rgba(15, 8, 3, 0.9);
}

/* ==========================================================================
   VI. HIỆU ỨNG CHỚP ĐỎ BÁO ĐỘNG DỒN DẬP KHI MẤT MẠNG (OFFLINE STATE)
   ========================================================================== */
.emergency-alert {
    border-color: #dc2626 !important;
    box-shadow: 0 0 25px rgba(220, 38, 38, 0.7) !important;
    animation: pulse-red-cyber 0.5s infinite ease-in-out;
}

@keyframes pulse-red-cyber {
    0% {
        box-shadow: 0 0 10px rgba(220, 38, 38, 0.4);
        border-color: #b91c1c !important;
    }

    50% {
        box-shadow: 0 0 35px rgba(239, 68, 68, 0.9);
        border-color: #f87171 !important;
        background: rgba(30, 0, 0, 0.9);
    }

    100% {
        box-shadow: 0 0 10px rgba(220, 38, 38, 0.4);
        border-color: #b91c1c !important;
    }
}

/* ==========================================================================
   VII. CHẾ ĐỘ TỰ ĐỘNG THÍCH ỨNG DI ĐỘNG (VERTICAL RESPONSIVE)
   ========================================================================== */
@media (max-width: 480px) {

    .info-grid,
    .block .info-grid,
    .stack-values {
        grid-template-columns: 1fr !important;
        gap: 6px;
    }

    .info-card.full-width {
        grid-column: span 1;
    }

    .clock {
        font-size: 2.2rem;
    }

    .block {
        padding: 1.2rem;
    }

    .weather-layout,
    .geo-layout {
        grid-template-columns: 64px 1fr;
        gap: 10px;
    }

    .weather-icon {
        width: var(--icon-size);
        height: var(--icon-size);
    }

    .geo-layout .flag-3d-box {
        width: var(--flag-size);
        height: var(--flag-size);
    }

    .weather-text-box,
    .geo-text-box {
        align-items: center;
        text-align: center;
    }

    .v4-val-box,
    .v6-val-box {
        text-align: center;
        justify-content: center;
    }

    .v4-val-box::before {
        content: "IPv4";
        font-size: 0.65rem;
        color: #fb923c;
        font-weight: 700;
        display: inline-flex;
        align-items: center;

        /* Thiết kế dạng hình oval (viên thuốc) */
        background: rgba(251, 146, 60, 0.1);
        padding: 3px 8px;
        /* Tăng nhẹ độ rộng hai bên để dáng oval cân đối */
        border-radius: 100px;
        /* Bo tròn hoàn toàn hai đầu */
        border: 1px solid rgba(251, 146, 60, 0.25);
        margin-right: 8px;

        transform: translateY(-1px);
        text-transform: uppercase;
        letter-spacing: 0.5px;
    }

    .v6-val-box::before {
        content: "IPv6";
        font-size: 0.65rem;
        color: #a78bfa;
        font-weight: 700;
        display: inline-flex;
        align-items: center;

        /* Thiết kế dạng hình oval (viên thuốc) đồng bộ với v4 */
        background: rgba(167, 139, 250, 0.1);
        /* Màu nền tím nhạt 10% trong suốt */
        padding: 3px 8px;
        border-radius: 100px;
        border: 1px solid rgba(167, 139, 250, 0.25);
        margin-right: 8px;

        transform: translateY(-1px);
        text-transform: uppercase;
        letter-spacing: 0.5px;
    }
}

/* ==========================================================================
   VIII. CẤU HÌNH SONG SONG CÂN BẰNG TỶ LỆ CHỮ (LANDSCAPE HOÀN TOÀN / PANORAMA 21:9)
   ========================================================================= */
@media (min-width: 950px) and (orientation: landscape) {
    .wrapper {
        max-width: 96vw;
        display: grid;
        grid-template-columns: 1fr 0.8fr 2fr;
        gap: 15px;
        align-items: stretch;
    }

    .block {
        padding: clamp(15px, 2.5vh, 30px) 1.5vw !important;
    }

    .wrapper>.block:first-child {
        display: flex;
        flex-direction: column;
        justify-content: center;
    }

    .clock {
        font-size: clamp(48px, 6.5vh, 72px) !important;
        margin: clamp(10px, 1.5vh, 20px) 0 !important;
    }

    .greeting {
        font-size: clamp(12px, 1.6vh, 16px) !important;
    }

    .date {
        font-size: clamp(14px, 2vh, 18px) !important;
    }

    .lunar-date {
        font-size: clamp(11px, 1.5vh, 14px) !important;
        margin-top: clamp(4px, 0.6vh, 8px) !important;
    }

    .info-title {
        font-size: clamp(14px, 2vh, 18px) !important;
        margin-bottom: clamp(12px, 1.8vh, 20px) !important;
        padding-bottom: clamp(6px, 0.8vh, 10px) !important;
    }

    .info-grid {
        grid-template-columns: 1fr !important;
        gap: clamp(6px, 1vh, 12px) !important;
    }

    .info-card.full-width {
        grid-column: span 1 !important;
    }

    .info-card {
        padding: clamp(8px, 1.2vh, 14px) 1vw !important;
    }

    .info-label {
        font-size: clamp(11px, 1.4vh, 13px) !important;
    }

    .info-value,
    .v4-val-box,
    .v6-val-box {
        font-size: clamp(14px, 1.8vh, 16px) !important;
    }

    .network-stack-container {
        gap: clamp(10px, 1.5vh, 16px) !important;
    }

    .net-stack-row {
        gap: clamp(4px, 0.8vh, 8px) !important;
    }

    .stack-title {
        font-size: clamp(12px, 1.5vh, 14px) !important;
    }

    .stack-values {
        grid-template-columns: 1fr 1fr !important;
        gap: 12px !important;
    }

    .v4-val-box,
    .v6-val-box {
        text-align: left !important;
        justify-content: flex-start !important;
        padding: clamp(10px, 1.4vh, 14px) 1vw !important;
    }

    .flag-3d-box {
        width: var(--flag-size) !important;
        height: var(--flag-size) !important;
    }
}