:root {
  --bg: #f2f2f7;
  --nav: rgba(249, 249, 249, 0.92);
  --text: #000;
  --sub: #8e8e93;
  --hairline: rgba(0, 0, 0, 0.16);
  --blue: #0b84fe;
  --blue-press: #0066d6;
  --mine: #0b84fe;
  --theirs: #e9e9eb;
  --theirs-text: #000;
  --composer: #ffffff;
  --field: #e9e9eb;
  --chip: #e9e9eb;
  --shadow: 0 1px 0 var(--hairline);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000;
    --nav: rgba(28, 28, 30, 0.92);
    --text: #fff;
    --sub: #8e8e93;
    --hairline: rgba(255, 255, 255, 0.18);
    --mine: #0b84fe;
    --theirs: #26252a;
    --theirs-text: #fff;
    --composer: #1c1c1e;
    --field: #2c2c2e;
    --chip: #2c2c2e;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font: 17px/1.35 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", system-ui, sans-serif;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}
body { overflow: hidden; }

.screen {
  display: flex;
  flex-direction: column;
  height: 100%;
  height: 100dvh;
}
.screen[hidden] { display: none; }

/* ---- name gate ---- */
#gate {
  align-items: center;
  justify-content: center;
  padding: 32px 24px calc(32px + env(safe-area-inset-bottom));
}
.gate-inner { width: 100%; max-width: 360px; text-align: center; }
.gate-icon { font-size: 52px; line-height: 1; margin-bottom: 12px; }
#gate h1 { font-size: 28px; letter-spacing: -0.4px; margin: 0 0 8px; }
.gate-sub { color: var(--sub); margin: 0 0 28px; }
#gate-form { display: flex; flex-direction: column; gap: 12px; }
#gate-name, #gate-form button, #composer-input {
  font-size: 16px; /* prevents iOS Safari zoom on focus */
}
#gate-name {
  width: 100%;
  border: none;
  border-radius: 12px;
  background: var(--field);
  color: var(--text);
  padding: 14px 16px;
  outline: none;
}
#gate-form button {
  border: none;
  border-radius: 12px;
  background: var(--blue);
  color: #fff;
  font-weight: 600;
  padding: 14px 16px;
}
#gate-form button:active { background: var(--blue-press); }

/* ---- nav ---- */
.nav {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  min-height: 52px;
  padding: calc(6px + env(safe-area-inset-top)) 16px 10px;
  background: var(--nav);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 0.5px solid var(--hairline);
}
.nav-center { text-align: center; }
.nav-title { font-weight: 600; font-size: 17px; letter-spacing: -0.2px; }
.nav-sub {
  display: block;
  margin: 1px auto 0;
  border: 0;
  background: none;
  color: var(--blue);
  font: inherit;
  font-size: 12px;
  padding: 0;
  cursor: pointer;
}

/* ---- message log ---- */
.log {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 10px 12px 8px;
  overscroll-behavior: contain;
}
.day {
  text-align: center;
  color: var(--sub);
  font-size: 12px;
  font-weight: 500;
  margin: 10px 0 8px;
}
.row {
  display: flex;
  flex-direction: column;
  margin: 2px 0 6px;
  max-width: 78%;
}
.row.mine { margin-left: auto; align-items: flex-end; }
.row.theirs { margin-right: auto; align-items: flex-start; }
.meta {
  font-size: 11px;
  color: var(--sub);
  font-weight: 500;
  margin: 0 8px 3px;
}
.bubble {
  padding: 7px 12px;
  border-radius: 18px;
  word-wrap: break-word;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}
.row.mine .bubble {
  background: var(--mine);
  color: #fff;
  border-bottom-right-radius: 5px;
}
.row.theirs .bubble {
  background: var(--theirs);
  color: var(--theirs-text);
  border-bottom-left-radius: 5px;
}
.row.bot .bubble { border-bottom-left-radius: 5px; }

/* ---- composer ---- */
.composer {
  position: sticky;
  bottom: 0;
  background: var(--composer);
  border-top: 0.5px solid var(--hairline);
  padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
}
.chips {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  padding: 2px 2px 8px;
  scrollbar-width: none;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto;
  border: 0;
  background: var(--chip);
  color: var(--text);
  font: inherit;
  font-size: 13px;
  padding: 6px 10px;
  border-radius: 999px;
}
.chip:active { opacity: 0.7; }
.composer-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}
#composer-input {
  flex: 1;
  resize: none;
  border: 0;
  background: var(--field);
  color: var(--text);
  border-radius: 20px;
  padding: 8px 14px;
  max-height: 120px;
  line-height: 1.3;
  outline: none;
  font-family: inherit;
}
.send {
  flex: 0 0 auto;
  width: 32px;
  height: 32px;
  margin-bottom: 2px;
  border: 0;
  border-radius: 50%;
  background: var(--blue);
  color: #fff;
  display: grid;
  place-items: center;
  padding: 0;
}
.send:disabled { background: #c7c7cc; color: #fff; }
.send svg { display: block; transform: rotate(-90deg); }

.typing {
  color: var(--sub);
  font-size: 13px;
  padding: 4px 8px 10px;
}
