:root {
  color-scheme: light;
  --page: #edf0f2;
  --panel: #ffffff;
  --panel-soft: #f5f6f7;
  --bubble: #e3eee9;
  --bubble-grad-top: #f9fcfa;
  --bubble-grad-bottom: #dce9e3;
  --guest-grad-top: #2f8a79;
  --guest-grad-bottom: #17594e;
  --text: #202421;
  --muted: #68706b;
  --line: #d9dfdb;
  --accent: #1e6b5f;
  --accent-dark: #155047;
  --accent-contrast: #ffffff;
  --danger: #a33434;
  --focus: rgba(30, 107, 95, 0.24);
  --shadow: 0 12px 36px rgba(24, 32, 28, 0.12);
  --direct-guest-visible-height: 100dvh;
  --direct-guest-viewport-top: 0px;
}

.direct-guest-legal-links {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: .55rem;
  margin: 1rem auto 0;
  color: var(--muted, #bdb6c4);
  font-size: .82rem;
}

.direct-guest-legal-links a {
  color: inherit;
  text-underline-offset: .18em;
}

.direct-guest-legal-links a:focus-visible {
  outline: 2px solid #d4af5f;
  outline-offset: 3px;
}

.shield-legal-links {
  position: absolute;
  right: 18px;
  bottom: max(12px, env(safe-area-inset-bottom));
  left: 18px;
  margin-top: 0;
}

.consent-v2-fields {
  display: grid;
  gap: .8rem;
  margin: 1rem 0;
  text-align: left;
}

.consent-v2-fields[hidden] { display: none; }

.consent-choice {
  display: grid;
  grid-template-columns: 1.4rem 1fr;
  gap: .65rem;
  align-items: start;
}

.consent-choice input {
  width: 1.2rem;
  height: 1.2rem;
  margin: .18rem 0 0;
  accent-color: #2f9e58;
}

.privacy-code-panel {
  display: grid;
  gap: .7rem;
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid rgba(255, 255, 255, .14);
}

.privacy-code-panel[hidden] { display: none; }

.privacy-code-output {
  display: block;
  min-height: 1.5rem;
  color: #d4af5f;
  font: 700 1.25rem/1.3 ui-monospace, "Cascadia Mono", monospace;
  letter-spacing: .08em;
  overflow-wrap: anywhere;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --page: #121714;
    --panel: #1c231f;
    --panel-soft: #232c27;
    --bubble: #2a342f;
    --bubble-grad-top: #303c35;
    --bubble-grad-bottom: #222d27;
    --guest-grad-top: #359985;
    --guest-grad-bottom: #1b6658;
    --text: #f2f4f2;
    --muted: #adb6b0;
    --line: #37433c;
    --accent: #2d8a78;
    --accent-dark: #46a891;
    --accent-contrast: #ffffff;
    --danger: #ef9898;
    --focus: rgba(70, 168, 145, 0.28);
    --shadow: 0 14px 40px rgba(0, 0, 0, 0.34);
  }
}

* {
  box-sizing: border-box;
}

[hidden],
.mic-button[hidden] {
  display: none !important;
}

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

