/* BuzzOff — mobile-first, light/dark/auto */

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

/* ── Color tokens (dark default) ─────────────────── */

:root {
    --bg: #0d1117;
    --bg2: #161b22;
    --bg3: #21262d;
    --border: rgba(255, 255, 255, 0.13);
    --text: #e6edf3;
    --text-muted: rgba(255, 255, 255, 0.60);
    --red: #f85149;
    --red-dim: rgba(248, 81, 73, 0.15);
    --red-glow: rgba(248, 81, 73, 0.3);
    --green: #3fb950;
    --green-dim: rgba(63, 185, 80, 0.15);
    --green-border: rgba(63, 185, 80, 0.40);
    --accent: #58a6ff;
    --accent-dim: rgba(88, 166, 255, 0.14);
    --accent-border: rgba(88, 166, 255, 0.35);
    --shadow: rgba(0, 0, 0, 0.4);
    --radius: 10px;
}

/* Auto: follow system preference */
@media (prefers-color-scheme: light) {
    :root {
        --bg:           #ffffff;
        --bg2:          #f5f7fa;
        --bg3:          #e4e8ed;
        --border:       rgba(0, 0, 0, 0.13);
        --text:         #1a1f26;
        --text-muted:   rgba(0, 0, 0, 0.60);
        --red:          #b91c1c;
        --red-dim:      rgba(185, 28, 28, 0.10);
        --red-glow:     rgba(185, 28, 28, 0.25);
        --green:        #15803d;
        --green-dim:    rgba(21, 128, 61, 0.10);
        --green-border: rgba(21, 128, 61, 0.40);
        --accent:       #1d4ed8;
        --accent-dim:   rgba(29, 78, 216, 0.10);
        --accent-border: rgba(29, 78, 216, 0.35);
        --shadow:       rgba(0, 0, 0, 0.14);
    }
}

/* Manual overrides — win over the media query */
:root[data-theme="dark"] {
    --bg:           #0d1117;
    --bg2:          #161b22;
    --bg3:          #21262d;
    --border:       rgba(255, 255, 255, 0.13);
    --text:         #e6edf3;
    --text-muted:   rgba(255, 255, 255, 0.60);
    --red:          #f85149;
    --red-dim:      rgba(248, 81, 73, 0.15);
    --red-glow:     rgba(248, 81, 73, 0.3);
    --green:        #3fb950;
    --green-dim:    rgba(63, 185, 80, 0.15);
    --green-border: rgba(63, 185, 80, 0.40);
    --accent:       #58a6ff;
    --accent-dim:   rgba(88, 166, 255, 0.14);
    --accent-border: rgba(88, 166, 255, 0.35);
    --shadow:       rgba(0, 0, 0, 0.4);
}

:root[data-theme="light"] {
    --bg:           #ffffff;
    --bg2:          #f5f7fa;
    --bg3:          #e4e8ed;
    --border:       rgba(0, 0, 0, 0.13);
    --text:         #1a1f26;
    --text-muted:   rgba(0, 0, 0, 0.60);
    --red:          #b91c1c;
    --red-dim:      rgba(185, 28, 28, 0.10);
    --red-glow:     rgba(185, 28, 28, 0.25);
    --green:        #15803d;
    --green-dim:    rgba(21, 128, 61, 0.10);
    --green-border: rgba(21, 128, 61, 0.40);
    --accent:       #1d4ed8;
    --accent-dim:   rgba(29, 78, 216, 0.10);
    --accent-border: rgba(29, 78, 216, 0.35);
    --shadow:       rgba(0, 0, 0, 0.14);
}

/* ── 80s Vaporwave theme ─────────────────────────── */

