:root {
  color-scheme: light;
  --page: #eef1f4;
  --surface: #ffffff;
  --surface-soft: #f7f8fa;
  --chat-area: #ffffff;
  --chrome-area: #167d87;
  --text: #17191f;
  --muted: #626b78;
  --line: rgba(24, 28, 36, 0.12);
  --accent: #167d87;
  --accent-dark: #0e5960;
  --admin: #7b3f98;
  --danger: #d93025;
  --shadow: 0 0.8rem 1.8rem rgba(0, 0, 0, 0.14);
  --radius: 0.625rem;
  --shell-gap: clamp(0.5rem, 2.5vw, 1rem);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  height: 100%;
  font-size: 16px;
  overflow: hidden;
}

body {
  min-width: 320px;
  height: 100%;
  min-height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--page);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.45;
  text-size-adjust: 100%;
}

button,
input,
textarea {
  font: inherit;
}

button {
  min-height: 2.875rem;
  border: 0;
  border-radius: 0.5rem;
  background: var(--accent);
  color: #fff;
  font-weight: 800;
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

input,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 0.5rem;
  background: #fff;
  color: var(--text);
  font-size: 1rem;
}

input {
  min-height: 3rem;
  padding: 0 0.75rem;
}

textarea {
  min-height: 3rem;
  max-height: 9rem;
  padding: 0.75rem;
  background: #fff;
  resize: vertical;
}

a {
  color: var(--accent-dark);
  text-decoration: underline;
  text-underline-offset: 0.14em;
  overflow-wrap: anywhere;
}

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

.chat-shell {
  position: fixed;
  top: var(--shell-gap);
  right: auto;
  bottom: var(--shell-gap);
  left: 50%;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  width: min(calc(100% - (var(--shell-gap) * 2)), 44rem);
  height: auto;
  min-height: 0;
  margin: 0;
  overflow: hidden;
  border: 3px solid #0e5960;
  border-radius: 1rem;
  background: var(--chrome-area);
  box-shadow: inset 0 0 0 2px var(--chrome-area), var(--shadow);
  transform: translateX(-50%);
}

.chat-topbar {
  position: sticky;
  grid-row: 1;
  grid-column: 1;
  top: 0;
  z-index: 3;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.75rem;
  align-items: center;
  padding: calc(0.75rem + env(safe-area-inset-top)) 0.15rem 0.75rem 0.875rem;
  border-bottom: 1px solid var(--line);
  background: var(--chrome-area);
  backdrop-filter: blur(0.75rem);
}

.chat-body {
  grid-row: 2;
  grid-column: 1;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  min-height: 0;
  overflow: hidden;
  background: var(--chat-area);
}

