:root {
  --accent: #67e8c9;
  --accent-2: #ff8a65;
  --bg-from: #11100f;
  --bg-to: #1e2f27;
  --panel: rgba(24, 25, 23, 0.82);
  --panel-strong: rgba(31, 34, 31, 0.95);
  --line: rgba(255, 255, 255, 0.14);
  --text: #f6f4ee;
  --muted: #bbb6aa;
  --danger: #ff6b6b;
  --own: rgba(103, 232, 201, 0.16);
  --other: rgba(255, 255, 255, 0.08);
  --shadow: 0 24px 80px rgba(0, 0, 0, 0.34);
  --chat-wallpaper: none;
  --app-height: 100dvh;
  --keyboard-offset: 0px;
  --ios-top-guard: 0px;
  --ios-bottom-guard: 0px;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background-color: #11100f;
  overscroll-behavior: none;
  touch-action: manipulation;
}

body {
  position: fixed;
  inset: 0;
  min-height: var(--app-height);
  color: var(--text);
  background:
    linear-gradient(135deg, color-mix(in srgb, var(--bg-from), #000 12%), color-mix(in srgb, var(--bg-to), #000 10%)),
    var(--chat-wallpaper);
  background-size: cover;
  background-position: center;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  user-select: none;
}

html.ios-device {
  --ios-bottom-guard: max(20px, env(safe-area-inset-bottom));
}

html.ios-standalone {
  --ios-top-guard: max(54px, env(safe-area-inset-top));
}

body::before {
  position: fixed;
  inset: 0;
  pointer-events: none;
  content: "";
  background:
    linear-gradient(90deg, rgba(255, 138, 101, 0.08), transparent 42%),
    radial-gradient(circle at 78% 20%, rgba(103, 232, 201, 0.12), transparent 30%),
    rgba(0, 0, 0, 0.2);
}

button,
input,
textarea {
  font: inherit;
}

button {
  border: 0;
  touch-action: manipulation;
}

.shell {
  position: relative;
  z-index: 1;
  display: grid;
  width: 100%;
  height: var(--app-height);
  min-height: 0;
  overflow: hidden;
  padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}

.gate {
  align-self: center;
  justify-self: center;
  width: min(430px, 100%);
  padding: 26px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
  overflow: hidden;
}

.brand-mark {
  display: grid;
  width: 54px;
  height: 54px;
  place-items: center;
  border: 1px solid color-mix(in srgb, var(--accent), white 12%);
  border-radius: 8px;
  color: #0c1713;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  font-size: 15px;
  font-weight: 850;
  letter-spacing: 0;
}

.brand-mark.small {
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
  font-size: 12px;
}

.gate h1,
.room-title h1 {
  margin: 18px 0 8px;
  font-size: clamp(28px, 8vw, 42px);
  line-height: 1.02;
  letter-spacing: 0;
}

.gate p,
.room-title p {
  margin: 0;
  color: var(--muted);
}

.auth-form {
  display: grid;
  gap: 14px;
  margin-top: 24px;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 680;
}

input,
textarea {
  width: 100%;
  min-width: 0;
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  outline: 0;
  background: rgba(255, 255, 255, 0.08);
  font-size: 16px;
  user-select: text;
}

input {
  height: 46px;
  padding: 0 13px;
}

textarea {
  min-height: 46px;
  max-height: 150px;
  padding: 12px 13px;
  resize: none;
}

input:focus,
textarea:focus {
  border-color: color-mix(in srgb, var(--accent), white 12%);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent), transparent 75%);
}

.primary-action,
.secondary-action,
.send-button,
.icon-button {
  display: inline-grid;
  place-items: center;
  min-width: 44px;
  min-height: 44px;
  border-radius: 8px;
  color: var(--text);
  cursor: pointer;
  transition:
    transform 160ms ease,
    border-color 160ms ease,
    background 160ms ease;
}

