/* ══════════════════════════════════════════════════════════════════════════
   Noise Meter 2.0 (js/tools/NoiseDetectorManager.js)
   Floating window mounted on <html> (outside the body zoom). Own palette on purpose,
   no h1–h6 (themes force heading colours). Selectors start with #noise-meter so the
   theme files cannot pull their button/input skins in.
   ══════════════════════════════════════════════════════════════════════════ */
#noise-meter {
    --nm-bg: #ffffff; --nm-bg2: #f5f6fa; --nm-ink: #0f172a; --nm-ink2: #475569; --nm-ink3: #94a3b8;
    --nm-line: rgba(15, 23, 42, 0.08); --nm-acc: #6d5efc; --nm-acc2: #a855f7;
    --nm-target: #06b6d4; --nm-zone: #10b981;
    --nm-shadow: 0 28px 70px -14px rgba(15, 23, 42, 0.32), 0 0 0 1px rgba(15, 23, 42, 0.06);
    position: fixed; z-index: 2147483640; display: flex; flex-direction: column;
    background: var(--nm-bg); color: var(--nm-ink); border-radius: 22px; box-shadow: var(--nm-shadow);
    font-family: 'Outfit', 'Inter', 'Cairo', system-ui, sans-serif; overflow: hidden;
    min-width: 320px; min-height: 300px; outline: none;
    opacity: 0; transform: translateY(10px) scale(.98); transition: opacity .22s ease, transform .3s cubic-bezier(.2, .9, .25, 1.15), box-shadow .3s ease;
    -webkit-user-select: none; user-select: none; touch-action: none;
}
#noise-meter.show { opacity: 1; transform: none; }
[data-theme="dark"] #noise-meter {
    --nm-bg: #141a2b; --nm-bg2: #1d2439; --nm-ink: #f1f5f9; --nm-ink2: #cbd5e1; --nm-ink3: #7c8aa5;
    --nm-line: rgba(255, 255, 255, 0.08);
    --nm-shadow: 0 28px 70px -14px rgba(0, 0, 0, 0.65), 0 0 0 1px rgba(255, 255, 255, 0.07);
}
#noise-meter * { box-sizing: border-box; }
#noise-meter button { font: inherit; cursor: pointer; -webkit-tap-highlight-color: transparent; margin: 0; }
#noise-meter i { -webkit-text-fill-color: currentColor; }

/* glow ring that follows the current zone; red pulse when over the expected level */
#noise-meter::after {
    content: ''; position: absolute; inset: 0; border-radius: inherit; pointer-events: none;
    box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--nm-zone) 40%, transparent);
    transition: box-shadow .3s ease;
}
#noise-meter.nm-over::after { box-shadow: inset 0 0 0 3px rgba(239, 68, 68, .7); animation: nm-throb 1s ease-in-out infinite; }
#noise-meter.nm-flash { box-shadow: 0 0 0 6px rgba(239, 68, 68, .5), var(--nm-shadow); }
#noise-meter.nm-flash .nm-scene { animation: nm-shake .45s ease; }
@keyframes nm-throb { 50% { box-shadow: inset 0 0 0 5px rgba(239, 68, 68, .35); } }
@keyframes nm-shake { 20%, 60% { transform: translateX(-5px); } 40%, 80% { transform: translateX(5px); } }

/* header */
#noise-meter .nm-head { display: flex; align-items: center; gap: 8px; padding: 12px 12px 8px; cursor: grab; flex: none; }
#noise-meter .nm-head.dragging { cursor: grabbing; }
#noise-meter .nm-logo { width: 36px; height: 36px; flex: none; border-radius: 12px; display: grid; place-items: center; color: #fff; background: linear-gradient(135deg, #d946ef, var(--nm-acc)); box-shadow: 0 8px 18px -8px rgba(168, 85, 247, .9); }
#noise-meter .nm-title { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.2; }
#noise-meter .nm-title b { font-size: 16px; font-weight: 800; color: var(--nm-ink); }
#noise-meter .nm-sub { font-size: 12.5px; font-weight: 600; color: var(--nm-ink3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#noise-meter.nm-over .nm-sub { color: #ef4444; }
#noise-meter .nm-ic { width: 36px; height: 36px; flex: none; border-radius: 11px; border: 0; background: var(--nm-bg2); color: var(--nm-ink2); display: grid; place-items: center; font-size: 14px; position: relative; transition: background .15s, color .15s; }
#noise-meter .nm-ic:hover { color: var(--nm-acc); background: color-mix(in srgb, var(--nm-acc) 12%, var(--nm-bg)); }
#noise-meter .nm-x-btn:hover { color: #ef4444; background: rgba(239, 68, 68, .1); }
#noise-meter .nm-mic-btn { color: #ef4444; }
#noise-meter .nm-mic-btn.on { color: #10b981; }
#noise-meter .nm-mic-btn.on::after { content: ''; position: absolute; top: 6px; inset-inline-end: 6px; width: 7px; height: 7px; border-radius: 50%; background: #ef4444; animation: nm-rec 1.4s ease-in-out infinite; }
@keyframes nm-rec { 50% { opacity: .25; } }
#noise-meter [data-tip]:hover::before {
    content: attr(data-tip); position: absolute; top: calc(100% + 6px); left: 50%; transform: translateX(-50%); white-space: nowrap;
    padding: 5px 8px; border-radius: 8px; background: #0f172a; color: #fff; font-size: 11.5px; font-weight: 700; pointer-events: none; z-index: 30;
}