body {
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
  color: var(--text);
  background: var(--page);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

button,
input,
textarea {
  font: inherit;
  letter-spacing: 0;
}

button {
  cursor: pointer;
  touch-action: manipulation;
}

button:disabled {
  cursor: default;
}

.privacy-shield {
  position: fixed;
  top: var(--direct-guest-viewport-top, 0px);
  right: 0;
  bottom: auto;
  left: 0;
  z-index: 99999;
  display: grid;
  place-items: center;
  height: var(--direct-guest-visible-height, 100dvh);
  min-height: 0;
  padding: max(20px, env(safe-area-inset-top)) 18px max(20px, env(safe-area-inset-bottom));
  color: #f7f8f7;
  background: #171a18;
}

.shield-card,
.dialog-card {
  width: min(100%, 420px);
  padding: 24px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 8px;
  background: #222724;
  box-shadow: var(--shadow);
}

.shield-card h1,
.dialog-card h2 {
  margin: 0 0 10px;
  font-size: 21px;
  font-weight: 600;
  line-height: 1.25;
}

.shield-card p {
  margin: 0 0 18px;
  color: #cbd1cd;
  line-height: 1.5;
}

.shield-mark {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  margin-bottom: 16px;
  border-radius: 50%;
  color: #bce2d8;
  background: rgba(45, 138, 120, 0.22);
  font-size: 15px;
}

.fineprint {
  margin-top: 14px !important;
  font-size: 13px;
}

.primary,
.secondary,
.danger,
.link-button,
.photo-view-button {
  min-height: 44px;
  padding: 10px 15px;
  border-radius: 8px;
  font-weight: 600;
}

.primary {
  border: 1px solid var(--accent);
  color: var(--accent-contrast);
  background: var(--accent);
}

.primary:hover,
.primary:focus-visible {
  border-color: var(--accent-dark);
  background: var(--accent-dark);
}

.secondary {
  border: 1px solid var(--line);
  color: var(--text);
  background: var(--panel-soft);
}

.danger {
  border: 1px solid currentColor;
  color: var(--danger);
  background: transparent;
}

.link-button {
  border: 0;
  color: #bce2d8;
  background: transparent;
  text-align: left;
}

form {
  display: grid;
  gap: 10px;
}

label {
  font-size: 14px;
  font-weight: 600;
}

input,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px 13px;
  color: var(--text);
  background: var(--panel);
}

input:focus,
textarea:focus,
button:focus-visible,
a:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 1px;
}

.error {
  min-height: 1.25em;
  margin: 4px 0 0 !important;
  color: #ffb4b4 !important;
  font-size: 13px;
}

.chat-shell {
  position: fixed;
  top: var(--direct-guest-viewport-top, 0px);
  left: 50%;
  width: min(100%, 760px);
  height: var(--direct-guest-visible-height, 100dvh);
  min-height: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform: translateX(-50%);
  background: var(--panel);
  box-shadow: 0 0 40px rgba(24, 32, 28, 0.12);
}

