/* ==========================================================
   CH NET GUARD — 3D Interactive Map section (Phase 8)
   ----------------------------------------------------------
   Sits between HERO and ABOUT. Three.js scene mounted into
   #map3d-scene; everything else here is the HUD frame,
   tooltips, and fallback.
   ========================================================== */

/* ---------- Section frame ---------- */
.section-map3d {
    position: relative;
    overflow: hidden;
    isolation: isolate;
    /* Sit flush against the hero — no top border seam, just a
       soft gradient that fades the deep bg into the section */
    background:
        radial-gradient(
            ellipse 80% 50% at 50% 0%,
            rgba(15, 181, 164, 0.06) 0%,
            transparent 70%
        ),
        var(--bg-deep);
}

.section-map3d .grid-bg {
    position: absolute;
    inset: 0;
    background-image:
        linear-gradient(rgba(20, 215, 195, 0.04) 1px, transparent 1px),
        linear-gradient(90deg, rgba(20, 215, 195, 0.04) 1px, transparent 1px);
    background-size: 56px 56px;
    mask-image: radial-gradient(ellipse 70% 80% at 50% 50%, #000 30%, transparent 90%);
    pointer-events: none;
    z-index: 0;
}

.section-map3d > .container-x {
    position: relative;
    z-index: 1;
}

.map3d-sub {
    max-width: 720px;
    margin-bottom: var(--space-6);
}

/* ---------- Stage container (3D area) ---------- */
.map3d-stage {
    position: relative;
    width: 100%;
    height: clamp(440px, 62vh, 720px);
    margin-top: var(--space-5);
    border-radius: 18px;
    overflow: hidden;
    background:
        radial-gradient(ellipse 90% 70% at 50% 60%, rgba(8, 12, 28, 0.6) 0%, rgba(3, 4, 10, 0.95) 70%),
        linear-gradient(180deg, #050811 0%, #03040A 100%);
    border: 1px solid rgba(31, 37, 71, 0.7);
    box-shadow:
        inset 0 0 60px rgba(15, 181, 164, 0.05),
        0 30px 80px rgba(0, 0, 0, 0.55);
    cursor: crosshair;
}

/* Soft inner vignette to push focus to the center */
.map3d-stage::after {
    content: "";
    position: absolute;
    inset: 0;
    pointer-events: none;
    background:
        radial-gradient(ellipse 80% 60% at 50% 50%, transparent 40%, rgba(3, 4, 10, 0.55) 100%);
    z-index: 2;
}

/* Subtle scanline overlay for the cyber-noir mood */
.map3d-stage::before {
    content: "";
    position: absolute;
    inset: 0;
    pointer-events: none;
    background: repeating-linear-gradient(
        0deg,
        rgba(255, 255, 255, 0.012) 0px,
        rgba(255, 255, 255, 0.012) 1px,
        transparent 1px,
        transparent 3px
    );
    mix-blend-mode: overlay;
    z-index: 3;
    opacity: 0.7;
}

/* ---------- Canvas mount ---------- */
.map3d-canvas-wrap {
    position: absolute;
    inset: 0;
    z-index: 1;
}

.map3d-canvas-wrap canvas {
    display: block;
    width: 100% !important;
    height: 100% !important;
}

/* ---------- HUD corner brackets ---------- */
.map3d-bracket {
    position: absolute;
    width: 28px;
    height: 28px;
    border: 1px solid var(--accent-teal-2);
    opacity: 0.55;
    z-index: 4;
    pointer-events: none;
    transition: opacity 0.4s ease;
}
.map3d-bracket--tl { top: 14px;    left: 14px;    border-right: none; border-bottom: none; }
.map3d-bracket--tr { top: 14px;    right: 14px;   border-left: none;  border-bottom: none; }
.map3d-bracket--bl { bottom: 14px; left: 14px;    border-right: none; border-top: none; }
.map3d-bracket--br { bottom: 14px; right: 14px;   border-left: none;  border-top: none; }

.map3d-stage:hover .map3d-bracket { opacity: 0.85; }

/* ---------- HUD labels ---------- */
.map3d-hud {
    position: absolute;
    z-index: 5;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 6px 10px;
    background: rgba(5, 8, 17, 0.7);
    border: 1px solid rgba(20, 215, 195, 0.25);
    border-radius: 999px;
    font-family: var(--font-mono, ui-monospace, "JetBrains Mono", monospace);
    font-size: 11px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-secondary);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    pointer-events: none;
    user-select: none;
}
.map3d-hud--tl { top: 28px;    left: 28px; }
.map3d-hud--tr { top: 28px;    right: 28px; }
.map3d-hud--bl { bottom: 28px; left: 28px; }
.map3d-hud--br { bottom: 28px; right: 28px; }

.map3d-hud-dot {
    width: 7px; height: 7px;
    border-radius: 50%;
    background: var(--accent-teal-2);
    box-shadow: 0 0 8px var(--accent-teal-2), 0 0 16px var(--accent-teal);
    animation: map3d-hud-pulse 1.8s ease-in-out infinite;
}

@keyframes map3d-hud-pulse {
    0%, 100% { opacity: 1;   transform: scale(1); }
    50%      { opacity: 0.5; transform: scale(0.75); }
}

.map3d-hud-sep    { opacity: 0.5; }
.map3d-hud-label  { color: var(--text-muted); }
.map3d-hud-value  { color: var(--accent-teal-2); font-variant-numeric: tabular-nums; }
.map3d-hud-counter { color: var(--accent-teal-2); font-variant-numeric: tabular-nums; }

/* On small screens show only the most informative HUDs */
.map3d-hint-mobile  { display: none; }
.map3d-hint-desktop { display: inline; }

/* ---------- Hover tooltip ---------- */
.map3d-tooltip {
    position: absolute;
    z-index: 6;
    min-width: 180px;
    padding: 10px 12px;
    background: rgba(7, 11, 24, 0.92);
    border: 1px solid rgba(20, 215, 195, 0.45);
    border-radius: 10px;
    font-family: var(--font-mono, ui-monospace, "JetBrains Mono", monospace);
    font-size: 12px;
    color: var(--text-primary);
    box-shadow:
        0 0 0 1px rgba(20, 215, 195, 0.08),
        0 12px 30px rgba(0, 0, 0, 0.55),
        0 0 24px rgba(20, 215, 195, 0.18);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    pointer-events: none;
    opacity: 0;
    transform: translate(-50%, calc(-100% - 14px)) scale(0.94);
    transition: opacity 0.18s ease, transform 0.18s ease;
    white-space: nowrap;
}

.map3d-tooltip[data-visible="true"] {
    opacity: 1;
    transform: translate(-50%, calc(-100% - 14px)) scale(1);
}

.map3d-tooltip-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 4px;
}

