/* segv.sh — monospace, black on white (white on black in dark mode), 1px rules. */
:root {
  color-scheme: light dark;
  --fg: #000;
  --bg: #fff;
  --dim: #666;
  --hi: #f2f2f2;
  --mono:
    ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, "Liberation Mono", "DejaVu Sans Mono",
    "Noto Sans Mono", "Noto Sans Mono CJK JP", "Hiragino Kaku Gothic ProN", "Osaka-Mono",
    "MS Gothic", monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    --fg: #fff;
    --bg: #000;
    --dim: #999;
    --hi: #1c1c1c;
  }
}

*,
*::before,
*::after {
  box-sizing: border-box;
}
html,
body {
  margin: 0;
  height: 100%;
}
body {
  background: var(--bg);
  color: var(--fg);
  font: 14px/1.5 var(--mono);
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}
h1,
h2,
h3,
p,
ul {
  margin: 0;
  padding: 0;
  font-size: inherit;
}
h1 {
  font-size: 20px;
}
ul {
  list-style: none;
}
a {
  color: inherit;
}

button,
input,
textarea {
  font: inherit;
  color: inherit;
  border-radius: 0;
}
button,
.btn {
  display: inline-block;
  background: var(--bg);
  border: 1px solid var(--fg);
  padding: 2px 10px;
  cursor: pointer;
  white-space: nowrap;
}
button:hover:not(:disabled),
.btn:hover {
  background: var(--fg);
  color: var(--bg);
}
button:disabled {
  opacity: 0.4;
  cursor: default;
}
.link {
  border: 0;
  padding: 0;
  background: none;
  text-decoration: underline;
  text-underline-offset: 3px;
}
.link:hover:not(:disabled) {
  background: none;
  color: inherit;
  text-decoration-thickness: 2px;
}
input[type="text"],
textarea {
  display: block;
  width: 100%;
  min-width: 0;
  background: var(--bg);
  border: 1px solid var(--fg);
  padding: 4px 6px;
}
input::placeholder,
textarea::placeholder {
  color: var(--dim);
}
input[type="checkbox"],
input[type="radio"] {
  accent-color: var(--fg);
  margin: 0 6px 0 0;
  vertical-align: -2px;
}
:focus-visible,
.btn:focus-within {
  outline: 2px solid var(--fg);
  outline-offset: 1px;
}
input[type="text"]:focus,
textarea:focus {
  outline: 1px solid var(--fg);
  outline-offset: -2px;
}
.vh {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  overflow: hidden;
  pointer-events: none;
}

.dim {
  color: var(--dim);
}
.strong {
  font-weight: 700;
}
.small {
  font-size: 12px;
}
.row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.grow {
  flex: 1;
  min-width: 0;
}
.check {
  cursor: pointer;
}
.alert,
.warnings {
  background: var(--fg);
  color: var(--bg);
  padding: 8px 12px;
}
.warnings {
  max-height: 30vh;
  overflow-y: auto;
}
.warnings p + p {
  margin-top: 4px;
}