.chat-header {
  flex: 0 0 auto;
  min-height: 62px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: max(9px, env(safe-area-inset-top)) 12px 9px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.chat-profile {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 10px;
}

.chat-profile-avatar {
  width: 42px;
  height: 42px;
  flex: 0 0 42px;
  display: block;
  border-radius: 50%;
  object-fit: cover;
  background: var(--soft);
}

.chat-profile-avatar[hidden] {
  display: none;
}

.chat-profile h1 {
  flex: 1 1 auto;
  min-width: 0;
  margin: 0;
  overflow: hidden;
  font-size: 18px;
  font-weight: 600;
  line-height: 1.25;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.header-actions {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 2px;
}

.icon-button,
.composer-icon-button,
.composer-action-button {
  display: inline-grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 50%;
  line-height: 1;
}

.icon-button svg,
.composer-icon-button svg,
.composer-action-button svg,
.source-dialog-choice svg,
.message-kind-label svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.icon-button {
  width: 42px;
  min-width: 42px;
  height: 42px;
  min-height: 42px;
  color: var(--muted);
  background: transparent;
  font-size: 19px;
}

.icon-button:hover {
  color: var(--text);
  background: var(--panel-soft);
}

.nickname-card {
  flex: 0 0 auto;
  padding: 18px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--panel-soft);
}

.nickname-card h2 {
  margin: 0 0 5px;
  font-size: 18px;
  font-weight: 600;
}

.nickname-card p {
  margin: 0 0 14px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.45;
}

.nickname-card form {
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
}

.nickname-card label {
  grid-column: 1 / -1;
}

.messages {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 16px 14px 20px;
  background: var(--page);
  scrollbar-gutter: stable;
  -webkit-overflow-scrolling: touch;
}

.message {
  max-width: min(86%, 520px);
  padding: 10px 12px;
  border: 1px solid color-mix(in srgb, var(--line) 72%, transparent);
  border-radius: 18px;
  color: var(--text);
  background: linear-gradient(165deg, var(--bubble-grad-top), var(--bubble-grad-bottom));
  font-size: 15px;
  line-height: 1.35;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
  box-shadow: 0 3px 10px rgba(24, 32, 28, 0.12), inset 0 1px 0 rgba(255, 255, 255, 0.42);
}

.message.guest {
  align-self: flex-end;
  border-color: transparent;
  border-radius: 18px 18px 6px 18px;
  color: var(--accent-contrast);
  background: linear-gradient(165deg, var(--guest-grad-top), var(--guest-grad-bottom));
  box-shadow: 0 4px 14px var(--focus), inset 0 1px 0 rgba(255, 255, 255, 0.28), inset 0 -3px 8px rgba(0, 0, 0, 0.2);
}

.message.owner {
  align-self: flex-start;
  border-radius: 18px 18px 18px 6px;
}

.message-sender {
  display: block;
  margin-bottom: 4px;
  font-size: 12px;
  font-weight: 700;
  line-height: 1.2;
  opacity: 0.76;
}

.message-meta {
  display: block;
  margin-top: 5px;
  font-size: 11px;
  line-height: 1;
  text-align: right;
  white-space: nowrap;
  opacity: 0.7;
}

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

.connection-status {
  flex: 0 0 auto;
  min-height: 0;
  margin: 0;
  padding: 0 14px;
  color: var(--muted);
  background: var(--panel);
  font-size: 12px;
}

.connection-status:not(:empty) {
  min-height: 28px;
  padding-top: 6px;
}

.location-card,
.photo-card {
  min-width: min(240px, 68vw);
  display: grid;
  gap: 7px;
}

.location-card strong,
.photo-card strong {
  font-size: 14px;
  font-weight: 700;
}

.location-card a {
  width: fit-content;
  color: inherit;
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.photo-card small {
  line-height: 1.35;
  opacity: 0.82;
}

.photo-view-button {
  width: fit-content;
  border: 1px solid currentColor;
  color: inherit;
  background: rgba(255, 255, 255, 0.12);
}

.message.owner .photo-view-button {
  background: var(--panel);
}

.guest-photo-upload-card {
  width: min(260px, 68vw);
}

.guest-photo-upload-preview {
  width: 100%;
  max-height: 320px;
  display: block;
  border-radius: 12px;
  object-fit: contain;
  background: rgba(0, 0, 0, 0.08);
}

.guest-photo-upload-status {
  display: block;
}

.guest-photo-upload-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.guest-photo-upload-actions[hidden] {
  display: none;
}

.guest-photo-upload-actions button {
  min-height: 44px;
  flex: 1 1 104px;
  border: 1px solid currentColor;
  color: inherit;
  background: rgba(255, 255, 255, 0.12);
}

.composer {
  position: relative;
  z-index: 5;
  flex: 0 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 10px max(10px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: var(--panel);
}

.composer-input-bubble {
  min-width: 0;
  min-height: 44px;
  flex: 1 1 auto;
  display: flex;
  align-items: flex-end;
  gap: 2px;
  padding: 0 4px 0 12px;
  border: 1px solid var(--line);
  border-radius: 24px;
  background: var(--panel-soft);
}

.composer-input-bubble:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--focus);
}

.composer.is-owner-locked .composer-input-bubble {
  border-color: var(--line);
  box-shadow: none;
  opacity: 0.58;
}

.composer.is-owner-locked textarea {
  color: var(--muted);
  cursor: not-allowed;
}

.composer textarea {
  min-width: 0;
  min-height: 44px;
  max-height: 132px;
  flex: 1 1 auto;
  resize: none;
  overflow-y: auto;
  border: 0;
  border-radius: 0;
  padding: 11px 4px 11px 0;
  outline: 0;
  color: var(--text);
  background: transparent;
  line-height: 1.35;
}

.composer-tools {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 2px;
}

.composer-icon-button {
  width: 40px;
  min-width: 40px;
  height: 40px;
  min-height: 40px;
  color: var(--muted);
  background: transparent;
  font-size: 18px;
}

.composer-icon-button:hover,
.composer-icon-button:focus-visible {
  color: var(--accent);
  background: var(--bubble);
}

.composer-icon-button:disabled {
  opacity: 0.5;
}

.composer-action-slot {
  width: 44px;
  min-width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  align-self: flex-end;
}

.composer-action-button {
  width: 44px;
  min-width: 44px;
  height: 44px;
  min-height: 44px;
  color: var(--accent-contrast);
  background: var(--accent);
  font-size: 19px;
}

.composer-action-button:hover,
.composer-action-button:focus-visible {
  background: var(--accent-dark);
}

.composer-action-button:disabled {
  opacity: 0.48;
}

.mic-button.is-recording {
  background: var(--danger);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--danger) 24%, transparent);
  animation: direct-chat-recording-pulse 1.2s ease-in-out infinite;
}

