:root {
  --bg: #0e1621;
  --bg-elevated: #17212b;
  --bg-bubble-in: #182533;
  --bg-bubble-out: #2b5278;
  --text: #e4ecf2;
  --text-muted: #8b9bab;
  --accent: #5288c1;
  --border: #242f3d;
  --danger: #e05f5f;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
  font-family:
    Inter,
    system-ui,
    -apple-system,
    'Segoe UI',
    Roboto,
    sans-serif;
  color: var(--text);
  background: var(--bg);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  height: 100%;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  height: 100%;
  min-height: 100%;
  min-height: 100dvh;
  background: var(--bg);
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
  overscroll-behavior-y: none;
}

#root,
.app-shell {
  height: 100%;
  min-height: 100%;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.app-shell > * {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
  width: 100%;
}

button,
input {
  font: inherit;
}

img,
video {
  max-width: 100%;
  vertical-align: middle;
}

/* Home */
.home-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(24px + var(--safe-top)) 20px calc(24px + var(--safe-bottom));
  background: radial-gradient(1200px 600px at 50% -10%, #1b2d44 0%, var(--bg) 55%);
  overflow-y: auto;
  overscroll-behavior-y: contain;
}

.home-card {
  width: 100%;
  max-width: 400px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 28px 24px 32px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.35);
}

.home-title {
  margin: 0 0 8px;
  font-size: 1.5rem;
  font-weight: 700;
}

.home-sub {
  margin: 0 0 24px;
  color: var(--text-muted);
  font-size: 0.95rem;
}

.home-primary {
  width: 100%;
  padding: 14px 18px;
  border: none;
  border-radius: 12px;
  background: linear-gradient(180deg, #5a9fd4 0%, var(--accent) 100%);
  color: #fff;
  font-weight: 600;
  cursor: pointer;
  margin-bottom: 28px;
}

.home-primary:disabled {
  opacity: 0.65;
}

.home-form label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  margin-bottom: 8px;
}

.home-row {
  display: flex;
  gap: 10px;
}

.home-input {
  flex: 1;
  min-width: 0;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
}

.home-secondary {
  padding: 12px 18px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg-bubble-in);
  color: var(--text);
  font-weight: 600;
  cursor: pointer;
}

.home-err {
  margin: 16px 0 0;
  color: var(--danger);
  font-size: 0.9rem;
}

/* Chat layout */
.chat-layout {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg);
  max-width: 720px;
  margin: 0 auto;
}

.chat-header {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: calc(10px + var(--safe-top)) 12px 12px;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  z-index: 10;
}

.chat-back {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg-bubble-in);
  color: var(--text);
  font-size: 1.2rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  text-decoration: none;
}

.chat-head-main {
  flex: 1;
  min-width: 0;
}

.chat-room-title {
  font-weight: 700;
  font-size: 1rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-head-sub {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 2px;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.dot-on {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #6bcb77;
}
.dot-off {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #c9a227;
}

.chat-share {
  flex-shrink: 0;
  border: 1px solid var(--border);
  background: var(--bg-bubble-in);
  color: var(--accent);
  font-weight: 600;
  padding: 8px 14px;
  border-radius: 12px;
  cursor: pointer;
  font-size: 0.88rem;
}

.chat-banner {
  flex: 0 0 auto;
  background: rgba(224, 95, 95, 0.15);
  color: #ffb4b4;
  padding: 10px 14px;
  text-align: center;
  font-size: 0.9rem;
}

.chat-messages {
  flex: 1 1 auto;
  min-height: 0;
  min-width: 0;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
  touch-action: pan-y;
  padding-bottom: 8px;
}

.chat-typing {
  padding: 6px 16px 12px;
  font-size: 0.8rem;
  font-style: italic;
  color: var(--text-muted);
}

.chat-bottom-anchor {
  height: 1px;
}

/* Message row */
.msg-row {
  display: flex;
  justify-content: flex-start;
  margin-bottom: 10px;
  padding: 0 12px;
}
.msg-row-own {
  justify-content: flex-end;
}

.msg-wrap {
  max-width: min(85vw, 420px);
  position: relative;
  touch-action: manipulation;
}

.msg-name {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--accent);
  margin: 0 4px 4px;
}

.msg-bubble {
  position: relative;
  touch-action: manipulation;
  background: var(--bg-bubble-in);
  border-radius: 16px 16px 16px 6px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
}
.msg-bubble-own {
  background: var(--bg-bubble-out);
  border-radius: 16px 16px 6px 16px;
}

.msg-text {
  margin: 0;
  font-size: 0.95rem;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
}

.msg-media-link {
  display: block;
  border-radius: 12px;
  overflow: hidden;
  line-height: 0;
}

.msg-img {
  display: block;
  max-height: 240px;
  width: 100%;
  object-fit: cover;
}

.msg-video {
  display: block;
  width: 100%;
  max-height: 280px;
  border-radius: 12px;
  background: #000;
}

.msg-meta {
  display: flex;
  justify-content: flex-start;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
}
.msg-bubble-own .msg-meta {
  justify-content: flex-end;
}

.msg-you {
  font-size: 0.6rem;
  color: rgba(255, 255, 255, 0.65);
}
.msg-time {
  font-size: 0.65rem;
  color: var(--text-muted);
}

.msg-quick {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 6px;
}
.msg-row-own .msg-quick {
  justify-content: flex-end;
}

.msg-quick button {
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  border-radius: 999px;
  padding: 4px 8px;
  font-size: 0.85rem;
  cursor: pointer;
}

.msg-reactions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}
.msg-row-own .msg-reactions {
  justify-content: flex-end;
}

.msg-react-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  border: 1px solid var(--border);
  background: rgba(23, 33, 43, 0.95);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 0.85rem;
  cursor: pointer;
  color: var(--text);
}

.react-count {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 600;
}

/* Emoji modal */
.emoji-modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 12px;
  padding-bottom: calc(12px + var(--safe-bottom));
}
.emoji-modal-back {
  position: absolute;
  inset: 0;
  border: none;
  background: rgba(0, 0, 0, 0.55);
  cursor: pointer;
}
.emoji-panel {
  position: relative;
  z-index: 51;
  background: var(--bg-elevated);
  border-radius: 16px;
  border: 1px solid var(--border);
  padding: 12px;
  max-width: 380px;
  width: 100%;
  max-height: 45vh;
  overflow-y: auto;
}
.emoji-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.emoji-grid button {
  font-size: 1.35rem;
  padding: 6px;
  border: none;
  background: var(--bg-bubble-in);
  border-radius: 10px;
  cursor: pointer;
}

/* Composer */
.composer {
  flex: 0 0 auto;
  position: relative;
  background: var(--bg-elevated);
  border-top: 1px solid var(--border);
  padding: 10px 10px calc(10px + var(--safe-bottom));
  max-height: min(440px, 62dvh);
  overflow-y: auto;
  overscroll-behavior-y: contain;
  -webkit-overflow-scrolling: touch;
}

.composer-form {
  display: flex;
  align-items: center;
  gap: 8px;
}

.composer-input {
  flex: 1;
  min-width: 0;
  padding: 12px 14px;
  border-radius: 22px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
}

.composer-icon {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg-bubble-in);
  cursor: pointer;
  font-size: 1.1rem;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.composer-send {
  border: none;
  border-radius: 22px;
  padding: 0 18px;
  height: 42px;
  font-weight: 600;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  flex-shrink: 0;
}

.composer-send:disabled,
.composer-icon:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.hidden {
  display: none !important;
}