/* voice-level picker */
#noise-meter .nm-targets { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; padding: 0 12px 10px; flex: none; }
#noise-meter .nm-target {
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px; min-height: 52px; padding: 5px 4px;
    border-radius: 14px; border: 1.5px solid var(--nm-line); background: var(--nm-bg2); color: var(--nm-ink2); transition: all .18s ease;
}
#noise-meter .nm-target:hover { border-color: color-mix(in srgb, var(--lc) 60%, transparent); }
#noise-meter .nm-target-emoji { font-size: 19px; line-height: 1.1; }
#noise-meter .nm-target-name { font-size: 12px; font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
#noise-meter .nm-target.on { border-color: var(--lc); background: color-mix(in srgb, var(--lc) 14%, var(--nm-bg)); color: var(--nm-ink); box-shadow: 0 8px 18px -12px var(--lc); }
#noise-meter .nm-target.on .nm-target-name { color: color-mix(in srgb, var(--lc) 75%, var(--nm-ink)); }

/* scene */
#noise-meter .nm-scene { position: relative; flex: 1; min-height: 0; margin: 0 12px; border-radius: 18px; background: var(--nm-bg2); overflow: hidden; }
#noise-meter .nm-canvas { position: absolute; inset: 0; display: block; }
#noise-meter[data-scene="frog"] .nm-scene { background: radial-gradient(ellipse at 50% 60%, color-mix(in srgb, #84cc16 14%, var(--nm-bg2)), var(--nm-bg2) 70%); }
#noise-meter[data-scene="balls"] .nm-scene { background: linear-gradient(180deg, var(--nm-bg2), color-mix(in srgb, var(--nm-acc) 8%, var(--nm-bg2))); }
#noise-meter[data-scene="traffic"] .nm-scene { background: radial-gradient(ellipse at 50% 50%, color-mix(in srgb, var(--nm-zone) 12%, var(--nm-bg2)), var(--nm-bg2) 70%); }

#noise-meter .nm-banner {
    position: absolute; top: 10px; left: 50%; transform: translate(-50%, -140%); z-index: 6; max-width: calc(100% - 20px);
    display: flex; align-items: center; gap: 8px; padding: 8px 14px; border-radius: 99px; font-size: 13.5px; font-weight: 800; white-space: nowrap;
    background: #fef3c7; color: #92400e; box-shadow: 0 10px 24px -12px rgba(0, 0, 0, .35); transition: transform .3s cubic-bezier(.2, .9, .25, 1.2), opacity .2s ease;
    opacity: 0; visibility: hidden; pointer-events: none;
}
#noise-meter .nm-banner.show { transform: translate(-50%, 0); opacity: 1; visibility: visible; }
#noise-meter .nm-banner.alert { background: #ef4444; color: #fff; }
#noise-meter .nm-banner b { font-weight: 900; }

#noise-meter .nm-shush { position: absolute; left: 50%; top: 50%; z-index: 7; font-size: 110px; line-height: 1; pointer-events: none; transform: translate(-50%, -50%) scale(0); opacity: 0; filter: drop-shadow(0 12px 24px rgba(0, 0, 0, .3)); }
#noise-meter .nm-shush.pop { animation: nm-pop 1.6s cubic-bezier(.2, .9, .25, 1.3) forwards; }
@keyframes nm-pop { 0% { transform: translate(-50%, -50%) scale(0); opacity: 0; } 18% { transform: translate(-50%, -50%) scale(1.25); opacity: 1; } 80% { transform: translate(-50%, -50%) scale(1); opacity: 1; } 100% { transform: translate(-50%, -50%) scale(.6); opacity: 0; } }

