:root {
  color-scheme: light dark;
  --background: #f5f5f3;
  --surface: #fff;
  --subtle: #ededea;
  --text: #191919;
  --muted: #585854;
  --line: #dcdcd7;
  --button: #222;
  --button-text: #fff;
  --sent: #252525;
  --received: #ededea;
  --focus: #3b3b3b;
  font: 100%/1.5 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --background: #131313;
    --surface: #1b1b1b;
    --subtle: #272727;
    --text: #f3f3f0;
    --muted: #b7b7b2;
    --line: #3c3c3a;
    --button: #f4f4f1;
    --button-text: #171717;
    --sent: #f0f0ed;
    --received: #292929;
    --focus: #ecece8;
  }
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; min-height: 100svh; background: var(--background); color: var(--text); }
h1, h2, p { margin: 0; }
h1, h2 { font-weight: 650; line-height: 1.14; letter-spacing: -.032em; }
input, textarea, button { font: inherit; color: inherit; }
a { color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 3px; }

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

.skip:focus {
  z-index: 5;
  top: .5rem;
  left: .5rem;
  width: auto;
  height: auto;
  padding: .65rem .9rem;
  clip-path: none;
  background: var(--surface);
}

.muted { color: var(--muted); }
.masthead {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  min-height: 4rem;
  padding: .65rem clamp(.85rem, 4vw, 2rem);
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.brand, .masthead-actions { display: inline-flex; align-items: center; min-width: 0; gap: .65rem; }
.brand { text-decoration: none; font-weight: 680; white-space: nowrap; letter-spacing: -.025em; }
.brand img { display: block; flex: none; }
.mode {
  flex: none;
  padding: .2rem .55rem;
  border-radius: 999px;
  background: var(--subtle);
  font-size: .8rem;
  white-space: nowrap;
}

.account-menu { position: relative; min-width: 0; }
.account-menu summary {
  display: grid;
  align-items: center;
  min-height: 2.75rem;
  max-width: 12rem;
  padding-inline: .55rem;
  list-style: none;
  overflow: hidden;
  overflow-wrap: anywhere;
  cursor: pointer;
}

.account-menu summary::-webkit-details-marker { display: none; }
.account-menu[open] summary, .account-menu summary:hover { background: var(--subtle); border-radius: .6rem; }
.account-popover {
  display: grid;
  position: absolute;
  right: 0;
  z-index: 2;
  min-width: 10rem;
  padding: .35rem;
  border: 1px solid var(--line);
  border-radius: .75rem;
  background: var(--surface);
}

.account-popover button { text-align: left; padding-inline: .65rem; }
.entry {
  display: grid;
  place-items: start center;
  min-height: calc(100svh - 4rem);
  padding: clamp(2rem, 12vh, 6rem) 1rem 2rem;
}

.entry-content { width: min(100%, 23rem); }
.entry-mark { display: block; margin-bottom: 1.1rem; }
.entry h1 { font-size: clamp(1.7rem, 4.4vw, 2.25rem); }
.entry h1 + p { margin-top: .5rem; }
.stacked-form { display: grid; gap: .7rem; margin-top: 1.4rem; }
.form-field { display: grid; gap: .35rem; }
.stacked-form > .solid-button { margin-top: .35rem; }
.entry-actions { display: flex; flex-wrap: wrap; justify-content: space-between; gap: .25rem .5rem; }
.privacy-note { max-width: 32ch; margin-top: 1rem; font-size: .8rem; }
.feedback { margin-block: .3rem 0; font-size: .875rem; overflow-wrap: anywhere; }
.feedback:empty { margin: 0; }
.feedback[data-error] { font-weight: 620; }

input, textarea {
  width: 100%;
  min-width: 0;
  min-height: 2.75rem;
  padding: .55rem .75rem;
  border: 1px solid var(--line);
  border-radius: .7rem;
  background: var(--surface);
}

input::placeholder, textarea::placeholder { color: var(--muted); }
input:focus-visible, textarea:focus-visible { outline-offset: 1px; }
input[readonly] { color: var(--muted); background: var(--subtle); }

button {
  min-height: 2.75rem;
  border: 0;
  border-radius: .65rem;
  background: transparent;
  cursor: pointer;
}

button:disabled { opacity: .55; cursor: default; }
button:enabled { touch-action: manipulation; }
.solid-button { padding: .5rem .85rem; background: var(--button); color: var(--button-text); font-weight: 620; }
.solid-button:enabled:active { opacity: .78; }
.text-button { padding: .35rem .65rem; background: transparent; font-weight: 600; text-decoration: underline; text-underline-offset: .16em; }
.text-button:hover, .account-popover button:hover { background: var(--subtle); }

.chat-layout {
  display: grid;
  grid-template-columns: minmax(16rem, min(34vw, 22rem)) minmax(0, 1fr);
  width: min(100%, 85rem);
  height: calc(100svh - 4rem);
  min-height: 24rem;
  margin-inline: auto;
  background: var(--surface);
}

.sidebar { display: flex; flex-direction: column; gap: .65rem; min-width: 0; min-height: 0; padding: 1.2rem .95rem; border-right: 1px solid var(--line); }
.sidebar h1 { font-size: 1.65rem; margin-bottom: .35rem; }
.add-contact { display: grid; gap: .35rem; }
.add-contact label { font-weight: 550; }
.input-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: end; gap: .5rem; }
.contact-list { display: grid; align-content: start; min-height: 0; margin: 0; padding: .2rem .2rem .2rem 0; list-style: none; overflow: auto; }
.contact-list li { min-width: 0; }
.contact-item { display: flex; min-width: 0; align-items: center; gap: .5rem; padding: .6rem .65rem; min-height: 3.5rem; }
button.contact-item { width: 100%; text-align: left; }
.contact-item:hover:is(button), .contact-item[aria-current="true"] { background: var(--subtle); }
.contact-identity { display: grid; flex: 1; min-width: 0; }
.contact-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 640; }
.contact-meta { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .8rem; color: var(--muted); }
.contact-item .text-button { flex: none; padding: .35rem .35rem; }