:root[data-theme="80s"] {
    --bg:           #08001a;
    --bg2:          #110030;
    --bg3:          #1e0050;
    --border:       rgba(255, 0, 255, 0.28);
    --text:         #f0e0ff;
    --text-muted:   #c084fc;
    --red:          #ff0090;
    --red-dim:      rgba(255, 0, 144, 0.18);
    --red-glow:     rgba(255, 0, 144, 0.45);
    --green:        #39ff14;
    --green-dim:    rgba(57, 255, 20, 0.14);
    --green-border: rgba(57, 255, 20, 0.45);
    --accent:       #00e5ff;
    --accent-dim:   rgba(0, 229, 255, 0.14);
    --accent-border: rgba(0, 229, 255, 0.40);
    --shadow:       rgba(0, 0, 0, 0.7);
}

[data-theme="80s"] .app-title {
    color: #ff80ff;
    text-shadow: 0 0 8px #ff00ff, 0 0 18px rgba(255, 0, 255, 0.5);
}

[data-theme="80s"] .header {
    background: linear-gradient(135deg, #110030 0%, #1e0050 100%);
    border-bottom-color: rgba(255, 0, 255, 0.35);
}

[data-theme="80s"] .start-btn {
    background: var(--accent);
    color: #000;
    box-shadow: 0 0 16px rgba(0, 229, 255, 0.55), 0 4px 14px rgba(0, 229, 255, 0.3);
}

[data-theme="80s"] .start-btn:hover {
    box-shadow: 0 0 24px rgba(0, 229, 255, 0.7), 0 6px 20px rgba(0, 229, 255, 0.45);
}

[data-theme="80s"] .status-clear .status-dot {
    box-shadow: 0 0 10px var(--green), 0 0 22px rgba(57, 255, 20, 0.5);
}

[data-theme="80s"] .status-detected .status-dot {
    box-shadow: 0 0 10px var(--red), 0 0 22px rgba(255, 0, 144, 0.5);
}

[data-theme="80s"] .section {
    border-color: rgba(255, 0, 255, 0.22);
}

[data-theme="80s"] .section-header {
    border-bottom-color: rgba(255, 0, 255, 0.18);
}

html, body {
    height: 100%;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    -webkit-font-smoothing: antialiased;
}

.app {
    height: 100dvh;
    display: flex;
    flex-direction: column;
    gap: 0;
    max-width: none;
    padding: 0;
    overflow: hidden;
}

/* ── Header ─────────────────────────────────────── */

.header {
    display: flex;
    align-items: stretch;
    justify-content: space-between;
    padding: 0 0 0 1rem;
    gap: 1rem;
    height: 60px;
    background: var(--bg3);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.header-brand {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 0.65rem;
    align-self: stretch;
    padding: 5px 0;
    flex: 1 1 auto;
    min-width: 0;
}

.brand-icon {
    height: 100%;
    width: auto;
    aspect-ratio: 1;
    flex-shrink: 0;
    border-radius: 8px;
}

/* Default (dark): show dark icon only */
.brand-icon-light,
.brand-icon-80s  { display: none; }

/* Light theme */
:root[data-theme="light"] .brand-icon-dark  { display: none; }
:root[data-theme="light"] .brand-icon-light { display: block; }

/* 80s theme */
:root[data-theme="80s"] .brand-icon-dark { display: none; }
:root[data-theme="80s"] .brand-icon-80s  { display: block; }

/* Auto theme — follow system preference */
@media (prefers-color-scheme: light) {
    :root:not([data-theme="dark"]):not([data-theme="80s"]) .brand-icon-dark  { display: none; }
    :root:not([data-theme="dark"]):not([data-theme="80s"]) .brand-icon-light { display: block; }
}

.header-actions {
    display: flex;
    align-items: stretch;
    gap: 0;
    flex-shrink: 0;
}

.header-actions .icon-btn {
    border: none;
    border-left: 1px solid var(--border);
    border-radius: 0;
    background: transparent;
    font-size: 1.4rem;
    min-width: 48px;
    height: auto;
    color: var(--text-muted);
    padding: 5px;
}

.header-actions .icon-btn:hover {
    color: var(--text);
    border-color: var(--border);
    background: var(--border);
}

.app-title {
    font-size: 1.4rem;
    font-weight: 700;
    letter-spacing: -0.5px;
    color: var(--text);
    line-height: 1;
}

.app-subtitle {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-weight: 400;
    white-space: nowrap;
}

/* ── Icon buttons (theme toggle, help, dialog close) */

.icon-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 32px;
    height: 32px;
    padding: 0 0.5rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg2);
    color: var(--text-muted);
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
}