/* footer: scene switch + session stats */
#noise-meter .nm-foot { display: flex; align-items: center; gap: 8px; padding: 10px 12px 12px; flex: none; min-width: 0; }
#noise-meter .nm-views { flex: 1; min-width: 0; display: flex; gap: 3px; padding: 3px; border-radius: 13px; background: var(--nm-bg2); overflow-x: auto; scrollbar-width: none; touch-action: pan-x; }
#noise-meter .nm-views::-webkit-scrollbar { display: none; }
#noise-meter .nm-view { flex: none; display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 9px; border: 0; border-radius: 10px; background: transparent; color: var(--nm-ink3); font-size: 12.5px; font-weight: 800; }
#noise-meter .nm-view span { display: none; }
#noise-meter .nm-view.on { background: var(--nm-bg); color: var(--nm-acc); box-shadow: 0 2px 8px -3px rgba(15, 23, 42, .25); }
#noise-meter .nm-view.on span { display: inline; }
#noise-meter .nm-view:hover:not(.on) { color: var(--nm-ink); }
#noise-meter .nm-stats { display: flex; align-items: center; gap: 4px; flex: none; }
#noise-meter .nm-stat { display: inline-flex; align-items: center; gap: 5px; height: 34px; padding: 0 9px; border-radius: 10px; background: var(--nm-bg2); font-size: 13px; color: var(--nm-ink2); font-variant-numeric: tabular-nums; }
#noise-meter .nm-stat b { font-weight: 800; color: var(--nm-ink); }
#noise-meter .nm-stat-streak i { color: #10b981; }
#noise-meter .nm-stat-stars i { color: #f59e0b; }
#noise-meter .nm-stat-alerts i { color: #ef4444; }
#noise-meter .nm-stat.bump { animation: nm-bump .7s cubic-bezier(.2, .9, .25, 1.6); }
@keyframes nm-bump { 40% { transform: scale(1.3); background: #fef3c7; } }
#noise-meter .nm-reset-btn { width: 34px; height: 34px; }
#noise-meter .nm-foot [data-tip]:hover::before { top: auto; bottom: calc(100% + 6px); }

/* resize grip */
#noise-meter .nm-grip { position: absolute; bottom: 0; inset-inline-end: 0; width: 22px; height: 22px; cursor: nwse-resize; z-index: 8; touch-action: none; }
#noise-meter[dir="rtl"] .nm-grip { cursor: nesw-resize; }
#noise-meter .nm-grip::after { content: ''; position: absolute; bottom: 6px; inset-inline-end: 6px; width: 8px; height: 8px; border-bottom: 2px solid var(--nm-ink3); border-inline-end: 2px solid var(--nm-ink3); border-end-end-radius: 3px; opacity: .6; }

/* compact window: hide the words, keep the controls */
#noise-meter.nm-compact .nm-target { min-height: 40px; }
#noise-meter.nm-compact .nm-target-name { font-size: 10.5px; }
#noise-meter.nm-compact .nm-target-emoji { font-size: 15px; }
#noise-meter.nm-compact .nm-stat-alerts, #noise-meter.nm-compact .nm-view.on span { display: none; }

/* full screen (projector) */
#noise-meter.nm-full { left: 0 !important; top: 0 !important; width: 100vw !important; height: 100vh !important; border-radius: 0; }
#noise-meter.nm-full .nm-grip { display: none; }
#noise-meter.nm-full .nm-head { cursor: default; padding: 16px 20px 10px; }
#noise-meter.nm-full .nm-title b { font-size: 22px; }
#noise-meter.nm-full .nm-sub { font-size: 15px; }
#noise-meter.nm-full .nm-targets { padding: 0 20px 14px; gap: 10px; max-width: 900px; width: 100%; margin: 0 auto; }
#noise-meter.nm-full .nm-target { min-height: 74px; border-radius: 18px; }
#noise-meter.nm-full .nm-target-emoji { font-size: 28px; }
#noise-meter.nm-full .nm-target-name { font-size: 15px; }
#noise-meter.nm-full .nm-scene { margin: 0 20px; border-radius: 24px; }
#noise-meter.nm-full .nm-foot { padding: 14px 20px 18px; }
#noise-meter.nm-full .nm-stat { height: 42px; font-size: 16px; padding: 0 14px; }
#noise-meter.nm-full .nm-banner { font-size: 20px; padding: 12px 22px; top: 18px; }
#noise-meter.nm-full .nm-shush { font-size: 200px; }

/* settings sheet (slides over the scene) */
#noise-meter .nm-settings {
    position: absolute; inset: 0; z-index: 10; display: flex; flex-direction: column; background: var(--nm-bg);
    transform: translateY(102%); transition: transform .3s cubic-bezier(.2, .9, .25, 1); border-radius: inherit;
}
#noise-meter.nm-settings-open .nm-settings { transform: none; }
#noise-meter .nm-set-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 14px 8px; flex: none; }
#noise-meter .nm-set-head b { font-size: 15px; font-weight: 800; color: var(--nm-ink); }
#noise-meter .nm-set-body { flex: 1; overflow-y: auto; padding: 0 14px 14px; display: flex; flex-direction: column; gap: 10px; touch-action: pan-y; scrollbar-width: thin; }
#noise-meter .nm-set-body section { background: var(--nm-bg2); border: 1px solid var(--nm-line); border-radius: 14px; padding: 10px 12px; display: flex; flex-direction: column; gap: 10px; }
#noise-meter .nm-set-title { font-size: 11.5px; font-weight: 800; letter-spacing: .05em; text-transform: uppercase; color: var(--nm-ink3); }
#noise-meter .nm-set-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
#noise-meter .nm-set-row.nm-col { flex-direction: column; align-items: stretch; gap: 6px; }
#noise-meter .nm-set-row label { font-size: 13px; font-weight: 700; color: var(--nm-ink); display: flex; justify-content: space-between; gap: 8px; }
#noise-meter .nm-set-row output { color: var(--nm-acc); font-weight: 800; font-variant-numeric: tabular-nums; }
#noise-meter .nm-hint { font-size: 12px; color: var(--nm-ink3); }

#noise-meter .nm-range { -webkit-appearance: none; appearance: none; width: 100%; height: 6px; border-radius: 99px; background: color-mix(in srgb, var(--nm-acc) 22%, var(--nm-line)); outline: none; margin: 6px 0; touch-action: pan-x; }
#noise-meter .nm-range::-webkit-slider-thumb { -webkit-appearance: none; width: 22px; height: 22px; border-radius: 50%; background: #fff; border: 0; box-shadow: 0 0 0 3px var(--nm-acc), 0 4px 10px rgba(0, 0, 0, .2); cursor: pointer; }
#noise-meter .nm-range::-moz-range-thumb { width: 20px; height: 20px; border-radius: 50%; background: #fff; border: 3px solid var(--nm-acc); cursor: pointer; }

#noise-meter .nm-segs { display: flex; flex-wrap: wrap; gap: 4px; }
#noise-meter .nm-seg { height: 32px; padding: 0 11px; border-radius: 99px; border: 1px solid var(--nm-line); background: var(--nm-bg); color: var(--nm-ink2); font-size: 12.5px; font-weight: 700; }
#noise-meter .nm-seg.on { background: var(--nm-acc); border-color: var(--nm-acc); color: #fff; }

#noise-meter .nm-switch { display: inline-flex; align-items: center; gap: 8px; border: 0; background: none; padding: 0; color: var(--nm-ink2); font-size: 12.5px; font-weight: 700; }
#noise-meter .nm-switch span { width: 42px; height: 24px; border-radius: 99px; background: var(--nm-ink3); position: relative; transition: background .2s; }
#noise-meter .nm-switch span::after { content: ''; position: absolute; top: 3px; inset-inline-start: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: inset-inline-start .2s; }
#noise-meter .nm-switch.on span { background: #10b981; }
#noise-meter .nm-switch.on span::after { inset-inline-start: 21px; }
#noise-meter .nm-switch em { font-style: normal; }

#noise-meter .nm-btn { display: inline-flex; align-items: center; justify-content: center; gap: 7px; min-height: 36px; padding: 0 14px; border-radius: 11px; border: 0; background: var(--nm-acc); color: #fff; font-size: 13px; font-weight: 800; }
#noise-meter .nm-btn.ghost { background: var(--nm-bg); color: var(--nm-ink); border: 1px solid var(--nm-line); }
#noise-meter .nm-btn:disabled { opacity: .6; cursor: progress; }

#noise-meter .nm-legend-row { display: grid; grid-template-columns: 10px auto 1fr; align-items: center; gap: 8px; font-size: 12.5px; }
#noise-meter .nm-legend-row i { width: 10px; height: 10px; border-radius: 3px; }
#noise-meter .nm-legend-row b { color: var(--nm-ink); white-space: nowrap; }
#noise-meter .nm-legend-row span { color: var(--nm-ink3); }

/* microphone error card */
#noise-meter .nm-mic-error { position: absolute; inset: 10px; z-index: 9; display: flex; flex-direction: column; gap: 12px; padding: 14px; border-radius: 14px; background: var(--nm-bg); border: 1px solid rgba(239, 68, 68, .35); font-size: 13px; line-height: 1.55; color: var(--nm-ink2); overflow-y: auto; touch-action: pan-y; }
#noise-meter .nm-err-body { display: flex; gap: 10px; }
#noise-meter .nm-err-body > i { color: #ef4444; margin-top: 3px; }
#noise-meter .nm-err-more { color: #ef4444; }
#noise-meter .nm-err-btns { display: flex; gap: 8px; justify-content: flex-end; margin-top: auto; }

@media (prefers-reduced-motion: reduce) {
    #noise-meter, #noise-meter * { animation: none !important; transition: none !important; }
}
