/*
 * ═══════════════════════════════════════════════════════
 *  AURA — "Midnight Engineering" Design System
 *  Peer-to-Peer File Transfer · Engineering Futurist UI
 *  100% Local. Zero Cloud. Pure Privacy.
 * ═══════════════════════════════════════════════════════
 */

/* ─── Fonts ─── */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800;900&family=Roboto+Mono:wght@400;500;600&display=swap');

/* ─── Design Tokens ─── */
:root {
    /* Core Palette — Midnight Engineering */
    --bg-abyss:       #060a12;
    --bg-primary:     #0a0e17;
    --bg-secondary:   #0f1520;
    --bg-elevated:    #141c2b;
    --bg-surface:     #182035;
    --bg-glass:       rgba(14, 20, 32, 0.65);
    --bg-glass-hover: rgba(20, 28, 43, 0.80);

    /* Primary Accent — Electric Cyan "The Aura" */
    --cyan:           #00ffff;
    --cyan-bright:    #66ffff;
    --cyan-dim:       #00cccc;
    --cyan-glow:      rgba(0, 255, 255, 0.10);
    --cyan-glow-md:   rgba(0, 255, 255, 0.18);
    --cyan-glow-lg:   rgba(0, 255, 255, 0.30);

    /* Secondary — Slate Gray */
    --slate:          #3d4f65;
    --slate-light:    #5a7090;
    --slate-dim:      #2a3545;

    /* Text Hierarchy */
    --text-primary:   #e8edf5;
    --text-secondary: #8899aa;
    --text-muted:     #4e5d6e;
    --text-ghost:     #2e3a48;

    /* Status Colors */
    --green:          #00ff88;
    --green-glow:     rgba(0, 255, 136, 0.15);
    --blue:           #4488ff;
    --blue-glow:      rgba(68, 136, 255, 0.15);
    --amber:          #ffaa00;
    --red:            #ff4466;

    /* Borders */
    --border-subtle:  rgba(255, 255, 255, 0.04);
    --border-default: rgba(255, 255, 255, 0.07);
    --border-accent:  rgba(0, 255, 255, 0.15);
    --border-glow:    rgba(0, 255, 255, 0.30);

    /* Shadows */
    --shadow-sm:      0 2px 8px rgba(0, 0, 0, 0.4);
    --shadow-md:      0 4px 16px rgba(0, 0, 0, 0.5);
    --shadow-lg:      0 8px 32px rgba(0, 0, 0, 0.6);
    --shadow-xl:      0 16px 64px rgba(0, 0, 0, 0.7);
    --shadow-cyan:    0 0 24px rgba(0, 255, 255, 0.12);
    --shadow-cyan-lg: 0 0 48px rgba(0, 255, 255, 0.18);

    /* Radius */
    --r-xs:  6px;
    --r-sm:  8px;
    --r-md:  12px;
    --r-lg:  16px;
    --r-xl:  20px;
    --r-2xl: 24px;
    --r-full: 50%;

    /* Transitions */
    --ease-out:   cubic-bezier(0.16, 1, 0.3, 1);
    --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
    --t-fast:     150ms;
    --t-normal:   280ms;
    --t-slow:     500ms;
    --t-glacial:  800ms;

    /* Layout */
    --header-h: 56px;
    --footer-h: 100px;
    --card-w:   220px;
    --card-h:   260px;
    --icon-size: 24px;
}

/* ─── Reset & Base ─── */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    height: 100%;
    -webkit-text-size-adjust: 100%;
}

html, body {
    width: 100%;
    overflow-x: hidden;
}

body {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    color: var(--text-primary);
    background-color: var(--bg-abyss);
    font-size: 14px;
    font-weight: 400;
    line-height: 1.5;
    position: relative;
}

[hidden] { display: none !important; }

a {
    text-decoration: none;
    color: currentColor;
    cursor: pointer;
}

/* ─── Utility Classes ─── */
.row      { display: flex; flex-direction: row; }
.row-reverse { display: flex; flex-direction: row-reverse; }
.column   { display: flex; flex-direction: column; }
.center   { display: flex; align-items: center; justify-content: center; }
.grow     { flex-grow: 1; }
.full     { position: absolute; top: 0; left: 0; right: 0; bottom: 0; }
.mono     { font-family: 'Roboto Mono', 'Fira Code', monospace; }

/* ─── Typography ─── */
h1 {
    font-size: clamp(28px, 4vw, 40px);
    font-weight: 800;
    letter-spacing: -0.03em;
    line-height: 1.1;
    color: var(--text-primary);
}

