:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --panel: #ffffff;
  --panel-strong: #111827;
  --line: #d8dee6;
  --muted: #6b7280;
  --text: #111827;
  --accent: #0f766e;
  --accent-strong: #0b5f59;
  --danger: #b91c1c;
  --shadow: 0 18px 50px rgba(15, 23, 42, 0.12);
  --chat-control-bg: rgba(255, 255, 255, 0.14);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: default;
  opacity: 0.45;
}

.hidden {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

.icon-defs {
  display: none;
}

.icon {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.app-shell {
  min-height: 100vh;
}

.auth-view {
  display: flex;
  min-height: 100vh;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 22px;
  padding: 28px 16px;
}

.auth-brand,
.auth-panel {
  width: min(420px, calc(100vw - 32px));
}

.auth-brand {
  display: grid;
  justify-items: center;
  gap: 8px;
  text-align: center;
}

.brand-logo {
  display: block;
  width: clamp(196px, 52vw, 220px);
  height: auto;
}

.auth-brand p,
.chat-head p,
.user-card span {
  margin: 6px 0 0;
  color: var(--muted);
}

.auth-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  padding: 20px;
}

.auth-tabs,
.app-tabs {
  display: grid;
  gap: 6px;
  border-radius: 8px;
  background: #edf1f5;
  padding: 4px;
}

.auth-tabs {
  grid-template-columns: 1fr 1fr;
  margin-bottom: 18px;
}

.app-tabs {
  position: fixed;
  z-index: 4;
  right: 0;
  bottom: 0;
  left: 0;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0;
  width: auto;
  border-top: 0;
  border-radius: 0;
  background: var(--chat-control-bg);
  color: rgba(238, 246, 255, 0.72);
  padding: 3px 8px calc(3px + env(safe-area-inset-bottom));
  box-shadow: none;
  backdrop-filter: blur(14px);
}

.auth-tab {
  display: flex;
  min-width: 0;
  height: 40px;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-weight: 700;
  line-height: 1;
  padding: 0 12px;
}

.app-tab {
  display: flex;
  gap: 6px;
  min-width: 0;
  height: 30px;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: rgba(238, 246, 255, 0.72);
  font-weight: 700;
}

.app-tab .icon {
  width: 17px;
  height: 17px;
}

.tab-label {
  font-size: 11px;
  line-height: 1;
  letter-spacing: 0;
}

.auth-tab.active {
  background: var(--panel);
  color: var(--accent);
  box-shadow: 0 1px 5px rgba(15, 23, 42, 0.08);
}

.app-tab.active {
  background: transparent;
  color: #5eead4;
  box-shadow: none;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.form-grid label,
.compact-form input,
.message-form textarea {
  min-width: 0;
}

.form-grid label {
  display: grid;
  gap: 6px;
  color: #374151;
  font-size: 13px;
  font-weight: 700;
}

.wide {
  grid-column: 1 / -1;
}

input,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #ffffff;
  color: var(--text);
  font-size: 16px;
  outline: none;
  padding: 11px 12px;
}

input:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.14);
}

.primary-action,
.send-button,
.icon-button {
  display: grid;
  place-items: center;
  border-radius: 6px;
}

.primary-action,
.send-button {
  height: 44px;
  border: 0;
  background: var(--accent);
  color: #ffffff;
  font-weight: 800;
  line-height: 1;
  padding: 0 14px;
}

.primary-action:hover,
.send-button:hover {
  background: var(--accent-strong);
}

.text-link {
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 0;
  font-size: 13px;
  font-weight: 700;
  text-align: center;
}

.text-link:hover {
  color: var(--accent);
}

.icon-button {
  width: 40px;
  height: 40px;
  border: 1px solid var(--line);
  background: #ffffff;
  color: var(--text);
}

.icon-button:hover {
  border-color: #9ca3af;
}

.danger-action {
  border-color: rgba(185, 28, 28, 0.26);
  color: var(--danger);
}

.icon-action .icon {
  width: 22px;
  height: 22px;
}

.form-error {
  min-height: 20px;
  margin: 14px 0 0;
  color: var(--danger);
  font-size: 13px;
}

.team-view {
  display: grid;
  height: 100vh;
  height: 100dvh;
  grid-template-rows: auto minmax(0, 1fr);
  background: #eef2f5;
  padding-bottom: calc(36px + env(safe-area-inset-bottom));
}

.app-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 40px;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(5, 10, 24, 0.92);
  color: #ffffff;
  padding: 12px 16px;
  backdrop-filter: blur(14px);
}

.team-view:not(.view-lobby) .app-head {
  display: none;
}

.user-card {
  min-width: 0;
}

.user-card strong,
.user-card span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-card span {
  max-width: 320px;
  color: rgba(238, 246, 255, 0.72);
  font-size: 12px;
}

.tab-view {
  grid-row: 2;
  min-height: 0;
  min-width: 0;
  width: 100%;
  max-width: 100vw;
}

