:root {
  color-scheme: light;
  --ink: #111827;
  --muted: #657083;
  --line: #dbe2ea;
  --panel: #ffffff;
  --canvas: #f4f7fb;
  --host: #0f766e;
  --guest: #2563eb;
  --warm: #f59e0b;
  --danger: #dc2626;
  --shadow: 0 18px 50px rgba(15, 23, 42, 0.12);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

html {
  height: 100%;
}

body,
#app {
  min-height: 100%;
}

body {
  background:
    linear-gradient(135deg, rgba(15, 118, 110, 0.08), transparent 34%),
    linear-gradient(315deg, rgba(245, 158, 11, 0.12), transparent 42%),
    var(--canvas);
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

.shell {
  min-height: 100vh;
  padding: 20px;
}

.guest-shell {
  height: 100vh;
  height: 100dvh;
  min-height: 0;
  overflow: hidden;
  padding: max(8px, env(safe-area-inset-top)) 8px max(8px, env(safe-area-inset-bottom));
}

.guest-shell .app-frame {
  height: 100%;
  width: min(760px, 100%);
}

.guest-shell .solo-chat {
  height: 100%;
  min-height: 0;
  border-radius: 8px;
  box-shadow: none;
}

.guest-shell .panel {
  background: rgba(255, 255, 255, 0.96);
}

.guest-shell .chat {
  grid-template-rows: auto minmax(0, 1fr) auto;
}

.guest-shell .messages {
  min-height: 0;
}

.app-frame {
  width: min(1180px, 100%);
  margin: 0 auto;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}

.top-actions,
.host-action-row {
  display: flex;
  align-items: end;
  justify-content: flex-end;
  gap: 10px;
}

.host-brand-row {
  display: flex;
  width: 100%;
  align-items: end;
  justify-content: space-between;
  gap: 12px;
}

.host-action-row {
  width: 100%;
}

.host-action-row .btn {
  flex: 1;
}

.language-field {
  width: min(260px, 48%);
}

.compact {
  min-width: 170px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand-mark {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border-radius: 8px;
  background: var(--ink);
  color: white;
  font-weight: 800;
  font-size: 18px;
}

.brand-title {
  margin: 0;
  font-size: 18px;
  line-height: 1.1;
}

.brand-subtitle {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.grid {
  display: grid;
  grid-template-columns: 0.82fr 1.18fr;
  gap: 18px;
  align-items: stretch;
}

.guest-grid {
  grid-template-columns: minmax(0, 760px);
  justify-content: center;
}

.panel {
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid rgba(219, 226, 234, 0.9);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.invite {
  display: flex;
  min-height: 650px;
  flex-direction: column;
  padding: 22px;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(15, 23, 42, 0.5);
}

.modal {
  position: relative;
  width: min(520px, 100%);
  max-height: calc(100vh - 36px);
  min-height: 0;
  overflow-y: auto;
}

.icon-btn {
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  border-radius: 8px;
  background: white;
  color: var(--ink);
  font-size: 26px;
  line-height: 1;
}

.close {
  position: absolute;
  top: 12px;
  right: 12px;
  border: 1px solid var(--line);
}

.invite-copy {
  margin-bottom: 18px;
}

.foreign-copy {
  padding-right: 42px;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--host);
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.headline {
  margin: 0;
  font-size: clamp(30px, 5vw, 56px);
  line-height: 1;
}

.body-copy {
  margin: 14px 0 0;
  color: var(--muted);
  font-size: 16px;
  line-height: 1.55;
}

.qr-zone {
  display: grid;
  flex: 1;
  place-items: center;
  padding: 18px 0;
}

.qr-card {
  width: min(330px, 100%);
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  text-align: center;
}

#qr {
  display: grid;
  min-height: 244px;
  place-items: center;
}

#qr img,
#qr canvas {
  width: min(244px, 100%) !important;
  height: min(244px, 100%) !important;
}

.qr-fallback {
  overflow-wrap: anywhere;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.local-prompt {
  margin: 16px 0 0;
  font-size: 23px;
  font-weight: 800;
  line-height: 1.2;
}

.room-link {
  display: block;
  margin-top: 10px;
  overflow-wrap: anywhere;
  color: var(--muted);
  font-size: 12px;
}

.controls {
  display: grid;
  gap: 10px;
  margin-top: auto;
}

.control-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.field {
  display: grid;
  gap: 6px;
}

.field span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.select,
.input {
  min-height: 42px;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  color: var(--ink);
  padding: 0 12px;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.btn {
  display: inline-flex;
  min-height: 42px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border-radius: 8px;
  padding: 0 14px;
  background: var(--ink);
  color: white;
  font-weight: 800;
}

.composer .btn {
  min-height: 46px;
  align-self: start;
}

.btn.secondary {
  border: 1px solid var(--line);
  background: white;
  color: var(--ink);
}

.btn.warning {
  background: var(--warm);
  color: #1f2937;
}

.chat {
  display: grid;
  min-height: 650px;
  grid-template-rows: auto 1fr auto;
  overflow: hidden;
}

.host-chat {
  grid-template-rows: minmax(0, 1fr) auto;
}

.solo-chat {
  min-height: calc(100vh - 96px);
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--line);
  padding: 14px;
}

.room-meta {
  min-width: 0;
}

.room-meta h2 {
  margin: 0;
  overflow: hidden;
  font-size: 18px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.room-meta p {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.chat-tools {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.chat-tools .select {
  width: 145px;
}

.messages {
  display: flex;
  flex-direction: column;
  gap: 16px;
  overflow-y: auto;
  padding: 20px 22px;
}

.empty {
  margin: auto;
  max-width: 370px;
  color: var(--muted);
  text-align: center;
  line-height: 1.5;
}

.msg {
  display: grid;
  width: max-content;
  max-width: min(72%, 680px);
  gap: 6px;
}

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

.msg.theirs {
  align-self: flex-start;
}

.bubble {
  border-radius: 8px;
  padding: 10px 14px;
  background: white;
  border: 1px solid var(--line);
  line-height: 1.45;
  white-space: normal;
  width: auto;
  max-width: 100%;
  overflow-wrap: break-word;
  word-break: normal;
  font-size: 17px;
}

.bubble p {
  margin: 0;
  white-space: pre-wrap;
}

.typing-dots {
  display: inline-flex;
  min-width: 36px;
  align-items: center;
  gap: 4px;
  padding: 4px 0;
}

.typing-dots span {
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: currentColor;
  opacity: 0.35;
  animation: dotPulse 1.1s infinite ease-in-out;
}

.typing-dots span:nth-child(2) {
  animation-delay: 0.16s;
}

.typing-dots span:nth-child(3) {
  animation-delay: 0.32s;
}

@keyframes dotPulse {
  0%,
  80%,
  100% {
    transform: translateY(0);
    opacity: 0.35;
  }

  40% {
    transform: translateY(-3px);
    opacity: 0.9;
  }
}

.bubble .original {
  margin-bottom: 8px;
  padding-bottom: 8px;
  border-bottom: 1px solid rgba(101, 112, 131, 0.24);
  color: var(--muted);
  font-size: 15px;
}

.bubble .outbound {
  margin-top: 8px;
  margin-bottom: 0;
  padding-top: 8px;
  padding-bottom: 0;
  border-top: 1px solid rgba(101, 112, 131, 0.24);
  border-bottom: 0;
}

.mine .bubble .original {
  border-bottom-color: rgba(255, 255, 255, 0.35);
  color: rgba(255, 255, 255, 0.82);
}

.mine .bubble .outbound {
  border-top-color: rgba(255, 255, 255, 0.35);
}

.mine .bubble {
  justify-self: end;
  background: var(--host);
  border-color: var(--host);
  color: white;
}

.msg.guest-mine .bubble {
  background: var(--guest);
  border-color: var(--guest);
}

.msg-meta {
  color: var(--muted);
  font-size: 13px;
}

.mine .msg-meta {
  text-align: right;
}

.composer {
  display: grid;
  grid-template-columns: 1fr auto;
  align-content: start;
  align-items: stretch;
  gap: 10px;
  border-top: 1px solid var(--line);
  padding: 14px;
  background: rgba(255, 255, 255, 0.82);
}

.text-input {
  min-height: 46px;
  max-height: 110px;
  resize: none;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  overflow-y: auto;
  line-height: 1.35;
}

.host-only {
  display: block;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 20px;
  z-index: 10;
  transform: translateX(-50%);
  border-radius: 8px;
  background: var(--ink);
  color: white;
  padding: 10px 14px;
  box-shadow: var(--shadow);
  font-size: 14px;
}

@media (max-width: 880px) {
  html,
  body,
  #app {
    height: 100%;
  }

  .shell {
    height: 100vh;
    height: 100dvh;
    min-height: 0;
    overflow: hidden;
    padding: 12px;
  }

  .guest-shell {
    position: fixed;
    inset: 0;
    width: 100%;
    padding: max(6px, env(safe-area-inset-top)) 6px max(6px, env(safe-area-inset-bottom));
  }

  .app-frame {
    display: grid;
    height: 100%;
    grid-template-rows: auto minmax(0, 1fr);
  }

  .guest-shell .app-frame {
    display: block;
    height: 100%;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 10px;
  }

  .brand-mark {
    width: 34px;
    height: 34px;
    font-size: 16px;
  }

  .brand-title {
    font-size: 17px;
  }

  .brand-subtitle {
    font-size: 12px;
  }

  .top-actions,
  .host-action-row {
    width: 100%;
    flex-wrap: wrap;
    justify-content: flex-start;
  }

  .top-actions .btn,
  .top-actions .field,
  .host-action-row .btn {
    flex: 1;
  }

  .top-actions .btn,
  .host-action-row .btn {
    min-height: 40px;
  }

  .host-brand-row {
    align-items: center;
  }

  .language-field {
    width: min(210px, 56%);
  }

  .language-field span {
    display: none;
  }

  .compact {
    min-width: min(100%, 160px);
  }

  .grid {
    grid-template-columns: 1fr;
  }

  .invite,
  .chat {
    min-height: auto;
  }

  .chat {
    height: 100%;
    min-height: 0;
    grid-template-rows: auto minmax(0, 1fr) auto;
  }

  .host-chat {
    grid-template-rows: minmax(0, 1fr) auto;
  }

  .guest-shell .chat {
    height: 100%;
  }

  .solo-chat {
    min-height: auto;
  }

  .chat-header {
    padding: 12px;
  }

  .room-meta h2 {
    font-size: 17px;
  }

  .room-meta p {
    font-size: 12px;
  }

  .control-row,
  .composer {
    grid-template-columns: 1fr;
  }

  .msg {
    max-width: 88%;
  }

  .chat-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .guest-shell .chat-header {
    gap: 8px;
    padding: 10px 12px;
  }

  .guest-shell .room-meta h2 {
    font-size: 20px;
  }

  .guest-shell .room-meta p {
    font-size: 13px;
    line-height: 1.35;
  }

  .guest-shell .chat-tools .select {
    min-height: 40px;
    width: 100%;
  }

  .guest-shell .messages {
    padding: 14px 12px;
  }

  .guest-shell .composer {
    grid-template-columns: 1fr;
    align-content: start;
    gap: 8px;
    padding: 10px 12px;
  }

  .guest-shell .text-input {
    min-height: 42px;
    max-height: 82px;
  }

  .guest-shell .composer .btn {
    min-height: 42px;
  }

  .chat-tools {
    justify-content: flex-start;
    width: 100%;
  }

  .chat-tools .btn {
    min-height: 38px;
  }

  .chat-tools .select {
    flex: 1;
    min-width: 150px;
  }
}

@media (max-width: 520px) {
  .brand-subtitle,
  .topbar > .btn.secondary {
    display: none;
  }

  .headline {
    font-size: 34px;
  }

  .local-prompt {
    font-size: 20px;
  }
}