.icon-btn:hover {
    color: var(--text);
    border-color: var(--accent);
}

/* ── Status + Start row ──────────────────────────── */

.status-row {
    display: flex;
    align-items: stretch;
    gap: 0.5rem;
    margin: 0.5rem 1rem 0;
    flex-shrink: 0;
}

/* ── Status indicator ────────────────────────────── */

.status-indicator {
    flex: 1;
    border-radius: var(--radius);
    padding: 1rem 1.25rem;
    border: 1px solid var(--border);
    transition: all 0.3s ease;
}

.status-idle {
    background: var(--bg2);
}

.status-clear {
    background: var(--green-dim);
    border-color: var(--green-border);
}

.status-detected {
    background: var(--red-dim);
    border-color: var(--red);
    animation: pulse-border 1.2s ease-in-out infinite;
}

@keyframes pulse-border {
    0%, 100% { border-color: var(--red); box-shadow: 0 0 0 0 var(--red-glow); }
    50%       { border-color: var(--red); box-shadow: 0 0 0 6px transparent; }
}

.status-inner {
    display: flex;
    align-items: center;
    gap: 0.6rem;
}

.status-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
    background: var(--text-muted);
    transition: background 0.3s;
}

.status-idle    .status-dot { background: var(--text-muted); }
.status-clear   .status-dot { background: var(--green); box-shadow: 0 0 6px var(--green); }
.status-detected .status-dot {
    background: var(--red);
    box-shadow: 0 0 8px var(--red);
    animation: dot-blink 0.6s ease-in-out infinite;
}

@keyframes dot-blink {
    0%, 100% { opacity: 1; }
    50%       { opacity: 0.4; }
}

.status-text {
    font-size: 1.4rem;
    font-weight: 700;
    letter-spacing: 0.05em;
    transition: color 0.3s;
}

.status-idle     .status-text { color: var(--text-muted); }
.status-clear    .status-text { color: var(--green); }
.status-detected .status-text { color: var(--red); }

.status-subtext {
    font-size: 0.78rem;
    color: var(--text-muted);
    margin-top: 0.25rem;
    padding-left: 1.6rem;
    min-height: 1.2em;
}

/* ── Sample rate warning (inline in status subtext) ── */

.subtext-warn {
    color: #c98000;
}

[data-theme="light"] .subtext-warn {
    color: #7a4d00;
}

.warn-more-btn {
    background: none;
    border: none;
    padding: 0;
    font: inherit;
    font-size: inherit;
    color: inherit;
    text-decoration: underline;
    cursor: pointer;
    opacity: 0.85;
}

/* ── Sections wrapper (fills remaining viewport) ──── */

.sections-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 0.5rem 1rem;
    gap: 0.5rem;
    overflow: hidden;
    min-height: 0;
}

/* ── Sections ────────────────────────────────────── */

.section {
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.6rem 0.75rem;
    border-bottom: 1px solid var(--border);
}

.section-title {
    font-size: 0.78rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
}

.fft-range-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-family: 'SF Mono', 'Fira Code', monospace;
}

/* ── History section ─────────────────────────────── */

.history-section {
    flex: 1;
    min-height: 80px;
}

/* ── Event log ───────────────────────────────────── */

.event-log {
    flex: 1;
    overflow-y: scroll;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-y: contain;
    padding: 0.4rem 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    min-height: 0;
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
}

.event-log::-webkit-scrollbar {
    width: 5px;
}

.event-log::-webkit-scrollbar-track {
    background: transparent;
}

.event-log::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}

