/* HART web app, parents' settings and panel simulator (P04, P08, P09, P10). Plain CSS, no build step (D15). */

:root {
  --bg: #f4f2ee;
  --card: #ffffff;
  --ink: #1f1d1a;
  --muted: #6b665e;
  --line: #ddd8cf;
  --accent: #b5305b;
  --accent-ink: #ffffff;
  --ok: #2f7d4f;
  --warn: #a5541a;
  --dev: #fff2b3;
  --dev-ink: #5a4500;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #171614;
    --card: #222120;
    --ink: #ece9e4;
    --muted: #a39d93;
    --line: #3a3733;
    --accent: #ff6f97;
    --accent-ink: #1a0b10;
    --ok: #6fd39a;
    --warn: #f0a46a;
    --dev: #4a3c00;
    --dev-ink: #ffe680;
  }
}

* { box-sizing: border-box; }

/* The hidden attribute wins over any display set below. */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
}

h2 { font-size: 1rem; margin: 0 0 8px; }

button, .button, select, input {
  font: inherit;
  color: inherit;
  padding: 10px 16px;
  min-height: 44px; /* big enough for small fingers */
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--card);
  cursor: pointer;
}

input { cursor: text; }
input[type="number"] { width: 7.5em; }

button:disabled { opacity: 0.45; cursor: not-allowed; }
button:focus-visible, .button:focus-within, select:focus-visible, input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

a { color: var(--accent); }

.hint { margin: 0; font-size: 0.85rem; color: var(--muted); }

/* -- signing in (D36, D67, D68): big, few words, a picture or a code -------------- */

.screen-note { margin: 0; padding: 48px 16px; text-align: center; color: var(--muted); }

.screen {
  min-height: 100svh;
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 18px;
  padding: 24px 16px;
  text-align: center;
}

.screen-heart { width: min(40vw, 160px); fill: var(--accent); shape-rendering: crispEdges; }
.screen-heart--off { fill: var(--muted); opacity: 0.55; }
.screen-text { margin: 0; max-width: 28em; font-size: 1.15rem; }
.screen-text:empty { display: none; }

.big-button {
  font-size: 1.4rem;
  font-weight: 600;
  padding: 18px 40px;
  min-height: 72px;
  border-radius: 18px;
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}

/* A QR code to be signed in by a parent (D67, D68): big enough to scan from a
   phone across a table, dark on white with its quiet zone in any theme. */
.qr-box {
  width: min(78vw, 52svh, 340px);
  aspect-ratio: 1;
  background: #fff;
  border-radius: 12px;
  line-height: 0;
}

.qr { width: 100%; height: 100%; image-rendering: pixelated; border-radius: 12px; }

.screen-title { margin: 0; max-width: 24em; font-size: 1.35rem; overflow-wrap: anywhere; }

/* Faces to tap (D69): the children on a shared device, or whom a parent signs in on one. */
.face-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 160px));
  justify-content: center;
  gap: 14px;
  width: min(100%, 720px);
}

.person--big { padding: 10px; gap: 8px; }
.person--big .person-name { font-size: 1.1rem; }
.add-box { display: grid; justify-items: center; gap: 14px; }

/* -- the header and footer of a signed-in page ----------------------------------- */

.top-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 14px;
  padding: 8px 12px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
}

.who { font-weight: 700; font-size: 1.05rem; }

/* On a device of children, the child acting now: their face and name; tapped, back to the faces (D69). */
.me-button { display: inline-flex; align-items: center; gap: 10px; padding: 4px 14px 4px 4px; font-weight: 700; }
.face--me { width: 48px; flex: none; border-radius: 6px; }
.me-name { overflow-wrap: anywhere; }
.acting { display: inline-flex; align-items: center; gap: 8px; }
.top-link { display: inline-flex; align-items: center; min-height: 44px; font-weight: 600; }

/* A parent acting as one of their children (D52): a band says so at a glance. */
.acting-other .top-bar { box-shadow: inset 0 -4px 0 var(--accent); }
.acting-other .acting select { border-color: var(--accent); font-weight: 600; }

.foot {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 16px;
  max-width: 1100px;
  margin: 12px auto 0;
  padding: 20px 12px 32px;
  border-top: 1px solid var(--line);
}

.foot-link { color: var(--muted); font-size: 0.85rem; }

/* -- the panel simulator's bar: a development tool -------------------------------- */

.dev-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 14px;
  padding: 8px 12px;
  background: var(--dev);
  color: var(--dev-ink);
  border-bottom: 2px dashed currentColor;
  font-size: 0.9rem;
}

