* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: 'Segoe UI', -apple-system, BlinkMacSystemFont, Roboto, sans-serif;
}

:root {
  --tg-theme-bg: rgb(33, 33, 33); /* Telegram Web A Dark background */
  --tg-theme-bg-secondary: rgb(15, 15, 15); /* Telegram Web A sidebar/header */
  --tg-theme-text: rgb(255, 255, 255);
  --tg-theme-text-secondary: rgb(170, 170, 170);
  --tg-theme-primary: rgb(135, 116, 225); /* Primary Accent */
}

body {
  min-height: 100vh;
  min-height: 100dvh; /* Dynamic viewport height for mobile browsers */
  background: #000000;
  color: var(--tg-theme-text);
  display: flex;
  justify-content: center;
  align-items: flex-start;
  overflow-x: hidden;
  overflow-y: auto;
}

.container {
  width: 100%;
  max-width: 720px;
  background-color: transparent;
  min-height: 100vh;
  min-height: 100dvh;
  position: relative;
  z-index: 10;
  display: flex;
  flex-direction: column;
  box-shadow: 0 0 40px rgba(0, 0, 0, 0.45);
  overflow: hidden;
}

.container::before {
  content: "";
  position: absolute;
  top: -10px; left: -10px; right: -10px; bottom: -10px; /* Bleed to avoid blurry edges */
  background-image: url("bg.png");
  background-size: cover;
  background-position: center;
  background-attachment: fixed;
  filter: blur(6px) brightness(0.65); /* Slight blur and darken */
  z-index: -1;
}

.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 15px 20px;
  background: var(--tg-theme-bg-secondary);
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.profile {
  display: flex;
  align-items: center;
  gap: 12px;
}

.profile img {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  object-fit: cover;
}

.name {
  font-size: 18px;
  font-weight: 600;
  color: var(--tg-theme-text);
}

.username {
  font-size: 14px;
  color: var(--tg-theme-primary);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}



.join-btn {
  background: transparent;
  color: var(--tg-theme-primary);
  padding: 8px 16px;
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  transition: .2s;
  border: none;
  text-transform: uppercase;
}

.join-btn:hover {
  background: rgba(135, 116, 225, 0.1);
  border-radius: 8px;
}

.compose {
  padding: 20px;
  font-size: 20px;
  font-weight: 600;
  color: var(--tg-theme-text);
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  display: flex;
  justify-content: center;
  align-items: center;
  position: relative;
}

.kv-warning {
  font-size: 12px;
  color: #ff4b4b;
  font-weight: bold;
  background: rgba(255, 75, 75, 0.1);
  padding: 4px 8px;
  border-radius: 6px;
  display: none;
  position: absolute;
  right: 20px;
}

.editor {
  margin: 20px;
  background: var(--tg-theme-bg-secondary);
  border-radius: 12px;
  overflow: hidden;
  flex: 1;
  display: flex;
  flex-direction: column;
}

.toolbar {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  padding: 10px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  background: var(--tg-theme-bg-secondary);
}

.tool {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  cursor: pointer;
  color: var(--tg-theme-text-secondary);
  transition: .2s;
}

.tool:hover {
  background: rgba(255, 255, 255, 0.05);
  color: var(--tg-theme-text);
}

.tool.active {
  color: var(--tg-theme-primary);
  background: rgba(135, 116, 225, 0.1);
}

.editor-box {
  min-height: 120px;
  flex: 1;
  padding: 15px;
  outline: none;
  color: var(--tg-theme-text);
  font-size: 15px;
  line-height: 1.3;
  text-align: left;
  word-break: break-word;
  overflow-wrap: break-word;
  white-space: pre-wrap;
  overflow-y: auto;
}

.editor-box:empty::before {
  content: "Message";
  color: var(--tg-theme-text-secondary);
}

