/* Dynamic Monkey Video Player — mobile-only portrait shell. */

:root {
  --bg: #08090c;
  --ink: #ffffff;
  --muted: rgba(255, 255, 255, 0.62);
  --chip-bg: rgba(10, 12, 16, 0.55);
  --accent: #ffd23f;
  --stage-max-w: 460px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 400 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
        "Helvetica Neue", Arial, "Apple Color Emoji", "Segoe UI Emoji", sans-serif;
  overscroll-behavior: none;
}

body {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

.shell {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  width: 100%;
  height: 100%;
  justify-content: center;
}

.shell__note {
  display: none;
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

/* ---------------------------------------------------------------- stage -- */

.stage {
  position: relative;
  width: 100%;
  height: 100%;
  max-width: var(--stage-max-w);
  overflow: hidden;
  background: #000;
  isolation: isolate;
  touch-action: manipulation;
}

.stage__video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #000;
}

/* Legibility bed for the comment stack and controls. */
.stage__scrim {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(to bottom, rgba(0, 0, 0, 0.55) 0%, rgba(0, 0, 0, 0) 22%),
    linear-gradient(to top, rgba(0, 0, 0, 0.72) 0%, rgba(0, 0, 0, 0.28) 26%,
                    rgba(0, 0, 0, 0) 52%);
}

/* Fade to black across the last second (43s -> 44s), then lifted to reveal
   the first frame as the end card. */
.stage__fade {
  position: absolute;
  inset: 0;
  z-index: 2;
  background: #000;
  opacity: 0;
  pointer-events: none;
}

/* ------------------------------------------------------------------ hud -- */

.hud {
  position: absolute;
  top: calc(10px + var(--safe-t));
  left: 12px;
  right: 12px;
  z-index: 4;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

.hud__row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.hud__chip {
  padding: 4px 9px;
  border-radius: 999px;
  background: var(--chip-bg);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.01em;
  white-space: nowrap;
  max-width: 46%;
  overflow: hidden;
  text-overflow: ellipsis;
}

.hud__count {
  margin: 6px 0 0;
  font-size: 10px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

/* ------------------------------------------------------------- comments -- */

.comments {
  position: absolute;
  left: 8px;
  bottom: calc(72px + var(--safe-b));
  z-index: 3;
  width: min(75%, 310px);
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  pointer-events: none;
}

/* Wrapper owns the height animation so older rows glide upward. */
.comment {
  overflow: hidden;
  will-change: height, opacity;
}

.comment__inner {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding-top: 8px;
  will-change: transform, opacity;
}

.comment__avatar {
  flex: 0 0 auto;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  object-fit: cover;
  background: #23262d;
  box-shadow: 0 0 0 1.5px rgba(255, 255, 255, 0.65),
              0 2px 8px rgba(0, 0, 0, 0.5);
}

.comment__body {
  min-width: 0;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.85), 0 0 12px rgba(0, 0, 0, 0.45);
}

.comment__name {
  display: block;
  font-size: 11.5px;
  font-weight: 800;
  letter-spacing: 0.01em;
  color: #f0f0f0;
}

.comment__text {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: #e8e8e8;
  overflow-wrap: anywhere;
}

.comment__emoji {
  margin-left: 3px;
  font-size: 14px;
}

/* -------------------------------------------------------------- bigplay -- */

/* Centred with margin:auto, never with translate(-50%). Every show, hide and
   tap animates this button's transform; WebKit can drop a percentage translate
   while interpolating between transform lists of different lengths, and the
   button would slide down-right mid-animation. With the centring out of the
   transform, the only thing ever animated is scale(). */
.bigplay {
  position: absolute;
  z-index: 5;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  margin: auto;
  transform: scale(1);
  width: 78px;
  height: 78px;
  border: 0;
  border-radius: 50%;
  background: rgba(12, 14, 18, 0.5);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.18), 0 10px 30px rgba(0, 0, 0, 0.45);
  color: #fff;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: opacity 0.22s ease, transform 0.22s ease;
}

/* The play triangle needs an optical nudge right; the repeat glyph does not. */
.bigplay svg { width: 34px; height: 34px; fill: currentColor; }
.bigplay .icon-bigplay { margin-left: 3px; }

.bigplay:active {
  transform: scale(0.92);
}

/* While playing the centre button is a pause control that fades out with the
   rest of the chrome; a tap on the picture brings it back. It stays put while
   the video is buffering, so the spinner is never hidden mid-stall. */
.stage.is-idle:not(.is-buffering) .bigplay {
  opacity: 0;
  transform: scale(0.82);
  pointer-events: none;
}

/* Spinner ring: shown while a mix is loading or the video is buffering, in
   place of whichever icon would otherwise be there. Replaces an opacity pulse
   on the play icon, which read as a glitch rather than as "working". */
.bigplay::after {
  content: '';
  position: absolute;
  inset: 14px;
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.22);
  border-top-color: #fff;
  opacity: 0;
  pointer-events: none;
}