h2 {
    font-size: clamp(16px, 2.5vw, 20px);
    font-weight: 400;
    letter-spacing: -0.01em;
    line-height: 1.5;
    color: var(--text-secondary);
}

h3 {
    font-size: 16px;
    font-weight: 600;
    letter-spacing: 0;
    margin: 0 0 12px;
    color: var(--text-primary);
}

.font-subheading {
    font-size: 14px;
    font-weight: 400;
    line-height: 1.5;
    color: var(--text-secondary);
    word-break: break-word;
}

.font-body2 {
    font-size: 12px;
    line-height: 1.5;
    color: var(--text-muted);
}

/* ═══════════════════════════════════════
   CIRCUIT BOARD BACKGROUND ANIMATION
   ═══════════════════════════════════════ */

#aura-circuit-bg {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    z-index: 0;
    pointer-events: none;
    opacity: 0.35;
}

/* CSS fallback traces — subtle geometric grid glow */
.circuit-overlay {
    position: fixed;
    inset: 0;
    z-index: 0;
    pointer-events: none;
    overflow: hidden;
}

.circuit-overlay::before {
    content: '';
    position: absolute;
    inset: 0;
    background:
        /* Horizontal micro-lines */
        repeating-linear-gradient(
            0deg,
            transparent,
            transparent 80px,
            rgba(0, 255, 255, 0.015) 80px,
            rgba(0, 255, 255, 0.015) 81px
        ),
        /* Vertical micro-lines */
        repeating-linear-gradient(
            90deg,
            transparent,
            transparent 80px,
            rgba(0, 255, 255, 0.015) 80px,
            rgba(0, 255, 255, 0.015) 81px
        );
    animation: circuit-drift 30s linear infinite;
}

.circuit-overlay::after {
    content: '';
    position: absolute;
    width: 200%;
    height: 200%;
    top: -50%;
    left: -50%;
    background: radial-gradient(
        ellipse 600px 400px at 50% 50%,
        rgba(0, 255, 255, 0.04),
        transparent 70%
    );
    animation: aura-sweep 12s ease-in-out infinite alternate;
}

@keyframes circuit-drift {
    from { transform: translate(0, 0); }
    to   { transform: translate(80px, 80px); }
}

@keyframes aura-sweep {
    0%   { transform: translate(-10%, -10%) scale(1); }
    50%  { transform: translate(10%, 5%) scale(1.1); }
    100% { transform: translate(-5%, 10%) scale(1); }
}

/* Pulsing trace nodes at intersections */
.trace-node {
    position: fixed;
    width: 3px;
    height: 3px;
    border-radius: var(--r-full);
    background: var(--cyan);
    opacity: 0;
    z-index: 0;
    pointer-events: none;
    animation: node-pulse 4s ease-in-out infinite;
}
.trace-node:nth-child(1) { top: 20%; left: 15%; animation-delay: 0s; }
.trace-node:nth-child(2) { top: 45%; left: 75%; animation-delay: 1.2s; }
.trace-node:nth-child(3) { top: 70%; left: 30%; animation-delay: 2.4s; }
.trace-node:nth-child(4) { top: 30%; left: 60%; animation-delay: 0.8s; }
.trace-node:nth-child(5) { top: 80%; left: 85%; animation-delay: 3.1s; }
.trace-node:nth-child(6) { top: 15%; left: 45%; animation-delay: 1.8s; }

@keyframes node-pulse {
    0%, 100% { opacity: 0; transform: scale(0.5); box-shadow: 0 0 0 rgba(0,255,255,0); }
    50%      { opacity: 0.8; transform: scale(1.5); box-shadow: 0 0 12px rgba(0,255,255,0.5); }
}


/* ═══════════════════════════════════════
   STATUS BAR (Top)
   ═══════════════════════════════════════ */

.status-bar {
    position: fixed;
    top: 0; left: 0; right: 0;
    height: var(--header-h);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 clamp(12px, 3vw, 24px);
    z-index: 50;
    backdrop-filter: blur(20px) saturate(150%);
    -webkit-backdrop-filter: blur(20px) saturate(150%);
    background: rgba(10, 14, 23, 0.75);
    border-bottom: 1px solid var(--border-subtle);
}

.status-bar__left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.status-bar__right {
    display: flex;
    align-items: center;
    gap: 4px;
}

