/* ============================================================
   KnotCipher Ghost — style.css
   Original structure + Ghost Mode styles
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Share+Tech+Mono&family=Outfit:wght@300;400;500;600;700&display=swap');

:root {
  --bg-dark:      #0a1628;
  --bg-mid:       #0f2240;
  --accent:       #2a5298;
  --accent-light: #3d6fc9;
  --accent-glow:  rgba(42, 82, 152, 0.35);
  --gold:         #ffc107;
  --gold-dark:    #e6a800;
  --green:        #00c853;
  --red:          #f44336;
  --text-dark:    #1a1a2e;
  --text-muted:   #888;
  --border:       #e0e0e0;
  --bubble-own:   #2a5298;
  --bubble-other: #ffffff;
  --surface:      #fafafa;
  --radius:       20px;
  --shadow:       0 24px 64px rgba(0,0,0,0.35);
}

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

body {
  font-family: 'Outfit', sans-serif;
  background: linear-gradient(135deg, #0a1628 0%, #0f2240 45%, #1a3a5c 100%);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 16px;
  position: relative;
  overflow: hidden;
}

/* Subtle animated background grid */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  background-image:
    linear-gradient(rgba(42,82,152,0.07) 1px, transparent 1px),
    linear-gradient(90deg, rgba(42,82,152,0.07) 1px, transparent 1px);
  background-size: 40px 40px;
  animation: gridMove 20s linear infinite;
  pointer-events: none;
  z-index: 0;
}

@keyframes gridMove {
  0%   { background-position: 0 0; }
  100% { background-position: 40px 40px; }
}

/* ── Container ── */
.chat-container {
  background: rgba(255,255,255,0.97);
  border-radius: var(--radius);
  width: 100%;
  max-width: 900px;
  height: 88vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow), 0 0 0 1px rgba(255,255,255,0.1);
  overflow: hidden;
  position: relative;
  z-index: 1;
  animation: slideUp 0.5s cubic-bezier(0.22, 1, 0.36, 1) both;
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(30px) scale(0.98); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* ── Header ── */
.header {
  background: linear-gradient(135deg, #0f2240 0%, #1e3c72 60%, #2a5298 100%);
  color: white;
  padding: 18px 24px;
  text-align: center;
  position: relative;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}

.header::after {
  content: "";
  position: absolute;
  bottom: 0; left: 0; right: 0;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--gold), transparent);
  opacity: 0.6;
}

.header h1 {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.3px;
  margin-bottom: 3px;
}

.header p {
  font-size: 11.5px;
  opacity: 0.75;
  font-weight: 300;
  letter-spacing: 0.3px;
}

.header small {
  font-size: 10.5px;
  opacity: 0.6;
  font-family: 'Share Tech Mono', monospace;
  display: block;
  margin-top: 6px;
}

.header-meta {
  display: flex;
  justify-content: center;
  gap: 16px;
  margin-top: 8px;
}

#onlineCount {
  font-size: 10.5px;
  background: rgba(0,200,83,0.2);
  color: #69f0ae;
  padding: 2px 8px;
  border-radius: 20px;
  border: 1px solid rgba(0,200,83,0.3);
  font-family: 'Share Tech Mono', monospace;
}

/* ── Key Section ── */
.key-section {
  background: #fffbea;
  padding: 12px 16px;
  border-bottom: 2px solid #ffe082;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

.key-section .input-wrapper {
  flex: 2;
  position: relative;
  display: flex;
  align-items: center;
  min-width: 180px;
}

.key-section input {
  width: 100%;
  padding: 9px 36px 9px 12px;
  border: 1.5px solid #ffe082;
  border-radius: 8px;
  font-family: 'Share Tech Mono', monospace;
  font-size: 13px;
  background: white;
  transition: border-color 0.2s;
  outline: none;
}

.key-section input:focus {
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(255,193,7,0.15);
}

#toggleKeyVisibility {
  position: absolute;
  right: 8px;
  background: none;
  border: none;
  cursor: pointer;
  font-size: 14px;
  padding: 2px;
  opacity: 0.6;
  transition: opacity 0.2s;
}

#toggleKeyVisibility:hover { opacity: 1; }