.event-log-entry {
    font-family: 'SF Mono', 'Fira Code', monospace;
    font-size: 0.75rem;
    color: var(--text-muted);
    display: flex;
    gap: 0.6em;
    line-height: 1.5;
}

.event-log-entry .log-time {
    flex-shrink: 0;
    opacity: 0.6;
}

.event-log-entry.log-detected {
    color: var(--accent);
}

.event-log-entry.log-cleared {
    color: var(--text-muted);
}

.event-log-empty {
    font-family: 'SF Mono', 'Fira Code', monospace;
    font-size: 0.75rem;
    color: var(--text-muted);
    opacity: 0.45;
    padding: 0.25rem 0;
}

/* ── Controls section ────────────────────────────── */

.controls-section {
    padding: 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.control-group {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.control-group-label {
    font-size: 0.7rem;
    font-weight: 500;
    color: var(--text-muted);
    letter-spacing: 0.02em;
}

/* ── Help tips ───────────────────────────────────── */

.help-tip {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.1em;
    height: 1.1em;
    border-radius: 50%;
    background: var(--bg3);
    color: var(--text-muted);
    font-size: 0.6rem;
    font-weight: 700;
    cursor: pointer;
    user-select: none;
    vertical-align: middle;
    margin-left: 0.2em;
    border: 1px solid var(--border);
    outline: none;
}

.help-tip:hover,
.help-tip:focus,
.help-tip.open {
    color: var(--accent);
    border-color: var(--accent);
}

.help-tip-text {
    display: none;
    position: absolute;
    bottom: calc(100% + 6px);
    left: 50%;
    transform: translateX(-50%);
    width: 200px;
    background: var(--bg3);
    border: 1px solid var(--border);
    border-radius: 7px;
    padding: 0.45rem 0.6rem;
    font-size: 0.72rem;
    font-weight: 400;
    color: var(--text);
    letter-spacing: 0;
    line-height: 1.4;
    white-space: normal;
    box-shadow: 0 2px 10px var(--shadow);
    z-index: 200;
    pointer-events: none;
}

.help-tip.open .help-tip-text {
    pointer-events: auto;
}

.help-tip:hover .help-tip-text,
.help-tip:focus .help-tip-text,
.help-tip.open .help-tip-text {
    display: block;
}

/* Inside dialogs, suppress clipped CSS hover — use click (.open) with fixed positioning instead */
dialog .help-tip:hover .help-tip-text,
dialog .help-tip:focus .help-tip-text {
    display: none;
}

dialog .help-tip.open .help-tip-text {
    display: block;
    position: fixed;
    transform: none;
    left: auto;
    bottom: auto;
}

/* ── Option tabs (inside options dialog) ──────────── */

.option-tabs {
    display: flex;
    gap: 0.25rem;
    background: var(--bg3);
    padding: 3px;
    border-radius: 8px;
    width: fit-content;
}

.option-tab {
    padding: 0.3rem 0.75rem;
    border: none;
    border-radius: 6px;
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    background: transparent;
    color: var(--text-muted);
    transition: all 0.15s;
}

.option-tab.active {
    background: var(--bg);
    color: var(--accent);
    box-shadow: 0 1px 4px var(--shadow);
}

/* ── Custom band inputs ───────────────────────────── */

.freq-input {
    width: 90px;
    padding: 0.35rem 0.5rem;
    background: var(--bg3);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    font-size: 0.9rem;
    text-align: right;
}

.freq-input:focus {
    outline: none;
    border-color: var(--accent);
}

.hz-label {
    color: var(--text-muted);
    font-size: 0.8rem;
}

.hidden {
    display: none !important;
}

/* ── Custom band inputs ───────────────────────────── */

.custom-band-inputs {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    margin-top: 0.1rem;
}

/* ── Alert toggles ───────────────────────────────── */

.alerts-row {
    display: flex;
    gap: 0.5rem;
}

.toggle-btn {
    flex: 1;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg3);
    color: var(--text-muted);
    font-size: 0.82rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
}

.toggle-btn[data-active="true"] {
    background: var(--accent-dim);
    border-color: var(--accent-border);
    color: var(--accent);
}

/* ── Start / Stop button ─────────────────────────── */

.start-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.25rem;
    min-width: 96px;
    padding: 0.85rem 1rem;
    border: 2px solid transparent;
    border-radius: var(--radius);
    font-weight: 700;
    cursor: pointer;
    background: var(--accent);
    color: #fff;
    box-shadow: 0 4px 14px color-mix(in srgb, var(--accent) 50%, transparent);
    transition: all 0.15s;
    flex-shrink: 0;
}

