/*
 * link - Modern Minimalist Design System
 * Redesigned for absolute clarity, premium glassmorphism, and seamless transitions.
 */

:root {
    --icon-size: 24px;
    --primary-color: #3b82f6; /* Premium cobalt blue */
    --accent-color: #60a5fa;
    --peer-width: 140px;
    
    /* Light Mode colors */
    --bg-color: #f8fafc;
    --bg-color-secondary: #eff3f8;
    --text-color: #0f172a;
    --text-muted: #64748b;
    --success-color: #10b981;
    --error-color: #f43f5e;
    --warning-color: #f59e0b;
    --border-color: rgba(15, 23, 42, 0.05);
    --card-bg: rgba(255, 255, 255, 0.8);
    --drawer-bg: rgba(255, 255, 255, 0.85);
    --modal-bg: rgba(255, 255, 255, 0.9);
    --card-shadow: 0 12px 30px -4px rgba(31, 38, 135, 0.04), 0 1px 2px rgba(0, 0, 0, 0.02);
    --transition-speed: 0.3s;
}

/* Dark Mode Overrides */
@media (prefers-color-scheme: dark) {
    body:not(.theme-light) {
        --bg-color: #08090d;
        --bg-color-secondary: #0f121d;
        --text-color: #f8fafc;
        --text-muted: #94a3b8;
        --primary-color: #3b82f6;
        --accent-color: #60a5fa;
        --border-color: rgba(255, 255, 255, 0.05);
        --card-bg: rgba(20, 24, 38, 0.6);
        --drawer-bg: rgba(11, 12, 19, 0.85);
        --modal-bg: rgba(16, 20, 32, 0.85);
        --card-shadow: 0 16px 40px -8px rgba(0, 0, 0, 0.6), 0 0 0 1px rgba(255, 255, 255, 0.03);
    }
}

body.theme-light {
    --bg-color: #f8fafc;
    --bg-color-secondary: #eff3f8;
    --text-color: #0f172a;
    --text-muted: #64748b;
    --primary-color: #3b82f6;
    --accent-color: #60a5fa;
    --border-color: rgba(15, 23, 42, 0.05);
    --card-bg: rgba(255, 255, 255, 0.8);
    --drawer-bg: rgba(255, 255, 255, 0.85);
    --modal-bg: rgba(255, 255, 255, 0.9);
    --card-shadow: 0 12px 30px -4px rgba(31, 38, 135, 0.04), 0 1px 2px rgba(0, 0, 0, 0.02);
}

body.theme-dark {
    --bg-color: #08090d;
    --bg-color-secondary: #0f121d;
    --text-color: #f8fafc;
    --text-muted: #94a3b8;
    --primary-color: #3b82f6;
    --accent-color: #60a5fa;
    --border-color: rgba(255, 255, 255, 0.05);
    --card-bg: rgba(20, 24, 38, 0.6);
    --drawer-bg: rgba(11, 12, 19, 0.85);
    --modal-bg: rgba(16, 20, 32, 0.85);
    --card-shadow: 0 16px 40px -8px rgba(0, 0, 0, 0.6), 0 0 0 1px rgba(255, 255, 255, 0.03);
}

/* Global Reset & Base Layout */
html {
    height: 100%;
}

html, body {
    margin: 0;
    padding: 0;
    width: 100%;
    overflow-x: hidden;
    height: 100%;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    color: var(--text-color);
    background-color: var(--bg-color);
    background-image: radial-gradient(circle at center, var(--bg-color-secondary) 0%, var(--bg-color) 80%);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    overflow-y: hidden;
    transition: background-color 0.4s ease;
}

/* Layout Utilities */
.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; }
[hidden] { display: none !important; }

/* Navigation Header */
header {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 72px;
    display: flex;
    align-items: center;
    padding: 0 24px;
    box-sizing: border-box;
    z-index: 10;
}

header a {
    margin-left: 12px;
    color: var(--text-muted);
    transition: color 0.2s, transform 0.2s;
}

header a:hover {
    color: var(--text-color);
    transform: scale(1.05);
}

