/* ---------------------------------------------------------------
   JAM — Voice Notes
   Phone art: Assets/phone-frame.png (2314x4390, transparent screen).

   The art is hand-drawn, so its four inner corners have different
   radii (TL ~12.7%, TR ~11.4%, BL ~9.5% of phone width) and no single
   CSS radius can trace them. Instead the screen is oversized so it
   runs UNDER the bezel on all four sides — the art then defines the
   visible corner shape and there is nothing to misalign.

   Aperture, measured off the PNG's alpha channel:
     left 8.861%  top 4.667%  width 82.595%  height 91.000%
     bezel: 6.65% of width each side, 3.33% / 3.67% of height
   The bleed below is ~half the bezel, verified against the alpha mask
   to leave zero gap and zero spill past the phone silhouette.
   --------------------------------------------------------------- */

:root {
  /* One solid ground everywhere — page and app screen alike. */
  --page:        #FDF088;
  --bg:          #FDF088;

  --accent:      #FF120A;           /* bubbles, header, buttons */
  --accent-deep: #C40E08;           /* borders and focus rings  */
  --accent-ink:  #8C0A05;           /* red type on the yellow — 8.3:1 */
  --cream:       #FFF7D8;
  --ink:         #33110C;

  /* phone geometry — aperture plus a bleed that tucks under the bezel */
  --phone-ratio: 0.527107;          /* 2314 / 4390 */
  --screen-l:  5.861%;              /* 8.861% aperture − 3.0% bleed   */
  --screen-t:  3.067%;              /* 4.667% aperture − 1.6% bleed   */
  --screen-w: 88.595%;              /* 82.595% aperture + 2 × 3.0%    */
  --screen-h: 94.200%;              /* 91.000% aperture + 2 × 1.6%    */

  --pw: clamp(220px, min(86vw, 42vh), 400px);   /* phone width  */
  --ph: calc(var(--pw) / 0.527107);             /* phone height */

  /* how far the screen runs under the bezel — content is inset by this
     much again so nothing readable hides beneath the frame */
  --bleed-x: calc(var(--pw) * .030);
  --bleed-y: calc(var(--ph) * .016);

  /* The notch bites .030 of phone height below the aperture top (measured off
     the frame's alpha), and the screen starts --bleed-y above the aperture, so
     from the screen's own top edge the notch ends here. */
  --notch-clear: calc(var(--ph) * .046);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* soft vignette so the phone reads as an object on the yellow */
.stage {
  position: relative;
  min-height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(14px, 2.6vh, 30px);
  padding: clamp(12px, 3vh, 40px) 16px;
}

/* Page title. The source jpg is black type on a flat #F1ECE8 ground, so it
   was keyed to a transparent PNG — multiply blending would have rendered
   that ground as #CEC1BB, a visibly darker block against the page. */
.wordmark {
  flex: none;
  width: min(var(--pw), 80vw);
  height: auto;
  display: block;
  user-select: none;
}

/* ---------------------------------------------------------------
   Phone
   --------------------------------------------------------------- */

.phone {
  position: relative;
  width: var(--pw);
  aspect-ratio: var(--phone-ratio);
  filter: drop-shadow(0 26px 34px rgba(52, 44, 40, .34))
          drop-shadow(0 4px 10px rgba(52, 44, 40, .24));
}

.frame {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 2;
  pointer-events: none;      /* clicks pass through to the UI beneath */
  user-select: none;
}

.screen {
  position: absolute;
  left: var(--screen-l);
  top: var(--screen-t);
  width: var(--screen-w);
  height: var(--screen-h);
  z-index: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  border-radius: calc(var(--pw) * .155);   /* only has to avoid spill */
  font-size: calc(var(--pw) * .0355);
}

/* ---------------------------------------------------------------
   Header
   --------------------------------------------------------------- */

.chat-header {
  flex: none;
  background: var(--accent);
  color: var(--cream);
  box-shadow: 0 .4em 1.1em rgba(120, 10, 6, .18);
  z-index: 3;
}

/* clears the notch, plus breathing room so it does not crowd the group name */
.notch-space { height: calc(var(--notch-clear) + var(--ph) * .014); }

.chat-header__row {
  display: flex;
  align-items: center;
  gap: .7em;
  padding: .5em calc(1em + var(--bleed-x)) .85em;
}

.back { width: 1.3em; height: 1.3em; flex: none; opacity: .9; }
.back svg { width: 100%; height: 100%; display: block; }

.avatar {
  border-radius: 50%;
  object-fit: cover;
  object-position: 50% 35%;
  flex: none;
  background: var(--bg);
}

.avatar--header {
  width: 2.5em;
  height: 2.5em;
  object-position: 50% 50%;   /* group artwork, not a face crop */
  box-shadow: 0 0 0 .13em var(--cream);
}

.chat-header__id { display: flex; flex-direction: column; line-height: 1.15; min-width: 0; }

.chat-header__name {
  font-size: 1.22em;
  font-weight: 800;
  letter-spacing: .015em;
}

.chat-header__status {
  display: flex;
  align-items: center;
  gap: .4em;
  font-size: .82em;
  font-weight: 500;
  opacity: .82;
  margin-top: .18em;
}

.dot {
  width: .48em; height: .48em;
  border-radius: 50%;
  background: #7CE08A;
  box-shadow: 0 0 0 .1em rgba(124,224,138,.3);
}

.chat-header__icons {
  margin-left: auto;
  display: flex;
  gap: .75em;
  opacity: .85;
}
.chat-header__icons svg { width: 1.25em; height: 1.25em; display: block; }

/* ---------------------------------------------------------------
   Thread
   --------------------------------------------------------------- */

.thread {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  display: flex;
  flex-direction: column;
  gap: .45em;
  padding: 1.2em calc(.9em + var(--bleed-x)) 1.1em;
  scrollbar-width: none;
}
.thread::-webkit-scrollbar { display: none; }

/* messages stack up from the bottom without the flex-end scroll-clipping bug */
.thread > :first-child { margin-top: auto; }

.day {
  align-self: center;
  font-size: .72em;
  font-weight: 700;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--accent-ink);
  background: rgba(255, 18, 10, .12);
  padding: .45em 1em;
  border-radius: 999px;
  margin: .7em 0 .45em;
}

