/* ═══════════════════════════════════════════
   VARIABLES
═══════════════════════════════════════════ */
@import url('https://fonts.googleapis.com/css2?family=Press+Start+2P&family=Onest:wght@300;400;500;600;700&display=swap');

:root,
[data-theme="dark"] {
  --bg:          #0a0a12;
  --surface:     #0f0f1a;
  --surface2:    #141422;
  --surface3:    #1a1a2e;
  --border:      #1e1e36;
  --border-hi:   #2a2a48;
  --accent:      #5c6bf2;
  --accent-dim:  rgba(92,107,242,0.12);
  --accent-glow: rgba(92,107,242,0.35);
  --text:        #d4d4f0;
  --text2:       #6868a0;
  --muted:       #3a3a60;
  --own-bg:      rgba(92,107,242,0.10);
  --own-border:  #2a2e6a;
  --own-name:    #7a87f5;
  --px:          rgba(0,0,0,0.8);
  --px-ac:       rgba(92,107,242,0.45);
  --green:       #20d4a0;
  --green-dim:   rgba(32,212,160,0.08);
  --green-bd:    #1a4a3c;
  --red:         #f25c6b;
  --red-dim:     rgba(242,92,107,0.10);
  --red-bd:      #4a1e24;
  --toggle-bg:   #141422;
  --toggle-fg:   #6868a0;
}
.login-art {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 76px;
  height: 76px;
  display: flex; align-items: center; justify-content: center;
  pointer-events: none;
  opacity: 0.95;
}
.login-art img {
  width: 100%; height: 100%; display: block;
}

@media (max-width: 640px) {
  .login-art { width: 56px; height: 56px; top: 10px; right: 10px; opacity: 0.9; }
}

[data-theme="light"] {
  --bg:          #e8e8f4;
  --surface:     #f2f2ff;
  --surface2:    #e6e6f6;
  --surface3:    #dadaee;
  --border:      #c4c4dc;
  --border-hi:   #aaaace;
  --accent:      #4a59e6;
  --accent-dim:  rgba(74,89,230,0.10);
  --accent-glow: rgba(74,89,230,0.30);
  --text:        #14142a;
  --text2:       #5858a0;
  --muted:       #9090c0;
  --own-bg:      rgba(74,89,230,0.07);
  --own-border:  #b0b8f0;
  --own-name:    #4a59e6;
  --px:          rgba(80,80,140,0.30);
  --px-ac:       rgba(74,89,230,0.40);
  --green:       #0da878;
  --green-dim:   rgba(13,168,120,0.08);
  --green-bd:    #8ad4bc;
  --red:         #d63040;
  --red-dim:     rgba(214,48,64,0.08);
  --red-bd:      #f0a0a8;
  --toggle-bg:   #e0e0f4;
  --toggle-fg:   #5858a0;
}

/* ═══════════════════════════════════════════
   RESET & BASE
═══════════════════════════════════════════ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Onest', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  overflow: hidden;
  transition: background 0.2s, color 0.2s;
}

.hidden { display: none !important; }

/* dot grid */
.bg-grid {
  position: fixed; inset: 0; z-index: 0; pointer-events: none;
  background-image: radial-gradient(circle, var(--border) 1px, transparent 1px);
  background-size: 20px 20px;
  opacity: 0.7;
}
.bg-glow { display: none; }
#app { position: relative; z-index: 1; }

/* ═══════════════════════════════════════════
   THEME TOGGLE
═══════════════════════════════════════════ */
#theme-toggle {
  position: fixed; top: 14px; right: 14px; z-index: 300;
  width: 34px; height: 34px;
  border: 2px solid var(--border-hi);
  background: var(--toggle-bg);
  color: var(--toggle-fg);
  font-size: 0.82rem;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 2px 2px 0 var(--px);
  transition: background 0.12s, color 0.12s;
}
#theme-toggle:hover  { background: var(--accent-dim); border-color: var(--accent); color: var(--accent); }
#theme-toggle:active { transform: translate(2px,2px); box-shadow: none; }

/* ═══════════════════════════════════════════
   LOGIN SCREEN
═══════════════════════════════════════════ */
#login-screen {
  min-height: 100vh;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: 20px 16px;
  animation: fadeUp 0.28s ease both;
}
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: none; }
}

/* online badge */
#online-badge {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 6px 14px;
  background: var(--green-dim);
  border: 2px solid var(--green-bd);
  font-size: 0.72rem; font-weight: 500; color: var(--green);
  margin-bottom: 20px;
  box-shadow: 2px 2px 0 var(--px);
}
.badge-pulse {
  width: 6px; height: 6px;
  background: var(--green); flex-shrink: 0;
}
.badge-sep  { width: 2px; height: 12px; background: var(--green-bd); }
.badge-label { color: var(--green); opacity: 0.6; font-size: 0.67rem; }

