/* ===== Design Tokens ===== */
:root {
    --bg-primary: #0f0f17;
    --bg-secondary: #1a1a2e;
    --bg-tertiary: #16213e;
    --bg-glass: rgba(255, 255, 255, 0.05);
    --bg-glass-hover: rgba(255, 255, 255, 0.08);
    --border-glass: rgba(255, 255, 255, 0.1);
    --accent: #7c3aed;
    --accent-light: #a78bfa;
    --accent-glow: rgba(124, 58, 237, 0.35);
    --accent-secondary: #06b6d4;
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --bubble-own: linear-gradient(135deg, #7c3aed, #6d28d9);
    --bubble-other: rgba(255, 255, 255, 0.06);
    --danger: #ef4444;
    --success: #22c55e;
    --radius-sm: 8px;
    --radius-md: 14px;
    --radius-lg: 22px;
    --radius-full: 50%;
    --shadow-sm: 0 2px 8px rgba(0,0,0,0.25);
    --shadow-md: 0 8px 32px rgba(0,0,0,0.35);
    --shadow-glow: 0 0 30px var(--accent-glow);
    --transition: 0.25s cubic-bezier(.4,0,.2,1);
}

/* ===== Reset & Global ===== */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

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

body, html {
    font-family: 'Inter', sans-serif;
    font-size: 15px;
    width: 100%; height: 100%;
    overflow: hidden;
    background: var(--bg-primary);
    color: var(--text-primary);
    -webkit-font-smoothing: antialiased;
}

/* ===== Scrollbar ===== */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--text-muted); border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: var(--accent-light); }

/* ===== Main Container ===== */
#main {
    display: flex;
    flex-direction: column;
    width: 100%; height: 100%;
    min-height: 100vh;
    min-height: 100dvh;
    background: var(--bg-primary);
}

/* ===== LOGIN SCREEN ===== */
.form-container {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100%;
    min-height: 100vh;
    background: radial-gradient(ellipse at 50% 0%, rgba(124,58,237,0.15) 0%, transparent 60%),
                var(--bg-primary);
    animation: fadeIn 0.6s ease;
}

.login-card {
    background: var(--bg-glass);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-lg);
    padding: 40px 36px 36px;
    width: 90%;
    max-width: 380px;
    box-shadow: var(--shadow-md), var(--shadow-glow);
    text-align: center;
    animation: slideUp 0.5s ease;
}

.login-card .login-icon {
    width: 64px; height: 64px;
    background: var(--bubble-own);
    border-radius: var(--radius-full);
    display: flex; align-items: center; justify-content: center;
    margin: 0 auto 18px;
    font-size: 28px;
    box-shadow: var(--shadow-glow);
}

.login-card h2 {
    font-size: 1.35rem;
    font-weight: 700;
    margin-bottom: 6px;
    color: var(--text-primary);
}

.login-card p.subtitle {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 24px;
}

.login-card input[type="text"] {
    width: 100%;
    padding: 13px 16px;
    background: rgba(255,255,255,0.06);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: 0.95rem;
    font-family: inherit;
    outline: none;
    transition: var(--transition);
    margin-bottom: 18px;
}

.login-card input[type="text"]:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.login-card input[type="text"]::placeholder {
    color: var(--text-muted);
}

.btn-primary {
    width: 100%;
    padding: 13px;
    background: var(--bubble-own);
    color: #fff;
    border: none;
    border-radius: var(--radius-md);
    font-size: 0.95rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: var(--transition);
    box-shadow: var(--shadow-sm);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-glow), var(--shadow-md);
}

.btn-primary:active {
    transform: translateY(0);
}

/* ===== HEADER ===== */
#header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 18px;
    background: linear-gradient(135deg, var(--bg-secondary), var(--bg-tertiary));
    border-bottom: 1px solid var(--border-glass);
    animation: fadeIn 0.4s ease;
    flex-shrink: 0;
}