/* Language Selection Styling */
.language-select-wrapper {
    display: flex;
    align-items: center;
    position: relative;
    margin-left: 12px;
    height: 36px;
    padding: 0 10px;
    border-radius: 18px;
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    transition: all var(--transition-speed) cubic-bezier(0.4, 0, 0.2, 1);
    cursor: pointer;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

.language-select-wrapper:hover {
    background: var(--bg-color-secondary);
    border-color: var(--primary-color);
    box-shadow: var(--card-shadow);
}

.language-select-wrapper .icon {
    width: 18px;
    height: 18px;
    margin-right: 4px;
    color: var(--text-muted);
    transition: color var(--transition-speed);
}

.language-select-wrapper:hover .icon {
    color: var(--text-color);
}

.language-select-wrapper select {
    background: transparent;
    border: 0;
    color: var(--text-color);
    font-family: 'Inter', sans-serif;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    outline: none;
    padding-right: 2px;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
}

/* Typography */
h1 {
    font-size: 32px;
    font-weight: 700;
    letter-spacing: -0.025em;
    margin: 0 0 8px;
}

h2 {
    font-size: 20px;
    font-weight: 600;
    letter-spacing: -0.02em;
    margin: 0;
}

h3 {
    font-size: 18px;
    font-weight: 600;
    letter-spacing: -0.01em;
    margin: 0 0 16px 0;
}

.font-subheading {
    font-size: 14px;
    font-weight: 500;
    line-height: 20px;
}

.font-body1 {
    font-size: 14px;
    font-weight: 400;
    line-height: 20px;
}

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

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

/* Icon Buttons */
.icon-button {
    width: 42px;
    height: 42px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 12px;
    border: 1px solid var(--border-color);
    background: var(--card-bg);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    color: var(--text-color);
    cursor: pointer;
    box-shadow: var(--card-shadow);
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    outline: none;
    position: relative;
}

.icon-button:hover {
    background: var(--bg-color-secondary);
    border-color: var(--text-muted);
    color: var(--primary-color);
}

.icon-button.active {
    background: var(--primary-color);
    border-color: var(--primary-color);
    color: white;
}

.icon-button.active:hover {
    background: var(--primary-color);
    color: white;
    opacity: 0.9;
}

.icon-button .badge {
    position: absolute;
    top: -4px;
    right: -4px;
    background-color: var(--primary-color);
    color: white;
    font-size: 10px;
    font-weight: 700;
    height: 18px;
    min-width: 18px;
    border-radius: 9px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px rgba(37, 99, 235, 0.3);
}

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

/* Peers Container */
x-peers {
    width: 100%;
    max-width: 960px;
    padding: 24px;
    box-sizing: border-box;
    display: flex;
    flex-flow: row wrap;
    align-items: center;
    justify-content: center;
    gap: 24px;
    z-index: 2;
}

/* No Peers State (Radar Pulse Animation) */
x-no-peers {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    position: relative;
    padding: 60px 24px;
    width: 100%;
    max-width: 400px;
    text-align: center;
    animation: fade-in 0.5s ease-out backwards;
}

x-no-peers h2 {
    font-size: 15px;
    font-weight: 500;
    color: var(--text-muted);
    line-height: 1.5;
    margin-top: 120px;
    z-index: 2;
    max-width: 280px;
}

x-no-peers::before {
    content: '';
    position: absolute;
    top: 40px;
    left: calc(50% - 40px);
    width: 80px;
    height: 80px;
    border: 1.5px dashed var(--primary-color);
    border-radius: 50%;
    opacity: 0.5;
    animation: rotate-slow 15s linear infinite;
    pointer-events: none;
    z-index: 1;
}

x-no-peers::after {
    content: '';
    position: absolute;
    top: 40px;
    left: calc(50% - 40px);
    width: 80px;
    height: 80px;
    background-image: radial-gradient(circle, var(--primary-color) 0%, transparent 65%);
    border-radius: 50%;
    opacity: 0.25;
    animation: breathing 3s ease-in-out infinite;
    pointer-events: none;
    z-index: 1;
}

@keyframes rotate-slow {
    0% {
        transform: rotate(0deg);
    }
    100% {
        transform: rotate(360deg);
    }
}

@keyframes breathing {
    0%, 100% {
        transform: scale(0.92);
        opacity: 0.15;
    }
    50% {
        transform: scale(1.08);
        opacity: 0.35;
    }
}

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

/* Individual Peer Element */
x-peer {
    display: flex;
    flex-direction: column;
    align-items: center;
    animation: peer-pop 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes peer-pop {
    0% { transform: scale(0.6); opacity: 0; }
    100% { transform: scale(1); opacity: 1; }
}

x-peer label {
    width: var(--peer-width);
    padding: 28px 16px 20px;
    border-radius: 24px;
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    box-shadow: var(--card-shadow);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    display: flex;
    flex-direction: column;
    align-items: center;
    cursor: pointer;
    position: relative;
    overflow: hidden;
    transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
    touch-action: manipulation;
    -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
}

x-peer label:hover {
    transform: translateY(-6px);
    border-color: rgba(37, 99, 235, 0.2);
    box-shadow: 0 20px 40px -10px rgba(15, 23, 42, 0.08), 0 0 0 1px rgba(37, 99, 235, 0.05);
}

body.theme-dark x-peer label:hover {
    border-color: rgba(96, 165, 250, 0.2);
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(96, 165, 250, 0.05);
}

x-peer input[type="file"] {
    position: absolute;
    width: 0;
    height: 0;
    opacity: 0;
}

x-peer x-icon {
    --icon-size: 28px;
    width: var(--icon-size);
    height: var(--icon-size);
    padding: 16px;
    border-radius: 50%;
    background: var(--bg-color-secondary);
    color: var(--text-color);
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 16px;
    position: relative;
    z-index: 2;
    transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
}

x-peer label:hover x-icon {
    background: var(--primary-color);
    color: white;
    transform: scale(1.05);
}

/* Peer Text Metadata */
x-peer .name {
    width: 100%;
    font-size: 14px;
    font-weight: 600;
    letter-spacing: -0.01em;
    color: var(--text-color);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    text-align: center;
    margin-bottom: 2px;
}

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

x-peer .status {
    font-size: 11px;
    font-weight: 600;
    color: var(--primary-color);
    text-align: center;
    height: 16px;
}

x-peer[transfer] .status::before {
    content: 'Sending...';
}

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

/* Connection Type Badge */
x-peer .connection-type {
    margin-top: 8px;
    padding: 2px 8px;
    border-radius: 8px;
    font-size: 9px;
    font-weight: 700;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    background: var(--bg-color-secondary);
    border: 1px solid var(--border-color);
    opacity: 0.9;
}

x-peer .connection-type.p2p {
    color: var(--success-color);
    background-color: rgba(16, 185, 129, 0.08);
    border-color: rgba(16, 185, 129, 0.15);
}

x-peer .connection-type.relay {
    color: var(--warning-color);
    background-color: rgba(245, 158, 11, 0.08);
    border-color: rgba(245, 158, 11, 0.15);
}

/* Peer Circular Progress Ring */
.progress {
    width: 68px;
    height: 68px;
    position: absolute;
    top: 24px;
    left: calc(50% - 34px);
    clip: rect(0px, 68px, 68px, 34px);
    --progress: rotate(0deg);
    transition: transform 200ms;
    pointer-events: none;
    z-index: 1;
}

.circle {
    box-sizing: border-box;
    width: 68px;
    height: 68px;
    border: 3px solid var(--primary-color);
    border-radius: 50%;
    position: absolute;
    top: 0;
    left: 0;
    clip: rect(0px, 34px, 68px, 0px);
    will-change: transform;
    transform: var(--progress);
}

.over50 {
    clip: rect(auto, auto, auto, auto);
}

.over50 .circle.right {
    transform: rotate(180deg);
}

/* Drag State for Peer Card */
x-peer[drop] label {
    transform: scale(1.05);
    border-color: var(--primary-color);
    background-color: rgba(37, 99, 235, 0.05);
}

/* Footer Section */
footer {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 24px;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    z-index: 10;
}

footer .logo {
    --icon-size: 32px;
    margin-bottom: 12px;
    color: var(--primary-color);
    opacity: 0.85;
    animation: float 4s ease-in-out infinite;
}

@keyframes float {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-4px); }
}

