:root {
  --bg: #fff4dc;
  --ink: #3b2f22;
  --card: #fffdf7;
  --orange: #ff8a1f;
  --red: #ec3d36;
  --green: #22b24c;
  --blue: #2f7cf6;
  --ring: #ff8a1f;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg) radial-gradient(circle at 50% 120%, #ffe2a8, transparent 70%);
  color: var(--ink);
  font: 600 16px/1.2 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
button { font: inherit; color: inherit; border: 0; padding: 0; background: none; cursor: pointer; }
.icon { width: 50%; height: 50%; fill: currentColor; color: #fff; pointer-events: none; }

/* Login (for grown-ups) */
#login { height: 100%; display: grid; place-items: center; padding: 1rem; }
#login form { width: min(22rem, 100%); display: grid; gap: .8rem; text-align: center; }
#login .logo { width: 5rem; margin: 0 auto; }
#login h1 { margin: 0 0 .5rem; font-size: 1.8rem; }
#login input { font: inherit; font-size: 1.2rem; padding: .9rem 1rem; border: 2px solid #e8d8b8; border-radius: 14px; background: #fff; user-select: text; -webkit-user-select: text; }
#login input { -webkit-touch-callout: default; } /* copy and paste work here */
#login form > button { font-size: 1.3rem; padding: .9rem; border-radius: 14px; background: var(--orange); color: #fff; }
.pw { position: relative; display: grid; }
.pw input { padding-right: 3.4rem; }
.eye { position: absolute; right: .4rem; top: 50%; transform: translateY(-50%); width: 2.8rem; height: 2.8rem; display: grid; place-items: center; color: #8a7d69; }
.eye svg { width: 1.6rem; height: 1.6rem; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.eye[aria-pressed="true"] .slash { display: none; }
#login .error { color: var(--red); margin: 0; }

#app { height: 100vh; height: 100dvh; }
#app > section { height: 100%; padding: max(2vmin, env(safe-area-inset-top)) 2vmin max(2vmin, env(safe-area-inset-bottom)); }

/* People */
.avatar {
  position: relative;
  display: grid;
  place-items: center;
  flex: none;
  width: var(--s);
  height: var(--s);
  border-radius: 50%;
  background: var(--c, #ffd166);
  box-shadow: 0 1vmin 2.5vmin rgba(90, 60, 20, .18), inset 0 0 0 .6vmin rgba(255, 255, 255, .6);
}
.avatar img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; }
.avatar .emoji { font-size: calc(var(--s) * .58); line-height: 1; font-family: "Noto Color Emoji", "Apple Color Emoji", "Segoe UI Emoji", sans-serif; }
.count {
  position: absolute; right: -1.2vmin; top: -1.2vmin; min-width: 8vmin; height: 8vmin; padding: 0 1.5vmin;
  border-radius: 4vmin; background: var(--blue); color: #fff; font-size: 4.6vmin; display: grid; place-items: center;
  box-shadow: 0 .5vmin 1.5vmin rgba(0, 0, 0, .25);
}
.count:empty { display: none; }

/* Contacts: app.js sets the columns and the picture size (--s) so that everyone fits */
#home { position: relative; }
#contacts { height: 100%; display: grid; gap: 4vmin; align-content: center; justify-items: center; overflow: hidden auto; padding: 4vmin 2vmin; scrollbar-width: none; --s: 24vmin; }
#contacts::-webkit-scrollbar { display: none; }
.contact { display: grid; justify-items: center; gap: 1.4vmin; width: 100%; min-width: 0; transition: transform .15s; }
.contact .name { font-size: 4vmin; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.contact:active { transform: scale(.94); }
.contact.unheard { animation: bounce 1.1s ease-in-out infinite; }
.contact.unheard .avatar { animation: glow 1.1s ease-in-out infinite alternate; }
#me { position: absolute; top: max(2vmin, env(safe-area-inset-top)); right: 2vmin; --s: 9vmin; opacity: .75; }
#me .avatar { box-shadow: none; }

/* Conversation: header and messages, the microphone below (phones) or on the right (the Pi) */
#chat {
  display: grid;
  gap: 2vmin;
  grid-template-rows: auto minmax(0, 1fr) auto;
  grid-template-areas: "head" "list" "controls";
}
@media (orientation: landscape) {
  #chat { grid-template-columns: minmax(0, 1fr) minmax(0, 38vw); grid-template-rows: auto minmax(0, 1fr); grid-template-areas: "head controls" "list controls"; }
}
#head { grid-area: head; display: flex; align-items: center; gap: 3vmin; min-width: 0; }
#back { position: relative; flex: none; width: 14vmin; height: 14vmin; border-radius: 50%; background: #fff; display: grid; place-items: center; box-shadow: 0 1vmin 2.5vmin rgba(90, 60, 20, .18); transition: transform .1s, opacity .2s; }
#back .icon { color: var(--ink); width: 56%; height: 56%; }
#back:active { transform: scale(.92); }
#back.disabled { opacity: .3; pointer-events: none; }
#back.unheard { animation: glow 1.1s ease-in-out infinite alternate; }
#back .count { right: -2vmin; top: -2vmin; min-width: 7vmin; height: 7vmin; font-size: 4vmin; }
#who { display: flex; align-items: center; gap: 2.5vmin; min-width: 0; --s: 12vmin; }
#who .name { font-size: 5.5vmin; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

#list { grid-area: list; display: flex; flex-direction: column; gap: 2.2vmin; overflow: hidden auto; overscroll-behavior: contain; padding: 1.5vmin 1vmin 2vmin; scrollbar-width: none; }
#list::-webkit-scrollbar { display: none; }
#list .empty { margin: auto; opacity: .3; --s: 30vmin; }
.row { display: flex; align-items: flex-end; gap: 1.5vmin; --s: 8vmin; }
.row:first-child { margin-top: auto; } /* few messages sit at the bottom, next to the microphone */
.row.out { flex-direction: row-reverse; }
.row > .avatar { box-shadow: none; }
.bubble {
  display: flex; align-items: center; gap: 2vmin; width: var(--w); min-width: 0; max-width: calc(100% - 10vmin);
  padding: 1.5vmin 2.4vmin 1.5vmin 1.5vmin; border-radius: 5vmin; background: var(--card); text-align: left;
  box-shadow: 0 .6vmin 1.6vmin rgba(90, 60, 20, .13); transition: transform .1s;
}
.bubble:active { transform: scale(.97); }
.row.in .bubble { border-bottom-left-radius: 1.5vmin; }
.row.out .bubble { background: #e3f5cf; border-bottom-right-radius: 1.5vmin; }
.bubble .play { flex: none; width: 10vmin; height: 10vmin; box-shadow: none; }
.bubble .play .icon { width: 52%; height: 52%; }
.wave { flex: 1; min-width: 0; height: 7vmin; display: flex; align-items: center; gap: .45vmin; }
.wave i { flex: 1; height: calc(var(--h) * 100%); border-radius: 1vmin; background: #cdbfa6; }
.row.out .wave i { background: #a9c99a; }
.wave i.on, .row.out .wave i.on { background: var(--blue); }
.meta { flex: none; display: grid; justify-items: end; gap: .6vmin; font-size: max(11px, 2.6vmin); font-weight: 500; color: #8a7d69; }
.meta .tick { width: 1.3em; height: 1.3em; vertical-align: -.3em; color: #b3a68f; }
.row.heard .meta .tick { color: var(--blue); }
.row.new .bubble { box-shadow: 0 0 0 .8vmin rgba(47, 124, 246, .6), 0 .6vmin 1.6vmin rgba(90, 60, 20, .13); }
.row.new > .avatar { animation: glow 1.1s ease-in-out infinite alternate; }
.row.playing .bubble .play { animation: pulse .8s ease-in-out infinite alternate; }

#controls { grid-area: controls; position: relative; display: grid; place-items: center; min-height: 0; padding: 3vmin 0; }

/* Big round buttons */
.big, .round { position: relative; border-radius: 50%; display: grid; place-items: center; color: #fff; transition: transform .1s, filter .2s; }
.big:active, .round:active { transform: scale(.93); }
.orange { background: radial-gradient(circle at 35% 30%, #ffb15c, var(--orange) 60%, #e86f00); box-shadow: 0 2vmin 4vmin rgba(232, 111, 0, .45); }
.red { background: radial-gradient(circle at 35% 30%, #ff7a73, var(--red) 60%, #c9221c); box-shadow: 0 1.6vmin 3vmin rgba(201, 34, 28, .4); }
.green { background: radial-gradient(circle at 35% 30%, #5fe07f, var(--green) 60%, #12903a); box-shadow: 0 1.6vmin 3vmin rgba(18, 144, 58, .4); }
.blue { background: radial-gradient(circle at 35% 30%, #74a8ff, var(--blue) 60%, #1a5ed1); box-shadow: 0 1.6vmin 3vmin rgba(26, 94, 209, .4); }

#mic { width: min(46vmin, 26vh); height: min(46vmin, 26vh); --lvl: 0; }
@media (orientation: landscape) { #mic { width: min(46vmin, 32vw); height: min(46vmin, 32vw); } }
#mic .icon { width: 46%; height: 46%; }
#mic .ring { position: absolute; inset: -3vmin; width: calc(100% + 6vmin); height: calc(100% + 6vmin); transform: rotate(-90deg); pointer-events: none; overflow: visible; }
#mic .ring circle { fill: none; stroke: var(--red); stroke-width: 3.5; stroke-linecap: round; stroke-dasharray: 295.3; stroke-dashoffset: 295.3; opacity: 0; }
#mic.ready { animation: breathe 1.6s ease-in-out infinite; }
#mic.recording { background: radial-gradient(circle at 35% 30%, #ff7a73, var(--red) 60%, #c9221c); box-shadow: 0 0 0 calc(1.5vmin + var(--lvl) * 7vmin) rgba(236, 61, 54, .28), 0 2vmin 4vmin rgba(201, 34, 28, .4); }
#mic.finishing { background: radial-gradient(circle at 35% 30%, #ff7a73, var(--red) 60%, #c9221c); filter: saturate(.45); transform: scale(.94); }
#mic.recording .ring circle { opacity: 1; }
#mic.disabled { filter: grayscale(1) opacity(.6); }

#review { display: grid; grid-template-areas: "discard play send"; align-items: center; justify-items: center; gap: 5vmin; }
#discard { grid-area: discard; width: 22vmin; height: 22vmin; }
#play { grid-area: play; width: 22vmin; height: 22vmin; }
#send { grid-area: send; width: 28vmin; height: 28vmin; }
.play .icon, #play .icon { margin-left: 6%; }
#play.playing { animation: pulse .8s ease-in-out infinite alternate; }
#send.failed { animation: wiggle .4s ease-in-out 2; }
@media (orientation: landscape) {
  #review { grid-template-areas: "play play" "discard send"; gap: 4vmin; }
  #discard, #send { width: 25vmin; height: 25vmin; }
}
#send .to { position: absolute; right: -2vmin; top: -2vmin; --s: 11vmin; width: var(--s); height: var(--s); }
#send .to:empty { display: none; }
#send.busy { filter: saturate(.4); pointer-events: none; }

#sent { width: min(40vmin, 26vh); height: min(40vmin, 26vh); border-radius: 50%; background: var(--green); display: grid; place-items: center; animation: pop 1.4s ease-out forwards; }
#send .to .avatar { width: 100%; height: 100%; }

/* "Tap to start" (browsers need a touch before they may play sound) */
#start { position: fixed; inset: 0; display: grid; place-items: center; background: rgba(255, 244, 220, .92); }
#start .icon { width: 40vmin; height: 40vmin; color: var(--orange); fill: none; animation: tap 1.2s ease-in-out infinite; }

@keyframes breathe { 50% { transform: scale(1.06); } }
@keyframes glow { from { box-shadow: 0 0 0 0 rgba(255, 196, 0, .9); } to { box-shadow: 0 0 0 2.4vmin rgba(255, 196, 0, .25); } }
@keyframes bounce { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-1.5vmin); } }
@keyframes pulse { to { transform: scale(1.1); } }
@keyframes wiggle { 25% { transform: rotate(-6deg); } 75% { transform: rotate(6deg); } }
@keyframes pop { 0% { transform: scale(.3); opacity: 0; } 25% { transform: scale(1.1); opacity: 1; } 40% { transform: scale(1); } 85% { opacity: 1; } 100% { opacity: 0; transform: scale(1.05); } }
@keyframes tap { 50% { transform: translateY(3vmin) scale(.92); } }