.header-avatar {
    width: 38px; height: 38px;
    border-radius: var(--radius-full);
    background: var(--bubble-own);
    display: flex; align-items: center; justify-content: center;
    font-weight: 700;
    font-size: 1rem;
    color: #fff;
    text-transform: uppercase;
    flex-shrink: 0;
    box-shadow: var(--shadow-sm);
}

.header-info {
    flex: 1;
    min-width: 0;
}

.header-info .header-nick {
    font-weight: 600;
    font-size: 0.95rem;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.header-info .header-status {
    font-size: 0.72rem;
    color: var(--success);
    display: flex;
    align-items: center;
    gap: 4px;
}

.header-info .header-status::before {
    content: '';
    width: 6px; height: 6px;
    background: var(--success);
    border-radius: var(--radius-full);
    display: inline-block;
    animation: pulse 2s infinite;
}

.header-logo {
    height: 28px;
    object-fit: contain;
    margin: 0 auto;
    filter: drop-shadow(0 0 6px rgba(255,255,255,0.15));
}

.logout {
    padding: 7px 16px;
    background: rgba(255,255,255,0.06);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.8rem;
    font-weight: 500;
    transition: var(--transition);
}

.logout:hover {
    background: rgba(239,68,68,0.15);
    border-color: var(--danger);
    color: var(--danger);
}

/* ===== MESSAGES AREA ===== */
#result {
    flex: 1;
    overflow-y: auto;
    padding: 18px 14px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    scroll-behavior: smooth;
}

/* ===== MESSAGE BUBBLES ===== */
.message-row {
    display: flex;
    flex-direction: column;
    max-width: 82%;
    animation: msgIn 0.3s ease;
}

.message-row.own {
    align-self: flex-end;
}

.message-row.other {
    align-self: flex-start;
}

.message-bubble {
    padding: 10px 14px;
    border-radius: var(--radius-md);
    line-height: 1.45;
    font-size: 0.9rem;
    word-wrap: break-word;
    position: relative;
}

.message-row.own .message-bubble {
    background: var(--bubble-own);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.message-row.other .message-bubble {
    background: var(--bubble-other);
    border: 1px solid var(--border-glass);
    color: var(--text-primary);
    border-bottom-left-radius: 4px;
}

.message-nick {
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--accent-light);
    margin-bottom: 3px;
}

.message-row.own .message-nick {
    display: none;
}

.message-time {
    font-size: 0.65rem;
    color: rgba(255,255,255,0.45);
    text-align: right;
    margin-top: 4px;
}

.message-row.other .message-time {
    color: var(--text-muted);
}

/* ===== RADIO PLAYER BAR ===== */
.radio-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 14px;
    background: linear-gradient(135deg, rgba(124,58,237,0.12), rgba(6,182,212,0.08));
    border-bottom: 1px solid var(--border-glass);
    flex-shrink: 0;
    animation: fadeIn 0.4s ease;
}

.radio-play-btn {
    width: 36px; height: 36px;
    background: var(--bubble-own);
    border: none;
    border-radius: var(--radius-full);
    color: #fff;
    font-size: 0.9rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: var(--transition);
    box-shadow: var(--shadow-sm);
}

.radio-play-btn:hover {
    transform: scale(1.1);
    box-shadow: var(--shadow-glow);
}

.radio-play-btn:active {
    transform: scale(0.95);
}

.radio-bar.playing .radio-play-btn {
    box-shadow: var(--shadow-glow);
    animation: pulse 2s infinite;
}

.radio-icon {
    line-height: 1;
}

.radio-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex: 1;
    min-width: 0;
}

.radio-live-badge {
    font-size: 0.65rem;
    font-weight: 600;
    color: var(--danger);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.radio-bar.playing .radio-live-badge {
    animation: pulse 1.5s infinite;
}

.radio-title {
    font-size: 0.8rem;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.radio-volume {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}

.volume-icon {
    font-size: 0.85rem;
}

.volume-slider {
    -webkit-appearance: none;
    appearance: none;
    width: 70px;
    height: 4px;
    background: rgba(255,255,255,0.12);
    border-radius: 2px;
    outline: none;
    cursor: pointer;
}

.volume-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 14px; height: 14px;
    border-radius: var(--radius-full);
    background: var(--accent-light);
    cursor: pointer;
    box-shadow: 0 0 6px var(--accent-glow);
    transition: var(--transition);
}

.volume-slider::-webkit-slider-thumb:hover {
    transform: scale(1.2);
}

.volume-slider::-moz-range-thumb {
    width: 14px; height: 14px;
    border-radius: var(--radius-full);
    background: var(--accent-light);
    cursor: pointer;
    border: none;
}

/* ===== SENDER BAR ===== */
#sender {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border-glass);
    flex-shrink: 0;
}