.primary-action {
  display: inline-flex;
  width: 100%;
  justify-content: center;
  gap: 10px;
  margin-top: 22px;
  padding: 0 16px;
  color: #081310;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  font-weight: 800;
}

.secondary-action {
  width: 100%;
  margin-top: 12px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.08);
  font-weight: 760;
}

.send-button {
  color: #081310;
  background: var(--accent);
}

.icon-button {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.08);
}

.icon-button.active {
  border-color: color-mix(in srgb, var(--accent), white 10%);
  color: #081310;
  background: var(--accent);
}

.primary-action:hover,
.send-button:hover,
.icon-button:hover {
  transform: translateY(-1px);
}

.primary-action:disabled,
.send-button:disabled,
.icon-button:disabled {
  cursor: progress;
  opacity: 0.55;
  transform: none;
}

.manual-install {
  display: grid;
  gap: 8px;
  margin-top: 16px;
  color: var(--muted);
  font-size: 14px;
}

.install-step {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  min-height: 42px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.07);
}

.step-icon {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border-radius: 8px;
  color: #081310;
  background: var(--accent);
}

.chat {
  display: grid;
  grid-template-rows: auto auto auto 1fr auto;
  width: min(940px, 100%);
  height: calc(var(--app-height) - max(32px, env(safe-area-inset-top)) - max(32px, env(safe-area-inset-bottom)));
  place-self: center;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.chat-header {
  grid-row: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 14px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.04);
}

.room-title {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 12px;
}

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

.room-title p {
  margin-top: 2px;
  font-size: 13px;
}

.header-actions {
  display: flex;
  flex: 0 0 auto;
  gap: 8px;
}

.notice {
  grid-row: 2;
  margin: 12px 14px 0;
  padding: 10px 12px;
  border: 1px solid color-mix(in srgb, var(--accent-2), transparent 48%);
  border-radius: 8px;
  color: var(--text);
  background: color-mix(in srgb, var(--accent-2), transparent 84%);
  font-size: 14px;
}

.typing {
  grid-row: 3;
  min-height: 27px;
  padding: 8px 18px 0;
  color: var(--muted);
  font-size: 13px;
}

.messages {
  grid-row: 4;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  padding: 8px 14px calc(16px + var(--keyboard-offset));
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
}

.message {
  display: grid;
  max-width: min(78%, 620px);
  gap: 6px;
  align-self: flex-start;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--other);
}

.message.own {
  align-self: flex-end;
  border-color: color-mix(in srgb, var(--accent), transparent 54%);
  background: var(--own);
}

.message.system {
  max-width: 88%;
  align-self: center;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.06);
  font-size: 13px;
  text-align: center;
}

.message.media-message {
  padding: 4px;
  border-color: transparent;
  background: transparent;
}

.message.media-message.own {
  background: transparent;
}

.message.media-message .message-meta,
.message.media-message .message-readers,
.message.media-message .message-status {
  padding: 0 4px;
}

.message-meta {
  display: flex;
  min-width: 0;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: 12px;
}

.message-author {
  overflow: hidden;
  font-weight: 750;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.message-body {
  overflow-wrap: anywhere;
  color: var(--text);
  font-size: 15px;
  line-height: 1.42;
}

.message-body p {
  margin: 0 0 8px;
}

.message-body p:last-child {
  margin-bottom: 0;
}

.message-body blockquote {
  margin: 4px 0;
  padding: 6px 10px;
  border-left: 3px solid var(--accent);
  color: color-mix(in srgb, var(--text), var(--muted) 18%);
  background: rgba(255, 255, 255, 0.06);
}

.message-body code,
.message-body pre {
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.26);
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}

.message-body code {
  padding: 1px 5px;
  font-size: 0.92em;
}

.message-body pre {
  max-width: 100%;
  margin: 6px 0;
  overflow-x: auto;
  padding: 10px;
}

.message-body pre code {
  padding: 0;
  border: 0;
  background: transparent;
}

.message-body a {
  color: var(--accent);
}

