/* Friends chat. Bright, calm and readable for ten-year-olds.
   Colour pairs used for text were checked for at least 4.5:1 contrast. */

:root {
  --bg: #f6f2ff;
  --surface: #ffffff;
  --ink: #1d1b2f;
  --muted: #5a5670;
  --brand: #5b3cc4;      /* white on brand: 7.2:1 */
  --brand-ink: #ffffff;
  --mine: #5b3cc4;
  --mine-ink: #ffffff;
  --theirs: #ffffff;
  --theirs-ink: #1d1b2f;
  --line: #ddd5f3;
  --danger: #b3261e;     /* white on danger: 6.5:1 */
  --focus: #ff9f1c;
  --radius: 20px;
  --tap: 48px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15121f;
    --surface: #221d33;
    --ink: #f3f0ff;
    --muted: #b8b2d1;
    --brand: #8b6cff;    /* dark ink on this brand: 5.6:1 */
    --brand-ink: #15121f;
    --mine: #8b6cff;
    --mine-ink: #15121f;
    --theirs: #2d2742;
    --theirs-ink: #f3f0ff;
    --line: #3a3352;
    --danger: #ff8a80;
    color-scheme: dark;
  }
  .btn.danger { color: #15121f; }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font: 18px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}

#app { height: 100%; }

h1 { font-size: 1.6rem; margin: 0 0 .4rem; }
h2 { font-size: 1.3rem; margin: 0; }
h3 { font-size: 1.05rem; margin: 1.2rem 0 .5rem; }
p { margin: .4rem 0; }
.muted { color: var(--muted); }
.lead { font-size: 1.15rem; }
.loading { padding: 2rem; text-align: center; }

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
  border-radius: 8px;
}

/* ----- buttons and fields ----- */

.btn {
  min-height: var(--tap);
  min-width: var(--tap);
  padding: .6rem 1.1rem;
  border-radius: 999px;
  border: 2px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
}
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.ghost { background: transparent; }
.btn.small { min-height: 44px; padding: .4rem .9rem; font-size: .95rem; }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn[aria-checked="true"] { border-color: var(--brand); box-shadow: inset 0 0 0 2px var(--brand); }
.btn:disabled { opacity: .5; }

.field { display: grid; gap: .3rem; margin: .9rem 0; }
.field label { font-weight: 600; }
input, textarea, select {
  font: inherit;
  color: var(--ink);
  background: var(--surface);
  border: 2px solid var(--line);
  border-radius: 14px;
  padding: .65rem .8rem;
  min-height: var(--tap);
}
textarea { resize: none; width: 100%; }

/* ----- simple screens ----- */

.screen {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: max(24px, env(safe-area-inset-top)) 16px 24px;
}
.card {
  width: min(460px, 100%);
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: 0 6px 30px rgb(40 20 90 / .12);
}
.card .btn.primary { width: 100%; margin-top: .6rem; }
.form-error { color: var(--danger); font-weight: 600; }
.safety-code {
  font: 700 2rem/1.2 ui-monospace, "SF Mono", Consolas, monospace;
  letter-spacing: .08em;
  text-align: center;
  padding: .8rem;
  background: var(--bg);
  border-radius: 14px;
}
.safety-code.small { font-size: 1.1rem; padding: .2rem .5rem; display: inline-block; }

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

.chat {
  height: 100%;
  display: flex;
  flex-direction: column;
  max-width: 820px;
  margin: 0 auto;
}

.top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: .8rem;
  padding: max(12px, env(safe-area-inset-top)) 16px 10px;
  border-bottom: 2px solid var(--line);
  background: var(--bg);
}
.top h1 { font-size: 1.4rem; margin: 0; }
.top-actions { display: flex; gap: .4rem; flex-shrink: 0; }
.watchers { font-size: .9rem; color: var(--muted); margin: 0; }

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 12px 16px 20px;
  overscroll-behavior: contain;
}
.empty { text-align: center; color: var(--muted); margin-top: 3rem; }
.day {
  text-align: center;
  font-size: .85rem;
  color: var(--muted);
  margin: 1.2rem 0 .4rem;
  font-weight: 600;
}