/* LOCAL MODE ACTIVE Badge */
.mode-badge {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 5px 14px;
    border-radius: 100px;
    background: rgba(0, 255, 255, 0.06);
    border: 1px solid var(--border-accent);
    font-family: 'Roboto Mono', monospace;
    font-size: 10px;
    font-weight: 600;
    color: var(--cyan);
    text-transform: uppercase;
    letter-spacing: 0.12em;
    user-select: none;
    transition: all var(--t-normal) var(--ease-out);
}

.mode-badge .pulse-dot {
    width: 6px; height: 6px;
    border-radius: var(--r-full);
    background: var(--cyan);
    animation: dot-breathe 2.5s ease-in-out infinite;
    flex-shrink: 0;
}

.mode-badge.offline {
    border-color: rgba(255, 170, 0, 0.3);
    background: rgba(255, 170, 0, 0.06);
    color: var(--amber);
}

.mode-badge.offline .pulse-dot {
    background: var(--amber);
}

@keyframes dot-breathe {
    0%, 100% { opacity: 0.4; box-shadow: 0 0 0 0 rgba(0,255,255,0.3); }
    50%      { opacity: 1;   box-shadow: 0 0 8px 2px rgba(0,255,255,0.15); }
}

/* Connection Status Dot */
#connectionStatus {
    width: 8px; height: 8px;
    border-radius: var(--r-full);
    background: var(--slate);
    transition: all var(--t-normal) var(--ease-out);
    flex-shrink: 0;
}

#connectionStatus.connected {
    background: var(--green);
    box-shadow: 0 0 6px var(--green-glow), 0 0 12px rgba(0,255,136,0.2);
    animation: status-live 2s ease-in-out infinite;
}

@keyframes status-live {
    0%, 100% { box-shadow: 0 0 4px rgba(0,255,136,0.2); }
    50%      { box-shadow: 0 0 12px rgba(0,255,136,0.4); }
}

/* Icon Buttons */
.icon-button {
    width: 36px; height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--r-sm);
    color: var(--text-muted);
    border: none;
    outline: none;
    background: transparent;
    cursor: pointer;
    transition: all var(--t-fast) var(--ease-out);
    -webkit-tap-highlight-color: transparent;
}

.icon-button:hover {
    color: var(--cyan);
    background: var(--cyan-glow);
}

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


/* ═══════════════════════════════════════
   MAIN CONTENT AREA
   ═══════════════════════════════════════ */

.app-main {
    flex: 1;
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: calc(var(--header-h) + 20px) 20px calc(var(--footer-h) + 20px);
    z-index: 1;
    position: relative;
    min-height: 100vh;
}


/* ═══════════════════════════════════════
   PEER DISCOVERY — NODE CARDS
   ═══════════════════════════════════════ */

/* Peers Container — Geometric Grid */
x-peers {
    display: grid;
    grid-template-columns: repeat(auto-fit, var(--card-w));
    gap: 20px;
    justify-content: center;
    align-content: center;
    width: 100%;
    max-width: 960px;
    z-index: 2;
    padding: 10px;
}

/* Empty State */
x-no-peers {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    padding: 40px 20px;
    animation: fade-up 600ms var(--ease-out) backwards;
    animation-delay: 400ms;
}

x-no-peers h2 {
    color: var(--text-secondary);
    font-weight: 400;
    font-size: clamp(15px, 2.5vw, 18px);
    max-width: 320px;
    margin-bottom: 24px;
}

x-peers:not(:empty) + x-no-peers {
    display: none;
}

/* Bluetooth Scan Button */
#btScan {
    padding: 10px 24px;
    background: var(--bg-elevated);
    border: 1px solid var(--border-accent);
    border-radius: var(--r-lg);
    color: var(--cyan);
    font-family: 'Inter', sans-serif;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    transition: all var(--t-fast) var(--ease-out);
}

#btScan:hover {
    background: var(--cyan-glow-md);
    box-shadow: var(--shadow-cyan);
    transform: translateY(-2px);
}

#btScan.scanning {
    animation: scan-pulse 1.5s ease-in-out infinite;
    pointer-events: none;
}

@keyframes scan-pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50%      { opacity: 0.6; transform: scale(0.97); }
}

/* ─── Node Card ─── */

x-peer {
    -webkit-user-select: none;
    user-select: none;
}

x-peer label {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: var(--card-w);
    min-height: var(--card-h);
    padding: 28px 16px 24px;
    cursor: pointer;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    position: relative;
    border-radius: var(--r-xl);
    background: var(--bg-glass);
    backdrop-filter: blur(16px) saturate(130%);
    -webkit-backdrop-filter: blur(16px) saturate(130%);
    border: 1px solid var(--border-default);
    box-shadow: var(--shadow-md);
    transition: all var(--t-normal) var(--ease-out);
    overflow: hidden;
}

