/* Phantom Chat: P5R-style phone chat, recreated in CSS */
:root {
  color-scheme: dark;
  --red: #e60012;
  --red-dark: #8f000b;
  --black: #0a0a0a;
  --white: #ffffff;
  --display: 'Anton', 'Impact', sans-serif;
  --body: 'Noto Sans', system-ui, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }

html, body { height: 100%; }
body {
  background: var(--black);
  color: var(--white);
  font-family: var(--body);
  font-weight: 700;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}

.screen {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  height: 100dvh;
}

/* ---------- Login ---------- */
#login {
  align-items: center;
  justify-content: center;
  padding: 16px;
  background:
    linear-gradient(115deg, transparent 0 38%, var(--red) 38% 62%, transparent 62%),
    radial-gradient(circle, rgba(255,255,255,.08) 1.5px, transparent 2px) 0 0 / 10px 10px,
    var(--black);
}
.login-card { width: 100%; max-width: 360px; }

.logo {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  margin-bottom: 28px;
  font-family: var(--display);
  font-weight: 400;
  font-size: 46px;
  line-height: 1;
}
.logo > span { display: flex; gap: 2px; }
/* ransom-note letters, set up in app.js */
.logo .l {
  display: inline-block;
  padding: 2px 6px;
  border: 2px solid var(--black);
}
.logo .l.w { background: var(--white); color: var(--black); }
.logo .l.b { background: var(--black); color: var(--white); border-color: var(--white); }
.logo .l.r { background: var(--red); color: var(--white); }

