:root {
  color-scheme: light dark;
  --canvas: #fcf2f4;
  --canvas-tint: #f3dbe2;
  --surface: #fffafb;
  --paper: #fdf4f6;
  --ink: #39232f;
  --muted: #725664;
  --rose: #9f4165;
  --rose-hover: #843351;
  --on-rose: #fff;
  --ring: #a74869;
  --edge: #e8ccd6;
  --soft: #f5e1e8;
  --own: #f3d2df;
  --own-edge: #e9c1d2;
  --danger: #9b304d;
  --shadow: 0 24px 80px #793d5321, 0 4px 16px #793d530d;
  --serif: ui-serif, "Georgia", serif;
  font: 16px -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --canvas: #2b1b25;
    --canvas-tint: #462534;
    --surface: #38252f;
    --paper: #301f29;
    --ink: #fff1f5;
    --muted: #e0b9ca;
    --rose: #e6a0ba;
    --rose-hover: #f3bfd1;
    --on-rose: #361e2c;
    --ring: #f0afc7;
    --edge: #654254;
    --soft: #4c3040;
    --own: #63394e;
    --own-edge: #7a485e;
    --danger: #ffadc2;
    --shadow: 0 24px 80px #16091280;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background:
    radial-gradient(ellipse at 12% 6%, var(--surface), transparent 48%),
    radial-gradient(ellipse at 88% 98%, var(--canvas-tint), transparent 62%),
    var(--canvas);
  color: var(--ink);
}

button, input { font: inherit; }
button {
  min-height: 44px;
  border: 1px solid var(--edge);
  border-radius: 999px;
  background: var(--surface);
  color: var(--ink);
  padding: 8px 14px;
  cursor: pointer;
}

button:disabled { opacity: .55; cursor: default; }
button:focus-visible, input:focus-visible, .history:focus-visible {
  outline: 2px solid var(--ring);
  outline-offset: 2px;
}

input {
  min-width: 0;
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--edge);
  border-radius: 17px;
  padding: 12px 14px;
}

input::placeholder { color: var(--muted); }
.primary { background: var(--rose); border-color: var(--rose); color: var(--on-rose); font-weight: 700; }
.quiet { background: var(--soft); color: var(--ink); }
@media (hover: hover) {
  .primary:not(:disabled):hover { background: var(--rose-hover); border-color: var(--rose-hover); }
  .quiet:not(:disabled):hover { border-color: var(--ring); }
}

.app {
  display: grid;
  place-items: center;
  max-width: 800px;
  min-height: 100vh;
  min-height: 100dvh;
  margin: auto;
}

.login {
  width: min(calc(100% - 32px), 440px);
  margin-block: max(18px, env(safe-area-inset-top)) max(18px, env(safe-area-inset-bottom));
  padding: clamp(22px, 7vw, 44px);
  background: var(--surface);
  border: 1px solid var(--edge);
  border-radius: 32px;
  box-shadow: var(--shadow);
  text-align: center;
}

.brand-icon { display: block; flex-shrink: 0; border-radius: 26%; }
.login .brand-icon, .empty .brand-icon { margin-inline: auto; }
.eyebrow {
  color: var(--rose);
  font-size: .69rem;
  font-weight: 750;
  letter-spacing: .16em;
  margin: 22px 0 6px;
}

.login h1 {
  margin: 0;
  font: 600 clamp(43px, 11vw, 63px)/1.02 var(--serif);
  letter-spacing: -.06em;
}

.description { color: var(--muted); line-height: 1.55; margin: 13px 0 26px; }
#login-form { display: grid; gap: 9px; text-align: left; }
#login-form label { font-size: .88rem; font-weight: 700; }
#login-button { margin-top: 4px; min-height: 49px; }
.error { color: var(--danger); font-size: .875rem; margin: 7px 0; }
.error:empty { display: none; }

.chat {
  width: 100%;
  height: 100vh;
  height: 100dvh;
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  background: var(--paper);
  overflow: hidden;
}

.chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: calc(12px + env(safe-area-inset-top)) 16px 12px;
  border-bottom: 1px solid var(--edge);
  background: var(--surface);
}

.peer { flex: 1; min-width: 0; }
.peer h1 { font: 600 1.33rem/1.15 var(--serif); margin: 0; }
.peer p { font-size: .78rem; color: var(--muted); margin: 3px 0 0; }
#logout { font-size: .83rem; font-weight: 650; }
.history {
  overflow: auto;
  overscroll-behavior: contain;
  padding: 16px;
  display: flex;
  flex-direction: column;
  background:
    radial-gradient(ellipse at 100% 0, var(--soft), transparent 48%),
    var(--paper);
}

.older { align-self: center; margin-bottom: 14px; }
.empty { margin: auto; color: var(--muted); text-align: center; }
.empty p { margin: 6px 0 0; }
.empty .empty-title { color: var(--ink); font: 600 1.55rem var(--serif); margin-top: 13px; }
#messages {
  list-style: none;
  margin: auto 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 9px;
}
.empty:not([hidden]) + #messages { display: none; }

.message {
  align-self: flex-start;
  max-width: min(86%, 420px);
  padding: 10px 13px;
  background: var(--surface);
  border: 1px solid var(--edge);
  border-radius: 19px 19px 19px 6px;
  overflow-wrap: anywhere;
  box-shadow: 0 2px 6px #642b4310;
}

.message.own {
  align-self: flex-end;
  background: var(--own);
  border-color: var(--own-edge);
  border-radius: 19px 19px 6px 19px;
}

.body { white-space: pre-wrap; line-height: 1.42; }
.message-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 0 8px; margin-top: 4px; }
.message time { color: var(--muted); font-size: .69rem; }
.delete-message {
  min-height: 28px;
  margin-left: auto;
  padding: 2px 4px;
  border: 0;
  background: transparent;
  color: var(--ink);
  font-size: .75rem;
  text-decoration: underline;
}
.message img { display: block; width: auto; max-width: 100%; max-height: 300px; border-radius: 11px; }
.message audio { display: block; width: min(230px, 55vw); height: 42px; }

footer {
  background: var(--surface);
  border-top: 1px solid var(--edge);
  padding: 10px max(10px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
}

.composer, .actions { display: flex; gap: 8px; align-items: center; }
.composer input:not([type=file]), .actions span { flex: 1; }
.actions { margin-bottom: 7px; font-size: .84rem; }
.actions button { padding-inline: 9px; }
#draft { border-radius: 999px; }
.icon-button {
  width: 44px;
  min-width: 44px;
  display: grid;
  place-items: center;
  padding: 0;
}
.icon-button svg {
  width: 21px;
  height: 21px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.65;
  stroke-linecap: round;
  stroke-linejoin: round;
}

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

@media (min-width: 760px) and (min-height: 550px) {
  .chat {
    width: min(calc(100% - 48px), 720px);
    height: min(calc(100dvh - 48px), 860px);
    border: 1px solid var(--edge);
    border-radius: 28px;
    box-shadow: var(--shadow);
  }
  .chat-header, .history, footer { padding-inline: 22px; }
}

.call-panel {
  flex-wrap: wrap;
  padding: 7px 9px;
  background: var(--soft);
  border: 1px solid var(--edge);
  border-radius: 17px;
}

.call-panel span {
  min-width: 8em;
  font-weight: 700;
}

#push-toggle[aria-pressed="true"] {
  color: var(--rose);
  border-color: var(--rose);
}

.push-notice {
  color: var(--muted);
  font-size: .83rem;
  margin: 7px 0;
}
.push-notice:empty { display: none; }