/* Inner glow border effect */
x-peer label::before {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: var(--r-xl);
    padding: 1px;
    background: linear-gradient(
        135deg,
        rgba(0, 255, 255, 0.08),
        transparent 50%,
        rgba(0, 255, 255, 0.04)
    );
    -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
    mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
    -webkit-mask-composite: xor;
    mask-composite: exclude;
    pointer-events: none;
    transition: opacity var(--t-normal) var(--ease-out);
    opacity: 0.5;
}

x-peer label:hover {
    background: var(--bg-glass-hover);
    border-color: var(--border-accent);
    box-shadow: var(--shadow-cyan), var(--shadow-lg);
    transform: translateY(-4px) scale(1.02);
}

x-peer label:hover::before {
    opacity: 1;
}

/* Active / pressed */
x-peer label:active {
    transform: translateY(-1px) scale(0.99);
    transition-duration: 80ms;
}

/* File Input hidden */
input[type="file"] {
    visibility: hidden;
    position: absolute;
    width: 0;
    height: 0;
}

/* ─── Device Icon (inside Node Card) ─── */

x-peer .icon-container {
    position: relative;
    width: 72px;
    height: 72px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 16px;
}

x-peer x-icon {
    --icon-size: 36px;
    width: 56px;
    height: 56px;
    padding: 10px;
    border-radius: var(--r-full);
    background: linear-gradient(145deg, var(--cyan-dim), var(--cyan));
    color: var(--bg-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--t-normal) var(--ease-out);
    will-change: transform;
    box-shadow: 0 4px 20px rgba(0, 255, 255, 0.25);
    z-index: 2;
}

x-peer:not([transfer]):hover x-icon {
    transform: scale(1.1);
    box-shadow: 0 6px 30px rgba(0, 255, 255, 0.35);
}

x-peer x-icon {
    animation: card-enter 500ms var(--ease-spring) 1;
}

@keyframes card-enter {
    0%   { transform: scale(0.3); opacity: 0; }
    100% { transform: scale(1);   opacity: 1; }
}

/* ─── Radial Progress Ring ─── */

x-peer .progress-ring {
    position: absolute;
    top: 0; left: 0;
    width: 72px;
    height: 72px;
    z-index: 1;
}

x-peer .progress-ring circle {
    fill: none;
    stroke-width: 3;
    stroke-linecap: round;
    transform: rotate(-90deg);
    transform-origin: center;
    transition: stroke-dashoffset 250ms var(--ease-out);
}

x-peer .progress-ring .ring-bg {
    stroke: var(--border-default);
}

x-peer .progress-ring .ring-fill {
    stroke: var(--cyan);
    stroke-dasharray: 201; /* 2πr ≈ 201 for r=32 */
    stroke-dashoffset: 201;
    filter: drop-shadow(0 0 4px rgba(0, 255, 255, 0.5));
}

x-peer[transfer] .progress-ring .ring-fill {
    animation: ring-glow 1.5s ease-in-out infinite;
}

@keyframes ring-glow {
    0%, 100% { filter: drop-shadow(0 0 3px rgba(0,255,255,0.3)); }
    50%      { filter: drop-shadow(0 0 8px rgba(0,255,255,0.6)); }
}

/* ─── Card Text ─── */

x-peer .hostname {
    font-family: 'Roboto Mono', monospace;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
    text-align: center;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    max-width: 100%;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 2px;
}

x-peer .device-name {
    font-size: 11px;
    color: var(--text-muted);
    text-align: center;
    margin-bottom: 8px;
}

/* Connection Badge */
x-peer .conn-badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-family: 'Roboto Mono', monospace;
    font-size: 9px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    padding: 3px 10px;
    border-radius: 100px;
    margin-bottom: 6px;
}

x-peer .conn-badge .badge-dot {
    width: 5px; height: 5px;
    border-radius: var(--r-full);
    flex-shrink: 0;
}

x-peer .conn-badge.wifi {
    color: var(--green);
    background: var(--green-glow);
    border: 1px solid rgba(0, 255, 136, 0.15);
}
x-peer .conn-badge.wifi .badge-dot {
    background: var(--green);
    box-shadow: 0 0 4px rgba(0,255,136,0.4);
}