.msg { display: flex; flex-direction: column; margin-top: .8rem; max-width: 80%; }
.msg.continues { margin-top: .25rem; }
.msg.mine { margin-left: auto; align-items: flex-end; }
.msg.theirs { margin-right: auto; align-items: flex-start; }
.who { font-size: .85rem; font-weight: 700; margin: 0 .5rem .15rem; }
.who .device { font-weight: 400; color: var(--muted); }
.msg time { font-size: .75rem; color: var(--muted); margin: .15rem .5rem 0; }

.bubble {
  border-radius: var(--radius);
  padding: .55rem .9rem;
  background: var(--theirs);
  color: var(--theirs-ink);
  box-shadow: 0 1px 3px rgb(40 20 90 / .1);
  overflow-wrap: anywhere;
}
.mine .bubble { background: var(--mine); color: var(--mine-ink); }
.bubble .text { margin: 0; white-space: pre-wrap; }
.bubble .big-emoji { font-size: 2.6rem; line-height: 1.2; }
.msg.is-sticker .bubble, .msg.is-drawing .bubble { background: none; box-shadow: none; padding: 0; }
.msg.is-text:has(.big-emoji) .bubble { background: none; box-shadow: none; padding: 0; }
img.sticker { width: 120px; height: 120px; display: block; }
canvas.drawing {
  display: block;
  width: min(320px, 70vw);
  height: auto;
  border-radius: 16px;
  border: 2px solid var(--line);
}
.voice { display: flex; align-items: center; gap: .5rem; }
.voice audio { max-width: 240px; height: 44px; }
.mine .voice .muted { color: inherit; }

/* ----- composer ----- */

.compose {
  border-top: 2px solid var(--line);
  padding: 8px 12px max(10px, env(safe-area-inset-bottom));
  background: var(--bg);
}
.compose.readonly p { text-align: center; color: var(--muted); margin: .5rem 0; }
.compose .row { display: flex; gap: .5rem; align-items: flex-end; }
.compose .send { flex-shrink: 0; }
.tools { display: flex; gap: .4rem; margin-bottom: .4rem; }
.tool {
  width: 52px;
  height: 48px;
  font-size: 1.5rem;
  border-radius: 14px;
  border: 2px solid var(--line);
  background: var(--surface);
  cursor: pointer;
}
.panel {
  max-height: 40vh;
  overflow-y: auto;
  margin-bottom: .5rem;
  background: var(--surface);
  border-radius: 16px;
  padding: .5rem;
}
.grid { display: grid; gap: .3rem; }
.emoji-grid { grid-template-columns: repeat(auto-fill, minmax(48px, 1fr)); }
.sticker-grid { grid-template-columns: repeat(auto-fill, minmax(88px, 1fr)); }
.emoji-btn, .sticker-btn {
  min-height: 48px;
  border: 0;
  background: transparent;
  font-size: 1.7rem;
  border-radius: 12px;
  cursor: pointer;
}
.sticker-btn img { width: 76px; height: 76px; display: block; margin: auto; }
.emoji-btn:hover, .sticker-btn:hover { background: var(--bg); }

/* ----- dialogs ----- */

.sheet {
  width: min(720px, calc(100% - 24px));
  max-height: calc(100% - 24px);
  border: 0;
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  padding: 1.2rem;
}
.sheet::backdrop { background: rgb(20 10 40 / .5); }
.sheet-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: .6rem; }

