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

:root {
    --mibbit-green: #006400;
    --mibbit-dark: #004d00;
    --mibbit-light: #008000;
    --chat-bg: #ffffff;
    --user-bg: #f0f0f0;
    --header-height: 35px;
    --userlist-width: 180px;
    --chat-font-family: 'Inter', Arial, sans-serif;
    --chat-font-size: 15px;
    --chat-line-height: 1.5;
}

.chat-messages, .user-list {
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: var(--mibbit-green) #ccc;
}
.chat-messages::-webkit-scrollbar, .user-list::-webkit-scrollbar {
    width: 6px;
    height: 6px;
    display: block;
}
.chat-messages::-webkit-scrollbar-track, .user-list::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 3px;
}
.chat-messages::-webkit-scrollbar-thumb, .user-list::-webkit-scrollbar-thumb {
    background: var(--mibbit-green);
    border-radius: 3px;
}
* {
    scrollbar-width: none;
    -ms-overflow-style: none;
}
*::-webkit-scrollbar {
    display: none;
    width: 0;
    height: 0;
}
.userlist-wrapper {
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: var(--mibbit-green) #ccc;
}
.userlist-wrapper::-webkit-scrollbar {
    display: block;
    width: 8px;
    height: 8px;
}
.userlist-wrapper::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}
.userlist-wrapper::-webkit-scrollbar-thumb {
    background: var(--mibbit-green);
    border-radius: 4px;
}
.emoji-picker {
    scrollbar-width: thin;
    scrollbar-color: var(--mibbit-green) #ddd;
}
.emoji-picker::-webkit-scrollbar {
    width: 6px;
    display: block;
}

html, body {
    height: 100%;
    width: 100%;
    overflow: hidden;
    font-family: var(--chat-font-family);
    font-size: var(--chat-font-size);
}

body {
    background: var(--mibbit-green);
    display: flex;
    flex-direction: column;
}