#login-form { display: flex; flex-direction: column; gap: 14px; }
#login-form label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-family: var(--display);
  font-weight: 400;
  font-size: 18px;
  letter-spacing: 1px;
  transform: skewX(-8deg);
}
#login-form input {
  font: 700 18px var(--body);
  padding: 12px 14px;
  border: 3px solid var(--black);
  background: var(--white);
  color: var(--black);
  outline: none;
  clip-path: polygon(0 4%, 100% 0, 98% 100%, 1% 94%);
}
#login-form input:focus { background: #fff6c8; }
#login-form button, .composer button {
  font-family: var(--display);
  font-weight: 400;
  letter-spacing: 1px;
  color: var(--white);
  background: var(--black);
  border: 3px solid var(--white);
  cursor: pointer;
}
#login-form button {
  margin-top: 8px;
  padding: 14px;
  font-size: 24px;
  transform: skewX(-8deg) rotate(-2deg);
  box-shadow: 6px 6px 0 var(--red);
}
#login-form button:active { transform: skewX(-8deg) rotate(-2deg) translate(3px, 3px); box-shadow: 3px 3px 0 var(--red); }
.error { min-height: 1.4em; color: #ffe600; text-align: center; font-size: 15px; }

/* ---------- Chat ---------- */
#chat, #home { background: var(--bg); }
:root { --bg: #b0000b; --bg-shadow: #6e0007; }

.topbar {
  position: relative;
  flex: none;
  padding: calc(env(safe-area-inset-top) + 10px) 12px 10px;
  background: var(--black);
  border-bottom: 4px solid var(--white);
  z-index: 3;
}
.title {
  display: inline-block;
  padding: 2px 16px 2px 12px;
  background: var(--white);
  color: var(--black);
  font-family: var(--display);
  font-size: 26px;
  letter-spacing: 1px;
  transform: skewX(-12deg) rotate(-1.5deg);
  clip-path: polygon(0 8%, 100% 0, 96% 100%, 2% 92%);
}
.title span { display: inline-block; transform: skewX(12deg); }

.members { display: flex; gap: 4px; margin-top: 10px; overflow-x: auto; scrollbar-width: none; }
.members { gap: 2px; margin-top: 4px; }
.members .avatar { --av: 46px; flex: none; margin-top: 0; animation: none; }
.members .avatar.off { filter: grayscale(1) brightness(.5); }

.log {
  position: relative;          /* offsetParent for the path anchors */
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 18px 8px 24px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  overscroll-behavior: contain;
}

/* the black zigzag path behind the conversation, drawn by app.js */
.path {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  pointer-events: none;
  overflow: visible;
}
.path .shadow { stroke: var(--bg-shadow); }
.path .line { stroke: var(--black); }
.path polyline { fill: none; stroke-linejoin: miter; stroke-miterlimit: 12; }

/* one message */
.row { display: flex; align-items: flex-start; margin-left: var(--jx, 0px); }
.row.me { justify-content: flex-end; margin-left: 0; margin-right: var(--jx, 0px); }

.who { flex: none; width: var(--av, 110px); display: flex; flex-direction: column; align-items: center; gap: 2px; }
.row.me .who { display: none; }
.who .name {
  position: relative;
  z-index: 2;                 /* on top of the frame */
  max-width: 108px;
  font-size: 14px;
  letter-spacing: .5px;
  text-transform: uppercase;
  background: var(--black);
  border: 2px solid var(--white);
  padding: 1px 7px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transform: rotate(-4deg);
  margin-top: calc(var(--av, 110px) * -0.2);   /* overlap the bottom edge of the frame */
}

/* avatar: P5 icon frame (black outline, white border, colour inside) drawn as SVG in app.js.
   The top of the SVG is spare room so a portrait's head can break out over the frame. */
.avatar {
  position: relative;
  z-index: 1;
  display: block;
  width: var(--av, 110px);
  height: var(--av, 110px);
  margin-top: calc(var(--av, 110px) * -0.15);
  overflow: visible;
  animation: slide .28s ease-out both;
}
.avatar svg { display: block; width: 100%; height: 100%; overflow: visible; }

/* speech bubble: outline layer, bolt outline, fill layer, bolt fill */
.bubble {
  --out: var(--white);
  --in: var(--black);
  position: relative;
  z-index: 1;
  isolation: isolate;
  max-width: min(calc(100vw - 160px), 460px);
  margin: 24px 0 0 20px;
  padding: 13px 18px 15px 18px;
  color: var(--white);
  font-size: 15px;
  line-height: 1.4;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  transform: rotate(var(--tilt, 0deg));
  transform-origin: 0 24px;
  animation: pop .3s cubic-bezier(.2, 1.5, .4, 1) both;
  cursor: pointer;
}
.bubble::before, .bubble::after {
  content: '';
  position: absolute;
  clip-path: var(--shape);
}
.bubble::before { inset: -4px; z-index: -3; background: var(--out); }
.bubble::after { inset: 0; z-index: -1; background: var(--in); }
.bubble .tail {
  position: absolute;
  left: -27px;
  top: 10px;
  width: 38px;
  height: 30px;
  overflow: visible;
}
.bubble .tail.o { z-index: -2; fill: var(--out); stroke: var(--out); stroke-width: 8; stroke-linejoin: miter; }
.bubble .tail.i { z-index: 0; fill: var(--in); }

.shape-0 { --shape: polygon(0 5%, 100% 0, 97% 100%, 2% 93%); }
.shape-1 { --shape: polygon(2% 0, 98% 7%, 100% 94%, 0 100%); }
.shape-2 { --shape: polygon(0 0, 96% 4%, 100% 100%, 3% 95%); }

/* my messages: white, on the right, bolt pointing right */
.row.me .bubble {
  --out: var(--black);
  --in: var(--white);
  color: var(--black);
  margin: 0 26px 0 40px;
  transform-origin: 100% 24px;
}
.row.me .bubble .tail { left: auto; right: -27px; transform: scaleX(-1); }
.row.me .shape-0 { --shape: polygon(5% 0, 100% 8%, 98% 100%, 0 90%); }
.row.me .shape-1 { --shape: polygon(0 6%, 97% 0, 100% 92%, 4% 100%); }
.row.me .shape-2 { --shape: polygon(3% 0, 100% 3%, 96% 100%, 0 94%); }

/* "?" / "!" / "!?" pop-up on questions and shouting */
.badge {
  position: absolute;
  z-index: 2;
  top: -30px;
  right: -8px;
  font-family: var(--display);
  font-size: 36px;
  line-height: 1;
  color: var(--white);
  -webkit-text-stroke: 7px var(--black);
  paint-order: stroke fill;
  transform: rotate(12deg);
  animation: badge .4s .15s cubic-bezier(.2, 1.8, .4, 1) both;
}

.time {
  display: none;
  position: absolute;
  bottom: -18px;
  right: 6px;
  font-size: 10px;
  padding: 0 5px;
  background: var(--black);
  color: var(--white);
}
.bubble.show-time .time { display: block; }

.day {
  position: relative;
  z-index: 1;
  align-self: center;
  margin: 8px 0 0;
  padding: 2px 14px;
  background: var(--white);
  color: var(--black);
  border: 3px solid var(--black);
  font-family: var(--display);
  font-weight: 400;
  letter-spacing: 1px;
  font-size: 14px;
  transform: skewX(-12deg) rotate(-2deg);
}

@keyframes pop {
  0%   { transform: scale(.2) rotate(-12deg); opacity: 0; }
  60%  { transform: scale(1.05) rotate(calc(var(--tilt, 0deg) + 1.5deg)); opacity: 1; }
  100% { transform: scale(1) rotate(var(--tilt, 0deg)); }
}
@keyframes slide {
  0%   { transform: translateX(-30px); opacity: 0; }
  100% { transform: none; opacity: 1; }
}
@keyframes badge {
  0%   { transform: scale(0) rotate(40deg); }
  100% { transform: scale(1) rotate(12deg); }
}
.no-anim .bubble, .no-anim .avatar, .no-anim .badge { animation: none; }

/* composer */
.composer {
  position: relative;
  z-index: 3;
  flex: none;
  display: flex;
  gap: 8px;
  padding: 10px 10px calc(env(safe-area-inset-bottom) + 10px);
  background: var(--black);
  border-top: 4px solid var(--white);
}
.composer input {
  flex: 1;
  min-width: 0;
  font: 700 16px var(--body);
  padding: 12px 14px;
  border: none;
  outline: none;
  background: var(--white);
  color: var(--black);
  clip-path: polygon(0 6%, 100% 0, 99% 100%, 1% 92%);
}
.composer button {
  flex: none;
  padding: 0 18px;
  font-size: 20px;
  background: var(--red);
  border-color: var(--white);
  transform: skewX(-10deg);
}
.composer button:active { background: var(--white); color: var(--red); }

.status {
  position: fixed;
  top: calc(env(safe-area-inset-top) + 60px);
  left: 50%;
  transform: translateX(-50%) rotate(-3deg);
  padding: 4px 14px;
  background: #ffe600;
  color: var(--black);
  font-family: var(--display);
  letter-spacing: 1px;
  border: 3px solid var(--black);
  z-index: 5;
}

/* ---------- Desktop / landscape: keep the chat in a column and scale it up ---------- */
@media (min-width: 720px) {
  :root { --col: 760px; --side: max(24px, calc((100vw - var(--col)) / 2)); }

  .topbar, .composer { padding-left: var(--side); padding-right: var(--side); }
  .log { padding: 26px var(--side) 34px; gap: 24px; }
  .title { font-size: 34px; }
  .members .avatar { --av: 58px; }

  .row { margin-left: calc(var(--jx, 0px) * 1.4); }
  .row.me { margin-right: calc(var(--jx, 0px) * 1.4); }
  .log { --av: 150px; }
  .who .name { max-width: 150px; font-size: 17px; }
  .bubble::before { inset: -5px; }

  .bubble {
    max-width: 540px;
    margin: 34px 0 0 30px;
    padding: 16px 26px 18px 24px;
    font-size: 19px;
  }
  .row.me .bubble { margin: 0 36px 0 60px; }
  .bubble .tail { left: -38px; top: 14px; width: 52px; height: 41px; }
  .row.me .bubble .tail { right: -38px; }
  .badge { font-size: 48px; top: -40px; -webkit-text-stroke-width: 9px; }
  .time { font-size: 12px; bottom: -22px; }
  .day { font-size: 17px; }

  .composer input { font-size: 18px; padding: 14px 18px; }
  .composer button { font-size: 24px; padding: 0 26px; }
}

/* NOTIFY ME + LOG OUT in the top bar */
.actions {
  position: absolute;
  right: 12px;
  top: calc(env(safe-area-inset-top) + 14px);
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
}
.notify, .logout {
  padding: 4px 12px;
  font-family: var(--display);
  font-size: 16px;
  letter-spacing: 1px;
  border: 3px solid var(--white);
  cursor: pointer;
}
.notify { color: var(--black); background: #ffe600; transform: skewX(-10deg) rotate(3deg); }
.notify:active { background: var(--white); }
.logout { color: var(--white); background: var(--black); font-size: 13px; padding: 2px 10px; transform: skewX(-10deg) rotate(-2deg); }
.logout:active { background: var(--red); }
.reset { background: var(--red); transform: skewX(-10deg) rotate(2deg); }
.reset:active { background: var(--black); }
@media (min-width: 720px) { .actions { right: var(--side); } .notify { font-size: 19px; } .logout { font-size: 15px; } }

/* ---------- Home: chat list ---------- */
.topbar .head { display: flex; align-items: center; gap: 12px; padding-right: 120px; }
.back {
  flex: none;
  width: 50px;
  height: 40px;
  display: grid;
  place-items: center;
  background: var(--black);
  border: 3px solid var(--white);
  transform: skewX(-10deg);
  cursor: pointer;
}
.back svg { width: 30px; height: 24px; fill: var(--white); }
.back:active { background: var(--red); }

.chatlist {
  flex: 1;
  overflow-y: auto;
  padding: 26px 14px 30px;
  display: flex;
  flex-direction: column;
  gap: 22px;
  overscroll-behavior: contain;
}
.chatrow {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 8px 18px 10px 6px;
  margin-left: var(--jx, 0px);
  max-width: calc(100% - var(--jx, 0px));
  color: var(--white);
  background: var(--black);
  border: 3px solid var(--white);
  box-shadow: 6px 7px 0 var(--bg-shadow);
  font: inherit;
  text-align: left;
  cursor: pointer;
  transform: skewX(-8deg) rotate(var(--tilt, 0deg));
  animation: rowin .25s ease-out both;      /* moves with `translate`, so the slant from `transform` stays */
}
@keyframes rowin { from { translate: -30px 0; opacity: 0; } to { translate: 0 0; opacity: 1; } }
.chatrow > * { transform: skewX(8deg); }          /* contents stay upright */
.chatrow:active { background: var(--red); }
.chatrow .avatar { --av: 78px; flex: none; margin-top: -26px; animation: none; }
.chatrow .info { flex: 1; min-width: 0; }
.chatrow .cname {
  display: block;
  font-family: var(--display);
  font-weight: 400;
  font-size: 22px;
  letter-spacing: 1px;
  text-transform: uppercase;
  line-height: 1.1;
}
.chatrow .preview {
  display: block;
  margin-top: 3px;
  font-size: 14px;
  opacity: .8;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chatrow .when { align-self: flex-end; flex: none; font-size: 11px; opacity: .65; margin-bottom: 2px; }
.chatrow.unread .preview { opacity: 1; }

/* P5 starburst with the unread count */
.unread-badge {
  position: absolute;
  right: -14px;
  top: -20px;
  width: 50px;
  height: 50px;
  display: grid;
  place-items: center;
  animation: badge .4s cubic-bezier(.2, 1.8, .4, 1) both;
}
.unread-badge svg { position: absolute; inset: 0; width: 100%; height: 100%; }
.unread-badge span {
  position: relative;
  font-family: var(--display);
  font-size: 19px;
  color: var(--white);
  -webkit-text-stroke: 4px var(--black);
  paint-order: stroke fill;
}

@media (min-width: 720px) {
  .chatlist { padding: 34px var(--side) 40px; gap: 28px; }
  .chatrow .avatar { --av: 100px; margin-top: -34px; }
  .chatrow .cname { font-size: 28px; }
  .chatrow .preview { font-size: 16px; }
  .unread-badge { width: 60px; height: 60px; }
  .unread-badge span { font-size: 23px; }
}
