/* An original 80s neon look: a dark night sky, a striped sunset and a glowing grid.
   Fonts already on the phone only: this page loads nothing from other sites. */
:root {
  color-scheme: dark;
  --night: #0d0221;
  --night-2: #1b0b3a;
  --panel: rgba(27, 11, 58, 0.82);
  --pink: #ff2a6d;
  --magenta: #b5179e;
  --purple: #7209b7;
  --cyan: #05d9e8;
  --yellow: #ffd319;
  --orange: #ff8a00;
  --ink: #f5f3ff;
  --dim: #c4b5fd;
  --error: #ff8fab;
  --display: Futura, "Trebuchet MS", "Century Gothic", system-ui, sans-serif;
  --body: "Avenir Next", "Segoe UI", system-ui, sans-serif;
  --radius: 10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: linear-gradient(180deg, var(--night) 0%, var(--night-2) 60%, #2a0845 100%) fixed;
  color: var(--ink);
  font: 15px/1.55 var(--body);
}

.masthead {
  padding: 14px 16px;
  border-bottom: 2px solid var(--pink);
  box-shadow: 0 2px 18px rgba(255, 42, 109, 0.45);
  background: rgba(13, 2, 33, 0.9);
}

.masthead-row {
  max-width: 600px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 12px;
}

.monogram {
  flex: none;
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border: 2px solid var(--cyan);
  border-radius: var(--radius);
  color: var(--cyan);
  font: italic 900 17px var(--display);
  text-shadow: 0 0 8px var(--cyan);
  box-shadow: 0 0 10px rgba(5, 217, 232, 0.6), inset 0 0 10px rgba(5, 217, 232, 0.35);
}

/* Sunset-coloured lettering with a neon glow. */
.title {
  margin: 0;
  font: italic 900 26px/1.1 var(--display);
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--yellow);
  background: linear-gradient(180deg, var(--yellow) 10%, var(--orange) 55%, var(--pink) 90%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 0 6px rgba(255, 42, 109, 0.7));
}

.status {
  margin: 0;
  color: var(--cyan);
  font-size: 12px;
  font-weight: bold;
  letter-spacing: 1px;
  text-transform: uppercase;
}

main {
  flex: 1;
  width: 100%;
  max-width: 600px;
  margin: 0 auto;
  padding: 24px 16px;
}

.panel {
  background: var(--panel);
  border: 2px solid var(--magenta);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: 0 0 22px rgba(181, 23, 158, 0.45);
}

label {
  display: block;
  margin-bottom: 16px;
  font-weight: bold;
  color: var(--dim);
}

/* 16px stops iPhones zooming the page when a box is tapped. */
input {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 10px 12px;
  background: rgba(13, 2, 33, 0.85);
  color: var(--ink);
  border: 2px solid var(--purple);
  border-radius: var(--radius);
  font: 16px var(--body);
}

input:focus {
  outline: none;
  border-color: var(--cyan);
  box-shadow: 0 0 12px rgba(5, 217, 232, 0.6);
}