.login-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--mibbit-green);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}
.login-screen.hidden { display: none; }
.login-box { text-align: center; padding: 40px; background: rgba(0,0,0,0.2); border-radius: 12px; min-width: 320px; }
.login-title { color: white; font-size: 24px; font-weight: bold; margin-bottom: 10px; text-shadow: 2px 2px 4px rgba(0,0,0,0.3); }
.login-subtitle { color: white; font-size: 18px; margin-bottom: 20px; }
.login-input { padding: 10px 20px; font-size: 16px; border: 2px solid #fff; border-radius: 5px; width: 250px; text-align: center; margin-bottom: 12px; outline: none; background: white; font-family: inherit; }
.login-row { display: flex; gap: 8px; justify-content: center; align-items: center; margin-bottom: 12px; }
.password-toggle { background: rgba(255,255,255,0.8); border: none; padding: 8px 12px; border-radius: 5px; cursor: pointer; font-size: 14px; }
.enter-btn { background: linear-gradient(135deg, #ff6b6b, #ee5a24); color: white; border: none; padding: 12px 30px; font-size: 18px; font-weight: bold; border-radius: 25px; cursor: pointer; text-transform: uppercase; letter-spacing: 2px; box-shadow: 0 4px 15px rgba(0,0,0,0.3); margin-top: 10px; }

.chat-container {
    display: none;
    flex: 1;
    flex-direction: column;
    height: 100vh;
    width: 100vw;
    overflow: hidden;
}
.chat-container.active { display: flex; }

/* Top bar without menu icon */
.top-bar {
    display: flex;
    align-items: center;
    background: var(--mibbit-green);
    border-bottom: 2px solid var(--mibbit-dark);
    flex-shrink: 0;
}
.header {
    flex: 1;
    color: white;
    padding: 5px 10px;
    display: flex;
    align-items: center;
    gap: 5px;
    overflow-x: auto;
    overflow-y: hidden;
    white-space: nowrap;
    font-size: 13px;
    font-weight: bold;
    font-family: inherit;
}
.tab {
    background: rgba(255,255,255,0.2);
    padding: 5px 12px;
    border-radius: 3px 3px 0 0;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    user-select: none;
    border: 1px solid transparent;
    height: 28px;
}
.tab.active { background: var(--chat-bg); color: var(--mibbit-green); border-color: var(--mibbit-dark); }
.tab-close { font-size: 14px; margin-left: 3px; cursor: pointer; padding: 0 4px; }
.tab-close:hover { color: red; }
.tab-unread {
    background: #ffcccc !important;
    color: #000 !important;
    font-weight: bold;
}

.main-content {
    display: flex;
    flex: 1;
    overflow: hidden;
    min-height: 0;
}

.chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--chat-bg);
    min-width: 0;
    height: 100%;
    overflow: hidden;
}
.chat-messages {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 10px 10px 10px 4px;
    font-size: var(--chat-font-size);
    line-height: var(--chat-line-height);
    font-family: var(--chat-font-family);
}
.message {
    margin-bottom: 8px;
    word-wrap: break-word;
    word-break: break-word;
    font-family: var(--chat-font-family);
    font-size: var(--chat-font-size);
    line-height: var(--chat-line-height);
}
.message .timestamp {
    color: #666;
    font-size: 11px;
    font-family: inherit;
}
.message .nickname {
    font-weight: bold;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 2px;
    font-family: inherit;
    border-radius: 3px;
    padding: 0 2px;
}
.message .nickname:hover { text-decoration: underline; }
.rank-icon {
    font-size: 12px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-family: inherit;
    margin-right: -2px;
}
.rank-icon img {
    width: 14px;
    height: 14px;
    vertical-align: middle;
}
.nick-arrow {
    margin-left: 0;
    margin-right: 0;
    font-weight: normal;
}
/* Highlight for mentioned own nickname */
.mention {
    background-color: #87CEEB;
    color: white;
    font-weight: bold;
    border-radius: 3px;
    padding: 0 3px;
    display: inline-block;
}

.action-message {
    background: #eef3fc;
    border-left: 4px solid #1976d2;
    border-radius: 8px;
    padding: 6px 12px;
    margin: 6px 0;
    display: inline-block;
    max-width: 95%;
    width: auto;
    clear: both;
    box-shadow: 0 1px 2px rgba(0,0,0,0.03);
    font-family: var(--chat-font-family);
    font-size: var(--chat-font-size);
}
.action-message .nickname {
    font-weight: 600;
    margin-right: 4px;
    display: inline-flex;
    align-items: center;
    gap: 2px;
    border-radius: 3px;
    padding: 0 2px;
}

.input-wrapper {
    background: var(--mibbit-green);
    padding: 5px;
    flex-shrink: 0;
    border-top: 2px solid var(--mibbit-dark);
}
.format-toolbar { display: flex; gap: 5px; align-items: center; padding: 0 5px 5px 5px; flex-wrap: wrap; }
.format-btn { background: rgba(255,255,255,0.9); border: 1px solid #ccc; padding: 4px 10px; cursor: pointer; border-radius: 3px; font-weight: bold; font-size: 12px; min-width: 28px; font-family: inherit; }
.format-btn.active { background: #ffeb3b; border-color: #ffc107; }
.toggle-btn { background: rgba(255,255,255,0.8); border: 1px solid #999; padding: 3px 8px; cursor: pointer; border-radius: 3px; font-size: 11px; }
.toggle-btn.active { background: #90ee90; }
.input-row { display: flex; gap: 5px; margin-top: 5px; }
.chat-input { flex: 1; padding: 8px 10px; border: 1px solid #ccc; border-radius: 3px; font-size: 14px; outline: none; background: white; transition: all 0.1s ease; font-family: var(--chat-font-family); }
.send-btn { background: var(--mibbit-light); color: white; border: none; padding: 8px 20px; cursor: pointer; border-radius: 3px; font-weight: bold; font-family: inherit; }

.userlist-wrapper {
    width: var(--userlist-width);
    display: flex;
    flex-direction: column;
    background: var(--user-bg);
    border-left: 2px solid var(--mibbit-green);
    height: 100%;
    flex-shrink: 0;
    overflow-y: auto;
}
.userlist-section {
    border-bottom: 1px solid #ccc;
}
.section-header {
    background: var(--mibbit-green);
    color: white;
    padding: 4px 8px;
    font-size: 11px;
    font-weight: bold;
    cursor: pointer;
    user-select: none;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-family: inherit;
}
.section-header:hover { background: var(--mibbit-dark); }
.section-header .toggle-icon { font-size: 12px; }
.section-content {
    overflow: visible;
}
.section-content.collapsed {
    display: none;
}
.user-list {
    padding: 3px;
}
.user-item {
    padding: 4px 3px;
    cursor: pointer;
    font-size: 12px;
    display: flex;
    align-items: center;
    gap: 4px;
    border-radius: 3px;
    transition: background 0.2s;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-family: var(--chat-font-family);
}
.user-item:hover { background: rgba(0,100,0,0.15); }
.user-item.selected { background: rgba(0,100,0,0.25); }
.user-rank {
    font-size: 12px;
    width: 18px;
    text-align: center;
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.user-rank img {
    width: 14px;
    height: 14px;
}
.user-nick { flex: 1; overflow: hidden; text-overflow: ellipsis; }

.rank-owner { color: #ff6600; }
.rank-superadmin { color: #dc143c; }
.rank-admin { color: #006400; }
.rank-rj { color: #006400; }
.rank-vip { color: #006400; }
.rank-normal { color: #666; }

.pm-view .userlist-wrapper { display: none; }

.picker-overlay {
    position: fixed;
    bottom: 85px;
    left: 10px;
    background: white;
    border: 2px solid var(--mibbit-green);
    border-radius: 5px;
    padding: 10px;
    display: none;
    box-shadow: 0 -4px 15px rgba(0,0,0,0.3);
    z-index: 200;
    max-width: 320px;
    max-height: 250px;
    overflow-y: auto;
}
.picker-overlay.show { display: grid; }
.emoji-picker { grid-template-columns: repeat(8, 1fr); gap: 5px; overflow-y: auto; max-height: 250px; }
.color-picker { grid-template-columns: repeat(4, 1fr); gap: 5px; }
.emoji-item { cursor: pointer; font-size: 20px; padding: 5px; text-align: center; border-radius: 3px; }
.emoji-item:hover { background: #f0f0f0; transform: scale(1.1); }
.color-item { width: 35px; height: 35px; cursor: pointer; border: 2px solid #ccc; border-radius: 3px; }
.picker-header { grid-column: 1 / -1; display: flex; justify-content: space-between; align-items: center; margin-bottom: 5px; padding-bottom: 5px; border-bottom: 1px solid #ccc; font-weight: bold; color: var(--mibbit-green); position: sticky; top: 0; background: white; z-index: 1; }

.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.6);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 2000;
}
.modal-overlay.show { display: flex; }
.modal-box {
    background: white;
    border-radius: 8px;
    min-width: 300px;
    max-width: 500px;
    max-height: 80vh;
    overflow: hidden;
    box-shadow: 0 10px 40px rgba(0,0,0,0.3);
    font-family: var(--chat-font-family);
}
.modal-header { background: var(--mibbit-green); color: white; padding: 12px 15px; font-weight: bold; display: flex; justify-content: space-between; align-items: center; }
.modal-close { cursor: pointer; font-size: 20px; }
.modal-body { padding: 15px; max-height: 60vh; overflow-y: auto; overflow-x: hidden; word-wrap: break-word; }
.modal-footer { padding: 10px 15px; background: #f5f5f5; display: flex; gap: 10px; justify-content: flex-end; }
.modal-btn { padding: 8px 16px; border: none; border-radius: 4px; cursor: pointer; font-family: inherit; }
.modal-btn.primary { background: var(--mibbit-green); color: white; }
.modal-btn.secondary { background: #ccc; }
.modal-input { width: 100%; padding: 10px; border: 1px solid #ccc; border-radius: 4px; margin-top: 10px; font-size: 14px; font-family: inherit; }

.whois-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.whois-table td { padding: 8px; border-bottom: 1px solid #eee; }
.whois-table td:first-child { font-weight: bold; color: var(--mibbit-green); width: 30%; }

.context-menu {
    position: fixed;
    background: white;
    border: 2px solid var(--mibbit-green);
    box-shadow: 3px 3px 8px rgba(0,0,0,0.3);
    z-index: 1000;
    display: none;
    min-width: 130px;
    max-width: var(--userlist-width);
    border-radius: 3px;
    font-family: var(--chat-font-family);
}
.context-header { background: var(--mibbit-green); color: white; padding: 6px 10px; font-size: 12px; font-weight: bold; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.context-menu-item { padding: 8px 12px; cursor: pointer; font-size: 12px; border-bottom: 1px solid #eee; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.context-menu-item:hover { background: #f0f8ff; }

.join, .part, .quit, .nick-change {
    display: flex;
    justify-content: flex-start;
    margin: 4px 0;
}
.join span, .part span, .quit span, .nick-change span {
    background: #eaf7ea;
    border-left: 4px solid #2e7d32;
    padding: 2px 10px;
    border-radius: 20px;
    display: inline-block;
    font-size: 11px;
    color: #2c5e2c;
    max-width: 100%;
    white-space: normal;
    word-break: break-word;
    font-family: inherit;
}
.part span, .quit span {
    background: #fff3e0;
    border-left-color: #d4a373;
    color: #8b5a2b;
}
.nick-change span {
    background: #e3f2fd;
    border-left-color: #1976d2;
    color: #0d47a1;
}

.topic {
    background: #e8f0fe;
    border: 1px solid #bdd4ff;
    border-radius: 6px;
    padding: 6px 12px;
    margin: 8px 0;
    text-align: center;
    font-size: 12px;
    color: #0b3b5f;
    font-family: inherit;
}
.topic strong {
    color: #006400;
}

.youtube-embed {
    position: fixed;
    bottom: 20px;
    right: 20px;
    background: #000;
    border-radius: 8px;
    z-index: 300;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
    transition: none;
    max-width: 320px;
    width: 230px;
    cursor: default;
}
.youtube-embed.minimized {
    width: 40px;
    height: 40px;
    background: #333;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 20px;
}
.youtube-embed.minimized .video-container, .youtube-embed.minimized .embed-header { display: none; }
.youtube-embed .embed-header {
    background: #222;
    padding: 8px 10px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-radius: 8px 8px 0 0;
    color: white;
    font-size: 12px;
    cursor: move;
    user-select: none;
    touch-action: none;
}
.youtube-embed .embed-header button {
    background: none;
    border: none;
    color: white;
    cursor: pointer;
    font-size: 16px;
    margin-left: 8px;
}
.video-container {
    position: relative;
    padding-bottom: 56.25%;
    height: 0;
    overflow: hidden;
}
.video-container iframe {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border: none;
}

.user-popup {
    position: fixed;
    background: white;
    border: 2px solid var(--mibbit-green);
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
    z-index: 1000;
    min-width: 130px;
    padding: 8px 0;
    display: none;
    font-family: var(--chat-font-family);
}
.user-popup .popup-item {
    padding: 8px 12px;
    cursor: pointer;
    font-size: 14px;
    border-bottom: 1px solid #eee;
}
.user-popup .popup-item:last-child { border-bottom: none; }
.user-popup .popup-item:hover { background: #f0f8ff; }
.user-popup .popup-item:active { background: #ddd; }

.youtube-thumb {
    display: inline-block;
    cursor: pointer;
    border: 1px solid #ccc;
    border-radius: 4px;
    overflow: hidden;
    max-width: 100px;
    margin: 2px 0;
    transition: transform 0.1s ease;
}
.youtube-thumb img { width: 100px; height: auto; display: block; }
.youtube-thumb:hover { transform: scale(1.02); }

.view-image-btn {
    background: var(--mibbit-light);
    border: none;
    color: white;
    padding: 2px 8px;
    border-radius: 12px;
    cursor: pointer;
    font-size: 11px;
    margin: 0 2px;
    display: inline-block;
    font-weight: bold;
    font-family: inherit;
}
.view-image-btn:hover {
    background: var(--mibbit-dark);
}

@media (max-width: 768px) {
    .userlist-wrapper { width: 97px; }
    .user-nick { font-size: 12px; }
    .youtube-thumb { max-width: 100px; }
    .login-box { min-width: 280px; padding: 20px; }
    .login-input { width: 200px; }
    .action-message { max-width: 90%; padding: 4px 8px; }
}