.chat-title-block {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  min-width: 0;
  min-height: auto;
  padding: 0;
  border-radius: 0.35rem;
  background: transparent;
  color: #fff;
  text-align: left;
  touch-action: manipulation;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

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

.chat-title-block *,
.guide-toggle,
.guide-toggle *,
.message-bubble[data-message-id],
.message-bubble[data-message-id] * {
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

.chat-title-block:hover,
.chat-title-block:focus-visible {
  background: transparent;
  color: #fff;
}

.chat-title-block:focus-visible {
  outline: 0.15rem solid rgba(36, 145, 255, 0.42);
  outline-offset: 0.2rem;
}

.chat-title-icon {
  width: 1.95rem;
  flex: 0 0 1.95rem;
  color: inherit;
  font-size: 1.55rem;
  line-height: 1;
  text-align: center;
}

.chat-title-heading {
  display: block;
  font-size: 1.2rem;
  font-weight: 800;
  line-height: 1.15;
}

.chat-status-line {
  display: block;
  color: rgba(255, 255, 255, 0.82);
  font-size: 0.875rem;
  font-weight: 700;
}

.guide-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
}

.guide-toggle {
  width: 2.55rem;
  min-height: 2.55rem;
  padding: 0;
  background: transparent;
  color: #fff;
  font-size: 1.45rem;
  touch-action: manipulation;
  user-select: none;
}

.guide-toggle:hover,
.guide-toggle:focus-visible {
  background: transparent;
  color: #fff;
}

.guide-toggle:focus-visible {
  outline: 0.15rem solid rgba(36, 145, 255, 0.42);
  outline-offset: 0.1rem;
}

.topbar-actions {
  position: relative;
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.topbar-menu {
  position: absolute;
  top: calc(100% + 0.35rem);
  right: 0;
  z-index: 4;
  min-width: 13rem;
  padding: 0.35rem;
  border: 1px solid var(--line);
  border-radius: 0.5rem;
  background: #fff;
  box-shadow: var(--shadow);
}

.topbar-menu button {
  display: flex;
  gap: 0.45rem;
  align-items: center;
  width: 100%;
  min-height: 2.75rem;
  padding: 0 0.8rem;
  background: transparent;
  color: var(--text);
  font-size: 0.95rem;
  font-weight: 800;
  text-align: left;
}

.topbar-menu button:hover,
.topbar-menu button:focus-visible {
  background: var(--surface-soft);
  color: var(--text);
  outline: 0;
}

.topbar-menu button i {
  width: 1.15rem;
  flex: 0 0 1.15rem;
  text-align: center;
}

.menu-profile,
.guest-menu-profile {
  display: grid;
  gap: 0.08rem;
  padding: 0.55rem 0.8rem 0.65rem;
  margin-bottom: 0.25rem;
  border-bottom: 1px solid var(--line);
}

.menu-profile span,
.guest-menu-profile span {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
}

.menu-profile strong,
.guest-menu-profile strong {
  min-width: 0;
  color: var(--text);
  font-size: 0.98rem;
  line-height: 1.2;
  overflow-wrap: anywhere;
}

.menu-version {
  padding: 0.45rem 0.8rem 0.25rem;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  text-align: right;
}

.topbar-menu .guest-logout,
.topbar-menu .admin-logout {
  background: transparent;
  color: var(--text);
}

.topbar-menu .danger-button {
  background: transparent;
  color: var(--danger);
}

.topbar-menu .success-button {
  background: transparent;
  color: #138a36;
}

.notice-panel,
.join-panel {
  margin: 0.875rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-soft);
}

.notice-panel {
  grid-row: 1;
  grid-column: 1;
}

.join-panel,
.guide-panel {
  grid-row: 2;
  grid-column: 1;
}

.guide-panel {
  margin: 0.875rem;
  border: 0;
  background: transparent;
  padding: 0;
}

.panel-back {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  width: fit-content;
  min-height: 2.25rem;
  margin-bottom: 0.75rem;
  padding: 0;
  background: transparent;
  color: var(--accent);
  font-size: 0.95rem;
  font-weight: 800;
}

.panel-back i {
  font-size: 0.78rem;
}

.panel-back:hover,
.panel-back:focus-visible {
  background: transparent;
  color: var(--accent);
}

.panel-back:focus-visible {
  outline: 0.15rem solid rgba(36, 145, 255, 0.42);
  outline-offset: 0.12rem;
}

.notice-panel,
.join-panel {
  padding: 1rem;
}

.notice-panel p {
  margin: 0;
  color: var(--muted);
  font-size: 1rem;
  font-weight: 700;
}

.open-status-text {
  color: #138a36;
  font-weight: 800;
}

.closed-status-text {
  color: #d92d20;
  font-weight: 800;
}

.join-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.75rem;
  margin-bottom: 0.875rem;
}

.join-button {
  padding-right: 1.25rem;
  padding-left: 1.25rem;
}

label span,
.pin-form label,
.guide-card label,
.guide-controls label {
  display: block;
  margin-bottom: 0.35rem;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
  text-transform: uppercase;
}

.form-note {
  min-height: 1.25rem;
  margin: 0.7rem 0 0;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
}

.join-panel .form-note:empty {
  display: none;
}

.inline-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 6.25rem;
  gap: 0.625rem;
}

.guide-controls {
  display: grid;
  gap: 1rem;
  padding-top: 0;
}

.danger-button {
  background: var(--danger);
}

.pin-form,
.guide-card {
  display: grid;
  gap: 0.625rem;
  padding: 1rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-soft);
}

.guide-users-card h2 {
  margin: 0;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
  text-transform: uppercase;
}

