/* The comment thread with branches that open: the comments on one frame of a design file, in a dark card on a near
   black page with a soft light and a fine grain. The replies hang from their parent on thin branches drawn by an SVG
   laid over the thread (.ct__branches): the script redraws them from where the avatars are. A reply list (.kids) is
   only clipped by its height; GSAP opens it and moves the rows inside, the CSS styles their children. */
:root {
  --page: #08080a;            /* the page */
  --card: #121316;            /* the body of the card */
  --card-low: #0e0f11;        /* the bottom of the card */
  --edge: rgba(255, 255, 255, 0.07); /* the card's edge */
  --ink: #ececf1;             /* the words */
  --muted: #8b8d98;           /* the small words */
  --soft: #5d606b;            /* the faintest words */
  --branch: #2c2e35;          /* the branches at rest */
  --accent: #8fa3ff;          /* the light on the branches, the votes */
  --peach: #ffb48a;           /* the first avatar */
  --blue: #9fb1ff;            /* the second avatar */
  --mint: #95ecc9;            /* the third avatar */
}

* {
  box-sizing: border-box;
}

html {
  touch-action: manipulation;
}

html,
body {
  margin: 0;
  overflow-x: clip;
}

body {
  min-height: 100svh;
  background: var(--page);
  color: var(--ink);
  font-family: 'Mona Sans Variable', system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.sr {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* the page: two faint lights and a grain, never flat */
.stage {
  position: relative;
  min-height: 100svh;
  display: grid;
  place-items: center;
  padding: 16px;
  overflow: hidden;
  background:
    radial-gradient(60% 45% at 30% 18%, color-mix(in srgb, var(--accent) 9%, transparent), transparent 70%),
    radial-gradient(50% 40% at 78% 88%, color-mix(in srgb, var(--peach) 6%, transparent), transparent 70%),
    var(--page);
}

.stage::before {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0.07;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

.ct {
  position: relative;
  width: min(92vw, 380px);
  opacity: 0;
}

/* the coloured glow the card throws on the page */
.ct__glow {
  position: absolute;
  left: 12%;
  right: 12%;
  bottom: -14px;
  height: 40%;
  border-radius: 50%;
  background: radial-gradient(closest-side, color-mix(in srgb, var(--accent) 22%, transparent), transparent);
  filter: blur(18px);
  pointer-events: none;
}

.ct__card {
  position: relative;
  border-radius: 20px;
  padding: clamp(10px, 3vh, 18px) clamp(14px, 4.4vw, 18px) clamp(8px, 2.6vh, 18px);
  background: linear-gradient(180deg, var(--card), var(--card-low));
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.06),
    0 0 0 1px var(--edge),
    0 2px 4px rgba(0, 0, 0, 0.35),
    0 14px 28px -12px rgba(0, 0, 0, 0.6),
    0 40px 80px -30px rgba(0, 0, 0, 0.85);
  overflow: hidden;
}

/* a soft light inside the card that follows the pointer */
.ct__shine {
  --mx: 30%;
  --my: 0%;
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(240px circle at var(--mx) var(--my), rgba(255, 255, 255, 0.045), transparent 70%);
}

/* the top edge catching the light where the pointer is */
.ct__card::before {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  height: 1px;
  background: radial-gradient(160px 1px at var(--ex, 30%) 0, rgba(255, 255, 255, 0.4), transparent);
  pointer-events: none;
}

.ct__head {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: clamp(8px, 2.2vh, 13px);
  margin-bottom: clamp(2px, 1vh, 8px);
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  font-size: 12.5px;
}

.ct__file {
  display: flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
  white-space: nowrap;
}

.ct__frame {
  width: 14px;
  height: 14px;
  flex: none;
  fill: none;
  stroke: var(--muted);
  stroke-width: 1.3;
  stroke-linecap: round;
}

.ct__name {
  font-weight: 600;
  font-variation-settings: 'wdth' 104;
}

.ct__sep {
  color: var(--soft);
}

.ct__muted {
  color: var(--muted);
}

.ct__state {
  flex: none;
  font-size: 11px;
  font-weight: 500;
  color: var(--muted);
  padding: 3px 9px;
  border-radius: 999px;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.09);
  background: rgba(255, 255, 255, 0.025);
}

.ct__thread {
  position: relative;
}

.ct__branches {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
  pointer-events: none;
}

.branch {
  fill: none;
  stroke: var(--branch);
  stroke-width: 1.2;
  stroke-linecap: round;
  transition: stroke 0.35s ease;
}

.branch.is-lit {
  stroke: color-mix(in srgb, var(--accent) 55%, var(--branch));
}

.pulse,
.pulse-glow {
  fill: none;
  stroke: var(--accent);
  stroke-linecap: round;
}

.pulse {
  stroke-width: 1.4;
  stroke: color-mix(in srgb, var(--accent) 50%, #ffffff);
}

.pulse-glow {
  stroke-width: 4;
  opacity: 0.8;
}

/* one comment: the avatar, then the name, the time and the vote, the words, the replies */
.c {
  position: relative;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 10px;
  padding: clamp(4px, 1.4vh, 9px) 0;
  font-size: clamp(11.5px, 3vh, 13.5px);
}

.c__av {
  --size: 22px;
  position: relative;
  display: grid;
  place-items: center;
  width: var(--size);
  height: var(--size);
  border-radius: 50%;
  font-size: calc(var(--size) * 0.38);
  font-weight: 650;
  font-variation-settings: 'wdth' 110;
  letter-spacing: 0.02em;
  color: rgba(10, 10, 14, 0.82);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.5), inset 0 -2px 4px rgba(0, 0, 0, 0.18), 0 0 0 2px var(--card), 0 4px 10px -4px rgba(0, 0, 0, 0.7);
  z-index: 1;
}

.c--root > .c__av {
  --size: 26px;
}

/* a thin ring that lights when the avatar's thread is open */
.c__av::after {
  content: '';
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  box-shadow: 0 0 0 1px var(--accent);
  opacity: var(--ring, 0);
  transform: scale(calc(0.86 + var(--ring, 0) * 0.14));
}

.c__av--peach {
  background: radial-gradient(120% 120% at 30% 20%, #ffd9bf, var(--peach) 45%, #e9806c);
}

.c__av--blue {
  background: radial-gradient(120% 120% at 30% 20%, #dbe2ff, var(--blue) 45%, #6274ec);
}

.c__av--mint {
  background: radial-gradient(120% 120% at 30% 20%, #dcfff0, var(--mint) 45%, #44b893);
}

.c__av--mini {
  --size: 16px;
  font-size: 0;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.45), 0 0 0 1.5px var(--card);
}

.c__body {
  min-width: 0;
}

.c__meta {
  display: flex;
  align-items: center;
  gap: 7px;
  margin: 0;
  min-height: 22px;
  line-height: 1.2;
}

.c__who {
  font-weight: 600;
  font-variation-settings: 'wdth' 102;
  white-space: nowrap;
}

.c__time {
  color: var(--soft);
  font-size: 0.88em;
}

.c__text {
  margin: 2px 0 0;
  line-height: 1.42;
  color: color-mix(in srgb, var(--ink) 82%, var(--muted));
}

/* the vote: a chevron and a number that rolls */
.vote {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 3px;
  margin-left: auto;
  height: 22px;
  padding: 0 7px 0 4px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 11.5px;
  font-weight: 560;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: color 0.3s ease, background-color 0.3s ease, box-shadow 0.3s ease;
}

.vote[aria-pressed='true'] {
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--accent) 26%, transparent);
}

.vote__icon {
  width: 14px;
  height: 14px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
  overflow: visible;
}

.vote__n {
  position: relative;
  display: inline-block;
  height: 1.2em;
  line-height: 1.2em;
  overflow: hidden;
  vertical-align: top;
}

.vote__n > span {
  display: block;
}

.vote__n > span + span {
  position: absolute;
  left: 0;
  top: 0;
}

/* the ring that leaves the chevron when a vote is given */
.vote__ring {
  position: absolute;
  left: 4px;
  top: 50%;
  width: 14px;
  height: 14px;
  margin-top: -7px;
  border-radius: 50%;
  box-shadow: 0 0 0 1px var(--accent);
  pointer-events: none;
}

/* the replies chip: the faces of who answered, the count, a chevron */
.more {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: clamp(24px, 6vh, 26px);
  margin-top: clamp(4px, 1.4vh, 7px);
  padding: 0 9px 0 5px;
  border: 0;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.04);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.07), inset 0 1px 0 rgba(255, 255, 255, 0.04);
  color: var(--ink);
  font: inherit;
  font-size: 11.5px;
  font-weight: 560;
  cursor: pointer;
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
  transition: background-color 0.3s ease, box-shadow 0.3s ease;
}

