html, body { overscroll-behavior: none; height: 100%; overflow: hidden; touch-action: manipulation; }

* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", "Noto Sans SC", sans-serif; background: #0f0f23; color: #e0e0e0; height: 100vh; overflow: hidden; }
input:focus, button:focus { outline: none; }
::placeholder { color: #555; }
.hidden { display: none !important; }

/* ========== Auth Page ========== */
.auth-page { display: flex; justify-content: center; align-items: center; height: 100vh; background: linear-gradient(135deg, #0f0f23 0%, #1a1a3e 50%, #16213e 100%); }
.auth-box { background: #1a1a2e; border-radius: 12px; padding: 40px 30px; width: 380px; max-width: 90vw; box-shadow: 0 8px 32px rgba(0,0,0,0.4); }
.auth-title { text-align: center; font-size: 24px; margin-bottom: 24px; color: #e94560; }
.auth-tabs { display: flex; margin-bottom: 20px; border-bottom: 1px solid #333; }
.tab-btn { flex: 1; padding: 10px; background: none; border: none; color: #666; font-size: 15px; cursor: pointer; transition: all 0.2s; }
.tab-btn.active { color: #e94560; border-bottom: 2px solid #e94560; }
.auth-form { display: none; flex-direction: column; gap: 12px; }
.auth-form.active { display: flex; }
.auth-input { padding: 12px; border: 1px solid #333; border-radius: 6px; background: #0f0f23; color: #e0e0e0; font-size: 15px; transition: border 0.2s; }
.auth-input:focus { border-color: #e94560; }
.auth-btn { padding: 12px; background: #e94560; color: #fff; border: none; border-radius: 6px; font-size: 16px; cursor: pointer; transition: background 0.2s; }
.auth-btn:hover { background: #d63850; }
.auth-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.auth-error { color: #e94560; font-size: 13px; text-align: center; min-height: 20px; }

/* ========== Chat Page ========== */
.chat-page { display: flex; flex-direction: column; height: 100vh; }

/* Top Bar */
.top-bar { display: flex; justify-content: space-between; align-items: center; padding: 10px 16px; background: #1a1a2e; border-bottom: 1px solid #2a2a4a; flex-shrink: 0; }
.top-left { display: flex; align-items: center; gap: 12px; }
.app-name { font-size: 16px; font-weight: bold; color: #e94560; }
.online-count { font-size: 12px; color: #4ecca3; }
.top-right { display: flex; align-items: center; gap: 10px; }
.user-info { font-size: 13px; color: #aaa; }
.btn-logout { padding: 4px 12px; border: 1px solid #333; background: transparent; color: #888; border-radius: 4px; cursor: pointer; font-size: 12px; }
.top-right .sidebar-toggle { display: inline-block; padding: 4px 8px; background: none; border: none; color: #888; cursor: pointer; font-size: 18px; }

/* Channel Bar */
.channel-bar { background: #16213e; padding: 6px 16px; flex-shrink: 0; display: none; }
.channel-tabs { display: flex; gap: 4px; overflow-x: auto; }
.channel-tab { padding: 6px 14px; border: 1px solid transparent; background: transparent; color: #888; border-radius: 4px; cursor: pointer; font-size: 13px; white-space: nowrap; transition: all 0.2s; }
.channel-tab:hover { color: #ccc; background: #1a1a3e; }
.channel-tab.active { color: #fff; background: #e94560; border-color: #e94560; }

/* Announcement */
.announcement-bar { background: #2d1b2e; padding: 8px 16px; display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.announcement-icon { font-size: 14px; }
.announcement-text { font-size: 13px; color: #f1c40f; }

/* Main Area */
.main-area { display: flex; flex: 1; overflow: hidden; min-height: 0; }
.message-area { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.messages { flex: 1; overflow-y: auto; padding: 8px 12px; min-height: 0; }

.msg-item { margin-bottom: 6px; word-break: break-word; }
.msg-nickname { font-weight: bold; font-size: 13px; margin-right: 6px; }
.msg-nickname.admin { color: #e94560; }
.msg-content { font-size: 14px; }
.msg-time { font-size: 11px; color: #555; margin-left: 6px; }
.msg-system { color: #4ecca3; font-size: 13px; text-align: center; padding: 4px 0; }
.msg-announcement { color: #f1c40f; font-size: 13px; text-align: center; padding: 8px; background: #2d1b2e; border-radius: 4px; margin: 4px 0; }
.msg-mention { background: #3d1b4e; padding: 2px 4px; border-radius: 3px; }

/* Sidebar */
.sidebar { width: 220px; background: #1a1a2e; border-left: 1px solid #2a2a4a; display: flex; flex-direction: column; flex-shrink: 0; transition: margin-right 0.3s; }
.sidebar.hidden { margin-right: -220px; }
.sidebar-header { padding: 12px 16px; font-size: 13px; color: #888; border-bottom: 1px solid #2a2a4a; display: flex; justify-content: space-between; align-items: center; }
.sidebar-close { padding: 4px 8px; background: none; border: none; color: #888; cursor: pointer; font-size: 16px; display: none; }
.user-list { flex: 1; overflow-y: auto; padding: 8px 0; }
.user-item { padding: 6px 16px; font-size: 13px; color: #ccc; cursor: pointer; }
.user-item:hover { background: #2a2a4a; }
.user-item .online-dot { display: inline-block; width: 6px; height: 6px; background: #4ecca3; border-radius: 50%; margin-right: 6px; }

/* Input Area */
.input-area { display: flex; align-items: center; padding: 8px 16px; background: #1a1a2e; border-top: 1px solid #2a2a4a; gap: 6px; flex-shrink: 0; }
.btn-emoji { width: 32px; height: 32px; border: none; background: transparent; font-size: 18px; cursor: pointer; border-radius: 4px; flex-shrink: 0; }
.btn-emoji:hover { background: #2a2a4a; }
.input-wrapper { flex: 1; position: relative; }
.msg-input { width: 100%; padding: 8px 10px; border: 1px solid #333; border-radius: 4px; background: #0f0f23; color: #e0e0e0; font-size: 14px; }
.msg-input:focus { border-color: #e94560; }
.btn-send { padding: 8px 16px; background: #e94560; color: #fff; border: none; border-radius: 4px; font-size: 13px; cursor: pointer; flex-shrink: 0; }
.btn-send:disabled { opacity: 0.5; cursor: not-allowed; }

/* Mention Dropdown */
.mention-dropdown { position: absolute; bottom: 100%; left: 0; right: 0; background: #1a1a2e; border: 1px solid #333; border-radius: 6px; max-height: 150px; overflow-y: auto; z-index: 100; }
.mention-item { padding: 6px 10px; font-size: 12px; cursor: pointer; }
.mention-item:hover { background: #2a2a4a; }

/* Emoji Panel */
.emoji-panel { position: fixed; bottom: 52px; left: 16px; background: #1a1a2e; border: 1px solid #333; border-radius: 8px; width: 280px; max-width: 90vw; z-index: 200; box-shadow: 0 4px 20px rgba(0,0,0,0.5); }
.emoji-categories { display: flex; padding: 6px; gap: 2px; border-bottom: 1px solid #2a2a4a; }
.emoji-cat { padding: 2px 6px; border: none; background: transparent; font-size: 16px; cursor: pointer; border-radius: 4px; }
.emoji-cat:hover { background: #2a2a4a; }
.emoji-cat.active { background: #2a2a4a; }
.emoji-grid { display: grid; grid-template-columns: repeat(8, 1fr); padding: 6px; gap: 2px; max-height: 160px; overflow-y: auto; }
.emoji-item { padding: 4px; font-size: 20px; text-align: center; cursor: pointer; border-radius: 4px; }
.emoji-item:hover { background: #2a2a4a; }

/* ========== Game Panel ========== */
.game-panel { background: #16213e; flex: 1; min-height: 0; display: flex; flex-direction: column; overflow: hidden; }
.gp-divider { height: 2px; background: #2a2a4a; flex-shrink: 0; }
.gp-tabs { display: flex; gap: 2px; padding: 2px 12px 0; overflow-x: auto; flex-shrink: 0; }
.gp-tab { padding: 2px 8px; border: none; background: transparent; color: #888; font-size: 11px; cursor: pointer; border-radius: 3px 3px 0 0; white-space: nowrap; }
.gp-tab:hover { color: #ccc; background: #1a1a3e; }
.gp-tab.active { color: #fff; background: #0f3460; }
.gp-buttons { display: flex; flex-wrap: wrap; align-content: flex-start; gap: 4px; padding: 6px 12px; flex: 2 2 40%; min-height: 0; overflow-y: auto; }
.gp-btn { padding: 3px 8px; border: 1px solid #333; background: #0f0f23; color: #bbb; border-radius: 4px; cursor: pointer; font-size: 12px; line-height: 1.5; white-space: nowrap; }
.gp-btn:hover { background: #1a1a3e; border-color: #4ecca3; }
.gp-btn:active { transform: scale(0.96); }
.gp-btn .icon { font-size: 13px; margin-right: 2px; }
.gp-btn.done { background: #0d2d1a; border-color: #4ecca3; color: #4ecca3; cursor: default; }
.gp-btn.done .hint { font-size: 10px; }
.gp-btn.locked { opacity: 0.4; cursor: not-allowed; }
.gp-log { overflow-y: auto; flex: 3 3 60%; min-height: 0; }
.gp-log-header { padding: 2px 12px; font-size: 10px; color: #666; border-top: 1px solid #2a2a4a; flex-shrink: 0; }
.gp-log-content { padding: 2px 12px 4px; font-size: 11px; }
.gp-log-item { padding: 0; color: #f39c12; line-height: 1.3; }

/* Sidebar Overlay (mobile) */
.sidebar-overlay { position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,0.5); z-index: 50; }

/* ========== Plugin Popup ========== */
.popup-overlay { position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,0.6); z-index: 300; }
.plugin-popup { position: fixed; top: 50%; left: 50%; transform: translate(-50%,-50%); width: 380px; max-width: 92vw; max-height: 80vh; background: #1a1a2e; border: 1px solid #2a2a4a; border-radius: 10px; z-index: 301; display: flex; flex-direction: column; box-shadow: 0 8px 32px rgba(0,0,0,0.5); }
.popup-header { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; border-bottom: 1px solid #2a2a4a; flex-shrink: 0; }
.popup-title { font-size: 15px; font-weight: bold; color: #e94560; }
.popup-close { background: none; border: none; color: #888; font-size: 18px; cursor: pointer; padding: 4px; }
.popup-body { padding: 12px 16px; overflow-y: auto; flex: 1; min-height: 0; font-size: 13px; display: flex; flex-direction: column; gap: 6px; overscroll-behavior: contain; }
.popup-loading { color: #666; text-align: center; padding: 20px; }
.popup-section { flex-shrink: 0; }
.popup-section:last-child { flex-shrink: 1; min-height: 0; }
.popup-section-title { font-size: 12px; color: #888; margin-bottom: 4px; font-weight: bold; }
.popup-stats { display: flex; flex-wrap: wrap; gap: 6px; }
.popup-stat { background: #0f0f23; border: 1px solid #1a1a3e; border-radius: 6px; padding: 8px 12px; flex: 1; min-width: 80px; text-align: center; }
.popup-stat-value { font-size: 18px; font-weight: bold; color: #4ecca3; }
.popup-stat-label { font-size: 10px; color: #666; margin-top: 2px; }
.popup-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.popup-btn { padding: 8px 14px; border: 1px solid #333; background: #0f0f23; color: #ccc; border-radius: 5px; cursor: pointer; font-size: 13px; flex: 1; min-width: 80px; }
.popup-btn:hover { background: #1a1a3e; border-color: #4ecca3; }
.popup-btn.primary { background: #e94560; border-color: #e94560; color: #fff; }
.popup-btn.primary:hover { background: #d63850; }
.popup-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.popup-btn .hint { font-size: 10px; opacity: 0.7; display: block; }
.popup-progress { background: #0f0f23; border-radius: 4px; padding: 8px 12px; }
.popup-progress-bar { height: 8px; background: #2a2a4a; border-radius: 4px; overflow: hidden; margin: 4px 0; }
.popup-progress-fill { height: 100%; background: linear-gradient(90deg, #4ecca3, #e94560); border-radius: 4px; transition: width 0.3s; }
.popup-progress-labels { display: flex; justify-content: space-between; font-size: 10px; color: #666; }
.popup-log { background: #0f0f23; border: 1px solid #1a1a3e; border-radius: 6px; padding: 8px; max-height: 120px; overflow-y: auto; font-size: 12px; line-height: 1.5; }
.popup-log-item { color: #f39c12; padding: 1px 0; border-bottom: 1px solid #1a1a3e; white-space: pre-wrap; word-break: break-all; }
.popup-log-item:last-child { border-bottom: none; }
.popup-list { background: #0f0f23; border: 1px solid #1a1a3e; border-radius: 6px; max-height: 150px; overflow-y: auto; }
.popup-list-item { padding: 6px 10px; border-bottom: 1px solid #1a1a3e; font-size: 12px; color: #ccc; display: flex; justify-content: space-between; }
.popup-list-item:last-child { border-bottom: none; }
.popup-list-item .rank { color: #e94560; font-weight: bold; margin-right: 6px; }
.popup-list-item .highlight { color: #4ecca3; }
.popup-empty { color: #666; text-align: center; padding: 10px; font-size: 12px; }

/* ========== Mobile <768px ========== */
@media (max-width: 767px) {
  .sidebar { display: none; position: fixed; top: 0; right: 0; bottom: 0; width: 260px; z-index: 100; border-left: none; box-shadow: -4px 0 20px rgba(0,0,0,0.5); }
  .sidebar.open { display: flex; }
  .sidebar-header { display: flex; justify-content: space-between; align-items: center; }
  .sidebar-close { padding: 4px 8px; background: none; border: none; color: #888; cursor: pointer; font-size: 16px; display: block; }
  .top-right .sidebar-toggle { display: inline-block; padding: 4px 8px; background: none; border: none; color: #888; cursor: pointer; font-size: 18px; }
  .emoji-panel { left: 8px; width: calc(100vw - 16px); }
  .channel-bar { display: block; overflow-x: auto; }
  .msg-input { font-size: 16px; }
  .game-panel { max-height: 35vh; }
  .plugin-popup { width: 94vw; max-height: 85vh; }
  .popup-body { font-size: 12px; padding: 10px 12px; }
  .popup-stat-value { font-size: 16px; }
}

@media (min-width: 768px) {
  .channel-bar { display: block; }
}