#displayName {
    cursor: pointer;
    font-weight: 500;
    font-size: 13px;
    color: var(--text-color);
    padding: 6px 14px;
    border-radius: 20px;
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    box-shadow: var(--card-shadow);
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

#displayName:hover {
    background: var(--bg-color-secondary);
    border-color: var(--text-muted);
    transform: translateY(-1px);
}

#roomContainer {
    margin-top: 8px;
}

#roomStatus {
    font-size: 11px;
    color: var(--text-muted);
}

.room-actions {
    display: flex;
    gap: 8px;
    margin-top: 8px;
}

footer button.button-link {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-muted);
    padding: 5px 12px;
    border-radius: 16px;
    font-size: 11px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    outline: none;
}

footer button.button-link:hover {
    border-color: var(--primary-color);
    color: var(--primary-color);
    background: rgba(37, 99, 235, 0.04);
}

/* Instructions Banner */
x-instructions {
    position: absolute;
    top: 96px;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-muted);
    opacity: 0.8;
    z-index: 1;
    pointer-events: none;
    text-align: center;
    animation: fade-in 0.3s ease-out;
}

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

x-peers:empty ~ x-instructions {
    display: none !important;
}

/* Dialog Overlay and Layout */
x-dialog {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 150;
    pointer-events: none;
}