.more[aria-expanded='true'] {
  background: color-mix(in srgb, var(--accent) 9%, transparent);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--accent) 22%, transparent);
}

.more__faces {
  display: inline-flex;
}

.more__faces .c__av + .c__av {
  margin-left: -5px;
}

.more__label {
  position: relative;
  display: inline-block;
  height: 1.2em;
  line-height: 1.2em;
  overflow: hidden;
}

.more__label > span {
  display: block;
}

.more__label > span + span {
  position: absolute;
  left: 0;
  top: 0;
}

.more__chev {
  width: 13px;
  height: 13px;
  margin-left: -2px;
  fill: none;
  stroke: var(--muted);
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.vote:focus-visible,
.more:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

@media (hover: hover) {
  .vote:hover {
    color: var(--ink);
    background: rgba(255, 255, 255, 0.05);
  }

  .vote[aria-pressed='true']:hover {
    color: var(--accent);
    background: color-mix(in srgb, var(--accent) 16%, transparent);
  }

  .more:hover {
    background: rgba(255, 255, 255, 0.07);
  }
}

/* a reply list is clipped by its height; GSAP opens it */
.kids {
  height: 0;
  overflow: hidden;
  padding-left: 36px;
}

.kids--deep {
  padding-left: 32px;
}

/* room for the vote's ring and the avatar's ring inside the clip */
.kids__in {
  padding: 0 6px;
  margin: 0 -6px;
}

.kids__in > .c {
  opacity: 0;
}