.message-image {
  display: block;
  width: min(100%, 460px);
  max-height: 62vh;
  border-radius: 8px;
  object-fit: contain;
  background: rgba(0, 0, 0, 0.16);
  cursor: zoom-in;
}

.message-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
}

.message-button {
  min-height: 34px;
  padding: 7px 10px;
  border: 1px solid color-mix(in srgb, var(--accent), transparent 48%);
  border-radius: 8px;
  color: #081310;
  background: var(--accent);
  font-size: 13px;
  font-weight: 800;
  text-decoration: none;
}

.message-status {
  justify-self: end;
  color: var(--muted);
  font-size: 11px;
}

.message-readers {
  margin-top: 2px;
  color: var(--muted);
  font-size: 11px;
}

.sticker {
  display: inline-grid;
  width: min(190px, 50vw);
  aspect-ratio: 1.55;
  place-items: center;
  border: 1px solid color-mix(in srgb, var(--accent), transparent 46%);
  border-radius: 8px;
  color: #081310;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  font-size: clamp(28px, 9vw, 58px);
  font-weight: 900;
}

.composer {
  grid-row: 5;
  display: grid;
  grid-template-columns: 46px minmax(0, 1fr) 46px;
  gap: 10px;
  align-items: end;
  padding: 12px 14px 14px;
  border-top: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.16);
  min-width: 0;
  transform: none;
  transition: transform 160ms ease;
  will-change: transform;
  z-index: 2;
}

.media-preview {
  position: relative;
  grid-column: 1 / -1;
  width: min(240px, 72vw);
  overflow: hidden;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.22);
}

.media-preview img {
  display: block;
  width: 100%;
  max-height: 180px;
  object-fit: cover;
}

.media-preview button {
  position: absolute;
  top: 6px;
  right: 6px;
  min-width: 32px;
  min-height: 32px;
  border-radius: 8px;
  color: var(--text);
  background: rgba(0, 0, 0, 0.58);
  font-weight: 900;
}

.admin-toolbar {
  display: flex;
  grid-column: 1 / -1;
  gap: 6px;
  min-width: 0;
  padding-bottom: 2px;
  overflow-x: auto;
  scrollbar-width: none;
}

.admin-toolbar::-webkit-scrollbar {
  display: none;
}

.admin-toolbar button,
.message-menu button {
  min-width: 38px;
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.08);
  font-weight: 800;
}

.admin-toolbar button:last-child {
  margin-left: auto;
  color: var(--danger);
}

.message-menu {
  position: fixed;
  z-index: 7;
  right: 12px;
  bottom: calc(82px + var(--keyboard-offset));
  display: flex;
  gap: 8px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-strong);
  box-shadow: var(--shadow);
}

.message-menu button {
  padding: 0 10px;
  font-size: 14px;
}

.photo-viewer {
  position: fixed;
  inset: 0;
  z-index: 9;
  display: grid;
  place-items: center;
  padding: max(18px, env(safe-area-inset-top)) 14px max(18px, env(safe-area-inset-bottom));
  background: rgba(0, 0, 0, 0.92);
}

.photo-viewer img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 8px;
}

.photo-viewer button {
  position: fixed;
  top: max(12px, env(safe-area-inset-top));
  right: 12px;
  z-index: 10;
  min-width: 42px;
  min-height: 42px;
  border-radius: 8px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.14);
  font-size: 24px;
}

.toast-stack {
  position: fixed;
  right: max(16px, env(safe-area-inset-right));
  bottom: max(16px, env(safe-area-inset-bottom));
  z-index: 6;
  display: grid;
  width: min(360px, calc(100vw - 32px));
  gap: 8px;
}

.toast {
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  background: var(--panel-strong);
  box-shadow: var(--shadow);
}

#effectsCanvas {
  position: fixed;
  inset: 0;
  z-index: 4;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.aurora {
  animation: auroraShift 3.2s ease-in-out;
}