.msg {
  display: flex;
  align-items: flex-end;
  gap: .55em;
}

/* the sender's name heads the run; only the last bubble keeps the avatar */
.sender {
  display: block;
  font-size: .74em;
  font-weight: 800;
  letter-spacing: .05em;
  text-transform: uppercase;
  color: var(--bg);
  margin-bottom: .45em;
}

.msg:not(.msg--head) .sender { display: none; }

.msg:not(.msg--tail) .avatar--msg { visibility: hidden; }

.msg:not(.msg--tail) .note,
.msg:not(.msg--tail) .bubble { border-bottom-left-radius: 1.35em; }

.avatar--msg {
  width: 1.9em;
  height: 1.9em;
  margin-bottom: .15em;
  box-shadow: 0 .1em .3em rgba(120, 10, 6,.25);
}

/* ---------------------------------------------------------------
   Voice note bubble
   --------------------------------------------------------------- */

.note,
.bubble {
  position: relative;
  flex: 1;
  min-width: 0;
  background: var(--accent);
  color: var(--cream);
  border-radius: 1.35em;
  border-bottom-left-radius: .4em;
  padding: .8em .95em .55em;
  box-shadow: 0 .35em .9em rgba(120, 10, 6, .28);
}

.note {
  cursor: pointer;
  transition: transform .18s ease, box-shadow .18s ease;
  -webkit-tap-highlight-color: transparent;
}