.stage.is-loading .bigplay svg,
.stage.is-buffering .bigplay svg { display: none; }

.stage.is-loading .bigplay::after,
.stage.is-buffering .bigplay::after {
  opacity: 1;
  animation: bigplay-spin 0.9s linear infinite;
}

@keyframes bigplay-spin {
  to { transform: rotate(360deg); }
}

/* ------------------------------------------------------------- controls -- */

.controls {
  position: absolute;
  z-index: 6;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 0 12px calc(12px + var(--safe-b));
  transition: opacity 0.25s ease, transform 0.25s ease;
}

.stage.is-idle .controls {
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
}

.stage.is-idle .hud { opacity: 0; }

.scrub {
  position: relative;
  height: 26px;
  display: flex;
  align-items: center;
}

.scrub__track {
  position: absolute;
  left: 0;
  right: 0;
  height: 3px;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.25);
  pointer-events: none;
  transition: height 0.15s ease;
}

/* The bar thickens and the knob grows under a finger, so a drag reads as a
   drag; the bar also refuses to auto-hide for as long as one is in progress. */
.stage.is-scrubbing .scrub__track { height: 5px; }
.stage.is-scrubbing .scrub__knob { width: 18px; height: 18px; margin-left: -9px; }
.stage.is-scrubbing .controls { opacity: 1; transform: none; pointer-events: auto; }

.scrub__buffer,
.scrub__fill {
  position: absolute;
  inset: 0 auto 0 0;
  border-radius: 3px;
  width: 0;
}

.scrub__buffer { background: rgba(255, 255, 255, 0.3); }
.scrub__fill { background: var(--accent); }

.scrub__knob {
  position: absolute;
  top: 50%;
  left: 0;
  width: 14px;
  height: 14px;
  margin-left: -7px;
  border-radius: 50%;
  background: var(--accent);
  transform: translateY(-50%);
  box-shadow: 0 1px 6px rgba(0, 0, 0, 0.6);
  transition: width 0.15s ease, height 0.15s ease, margin-left 0.15s ease;
}

.scrub__input {
  position: relative;
  z-index: 2;
  width: 100%;
  height: 26px;
  margin: 0;
  opacity: 0;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
  background: transparent;
}

.scrub__input::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 26px;
  height: 26px;
}

.controls__row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-top: 2px;
}

.controls__time {
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  margin-right: auto;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 0;
  color: #fff;
  background: rgba(255, 255, 255, 0.13);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  cursor: pointer;
  font: inherit;
  transition: background 0.18s ease, transform 0.12s ease;
}

.btn:active { transform: scale(0.94); }

.btn--icon {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  justify-content: center;
  padding: 0;
}

.btn--label {
  height: 34px;
  padding: 0 12px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
}

.btn svg { width: 16px; height: 16px; fill: currentColor; }
/* Stroked icons (the shuffle glyph) must keep their own fill:none. */
.btn svg[stroke] { fill: none; }

.icon-pause, .icon-muted, .icon-bigpause, .icon-bigrepeat { display: none; }
.stage.is-playing .icon-bigplay { display: none; }
.stage.is-playing .icon-bigpause { display: block; }
.stage.is-ended .icon-bigplay { display: none; }
.stage.is-ended .icon-bigrepeat { display: block; }
.stage.is-ended .icon-bigpause { display: none; }
/* The end card is a clean still: no comment may survive onto it. */
.stage.is-ended .comments { visibility: hidden; }

/* ----------------------------------------------------------- action rail -- */

/* TikTok-style column down the right edge. It sits above the control bar and to
   the right of the comment stack, which stops at 75% of the width. */
.rail {
  position: absolute;
  right: 6px;
  bottom: calc(84px + var(--safe-b));
  z-index: 6;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
}

.rail__btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
  gap: 1px;
  min-width: 48px;
  padding: 3px 0 2px;
  border: 0;
  background: none;
  color: #fff;
  font: inherit;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.12s ease;
}

.rail__btn:active { transform: scale(0.9); }
.rail__btn[hidden] { display: none; }
.rail__btn--static { cursor: default; }
.rail__btn--static:active { transform: none; }