/* Graphical Representation of Formatting Elements */
.editor-box code {
  font-family: 'Courier New', Courier, monospace;
  background: rgba(255, 255, 255, 0.08);
  padding: 2px 4px;
  border-radius: 4px;
  font-size: 14.5px;
  color: #e5c07b; /* Warm monospace code color */
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.editor-box blockquote {
  border-left: 3px solid var(--tg-theme-primary);
  padding: 2px 10px; /* Tighter padding */
  margin: 2px 0; /* Telegram has almost no vertical margin around quotes */
  color: var(--tg-theme-text-secondary);
  font-style: italic;
  background: rgba(135, 116, 225, 0.04);
  border-radius: 0 4px 4px 0;
  display: block;
}

/* Override default browser margin styling inside the editor to ensure consistent line-height */
.editor-box p,
.editor-box div,
.editor-box blockquote p,
.editor-box blockquote div {
  margin: 0 !important;
  padding: 0 !important;
  line-height: inherit;
}

.editor-box tg-spoiler,
.editor-box span.tg-spoiler {
  background: rgba(255, 255, 255, 0.15);
  color: transparent !important;
  filter: blur(5px);
  cursor: pointer;
  user-select: none;
  transition: filter 0.2s, color 0.2s;
  padding: 0 4px;
  border-radius: 3px;
}

.editor-box tg-spoiler:hover,
.editor-box span.tg-spoiler:hover {
  filter: blur(2px);
}

.editor-box tg-spoiler:active,
.editor-box span.tg-spoiler:active {
  filter: none;
  color: inherit !important;
  background: transparent;
  user-select: text;
}

.editor-box a {
  color: var(--tg-theme-primary);
  text-decoration: underline;
  cursor: pointer;
}

/* Monospace Preformatted Blocks styling */
.editor-box pre {
  white-space: pre-wrap;       /* CSS 3 - wraps instead of running off-screen */
  word-break: break-word;      /* Breaks long words */
  overflow-wrap: break-word;   
  background: rgba(255, 255, 255, 0.05);
  padding: 6px 10px;
  border-radius: 6px;
  margin: 2px 0;
  font-family: 'Courier New', Courier, monospace;
  font-size: 14.5px;
  color: #e5c07b;
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.editor-box pre code {
  background: transparent !important;
  padding: 0 !important;
  border: none !important;
  font-size: inherit !important;
  color: inherit !important;
}

.footer {
  padding: 15px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 20px;
  background: var(--tg-theme-bg-secondary);
}

.counter {
  color: var(--tg-theme-text-secondary);
  font-size: 14px;
}

.send-btn {
  background: var(--tg-theme-primary);
  color: white;
  border: none;
  padding: 12px 24px;
  border-radius: 8px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: .2s;
}

.send-btn:hover {
  background: rgba(135, 116, 225, 0.8);
}

@media(max-width: 768px) {
  body {
    padding: 0;
  }
  .container {
    border-radius: 0;
    box-shadow: none;
  }
  .editor {
    margin: 10px;
  }
}

/* Compact mode: Telegram mini window on PC (~380-500px wide, short height) */
@media(max-height: 600px) {
  .header {
    padding: 10px 14px;
  }
  .profile img {
    width: 40px;
    height: 40px;
  }
  .name {
    font-size: 16px;
  }
  .username {
    font-size: 13px;
  }
  .join-btn {
    padding: 6px 12px;
    font-size: 13px;
  }
  .compose {
    padding: 10px 14px;
    font-size: 17px;
  }
  .editor {
    margin: 8px;
  }
  .toolbar {
    padding: 6px;
    gap: 2px;
  }
  .tool {
    width: 32px;
    height: 32px;
  }
  .editor-box {
    min-height: 80px;
    padding: 10px;
  }
  .footer {
    padding: 10px 14px;
    gap: 12px;
  }
  .send-btn {
    padding: 10px 18px;
    font-size: 14px;
  }
  .counter {
    font-size: 13px;
  }
  .tg-emoji-keyboard {
    height: 220px;
  }
}

/* =========================================
   TELEGRAM NATIVE EMOJI KEYBOARD EXTENSION
   ========================================= */

.tg-emoji-keyboard {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 350px;
  background: var(--tg-theme-bg);
  z-index: 100;
  display: flex;
  flex-direction: column;
  box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.2);
}

.tg-keyboard-tabs {
  display: flex;
  align-items: center;
  background: var(--tg-theme-bg-secondary);
  padding: 0 5px;
  height: 48px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.tg-tabs-scroll-container {
  flex: 1;
  display: flex;
  gap: 4px;
  overflow-x: auto;
  align-items: center;
  height: 100%;
  padding-right: 10px;
  scrollbar-width: none; 
}
.tg-tabs-scroll-container::-webkit-scrollbar {
  display: none;
}

.tg-tab-btn {
  background: transparent;
  border: none;
  cursor: pointer;
  min-width: 44px;
  height: 100%;
  color: var(--tg-theme-text-secondary);
  transition: 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  font-size: 16px;
  padding: 0 10px;
}

.tg-tab-btn:hover {
  background: rgba(255, 255, 255, 0.05);
  border-radius: 8px;
}

.tg-tab-btn.active {
  color: var(--tg-theme-primary);
}

.tg-tab-btn.active::after {
  content: '';
  position: absolute;
  bottom: -1px;
  left: 15%;
  width: 70%;
  height: 3px;
  background: var(--tg-theme-primary);
  border-radius: 3px 3px 0 0;
}

.tg-close-btn {
  background: transparent;
  border: none;
  color: var(--tg-theme-text-secondary);
  font-size: 18px;
  padding: 0 15px;
  height: 100%;
  cursor: pointer;
  transition: 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.tg-close-btn:hover {
  color: var(--tg-theme-text);
}

.tg-no-packs {
  color: var(--tg-theme-text-secondary);
  font-size: 14px;
  margin-left: 10px;
}

.tg-keyboard-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 10px;
  background: var(--tg-theme-bg);
}

.tg-pack-title {
  color: var(--tg-theme-text-secondary);
  font-size: 14px;
  font-weight: 500;
  margin-bottom: 8px;
  margin-left: 6px;
  margin-top: 5px;
}

.tg-emoji-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
}

.tg-emoji-item {
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  border-radius: 8px;
  transition: background 0.15s;
}

.tg-emoji-item:active, .tg-emoji-item:hover {
  background: rgba(255, 255, 255, 0.08);
}

/* PC / Landscape compact emoji keyboard: width > height means desktop mini window */
@media(min-aspect-ratio: 1/1) {
  .tg-emoji-keyboard {
    height: 160px;
  }
  .tg-keyboard-tabs {
    height: 36px;
    padding: 0 3px;
  }
  .tg-tab-btn {
    min-width: 34px;
    font-size: 14px;
    padding: 0 6px;
  }
  .tg-keyboard-scroll {
    padding: 6px;
  }
  .tg-pack-title {
    font-size: 12px;
    margin-bottom: 4px;
    margin-top: 2px;
  }
  .tg-emoji-item {
    width: 38px;
    height: 38px;
  }
  .tg-emoji-grid {
    gap: 1px;
  }
}

/* =========================================
   CUSTOM MODAL UI
   ========================================= */

.modal-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-box {
  background: var(--tg-theme-bg);
  width: 90%;
  max-width: 320px;
  border-radius: 12px;
  padding: 20px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
  display: flex;
  flex-direction: column;
  gap: 15px;
}

.modal-title {
  color: var(--tg-theme-text);
  font-size: 18px;
  font-weight: 600;
  line-height: 1.4;
}

.modal-input {
  background: var(--tg-theme-bg-secondary);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: var(--tg-theme-text);
  padding: 12px;
  border-radius: 8px;
  font-size: 15px;
  outline: none;
  width: 100%;
  transition: border-color 0.2s;
}

.modal-input:focus {
  border-color: var(--tg-theme-primary);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 5px;
}

.modal-btn {
  background: transparent;
  border: none;
  font-size: 15px;
  font-weight: 600;
  padding: 8px 16px;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.2s;
}

.modal-cancel {
  color: var(--tg-theme-text-secondary);
}

.modal-cancel:hover {
  background: rgba(255, 255, 255, 0.05);
}

.modal-confirm {
  color: var(--tg-theme-primary);
}

.modal-confirm:hover {
  background: rgba(135, 116, 225, 0.1);
}