x-dialog[show] {
    pointer-events: auto;
}

x-dialog x-background {
    background: rgba(15, 23, 42, 0.35);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    box-sizing: border-box;
    opacity: 0;
    transition: opacity 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    z-index: 1;
}

x-dialog[show] x-background {
    opacity: 1;
}

x-dialog x-paper {
    background: var(--modal-bg);
    border: 1px solid var(--border-color);
    border-radius: 28px;
    padding: 32px;
    width: 100%;
    max-width: 420px;
    box-shadow: 0 25px 50px -12px rgba(15, 23, 42, 0.15);
    box-sizing: border-box;
    transform: scale(0.95) translateY(12px);
    opacity: 0;
    transition: all 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
    z-index: 2;
}

x-dialog[show] x-paper {
    transform: scale(1) translateY(0);
    opacity: 1;
}

x-dialog .row-reverse {
    gap: 8px;
    margin-top: 24px;
}

/* Modern Input and Textarea Elements */
.textarea {
    width: 100%;
    box-sizing: border-box;
    background: var(--bg-color-secondary);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 14px 18px;
    font-size: 14px;
    color: var(--text-color);
    transition: all 0.25s ease;
    outline: none;
    resize: none;
    min-height: 48px;
    line-height: 1.5;
    font-family: inherit;
}

.textarea:focus {
    border-color: var(--primary-color);
    background: var(--bg-color);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

/* Chat thread (SendTextDialog) - a scrollable per-peer message history
   above the composer, replacing the old single "last message" popup. */
.text-thread {
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-height: 45vh;
    overflow-y: auto;
    margin-bottom: 14px;
    padding-right: 2px;
}

.text-thread:empty {
    display: none;
}

.text-thread-empty {
    color: var(--text-color);
    opacity: 0.5;
    font-size: 13px;
    text-align: center;
    padding: 12px 0;
}

.text-msg {
    display: flex;
    flex-direction: column;
    max-width: 85%;
}

.text-msg-outgoing {
    align-self: flex-end;
    align-items: flex-end;
}

.text-msg-incoming {
    align-self: flex-start;
    align-items: flex-start;
}

.text-msg-bubble {
    background: var(--bg-color-secondary);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 10px 14px;
    font-size: 14px;
    line-height: 1.4;
    color: var(--text-color);
    word-break: break-word;
    white-space: pre-wrap;
    cursor: pointer;
}

.text-msg-outgoing .text-msg-bubble {
    background: var(--primary-color);
    color: #fff;
    border-color: transparent;
}

.text-msg-bubble a {
    color: inherit;
    text-decoration: underline;
}

.text-msg-status {
    font-size: 11px;
    opacity: 0.6;
    margin-top: 3px;
    padding: 0 4px;
}

.text-msg-status-failed {
    color: var(--error-color);
    opacity: 1;
}

.text-msg-status-retryable {
    cursor: pointer;
    text-decoration: underline;
}

/* Voice messages (SendTextDialog) - recording bar shown above the composer
   while VoiceRecorder is active, and the inline playable bubble rendered
   for {type: 'voice'} entries in the chat thread (see ui.js
   _renderVoiceBubble). Audio itself never touches this file - it's stored
   client-side in IndexedDB via voice-store.js. */
.voice-record-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    margin-bottom: 10px;
    border-radius: 12px;
    background: var(--bg-color-secondary);
    border: 1px solid var(--border-color);
    font-size: 13px;
}

.voice-record-dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: var(--error-color, #e53935);
    animation: voice-record-pulse 1.2s ease-in-out infinite;
    flex-shrink: 0;
}

@keyframes voice-record-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.3; }
}

#voiceRecordTime {
    font-variant-numeric: tabular-nums;
    font-weight: 600;
}