.dev-bar select, .dev-bar input, .dev-bar button {
  padding: 4px 8px;
  min-height: 36px;
  background: var(--card);
  color: var(--ink);
}

.dev-bar form { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; }
.dev-bar label { display: inline-flex; align-items: center; gap: 6px; }
.dev-bar input { width: 14em; max-width: 60vw; }
.dev-tag { font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; }
.dev-link { color: inherit; }

.status { margin-left: auto; }
.status::before { content: "●"; margin-right: 6px; }
.status[data-state="online"]::before { color: var(--ok); }
.status[data-state="connecting"]::before { color: var(--warn); }
.status[data-state="offline"]::before { color: var(--accent); }

/* -- the web app -------------------------------------------------------------------- */

.app {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 16px;
  padding: 12px;
  max-width: 1100px;
  margin: 0 auto;
}

@media (min-width: 860px) {
  .app { grid-template-columns: minmax(0, 560px) minmax(0, 1fr); align-items: start; }
  .draw { grid-row: span 2; }
}

.draw, .send, .inbox { display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; min-width: 0; }

.canvas-wrap {
  background: #000;
  border-radius: 8px;
  overflow: hidden;
  line-height: 0;
  /* The full width in portrait; in landscape no taller than the screen, so
     the colours and Send stay within reach. */
  width: min(100%, max(240px, calc(100svh - 120px)));
  margin-inline: auto;
}

#canvas, .draw-canvas {
  width: 100%;
  aspect-ratio: 1;
  image-rendering: pixelated;
  touch-action: none; /* drawing, not scrolling */
  cursor: crosshair;
}

.colours { display: grid; grid-template-columns: repeat(8, minmax(0, 1fr)); gap: 6px; }

.colours button {
  aspect-ratio: 1;
  min-height: 0;
  padding: 0;
  border: 3px solid transparent;
  border-radius: 50%;
}

.colours button[aria-checked="true"] { border-color: var(--ink); box-shadow: 0 0 0 2px var(--bg) inset; }

.tools { display: flex; flex-wrap: wrap; gap: 8px; }
.button { display: inline-flex; align-items: center; }

/* A button that is only a picture, such as full screen's (D82): its words are its label and tooltip. */
.icon-button { display: inline-flex; align-items: center; justify-content: center; min-width: 44px; padding: 8px; }
.icon { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.full-button { margin-left: auto; }
.full-button .icon--leave, .draw--full .full-button .icon--enter { display: none; }
.draw--full .full-button .icon--leave { display: block; }

/* Drafts on this device (D83): a picture of each, newest first, to tap open; a small cross deletes one. */
.drafts {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(64px, 1fr));
  gap: 10px;
}

.draft { position: relative; }
.draft-open { display: block; width: 100%; padding: 3px; border-width: 3px; border-radius: 10px; min-height: 0; background: #000; }
.draft[aria-current="true"] .draft-open { border-color: var(--accent); }
.draft-open canvas { display: block; width: 100%; aspect-ratio: 1; image-rendering: pixelated; border-radius: 5px; }

.draft-delete {
  position: absolute;
  top: -8px;
  right: -8px;
  width: 30px;
  height: 30px;
  min-height: 0;
  padding: 0;
  border-radius: 50%;
  font-size: 1.1rem;
  font-weight: 700;
  line-height: 1;
  background: var(--card);
}

/* Drawing full screen (D82): the drawing, its colours and tools fill the screen, by the browser's full screen
   or by covering the window where there is none. The canvas is as big as fits, the tools under it (upright)
   or beside it (sideways). */
.full-open, .full-open body { overflow: hidden; }

.draw.draw--full {
  position: fixed;
  inset: 0;
  z-index: 50;
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 12px max(12px, env(safe-area-inset-right)) 12px max(12px, env(safe-area-inset-left));
  overflow: auto;
  background: var(--bg);
  align-content: center;
  justify-items: center;
}

.draw--full > * { width: min(100%, 640px); }
.draw--full .canvas-wrap {
  width: min(100%, calc(100vh - 250px));
  width: min(100%, calc(100dvh - 250px));
}

@media (orientation: landscape) {
  .draw.draw--full {
    grid-template-columns: auto minmax(240px, 380px);
    column-gap: 20px;
    justify-content: center;
    align-items: center;
  }
  .draw--full > * { grid-column: 2; width: 100%; }
  .draw--full .canvas-wrap {
    grid-column: 1;
    grid-row: 1 / span 6;
    width: min(calc(100vw - 300px), calc(100vh - 24px));
    width: min(calc(100vw - 300px), calc(100dvh - 24px));
  }
}

.draw--full::backdrop { background: var(--bg); }

/* Who it is for (D64, D65): a group per family, own family first, each under its
   name; each person a big button with their picture, so a child who cannot read
   finds them by face. Up to 32 (D66) wrap into a grid that fits a phone. */
.people { display: grid; gap: 12px; }
.people-family { margin: 0 0 6px; font-size: 0.95rem; color: var(--muted); overflow-wrap: anywhere; }
.people-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 8px; }