/* card */
.login-card {
  width: 100%; max-width: 400px;
  background: var(--surface);
  border: 2px solid var(--border-hi);
  box-shadow: 4px 4px 0 var(--px), 6px 6px 0 var(--accent-dim);
  position: relative;
}
.card-shimmer {
  height: 3px;
  background: repeating-linear-gradient(90deg, var(--accent) 0,var(--accent) 6px, transparent 6px, transparent 12px);
  opacity: 0.5;
}
.login-body { padding: 28px 24px 30px; }

.login-icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 40px; height: 40px;
  background: var(--accent-dim); border: 2px solid var(--border-hi);
  color: var(--accent); margin-bottom: 16px;
  box-shadow: 2px 2px 0 var(--px);
}
.login-heading {
  font-family: 'Press Start 2P', monospace;
  font-size: 0.82rem; line-height: 1.8; color: var(--text); margin-bottom: 6px;
}
.login-heading em { font-style: normal; color: var(--accent); }
.login-sub { font-size: 0.77rem; color: var(--text2); margin-bottom: 20px; line-height: 1.6; }

/* auth tabs */
.auth-tabs {
  display: flex;
  border: 2px solid var(--border-hi);
  margin-bottom: 14px;
  box-shadow: 2px 2px 0 var(--px);
}
.auth-tab {
  flex: 1; height: 36px; border: none; background: none;
  color: var(--text2);
  font-family: 'Onest', sans-serif; font-size: 0.8rem; font-weight: 600;
  cursor: pointer;
  transition: background 0.1s, color 0.1s;
  border-right: 2px solid var(--border-hi);
}
.auth-tab:last-child { border-right: none; }
.auth-tab.active { background: var(--accent); color: #fff; }
.auth-tab:not(.active):hover { background: var(--surface2); color: var(--text); }

.tab-panel { animation: tabIn 0.14s ease both; }
@keyframes tabIn { from{opacity:0;transform:translateY(3px)} to{opacity:1;transform:none} }

/* error */
.auth-error {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  background: var(--red-dim);
  border: 2px solid var(--red-bd);
  color: var(--red);
  font-size: 0.78rem;
  margin-bottom: 12px;
  box-shadow: 2px 2px 0 var(--px);
  
  animation: 
    px-shake 0.28s steps(2) both,
    error-out 0.3s ease forwards 2.75s;
}
@keyframes error-out {
  from {
    opacity: 1;
    transform: translateY(0);
  }
  to {
    opacity: 0;
    transform: translateY(-8px);
    margin-bottom: -40px;
  }
}
@keyframes px-shake {
  0%{transform:translateX(0)} 25%{transform:translateX(-4px)}
  75%{transform:translateX(4px)} 100%{transform:translateX(0)}
}
.auth-error svg { flex-shrink: 0; }

/* fields */
.form-fields { display: flex; flex-direction: column; gap: 11px; margin-bottom: 14px; }
.field-group  { display: flex; flex-direction: column; gap: 5px; }
.field-label  {
  font-size: 0.63rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.1em;
  color: var(--text2);
}
.field-wrap {
  display: flex; align-items: center;
  background: var(--surface2); border: 2px solid var(--border);
  padding: 0 12px; height: 44px;
  transition: border-color 0.1s, box-shadow 0.1s;
}
.field-wrap:focus-within { border-color: var(--accent); box-shadow: 2px 2px 0 var(--px-ac); }
.field-input {
  flex: 1; background: none; border: none; outline: none;
  color: var(--text); font-family: 'Onest', sans-serif; font-size: 0.9rem;
}
.field-input::placeholder { color: var(--muted); }
.field-eye {
  background: none; border: none; padding: 0 2px; margin-left: 6px;
  cursor: pointer; color: var(--muted);
  display: flex; align-items: center; flex-shrink: 0;
  transition: color 0.1s;
}
.field-eye:hover { color: var(--text2); }

/* buttons */
.btn-join {
  width: 100%; height: 46px;
  background: var(--accent); border: 2px solid var(--accent); color: #fff;
  font-family: 'Onest', sans-serif; font-size: 0.88rem; font-weight: 700;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center; gap: 10px;
  letter-spacing: 0.04em;
  transition: transform 0.07s, box-shadow 0.07s;
  box-shadow: 3px 3px 0 var(--px);
}
.btn-join:hover  { box-shadow: 4px 4px 0 var(--px-ac); transform: translate(-1px,-1px); }
.btn-join:active { transform: translate(3px,3px); box-shadow: none; }
.btn-arrow { transition: transform 0.12s; }
.btn-join:hover .btn-arrow { transform: translateX(3px); }

/* ═══════════════════════════════════════════
   CHAT SCREEN
═══════════════════════════════════════════ */
#chat-screen {
  display: flex; flex-direction: row;
  height: 100vh; max-width: 777px; margin: 0 auto;
  background: var(--surface);
  border-left: 2px solid var(--border-hi);
  border-right: 2px solid var(--border-hi);
  animation: fadeUp 0.22s ease both;
  overflow: hidden;
}