x-peer .conn-badge.bluetooth {
    color: var(--blue);
    background: var(--blue-glow);
    border: 1px solid rgba(68, 136, 255, 0.15);
}
x-peer .conn-badge.bluetooth .badge-dot {
    background: var(--blue);
    box-shadow: 0 0 4px rgba(68,136,255,0.4);
}

/* Transfer status */
x-peer .transfer-status {
    font-family: 'Roboto Mono', monospace;
    font-size: 11px;
    font-weight: 500;
    color: var(--cyan);
    text-align: center;
    min-height: 16px;
}

x-peer:not([transfer]) .transfer-status {
    display: none;
}

x-peer[transfer] .device-name {
    display: none;
}

x-peer[transfer] .transfer-status::after {
    content: '';
    display: inline-block;
    animation: transfer-dots 1.5s steps(3, end) infinite;
}

@keyframes transfer-dots {
    0%   { content: '.'; }
    33%  { content: '..'; }
    66%  { content: '...'; }
}

x-peer[transfer] x-icon {
    opacity: 0.8;
}

/* Data stream particles (when transferring) */
x-peer[transfer] label::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 100%;
    height: 100%;
    transform: translate(-50%, -50%);
    background:
        radial-gradient(1px 1px at 20% 30%, rgba(0,255,255,0.6), transparent),
        radial-gradient(1px 1px at 80% 70%, rgba(0,255,255,0.4), transparent),
        radial-gradient(1px 1px at 50% 20%, rgba(0,255,255,0.5), transparent),
        radial-gradient(1.5px 1.5px at 35% 80%, rgba(0,255,255,0.3), transparent),
        radial-gradient(1px 1px at 65% 45%, rgba(0,255,255,0.5), transparent);
    animation: stream-particles 2s linear infinite;
    pointer-events: none;
    border-radius: var(--r-xl);
}

@keyframes stream-particles {
    0%   { opacity: 0; transform: translate(-50%,-50%) scale(0.8); }
    50%  { opacity: 1; }
    100% { opacity: 0; transform: translate(-50%,-50%) scale(1.4); }
}

/* Drop zone */
x-peer[drop] label {
    border-color: var(--cyan);
    box-shadow: 0 0 30px rgba(0,255,255,0.2), var(--shadow-lg);
}

x-peer[drop] x-icon {
    transform: scale(1.12);
    box-shadow: 0 0 40px rgba(0,255,255,0.4);
}


/* ═══════════════════════════════════════
   INSTRUCTIONS
   ═══════════════════════════════════════ */

x-instructions {
    position: absolute;
    bottom: calc(var(--footer-h) + 24px);
    opacity: 0.3;
    z-index: 1;
    text-align: center;
    color: var(--text-muted);
    font-size: 12px;
    font-family: 'Roboto Mono', monospace;
    letter-spacing: 0.03em;
    padding: 0 20px;
    transition: opacity var(--t-normal) var(--ease-out);
}

x-instructions::before {
    content: attr(mobile);
}

x-peers:empty ~ x-instructions {
    opacity: 0;
}

@media screen and (min-width: 768px) {
    x-instructions::before {
        content: attr(desktop);
    }
}


/* ═══════════════════════════════════════
   FOOTER
   ═══════════════════════════════════════ */

.app-footer {
    position: fixed;
    bottom: 0; left: 0; right: 0;
    height: var(--footer-h);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 5;
    backdrop-filter: blur(20px) saturate(150%);
    -webkit-backdrop-filter: blur(20px) saturate(150%);
    background: rgba(10, 14, 23, 0.7);
    border-top: 1px solid var(--border-subtle);
    gap: 4px;
    padding: 0 20px;
}

.footer-brand {
    font-family: 'Roboto Mono', monospace;
    font-size: 16px;
    font-weight: 700;
    letter-spacing: 0.3em;
    background: linear-gradient(135deg, var(--cyan), #00ffaa);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    text-transform: uppercase;
}

.footer-sub {
    font-size: 12px;
    color: var(--text-muted);
    text-align: center;
    font-family: 'Roboto Mono', monospace;
    font-weight: 400;
}

#displayName {
    font-size: 11px;
    color: var(--text-secondary);
    font-family: 'Roboto Mono', monospace;
}

.footer-credit {
    font-size: 10px;
    color: var(--text-ghost);
    text-align: center;
}

.footer-credit a {
    color: var(--text-muted);
    transition: color var(--t-fast);
}

.footer-credit a:hover {
    color: var(--cyan);
}

.github-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 4px;
    border-radius: var(--r-full);
}