.person {
  display: grid;
  align-content: start;
  justify-items: center;
  gap: 4px;
  min-width: 0;
  padding: 6px;
  border-width: 3px;
  border-radius: 14px;
}

.person-name {
  max-width: 100%;
  font-size: 0.9rem;
  font-weight: 600;
  line-height: 1.2;
  text-align: center;
  overflow-wrap: anywhere;
}

.person[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }

/* A profile picture (D64): 64 × 64 with sharp pixels. With none, or none to
   see, a plain placeholder: the empty canvas on a soft background. */
.face {
  display: block;
  width: 100%;
  aspect-ratio: 1;
  image-rendering: pixelated;
  border-radius: 8px;
  background: var(--line);
}

.face:not([data-pic="0"]) { background: #000; }

.send-button { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.result { margin: 0; min-height: 1.45em; }

.inbox-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }

.inbox-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  text-align: left;
}

.inbox-item canvas {
  width: 56px;
  height: 56px;
  image-rendering: pixelated;
  border-radius: 4px;
  background: #000;
  flex: none;
}

.viewer {
  border: none;
  border-radius: 12px;
  padding: 12px;
  background: var(--card);
  color: var(--ink);
  width: min(92vw, 640px);
}

.viewer::backdrop { background: rgba(0, 0, 0, 0.7); }
.viewer canvas { width: 100%; aspect-ratio: 1; display: block; border-radius: 6px; }

/* -- the panel simulator --------------------------------------------------------------- */