/* ── Sidebar ── */
#sidebar {
  width: 220px; flex-shrink: 0;
  display: flex; flex-direction: column;
  background: var(--surface2);
  border-right: 2px solid var(--border-hi);
  overflow: hidden; position: relative;
  transition: transform 0.22s ease, box-shadow 0.22s ease;
  z-index: 10;
}
#sidebar::after {
  content: '';
  position: absolute; right: 0; top: 0; bottom: 0; width: 2px;
  background: repeating-linear-gradient(180deg, var(--accent) 0,var(--accent) 3px, transparent 3px, transparent 9px);
  opacity: 0.1; pointer-events: none;
}

.sidebar-top {
  padding: 13px 12px;
  border-bottom: 2px solid var(--border-hi);
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; flex-shrink: 0;
}
.sidebar-logo { display: flex; align-items: center; gap: 7px; }
.sidebar-logo em {
  font-family: 'Press Start 2P', monospace;
  font-style: normal; font-size: 0.55rem; color: var(--accent); line-height: 1.5;
}

#online-badge-chat {
  display: flex; align-items: center; gap: 5px;
  padding: 3px 8px;
  background: var(--green-dim); border: 2px solid var(--green-bd);
  font-size: 0.66rem; color: var(--green); font-weight: 600;
  white-space: nowrap; box-shadow: 1px 1px 0 var(--px);
}
#online-count-chat { font-variant-numeric: tabular-nums; }
.badge-label-chat  { font-weight: 400; opacity: 0.6; font-size: 0.62rem; }

.sidebar-section-title {
  padding: 11px 13px 5px;
  font-size: 0.58rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.12em;
  color: var(--muted); flex-shrink: 0;
}

#rooms-list {
  flex: 1; list-style: none; overflow-y: auto;
  padding: 0 6px;
  scrollbar-width: thin; scrollbar-color: var(--border-hi) transparent;
}

.room-item {
  display: flex; align-items: center; gap: 8px;
  padding: 9px 10px; cursor: pointer; margin-bottom: 2px;
  border: 2px solid transparent; position: relative; overflow: hidden;
  transition: background 0.1s, border-color 0.1s;
  animation: fadeUp 0.2s ease both; opacity: 0;
}
.room-item:hover { background: var(--surface3); border-color: var(--border); }
.room-item.active { background: var(--accent-dim); border-color: var(--accent); box-shadow: inset 2px 0 0 var(--accent); }
.room-item .ripple-el {
  position: absolute; width: 60px; height: 60px;
  background: var(--accent); opacity: 0; transform: scale(0);
  pointer-events: none;
  animation: ripple-anim 0.3s ease-out forwards;
  margin-left: -30px; margin-top: -30px;
}
@keyframes ripple-anim { from{transform:scale(0);opacity:0.15} to{transform:scale(3);opacity:0} }

.room-icon  { font-size: 0.9rem; flex-shrink: 0; line-height: 1; }
.room-name  {
  flex: 1; font-size: 0.82rem; font-weight: 500; color: var(--text2);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.room-item.active .room-name         { color: var(--accent); font-weight: 600; }
.room-item:hover:not(.active) .room-name { color: var(--text); }
.room-count { font-size: 0.64rem; color: var(--muted); font-variant-numeric: tabular-nums; flex-shrink: 0; }

.unread-badge {
  min-width: 17px; height: 17px; padding: 0 4px;
  background: var(--accent); color: #fff;
  font-size: 0.6rem; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  font-variant-numeric: tabular-nums; flex-shrink: 0;
  animation: badge-pop 0.15s steps(2) both;
}
@keyframes badge-pop { from{transform:scale(0)} to{transform:scale(1)} }

/* sidebar bottom */
.sidebar-bottom {
  padding: 8px 6px;
  border-top: 2px solid var(--border-hi);
  display: flex; flex-direction: column; gap: 5px; flex-shrink: 0;
}

#create-room-btn {
  display: flex; align-items: center; gap: 7px;
  width: 100%; padding: 8px 10px;
  border: 2px dashed var(--border-hi); background: none;
  color: var(--text2);
  font-family: 'Onest', sans-serif; font-size: 0.77rem; font-weight: 500;
  cursor: pointer; transition: background 0.1s, border-color 0.1s, color 0.1s;
}
#create-room-btn:hover { background: var(--accent-dim); border-color: var(--accent); color: var(--accent); }