input::placeholder { color: #9d8cc9; }

/* Chunky arcade buttons. */
button {
  min-height: 44px;
  padding: 10px 16px;
  background: linear-gradient(180deg, var(--pink), var(--magenta));
  color: #ffffff;
  border: 0;
  border-radius: var(--radius);
  box-shadow: 0 4px 0 #5a0a4f, 0 0 14px rgba(255, 42, 109, 0.5);
  font: italic 900 15px var(--display);
  letter-spacing: 0.5px;
  text-transform: uppercase;
  cursor: pointer;
}

button:active { transform: translateY(3px); box-shadow: 0 1px 0 #5a0a4f; }

button.quiet {
  background: transparent;
  box-shadow: none;
  color: var(--cyan);
  padding: 10px 0;
  font: 13px var(--body);
  text-transform: none;
  text-decoration: underline;
}

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

.error:empty, .notice:empty { display: none; }
.error { color: var(--error); font-weight: bold; }
.notice { color: var(--yellow); font-weight: bold; }

.actions {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-top: 16px;
}

.actions form { margin: 0; }

/* Chat page: one continuous scene behind everything. The header, face and composer stay put,
   the messages scroll between them, and the neon floor runs on under the chat. */
body.chat {
  height: 100dvh;
  overflow: hidden;
  background: var(--night);
}

.chat .masthead {
  position: relative;
  z-index: 3;
  padding: 8px 16px;
  background: linear-gradient(180deg, rgba(13, 2, 33, 0.85), rgba(13, 2, 33, 0));
  border-bottom: 0;
  box-shadow: none;
}
.chat .title { font-size: 18px; white-space: nowrap; }
.chat .status { font-size: 10px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat .monogram { width: 34px; height: 34px; font-size: 13px; }
.chat .masthead-row { gap: 10px; }
.masthead-text { flex: 1; min-width: 0; }

.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 12px;
  white-space: nowrap;
}

.header-actions form { margin: 0; }
.header-actions button.quiet { min-height: 0; padding: 0; font-size: 12px; }

/* The face: about 60% of a phone screen, much less while typing. No box round it: it stands
   in the scene, and the bottom of the picture fades into it. */
.stage {
  flex: none;
  position: relative;
  z-index: 1;
  height: min(58dvh, 560px);
  margin-top: -16px;
  transition: height 0.25s ease;
}

.stage[hidden] { display: none; }
/* Only on touch screens, where the keyboard covers the page. */
@media (pointer: coarse) {
  .chat.typing .stage { height: 110px; }
}

/* The scene, fixed behind the whole page, with its horizon just behind his shoulders. */
.scene {
  /* Where the face area ends: the header, then the face (see .stage). */
  --horizon: calc(36px + min(58dvh, 560px));
  position: fixed;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  pointer-events: none;
}

/* A slow, swirling glow of colour behind everything. */
.scene::before {
  content: "";
  position: absolute;
  inset: -50%;
  background: conic-gradient(from 0deg, #3a0ca3, #b5179e, #ff2a6d, #ff8a00, #05d9e8, #3a0ca3);
  opacity: 0.35;
  filter: blur(40px);
  animation: swirl 24s linear infinite;
}

/* A striped sunset sitting on the horizon. */
.sun {
  position: absolute;
  left: 50%;
  bottom: calc(100% - var(--horizon) + 30px);
  width: min(80vw, 380px);
  aspect-ratio: 1;
  transform: translate(-50%, 50%);
  border-radius: 50%;
  background:
    linear-gradient(180deg, transparent 0 30%, var(--night) 30% 31.5%, transparent 31.5% 37%,
      var(--night) 37% 39%, transparent 39% 43%, var(--night) 43% 45.5%, transparent 45.5% 48%,
      var(--night) 48% 50%, transparent 50%),
    linear-gradient(180deg, var(--yellow) 0%, var(--orange) 45%, var(--pink) 80%);
  -webkit-mask: linear-gradient(180deg, #000 50%, transparent 50%);
  mask: linear-gradient(180deg, #000 50%, transparent 50%);
  box-shadow: 0 0 60px rgba(255, 138, 0, 0.5);
  opacity: 0.9;
}

/* A glowing floor running from the horizon (just behind his shoulders) towards you, under the chat.
   Drawn as flat lines, not a tilted layer, so every browser draws it the same. */
.floor {
  position: absolute;
  left: 0;
  top: calc(var(--horizon) - 30px);
  width: 100%;
  height: calc(100% - var(--horizon) + 30px);
  background: linear-gradient(180deg, rgba(13, 2, 33, 0.95), rgba(13, 2, 33, 0.75));
}

.floor line {
  stroke: rgba(255, 42, 109, 0.85);
  stroke-width: 1.5;
  vector-effect: non-scaling-stroke;
}

/* The face sits in front, centred, as large as the stage allows. */
.face {
  position: absolute;
  inset: 8px 0 0;
  display: flex;
  justify-content: center;
  align-items: flex-end;
}

.face svg {
  height: 100%;
  width: auto;
  max-width: 100%;
}

/* The face is Brendan's photo remade from flat triangles, in three layers (face-*.webp): the
   face with a red glow round it, a jaw plate that drops as he speaks, and eyelids. */
.face .iris { fill: url(#iris-glow); mix-blend-mode: screen; }
#mouth-glow { fill: url(#mouth-light); mix-blend-mode: screen; opacity: 0; }

/* A red-to-magenta haze behind him: it breathes slowly, and flares with his voice
   (--level, set by chat.js from 0 to 1). */
.aura {
  position: absolute;
  inset: -10% -20% -45%;
  background:
    radial-gradient(ellipse 45% 55% at 50% 52%, rgba(255, 30, 40, 0.75), rgba(255, 30, 40, 0) 70%),
    radial-gradient(ellipse 60% 70% at 50% 45%, rgba(181, 23, 158, 0.55), rgba(181, 23, 158, 0) 75%);
  opacity: calc(0.55 + var(--level, 0) * 0.45);
  animation: breathe 4s ease-in-out infinite alternate;
}

@keyframes breathe {
  from { transform: scale(0.96); }
  to { transform: scale(1.05); }
}

/* The stutter's glitch: the face jolts about and splits into red and cyan for a moment, like a
   tape skipping. chat.js only adds .glitch while motion is allowed. */
.stage.glitch .face svg { animation: glitch 0.12s steps(1) infinite; }

@keyframes glitch {
  0% {
    transform: translate(-7px, 2px) skewX(-3deg);
    filter: drop-shadow(-6px 0 0 rgba(255, 30, 60, 0.75)) drop-shadow(6px 0 0 rgba(5, 217, 232, 0.75));
  }
  33% {
    transform: translate(6px, -3px) skewX(2deg);
    filter: drop-shadow(5px 0 0 rgba(255, 30, 60, 0.75)) drop-shadow(-5px 0 0 rgba(5, 217, 232, 0.75));
  }
  66% {
    transform: translate(-3px, -1px) scaleX(1.03);
    filter: drop-shadow(-3px 0 0 rgba(255, 30, 60, 0.6)) drop-shadow(3px 0 0 rgba(5, 217, 232, 0.6));
  }
}

/* A blink every few seconds: the eyelids show for a moment. */
.face .lids {
  opacity: 0;
  animation: blink 5.5s infinite;
}

@keyframes blink {
  0%, 95.5%, 100% { opacity: 0; }
  96.5%, 98% { opacity: 1; }
}

@keyframes swirl { to { transform: rotate(360deg); } }

/* Nothing moves for people who've asked their phone for less motion, or while it's hidden. */
@media (prefers-reduced-motion: reduce) {
  .scene::before, .aura, .face .lids { animation: none; }
  .stage { transition: none; }
}

.messages {
  position: relative;
  z-index: 2;
  flex: 1;
  min-height: 0;
  margin-top: -40px;
  -webkit-mask-image: linear-gradient(180deg, transparent 0, #000 40px);
  mask-image: linear-gradient(180deg, transparent 0, #000 40px);
  max-width: none;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 40px max(16px, calc((100% - 568px) / 2)) 12px;
}

.bubble {
  margin: 0;
  max-width: 85%;
  padding: 8px 12px;
  border-radius: var(--radius);
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.bubble.assistant {
  align-self: flex-start;
  background: rgba(13, 2, 33, 0.78);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  border: 1.5px solid var(--cyan);
  box-shadow: 0 0 10px rgba(5, 217, 232, 0.35);
}

.bubble.user {
  align-self: flex-end;
  background: linear-gradient(135deg, var(--magenta), var(--purple));
  color: #ffffff;
  box-shadow: 0 0 10px rgba(181, 23, 158, 0.45);
}

.bubble.unconfirmed { opacity: 0.6; }
.bubble.typing { color: var(--dim); font-style: italic; }

/* The web pages a searched reply cites, under it. */
.sources {
  align-self: flex-start;
  max-width: 85%;
  margin: -4px 0 0;
  padding: 0 12px;
  color: var(--dim);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.sources a { color: var(--cyan); }

.composer {
  position: relative;
  z-index: 3;
  background: linear-gradient(180deg, rgba(13, 2, 33, 0), rgba(13, 2, 33, 0.85) 45%);
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
}

.composer-row {
  max-width: 600px;
  margin: 0 auto;
  display: flex;
  gap: 8px;
}

.composer input { margin: 0; flex: 1; min-width: 0; }

.sound {
  flex: none;
  padding: 10px;
  background: transparent;
  color: var(--cyan);
  border: 2px solid var(--cyan);
  box-shadow: 0 0 8px rgba(5, 217, 232, 0.4);
}

.sound:active { box-shadow: none; }

.sound[aria-pressed="true"] {
  background: var(--cyan);
  color: var(--night);
  box-shadow: 0 0 14px rgba(5, 217, 232, 0.8);
}

.sound[hidden] { display: none; }

.heard {
  max-width: 600px;
  margin: 0 auto 8px;
  color: var(--dim);
  font-style: italic;
  overflow-wrap: anywhere;
}

.heard:empty { display: none; }

footer {
  padding: 16px;
  border-top: 2px solid var(--pink);
  color: var(--dim);
  font-size: 12px;
  text-align: center;
}

footer p { margin: 0; }
footer .credit { color: var(--yellow); }

/* The People page (/admin): one card per person, built for a phone. */
.people {
  list-style: none;
  margin: 16px 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.person {
  background: var(--panel);
  border: 1.5px solid var(--purple);
  border-radius: var(--radius);
  padding: 12px 14px;
}

.person-name { margin: 0 0 4px; font-weight: bold; font-size: 16px; }
.person-meta { margin: 0 0 10px; color: var(--dim); font-size: 13px; overflow-wrap: anywhere; }

.tag {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 8px;
  border: 1px solid var(--cyan);
  border-radius: 999px;
  color: var(--cyan);
  font-size: 11px;
  font-weight: bold;
  text-transform: uppercase;
  vertical-align: middle;
}

.tag.off { border-color: var(--error); color: var(--error); }

.person-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.person-actions form { margin: 0; }

button.small { min-height: 38px; padding: 6px 12px; font-size: 13px; }

button.warn {
  background: transparent;
  color: var(--error);
  border: 2px solid var(--error);
  box-shadow: none;
}

.cap-form { display: flex; gap: 6px; align-items: center; }
.cap-form input { width: 76px; margin: 0; padding: 7px 8px; }

.link-panel { margin-bottom: 16px; border-color: var(--cyan); box-shadow: 0 0 18px rgba(5, 217, 232, 0.45); }
.link-panel input { font-size: 14px; }
.add-person { margin-bottom: 8px; }

/* On a phone the header holds the title and up to four links (People is for admins only). */
@media (max-width: 420px) {
  .chat .masthead { padding: 8px 10px; }
  .chat .masthead-row { gap: 8px; }
  .chat .monogram { display: none; }
  .chat .title { font-size: 16px; }
  .header-actions { gap: 9px; }
  .header-actions, .header-actions button.quiet { font-size: 11px; }
}