.panel-page { background: #0b0b0b; color: #ddd; }
.panel-page .dev-bar { background: #3a3000; color: #ffe680; }

.panel-main { display: grid; justify-items: center; gap: 10px; padding: 12px; }

.panel-frame {
  position: relative;
  width: min(94vw, calc(100vh - 140px), 900px);
  aspect-ratio: 1;
  border: 14px solid #000; /* the frame: both canvases fill exactly what is inside it */
  background: #000;
  border-radius: 10px;
  box-shadow: 0 0 0 6px #1b1b1b;
}

.panel-frame canvas { width: 100%; height: 100%; display: block; }
.panel-frame #fade { position: absolute; inset: 0; opacity: 0; }

.caption { margin: 0; color: #999; }
.panel-log { width: min(94vw, 900px); font-size: 0.85rem; color: #999; }
.panel-log ol { list-style: none; padding: 0; margin: 6px 0 0; max-height: 30vh; overflow-y: auto; }

/* -- the parents' settings (P08) ---------------------------------------------------------- */

.top-title { margin: 0; font-size: 1.1rem; }

.settings {
  display: grid;
  gap: 14px;
  max-width: 760px;
  margin: 0 auto;
  padding: 12px;
}

.cards { display: grid; gap: 14px; }

.card {
  display: grid;
  gap: 10px;
  min-width: 0;
  padding: 14px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
}

.card h2 { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin: 0; font-size: 1.15rem; }
.card h3 { margin: 0; font-size: 0.95rem; color: var(--muted); }
.card p { margin: 0; }

.part { display: grid; gap: 8px; padding-top: 10px; border-top: 1px solid var(--line); }
.part > button, .card > button { justify-self: start; }

.tag {
  padding: 2px 8px;
  font-size: 0.75rem;
  font-weight: 600;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--bg);
}

.tag--muted { font-weight: 400; color: var(--muted); }

.contacts, .pending-list, .devices, .passkeys { display: grid; gap: 8px; margin: 0; padding: 0; list-style: none; }
.contacts li, .pending-list li, .devices li, .passkeys li {
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px;
}
.contact-name { font-weight: 600; }

.row, .limit, .row label { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.limit, .row label { display: inline-flex; }

.made { display: grid; gap: 6px; padding: 10px; border-radius: 10px; background: var(--bg); }
.made-link { flex: 1 1 16em; min-width: 0; font-size: 0.85rem; }
.code-box { font-family: ui-monospace, "SF Mono", Menlo, monospace; letter-spacing: 0.08em; text-transform: uppercase; }
.made-code { width: 8.5em; font-size: 1.6rem; }

.note { margin: 0; }
.note:empty { display: none; }
.note[data-kind="ok"] { color: var(--ok); }
.note[data-kind="error"] { color: var(--accent); font-weight: 600; }

.busy, .busy button { cursor: progress; }

/* Names and pictures (D63, D64) and the order of the contact list (D65). */
.who-row { display: flex; align-items: center; gap: 12px; min-width: 0; }
.who-row h2 { flex: 1 1 auto; min-width: 0; overflow-wrap: anywhere; }
.face--card { width: 72px; flex: none; }
.face--small { width: 40px; flex: none; border-radius: 6px; }
.name-box { flex: 1 1 12em; min-width: 0; }

.contact-group { display: grid; gap: 6px; }
.contact-group + .contact-group { padding-top: 8px; }
.group-head { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; }
.group-head h4 { margin: 0; font-size: 0.95rem; overflow-wrap: anywhere; }
.contact-name { overflow-wrap: anywhere; }

.move { padding: 4px 10px; min-width: 44px; font-weight: 700; }

.face-dialog {
  border: none;
  border-radius: 12px;
  padding: 14px;
  background: var(--card);
  color: var(--ink);
  width: min(94vw, 480px);
  max-height: 96svh;
}

.face-dialog::backdrop { background: rgba(0, 0, 0, 0.7); }
.face-dialog[open] { display: grid; gap: 10px; }
.face-dialog h2 { margin: 0; font-size: 1.1rem; overflow-wrap: anywhere; }
/* The dialog is white: an outline keeps the white colour key in sight. */
.face-dialog .colours button:not([aria-checked="true"]) { box-shadow: 0 0 0 1px var(--line); }
.face-dialog .canvas-wrap { width: min(100%, max(200px, calc(96svh - 330px))); }

/* Framing a picked picture (D81): the picture in a square frame to drag and pinch, a live 64 × 64 preview with
   sharp pixels, a zoom slider, then Use or Cancel. Upright, the preview and slider come under the frame; on a
   sideways or wide screen, beside it, so the whole dialog fits the screen's height. */
.frame-dialog {
  border: none;
  border-radius: 12px;
  padding: 14px;
  background: var(--card);
  color: var(--ink);
  width: min(96vw, 520px);
  max-width: 96vw;
  max-height: 98svh;
  overflow: auto;
}

.frame-dialog::backdrop { background: rgba(0, 0, 0, 0.75); }
.frame-dialog[open] { display: grid; gap: 12px; grid-template-columns: minmax(0, 1fr); }

.frame-box {
  width: min(100%, max(200px, calc(98svh - 280px)));
  margin-inline: auto;
  background: #000;
  border-radius: 8px;
  overflow: hidden;
  line-height: 0;
}

.frame-canvas { display: block; width: 100%; aspect-ratio: 1; touch-action: none; cursor: grab; }
.frame-canvas:active { cursor: grabbing; }

.frame-side { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 12px 18px; min-width: 0; }
.frame-preview-box { width: 112px; flex: none; background: #000; border-radius: 6px; overflow: hidden; line-height: 0; }
.frame-preview { display: block; width: 100%; aspect-ratio: 1; image-rendering: pixelated; }
.frame-zoom-row { display: flex; align-items: center; gap: 8px; flex: 1 1 160px; min-width: 0; max-width: 360px; }
.frame-zoom-end { flex: none; font-size: 1.4rem; font-weight: 700; color: var(--muted); width: 1ch; text-align: center; }
.frame-zoom { flex: 1 1 auto; width: 100%; min-width: 0; min-height: 44px; padding: 0; border: none; background: none; }
.frame-tools { justify-content: center; }
.frame-tools button { min-width: 6.5em; }

@media (orientation: landscape) {
  .frame-dialog { width: fit-content; }
  .frame-dialog[open] {
    grid-template-columns: auto 210px;
    grid-template-rows: 1fr auto;
    align-items: center;
    column-gap: 16px;
  }
  .frame-box {
    grid-row: 1 / span 2;
    width: min(calc(98svh - 30px), calc(96vw - 270px), 640px);
    min-width: 160px;
  }
  .frame-side { flex-direction: column; flex-wrap: nowrap; align-self: center; }
  .frame-preview-box { width: min(140px, calc(98svh - 190px)); min-width: 64px; }
  .frame-zoom-row { flex: none; width: 100%; }
  .frame-tools { align-self: start; flex-wrap: nowrap; }
  .frame-tools button { min-width: 0; flex: 1; }
}