/* user panel */
.sidebar-user {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 8px;
  background: var(--surface3); border: 2px solid var(--border);
  font-size: 0.78rem; font-weight: 500; color: var(--text2);
  overflow: hidden;
}
.sidebar-user .user-avatar {
  width: 24px; height: 24px;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.67rem; font-weight: 700; color: #fff; flex-shrink: 0;
}
.sidebar-user .user-name {
  flex: 1; white-space: nowrap; overflow: hidden;
  text-overflow: ellipsis; color: var(--text);
}

/* logout button */
.logout-btn {
  display: flex; align-items: center; justify-content: center;
  width: 26px; height: 26px; flex-shrink: 0;
  background: var(--surface2);
  border: 2px solid var(--border-hi);
  color: var(--text2);
  cursor: pointer;
  box-shadow: 1px 1px 0 var(--px);
  transition: background 0.1s, border-color 0.1s, color 0.1s, box-shadow 0.07s;
}
.logout-btn:hover  { background: var(--red-dim); border-color: var(--red-bd); color: var(--red); }
.logout-btn:active { transform: translate(1px,1px); box-shadow: none; }

/* ── Chat Main ── */
.chat-main { flex: 1; display: flex; flex-direction: column; overflow: hidden; min-width: 0; }

/* header */
#chat-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px; height: 52px;
  background: var(--surface); border-bottom: 2px solid var(--border-hi);
  flex-shrink: 0; position: relative;
}
#chat-header::after {
  content: '';
  position: absolute; bottom: -4px; left: 0; right: 0; height: 2px;
  background: repeating-linear-gradient(90deg, var(--accent) 0,var(--accent) 4px, transparent 4px, transparent 8px);
  opacity: 0.2;
}

.header-left { display: flex; align-items: center; gap: 10px; }

/* hamburger — mobile only */
#sidebar-toggle {
  display: none;
  align-items: center; justify-content: center;
  width: 32px; height: 32px;
  background: none; border: 2px solid var(--border-hi);
  color: var(--text2); cursor: pointer; flex-shrink: 0;
  transition: background 0.1s, color 0.1s;
}
#sidebar-toggle:hover { background: var(--accent-dim); color: var(--accent); }

.header-room-info { display: flex; flex-direction: column; gap: 2px; }
.header-room-name {
  font-family: 'Press Start 2P', monospace;
  font-size: 0.56rem; color: var(--text); line-height: 1.5;
}
.header-username { font-size: 0.7rem; color: var(--text2); }

.header-status-wrap {
  width: 28px; height: 28px;
  border: 2px solid var(--border-hi); background: var(--surface2);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; box-shadow: 1px 1px 0 var(--px);
}
.header-status-wrap.connected { border-color: var(--green-bd); background: var(--green-dim); }
.status-dot {
  width: 8px; height: 8px;
  background: var(--muted); transition: background 0.2s;
}
.status-dot.online { background: var(--green); }

/* messages */
#messages {
  flex: 1;
  padding: 10px 12px;
  display: flex; flex-direction: column; gap: 7px;
  overflow-y: auto; overflow-x: clip;
  scrollbar-width: thin; scrollbar-color: transparent transparent;
  transition: scrollbar-color 0.2s;
}
#messages:hover {
  scrollbar-color: var(--border-hi) transparent;
}
#messages::before {
  content: ''; flex: 1;
}
.message {
  max-width: min(72%, 600px); padding: 6px 10px;
  background: var(--surface2); border: 2px solid var(--border);
  align-self: flex-start;
  animation: msgIn 0.12s ease both;
  box-shadow: 2px 2px 0 var(--px);
  position: relative;
  margin-top: 7px;
}
.message:first-child { margin-top: 0; }
@keyframes msgIn { from{opacity:0;transform:translateY(4px)} to{opacity:1;transform:none} }
.message.own    { align-self: flex-end; background: var(--own-bg); border-color: var(--own-border); box-shadow: -2px 2px 0 var(--px); }
.message.system { align-self: center; background: none; border: none; box-shadow: none; font-size: 0.7rem; color: var(--muted); font-style: italic; padding: 2px 0; max-width: 100%; }
.typing-indicator { background: var(--surface2); border: 2px solid var(--border); color: var(--text2); font-size: 0.8rem; font-style: italic; box-shadow: 2px 2px 0 var(--px); }

.msg-header { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin-bottom: 3px; }
.msg-user  { font-size: 0.61rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.07em; color: var(--accent); flex-shrink: 0; }
.message.own .msg-user { color: var(--own-name); }
.msg-time  { font-size: 0.6rem; color: var(--muted); white-space: nowrap; flex-shrink: 0; }
.msg-text  { display: block; font-size: 0.88rem; line-height: 1.45; color: var(--text); word-break: break-word; }

.dots span { animation: blink 0.9s steps(1) infinite; opacity: 0; }
.dots span:nth-child(2) { animation-delay: 0.3s; }
.dots span:nth-child(3) { animation-delay: 0.6s; }
@keyframes blink { 0%,49%{opacity:0} 50%,100%{opacity:1} }