.voice-record-hint {
    opacity: 0.7;
    flex-grow: 1;
}

.voice-record-bar .icon-button {
    width: 28px;
    height: 28px;
    border-radius: 8px;
    box-shadow: none;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
}

.voice-record-bar .icon-button .icon {
    width: 16px;
    height: 16px;
}

.voice-msg-bubble {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--bg-color-secondary);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 8px 12px;
    min-width: 160px;
}

.text-msg-outgoing .voice-msg-bubble {
    background: var(--primary-color);
    color: #fff;
    border-color: transparent;
}

.voice-msg-bubble.voice-msg-pending,
.voice-msg-bubble.voice-msg-unavailable {
    min-width: 0;
    font-size: 13px;
    font-style: italic;
    opacity: 0.7;
}

.voice-play-btn {
    width: 30px;
    height: 30px;
    flex-shrink: 0;
    border-radius: 50%;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(127, 127, 127, 0.18);
    color: inherit;
    cursor: pointer;
    padding: 0;
}

.text-msg-outgoing .voice-play-btn {
    background: rgba(255, 255, 255, 0.25);
}

.voice-play-btn .icon {
    width: 18px;
    height: 18px;
}

.voice-msg-track {
    flex: 1;
    height: 4px;
    border-radius: 2px;
    background: rgba(127, 127, 127, 0.25);
    overflow: hidden;
}

.text-msg-outgoing .voice-msg-track {
    background: rgba(255, 255, 255, 0.3);
}

.voice-msg-progress {
    height: 100%;
    width: 0%;
    background: currentColor;
    opacity: 0.8;
    border-radius: 2px;
}

.voice-msg-duration {
    font-size: 11px;
    font-variant-numeric: tabular-nums;
    opacity: 0.75;
    flex-shrink: 0;
}

/* Standard Buttons */
.button {
    padding: 12px 24px;
    border-radius: 16px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    border: none;
    outline: none;
    background: var(--bg-color-secondary);
    color: var(--text-color);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-transform: none;
    letter-spacing: normal;
}

.button:hover {
    background: var(--border-color);
    transform: translateY(-1px);
}

.button:active {
    transform: translateY(0);
}

.button#download, .button[type="submit"] {
    background: var(--primary-color);
    color: white;
}

.button#download:hover, .button[type="submit"]:hover {
    opacity: 0.95;
    background: var(--primary-color);
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.2);
}

/* Dialog Specific Overrides */
#receiveDialog .preview {
    margin: 16px 0;
    border-radius: 16px;
    overflow: hidden;
    border: 1px solid var(--border-color);
    background: var(--bg-color-secondary);
}

#img-preview {
    max-width: 100%;
    max-height: 240px;
    display: block;
    margin: 0 auto;
    object-fit: contain;
}

#receiveDialog label[for="autoDownload"] {
    font-size: 13px;
    color: var(--text-muted);
    cursor: pointer;
}

#receiveTextDialog #text {
    width: 100%;
    word-break: break-all;
    max-height: 200px;
    overflow-y: auto;
    background: var(--bg-color-secondary);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 16px;
    font-size: 14px;
    line-height: 1.5;
    white-space: pre-wrap;
    user-select: text;
    -webkit-user-select: text;
    box-sizing: border-box;
    margin-top: 12px;
}

#receiveTextDialog #text a {
    color: var(--primary-color);
    word-break: break-all;
}

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

/* Edit Nickname Dialog styles */
#nicknameInput {
    width: 100%;
    box-sizing: border-box;
}

/* Toast System */
.toast-container {
    position: fixed;
    bottom: 24px;
    left: 0;
    right: 0;
    display: flex;
    justify-content: center;
    pointer-events: none;
    z-index: 200;
}

x-toast {
    background: rgba(15, 23, 42, 0.9);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    color: white;
    border-radius: 20px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15);
    font-size: 13px;
    font-weight: 500;
    padding: 10px 24px;
    max-width: 320px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.25s, transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    transform: translateY(100px);
    opacity: 0;
}

body.theme-light x-toast {
    background: rgba(15, 23, 42, 0.95);
}

x-toast[show] {
    transform: translateY(0);
    opacity: 1;
}