.github-link svg {
    transition: filter var(--t-fast);
}

.github-link:hover svg {
    filter: drop-shadow(0 0 8px var(--cyan-dim));
}


/* ═══════════════════════════════════════
   OFFLINE FALLBACK
   ═══════════════════════════════════════ */

#offline-fallback {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 100;
    background: var(--bg-primary);
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    text-align: center;
    padding: 20px;
}

#offline-fallback .offline-icon {
    width: 80px; height: 80px;
    border-radius: var(--r-full);
    background: var(--bg-elevated);
    border: 1px solid var(--border-default);
    display: flex;
    align-items: center;
    justify-content: center;
    animation: pulse-soft 3s ease-in-out infinite;
}

#offline-fallback .offline-icon svg {
    width: 36px; height: 36px;
    fill: var(--text-muted);
}

@keyframes pulse-soft {
    0%, 100% { box-shadow: 0 0 0 0 var(--cyan-glow); }
    50%      { box-shadow: 0 0 20px 4px var(--cyan-glow); }
}

#offline-fallback h2 {
    color: var(--text-primary);
    font-weight: 600;
    font-size: 18px;
}

#offline-fallback p {
    color: var(--text-muted);
    font-size: 13px;
    max-width: 300px;
}


/* ═══════════════════════════════════════
   GLASSMORPHIC DIALOGS
   ═══════════════════════════════════════ */

x-dialog x-background {
    background: rgba(0, 0, 0, 0.60);
    backdrop-filter: blur(12px) saturate(120%);
    -webkit-backdrop-filter: blur(12px) saturate(120%);
    z-index: 10;
    transition: opacity var(--t-normal) var(--ease-out);
    will-change: opacity;
    padding: 20px;
}

x-dialog x-paper {
    z-index: 11;
    background: var(--bg-secondary);
    border: 1px solid var(--border-default);
    border-radius: var(--r-xl);
    padding: 28px;
    width: 100%;
    max-width: 420px;
    box-shadow: var(--shadow-xl), 0 0 40px rgba(0,255,255,0.05);
    transition: transform var(--t-normal) var(--ease-spring), opacity var(--t-normal);
    will-change: transform, opacity;
    position: relative;
    overflow: hidden;
}

/* Top glow accent on dialog */
x-dialog x-paper::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--cyan), transparent);
    opacity: 0.4;
}

x-dialog:not([show]) {
    pointer-events: none;
}

x-dialog:not([show]) x-paper {
    transform: scale(0.92) translateY(10px);
    opacity: 0;
}

x-dialog:not([show]) x-background {
    opacity: 0;
}

x-dialog .row-reverse > .button {
    margin-top: 20px;
    margin-left: 8px;
}

x-dialog a { color: var(--cyan); }

/* Receive Dialog */
#receiveDialog .row {
    margin-top: 20px;
    margin-bottom: 8px;
}

/* Receive Text Dialog */
#receiveTextDialog #text {
    width: 100%;
    word-break: break-all;
    max-height: 300px;
    overflow-x: hidden;
    overflow-y: auto;
    user-select: all;
    white-space: pre-wrap;
    color: var(--text-primary);
    padding: 16px;
    background: var(--bg-primary);
    border-radius: var(--r-md);
    border: 1px solid var(--border-subtle);
    margin-top: 8px;
}

#receiveTextDialog #text a {
    color: var(--cyan);
    cursor: pointer;
}

#receiveTextDialog #text a:hover {
    text-decoration: underline;
}

#receiveTextDialog h3 {
    user-select: none;
    pointer-events: none;
}


/* ═══════════════════════════════════════
   BUTTONS
   ═══════════════════════════════════════ */

.button {
    padding: 0 24px;
    min-height: 40px;
    min-width: 100px;
    font-size: 12px;
    font-weight: 600;
    font-family: 'Roboto Mono', monospace;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    white-space: nowrap;
    cursor: pointer;
    user-select: none;
    background: transparent;
    color: var(--cyan);
    border: 1px solid var(--border-accent);
    border-radius: var(--r-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--t-fast) var(--ease-out);
    position: relative;
    overflow: hidden;
    outline: none;
    -webkit-tap-highlight-color: transparent;
}

.button:hover {
    background: var(--cyan-glow-md);
    border-color: var(--border-glow);
    box-shadow: 0 0 16px rgba(0,255,255,0.1);
    transform: translateY(-1px);
}

.button:active {
    transform: translateY(0);
    transition-duration: 50ms;
}