#messages.fade-out { animation: msgFadeOut 0.1s ease forwards; }
@keyframes msgFadeOut { to{opacity:0;transform:translateY(-3px)} }

/* online count pop animation */
@keyframes onlinePop {
  0%   { transform: scale(1);    opacity: 1; }
  40%  { transform: scale(1.22); opacity: 1; }
  70%  { transform: scale(0.95); opacity: 0.85; }
  100% { transform: scale(1);    opacity: 1; }
}
#online-badge.pop,
#online-badge-chat.pop {
  animation: onlinePop 0.55s cubic-bezier(0.36, 0.07, 0.19, 0.97) both;
}

/* input */
#input-area {
  display: flex; padding: 11px 13px; gap: 8px;
  background: var(--surface); border-top: 2px solid var(--border-hi); flex-shrink: 0;
}
#message-input {
  flex: 1; height: 42px;
  background: var(--surface2); border: 2px solid var(--border);
  padding: 0 13px; color: var(--text);
  font-family: 'Onest', sans-serif; font-size: 0.9rem; outline: none;
  transition: border-color 0.1s, box-shadow 0.1s;
}
#message-input:focus { border-color: var(--accent); box-shadow: 2px 2px 0 var(--px-ac); }
#message-input::placeholder { color: var(--muted); }

#send-btn {
  width: 42px; height: 42px;
  background: var(--accent); border: 2px solid var(--accent);
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  color: #fff; flex-shrink: 0;
  transition: transform 0.07s, box-shadow 0.07s;
  box-shadow: 2px 2px 0 var(--px);
}
#send-btn:hover  { box-shadow: 3px 3px 0 var(--px-ac); transform: translate(-1px,-1px); }
#send-btn:active { transform: translate(2px,2px); box-shadow: none; }

/* ═══════════════════════════════════════════
   MODAL
═══════════════════════════════════════════ */
.modal { position: fixed; inset: 0; z-index: 300; display: flex; align-items: center; justify-content: center; padding: 20px; }
.modal.hidden { display: none !important; }
.modal-overlay { position: absolute; inset: 0; background: rgba(10,10,18,0.85); animation: fadeIn 0.14s ease both; }
@keyframes fadeIn { from{opacity:0} to{opacity:1} }

.modal-card {
  position: relative; width: 100%; max-width: 350px;
  background: var(--surface); border: 2px solid var(--border-hi);
  box-shadow: 6px 6px 0 var(--px), 8px 8px 0 var(--accent-dim);
  animation: modalIn 0.18s ease both; z-index: 1;
}
@keyframes modalIn { from{opacity:0;transform:scale(0.94) translateY(8px)} to{opacity:1;transform:none} }

.modal-shimmer {
  height: 3px;
  background: repeating-linear-gradient(90deg, var(--accent) 0,var(--accent) 5px, transparent 5px, transparent 10px);
  opacity: 0.55;
}
.modal-title { font-family: 'Press Start 2P', monospace; font-size: 0.62rem; color: var(--text); padding: 20px 22px 6px; line-height: 1.8; }
.modal-sub   { font-size: 0.77rem; color: var(--text2); padding: 0 22px 15px; line-height: 1.5; }
.modal-fields  { display: flex; flex-direction: column; gap: 10px; padding: 0 22px 17px; }
.modal-actions { display: flex; gap: 8px; padding: 0 22px 22px; }

.btn-modal-cancel {
  flex: 1; height: 40px;
  background: var(--surface2); border: 2px solid var(--border-hi);
  color: var(--text2);
  font-family: 'Onest', sans-serif; font-size: 0.82rem; font-weight: 600;
  cursor: pointer; box-shadow: 2px 2px 0 var(--px);
  transition: background 0.1s, color 0.1s;
}
.btn-modal-cancel:hover  { background: var(--surface3); color: var(--text); }
.btn-modal-cancel:active { transform: translate(2px,2px); box-shadow: none; }

.btn-modal-confirm {
  flex: 1; height: 40px;
  background: var(--accent); border: 2px solid var(--accent); color: #fff;
  font-family: 'Onest', sans-serif; font-size: 0.82rem; font-weight: 700;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center; gap: 7px;
  box-shadow: 2px 2px 0 var(--px); letter-spacing: 0.02em;
  transition: transform 0.07s, box-shadow 0.07s;
}
.btn-modal-confirm:hover  { box-shadow: 3px 3px 0 var(--px-ac); transform: translate(-1px,-1px); }
.btn-modal-confirm:active { transform: translate(2px,2px); box-shadow: none; }
.btn-modal-confirm:hover .btn-arrow { transform: translateX(3px); }

/* ═══════════════════════════════════════════
   MEDIUM SCREENS (640–860px)
═══════════════════════════════════════════ */
@media (max-width: 860px) {
  .message { max-width: 60%; }
}