/* bubbles that hug their content rather than filling the row */
.bubble--text,
.bubble--image,
.bubble--link { flex: 0 1 auto; }

.bubble__body {
  margin: 0;
  font-size: .95em;
  line-height: 1.4;
  letter-spacing: .005em;
}

/* picture message */
.bubble--image {
  max-width: 72%;
  padding: .34em .34em .3em;
}

.bubble__img {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 1.05em;
  border-bottom-left-radius: .3em;
  background: rgba(255, 247, 216, .18);
}

.bubble--image .note__meta { margin: .28em .35em .1em; }
.bubble--image .sender { margin: .22em .4em .4em; }

/* url message */
.bubble--link { max-width: 88%; }

.bubble__link {
  display: flex;
  align-items: center;
  gap: .45em;
  color: var(--cream);
  font-size: .95em;
  font-weight: 600;
  line-height: 1.35;
  text-decoration: underline;
  text-underline-offset: .18em;
  text-decoration-thickness: .08em;
  overflow-wrap: anywhere;
}
.bubble__link:hover { text-decoration-thickness: .14em; }
.bubble__link:focus-visible { outline: .16em solid var(--cream); outline-offset: .2em; border-radius: .3em; }
.bubble__link svg { width: .95em; height: .95em; flex: none; opacity: .8; }

.note:hover { transform: translateY(-1px); box-shadow: 0 .5em 1.1em rgba(120, 10, 6,.34); }
.note:active { transform: translateY(0); }
.note:focus-visible { outline: .18em solid var(--accent-deep); outline-offset: .22em; }

.note__file {
  display: flex;
  align-items: center;
  gap: .4em;
  font-family: "DM Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: .72em;
  letter-spacing: .01em;
  color: rgba(255, 247, 216, .84);
  margin-bottom: .55em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.note__file svg { width: 1.05em; height: 1.05em; flex: none; }

.note__player {
  display: flex;
  align-items: center;
  gap: .7em;
}

.play {
  position: relative;
  flex: none;
  width: 2.5em;
  height: 2.5em;
  border: 0;
  padding: 0;
  border-radius: 50%;
  background: var(--cream);
  color: var(--accent);
  display: grid;
  place-items: center;
  cursor: pointer;
  box-shadow: 0 .12em .35em rgba(90, 8, 5, .3);
  transition: transform .15s ease;
}
.play:hover { transform: scale(1.06); }
.play:focus-visible { outline: .16em solid var(--cream); outline-offset: .18em; }
.play svg { width: 1.15em; height: 1.15em; display: block; }
.play .icon-pause { display: none; }

.note.is-playing .play .icon-play  { display: none; }
.note.is-playing .play .icon-pause { display: block; }

.note.is-playing .play::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: .12em solid var(--cream);
  opacity: .55;
  animation: pulse 1.8s ease-out infinite;
  pointer-events: none;
}

@keyframes pulse {
  0%   { transform: scale(1);    opacity: .5; }
  100% { transform: scale(1.75); opacity: 0; }
}

/* waveform */
.wave {
  flex: 1;
  min-width: 0;
  height: 2.3em;
  display: flex;
  align-items: center;
  gap: .09em;
  overflow: hidden;
  cursor: pointer;
  touch-action: none;
}

.wave__bar {
  flex: 1 1 0;
  min-width: 0;
  border-radius: 999px;
  background: rgba(255, 247, 216, .34);
  transition: background-color .12s linear;
}
.wave__bar.is-played { background: var(--cream); }

.note__time {
  flex: none;
  font-family: "DM Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: .92em;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  min-width: 3.4em;
  text-align: right;
  letter-spacing: -.01em;
}

.note__meta {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: .3em;
  font-size: .68em;
  color: rgba(255, 247, 216, .80);
  margin-top: .3em;
}
.note__meta svg { width: 1.1em; height: 1.1em; }

/* ---------------------------------------------------------------
   Gated messages — typing indicator and reveal
   --------------------------------------------------------------- */