/* Transfer Center Drawer */
.drawer {
    position: fixed;
    top: 0;
    right: 0;
    width: 360px;
    max-width: 100%;
    height: 100%;
    background: var(--drawer-bg);
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    box-shadow: -10px 0 40px rgba(0, 0, 0, 0.05);
    z-index: 180;
    transform: translateX(100%);
    transition: transform 0.4s cubic-bezier(0.16, 1, 0.3, 1);
    display: flex;
    flex-direction: column;
    box-sizing: border-box;
    border-left: 1px solid var(--border-color);
}

.drawer.show {
    transform: translateX(0);
}

.drawer-header {
    padding: 24px 20px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: transparent;
}

.drawer-header h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
}

.drawer-body {
    flex-grow: 1;
    overflow-y: auto;
    padding: 20px;
    background: transparent;
}

/* Transfer Items styling */
.transfer-item {
    padding: 16px;
    margin-bottom: 12px;
    border-radius: 18px;
    background: var(--bg-color-secondary);
    border: 1px solid var(--border-color);
    font-size: 13px;
    display: flex;
    flex-direction: column;
    transition: all 0.25s ease;
}

.transfer-item:hover {
    transform: translateY(-2px);
    box-shadow: var(--card-shadow);
}

.transfer-item .file-info {
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 4px;
    color: var(--text-color);
}

.transfer-item .transfer-meta {
    font-size: 11px;
    color: var(--text-muted);
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}

.transfer-item .progress-container {
    display: flex;
    align-items: center;
    gap: 12px;
}

.transfer-item progress {
    flex-grow: 1;
    height: 6px;
    border-radius: 3px;
    border: none;
    background: var(--bg-color);
    overflow: hidden;
}

.transfer-item progress::-webkit-progress-bar {
    background-color: var(--bg-color);
}

.transfer-item progress::-webkit-progress-value {
    background-color: var(--primary-color);
    border-radius: 3px;
}

.transfer-item progress::-moz-progress-bar {
    background-color: var(--primary-color);
    border-radius: 3px;
}

.transfer-item .cancel-btn {
    background: transparent;
    border: 1px solid var(--error-color);
    color: var(--error-color);
    padding: 4px 10px;
    border-radius: 10px;
    font-size: 10px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    outline: none;
}

.transfer-item .cancel-btn:hover {
    background: var(--error-color);
    color: white;
}

.transfer-item .status-badge {
    padding: 3px 8px;
    border-radius: 6px;
    font-size: 9px;
    font-weight: 700;
    text-transform: uppercase;
}

.transfer-item .status-badge.completed {
    background-color: rgba(16, 185, 129, 0.1);
    color: var(--success-color);
}

.transfer-item .status-badge.cancelled {
    background-color: rgba(239, 68, 68, 0.1);
    color: var(--error-color);
}

.transfer-item .status-badge.transferring {
    background-color: rgba(59, 130, 246, 0.1);
    color: var(--primary-color);
}

.transfer-item .status-badge.queued {
    background-color: rgba(245, 158, 11, 0.1);
    color: var(--warning-color);
}

#transfer-list .empty-state {
    text-align: center;
    color: var(--text-muted);
    font-size: 13px;
    padding: 60px 20px;
}

/* Friends Drawer */
.friends-my-code {
    align-items: stretch;
    gap: 6px;
    margin-bottom: 20px;
    padding-bottom: 20px;
    border-bottom: 1px solid var(--border-color);
}

.friends-my-code label {
    color: var(--text-muted);
}

.friends-my-code input,
.friends-add input {
    font-family: inherit;
    font-size: 13px;
    padding: 8px 10px;
    border-radius: 10px;
    border: 1px solid var(--border-color);
    background: var(--bg-color-secondary);
    color: var(--text-color);
}

.friends-add {
    gap: 8px;
    margin-bottom: 20px;
}

.friends-add .button {
    padding: 8px 16px;
    white-space: nowrap;
}

#btnScanFriendQr {
    flex-shrink: 0;
}

#myDeviceQrWrap {
    flex-direction: column;
    gap: 8px;
}

#myDeviceQr {
    border-radius: 8px;
    background: #fff;
    padding: 10px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
}

#myDeviceQrWrap .font-body2 {
    max-width: 220px;
    font-size: 12px;
}

#qrScanDialog x-paper {
    max-width: 360px;
}

#qrScanVideo {
    aspect-ratio: 1 / 1;
    object-fit: cover;
}

#friends-list .empty-state {
    text-align: center;
    color: var(--text-muted);
    font-size: 13px;
    padding: 40px 20px;
}