/* ═══════════════════════════════════════════
   MOBILE — sidebar overlay + layout
═══════════════════════════════════════════ */
@media (max-width: 640px) {
  body { overflow: hidden; }

  #theme-toggle { top: 10px; right: 10px; width: 30px; height: 30px; font-size: 0.75rem; }

  /* login */
  #login-screen { padding: 16px 12px; justify-content: flex-start; padding-top: 60px; }
  .login-body   { padding: 22px 18px 24px; }
  .login-heading { font-size: 0.72rem; }

  /* sidebar becomes overlay */
  #sidebar {
    position: fixed; top: 0; left: 0; bottom: 0;
    width: 260px;
    transform: translateX(-100%);
    transition: transform 0.26s cubic-bezier(0.4, 0, 0.2, 1),
                box-shadow 0.26s ease;
    box-shadow: none;
    z-index: 100;
  }
  #sidebar.open {
    transform: translateX(0);
    box-shadow: 4px 0 0 var(--px), 6px 0 30px rgba(0,0,0,0.5);
  }

  /* backdrop when sidebar open */
  #sidebar-backdrop {
    display: none;
    position: fixed; inset: 0; z-index: 99;
    background: rgba(10,10,18,0.6);
  }
  #sidebar-backdrop.visible { display: block; }

  /* show hamburger */
  #sidebar-toggle { display: flex; }

  /* chat takes full width */
  #chat-screen { border-left: none; border-right: none; }

  .message { max-width: 75%; }

  /* bigger tap targets */
  .room-item  { padding: 11px 10px; }
  #send-btn   { width: 44px; height: 44px; }
  #message-input { height: 44px; font-size: 1rem; }

  .field-wrap  { height: 48px; }
  .field-input { font-size: 1rem; }
  .btn-join    { height: 50px; font-size: 0.92rem; }
}

/* ═══════════════════════════════════════════
   REPLY BAR (above input)
═══════════════════════════════════════════ */
.reply-bar {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px;
  background: var(--accent-dim);
  border-top: 2px solid var(--accent);
  border-bottom: 1px solid var(--border);
  font-size: 0.8rem; color: var(--text2);
  animation: tabIn 0.12s ease both;
  flex-shrink: 0;
  min-height: 52px;
}
.reply-bar svg { color: var(--accent); flex-shrink: 0; }
#reply-preview {
  flex: 1; overflow: hidden;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  color: var(--text2); line-height: 1.4;
}
#reply-preview strong { color: var(--accent); font-weight: 600; }
#cancel-reply {
  background: none; border: none; cursor: pointer;
  color: var(--muted); font-size: 1.1rem; padding: 4px 7px;
  line-height: 1; transition: color 0.1s;
  flex-shrink: 0;
}
#cancel-reply:hover { color: var(--red); }

/* ═══════════════════════════════════════════
   REPLY QUOTE (inside message bubble)
═══════════════════════════════════════════ */
.reply-quote {
  border-left: 3px solid var(--accent);
  padding: 4px 8px;
  margin-bottom: 5px;
  background: var(--accent-dim);
  font-size: 0.75rem;
  color: var(--text2);
  line-height: 1.45;
  cursor: pointer;
  transition: background 0.1s;
  word-break: break-word;
}
.reply-quote:hover { background: rgba(92,107,242,0.18); }
.reply-quote-user { font-weight: 700; color: var(--accent); margin-bottom: 1px; }

/* ═══════════════════════════════════════════
   MESSAGE ACTIONS (Persona-style, side popup)
═══════════════════════════════════════════ */
.msg-actions {
  position: absolute;
  top: 2px;
  /* shift left by gap so the padding bridges the gap to the bubble */
  left: calc(100% + 6px);
  display: flex;
  flex-direction: column;
  gap: 5px;
  z-index: 10;
  opacity: 0;
  pointer-events: none;
  transform: translateX(-14px) rotate(-8deg);
  transform-origin: top left;
  transition: opacity 0.18s ease, transform 0.22s cubic-bezier(0.34, 1.5, 0.64, 1);
  /* left padding fills the gap — cursor won't drop hover traveling from bubble to buttons */
  padding-left: 10px;
  margin-left: -10px;
}
.message.own .msg-actions {
  left: auto;
  right: calc(100% + 6px);
  transform-origin: top right;
  transform: translateX(14px) rotate(8deg);
  padding-left: 0;
  margin-left: 0;
  padding-right: 10px;
  margin-right: -10px;
}