/* Primary button variant */
.button.primary {
    background: linear-gradient(135deg, var(--cyan-dim), var(--cyan));
    color: var(--bg-primary);
    border: none;
    font-weight: 700;
}

.button.primary:hover {
    box-shadow: 0 4px 20px rgba(0,255,255,0.3);
}

button::-moz-focus-inner { border: 0; }


/* ═══════════════════════════════════════
   TEXT INPUT
   ═══════════════════════════════════════ */

.textarea {
    box-sizing: border-box;
    border: 1px solid var(--border-default);
    outline: none;
    padding: 14px 16px;
    border-radius: var(--r-md);
    margin: 8px 0;
    font-size: 14px;
    font-family: 'Inter', sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    display: block;
    overflow: auto;
    resize: none;
    min-height: 44px;
    line-height: 1.5;
    max-height: 300px;
    transition: border-color var(--t-fast) var(--ease-out), box-shadow var(--t-fast) var(--ease-out);
    width: 100%;
}

.textarea:focus {
    border-color: var(--cyan);
    box-shadow: 0 0 0 3px var(--cyan-glow), var(--shadow-cyan);
}


/* ═══════════════════════════════════════
   TOAST
   ═══════════════════════════════════════ */

.toast-container {
    position: fixed;
    top: 0; left: 0; right: 0;
    padding: calc(var(--header-h) + 12px) 16px 0;
    display: flex;
    justify-content: center;
    pointer-events: none;
    z-index: 60;
}

x-toast {
    display: flex;
    align-items: center;
    min-height: 48px;
    width: 100%;
    max-width: 380px;
    background: var(--bg-elevated);
    color: var(--text-primary);
    padding: 12px 20px;
    border-radius: var(--r-md);
    border: 1px solid var(--border-default);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    box-shadow: var(--shadow-lg), 0 0 16px rgba(0,255,255,0.05);
    pointer-events: all;
    transition: opacity 200ms, transform 300ms var(--ease-out);
    font-size: 13px;
    font-weight: 500;
}

x-toast:not([show]) {
    opacity: 0;
    pointer-events: none;
    transform: translateY(-60px);
}


/* ═══════════════════════════════════════
   ABOUT PAGE
   ═══════════════════════════════════════ */

#about {
    color: var(--text-primary);
    z-index: 11;
    overflow: hidden;
    pointer-events: none;
    text-align: center;
}

#about .fade-in {
    transition: opacity var(--t-slow) var(--ease-out);
    will-change: opacity;
    transition-delay: 300ms;
    z-index: 11;
    pointer-events: all;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    max-width: 400px;
    padding: 20px;
}

#about:not(:target) .fade-in {
    opacity: 0;
    pointer-events: none;
    transition-delay: 0;
}

#about .about-logo {
    width: 96px;
    height: 96px;
    border-radius: var(--r-xl);
    filter: drop-shadow(0 0 30px rgba(0, 255, 255, 0.4));
    margin-bottom: 8px;
}

#about x-background {
    position: absolute;
    width: 100%;
    height: 100%;
    background: var(--bg-primary);
    z-index: -1;
    opacity: 0;
    pointer-events: none;
    transition: opacity 300ms;
}

#about:target x-background {
    opacity: 1;
}

#about:target::before,
#about:target::after {
    content: '';
    position: absolute;
    top: 50%; left: 50%;
    width: 120px; height: 120px;
    border: 1px solid var(--cyan);
    border-radius: 50%;
    transform: translate(-50%, -50%) scale(0.1);
    opacity: 0;
    z-index: -1;
    animation: data-pulse 3s cubic-bezier(0.1, 0.8, 0.3, 1) infinite;
    pointer-events: none;
}

#about:target::after {
    animation-delay: 1.5s;
}

@keyframes data-pulse {
    0% { transform: translate(-50%, -50%) scale(0.8); opacity: 0.8; }
    100% { transform: translate(-50%, -50%) scale(4); opacity: 0; }
}

#about .row a {
    margin: 4px;
    color: var(--text-secondary);
}

#about .row a:hover {
    color: var(--cyan);
}

#about h1 {
    background: linear-gradient(135deg, var(--cyan), #00ffaa);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    font-size: 42px;
    letter-spacing: 0.15em;
}

#about .font-subheading {
    color: var(--text-secondary);
    max-width: 280px;
}


/* ═══════════════════════════════════════
   PLACEHOLDER / EMPTY STATES
   ═══════════════════════════════════════ */

[placeholder]:empty::before {
    content: attr(placeholder);
    color: var(--text-ghost);
}