.key-section > button {
  background: var(--gold);
  color: #333;
  border: none;
  padding: 9px 16px;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
  font-size: 13px;
  font-family: 'Outfit', sans-serif;
  transition: background 0.2s, transform 0.1s;
  white-space: nowrap;
}

.key-section > button:hover  { background: var(--gold-dark); }
.key-section > button:active { transform: scale(0.97); }

/* ── Ghost Mode Toggle ── */
.ghost-section {
  background: #1a1a2e;
  padding: 10px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  border-bottom: 1px solid #2a2a3e;
}

.mode-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: #ccc;
}

.mode-btn {
  background: #2a2a3e;
  border: none;
  padding: 6px 14px;
  border-radius: 20px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 500;
  transition: all 0.2s;
  color: #aaa;
}

.mode-btn.active {
  background: #6c63ff;
  color: white;
  box-shadow: 0 2px 8px rgba(108,99,255,0.3);
}

#ghostTimerContainer {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: #ccc;
}

#ghostTimerSelect {
  background: #2a2a3e;
  border: 1px solid #3a3a4e;
  padding: 6px 10px;
  border-radius: 8px;
  color: white;
  font-size: 12px;
}

/* ── Room Section ── */
.room-section {
  background: #e8f4fd;
  padding: 10px 16px;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
  border-bottom: 1px solid #b3d9f7;
}

.room-section input {
  flex: 2;
  padding: 9px 12px;
  border: 1.5px solid #90caf9;
  border-radius: 8px;
  font-size: 13px;
  font-family: 'Outfit', sans-serif;
  outline: none;
  min-width: 140px;
  transition: border-color 0.2s;
  background: white;
}

.room-section input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(42,82,152,0.12);
}

.room-section button {
  background: var(--accent);
  color: white;
  border: none;
  padding: 9px 16px;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
  font-size: 13px;
  font-family: 'Outfit', sans-serif;
  transition: background 0.2s, transform 0.1s;
  white-space: nowrap;
}

.room-section button:hover  { background: var(--accent-light); }
.room-section button:active { transform: scale(0.97); }

/* ── Status badges ── */
.status {
  padding: 5px 10px;
  font-size: 11px;
  font-weight: 500;
  color: white;
  border-radius: 20px;
  white-space: nowrap;
  font-family: 'Share Tech Mono', monospace;
  letter-spacing: 0.2px;
}

/* ── Typing indicator ── */
#typingIndicator {
  min-height: 18px;
  font-size: 11px;
  color: var(--text-muted);
  padding: 2px 20px 4px;
  font-style: italic;
  background: white;
  border-bottom: 1px solid #f0f0f0;
  transition: opacity 0.3s;
}

/* ── Messages Area ── */
.messages-area {
  flex: 1;
  overflow-y: auto;
  padding: 20px 20px 10px;
  background: var(--surface);
  scroll-behavior: smooth;
}

.messages-area::-webkit-scrollbar        { width: 5px; }
.messages-area::-webkit-scrollbar-track  { background: transparent; }
.messages-area::-webkit-scrollbar-thumb  { background: #ddd; border-radius: 10px; }

.empty-placeholder, .system-msg {
  text-align: center;
  color: var(--text-muted);
  padding: 30px 20px;
  font-size: 13px;
  line-height: 1.7;
}

.system-msg strong { color: var(--accent); }

/* ── Message ── */
.message {
  margin-bottom: 14px;
  display: flex;
  flex-direction: column;
  animation: fadeIn 0.25s ease both;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.message.sent     { align-items: flex-end; }
.message.received { align-items: flex-start; }

/* Ghost message special styling */
.message.ghost-message .message-bubble {
  border-left: 3px solid #ff6b6b;
}

.ghost-badge {
  font-size: 10px;
  background: rgba(255,107,107,0.2);
  padding: 2px 6px;
  border-radius: 12px;
  margin-left: 8px;
  color: #ff6b6b;
}

.msg-meta {
  margin-bottom: 2px;
  padding: 0 4px;
}

.sender-name {
  font-size: 10.5px;
  font-weight: 600;
  color: var(--accent);
  font-family: 'Share Tech Mono', monospace;
}

.message-bubble {
  max-width: 68%;
  padding: 10px 14px 8px;
  border-radius: 18px;
  word-wrap: break-word;
  position: relative;
}

.message.sent .message-bubble {
  background: var(--bubble-own);
  color: white;
  border-bottom-right-radius: 4px;
  box-shadow: 0 2px 8px rgba(42,82,152,0.3);
}

.message.received .message-bubble {
  background: var(--bubble-other);
  color: var(--text-dark);
  border: 1px solid #e8e8e8;
  border-bottom-left-radius: 4px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.06);
}

.bubble-text {
  font-size: 14px;
  line-height: 1.5;
}

.locked-msg {
  font-style: italic;
  opacity: 0.65;
  font-size: 12px;
}

.msg-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
  margin-top: 4px;
}