.emoji-btn {
    width: 40px; height: 40px;
    background: none;
    border: none;
    font-size: 1.35rem;
    cursor: pointer;
    border-radius: var(--radius-full);
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.emoji-btn:hover {
    background: var(--bg-glass-hover);
}

#msg {
    flex: 1;
    padding: 11px 16px;
    background: rgba(255,255,255,0.06);
    border: 1px solid var(--border-glass);
    border-radius: 24px;
    color: var(--text-primary);
    font-size: 0.9rem;
    font-family: inherit;
    outline: none;
    resize: none;
    transition: var(--transition);
    min-width: 0;
}

#msg:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

#msg::placeholder {
    color: var(--text-muted);
}

.send-btn {
    width: 42px; height: 42px;
    background: var(--bubble-own);
    border: none;
    border-radius: var(--radius-full);
    color: #fff;
    font-size: 1.1rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: var(--transition);
    box-shadow: var(--shadow-sm);
}

.send-btn:hover {
    transform: scale(1.08);
    box-shadow: var(--shadow-glow);
}

.send-btn:active {
    transform: scale(0.95);
}

/* char counter */
.char-counter {
    font-size: 0.65rem;
    color: var(--text-muted);
    min-width: 38px;
    text-align: center;
    flex-shrink: 0;
}

.char-counter.warn { color: var(--danger); }

/* ===== EMOJI PICKER ===== */
.emoji-picker {
    display: none;
    position: absolute;
    bottom: 62px;
    left: 14px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-md);
    padding: 10px;
    box-shadow: var(--shadow-md);
    z-index: 100;
    animation: fadeIn 0.2s ease;
}

.emoji-picker.show { display: flex; flex-wrap: wrap; gap: 4px; width: 240px; }

.emoji-picker button {
    font-size: 1.25rem;
    background: none;
    border: none;
    cursor: pointer;
    padding: 5px;
    border-radius: var(--radius-sm);
    transition: var(--transition);
}

.emoji-picker button:hover {
    background: var(--bg-glass-hover);
    transform: scale(1.2);
}

/* ===== TOAST ===== */
.toast {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%) translateY(-30px);
    padding: 12px 22px;
    border-radius: var(--radius-md);
    font-size: 0.85rem;
    font-weight: 500;
    color: #fff;
    z-index: 999;
    opacity: 0;
    pointer-events: none;
    transition: all 0.35s cubic-bezier(.4,0,.2,1);
    box-shadow: var(--shadow-md);
    backdrop-filter: blur(12px);
}

.toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

.toast.error {
    background: linear-gradient(135deg, rgba(239,68,68,0.9), rgba(185,28,28,0.9));
    border: 1px solid rgba(239,68,68,0.4);
}

.toast.success {
    background: linear-gradient(135deg, rgba(34,197,94,0.9), rgba(21,128,61,0.9));
    border: 1px solid rgba(34,197,94,0.4);
}

/* ===== ANIMATIONS ===== */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes slideUp {
    from { opacity: 0; transform: translateY(30px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes msgIn {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

/* ===== RESPONSIVE ===== */
@media (max-width: 600px) {
    body { font-size: 16px; }
    .login-card { padding: 32px 24px 28px; }
    #msg { font-size: 1rem; padding: 12px 14px; }
    .send-btn { width: 44px; height: 44px; }
    .message-row { max-width: 88%; }
    #result { padding: 14px 10px; }
    .emoji-picker.show { width: 200px; }
}