/* ═══════════════════════════════════════
   IMAGE PREVIEW
   ═══════════════════════════════════════ */

#img-preview {
    max-width: 100%;
    max-height: 50vh;
    margin: 12px auto;
    display: block;
    border-radius: var(--r-md);
    border: 1px solid var(--border-subtle);
}


/* ═══════════════════════════════════════
   CHECKBOX
   ═══════════════════════════════════════ */

input[type="checkbox"] {
    accent-color: var(--cyan);
    cursor: pointer;
}


/* ═══════════════════════════════════════
   SHADOWS (attribute-based)
   ═══════════════════════════════════════ */

[shadow="1"] { box-shadow: var(--shadow-sm); }
[shadow="2"] { box-shadow: var(--shadow-md); }


/* ═══════════════════════════════════════
   ANIMATIONS
   ═══════════════════════════════════════ */

@keyframes fade-up {
    from { opacity: 0; transform: translateY(16px); }
    to   { opacity: 1; transform: translateY(0); }
}

@keyframes fade-in {
    from { opacity: 0; }
    to   { opacity: 1; }
}


/* ═══════════════════════════════════════
   RESPONSIVE BREAKPOINTS
   ═══════════════════════════════════════ */

/* Mobile — < 480px : single column cards */
@media (max-width: 480px) {
    :root {
        --card-w: calc(100vw - 48px);
        --card-h: 200px;
        --header-h: 48px;
        --footer-h: 86px;
    }

    x-peers {
        grid-template-columns: 1fr;
        gap: 14px;
        padding: 0 12px;
    }

    x-peer label {
        flex-direction: row;
        min-height: auto;
        padding: 16px 20px;
        gap: 16px;
        width: 100%;
    }

    x-peer .icon-container {
        margin-bottom: 0;
        width: 56px;
        height: 56px;
    }

    x-peer x-icon {
        width: 44px;
        height: 44px;
        --icon-size: 28px;
    }

    x-peer .progress-ring {
        width: 56px;
        height: 56px;
    }
    x-peer .progress-ring circle {
        stroke-width: 2.5;
    }

    x-peer .card-info {
        align-items: flex-start;
    }

    x-peer .hostname {
        text-align: left;
        font-size: 12px;
    }

    x-peer .device-name {
        text-align: left;
    }

    .status-bar {
        height: var(--header-h);
        padding: 0 12px;
    }

    .mode-badge {
        font-size: 8px;
        padding: 4px 10px;
        letter-spacing: 0.08em;
    }

    .app-footer {
        height: var(--footer-h);
        gap: 2px;
    }

    .footer-brand {
        font-size: 13px;
    }
}

/* Tablet — 481px to 1023px */
@media (min-width: 481px) and (max-width: 1023px) {
    :root {
        --card-w: 200px;
        --card-h: 240px;
    }

    x-peers {
        grid-template-columns: repeat(auto-fit, var(--card-w));
        gap: 16px;
    }
}

/* Desktop — 1024px+ */
@media (min-width: 1024px) {
    :root {
        --card-w: 220px;
        --card-h: 260px;
    }

    x-peers {
        grid-template-columns: repeat(auto-fit, var(--card-w));
        gap: 24px;
    }
}

/* Very short screens */
@media (max-height: 420px) {
    .app-footer {
        height: 60px;
        padding: 4px 20px;
    }
    .footer-credit { display: none; }
}


/* ═══════════════════════════════════════
   iOS SPECIFIC
   ═══════════════════════════════════════ */

@supports (-webkit-overflow-scrolling: touch) {
    html { position: fixed; }
    x-instructions::before { content: attr(mobile); }
}

/* Edge specific */
@supports (-ms-ime-align: auto) {
    html, body { overflow: hidden; }
}


/* ═══════════════════════════════════════
   SCROLLBAR
   ═══════════════════════════════════════ */

::-webkit-scrollbar {
    width: 5px;
}

::-webkit-scrollbar-track {
    background: var(--bg-primary);
}

::-webkit-scrollbar-thumb {
    background: var(--slate-dim);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--slate);
}


/* ═══════════════════════════════════════
   SELECTION
   ═══════════════════════════════════════ */

::selection {
    background: var(--cyan-glow-lg);
    color: var(--cyan-bright);
}


/* ═══════════════════════════════════════
   NOSCRIPT
   ═══════════════════════════════════════ */

x-noscript {
    background: var(--bg-secondary);
    color: var(--text-primary);
    z-index: 200;
}