.lobby-view {
  display: grid;
  width: min(760px, 100%);
  grid-template-rows: auto minmax(0, 1fr);
  gap: 12px;
  margin: 0 auto;
  padding: 16px;
}

.settings-view {
  display: grid;
  width: min(760px, 100%);
  align-content: start;
  gap: 12px;
  margin: 0 auto;
  overflow: auto;
  padding: 16px;
}

.settings-form,
.settings-room {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  box-shadow: 0 10px 28px rgba(15, 23, 42, 0.08);
  padding: 16px;
}

.settings-form h2 {
  margin: 0 0 2px;
  font-size: 18px;
}

.settings-room {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 40px;
  align-items: center;
  gap: 12px;
}

.settings-room strong,
.settings-room span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.settings-room span {
  color: var(--muted);
  font-size: 12px;
}

.settings-room-select {
  width: 100%;
  margin-top: 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #ffffff;
  color: var(--text);
  font: inherit;
  font-size: 14px;
  outline: none;
  padding: 9px 10px;
}

.settings-room-select:disabled {
  opacity: 0.55;
}

.room-actions {
  display: grid;
  gap: 8px;
}

.compact-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 40px;
  gap: 8px;
}

.room-list {
  display: grid;
  align-content: start;
  gap: 8px;
  overflow: auto;
}

.room-item {
  display: grid;
  width: 100%;
  min-height: 58px;
  grid-template-columns: 32px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--text);
  padding: 10px 12px;
  text-align: left;
}

.room-item span,
.room-item strong,
.room-item small {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.room-item span {
  display: grid;
  gap: 2px;
}

.room-item small {
  color: var(--muted);
  font-size: 12px;
}

.room-item.active {
  border-color: #5cc5b7;
  background: #e7f6f3;
}

.chat-panel {
  position: relative;
  display: grid;
  width: 100%;
  max-width: 100vw;
  min-width: 0;
  min-height: 0;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  overflow: hidden;
  background:
    linear-gradient(155deg, rgba(6, 11, 27, 0.98) 0%, rgba(20, 17, 58, 0.97) 46%, rgba(10, 56, 72, 0.98) 100%);
  color: #eef6ff;
}

.chat-head,
.invite-panel,
.messages,
.empty-chat,
.composer {
  position: relative;
  z-index: 1;
}

.chat-head {
  display: grid;
  min-width: 0;
  min-height: 58px;
  grid-template-columns: minmax(88px, 1fr) minmax(0, 2fr) minmax(88px, 1fr);
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(5, 10, 24, 0.92);
  padding: 10px 12px;
  backdrop-filter: blur(14px);
}

.chat-title {
  display: contents;
  min-width: 0;
}

.chat-logo {
  display: block;
  grid-column: 1;
  justify-self: start;
  width: 74px;
  height: auto;
  filter: brightness(0) invert(1);
  opacity: 0.92;
}

.chat-head > div {
  min-width: 0;
}

.chat-head h2 {
  display: block;
  grid-column: 2;
  justify-self: center;
  max-width: 100%;
  margin: 0;
  overflow: hidden;
  color: #ffffff;
  font-size: 18px;
  text-align: center;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-head p {
  margin: 0;
  color: rgba(238, 246, 255, 0.7);
  font-size: 12px;
}

.chat-actions {
  display: flex;
  grid-column: 3;
  flex: 0 0 auto;
  justify-self: end;
  gap: 8px;
}

.chat-actions .icon-button,
.drop-zone .icon-button {
  border-color: rgba(255, 255, 255, 0.24);
  background: rgba(255, 255, 255, 0.13);
  color: #ffffff;
}

.invite-panel {
  grid-row: 2;
  display: grid;
  gap: 8px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(5, 10, 24, 0.58);
  padding: 10px 14px;
  backdrop-filter: blur(14px);
}

.invite-search {
  display: grid;
  grid-template-columns: 24px minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  color: rgba(238, 246, 255, 0.78);
}

.invite-search input,
.composer textarea {
  border-color: rgba(255, 255, 255, 0.2);
  background: var(--chat-control-bg);
  color: #ffffff;
}

.invite-search input::placeholder,
.composer textarea::placeholder {
  color: rgba(238, 246, 255, 0.58);
}

.invite-list {
  display: grid;
  max-height: 190px;
  gap: 6px;
  overflow: auto;
}

.invite-user {
  display: grid;
  gap: 2px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.1);
  color: #ffffff;
  padding: 8px 10px;
  text-align: left;
}

.invite-user span {
  color: rgba(238, 246, 255, 0.7);
  font-size: 12px;
}

.messages,
.empty-chat {
  grid-row: 3;
}

.messages {
  display: flex;
  min-height: 0;
  flex-direction: column;
  gap: 6px;
  overflow: auto;
  padding: 10px 12px;
}

.message {
  display: grid;
  max-width: min(620px, 78%);
  gap: 3px;
  align-self: flex-start;
}

.message.mine {
  align-self: flex-end;
}

.message.video-message {
  width: 100%;
  max-width: 100%;
}

.message.video-message.mine {
  align-self: stretch;
}

.message-meta {
  color: rgba(238, 246, 255, 0.62);
  font-size: 11px;
}

.bubble {
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.2);
  padding: 6px 9px;
  overflow-wrap: anywhere;
  color: #ffffff;
  line-height: 1.38;
  backdrop-filter: blur(10px);
}