.map3d-tooltip-tag {
    display: inline-block;
    padding: 2px 6px;
    border-radius: 4px;
    background: rgba(20, 215, 195, 0.15);
    border: 1px solid rgba(20, 215, 195, 0.4);
    color: var(--accent-teal-2);
    font-size: 10px;
    letter-spacing: 0.12em;
}

.map3d-tooltip-id    { color: var(--text-primary); font-weight: 600; }
.map3d-tooltip-coord { color: var(--text-secondary); font-size: 11px; }
.map3d-tooltip-meta  { color: var(--text-muted);    font-size: 11px; margin-top: 2px; }

/* ---------- Named-city variant ---------- */
/*
   When data-city is set (MILANO / ROMA / NAPOLI), the tooltip
   becomes a more prominent "city badge" — wider, with the
   Italian flag and large city name. The data-city attribute
   itself is used elsewhere for hue tinting per city if needed.
*/
.map3d-tooltip[data-city="MILANO"],
.map3d-tooltip[data-city="ROMA"],
.map3d-tooltip[data-city="NAPOLI"] {
    min-width: 220px;
    padding: 12px 14px;
    /* Italian-tricolor accent on the top border for visual ID */
    background:
        linear-gradient(180deg, rgba(0, 146, 70, 0.10), transparent 22%),
        rgba(7, 11, 24, 0.94);
    border-color: rgba(20, 215, 195, 0.55);
    box-shadow:
        0 0 0 1px rgba(20, 215, 195, 0.10),
        0 14px 36px rgba(0, 0, 0, 0.60),
        0 0 30px rgba(20, 215, 195, 0.22);
}

/* Hide the generic NODE tag on city tooltips — the flag + city
   name takes its place. */
.map3d-tooltip[data-city="MILANO"] .map3d-tooltip-tag,
.map3d-tooltip[data-city="ROMA"]   .map3d-tooltip-tag,
.map3d-tooltip[data-city="NAPOLI"] .map3d-tooltip-tag {
    display: none;
}

.map3d-tooltip[data-city="MILANO"] .map3d-tooltip-id,
.map3d-tooltip[data-city="ROMA"]   .map3d-tooltip-id,
.map3d-tooltip[data-city="NAPOLI"] .map3d-tooltip-id {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    font-size: 14px;
    letter-spacing: 0.02em;
}

.tip-flag {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 16px;
    border-radius: 2px;
    overflow: hidden;
    box-shadow:
        0 0 0 1px rgba(255, 255, 255, 0.20),
        0 2px 6px rgba(0, 0, 0, 0.45);
    flex: 0 0 auto;
}
.tip-flag svg { display: block; }

.tip-city {
    color: var(--text-primary);
    font-weight: 700;
    letter-spacing: 0.10em;
    font-size: 13px;
    text-transform: uppercase;
}