.guide-users-list {
  display: grid;
  gap: 0.55rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.guide-users-list li {
  display: grid;
  grid-template-columns: 0.65rem minmax(0, 1fr) auto;
  gap: 0.55rem;
  align-items: center;
  color: var(--text);
  font-weight: 800;
}

.guide-users-list .empty-users {
  display: block;
  color: var(--muted);
}

.user-status-dot {
  width: 0.65rem;
  height: 0.65rem;
  border-radius: 999px;
  background: #9aa3af;
}

.guide-users-list .online .user-status-dot {
  background: #15a05f;
}

.user-status-label {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.intro-save-row {
  min-height: 0;
  margin-top: 0;
}

.save-status {
  display: block;
  color: var(--muted);
  font-size: 0.92rem;
  font-weight: 800;
  text-align: right;
}

.save-status:empty {
  display: none;
}

.save-status.saved {
  color: #12733b;
}

.save-status.saving {
  color: var(--muted);
}

.save-status.saved::before {
  margin-right: 0.35rem;
  content: "\2713";
}

.save-status.error {
  color: var(--danger);
}

.chat-panel {
  grid-row: 3;
  grid-column: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 0.875rem 0 1rem;
  background: var(--chat-area);
  scroll-behavior: smooth;
}

.message-list {
  display: grid;
  gap: 0.75rem;
  margin: 0;
  padding: 0 0.875rem;
  list-style: none;
}

.message {
  display: flex;
  align-items: flex-start;
}

.message.admin {
  justify-content: flex-start;
}

.message.guest {
  justify-content: flex-end;
}

.message-bubble {
  position: relative;
  width: 80%;
  min-width: 0;
  overflow: hidden;
  padding: 0.78rem 0.85rem;
  border: 1px solid rgba(24, 28, 36, 0.08);
  border-radius: 0.75rem;
  background: #ebedf1;
  box-shadow: 0 0.35rem 1rem rgba(24, 28, 36, 0.06);
}

.message.admin .message-bubble {
  border-color: rgba(123, 63, 152, 0.14);
  background: #f6eff9;
  box-shadow: inset 0 0 0 1px rgba(123, 63, 152, 0.14);
}

.message-bubble[data-message-id] {
  touch-action: manipulation;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

.message-content {
  transition: filter 160ms ease, opacity 160ms ease;
}

.message-bubble.delete-armed .message-content {
  filter: blur(2px);
  opacity: 0.42;
}

.message-delete-button {
  position: absolute;
  top: 50%;
  left: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 3rem;
  height: 3rem;
  min-height: 3rem;
  padding: 0;
  border-radius: 999px;
  background: var(--danger);
  color: #fff;
  font-size: 1.05rem;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, -50%) scale(0.92);
  transition: opacity 160ms ease, transform 160ms ease;
}

.message-bubble.delete-armed .message-delete-button {
  opacity: 1;
  pointer-events: auto;
  transform: translate(-50%, -50%) scale(1);
}

.message-meta {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.35rem;
}

.message-name {
  min-width: 0;
  color: var(--text);
  font-weight: 800;
  overflow-wrap: anywhere;
}

.message-time {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
}

.message-text {
  color: #424b58;
  font-size: 1rem;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.empty-messages {
  margin: 1rem 0;
  padding: 1rem;
  border-radius: var(--radius);
  background: var(--surface-soft);
  color: var(--muted);
  font-weight: 700;
  text-align: center;
}

.composer {
  position: sticky;
  grid-row: 3;
  grid-column: 1;
  bottom: 0;
  z-index: 2;
  display: grid;
  grid-template-columns: 3rem minmax(0, 1fr) 3rem;
  gap: 0;
  padding: 0.65rem 0.875rem 0.8rem 0;
  background: var(--chrome-area);
  backdrop-filter: blur(0.75rem);
}

.composer-input-wrap {
  position: relative;
  display: grid;
  min-width: 0;
}

.composer-input-wrap textarea {
  border-color: rgba(24, 28, 36, 0.08);
  background: #fff;
  box-shadow: 0 0.35rem 1.2rem rgba(24, 28, 36, 0.08);
  resize: none;
}

.composer button {
  width: 3rem;
  height: 3rem;
  min-height: 3rem;
  padding: 0;
  border-radius: 0.4rem;
  background: transparent;
  color: #fff;
  box-shadow: none;
  font-size: 1.35rem;
}

.composer-add {
  color: #fff;
}

.composer-add i {
  transition: transform 180ms ease;
}

.composer-add[aria-expanded="true"] i {
  transform: rotate(45deg);
}

.composer-add:hover,
.composer-add:focus-visible {
  background: transparent;
  color: #fff;
}

.attachment-menu {
  position: absolute;
  bottom: calc(100% + 0.55rem);
  left: 0.45rem;
  z-index: 4;
  width: min(19.5rem, calc(100% - 5rem));
  padding: 0;
  border: 1px solid rgba(24, 28, 36, 0.12);
  border-radius: 1.1rem;
  background: rgba(255, 255, 255, 0.98);
  box-shadow: 0 1rem 2.5rem rgba(24, 28, 36, 0.18);
  opacity: 0;
  pointer-events: none;
  overflow: hidden;
  transform: translate(-0.35rem, 0.75rem) scale(0.95);
  transform-origin: bottom left;
  transition: opacity 180ms ease, transform 180ms cubic-bezier(0.2, 0.8, 0.2, 1);
}

.attachment-menu.is-open {
  opacity: 1;
  pointer-events: auto;
  transform: translate(0, 0) scale(1);
}

.attachment-menu button {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  height: auto;
  min-height: 3.95rem;
  padding: 0 1rem;
  border-radius: 0;
  background: transparent;
  color: var(--text);
  box-shadow: none;
  font-size: 1.18rem;
  font-weight: 800;
  text-align: left;
}

.attachment-menu button + button {
  border-top: 1px solid rgba(24, 28, 36, 0.12);
}

.attachment-menu button:hover,
.attachment-menu button:focus-visible {
  background: var(--surface-soft);
  color: var(--text);
  outline: 0;
}

.attachment-menu i {
  order: 2;
  width: 1.35rem;
  margin-left: 1.25rem;
  color: var(--text);
  text-align: center;
}

.attachment-menu span {
  order: 1;
}

@media (max-width: 24rem) {
  .chat-topbar {
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 0.5rem;
  }

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

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