:root {
  color-scheme: dark;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  --shell: #18131e;
  --panel: #211a28;
  --raised: #2c2335;
  --subtle: #31263b;
  --line: #3e3149;
  --text: #fbf7ff;
  --dim: #c1b5ca;
  --violet: #d0b0ff;
  --amber: #ffca83;
  --text-on-violet: #21102d;
  --radius: 16px;
}
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { width: 100%; min-height: 100%; margin: 0; }
body { background: var(--shell); color: var(--text); }
button, input, textarea, select { font: inherit; }
button, input, textarea, select, a { -webkit-tap-highlight-color: transparent; }
button {
  min-height: 44px;
  cursor: pointer;
  border: 1px solid transparent;
  border-radius: 12px;
  padding: 8px 13px;
  color: var(--text);
  background: var(--raised);
}
button:hover { background-color: var(--subtle); }
button:disabled { opacity: .55; cursor: default; }
:focus-visible { outline: 2px solid var(--amber); outline-offset: 3px; }
input, textarea, select {
  min-height: 44px;
  min-width: 0;
  color: var(--text);
  background: var(--shell);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 12px;
}
textarea { resize: vertical; }
a { color: var(--violet); }
p, h1, h2, h3 { margin: 0; }
p { line-height: 1.5; }
.primary { background: var(--violet); color: var(--text-on-violet); font-weight: 700; }
.primary:hover { background: #dfcaff; }
.outline { background: transparent; border-color: var(--line); }
.quiet { background: transparent; color: var(--violet); }
.icon-button {
  display: inline-grid;
  place-items: center;
  width: 44px;
  min-width: 44px;
  padding: 0;
}
.icon { width: 20px; height: 20px; display: block; }
.notice { color: var(--dim); font-size: .88rem; overflow-wrap: anywhere; }
.notice:empty { display: none; }
.notice[data-error="true"] { color: #ffb6bf; }
.row { display: flex; align-items: center; gap: 6px; min-width: 0; }
.center-screen {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: max(20px, env(safe-area-inset-top)) 20px max(20px, env(safe-area-inset-bottom));
  background: radial-gradient(ellipse at 50% 0%, #35203e, var(--shell) 72%);
}
.center-screen > p { color: var(--dim); }
.access-card {
  width: min(100%, 400px);
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 22px;
  padding: clamp(24px, 5vw, 38px);
  box-shadow: 0 22px 68px #08040a70;
}
.family-logo { display: block; width: auto; height: auto; object-fit: contain; }
.access-card .family-logo { max-width: 118px; max-height: 56px; margin-bottom: 22px; }
.access-card h1 { font-size: 1.9rem; letter-spacing: -.04em; margin-bottom: 22px; }
.access-card form, .dialog-form { display: grid; gap: 9px; }
.access-card label, .dialog-form label { font-size: .88rem; font-weight: 600; }
.access-card button.primary, .dialog-form button[type="submit"] { margin-top: 8px; }
.access-card .notice { margin-top: 15px; }

.portal {
  display: grid;
  grid-template-columns: minmax(310px, 370px) minmax(0, 1fr);
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}
.inbox, .thread, .placeholder { min-width: 0; min-height: 0; }
.inbox {
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border-right: 1px solid var(--line);
  padding-top: env(safe-area-inset-top);
}
.inbox-header, .thread-header {
  min-height: 72px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 16px;
}
.brand { display: flex; align-items: center; min-width: 0; gap: 11px; }
.brand .family-logo { max-width: 76px; max-height: 38px; }
.brand h1 { font-size: clamp(1.1rem, 3vw, 1.42rem); letter-spacing: -.045em; }
.search-field {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-inline: 12px;
  margin: 4px 16px 9px;
  color: var(--dim);
  background: var(--shell);
  border: 1px solid var(--line);
  border-radius: 14px;
}
.search-field:focus-within { border-color: var(--violet); }
.search-field input {
  flex: 1;
  border: 0;
  padding-inline: 0;
  background: transparent;
  outline-offset: -4px;
}
.filters {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  padding: 0 16px 8px;
}
.filters button { border-radius: 999px; background: transparent; color: var(--dim); border-color: var(--line); font-weight: 600; font-size: .88rem; }
.filters button[aria-pressed="true"] { background: #453052; color: var(--text); border-color: #6f5280; }
.inbox-scroll, .thread-scroll { flex: 1; min-height: 0; overflow: auto; overscroll-behavior: contain; scrollbar-color: var(--line) transparent; }
.inbox-scroll { padding: 0 9px max(12px, env(safe-area-inset-bottom)); }
.inset-notice { padding: 7px 16px; }
.chat-list, .messages { list-style: none; padding: 0; margin: 0; }
.chat-list li + li { margin-top: 3px; }
.chat-item {
  width: 100%;
  min-height: 70px;
  padding: 11px 10px;
  display: grid;
  align-items: center;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 11px;
  text-align: left;
  background: transparent;
  border-color: transparent;
}
.chat-item:hover, .chat-item[aria-current="true"] { background: var(--raised); }
.chat-item[aria-current="true"] { border-color: #614a72; }
.avatar {
  display: grid;
  flex: 0 0 auto;
  place-items: center;
  width: 42px;
  aspect-ratio: 1;
  border-radius: 15px;
  color: #efdcff;
  background: #483250;
  font-size: .85rem;
  font-weight: 800;
  text-transform: uppercase;
}
.avatar[data-color="1"] { background: #513f2d; color: #ffddac; }
.avatar[data-color="2"] { background: #344647; color: #c1f0e4; }
.avatar[data-color="3"] { background: #4e3043; color: #f9d0ec; }
.chat-description { min-width: 0; }
.chat-description strong, .chat-description span {
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-description strong { font-size: .97rem; }
.chat-description span, .chat-meta time { color: var(--dim); font-size: .83rem; margin-top: 4px; }
.chat-meta { display: grid; justify-items: end; gap: 4px; min-width: 39px; }
.chat-badges { display: flex; align-items: center; gap: 4px; color: var(--amber); }
.unread-count {
  min-width: 22px;
  min-height: 20px;
  display: grid;
  place-items: center;
  padding-inline: 4px;
  border-radius: 999px;
  background: var(--violet);
  color: var(--text-on-violet);
  font-size: .72rem;
  font-weight: 800;
}
.load-more { display: block; margin: 6px auto 10px; }

.placeholder {
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 13px;
  color: var(--dim);
  background: radial-gradient(ellipse at 60% 60%, #2e2135 0, transparent 67%);
}
.placeholder .icon { width: 48px; height: 48px; color: var(--violet); }
.thread { display: flex; flex-direction: column; background: #1d1724; padding-top: env(safe-area-inset-top); }
.thread-header {
  flex: 0 0 auto;
  justify-content: flex-start;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}
.thread-title { flex: 1; min-width: 0; }
.thread-title h2, .thread-title p { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.thread-title h2 { font-size: 1.06rem; }
.thread-title p { color: var(--dim); margin-top: 3px; font-size: .83rem; }
.back-button { display: none; }
.fany-button { color: var(--violet); font-weight: 720; }
#favoriteChat[aria-pressed="true"] { color: var(--amber); }
#favoriteChat[aria-pressed="true"] path { fill: currentColor; }
.thread-scroll {
  padding: 10px clamp(10px, 3vw, 38px) 16px;
  background-color: #1d1724;
  background-image: radial-gradient(circle at center, #7a54821e 1px, transparent 1px);
  background-size: 24px 24px;
}
.messages { display: flex; flex-direction: column; gap: 7px; }
.date-row { align-self: center; margin-block: 13px 5px; padding: 4px 10px; border-radius: 8px; color: var(--dim); font-size: .76rem; background: var(--shell); }
.message {
  align-self: flex-start;
  width: fit-content;
  max-width: min(82%, 640px);
  min-width: 70px;
  padding: 8px 11px 6px;
  border-radius: 3px 14px 14px 14px;
  border: 1px solid #493951;
  background: #2d2336;
  overflow-wrap: anywhere;
}
.message.outgoing { align-self: flex-end; border-color: #664a85; background: #433057; border-radius: 14px 3px 14px 14px; }
.message p { white-space: pre-wrap; margin-block: 3px; }
.message-meta { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 5px; color: #ded2e7; font-size: .72rem; margin-top: 3px; }
.message .media { display: block; max-width: 100%; max-height: 320px; margin-top: 5px; border-radius: 8px; }
.message .media-button { text-align: left; color: var(--violet); padding-inline: 7px; background: transparent; }
.composer {
  flex: 0 0 auto;
  padding: 8px clamp(8px, 2vw, 16px) max(9px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: var(--panel);
}
.composer-row { display: flex; align-items: flex-end; gap: 8px; }
.composer-row textarea { flex: 1; resize: none; height: 44px; max-height: 132px; border-radius: 14px; }
.send-button { border-radius: 14px; }
.attachment { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-width: 0; margin-bottom: 6px; }
.attachment span { min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--dim); }
.composer-notice { margin-bottom: 8px; }

dialog {
  width: min(460px, calc(100% - 24px));
  max-height: min(84dvh, 700px);
  overflow: auto;
  overscroll-behavior: contain;
  padding: 0 16px 16px;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: 0 20px 70px #08040ad0;
}
dialog::backdrop { background: #110c18bd; }
.dialog-header {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  background: var(--panel);
  padding-block: 12px;
}
.dialog-header h2 { font-size: 1.22rem; letter-spacing: -.03em; }
.dialog-body { display: grid; gap: 8px; }
.dialog-body > button { text-align: left; }
.dialog-body p { color: var(--dim); font-size: .9rem; }
.dialog-body h3 { margin: 8px 0 2px; font-size: .97rem; }
.dialog-body details { border-top: 1px solid var(--line); margin-top: 4px; padding-top: 4px; }
.dialog-body summary { cursor: pointer; min-height: 44px; display: flex; align-items: center; color: var(--violet); }
.dialog-body details > div { display: grid; gap: 8px; padding-bottom: 5px; }
#dialogNotice { margin-top: 12px; }
@media (min-width: 1100px) {
  .portal { grid-template-columns: minmax(350px, 28%) minmax(0, 1fr); }
}
@media (max-width: 720px) {
  .portal { grid-template-columns: minmax(0, 1fr); }
  .portal:not(.has-thread) .placeholder, .portal.has-thread .inbox { display: none; }
  .inbox { border-right: none; }
  .inbox-header, .thread-header { padding-inline: max(9px, env(safe-area-inset-left)) max(9px, env(safe-area-inset-right)); min-height: 61px; gap: 6px; }
  .inbox-header .brand { padding-left: 5px; }
  .back-button { display: inline-grid; }
  .thread-header .avatar { width: 33px; border-radius: 10px; }
  .thread-header .icon-button { width: 40px; min-width: 40px; }
  .thread-title h2 { font-size: .97rem; }
  .thread-title p { font-size: .75rem; }
  .fany-button { padding-inline: 9px; }
  .message { max-width: 90%; }
  dialog { margin: auto auto 0; width: 100%; border-radius: 18px 18px 0 0; max-height: 88dvh; padding-bottom: max(15px, env(safe-area-inset-bottom)); }
}
@media (prefers-reduced-motion: no-preference) {
  button { transition: background-color .14s ease, border-color .14s ease; }
}

.dialog-form label { display: grid; gap: 5px; }
.dialog-confirmation { display: grid; gap: 10px; background: var(--raised); padding: 12px; border-radius: 12px; }
.dialog-confirmation strong { color: var(--text); }
.dialog-confirmation .row { flex-wrap: wrap; }
.dialog-fieldset { display: grid; gap: 8px; margin: 0; padding: 0; border: 0; }

.wrap-row { flex-wrap: wrap; }

.thread-shortcuts {
  display: flex;
  gap: 6px;
  padding: 5px 16px 6px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}
.thread-shortcuts button { padding: 5px 11px; border-radius: 10px; font-size: .83rem; font-weight: 650; }
#shortcutStart { color: var(--violet); border-color: #675176; background-color: #302438; }
#shortcutStart:hover { background-color: #3c2d47; }
@media (max-width: 720px) {
  .thread-shortcuts {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1.2fr) minmax(0, 1fr);
    gap: 4px;
    padding-inline: max(8px, env(safe-area-inset-left)) max(8px, env(safe-area-inset-right));
  }
  .thread-shortcuts button { min-width: 0; padding-inline: 3px; font-size: .75rem; overflow-wrap: anywhere; }
}