/* shown via hover (desktop) or .actions-visible class (mobile tap) */
.message:hover .msg-actions,
.message.actions-visible .msg-actions {
  opacity: 1;
  pointer-events: auto;
  transform: translateX(0) rotate(-6deg);
}
.message.own:hover .msg-actions,
.message.own.actions-visible .msg-actions {
  transform: translateX(0) rotate(6deg);
}
.msg-action-btn {
  border: 2px solid;
  cursor: pointer; padding: 4px 10px;
  font-size: 0.68rem; font-weight: 700;
  line-height: 1; white-space: nowrap;
  letter-spacing: 0.04em;
  transition: transform 0.08s, box-shadow 0.08s;
}
.msg-action-btn:active { transform: translate(2px, 2px) !important; box-shadow: none !important; }
.msg-reply-btn {
  background: #0d2a1a;
  border-color: #20d46a;
  color: #20d46a;
  box-shadow: 3px 3px 0 #0033cc;
}
.msg-reply-btn:hover { transform: translate(-1px, -1px); box-shadow: 4px 4px 0 #0033cc; }
.msg-react-btn {
  background: #2a1600;
  border-color: #f29020;
  color: #f29020;
  box-shadow: 3px 3px 0 #0033cc;
}
.msg-react-btn:hover { transform: translate(-1px, -1px); box-shadow: 4px 4px 0 #0033cc; }

/* on touch devices show/hide via tap (.actions-visible), hide :hover */
@media (hover: none) {
  .message:hover .msg-actions { opacity: 0; pointer-events: none;
    transform: translateX(-14px) rotate(-8deg); }
  .message.own:hover .msg-actions { transform: translateX(14px) rotate(8deg); }

  /* на мобиле — кнопки снизу, горизонтально, не вылезают за экран */
  .msg-actions {
    position: absolute;
    top: auto;
    bottom: calc(100% + 6px);
    left: 0;
    right: auto;
    flex-direction: row;
    gap: 6px;
    transform: translateY(8px);
    transform-origin: bottom left;
    padding-left: 0;
    margin-left: 0;
    padding-right: 0;
    margin-right: 0;
  }
  .message.own .msg-actions {
    left: auto;
    right: 0;
    transform: translateY(8px);
    transform-origin: bottom right;
    padding-right: 0;
    margin-right: 0;
  }
  .message.actions-visible .msg-actions {
    opacity: 1;
    pointer-events: auto;
    transform: translateY(0) rotate(0deg);
  }
  .message.own.actions-visible .msg-actions {
    transform: translateY(0) rotate(0deg);
  }
}

/* ═══════════════════════════════════════════
   REACTIONS (below message text)
═══════════════════════════════════════════ */
.reactions {
  display: flex; flex-wrap: wrap; gap: 4px;
  margin-top: 5px;
  padding-top: 5px;
  border-top: 1px solid var(--border);
}
.reaction-pill {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 8px;
  background: var(--surface3);
  border: 1.5px solid var(--border-hi);
  font-size: 0.85rem;
  line-height: 1;
  cursor: pointer;
  transition: background 0.1s, border-color 0.1s, transform 0.08s, box-shadow 0.08s;
  user-select: none;
  box-shadow: 1px 1px 0 var(--px);
}
.reaction-pill:hover {
  background: var(--accent-dim);
  border-color: var(--accent);
  transform: translateY(-1px);
  box-shadow: 1px 2px 0 var(--px-ac);
}
.reaction-pill:active { transform: translateY(1px); box-shadow: none; }
.reaction-pill.mine {
  background: var(--accent-dim);
  border-color: var(--accent);
  box-shadow: 1px 1px 0 var(--px-ac);
}
.reaction-pill.mine .reaction-emoji { filter: none; }
.reaction-count {
  font-size: 0.73rem;
  font-weight: 600;
  color: var(--text2);
  min-width: 10px;
}
.reaction-pill.mine .reaction-count { color: var(--accent); }

/* ═══════════════════════════════════════════
   EMOJI PICKER MODAL (centered overlay)
═══════════════════════════════════════════ */
.emoji-modal {
  position: fixed; inset: 0; z-index: 400;
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  overflow-x: hidden;
}
.emoji-modal.hidden { display: none !important; }
.emoji-modal-overlay {
  position: absolute; inset: 0;
  background: rgba(10,10,18,0.75);
  animation: fadeIn 0.12s ease both;
}
.emoji-modal-card {
  position: relative; z-index: 1;
  width: 100%; max-width: 400px;
  background: var(--surface);
  border: 2px solid var(--border-hi);
  box-shadow: 6px 6px 0 var(--px), 8px 8px 0 var(--accent-dim);
  padding: 14px;
  animation: modalIn 0.16s ease both;
  display: flex; flex-direction: column; gap: 10px;
}
.emoji-modal-header {
  display: flex; align-items: center; justify-content: space-between;
}
.emoji-modal-title {
  font-size: 0.75rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.07em; color: var(--accent);
}
.emoji-modal-close {
  background: none; border: none; cursor: pointer;
  color: var(--muted); font-size: 0.85rem; padding: 2px 5px;
  transition: color 0.1s;
}
.emoji-modal-close:hover { color: var(--red); }
.emoji-modal-tabs {
  display: flex; flex-wrap: wrap; gap: 4px;
}
.emoji-tab-btn {
  background: var(--surface2); border: 1px solid var(--border);
  cursor: pointer; padding: 3px 8px;
  font-size: 0.68rem; color: var(--text2);
  transition: background 0.1s, color 0.1s, border-color 0.1s;
  white-space: nowrap;
}
.emoji-tab-btn:hover { background: var(--accent-dim); color: var(--accent); border-color: var(--accent); }
.emoji-tab-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.emoji-modal-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, 34px);
  gap: 2px;
  max-height: 260px;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: thin; 
  scrollbar-color: var(--border-hi) transparent;
  flex-shrink: 0;
  contain: layout; 
}