@keyframes direct-chat-recording-pulse {
  50% { transform: scale(0.92); }
}

.source-dialog {
  width: 100%;
  max-width: none;
  margin: auto 0 0;
  padding: 0;
  border: 0;
  color: var(--text);
  background: transparent;
}

.source-dialog::backdrop {
  background: rgba(0, 0, 0, 0.56);
}

.source-dialog-card {
  display: grid;
  gap: 8px;
  padding: 16px 14px max(16px, env(safe-area-inset-bottom));
  border-radius: 8px 8px 0 0;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.source-dialog-card h2 {
  margin: 0 4px 6px;
  font-size: 17px;
}

.source-dialog-choice,
.source-dialog-cancel {
  min-height: 48px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  background: var(--panel-soft);
  font-weight: 650;
  text-align: left;
}

.source-dialog-cancel {
  color: var(--muted);
  background: transparent;
  text-align: center;
}

.audio-card {
  min-width: min(240px, 68vw);
  display: grid;
  gap: 7px;
}

.message-kind-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.message-kind-label svg {
  width: 17px;
  height: 17px;
  flex: 0 0 auto;
}

.audio-card audio {
  width: 100%;
  max-width: 300px;
  height: 40px;
}

.audio-card small {
  opacity: 0.78;
}

.audio-load-status {
  min-height: 16px;
  font-size: 12px;
}

.source-dialog-choice {
  display: flex;
  align-items: center;
  gap: 10px;
}

.photo-dialog {
  width: 100%;
  max-width: none;
  height: 100%;
  max-height: none;
  margin: 0;
  padding: 0;
  border: 0;
  color: #ffffff;
  background: rgba(0, 0, 0, 0.96);
}

.photo-dialog::backdrop {
  background: rgba(0, 0, 0, 0.96);
}

.photo-dialog-card {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 14px;
  padding: max(14px, env(safe-area-inset-top)) 14px max(14px, env(safe-area-inset-bottom));
}

.photo-dialog-card header,
.dialog-card header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.photo-dialog-card h2,
.dialog-card h2 {
  margin: 0;
}

.eyebrow {
  margin: 0 0 2px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.photo-stage {
  min-height: 0;
  display: grid;
  place-items: center;
  overflow: hidden;
}

.photo-stage img {
  display: block;
  max-width: 100%;
  max-height: calc(100dvh - 160px);
  object-fit: contain;
  user-select: none;
  -webkit-user-drag: none;
}

.photo-warning {
  margin: 0;
  color: #d5dad7;
  font-size: 13px;
  line-height: 1.4;
  text-align: center;
}

.settings-dialog {
  width: min(calc(100% - 28px), 430px);
  max-width: 430px;
  padding: 0;
  border: 0;
  color: var(--text);
  background: transparent;
}

.settings-dialog::backdrop {
  background: rgba(0, 0, 0, 0.68);
}

.dialog-card {
  color: var(--text);
  border-color: var(--line);
  background: var(--panel);
}

.dialog-card p {
  color: var(--muted);
  line-height: 1.5;
}

.dialog-card hr {
  width: 100%;
  margin: 8px 0;
  border: 0;
  border-top: 1px solid var(--line);
}

.not-found-page {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 20px;
  color: #f7f5f0;
  background: #171717;
}

.not-found-card {
  text-align: center;
}

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

@media (max-width: 520px) {
  .chat-shell {
    width: 100%;
    box-shadow: none;
  }

  .nickname-card form {
    grid-template-columns: 1fr;
  }

  .nickname-card label {
    grid-column: auto;
  }

  .message {
    max-width: 88%;
  }

  .shield-card,
  .dialog-card {
    padding: 21px;
  }
}