.msg-time {
  font-size: 10px;
  opacity: 0.55;
  font-family: 'Share Tech Mono', monospace;
}

.msg-tick {
  font-size: 10px;
  color: #69f0ae;
}

.message.sent .msg-time { color: rgba(255,255,255,0.7); }

.message-encrypted {
  font-size: 9.5px;
  color: #bbb;
  margin-top: 3px;
  font-family: 'Share Tech Mono', monospace;
  padding: 0 4px;
  letter-spacing: 0.3px;
  max-width: 68%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.message.sent .message-encrypted { text-align: right; }

/* ── Input Area ── */
.input-area {
  padding: 14px 16px;
  background: white;
  border-top: 1px solid #ebebeb;
  display: flex;
  gap: 10px;
  align-items: center;
}

.input-area input {
  flex: 1;
  padding: 11px 18px;
  border: 1.5px solid #e0e0e0;
  border-radius: 25px;
  font-size: 14px;
  font-family: 'Outfit', sans-serif;
  outline: none;
  background: #f8f8f8;
  transition: border-color 0.2s, background 0.2s;
}

.input-area input:focus {
  border-color: var(--accent);
  background: white;
  box-shadow: 0 0 0 3px rgba(42,82,152,0.10);
}

.input-area button {
  background: linear-gradient(135deg, var(--accent), var(--accent-light));
  color: white;
  border: none;
  padding: 11px 22px;
  border-radius: 25px;
  cursor: pointer;
  font-weight: 600;
  font-size: 13.5px;
  font-family: 'Outfit', sans-serif;
  transition: transform 0.15s, box-shadow 0.15s, opacity 0.15s;
  white-space: nowrap;
  box-shadow: 0 3px 12px rgba(42,82,152,0.3);
}

.input-area button:hover  {
  transform: translateY(-1px);
  box-shadow: 0 5px 16px rgba(42,82,152,0.4);
}
.input-area button:active { transform: scale(0.97); }

/* ── Info bar ── */
.info {
  padding: 7px;
  text-align: center;
  font-size: 10.5px;
  color: #aaa;
  background: #f5f5f5;
  border-top: 1px solid #ebebeb;
  letter-spacing: 0.2px;
}

/* ── Toast ── */
.toast {
  position: fixed;
  bottom: 30px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: #1a1a2e;
  color: white;
  padding: 10px 20px;
  border-radius: 25px;
  font-size: 13px;
  font-family: 'Outfit', sans-serif;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s, transform 0.3s;
  z-index: 9999;
  box-shadow: 0 8px 24px rgba(0,0,0,0.3);
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ── Responsive ── */
@media (max-width: 600px) {
  body { padding: 0; align-items: stretch; }

  .chat-container {
    border-radius: 0;
    height: 100dvh;
    max-width: 100%;
    box-shadow: none;
  }

  .key-section,
  .room-section {
    padding: 10px 12px;
    gap: 6px;
  }

  .key-section input,
  .room-section input { font-size: 12px; }

  .header h1 { font-size: 18px; }

  .message-bubble { max-width: 85%; }
  .message-encrypted { max-width: 85%; }

  .input-area { padding: 10px 12px; }
  .input-area button { padding: 11px 16px; font-size: 12.5px; }
  
  .ghost-section {
    flex-direction: column;
    align-items: stretch;
  }
  
  #ghostTimerContainer {
    justify-content: space-between;
  }
}