.message.mine .bubble {
  border-color: rgba(255, 255, 255, 0.18);
  background: rgba(255, 255, 255, 0.2);
}

.video-bubble,
.youtube-bubble,
.message.mine .youtube-bubble,
.message.mine .video-bubble {
  border: 0;
  border-radius: 0;
  background: transparent;
  padding: 0;
  backdrop-filter: none;
}

.bubble img,
.bubble video {
  display: block;
  width: min(520px, 100%);
  max-height: 56vh;
  border-radius: 6px;
  background: #000000;
  object-fit: contain;
}

.video-bubble video {
  width: 100%;
  max-height: 72vh;
  border-radius: 6px;
}

.message.youtube-message {
  width: 100%;
  max-width: 100%;
}

.message.youtube-message.mine {
  align-self: stretch;
}

.youtube-bubble {
  width: 100%;
}

.rendered-markdown {
  display: grid;
  gap: 5px;
}

.rendered-markdown > :first-child {
  margin-top: 0;
}

.rendered-markdown > :last-child {
  margin-bottom: 0;
}

.rendered-markdown p {
  margin: 0;
}

.rendered-markdown h1,
.rendered-markdown h2,
.rendered-markdown h3 {
  margin: 2px 0;
  line-height: 1.2;
}

.rendered-markdown h1 {
  font-size: 20px;
}

.rendered-markdown h2 {
  font-size: 17px;
}

.rendered-markdown h3 {
  font-size: 15px;
}

.rendered-markdown ul,
.rendered-markdown ol {
  margin: 0;
  padding-left: 18px;
}

.rendered-markdown blockquote {
  margin: 0;
  border-left: 3px solid rgba(255, 255, 255, 0.35);
  padding-left: 8px;
  color: rgba(238, 246, 255, 0.82);
}

.rendered-markdown code {
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.28);
  padding: 1px 4px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.92em;
}

.rendered-markdown pre {
  margin: 0;
  overflow: auto;
}

.rendered-markdown pre code {
  display: block;
  padding: 8px;
}

.rendered-markdown a {
  color: #93f2e4;
  text-underline-offset: 3px;
}

.youtube-player {
  width: 100%;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  border-radius: 6px;
  background: #000000;
}

.youtube-player iframe {
  display: block;
  width: 100%;
  height: 100%;
  border: 0;
}

.empty-chat {
  display: grid;
  place-items: center;
  color: rgba(238, 246, 255, 0.72);
}

.composer {
  grid-row: 4;
  display: grid;
  min-width: 0;
  grid-template-columns: 40px minmax(0, 1fr);
  gap: 8px;
  border-top: 1px solid rgba(255, 255, 255, 0.14);
  background: var(--chat-control-bg);
  padding: 8px 10px;
  backdrop-filter: blur(14px);
}

.drop-zone {
  position: relative;
  display: grid;
  place-items: center;
}

.drop-zone.dragging .icon-button {
  border-color: rgba(94, 234, 212, 0.9);
  background: rgba(20, 184, 166, 0.3);
}

#file-input {
  position: absolute;
  inset: 0;
  opacity: 0;
  pointer-events: none;
}

.message-form {
  display: grid;
  min-width: 0;
  grid-template-columns: minmax(0, 1fr) 44px;
  gap: 8px;
}

.message-form textarea {
  min-height: 40px;
  max-height: 120px;
  resize: none;
}

.toast {
  position: fixed;
  z-index: 5;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  max-width: min(520px, calc(100vw - 24px));
  border-radius: 8px;
  background: var(--panel-strong);
  color: #ffffff;
  padding: 10px 14px;
  box-shadow: var(--shadow);
}

@media (max-width: 720px) {
  .app-head {
    gap: 8px;
    padding: 10px;
  }

  .lobby-view {
    padding: 12px;
  }

  .message {
    max-width: 86%;
  }
}

@media (max-width: 520px) {
  .auth-view {
    justify-content: flex-start;
    gap: 20px;
    padding: 24px 16px;
  }

  .auth-panel {
    padding: 18px;
  }

  .form-grid {
    gap: 10px;
  }

  input,
  textarea {
    padding: 10px 9px;
  }

  .chat-head {
    min-height: 58px;
  }

  .messages {
    padding: 8px;
  }

  .message {
    max-width: 92%;
  }
}