.thread { min-width: 0; min-height: 0; }
.thread-empty { display: grid; justify-items: center; align-content: center; gap: .5rem; padding: 1.75rem; height: 100%; text-align: center; }
.thread-active { display: grid; grid-template-rows: auto minmax(0, 1fr) auto; height: 100%; }
.thread-header { display: flex; align-items: center; gap: .65rem; min-width: 0; padding: .85rem 1rem; border-bottom: 1px solid var(--line); }
.thread-heading { min-width: 0; }
.thread-heading h2 { overflow-wrap: anywhere; font-size: 1.2rem; }
.thread-heading .muted { font-size: .85rem; overflow-wrap: anywhere; }
.back-button { display: none; flex: none; }
.thread-scroll { min-height: 0; overflow: auto; overscroll-behavior: contain; padding: .75rem 1rem; }
.thread-scroll:focus-visible { outline-offset: -3px; }
.thread-feedback { text-align: center; }
.thread-feedback:not(:empty) { margin: .8rem 0; }
#older { display: block; margin: 0 auto .65rem; }
.messages { display: grid; align-content: start; gap: .62rem; margin: 0; padding: .1rem; list-style: none; }
.message-item { display: grid; justify-items: start; gap: .17rem; min-width: 0; }
.message-item[data-own] { justify-items: end; }
.message-content { max-width: min(90%, 38rem); padding: .45rem .72rem; border-radius: .95rem .95rem .95rem .28rem; background: var(--received); overflow-wrap: anywhere; white-space: pre-wrap; }
.message-item[data-own] .message-content { border-radius: .95rem .95rem .28rem .95rem; background: var(--sent); color: var(--button-text); }
.message-time { padding-inline: .2rem; color: var(--muted); font-size: .75rem; }
.composer { padding: .7rem max(1rem, env(safe-area-inset-right)) max(.7rem, env(safe-area-inset-bottom)) max(1rem, env(safe-area-inset-left)); border-top: 1px solid var(--line); }
.composer textarea { display: block; max-height: 8rem; resize: vertical; }

@media (max-width: 42rem) {
  .chat-layout { grid-template-columns: minmax(0, 1fr); }
  .sidebar { border-right: 0; }
  .chat-layout:not([data-thread-open]) .thread, .chat-layout[data-thread-open] .sidebar { display: none; }
  .back-button { display: inline-block; }
  .thread-header { padding-inline: .5rem; }
  .brand { gap: .35rem; }
  .masthead-actions { gap: .25rem; }
  .account-menu summary { max-width: min(8rem, 37vw); }
}