.emoji-grid-btn {
  background: none; border: none;
  font-size: 1.25rem; line-height: 1;
  padding: 5px;
  cursor: pointer;
  transition: background 0.1s, transform 0.1s;
  text-align: center;
  width: 34px;
  height: 34px;
  box-sizing: border-box;
  overflow: hidden;
}
.emoji-grid-btn:hover { 
  background: var(--accent-dim); 
  transform: rotateX(30deg);
  box-shadow: inset 0 0 0 2px var(--accent);
}

/* emoji modal на мобиле — снизу экрана как шторка */
@media (hover: none) and (max-width: 600px) {
  .emoji-modal {
    align-items: flex-end;
    padding: 0;
  }
  .emoji-modal-card {
    max-width: 100%;
    border-radius: 0;
    border-left: none;
    border-right: none;
    border-bottom: none;
    box-shadow: 0 -4px 0 var(--px);
    padding: 12px 12px 24px;
    animation: modalSlideUp 0.22s cubic-bezier(0.34, 1.2, 0.64, 1) both;
  }
  .emoji-modal-grid {
    grid-template-columns: repeat(auto-fill, 40px);
    max-height: 220px;
  }
  .emoji-grid-btn {
    width: 40px;
    height: 40px;
    font-size: 1.4rem;
  }
}
@keyframes modalSlideUp {
  from { transform: translateY(100%); }
  to   { transform: translateY(0); }
}

.room-delete-btn {
  display: none;
  margin-left: auto;
  background: none;
  border: none;
  cursor: pointer;
  opacity: 0.4;
  padding: 2px 4px;
  border-radius: 4px;
  color: currentColor;
  flex-shrink: 0;
}
.room-item:hover .room-delete-btn {
  display: flex;
  align-items: center;
}
.room-delete-btn:hover {
  opacity: 1;
  background: rgba(220, 38, 38, 0.15);
}

.rainbow-wave {
  background: linear-gradient(
    90deg,
    hsl(0,100%,55%),
    hsl(60,100%,50%),
    hsl(120,100%,45%),
    hsl(200,100%,55%),
    hsl(270,100%,60%),
    hsl(360,100%,55%)
  );
  background-size: 300% auto;
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  animation: rainbow-flow 2s linear infinite, wave 1.4s ease-in-out infinite;
  display: inline-block;
  will-change: background-position, transform;
}

@keyframes rainbow-flow {
  to { background-position: 300% center; }
}

@keyframes wave {
  0%, 100% { transform: translateY(0); }
  50%       { transform: translateY(-4px); }
}

input:-webkit-autofill,
input:-webkit-autofill:hover,
input:-webkit-autofill:focus {
  -webkit-text-fill-color: var(--text);
  -webkit-box-shadow: 0 0 0px 1000px var(--color-input-bg) inset;
  transition: background-color 5000s ease-in-out 0s;
}

.field-group--disabled {
  opacity: 0.4;
  pointer-events: none;
  transition: opacity 0.3s;
}

.field-hint--success {
  display: block;
  font-size: 12px;
  color: var(--accent);
  margin-top: 4px;
}

.send-code-btn {
	display: flex;
	align-items: center;
	justify-content: center;

	width: 32px;
	height: 32px;

	border: 2px solid rgba(0, 0, 0, 0.7);
	border-radius: 6px; 

	transition: all 0.2s ease;
}

.send-code-btn:hover {
	border-color: rgba(0, 0, 0, 1);
}

[data-theme="dark"] .send-code-btn {
	border-color: rgba(255, 255, 255, 0.7);
}

[data-theme="dark"] .send-code-btn:hover {
	border-color: rgba(255, 255, 255, 1);
}

.send-code-icon {
	display: flex;
	align-items: center;
	justify-content: center;
	transition: transform 0.2s ease;
}

.send-code-btn:hover .send-code-icon {
	transform: scale(1.25);
}

.send-code-btn.sent {
	border-color: #4ade80;
	color: #4ade80;
}

