:root {
  color-scheme: light dark;
  --header: #1d1630;
  --accent: #6d4bd8;
  --bg: #f3f0f8;
  --panel: #ffffff;
  --text: #1c1724;
  --muted: #776f86;
  --border: #e2dcec;
  --theirs: #ffffff;
}

@media (prefers-color-scheme: dark) {
  :root {
    --accent: #7c5cf0;
    --bg: #120e1a;
    --panel: #1c1628;
    --text: #ece8f5;
    --muted: #9a91ad;
    --border: #2c2440;
    --theirs: #261e36;
  }
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  /* Shows behind the status bar and the home indicator. */
  background: var(--header);
}

body {
  font: 16px/1.35 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  -webkit-text-size-adjust: 100%;
}

button,
input,
textarea {
  font: inherit;
  color: inherit;
}

/* --vvh follows the visible area, so the composer sits on top of the keyboard. */
#app {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--vvh, 100dvh);
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

#login,
#chat {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

/* ---------- sign in ---------- */

#login {
  justify-content: center;
  align-items: center;
  padding: 24px;
  background: var(--header);
}

.card {
  width: 100%;
  max-width: 340px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 24px;
  border-radius: 20px;
  background: var(--panel);
  text-align: center;
}

.card img {
  align-self: center;
  border-radius: 18px;
}

.card h1 {
  margin: 0;
  font-size: 22px;
}

.fields {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.closed {
  margin: 0;
  color: var(--muted);
  font-size: 15px;
}

.card label {
  display: flex;
  flex-direction: column;
  gap: 5px;
  text-align: left;
  font-size: 13px;
  color: var(--muted);
}

.card input {
  padding: 11px 13px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg);
  font-size: 16px;
  color: var(--text);
  outline: none;
}

.card input:focus {
  border-color: var(--accent);
}

.error {
  margin: 0;
  color: #d33c5a;
  font-size: 14px;
}

button {
  padding: 11px 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: transparent;
  cursor: pointer;
}

button.primary {
  border-color: transparent;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
}

button:disabled {
  opacity: 0.5;
}

/* ---------- chat ---------- */

header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: calc(env(safe-area-inset-top) + 8px) calc(env(safe-area-inset-right) + 8px) 8px calc(env(safe-area-inset-left) + 16px);
  background: var(--header);
  color: #fff;
}

header h1 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
}

#status {
  flex: 1;
  font-size: 13px;
  opacity: 0.7;
}

.icon-btn {
  flex: none;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: inherit;
}

#list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 10px calc(env(safe-area-inset-right) + 10px) 8px calc(env(safe-area-inset-left) + 10px);
}

/* Pushes a short conversation to the bottom of the screen. */
.spacer {
  flex: 1;
}

.empty {
  align-self: center;
  margin: 0 0 40vh;
  color: var(--muted);
}

.day {
  align-self: center;
  margin: 10px 0 6px;
  padding: 3px 11px;
  border-radius: 11px;
  background: var(--panel);
  color: var(--muted);
  font-size: 12px;
}

.msg {
  display: flex;
}

.msg.mine {
  justify-content: flex-end;
}

.bubble {
  max-width: min(78%, 520px);
  padding: 7px 12px 5px;
  border-radius: 18px;
  border-bottom-left-radius: 6px;
  background: var(--theirs);
  box-shadow: 0 1px 1px rgba(0, 0, 0, 0.06);
  overflow-wrap: anywhere;
}

.mine .bubble {
  border-radius: 18px;
  border-bottom-right-radius: 6px;
  background: var(--accent);
  color: #fff;
}

.bubble .text {
  white-space: pre-wrap;
}

.bubble a {
  color: inherit;
}

.bubble.has-img {
  padding: 4px 4px 5px;
}

.bubble.has-img .text {
  padding: 5px 8px 0;
}

/* A photo in the list. The box takes the photo's shape before it has loaded,
   and the pins on top are placed in percent of it. */
.photo,
.crop {
  position: relative;
  display: block;
  overflow: hidden;
  border-radius: 14px;
  background: rgba(128, 128, 128, 0.2);
  cursor: zoom-in;
}

.photo {
  width: 280px;
  max-width: 100%;
}

.photo img {
  display: block;
  width: 100%;
  height: auto;
}

/* A pin message: a zoomed-in square of the photo around the pointed spot. */
.crop {
  width: 200px;
  height: 200px;
}

