/* Modern Anonymous Chatroom Styles */
:root {
    --bg: #0f172a;
    --panel: #111827;
    --muted: #94a3b8;
    --text: #e5e7eb;
    --accent: #22c55e;
    --accent-2: #60a5fa;
    --border: #1f2937;
    /* UI polish */
    --shadow: 0 10px 30px rgba(0,0,0,0.35);
}

* {
    box-sizing: border-box;
}

html,
body {
    height: 100%;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Noto Sans CJK', 'PingFang SC', 'Microsoft YaHei', Arial, sans-serif;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px;
    border-bottom: 1px solid var(--border);
    background: var(--panel);
    /* make header sticky with subtle blur */
    position: sticky;
    top: 0;
    backdrop-filter: saturate(140%) blur(8px);
}

.brand .title {
    font-size: 18px;
    font-weight: 600;
    /* gradient accent title */
    background: linear-gradient(90deg, var(--accent), var(--accent-2));
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}
.brand .title .icon { width: 20px; height: 20px; color: var(--accent-2); flex: 0 0 auto; }

.brand .subtitle {
    color: var(--muted);
    font-size: 12px;
    margin-top: 4px;
}

.presence {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--muted);
}

.presence .dot {
    width: 8px;
    height: 8px;
    background: var(--accent);
    border-radius: 50%;
    display: inline-block;
    animation: pulse 2.2s ease-in-out infinite;
}
@keyframes pulse {
    0%, 100% { transform: scale(1); opacity: 0.9; }
    50% { transform: scale(1.6); opacity: 0.4; }
}

.presence .active {
    background: #16a34a22;
    color: #86efac;
    padding: 4px 8px;
    border-radius: 999px;
    font-size: 12px;
}

.chat {
    max-width: 900px;
    margin: 0 auto;
    padding: 12px;
}

.messages {
    height: calc(100vh - 250px);
    overflow-y: auto;
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 8px;
    background: linear-gradient(180deg, #0b1220, #0f172a);
    /* softer panel and custom scrollbar */
    box-shadow: var(--shadow);
}
.messages::-webkit-scrollbar { width: 10px; }
.messages::-webkit-scrollbar-track { background: #0b1220; border-radius: 10px; }
.messages::-webkit-scrollbar-thumb { background: #1f2937; border-radius: 10px; border: 2px solid #0b1220; }
.messages:hover::-webkit-scrollbar-thumb { background: #334155; }
.messages .system {
    color: var(--muted);
    text-align: center;
    margin: 12px 0;
}

.msg {
    display: grid;
    grid-template-columns: 36px 1fr;
    gap: 8px 10px;
    align-items: start;
    padding: 10px 12px;
}

.msg+.msg { border-top: none; margin-top: 8px; }

.msg .avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: linear-gradient(135deg, #111827, #1f2937);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    box-shadow: inset 0 0 0 1px #334155;
}

.msg .meta {
    color: var(--muted);
    font-size: 12px;
    padding: 0 6px;
}

/* column wrapper stacking nickname, bubble, and time */
.msg .col { display: grid; grid-template-rows: auto auto auto; row-gap: 4px; }
/* utility: move column up by 45px (self messages only) */
.msg.self .col.up-45 { position: relative; top: -45px; }

.msg .content {
    position: relative;
    line-height: 1.6;
    word-break: break-word;
    font-size: 15px;
    background: #0b1220;
    border: 1px solid var(--border);
    border-radius: 12px 12px 12px 6px; /* left bubble */
    padding: 10px 12px;
    box-shadow: 0 6px 20px rgba(0,0,0,0.25);
    max-width: min(72%, 620px);
    display: inline-block;
    justify-self: start; /* shrink to content for other side */
}


/* WeChat-like right bubble for self messages */
.msg.self { grid-template-columns: 1fr 36px; }
.msg.self .avatar { grid-column: 2; }
.msg.self .meta { justify-self: end; text-align: right; }
.msg.self .content {
    justify-self: end;
    background: linear-gradient(180deg, #22c55e, #16a34a);
    color: #07120a;
    border-color: #15803d;
    border-radius: 12px 6px 12px 12px; /* right bubble */
}

.msg.self .time { justify-self: end; text-align: right; }

.msg .time {
    color: var(--muted);
    font-size: 11px;
    /* quiet timestamp */
    opacity: 0.75;
}
/* enter animation for new messages */
.msg.new { animation: fadeSlideIn 320ms ease-out both; }
@keyframes fadeSlideIn {
  0% { opacity: 0; transform: translateY(6px); }
  100% { opacity: 1; transform: translateY(0); }
}

.composer {
    margin-top: 12px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--panel);
    position: relative;
}

.composer-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px;
    border-bottom: 1px solid var(--border);
}

.me {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--muted);
}

.nickname {
    color: var(--accent-2);
    font-weight: 600;
}

.ghost {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: 8px;
    padding: 6px 10px;
    cursor: pointer;
}

.ghost:hover {
    border-color: #334155;
}

.input-row {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 8px;
    padding: 10px;
}

#messageInput {
    width: 100%;
    padding: 12px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: #0b1220;
    color: var(--text);
    transition: box-shadow 160ms ease, border-color 160ms ease;
}
#messageInput:focus {
    outline: none;
    border-color: #334155;
    box-shadow: 0 0 0 3px rgba(96,165,250,0.25);
}