.start-btn:hover {
    filter: brightness(1.1);
    box-shadow: 0 6px 20px color-mix(in srgb, var(--accent) 60%, transparent);
}

.start-btn:active {
    transform: scale(0.96);
    filter: brightness(0.95);
    box-shadow: 0 2px 6px color-mix(in srgb, var(--accent) 40%, transparent);
}


.start-icon {
    font-size: 1.5rem;
    line-height: 1;
}

.start-label {
    font-size: 0.72rem;
    font-weight: 700;
    text-align: center;
    line-height: 1.2;
    letter-spacing: 0.02em;
}

/* ── FFT canvas ──────────────────────────────────── */

.fft-section {
    flex: 2;
    min-height: 160px;
}

.fft-canvas {
    display: block;
    width: 100%;
    flex: 1;
    min-height: 0;
}

/* ── Desktop adjustments ─────────────────────────── */

@media (min-width: 480px) {
    .status-text {
        font-size: 1.7rem;
    }
}

/* ── Short viewport (landscape phone): hide history ─ */

@media (max-height: 500px) {
    .history-section {
        display: none;
    }
}

/* ── Options dialog body ─────────────────────────── */

.options-body {
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    overflow-y: auto;
}

/* ── Help dialog ─────────────────────────────────── */

.help-dialog {
    position: fixed;
    inset: 0;
    width: min(520px, calc(100vw - 2rem));
    max-height: calc(100dvh - 2rem);
    margin: auto;
    padding: 0;
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: calc(var(--radius) * 1.5);
    color: var(--text);
    box-shadow: 0 8px 32px var(--shadow);
    overflow: hidden;
}

.help-dialog::backdrop {
    background: rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(2px);
}

.help-content {
    display: flex;
    flex-direction: column;
    max-height: calc(100dvh - 2rem);
}

.help-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1rem 0.75rem;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.help-title {
    font-size: 1rem;
    font-weight: 700;
    color: var(--text);
}

.help-body {
    padding: 1rem;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    font-size: 0.88rem;
    line-height: 1.55;
}

.help-body h3 {
    font-size: 0.78rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    margin-top: 0.25rem;
}

.help-body p {
    color: var(--text);
}

.help-body a {
    color: var(--accent);
}

.help-body ul {
    padding-left: 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}

.privacy-note {
    background: var(--accent-dim);
    border: 1px solid var(--accent-border);
    border-radius: 8px;
    padding: 0.6rem 0.75rem;
}

.fa-icon {
    width: 1em;
    height: 1em;
    fill: currentColor;
    display: block;
}

.version-footer {
    margin-top: 1.5rem;
    font-size: 0.72rem;
    opacity: 0.45;
    text-align: right;
    font-family: monospace;
}

.attribution-footer {
    font-size: 0.72rem;
    opacity: 0.45;
    text-align: right;
}

/* ── Screen flash overlay ───────────────────────── */

#flash-overlay {
    position: fixed;
    inset: 0;
    pointer-events: none;
    background: var(--red);
    opacity: 0;
    z-index: 9999;
}

#flash-overlay.flash {
    animation: screen-flash 0.6s ease-out forwards;
}

@keyframes screen-flash {
    0%   { opacity: 0.4; }
    100% { opacity: 0; }
}