.rail__btn svg {
  width: 30px;
  height: 30px;
  fill: currentColor;
  filter: drop-shadow(0 1px 3px rgba(0, 0, 0, 0.7));
  transition: color 0.15s ease, transform 0.2s cubic-bezier(.2, 1.4, .4, 1);
}
.rail__btn svg[stroke] { fill: none; }

.rail__label {
  min-height: 14px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.01em;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.85), 0 0 8px rgba(0, 0, 0, 0.5);
  font-variant-numeric: tabular-nums;
}

/* The heart: a clean white outline until liked, then a rose gradient fills in from the
   centre with a soft glow, a quick pop, and a small burst. */
.heart path { fill: none; }
.heart__line { stroke: #fff; stroke-width: 1.9; stroke-linejoin: round; transition: stroke 0.2s ease; }
.heart__fill {
  fill: url(#heartGrad) !important;
  opacity: 0;
  transform: scale(0.5);
  transform-origin: 12px 12.5px;
  transition: opacity 0.18s ease, transform 0.32s cubic-bezier(.2, 1.5, .4, 1);
}
#likeBtn.is-on .heart__fill { opacity: 1; transform: scale(1); }
#likeBtn.is-on .heart__line { stroke: rgba(255, 255, 255, 0.35); stroke-width: 0.8; }
#likeBtn.is-on svg {
  filter: drop-shadow(0 0 7px rgba(255, 45, 85, 0.55)) drop-shadow(0 1px 3px rgba(0, 0, 0, 0.55));
}
#likeBtn.is-popping svg { animation: like-pop 0.4s cubic-bezier(.2, 1.4, .4, 1); }
@keyframes like-pop { 0% { transform: scale(1); } 40% { transform: scale(1.32); } 100% { transform: scale(1); } }

.burst { position: absolute; left: 50%; top: 18px; width: 0; height: 0; pointer-events: none; }
.burst i {
  position: absolute; left: -2.5px; top: -2.5px; width: 5px; height: 5px; border-radius: 50%;
  background: linear-gradient(135deg, #ffb3c2, #ff3d68);
  opacity: 0;
  animation: burst 0.55s ease-out forwards;
}
@keyframes burst {
  0%   { opacity: 1; transform: rotate(var(--a)) translateY(-12px) scale(1); }
  100% { opacity: 0; transform: rotate(var(--a)) translateY(-30px) scale(0.2); }
}

.toast {
  position: absolute;
  left: 50%;
  bottom: calc(96px + var(--safe-b));
  z-index: 8;
  max-width: 84%;
  padding: 9px 14px;
  border-radius: 12px;
  background: rgba(12, 14, 18, 0.88);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.14);
  font-size: 13px;
  font-weight: 600;
  line-height: 1.35;
  text-align: center;
  opacity: 0;
  transform: translate(-50%, 8px);
  transition: opacity 0.2s ease, transform 0.2s ease;
  pointer-events: none;
}
.toast.is-on { opacity: 1; transform: translate(-50%, 0); }

/* End card: first frame held, repeat icon centred, comments cleared. */
.stage.is-ended .bigplay {
  opacity: 1;
  transform: scale(1);
  pointer-events: auto;
}

.stage.is-ended .hud { opacity: 0; }
.stage.is-playing .icon-play { display: none; }
.stage.is-playing .icon-pause { display: block; }
.stage.is-muted .icon-sound { display: none; }
.stage.is-muted .icon-muted { display: block; }

/* --------------------------------------------------------- orientation -- */

.rotate-gate {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: none;
  place-items: center;
  background: var(--bg);
  text-align: center;
}

.rotate-gate__icon { font-size: 40px; }
.rotate-gate p { margin: 10px 0 0; font-weight: 700; }

/* Phones held sideways: the player is portrait-only by design. */
@media (max-width: 900px) and (orientation: landscape) {
  .rotate-gate { display: grid; }
}

/* Anything wider than a phone gets the same portrait stage, letterboxed. */
@media (min-width: 620px) {
  body { padding: 20px 0; }
  .shell { justify-content: center; }
  .shell__note { display: block; }
  .stage {
    height: min(calc(100vh - 80px), calc(var(--stage-max-w) * 16 / 9));
    aspect-ratio: 9 / 16;
    width: auto;
    border-radius: 22px;
    box-shadow: 0 24px 70px rgba(0, 0, 0, 0.6), 0 0 0 1px rgba(255, 255, 255, 0.08);
  }
}

@media (prefers-reduced-motion: reduce) {
  .comment, .comment__inner { transition: none !important; }
  .bigplay::after { animation: none !important; }
  #likeBtn.is-popping svg, .burst i { animation: none; }
  .burst { display: none; }
  .toast, .rail__btn svg, .heart__fill, .heart__line { transition: none; }
}