.send {
    background: linear-gradient(180deg, #22c55e, #16a34a);
    border: none;
    border-radius: 8px;
    color: #07120a;
    font-weight: 700;
    padding: 10px 16px;
    cursor: pointer;
    box-shadow: 0 6px 14px rgba(34,197,94,0.25), inset 0 -1px 0 rgba(255,255,255,0.3);
}
.send:disabled { opacity: 0.6; cursor: not-allowed; }
.send:active { transform: translateY(1px); }

.send:hover {
    filter: brightness(0.95);
}

.emoji-panel { position: absolute; left: 10px; right: 10px; bottom: 130px; z-index: 5; background: #0b1220; border: 1px solid var(--border); border-radius: 10px; padding: 0; transform-origin: bottom; transform: scaleY(0); opacity: 0; pointer-events: none; box-shadow: 0 8px 24px rgba(0,0,0,0.35); transition: transform 0.16s ease, opacity 0.16s ease; }
.emoji-panel.open { transform: scaleY(1); opacity: 1; pointer-events: auto; }
.emoji-panel .ep-header { display: flex; align-items: center; justify-content: space-between; padding: 8px 10px; border-bottom: 1px solid var(--border); }
.emoji-panel .ep-actions { display: flex; gap: 6px; }
.ep-btn { background: transparent; border: 1px solid var(--border); color: var(--text); border-radius: 6px; padding: 4px 8px; font-size: 12px; cursor: pointer; }
.ep-btn:hover { border-color: #334155; }
/* Beautified close button */
.ep-close { background: #0b1220; border-color: #334155; color: var(--text); border-radius: 999px; padding: 4px 12px; box-shadow: inset 0 -1px 0 rgba(255,255,255,0.06); }
.ep-close:hover { border-color: var(--accent-2); color: var(--accent-2); }
.emoji-panel .ep-body { height: 250px; overflow-y: auto; padding: 8px 10px; display: grid; grid-template-columns: repeat(auto-fill, minmax(32px, 1fr)); gap: 6px; }
.emoji { font-size: 22px; line-height: 32px; text-align: center; cursor: pointer; border-radius: 6px; transition: background 120ms ease, transform 120ms ease; }
.emoji:hover { background: #0e1626; transform: scale(1.06); }
.footer {
    text-align: center;
    color: var(--muted);
    font-size: 12px;
    padding: 18px;
}

/* 自定义昵称对话框样式 - 适配深色主题 */
.nickname-dialog-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
    backdrop-filter: blur(4px);
}

.nickname-dialog-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

.nickname-dialog {
    background: var(--panel);
    border-radius: 12px;
    box-shadow: var(--shadow);
    width: 90%;
    max-width: 400px;
    transform: translateY(-20px);
    transition: transform 0.2s ease;
    overflow: hidden;
    border: 1px solid var(--border);
}

.nickname-dialog-overlay.active .nickname-dialog {
    transform: translateY(0);
    animation: dialogSlideIn 0.3s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

@keyframes dialogSlideIn {
    from {
        opacity: 0;
        transform: translateY(30px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.nickname-dialog-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    text-align: center;
    background: linear-gradient(180deg, #111827, #0f172a);
}

.nickname-dialog-title {
    font-size: 18px;
    font-weight: 600;
    color: var(--text);
}

.nickname-dialog-body {
    padding: 20px;
}

.nickname-dialog-input {
    width: 100%;
    padding: 14px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 16px;
    margin-bottom: 16px;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
    background: #0b1220;
    color: var(--text);
}

.nickname-dialog-input:focus {
    outline: none;
    border-color: var(--accent-2);
    box-shadow: 0 0 0 3px rgba(96, 165, 250, 0.15);
}

.nickname-dialog-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
}

.nickname-dialog-button {
    padding: 10px 20px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    border: none;
}

.nickname-dialog-button.cancel {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text);
}

.nickname-dialog-button.cancel:hover {
    border-color: var(--text);
    background: rgba(229, 231, 235, 0.05);
}

.nickname-dialog-button.confirm {
    background: var(--accent-2);
    color: white;
    box-shadow: 0 4px 12px rgba(96, 165, 250, 0.3);
}

.nickname-dialog-button.confirm:hover:not(:disabled) {
    filter: brightness(1.1);
    transform: translateY(-1px);
    box-shadow: 0 6px 16px rgba(96, 165, 250, 0.4);
}

.nickname-dialog-button.confirm:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.nickname-dialog-hint {
    font-size: 12px;
    color: var(--muted);
    text-align: center;
    margin-bottom: 12px;
}

/* 响应式调整 */
@media (max-width: 640px) {
    .nickname-dialog {
        width: 95%;
        margin: 10px;
    }
    
    .nickname-dialog-button {
        padding: 8px 16px;
        flex: 1;
    }
    
    .nickname-dialog-actions {
        flex-direction: column-reverse;
    }
}

/* 自定义右键菜单样式 */
.custom-context-menu {
    position: fixed;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: var(--shadow);
    padding: 4px 0;
    min-width: 150px;
    z-index: 9999;
    opacity: 0;
    visibility: hidden;
    transform: translate(-5px, -5px);
    transition: all 0.2s ease;
}

.custom-context-menu.open {
    opacity: 1;
    visibility: visible;
    transform: translate(0, 0);
}

.custom-context-menu-item {
    display: block;
    width: 100%;
    padding: 8px 16px;
    text-align: left;
    background: none;
    border: none;
    color: var(--text);
    font-size: 14px;
    cursor: pointer;
    transition: background-color 0.15s ease;
}

.custom-context-menu-item:hover {
    background-color: rgba(255, 255, 255, 0.08);
}

.custom-context-menu-item a {
    color: inherit;
    text-decoration: none;
    display: block;
    width: 100%;
    height: 100%;
}

/* Responsive tweaks */
@media (max-width: 640px) {
    .messages {
        height: calc(106vh - 280px);
    }

    .brand .title {
        font-size: 16px;
    }
}

/* Toast 提示组件样式 */
.toast-container {
  position: fixed;
  top: 20vh; /* 从视口顶部下移，显示在中上位置 */
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 2000;
  pointer-events: none;
}
.toast {
  min-width: 220px;
  max-width: 520px;
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow);
  padding: 10px 14px;
  font-size: 14px;
  line-height: 1.5;
  transform: translateY(-8px);
  opacity: 0;
  pointer-events: auto;
  transition: transform 0.18s ease, opacity 0.18s ease, filter 0.18s ease;
}
.toast.show {
  transform: translateY(0);
  opacity: 1;
}
.toast.hide {
  transform: translateY(-8px);
  opacity: 0;
}
.toast.info { border-color: #60a5fa; }
.toast.success { border-color: #16a34a; }
.toast.warning { border-color: #f59e0b; }
.toast.error { border-color: #ef4444; }
.toast:hover { filter: brightness(1.03); }