.crop img {
  position: absolute;
  max-width: none;
}

.marker {
  position: absolute;
  width: 18px;
  height: 18px;
  margin: -9px 0 0 -9px;
  border: 3px solid #fff;
  border-radius: 50%;
  background: #ff7a1a;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.35), 0 2px 6px rgba(0, 0, 0, 0.5);
  pointer-events: none;
}

.marker.mine {
  background: #7c5cf0;
}

.marker.big {
  width: 30px;
  height: 30px;
  margin: -15px 0 0 -15px;
  border-width: 4px;
}

.marker.draft {
  background: #fff;
  border-color: #7c5cf0;
}

.marker .label {
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  margin-top: 6px;
  max-width: 180px;
  padding: 3px 8px;
  border-radius: 9px;
  background: rgba(0, 0, 0, 0.75);
  color: #fff;
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.meta {
  display: block;
  margin-top: 1px;
  text-align: right;
  font-size: 11px;
  opacity: 0.6;
  white-space: nowrap;
}

.has-img .meta {
  padding: 2px 8px 0;
}

.msg.pending .bubble {
  opacity: 0.6;
}

.msg.failed .bubble {
  cursor: pointer;
}

.msg.failed .meta {
  opacity: 1;
  font-weight: 600;
}

#composer {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  padding: 8px calc(env(safe-area-inset-right) + 8px) calc(env(safe-area-inset-bottom) + 8px) calc(env(safe-area-inset-left) + 8px);
  border-top: 1px solid var(--border);
  background: var(--panel);
}

/* With the keyboard up there is no home indicator to leave room for. */
body.keyboard #composer {
  padding-bottom: 8px;
}

#composer .icon-btn {
  color: var(--muted);
}

#composer .send {
  background: var(--accent);
  color: #fff;
}

#input {
  flex: 1;
  min-width: 0;
  max-height: 132px;
  padding: 9px 14px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--bg);
  resize: none;
  outline: none;
}

/* ---------- menu, photo viewer, toast ---------- */

dialog {
  width: min(92vw, 380px);
  max-height: 80vh;
  padding: 20px;
  border: 0;
  border-radius: 20px;
  background: var(--panel);
  color: var(--text);
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.5);
}

dialog h2 {
  margin: 0 0 12px;
  font-size: 19px;
}

dialog h3 {
  margin: 0;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
}

dialog p {
  margin: 0;
  font-size: 14px;
}

.group {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px 0 0;
}

.group + .group {
  margin-top: 14px;
  border-top: 1px solid var(--border);
}

#pushLog {
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: 12px;
  color: var(--muted);
  overflow-wrap: anywhere;
}

#pushLog li + li {
  margin-top: 4px;
}

#viewer {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  background: #000;
  color: #fff;
}

.viewer-top {
  display: flex;
  justify-content: flex-end;
  padding: calc(env(safe-area-inset-top) + 6px) 8px 6px;
}

/* The frame inside is sized by script to exactly the photo, so pins line up. */
#viewerStage {
  flex: 1;
  min-height: 0;
  display: grid;
  place-items: center;
  overflow: hidden;
}

#viewerFrame {
  position: relative;
  cursor: crosshair;
}

#viewerFrame img {
  display: block;
  width: 100%;
  height: 100%;
}

.viewer-bottom {
  padding: 10px 12px calc(env(safe-area-inset-bottom) + 10px);
}

body.keyboard .viewer-bottom {
  padding-bottom: 10px;
}

#viewerHint {
  margin: 0;
  min-height: 44px;
  display: grid;
  place-items: center;
  font-size: 14px;
  opacity: 0.7;
}

#pinBar {
  display: flex;
  gap: 8px;
}

#pinBar input {
  flex: 1;
  min-width: 0;
  padding: 10px 14px;
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.1);
  outline: none;
}

#pinBar button {
  border-color: rgba(255, 255, 255, 0.25);
}

#toast {
  position: absolute;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom) + 76px);
  z-index: 20;
  transform: translateX(-50%);
  max-width: 86%;
  padding: 9px 14px;
  border-radius: 14px;
  background: rgba(20, 16, 30, 0.92);
  color: #fff;
  font-size: 14px;
  text-align: center;
}

/* Layers of pin dots, over a photo in the list and over the open photo. */
.pins,
#viewerPins {
  position: absolute;
  inset: 0;
  pointer-events: none;
}