/* ---- single-column pages: boot, signed-out, recovery, fatal ---- */
/* env(safe-area-inset-*) is 0 except on screens with a notch or a home indicator (viewport-fit=cover). */
.boot {
  padding: calc(48px + env(safe-area-inset-top)) max(16px, env(safe-area-inset-right))
    calc(48px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  max-width: 40rem;
  margin: 0 auto;
}
.page {
  max-width: 40rem;
  margin: 0 auto;
  padding: calc(48px + env(safe-area-inset-top)) max(16px, env(safe-area-inset-right))
    calc(64px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  display: grid;
  gap: 16px;
}
.page section {
  border-top: 1px solid var(--fg);
  padding-top: 12px;
  display: grid;
  gap: 8px;
}
.page form.row,
.addm {
  flex-wrap: nowrap;
  align-items: stretch;
}
.progress {
  border: 1px solid var(--fg);
  padding: 8px 12px;
}
.recovery .code {
  font-size: 22px;
  font-weight: 700;
  line-height: 1.6;
  word-spacing: 0.4em;
  border: 1px solid var(--fg);
  padding: 12px 14px;
  user-select: all;
  overflow-wrap: break-word;
}
.recovery .code span {
  display: block;
}
.errors .error {
  display: flex;
  gap: 12px;
  align-items: baseline;
  padding: 6px 12px;
  border: 1px solid var(--fg);
  overflow-wrap: anywhere;
}
.errors .error span {
  flex: 1;
}

/* ---- signed in ---- */
.chat {
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  /* keeps the top bar, the composer and the list footer clear of a notch and the home indicator */
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom)
    env(safe-area-inset-left);
}
.bar {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 14px;
  padding: 4px 12px;
  border-bottom: 1px solid var(--fg);
}
.bar .push {
  margin-left: auto;
}
.chat .errors .error {
  border-width: 0 0 1px;
}
.panes {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(220px, 300px) 1fr;
}
.left {
  border-right: 1px solid var(--fg);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.me,
.newconv {
  padding: 8px 12px;
  border-bottom: 1px solid var(--fg);
}
.me {
  display: flex;
  align-items: baseline;
  gap: 12px;
}
.me .handle {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.newconv form {
  display: grid;
  gap: 6px;
}
.fp {
  word-spacing: 0.2em;
  overflow-wrap: break-word;
}
.lists {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 16px;
  padding: 6px 12px;
  border-bottom: 1px solid var(--fg);
}
.lists [aria-pressed="true"] {
  font-weight: 700;
  text-decoration: none;
}
.list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 0;
}
.pad {
  padding: 8px 12px;
}
.conv {
  display: flex;
  align-items: baseline;
  gap: 8px;
  width: 100%;
  border: 0;
  padding: 6px 12px;
  text-align: left;
  background: none;
}
.conv:hover:not(:disabled) {
  background: var(--hi);
  color: inherit;
}
.conv.on,
.conv.on:hover:not(:disabled) {
  background: var(--fg);
  color: var(--bg);
}
.conv .name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}
.conv.unread .name,
.conv .badge {
  font-weight: 700;
}
.conv .when {
  font-size: 12px;
  color: var(--dim);
}
.conv.on .when,
.conv.on .dim {
  color: inherit;
}
.right {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  position: relative;
}
.empty {
  padding: 16px 12px;
}
.convhead {
  display: flex;
  align-items: baseline;
  gap: 12px;
  padding: 6px 12px;
  border-bottom: 1px solid var(--fg);
}
.convhead .title {
  flex: 1;
  min-width: 0;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.back {
  display: none;
}
.convbody {
  flex: 1;
  min-height: 0;
  display: flex;
  position: relative;
}
.thread {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}
.msgwrap {
  flex: 1;
  min-height: 0;
  position: relative;
  display: flex;
}
.msgs {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 4px 12px 12px;
}
.msgs:focus-visible {
  outline-offset: -2px;
}
.day {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 14px 0 4px;
  font-size: 12px;
  color: var(--dim);
}
.day::before,
.day::after {
  content: "";
  flex: 1;
  border-top: 1px solid var(--dim);
}
.m {
  padding: 1px 0 1px 10px;
  border-left: 1px solid transparent;
}
.m.mine {
  border-left-color: var(--fg);
}
.m.head {
  margin-top: 10px;
}
.meta .dim {
  font-size: 12px;
}
.body {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
/* Markdown in messages (packages/engine/src/markdown.ts, packages/ui/src/msg-text.tsx). */
.body a {
  text-underline-offset: 3px;
}
.body code {
  padding: 0 3px;
  background: var(--hi);
}
.body pre {
  margin: 2px 0;
  padding: 4px 8px;
  font: inherit;
  white-space: pre-wrap;
  background: var(--hi);
  border: 1px solid var(--dim);
}
.body pre code {
  padding: 0;
  background: none;
}
.body blockquote {
  margin: 0;
  padding-left: 8px;
  border-left: 3px solid var(--dim);
}
.body ul,
.body ol {
  margin: 0;
  padding-left: 3ch;
}
.body ul {
  list-style: disc;
}
.body li ul {
  list-style: circle;
}
.md-h1,
.md-h2,
.md-h3 {
  font-weight: 700;
  line-height: 1.3;
  margin: 4px 0 2px;
}
.md-h1 {
  font-size: 20px;
}
.md-h2 {
  font-size: 17px;
}
.md-h3 {
  font-size: 15px;
}
.md-sub {
  font-size: 12px;
  color: var(--dim);
}
.spoiler {
  -webkit-box-decoration-break: clone;
  box-decoration-break: clone;
}
.spoiler:not(.shown) {
  color: transparent;
  background: var(--fg);
  cursor: pointer;
}
.spoiler:not(.shown) * {
  color: transparent;
  background: transparent;
  text-decoration-color: transparent;
}
.spoiler.shown {
  background: var(--hi);
}
.sys {
  color: var(--dim);
  padding: 6px 0 2px 11px;
  overflow-wrap: anywhere;
}
.sys .t {
  font-size: 12px;
}
.st {
  font-size: 12px;
  color: var(--dim);
}
.st.failed {
  color: var(--fg);
  font-weight: 700;
}
.reacts {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
  margin: 2px 0;
}
.react {
  font: inherit;
  font-size: 13px;
  line-height: 1.4;
  padding: 0 6px;
  color: var(--fg);
  background: var(--bg);
  border: 1px solid var(--dim);
  cursor: pointer;
}
.react.mine {
  border-color: var(--fg);
  font-weight: 700;
}
.react:disabled {
  cursor: default;
}
.react.add {
  color: var(--dim);
  border-style: dashed;
}
.palette {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 2px;
}
@media (hover: hover) {
  .m .react.add {
    visibility: hidden;
  }
  .m:hover .react.add,
  .m:focus-within .react.add {
    visibility: visible;
  }
}
.img {
  position: relative;
  display: inline-block;
  max-width: 100%;
  margin: 4px 0 2px;
  vertical-align: top;
}
.img img,
.img canvas {
  display: block;
  max-width: 100%;
  height: auto;
  box-sizing: content-box;
}
.img img {
  border: 1px solid var(--fg);
}
.img canvas {
  border: 1px dashed var(--dim);
}
.phmsg {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px;
  text-align: center;
}
.imgbtn {
  display: block;
  padding: 0;
  border: 0;
  background: none;
  cursor: zoom-in;
}
.imgbtn:hover:not(:disabled) {
  background: none;
}
.newbelow {
  position: absolute;
  left: 50%;
  bottom: 10px;
  transform: translateX(-50%);
}

.composer {
  border-top: 1px solid var(--fg);
  padding: 8px 12px;
  display: grid;
  gap: 6px;
}
.composer textarea {
  resize: none;
  min-height: calc(2lh + 10px);
  max-height: 40vh;
  field-sizing: content;
}
.composer .hint {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.composer .send {
  margin-left: auto;
}
.btn {
  position: relative;
}
.pending li {
  overflow-wrap: anywhere;
}

.members {
  width: 300px;
  flex: none;
  border-left: 1px solid var(--fg);
  overflow-y: auto;
  padding: 8px 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--bg);
}
.mlist li {
  padding: 8px 0;
  border-bottom: 1px solid var(--fg);
}
.mlist li:first-child {
  border-top: 1px solid var(--fg);
}
.confirm {
  margin-top: 6px;
}
.addm {
  display: flex;
  gap: 8px;
}

.viewer {
  position: fixed;
  inset: 0;
  z-index: 10;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: calc(16px + env(safe-area-inset-top)) calc(16px + env(safe-area-inset-right))
    calc(16px + env(safe-area-inset-bottom)) calc(16px + env(safe-area-inset-left));
  cursor: zoom-out;
}
.viewer img {
  max-width: 100%;
  max-height: calc(100% - 48px);
  width: auto;
  height: auto;
  object-fit: contain;
}
.viewer .row {
  cursor: default;
}

/* <dialog> opened with showModal(): centred on wide screens, the whole screen on phones (below). */
.settings {
  width: min(32rem, calc(100% - 32px));
  max-width: none;
  max-height: calc(100% - 64px);
  padding: 0;
  border: 1px solid var(--fg);
  background: var(--bg);
  color: var(--fg);
  overflow-y: auto;
  overscroll-behavior: contain;
}
/* ::backdrop does not inherit the custom properties in every browser: plain colours. */
.settings::backdrop,
.leave::backdrop {
  background: rgb(255 255 255 / 0.85);
}
@media (prefers-color-scheme: dark) {
  .settings::backdrop,
  .leave::backdrop {
    background: rgb(0 0 0 / 0.85);
  }
}
/* "open this link?" (leaving.tsx): small, centred on phones too. */
.leave {
  width: min(28rem, calc(100% - 32px));
  max-width: none;
  padding: 0;
  border: 1px solid var(--fg);
  background: var(--bg);
  color: var(--fg);
}
.leave .sheet {
  padding: 12px 16px 16px;
  display: grid;
  gap: 10px;
}
.leave h2 {
  font-weight: 700;
}
.leave .url {
  overflow-wrap: anywhere;
}
.leave .row {
  justify-content: flex-end;
}
.leave a.btn {
  text-decoration: none;
}
.settings .sheet {
  padding: 10px 16px 20px;
  display: grid;
  gap: 16px;
}
.settings h2 {
  font-weight: 700;
}
.settings section {
  border-top: 1px solid var(--fg);
  padding-top: 10px;
  display: grid;
  gap: 6px;
}
.settings h3 {
  font-weight: 700;
}
.settings .choice {
  border: 0;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 6px;
}
.settings .choice legend {
  padding: 0;
  margin-bottom: 4px;
}

@media (max-width: 1000px) {
  .members {
    position: absolute;
    inset: 0;
    width: auto;
    border-left: 0;
    z-index: 2;
  }
}
@media (max-width: 720px) {
  input[type="text"],
  textarea {
    font-size: 16px; /* no iOS zoom on focus */
  }
  .page {
    padding-top: calc(24px + env(safe-area-inset-top));
  }
  .panes {
    grid-template-columns: 1fr;
  }
  .left {
    border-right: 0;
  }
  .panes[data-pane="conv"] .left,
  .panes[data-pane="list"] .right {
    display: none;
  }
  .back {
    display: inline;
  }
  .settings {
    width: 100%;
    height: 100%;
    max-height: none;
    margin: 0;
    border: 0;
  }
  .settings .sheet {
    padding: calc(10px + env(safe-area-inset-top)) max(16px, env(safe-area-inset-right))
      calc(24px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  }
  .composer .hint:not(.strong) {
    display: none;
  }
}