.friend-row {
    gap: 10px;
    padding: 12px;
    margin-bottom: 10px;
    border-radius: 14px;
    background: var(--bg-color-secondary);
    border: 1px solid var(--border-color);
    /* A row now carries up to 3 action buttons (connect / invite-to-Pong /
       remove) alongside the label — wrap instead of overflowing the 360px
       drawer on narrow viewports or with longer translated button text. */
    flex-wrap: wrap;
    align-items: center;
}

.friend-row-label {
    min-width: 0;
}

.friend-row-label .font-subheading {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.friend-row-status {
    color: var(--text-muted);
}

.friend-row-status.friend-online {
    color: var(--success-color, #16a34a);
}

.friend-row button.button-link {
    font-size: 11px;
    padding: 6px 10px;
    border-radius: 12px;
    border: 1px solid var(--primary-color);
    background: transparent;
    color: var(--primary-color);
    cursor: pointer;
    white-space: nowrap;
}

.friend-row button.button-link:disabled {
    opacity: 0.5;
    cursor: default;
}

/* Online-friends panel on the main page (not the Friends drawer) — see
   friends-ui.js #_renderOnlinePeers. Deliberately `position: fixed` and kept
   *out* of the normal document flow: the home screen is a fixed single-view
   layout (`body { overflow-y: hidden }`) with the footer pinned via
   `position: absolute; bottom: 0`, sized to just fit the existing
   header/peers/instructions stack. Adding this panel into that flow would
   grow the centered content past the viewport and get clipped/occluded
   under the footer on common viewport heights. Floating it avoids touching
   that layout budget at all, at the cost of overlapping peer cards on very
   small screens — acceptable since it only ever holds a handful of compact
   chips (friends online at once), not the potentially-larger local-peers grid. */
#online-friends-section {
    position: fixed;
    top: 72px;
    right: 16px;
    z-index: 6;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
    max-width: min(240px, calc(100vw - 32px));
}

#online-friends-section[hidden] {
    display: none;
}

.online-friends-title {
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-size: 10px;
    font-weight: 700;
    text-align: right;
}

x-friend-peer {
    display: block;
    animation: peer-pop 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

x-friend-peer .friend-peer-card {
    padding: 10px 12px;
    border-radius: 14px;
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    box-shadow: var(--card-shadow);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 8px;
    cursor: pointer;
}

x-friend-peer x-icon {
    --icon-size: 16px;
    width: var(--icon-size);
    height: var(--icon-size);
    padding: 8px;
    border-radius: 50%;
    background: var(--bg-color-secondary);
    color: var(--text-color);
    display: flex;
    align-items: center;
    justify-content: center;
    flex: none;
}

x-friend-peer .friend-peer-info {
    min-width: 0;
    flex: 1;
    display: flex;
    flex-direction: column;
}

x-friend-peer .name {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-color);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

x-friend-peer .status {
    font-size: 10px;
    font-weight: 600;
}

x-friend-peer .status.friend-online {
    color: var(--success-color, #16a34a);
}

x-friend-peer .friend-pong-btn {
    flex: none;
    font-size: 10px;
    padding: 5px 10px;
    border-radius: 10px;
    border: 1px solid var(--primary-color);
    background: transparent;
    color: var(--primary-color);
    cursor: pointer;
    white-space: nowrap;
}

x-friend-peer .friend-pong-btn:disabled {
    opacity: 0.5;
    cursor: default;
}

#public-devices-list .empty-state {
    text-align: center;
    color: var(--text-muted);
    font-size: 13px;
    padding: 24px 20px;
}

/* Visibility toggle (public-directory opt-in) — small on/off pill, no deps */
.switch {
    position: relative;
    display: inline-block;
    width: 40px;
    height: 22px;
    flex-shrink: 0;
}

.switch input {
    position: absolute;
    inset: 0;
    opacity: 0;
    margin: 0;
    cursor: pointer;
    z-index: 1;
}

.switch .slider {
    position: absolute;
    pointer-events: none;
    cursor: pointer;
    inset: 0;
    background-color: var(--border-color);
    border-radius: 22px;
    transition: background-color .15s ease;
}

.switch .slider::before {
    content: "";
    position: absolute;
    height: 16px;
    width: 16px;
    left: 3px;
    bottom: 3px;
    background-color: #fff;
    border-radius: 50%;
    transition: transform .15s ease;
}

.switch input:checked + .slider {
    background-color: var(--primary-color);
}

.switch input:checked + .slider::before {
    transform: translateX(18px);
}

/* Universal Drag Overlay styling */
#drag-overlay {
    background-color: rgba(9, 10, 15, 0.4);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    z-index: 1000;
    pointer-events: none;
}

