/* Modern Anonymous Chatroom Styles */
:root {
    --bg: #f8fafc;
    --panel: #ffffff;
    --muted: #64748b;
    --text: #1e293b;
    --accent: #22c55e;
    --accent-2: #60a5fa;
    --border: #e2e8f0;
    /* UI polish */
    --shadow: 0 10px 30px rgba(0,0,0,0.1);
}

* {
    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;
    overflow: hidden;
}

.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: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 100;
    background: #ffffff;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
    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;
}

.brand .subtitle {
    color: var(--muted);
    font-size: 12px;
    margin-top: 5px;
}

.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: #2bb85f;
    color: #ffffff;
    padding: 4px 8px;
    border-radius: 999px;
    font-size: 12px;
}

.chat {
    max-width: 900px;
    margin: 80px auto 0;
    padding: 0px;
}

.messages {
    height: calc(100vh - 250px);
    overflow-y: auto;
    border: 0px solid var(--border);
    border-radius: 0px;
    padding: 2px;
    background: #ffffff;
    /* softer panel and custom scrollbar */
    box-shadow: var(--shadow);
}
.messages::-webkit-scrollbar { width: 2px; }
.messages::-webkit-scrollbar-track { background: #f1f1f1; border-radius: 3px; }
.messages::-webkit-scrollbar-thumb { background: #cccccc; border-radius: 3px; border: none; }
.messages:hover::-webkit-scrollbar-thumb { background: #999999; }
.messages .system {
    color: var(--muted);
    text-align: center;
    margin:0px 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; }
/* Reduce bottom margin for self messages */
.msg.self { margin-bottom: 4px; }

.msg .avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: linear-gradient(135deg, #e2e8f0, #f1f5f9);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
}

.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: -1px; }

.msg .content {
    position: relative;
    line-height: 1.6;
    word-break: break-word;
    font-size: 15px;
    background: #ffffff;
    border: 1px solid var(--border);
    border-radius: 12px 12px 12px 6px; /* left bubble */
    padding: 10px 12px;
    box-shadow: 0 1px 1px rgba(172, 172, 172, 0.1);
    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: #2bb85f;
    color: #07120a;
    border-color: transparent;
    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: 1px;
    border: 0px solid var(--border);
    border-radius: 0px;
    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: #ffffff;
    color: var(--text);
    transition: box-shadow 160ms ease, border-color 160ms ease;
}
#messageInput:focus {
    outline: none;
    border-color: #334155;
}

.send {
    background: linear-gradient(180deg, #58a9ff, #58a9ff);
    border: none;
    border-radius: 8px;
    color: #ffffff;
    font-weight: 700;
    padding: 10px 16px;
    cursor: pointer;
}
.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: 120px; z-index: 5; background: #ffffff; border: 1px solid var(--border); border-radius: 10px; padding: 0; transform-origin: bottom; transform: scaleY(0); opacity: 0; pointer-events: none; box-shadow: 0 0px 2px rgba(0,0,0,0.2); 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: #ffffff; 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.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
}

.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;
}

.nickname-dialog-overlay.active .nickname-dialog {
    transform: translateY(0);
}

.nickname-dialog-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    text-align: center;
}

.nickname-dialog-title {
    font-size: 18px;
    font-weight: 600;
    color: var(--text);
}

.nickname-dialog-body {
    padding: 20px;
}

.nickname-dialog-input {
    width: 100%;
    padding: 12px;
    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;
}

.nickname-dialog-input:focus {
    outline: none;
    border-color: var(--accent-2);
    box-shadow: 0 0 0 3px rgba(96, 165, 250, 0.1);
}

.nickname-dialog-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
}

.nickname-dialog-button {
    padding: 8px 16px;
    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: #334155;
    background: rgba(51, 65, 85, 0.05);
}

.nickname-dialog-button.confirm {
    background: var(--accent-2);
    color: white;
}

.nickname-dialog-button.confirm:hover {
    filter: brightness(0.9);
}

.nickname-dialog-button.confirm:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.nickname-dialog-hint {
    font-size: 12px;
    color: var(--muted);
    text-align: center;
    margin-bottom: 12px;
}

/* Responsive tweaks */
@media (max-width: 640px) {
    .messages {
        height: calc(114vh - 280px);
    }

    .brand .title {
        font-size: 16px;
    }
}