.draw-wrap { border: 2px solid var(--line); border-radius: 16px; overflow: hidden; }
.draw-canvas {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 4 / 3;
  touch-action: none;
  cursor: crosshair;
  background: #fff;
}
.swatches { display: flex; flex-wrap: wrap; gap: .4rem; margin: .7rem 0; }
.swatch {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 3px solid var(--line);
  background: var(--swatch);
  cursor: pointer;
}
.swatch[aria-checked="true"] { border-color: var(--ink); box-shadow: 0 0 0 3px var(--surface) inset; }
.draw-actions, .sizes, .voice-actions { display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; }
.draw-actions .btn.primary { margin-left: auto; }
.btn.record { background: var(--danger); border-color: var(--danger); color: #fff; font-size: 1.1rem; }
.voice-status { font-size: 1.1rem; }
.voice-preview { margin-top: .8rem; }
.voice-preview audio { width: 100%; }

.people { list-style: none; padding: 0; margin: .5rem 0; }
.people li {
  display: flex;
  flex-wrap: wrap;
  gap: .3rem .5rem;
  align-items: center;
  padding: .55rem 0;
  border-bottom: 1px solid var(--line);
}
.people .btn { margin-left: auto; }
.tag {
  font-size: .8rem;
  font-weight: 700;
  padding: .1rem .55rem;
  border-radius: 999px;
  background: var(--bg);
  color: var(--ink);
}
.invite { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: .6rem; align-items: center; }
.invite input { flex: 1 1 260px; font-size: .9rem; }
.request { padding: .7rem; border: 2px solid var(--line); border-radius: 16px; margin: .5rem 0; }
.request .row { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: .5rem; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: var(--ink);
  color: var(--bg);
  padding: .7rem 1.1rem;
  border-radius: 14px;
  max-width: calc(100% - 32px);
  z-index: 10;
}

@media (max-width: 480px) {
  .msg { max-width: 90%; }
  .top h1 { font-size: 1.2rem; }
}

@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; }
}

/* ----- chat list, friends and invites ----- */

.home { flex: 1; overflow-y: auto; padding: 8px 16px 16px; }
.conv-list { list-style: none; margin: 0; padding: 0; }
.conv {
  width: 100%;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: .1rem .6rem;
  text-align: left;
  min-height: 64px;
  padding: .7rem .9rem;
  margin: .4rem 0;
  border: 2px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  cursor: pointer;
}
.conv-title { font-weight: 700; display: flex; gap: .5rem; align-items: center; }
.conv-last { grid-column: 1; font-size: .9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge {
  grid-column: 2;
  grid-row: 1 / span 2;
  align-self: center;
  min-width: 28px;
  height: 28px;
  padding: 0 .4rem;
  border-radius: 999px;
  background: var(--brand);
  color: var(--brand-ink);
  font-weight: 700;
  display: grid;
  place-items: center;
}
.notice {
  width: 100%;
  min-height: var(--tap);
  margin: .4rem 0;
  padding: .7rem 1rem;
  border: 2px solid var(--focus);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
}
.home-actions { display: flex; gap: .5rem; justify-content: center; flex-wrap: wrap; }
.back { flex-shrink: 0; }
.top-title { flex: 1; min-width: 0; }
.top-title h1 { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row.wrap { flex-wrap: wrap; }

.share { display: grid; gap: .7rem; justify-items: center; margin: .6rem 0; }
.qr { width: min(260px, 70vw); height: auto; border-radius: 12px; border: 2px solid var(--line); }
.share-actions { display: flex; gap: .5rem; flex-wrap: wrap; justify-content: center; }
.link-input { width: 100%; font-size: .85rem; }
.steps { padding-left: 1.3rem; }
.steps li { margin: .4rem 0; }
.card .btn.ghost { width: 100%; margin-top: .4rem; }

.pick { border: 2px solid var(--line); border-radius: 16px; padding: .5rem .9rem; margin: 0 0 .8rem; }
.pick legend { font-weight: 700; padding: 0 .3rem; }
.check { display: flex; align-items: center; gap: .6rem; min-height: var(--tap); }
.check input { width: 26px; height: 26px; min-height: 0; accent-color: var(--brand); }
.check label { font-weight: 600; flex: 1; }