/* ---------- Fallback (no JS / reduced-motion) ---------- */
.map3d-fallback {
    position: absolute;
    inset: 0;
    z-index: 1;
    display: none;
    flex-direction: column;
    justify-content: center;
    align-items: flex-start;
    padding: 48px;
    gap: 16px;
}

/* JS turns this off by setting hidden / removing display */
.map3d-stage[data-fallback-active="true"] .map3d-fallback {
    display: flex;
}
.map3d-stage[data-fallback-active="true"] .map3d-canvas-wrap {
    display: none;
}

.map3d-fallback-row {
    display: flex;
    align-items: center;
    gap: 14px;
    font-family: var(--font-mono, ui-monospace, monospace);
    color: var(--text-secondary);
}
.map3d-fallback-flag    { font-size: 22px; }
.map3d-fallback-city    { color: var(--text-primary); font-weight: 600; }
.map3d-fallback-country { color: var(--text-muted); }

/* ---------- Mobile ---------- */
@media (max-width: 768px) {
    .map3d-stage {
        height: clamp(360px, 58vh, 520px);
        border-radius: 14px;
    }
    .map3d-hud {
        font-size: 10px;
        padding: 5px 8px;
        gap: 6px;
    }
    .map3d-hud--tl { top: 12px;    left: 12px; }
    .map3d-hud--tr { top: 12px;    right: 12px; }
    .map3d-hud--bl { bottom: 12px; left: 12px; }
    .map3d-hud--br { bottom: 12px; right: 12px; }

    .map3d-hud--br { display: none; } /* keep mobile uncluttered */

    .map3d-bracket { width: 20px; height: 20px; }
    .map3d-hint-mobile  { display: inline; }
    .map3d-hint-desktop { display: none; }
}

/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
    .map3d-hud-dot   { animation: none; }
    .map3d-tooltip   { transition: none; }
}

/* ==========================================================
   HUD CHATTER LOG (Phase 11)
   ----------------------------------------------------------
   A scrolling fake telemetry feed in the hero's bottom-right
   area, just above the COORD pill. New rows slide in from
   the bottom, the oldest row slides out the top, with each
   row dimming as it ages.
   ========================================================== */
.hud-chatter {
    position: absolute;
    z-index: 5;
    right: 28px;
    bottom: 60px;        /* just above the COORD pill (bottom: 28px + ~24px tall) */
    width: 320px;
    max-width: 38vw;
    display: flex;
    flex-direction: column;
    gap: 4px;
    pointer-events: none;
    font-family: var(--font-mono, ui-monospace, "JetBrains Mono", monospace);
    font-size: 10.5px;
    color: var(--text-secondary);
    text-align: right;
}

.hud-chatter-row {
    /* Each row is one log line; styled per-tag (OK/INFO/WARN). */
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    padding: 4px 10px;
    background: rgba(5, 8, 17, 0.55);
    border: 1px solid rgba(20, 215, 195, 0.15);
    border-radius: 6px;
    backdrop-filter: blur(3px);
    -webkit-backdrop-filter: blur(3px);
    letter-spacing: 0.04em;
    /* Start invisible/below; JS-applied .is-in class triggers slide-in */
    opacity: 0;
    transform: translateY(8px);
    transition: opacity 320ms ease-out, transform 320ms ease-out;
}

.hud-chatter-row.is-in {
    opacity: 1;
    transform: translateY(0);
}

/* Older rows dim — first is newest, third is oldest */
.hud-chatter .hud-chatter-row:nth-last-child(1).is-in { opacity: 0.85; }
.hud-chatter .hud-chatter-row:nth-last-child(2).is-in { opacity: 0.55; }
.hud-chatter .hud-chatter-row:nth-last-child(3).is-in { opacity: 0.30; }

/* Placeholders sit hidden until JS replaces them */
.hud-chatter-placeholder { visibility: hidden; }

/* Tag colours per log level — set as inline spans in the row */
.hud-chatter-tag {
    display: inline-block;
    margin-right: 6px;
    padding: 1px 5px;
    border-radius: 3px;
    font-size: 9px;
    letter-spacing: 0.10em;
    text-transform: uppercase;
    vertical-align: 1px;
}
.hud-chatter-tag--ok   { background: rgba(20, 215, 195, 0.15); color: var(--accent-teal-2); }
.hud-chatter-tag--info { background: rgba(59, 130, 246, 0.15); color: #93C5FD; }
.hud-chatter-tag--warn { background: rgba(245, 158, 11, 0.15); color: #FCD34D; }

.hud-chatter-id { color: var(--text-primary); }
.hud-chatter-meta { color: var(--text-muted); }

@media (max-width: 1023px) {
    /* Mobile: too noisy, hide entirely */
    .hud-chatter { display: none; }
}

@media (prefers-reduced-motion: reduce) {
    .hud-chatter-row { transition: none; }
}