.bubble--typing {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: .3em;
  padding: .95em 1em;
  border-radius: 1.35em;
  border-bottom-left-radius: .4em;
}

.bubble--typing i {
  width: .42em;
  height: .42em;
  border-radius: 50%;
  background: var(--cream);
  opacity: .45;
  animation: blink 1.25s ease-in-out infinite;
}
.bubble--typing i:nth-child(2) { animation-delay: .18s; }
.bubble--typing i:nth-child(3) { animation-delay: .36s; }

@keyframes blink {
  0%, 60%, 100% { opacity: .35; transform: translateY(0); }
  30%           { opacity: 1;   transform: translateY(-.22em); }
}

.msg--typing,
.msg.is-revealing,
.day.is-revealing { animation: drop-in .42s cubic-bezier(.2, .9, .3, 1.2) both; }

@keyframes drop-in {
  from { opacity: 0; transform: translateY(.7em) scale(.96); }
  to   { opacity: 1; transform: none; }
}

/* ---------------------------------------------------------------
   Emoji reactions — chips pinned to the bottom-left of a bubble
   --------------------------------------------------------------- */

.reactions {
  position: absolute;
  left: .9em;
  bottom: -.9em;
  display: flex;
  gap: .28em;
  pointer-events: none;
}

.reaction {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 1.85em;
  height: 1.85em;
  border-radius: 999px;
  background: var(--cream);
  box-shadow: 0 .14em .4em rgba(52, 44, 40, .3);
  font-size: .92em;
  line-height: 1;
  /* nudges the glyph off the emoji baseline into the optical centre */
  padding-bottom: .06em;
}

.reaction.is-revealing { animation: pop .4s cubic-bezier(.2, .9, .3, 1.6) both; }

@keyframes pop {
  from { opacity: 0; transform: scale(.3) translateY(.35em); }
  to   { opacity: 1; transform: none; }
}

/* make room so the chips do not collide with the next message */
.msg.has-reactions { margin-bottom: 1.05em; }

/* ---------------------------------------------------------------
   New-message button
   --------------------------------------------------------------- */

.compose {
  flex: none;
  padding: .5em calc(.8em + var(--bleed-x)) calc(.3em + var(--bleed-y));
  background: none;
}

.new-message {
  display: flex;
  align-items: center;
  gap: .6em;
  padding: .45em .45em .45em 1.25em;
  border-radius: 999px;
  background: var(--accent);
  border: .13em solid var(--accent-deep);
  text-decoration: none;
  color: var(--cream);
  box-shadow: 0 .35em .8em rgba(120, 10, 6, .3);
  transition: transform .18s ease, box-shadow .18s ease, background-color .18s ease;
}

.new-message:hover {
  transform: translateY(-2px);
  background: #FF3A33;
  box-shadow: 0 .6em 1.2em rgba(120, 10, 6, .4);
}
.new-message:active { transform: translateY(0); }
.new-message:focus-visible { outline: .16em solid var(--accent-deep); outline-offset: .2em; }

.new-message__label {
  flex: 1;
  min-width: 0;
  font-size: .95em;
  font-weight: 700;
  letter-spacing: .01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.new-message__send {
  flex: none;
  width: 2.2em;
  height: 2.2em;
  border-radius: 50%;
  background: var(--cream);
  color: var(--accent);
  display: grid;
  place-items: center;
  box-shadow: 0 .12em .3em rgba(90, 8, 5,.28);
}
.new-message__send svg { width: 1.1em; height: 1.1em; display: block; margin-left: .05em; }

.home-bar {
  width: 32%;
  height: .28em;
  margin: .7em auto .25em;
  border-radius: 999px;
  background: rgba(120, 10, 6, .3);
}

@media (prefers-reduced-motion: reduce) {
  *, *::after { animation: none !important; transition: none !important; }
}
