:root {
  --tg-bg: #0e1621;
  --tg-panel: #17212b;
  --tg-panel-2: #111a24;
  --tg-text: #e7edf4;
  --tg-muted: #7f91a4;
  --tg-accent: #66a9e0;
  --tg-accent-2: #2b5278;
  --tg-bubble: #182533;
  --tg-bubble-self: #234056;
  --tg-border: rgba(124, 155, 188, 0.15);
  --tg-danger: #d96f6f;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: radial-gradient(circle at top, #203246 0%, var(--tg-bg) 45%, #0a1119 100%); color: var(--tg-text); font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
a { color: inherit; text-decoration: none; }
button, input, select { font: inherit; }

.tg-shell { min-height: 100vh; }
.entry-screen, .join-screen { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.entry-card, .join-card {
  width: min(100%, 520px);
  background: rgba(23, 33, 43, 0.92);
  border: 1px solid var(--tg-border);
  border-radius: 28px;
  padding: 28px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.28);
  backdrop-filter: blur(18px);
}
.entry-kicker { color: var(--tg-accent); font-size: 13px; text-transform: uppercase; letter-spacing: 0.12em; margin-bottom: 12px; }
h1 { margin: 0 0 12px; font-size: clamp(28px, 6vw, 40px); line-height: 1.05; }
.entry-subtitle { margin: 0; color: var(--tg-muted); line-height: 1.5; }
.entry-actions, .join-footer { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 24px; }
.entry-footnote { margin-top: 18px; color: var(--tg-muted); font-size: 14px; }

.primary-button, .secondary-button, .ghost-button, .ghost-link {
  border: 0;
  border-radius: 16px;
  min-height: 52px;
  padding: 0 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: transform 0.16s ease, opacity 0.16s ease, background 0.16s ease;
}
.primary-button { background: linear-gradient(135deg, #4a8fcf, #2b5278); color: white; font-weight: 600; }
.secondary-button { background: rgba(102, 169, 224, 0.12); color: var(--tg-text); border: 1px solid var(--tg-border); }
.ghost-button, .ghost-link { background: transparent; color: var(--tg-muted); border: 1px dashed var(--tg-border); }
.compact { min-height: 40px; padding: 0 14px; border-radius: 12px; }
.primary-button:hover, .secondary-button:hover, .ghost-button:hover, .ghost-link:hover { transform: translateY(-1px); opacity: 0.96; }

.join-form { display: grid; gap: 16px; margin-top: 24px; }
.join-form label { display: grid; gap: 8px; }
.join-form span { font-size: 14px; color: var(--tg-muted); }
.join-form input, .join-form select {
  min-height: 52px;
  border-radius: 16px;
  border: 1px solid var(--tg-border);
  background: rgba(14, 22, 33, 0.9);
  color: var(--tg-text);
  padding: 0 16px;
}
.join-alert {
  margin-top: 18px;
  border-radius: 18px;
  padding: 14px 16px;
  background: rgba(217, 111, 111, 0.12);
  color: #ffd8d8;
  border: 1px solid rgba(217, 111, 111, 0.24);
}

.chat-screen { min-height: 100vh; display: grid; grid-template-rows: auto 1fr auto; max-width: 980px; margin: 0 auto; }
.chat-topbar {
  position: sticky;
  top: 0;
  z-index: 6;
  background: linear-gradient(180deg, rgba(14,22,33,0.98), rgba(14,22,33,0.84));
  backdrop-filter: blur(16px);
}
.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 18px 12px;
}
.chat-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}
.chat-title { font-weight: 700; font-size: 20px; }
.chat-meta { color: var(--tg-muted); font-size: 14px; margin-top: 4px; }
.chat-status {
  margin: 0 18px 10px;
  padding: 10px 12px;
  border-radius: 14px;
  background: rgba(102, 169, 224, 0.08);
  color: var(--tg-muted);
  font-size: 13px;
}
.chat-thread { padding: 12px 14px 20px; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; }
.message-row { display: flex; scroll-margin-top: 116px; }
.message-row.system { justify-content: flex-start; }
.message-row.player { justify-content: flex-end; }
.message-row.is-pending .message-bubble {
  opacity: 0.72;
  transform: scale(0.995);
}
.message-bubble {
  max-width: min(92%, 560px);
  padding: 14px 16px;
  border-radius: 22px;
  background: var(--tg-bubble);
  border: 1px solid var(--tg-border);
  box-shadow: 0 10px 26px rgba(0, 0, 0, 0.18);
  transition: opacity 0.18s ease, transform 0.18s ease, border-color 0.24s ease, box-shadow 0.24s ease;
}
.message-row.player .message-bubble { background: var(--tg-bubble-self); }
.message-row.is-fresh .message-bubble,
.message-row.is-updated .message-bubble {
  border-color: rgba(102, 169, 224, 0.55);
  box-shadow: 0 0 0 1px rgba(102, 169, 224, 0.18), 0 14px 30px rgba(43, 82, 120, 0.38);
}
.message-row.is-fresh .message-bubble {
  animation: message-arrive 0.45s ease;
}
.message-row.is-updated .message-bubble {
  animation: message-refresh 0.55s ease;
}
.message-text { line-height: 1.52; font-size: 15px; white-space: pre-line; }
.message-text b { color: white; }
.message-time { margin-top: 10px; font-size: 12px; color: var(--tg-muted); text-align: right; }
.message-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}
.message-action {
  border: 0;
  border-radius: 14px;
  min-height: 42px;
  padding: 10px 14px;
  background: rgba(102, 169, 224, 0.12);
  color: var(--tg-text);
  white-space: normal;
  text-align: left;
  line-height: 1.35;
}
.message-action.primary { background: linear-gradient(135deg, #4a8fcf, #2b5278); color: white; }

.chat-footer {
  position: sticky;
  bottom: 0;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 10px;
  padding: 12px 14px calc(12px + var(--safe-bottom));
  background: linear-gradient(180deg, rgba(14,22,33,0.72), rgba(14,22,33,0.96));
  backdrop-filter: blur(16px);
}
.footer-action { width: 100%; min-height: 48px; font-size: 14px; }
.footer-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
}

@keyframes message-arrive {
  0% {
    opacity: 0;
    transform: translateY(14px) scale(0.98);
  }
  100% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes message-refresh {
  0% {
    transform: translateY(0) scale(1);
  }
  35% {
    transform: translateY(-4px) scale(1.01);
  }
  100% {
    transform: translateY(0) scale(1);
  }
}

@media (min-width: 900px) {
  .chat-screen {
    min-height: calc(100vh - 32px);
    margin: 16px auto;
    border: 1px solid var(--tg-border);
    border-radius: 28px;
    background: rgba(17, 26, 36, 0.62);
    backdrop-filter: blur(18px);
    overflow: hidden;
  }

}