.pulse {
  animation: bodyPulse 900ms ease-out;
}

@keyframes auroraShift {
  0%,
  100% {
    filter: hue-rotate(0deg) saturate(1);
  }
  50% {
    filter: hue-rotate(42deg) saturate(1.25);
  }
}

@keyframes bodyPulse {
  0%,
  100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.008);
  }
}

[data-icon] svg {
  display: block;
  width: 20px;
  height: 20px;
  stroke-width: 2.1;
}

[hidden] {
  display: none !important;
}

@media (max-width: 700px) {
  body {
    background-attachment: scroll;
  }

  .shell {
    width: 100vw;
    height: var(--app-height);
    padding: 0;
  }

  .gate {
    width: 100%;
    height: var(--app-height);
    min-height: 0;
    align-self: stretch;
    border: 0;
    border-radius: 0;
    padding: max(18px, env(safe-area-inset-top)) 16px max(14px, env(safe-area-inset-bottom));
    align-content: center;
    justify-self: stretch;
    overflow: hidden;
  }

  .chat {
    width: 100%;
    height: var(--app-height);
    border: 0;
    border-radius: 0;
    grid-template-rows: auto auto minmax(20px, auto) minmax(0, 1fr) auto;
  }

  .chat-header {
    min-height: 62px;
    padding: max(8px, env(safe-area-inset-top), var(--ios-top-guard)) 10px 8px;
  }

  .brand-mark.small {
    width: 36px;
    height: 36px;
  }

  .room-title {
    gap: 9px;
  }

  .room-title h1 {
    max-width: calc(100vw - 154px);
    font-size: 16px;
  }

  .room-title p,
  .typing {
    font-size: 12px;
  }

  .header-actions {
    gap: 6px;
  }

  .icon-button,
  .send-button {
    min-width: 42px;
    min-height: 42px;
  }

  .notice {
    margin: 8px 10px 0;
    padding: 8px 10px;
    font-size: 13px;
  }

  .typing {
    min-height: 22px;
    padding: 6px 12px 0;
  }

  .messages {
    gap: 8px;
    padding: 6px 10px calc(10px + var(--keyboard-offset));
  }

  .message {
    max-width: 92%;
    padding: 9px 10px;
  }

  .message-image {
    width: min(100%, 86vw);
    max-height: 46vh;
  }

  .message-body {
    font-size: 15px;
  }

  .composer {
    grid-template-columns: 42px minmax(0, 1fr) 42px;
    gap: 8px;
    padding: 8px 10px max(8px, env(safe-area-inset-bottom), var(--ios-bottom-guard));
  }

  .admin-toolbar {
    padding-bottom: 0;
  }

  .admin-toolbar button {
    min-height: 32px;
    font-size: 13px;
  }

  textarea {
    min-height: 42px;
    max-height: 112px;
    padding: 10px 12px;
  }

  .gate h1 {
    margin: 14px 0 8px;
    font-size: clamp(27px, 9vw, 36px);
  }

  .gate p {
    font-size: 15px;
    line-height: 1.35;
  }

  .brand-mark:not(.small) {
    width: 48px;
    height: 48px;
  }

  .auth-form {
    gap: 12px;
    margin-top: 18px;
  }

  .primary-action {
    margin-top: 16px;
  }

  .manual-install {
    gap: 7px;
    margin-top: 14px;
    font-size: 13px;
  }

  .install-step {
    min-height: 38px;
    padding: 7px 9px;
  }

  .toast-stack {
    right: 10px;
    bottom: max(10px, env(safe-area-inset-bottom));
    width: calc(100vw - 20px);
  }
}

@media (max-height: 680px) and (max-width: 700px) {
  .gate {
    align-content: start;
    padding-top: max(12px, env(safe-area-inset-top));
  }

  .gate h1 {
    font-size: 28px;
  }

  .manual-install {
    gap: 6px;
  }

  .install-step {
    min-height: 35px;
  }
}
