:root {
  color-scheme: light dark;
  --page: light-dark(#f0f0f3, #101013);
  --paper: light-dark(#fff, #080809);
  --surface: light-dark(#fff, #202023);
  --ink: light-dark(#161619, #f4f4f5);
  --muted: light-dark(#57575d, #aba9b0);
  --accent: light-dark(#0669bf, #79bcff);
  --accent-strong: light-dark(#185f9d, #acd5ff);
  --primary: light-dark(#086bc7, #68b2ff);
  --primary-hover: light-dark(#075ba8, #8ac4ff);
  --primary-ink: light-dark(#fff, #0e1929);
  --line: light-dark(#dcdce0, #3e3e44);
  --tint: light-dark(#f0f0f3, #252529);
  --hover: light-dark(#e8e8ed, #303034);
  --focus: light-dark(#0876d3, #79bcff);
  --thread: var(--paper);
  --bubble-in: light-dark(#e9e9ec, #252527);
  --bubble-out: light-dark(#006dca, #086bc7);
  --bubble-out-light: #0876d3;
  --glass: var(--surface);
  --glass-sheet: var(--surface);
  --glass-edge: light-dark(#b3b3bc66, #d1d0d43a);
  --glass-shine: light-dark(#ffffffdf, #f4f4f72a);
  --glass-shadow: light-dark(#2828321a, #0007);
  --glass-filter: blur(20px) saturate(145%);
  --danger: light-dark(#a34337, #ffac9e);
  --danger-solid: light-dark(#a34337, #a8473b);
  --sheet-shadow: light-dark(#17172546, #0009);
  font: 100%/1.55 system-ui, -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--ink);
  background: var(--page);
}
:root[data-text-size="0"] { font-size: 87.5%; }
:root[data-text-size="2"] { font-size: 112.5%; }
:root[data-text-size="3"] { font-size: 125%; }
:root[data-text-size="4"] { font-size: 137.5%; }
:root[data-theme="light"], [data-preview="light"] { color-scheme: only light; }
:root[data-theme="dark"], [data-preview="dark"] { color-scheme: dark; }
[data-preview="system"] { color-scheme: light dark; }

@supports ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  :root {
    --glass: light-dark(#ffffffe3, #252527df);
    --glass-sheet: light-dark(#fffffff2, #202023f0);
  }
}
@media (prefers-reduced-transparency: reduce), (prefers-contrast: more) {
  :root {
    --glass: var(--surface);
    --glass-sheet: var(--surface);
    --glass-edge: var(--line);
    --glass-filter: none;
  }
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; min-height: 100%; }
body { min-height: 100dvh; }
button, input, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; }
button:disabled { opacity: .53; cursor: default; }
button:focus-visible, a:focus-visible, input:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 3px;
}
h1, h2, h3, p { margin: 0; }
.icon-defs { position: absolute; width: 0; height: 0; overflow: hidden; }
.icon { width: 1.25rem; height: 1.25rem; fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; flex: none; pointer-events: none; }
.button, .icon-button {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  gap: .55rem;
  border: 1px solid transparent;
  border-radius: 18px;
  min-height: 48px;
  padding: .65rem 1rem;
  color: var(--ink);
  font-weight: 650;
  text-decoration: none;
  background: transparent;
  transition: background-color .16s, border-color .16s, color .16s;
}
.button.compact { font-size: .875rem; min-height: 42px; padding: .42rem .8rem; }
.button.primary, .icon-button.filled { color: var(--primary-ink); background: var(--primary); }
.button.primary:hover, .filled:hover { background: var(--primary-hover); }
.button.secondary { background: var(--surface); color: var(--accent-strong); border-color: var(--line); }
.button.secondary:hover { background: var(--hover); border-color: var(--line); }
.button.quiet, .icon-button { color: var(--accent-strong); }
.button.quiet:hover, .icon-button:not(.filled):hover { background: var(--hover); }
.icon-button { padding: .5rem; width: 44px; min-height: 44px; flex: 0 0 auto; border-radius: 50%; }
.glass {
  border: 1px solid var(--glass-edge);
  background: var(--glass);
  box-shadow: inset 0 1px 0 var(--glass-shine), 0 4px 18px var(--glass-shadow);
  -webkit-backdrop-filter: var(--glass-filter);
  backdrop-filter: var(--glass-filter);
}
.button.danger { color: var(--danger); background: light-dark(#fff4f1, #372823); border-color: light-dark(#f0d8d1, #704c42); }
.button.danger-solid { color: #fff; background: var(--danger-solid); }
.button.danger-solid:hover { background: light-dark(#8b3228, #984036); }

.welcome {
  min-height: 100dvh;
  background:
    radial-gradient(ellipse at 27% 20%, light-dark(#e8eef8, #171d2a), transparent 52%),
    radial-gradient(ellipse at 82% 76%, light-dark(#f1f1f5, #15151c), transparent 53%),
    var(--paper);
}
.site-bar {
  max-width: 1080px;
  margin-inline: auto;
  min-height: 76px;
  padding: max(14px, env(safe-area-inset-top)) max(26px, env(safe-area-inset-right)) 14px max(26px, env(safe-area-inset-left));
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.brand { display: inline-flex; align-items: center; gap: .65rem; font-weight: 820; letter-spacing: .08em; font-size: 1.2rem; }
.brand img { border-radius: 10px; }
.entry { display: grid; justify-items: center; padding: clamp(34px, 10vh, 104px) 20px 46px; }
.entry-card {
  width: min(100%, 438px);
  padding: clamp(25px, 7vw, 40px);
  border-radius: 32px;
  box-shadow: inset 0 1px 0 var(--glass-shine), 0 20px 55px var(--glass-shadow);
}
.main-mark { display: block; margin-bottom: 23px; border-radius: 24%; box-shadow: 0 6px 13px #2d3c5823; }
.entry h1 { font-size: clamp(1.65rem, 6vw, 2.2rem); line-height: 1.22; letter-spacing: -.035em; }
.subtitle { margin-top: 10px; color: var(--muted); }
.entry-actions, #invite-code-section { display: grid; gap: 10px; margin-top: 28px; }
.restore-control { width: 100%; margin-top: .65rem; font-size: .875rem; }
.code-value {
  display: block;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--tint);
  color: var(--accent-strong);
  font: .875rem/1.6 ui-monospace, SFMono-Regular, Consolas, monospace;
  overflow-wrap: anywhere;
  user-select: all;
}
.time-caption { font-variant-numeric: tabular-nums; font-size: .875rem; color: var(--muted); margin-top: 1rem; }
#confirm-pair { width: 100%; margin-top: 1rem; }

.chat {
  --chat-top: calc(64px + env(safe-area-inset-top));
  --chat-bottom: calc(74px + env(safe-area-inset-bottom));
  --chat-gutter: clamp(14px, 4.4vw, 28px);
  height: 100vh;
  height: 100dvh;
  max-width: 830px;
  margin-inline: auto;
  position: relative;
  overflow: hidden;
  background: var(--thread);
  box-shadow: 0 0 50px var(--glass-shadow);
}
.chat-chrome {
  position: absolute;
  z-index: 2;
  inset: 0 0 auto;
  padding: env(safe-area-inset-top) max(var(--chat-gutter), env(safe-area-inset-right)) 6px max(var(--chat-gutter), env(safe-area-inset-left));
  background: linear-gradient(to bottom, var(--thread) 2%, transparent 96%);
  pointer-events: none;
}
.chat-bar {
  display: grid;
  grid-template-columns: 46px minmax(0, 1fr) 46px;
  align-items: center;
  gap: .45rem;
  padding: 8px 0 3px;
}
.chat-bar button, .cooling { pointer-events: auto; }
.chat-install, .settings-button {
  width: 46px;
  height: 46px;
  grid-row: 1;
  color: var(--ink);
}
.chat-install { grid-column: 1; }
.settings-button { grid-column: 3; }
.chat-person {
  grid-column: 2;
  grid-row: 1;
  justify-self: center;
  min-width: 0;
  max-width: min(100%, 270px);
  padding: .27rem .78rem .32rem;
  border-radius: 22px;
  text-align: center;
}
.chat-person h1 { font-size: 1rem; line-height: 1.24; font-weight: 750; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-meta { display: flex; align-items: center; justify-content: center; flex-wrap: wrap; gap: 0 .37rem; margin-top: .15rem; color: var(--muted); font-size: .7rem; }
#peer-presence[data-online="true"] { color: var(--accent); font-weight: 680; }
#peer-presence:not(:empty) + .encrypted::before { content: "·"; margin-right: .08rem; color: var(--muted); }
.encrypted { display: inline-flex; align-items: center; gap: .2rem; color: var(--accent-strong); white-space: nowrap; }
.encrypted .icon { width: .75rem; height: .75rem; }
.connection { text-align: center; padding: .35rem .85rem; font-size: .8rem; border-radius: 18px; margin-top: .35rem; }
.cooling { display: flex; align-items: center; gap: .6rem; padding: 8px 12px; margin-top: .35rem; border: 1px solid light-dark(#edddbd, #604b2a); border-radius: 20px; background: light-dark(#fff7e7, #332819); color: light-dark(#725623, #f2cb87); font-size: .8rem; }
.cooling > div { flex: 1; }
.cooling p { margin-top: .12rem; }
.cooling .button { flex-shrink: 0; }

.thread {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  padding: calc(var(--chat-top) + 10px) max(var(--chat-gutter), env(safe-area-inset-right))
    calc(var(--chat-bottom) + 9px) max(var(--chat-gutter), env(safe-area-inset-left));
  scroll-padding-block: var(--chat-top) var(--chat-bottom);
  overflow-y: auto;
  overscroll-behavior-y: contain;
  background-color: var(--thread);
}
.history-control { display: flex; justify-content: center; margin: 0 0 9px; }
.thread-empty { display: grid; justify-items: center; text-align: center; margin: auto; color: var(--muted); padding: 1rem 0; }
.thread-empty p { margin: .75rem 0 .12rem; font-weight: 700; color: var(--ink); }
.thread-empty > span:last-child { font-size: .875rem; }
.empty-lock { color: var(--accent); background: var(--tint); border: 1px solid var(--line); width: 56px; height: 56px; border-radius: 22px; display: grid; place-items: center; }
.empty-lock .icon { width: 1.55rem; height: 1.55rem; }
.messages { display: flex; flex-direction: column; flex-shrink: 0; gap: 4px; list-style: none; margin: auto 0 0; padding: 0; }
.day { align-self: center; margin: .85rem 0 .48rem; padding: .15rem .5rem; font-size: .75rem; font-weight: 650; color: var(--muted); }
.message { display: flex; align-self: flex-start; max-width: min(83%, 540px); min-width: 0; }
.message.mine { align-self: flex-end; }
.message:not(.mine) + .mine, .message.mine + .message:not(.mine) { margin-top: 5px; }
.bubble { min-width: 62px; max-width: 100%; border-radius: 22px 22px 22px 8px; padding: .46rem .75rem .35rem; background: var(--bubble-in); }
.mine .bubble {
  background: linear-gradient(155deg, var(--bubble-out-light), var(--bubble-out));
  color: #fff;
  border-radius: 22px 22px 8px 22px;
}
.message:not(.mine):has(+ .message:not(.mine)) .bubble, .message.mine:has(+ .message.mine) .bubble { border-radius: 22px; }
.bubble p { font-size: .975rem; white-space: pre-wrap; overflow-wrap: anywhere; }
.bubble p.unavailable { color: var(--muted); font-size: .875rem; }
.bubble time { display: block; text-align: right; color: var(--muted); font-size: .7rem; font-variant-numeric: tabular-nums; margin-top: .12rem; }
.mine .bubble time, .mine .bubble p.unavailable { color: #fff; }
.bubble time .icon { color: currentColor; width: .85rem; height: .85rem; vertical-align: -.17rem; margin-inline-start: .22rem; }
.bubble time[data-receipt='read'] .icon { stroke-width: 2.15; }
.picture { padding: 0; border: 0; background: transparent; display: block; max-width: 100%; }
.picture img { display: block; object-fit: contain; max-width: 100%; height: auto; max-height: 330px; background: var(--tint); border-radius: 17px; }
.bubble .picture + p { margin-top: .35rem; }
.message.photo-only .bubble { background: transparent; padding: 0; }
.message.photo-only .bubble time { padding-inline: .3rem; color: var(--muted); }
audio { display: block; max-width: 100%; width: 260px; height: 42px; }
.image-download-message { color: var(--accent-strong); background: var(--tint); padding: .45rem .7rem; border-radius: 12px; display: block; font-size: .875rem; overflow-wrap: anywhere; }
.jump { position: absolute; right: var(--chat-gutter); bottom: calc(var(--chat-bottom) + 7px); z-index: 1; }

.composer {
  position: absolute;
  z-index: 2;
  inset: auto 0 0;
  padding: 9px max(var(--chat-gutter), env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(var(--chat-gutter), env(safe-area-inset-left));
  background: linear-gradient(to top, var(--thread) 4%, transparent 95%);
  pointer-events: none;
}
#compose { display: flex; align-items: end; gap: .55rem; }
.composer-field, .composer .media-button, .composer .attachment-draft { pointer-events: auto; }
.composer .media-button {
  width: 46px;
  height: 46px;
  color: var(--ink);
  margin-bottom: 1px;
}
.composer-field {
  display: flex;
  align-items: end;
  flex: 1;
  min-width: 0;
  padding: 1px 3px 1px 0;
  border-radius: 25px;
}
.composer .filled { border-radius: 50%; }
.composer .recording { color: #fff; background: var(--danger-solid); }
.composer #record { color: var(--muted); }
.composer #send, .composer #stop-record { width: 44px; min-height: 44px; }
input, textarea { display: block; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); color: var(--ink); padding: .58rem .72rem; width: 100%; min-width: 0; }
input:not([type="range"]):not([type="radio"]), textarea { font-size: max(1rem, 16px); }
textarea { resize: vertical; }
#text {
  flex: 1;
  resize: none;
  line-height: 1.4;
  min-height: 44px;
  max-height: 112px;
  padding: .66rem .36rem .66rem .95rem;
  border: 0;
  border-radius: 23px;
  background: transparent;
}
#text:focus-visible { outline: none; }
.composer-field:focus-within { border-color: var(--focus); }
#text::placeholder, input::placeholder, textarea::placeholder { color: var(--muted); }
.attachment-draft { display: flex; align-items: center; justify-content: space-between; padding: 7px 8px 8px; margin-bottom: 7px; border-radius: 20px; }
#draft-preview { display: flex; align-items: center; min-width: 0; gap: .6rem; overflow: hidden; }
#draft-preview img { display: block; border-radius: 6px; max-width: 65px; max-height: 50px; flex: none; }
#draft-preview span { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; font-size: .875rem; }
.record-status { display: flex; align-items: center; flex: 1; gap: .55rem; min-width: 0; min-height: 44px; padding-inline-start: .8rem; font-variant-numeric: tabular-nums; }
.record-status > span { width: 9px; height: 9px; border-radius: 50%; background: var(--danger); }
.record-status .button { margin-left: auto; }
#send-status { color: var(--muted); text-align: end; font-size: .8rem; padding: 4px 14px 0; }

dialog {
  width: min(calc(100% - 28px), 435px);
  max-height: min(calc(100dvh - 30px), 720px);
  overflow: auto;
  color: var(--ink);
  background: var(--glass-sheet);
  border: 1px solid var(--glass-edge);
  box-shadow: inset 0 1px 0 var(--glass-shine), 0 24px 80px var(--sheet-shadow);
  -webkit-backdrop-filter: var(--glass-filter);
  backdrop-filter: var(--glass-filter);
  border-radius: 30px;
  padding: 18px 20px 21px;
}
dialog::backdrop { background: light-dark(#31313c40, #0606099e); }
.dialog-bar { display: flex; align-items: center; justify-content: space-between; gap: .4rem; }
.dialog-bar h2 { font-size: 1.25rem; line-height: 1.28; }
.dialog-bar .icon-button { margin-right: -.4rem; }
dialog p { margin: .35rem 0 1rem; color: var(--muted); font-size: .935rem; }
dialog label, dialog h3 { display: block; font-size: .94rem; font-weight: 720; margin-bottom: .35rem; }
dialog form > .primary { margin-top: 12px; width: 100%; }
.dialog-actions, .input-row { display: flex; gap: .5rem; align-items: center; }
.dialog-actions { justify-content: end; flex-wrap: wrap; }
.input-row input { flex: 1; }
.settings-section { border-top: 1px solid var(--line); padding-top: .85rem; margin-top: .85rem; }
.settings-section p { margin: 0 0 .6rem; }
.settings-section textarea { margin-top: .6rem; font-family: ui-monospace, monospace; font-size: .875rem; }
.install-steps { display: grid; gap: .75rem; padding-left: 1.4rem; margin: .8rem 0 1.1rem; }
.install-steps strong, .install-steps span { display: block; }
.install-steps span { color: var(--muted); }
.image-dialog { width: fit-content; max-width: calc(100% - 18px); padding: 9px; }
.image-actions { display: flex; justify-content: end; }
.image-dialog img { display: block; margin: auto; max-width: 100%; max-height: 75dvh; object-fit: contain; border-radius: 10px; }
.toast { position: fixed; z-index: 5; inset: auto auto max(86px, calc(75px + env(safe-area-inset-bottom))) 50%; transform: translateX(-50%); padding: .6rem .95rem; border-radius: 12px; background: light-dark(#25262a, #efeff2); color: light-dark(#fff, #202027); max-width: min(85%, 450px); width: max-content; font-size: .9rem; box-shadow: 0 4px 16px #28283224; }
.no-script { padding: 1rem; text-align: center; }
@media (max-width: 480px) {
  .site-bar { min-height: 66px; padding-inline: 20px; }
  .entry { padding-top: clamp(35px, 9vh, 64px); }
  .main-mark { width: 64px; height: 64px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; scroll-behavior: auto !important; }
}

.dialog-feedback { background: var(--tint); color: var(--accent-strong); padding: .52rem .65rem; border-radius: 8px; }
#retry-pair { width: 100%; margin-top: .7rem; }

.settings-actions { display: flex; flex-wrap: wrap; gap: .35rem; }
.license { display: inline-block; margin-top: .8rem; color: var(--muted); font-size: .8rem; }


.site-actions { display: flex; align-items: center; gap: .3rem; }
.appearance-button { width: 100%; justify-content: start; }
#theme-current { margin-inline-start: auto; color: var(--muted); font-size: .875rem; }
.theme-picker {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: .55rem;
  border: 0;
  margin: .8rem 0 0;
  padding: 0;
  min-inline-size: 0;
}
.visually-hidden, .theme-choice input {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  clip-path: inset(50%);
  overflow: hidden;
  white-space: nowrap;
}
.theme-picker .theme-choice {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto 1fr;
  min-width: 0;
  gap: .45rem;
  margin: 0;
  padding: .27rem .27rem .55rem;
  border: 1px solid var(--line);
  border-radius: 17px;
  text-align: center;
  color: var(--muted);
  cursor: pointer;
}
.theme-choice:hover { background: var(--hover); }
.theme-choice:has(input:checked) {
  border-color: var(--accent);
  background: var(--tint);
  color: var(--accent-strong);
  box-shadow: inset 0 0 0 1px var(--accent);
}
.theme-choice:has(input:focus-visible) { outline: 2px solid var(--focus); outline-offset: 2px; }
.theme-choice input { margin: 0; padding: 0; }
.theme-swatch {
  position: relative;
  width: 100%;
  min-width: 0;
  min-height: 49px;
  aspect-ratio: 1.48;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--thread);
}
.theme-swatch::before, .theme-swatch::after {
  content: "";
  position: absolute;
  height: 19%;
  border: 1px solid var(--line);
}
.theme-swatch::before {
  inset: 25% auto auto 13%;
  width: 42%;
  border-radius: 7px 7px 7px 2px;
  background: var(--bubble-in);
}
.theme-swatch::after {
  inset: auto 13% 25% auto;
  width: 48%;
  border-radius: 7px 7px 2px 7px;
  background: var(--bubble-out);
}
.theme-name { font-size: .875rem; }

.font-settings { margin-top: 1rem; padding-top: .95rem; border-top: 1px solid var(--line); }
.font-heading { display: flex; align-items: baseline; justify-content: space-between; gap: .5rem; }
.font-heading label { margin: 0; }
#text-size-name { color: var(--muted); font-size: .875rem; }
.font-control {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: .72rem;
  color: var(--muted);
  font-weight: 650;
}
.font-control span:first-child { font-size: .8rem; }
.font-control span:last-child { font-size: 1.2rem; }
.font-control input {
  min-height: 44px;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 7px;
  background: transparent;
  accent-color: var(--accent);
}
.font-preview {
  display: flex;
  align-items: start;
  padding: .75rem;
  border: 1px solid var(--line);
  border-radius: 17px;
  background: var(--thread);
}
.font-preview p { margin: 0; color: var(--ink); }