.drag-overlay-card {
    background: var(--modal-bg);
    border: 1.5px dashed var(--primary-color);
    border-radius: 32px;
    padding: 48px 32px;
    box-shadow: var(--card-shadow);
    width: 340px;
    max-width: 90%;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
}

.drag-overlay-card h2 {
    margin-top: 16px;
    color: var(--text-color);
}

.drag-overlay-sub {
    font-size: 13px;
    color: var(--text-muted);
    margin-top: 8px;
}

body.drag-active #drag-overlay {
    pointer-events: auto;
}

/* About Screen Details */
#about {
    color: var(--text-color);
    z-index: 200;
    overflow: hidden;
    pointer-events: none;
    text-align: center;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

#about:target {
    pointer-events: auto;
}

#about .about-card {
    background: var(--modal-bg);
    border: 1px solid var(--border-color);
    border-radius: 28px;
    box-shadow: var(--card-shadow);
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    transition: all 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
    transform: scale(0.95) translateY(12px);
    opacity: 0;
    z-index: 2;
    /* Only clickable while the About screen is actually open (#about:target).
       Without this gate, this centered card sits invisibly (opacity:0) on
       top of the peer list at all times and swallows every click/tap on
       whatever is underneath it, even though nothing is visible. */
    pointer-events: none;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100%;
    max-width: 440px;
    padding: 32px;
    box-sizing: border-box;
}

#about:target .about-card {
    opacity: 1;
    pointer-events: all;
    transform: scale(1) translateY(0);
}

#about .about-card header {
    position: static;
    width: 100%;
    height: auto;
    padding: 0;
    margin-bottom: 16px;
    background: transparent;
}

#about .logo {
    --icon-size: 64px;
    color: var(--primary-color);
    margin-bottom: 16px;
}

#about h1 {
    font-size: 28px;
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--text-color);
    margin-bottom: 12px;
}

#about .font-subheading {
    font-weight: 600;
    color: var(--text-color);
    margin-bottom: 16px;
    line-height: 1.5;
    max-width: 360px;
}

#about .font-body1 {
    color: var(--text-muted);
    line-height: 1.6;
    margin-bottom: 24px;
}

#about .font-body2 {
    color: var(--text-muted);
    border-top: 1px solid var(--border-color);
    padding-top: 16px;
    width: 100%;
}

#about .row {
    gap: 16px;
}

#about .icon-button {
    background: var(--card-bg);
    border-color: var(--border-color);
    color: var(--text-color);
}

#about .icon-button:hover {
    background: var(--bg-color-secondary);
    border-color: var(--text-muted);
    color: var(--primary-color);
}

#about x-background {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(15, 23, 42, 0.35);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    opacity: 0;
    z-index: 1;
    transition: opacity 0.35s cubic-bezier(0.16, 1, 0.3, 1);
    pointer-events: none;
}

body.theme-dark #about x-background {
    background: rgba(0, 0, 0, 0.5);
}

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

/* Animations */
@keyframes fade-in {
    0% { opacity: 0; }
    100% { opacity: 1; }
}

/* Responsive Overrides */
@media (min-height: 800px) {
    x-peers {
        padding: 40px;
    }
}

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

@media (max-width: 600px) {
    header {
        height: 64px;
        padding: 0 16px;
    }
    
    x-peers {
        gap: 16px;
        padding: 16px;
    }
    
    x-peer label {
        width: 110px;
        padding: 20px 8px 16px;
    }
    
    x-peer x-icon {
        --icon-size: 24px;
        padding: 12px;
        margin-bottom: 12px;
    }
    
    .progress {
        width: 52px;
        height: 52px;
        top: 18px;
        left: calc(50% - 26px);
        clip: rect(0px, 52px, 52px, 26px);
    }
    
    .circle {
        width: 52px;
        height: 52px;
        clip: rect(0px, 26px, 52px, 0px);
    }
    
    x-instructions {
        top: 80px;
        padding: 0 16px;
        font-size: 12px;
    }
    
    footer {
        padding: 16px;
    }
    
    footer .logo {
        --icon-size: 28px;
    }
    
    .drawer {
        width: 100%;
    }
}

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