:root {
  --bg: #000;
  --panel: #161616;
  --text: #f5f5f7;
  --muted: #8a8f98;
  --accent: #fe2c55;
  --cyan: #25f4ee;
  --green: #27e07f;
  --h: 100vh;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

body {
  overflow: hidden;
}

.hidden {
  display: none !important;
}

#app {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

/* ---------- Feed ---------- */
#feed {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  scroll-snap-type: y mandatory;
  scrollbar-width: none;
  user-select: none;
  -webkit-user-select: none;
}

#feed::-webkit-scrollbar {
  display: none;
}

/* Game over */
#feed.locked {
  overflow: hidden;
}

.slot {
  position: relative;
  height: var(--h);
  scroll-snap-align: start;
  /* Gap lives inside each slot so cards scroll all the way to the top edge */
  padding: calc(env(safe-area-inset-top, 0px) + 6px) 6px 8px;
  display: flex;
  justify-content: center;
  gap: 16px;
}

.card {
  position: relative;
  flex: 1;
  min-width: 0;
  border-radius: 18px;
  overflow: hidden;
  container-type: inline-size;
}

.is-content .card::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(180deg, rgba(0, 0, 0, 0) 55%, rgba(0, 0, 0, 0.5) 100%);
}

/* ---------- Caption ---------- */
.caption {
  position: absolute;
  left: 14px;
  right: 72px;
  bottom: 18px;
  z-index: 2;
  font-size: 14px;
  line-height: 1.4;
  text-shadow: 0 1px 8px rgba(0, 0, 0, 0.4);
}

.handle {
  font-size: 15px;
  font-weight: 800;
}

.caption p {
  margin: 4px 0 0;
  font-weight: 500;
  color: rgba(255, 255, 255, 0.92);
}

.caption p b {
  font-weight: 700;
  color: #fff;
}

.sound {
  margin-top: 8px;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sound svg {
  flex: none;
  width: 14px;
  height: 14px;
}

/* ---------- Rail ---------- */
.rail {
  position: absolute;
  right: 14px;
  bottom: 26px;
  z-index: 3;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.rail-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  font-size: 12px;
  font-weight: 700;
  text-shadow: 0 1px 6px rgba(0, 0, 0, 0.4);
}

.rail-btn .ic {
  display: flex;
  align-items: center;
  justify-content: center;
}

.rail-btn svg {
  width: 32px;
  height: 32px;
  filter: drop-shadow(0 1px 4px rgba(0, 0, 0, 0.3));
}

.avatar {
  position: relative;
  width: 46px;
  height: 46px;
  margin-bottom: 6px;
  border-radius: 50%;
  border: 1.5px solid #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  font-weight: 800;
  color: #fff;
}

.avatar svg {
  width: 24px;
  height: 24px;
}

.avatar::after {
  content: "+";
  position: absolute;
  bottom: -9px;
  left: 50%;
  transform: translateX(-50%);
  width: 19px;
  height: 19px;
  border-radius: 50%;
  background: var(--accent);
  font-size: 15px;
  font-weight: 700;
  line-height: 18px;
  text-align: center;
}

/* ---------- Intro card (TikTok text post) ---------- */
.is-intro .card {
  background: var(--accent);
}

.tt-lines {
  position: absolute;
  inset: 0 64px 120px 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  text-align: center;
}

.tt-lines > div {
  line-height: 1.5;
  text-wrap: balance;
}

.tt-text {
  display: inline;
  background: #fff;
  color: #111;
  font-size: clamp(20px, 7.6cqi, 36px);
  font-weight: 800;
  letter-spacing: -0.02em;
  padding: 0.1em 0.38em;
  border-radius: 0.28em;
  -webkit-box-decoration-break: clone;
  box-decoration-break: clone;
}

/* ---------- Ad reel ---------- */
.pitch-media {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.pitch-hero {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  text-align: center;
  padding: 0 24px 120px;
}

.pitch-hero-icon {
  width: 104px;
  height: 104px;
  border-radius: 30px;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.12);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
}

.pitch-hero-icon svg {
  width: 50px;
  height: 50px;
}

.pitch-hero-brand {
  font-size: 30px;
  font-weight: 900;
  letter-spacing: -1px;
  color: #fff;
}

.pitch-footer {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 40px 14px 16px;
  background: linear-gradient(180deg, rgba(0, 0, 0, 0) 0%, rgba(0, 0, 0, 0.72) 45%);
}

.pitch-brand-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.pitch-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.14);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
}

.pitch-avatar svg {
  width: 18px;
  height: 18px;
}

.pitch-name {
  font-size: 15px;
  font-weight: 800;
}

.pitch-name small {
  display: block;
  font-size: 11px;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.6);
}

.pitch-title {
  margin: 0 0 14px;
  font-size: 20px;
  font-weight: 800;
  line-height: 1.2;
  letter-spacing: -0.4px;
}

.pitch-cta {
  width: 100%;
  padding: 14px;
  border: none;
  border-radius: 10px;
  background: #fff;
  color: #111;
  font-family: inherit;
  font-size: 15px;
  font-weight: 800;
  cursor: default;
}

.pitch-x {
  position: absolute;
  top: 14px;
  width: 50px;
  height: 50px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.9);
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 5;
  transition: transform 0.1s ease, background 0.1s ease;
}

.pitch-x svg {
  width: 24px;
  height: 24px;
}

.pitch-x:active {
  transform: scale(0.9);
  background: rgba(0, 0, 0, 0.7);
}

.is-pitch.active .pitch-x {
  animation: xpulse 1.1s ease-in-out infinite;
}

.tl { left: 14px; }
.tr { right: 14px; }

.pitch-plus {
  position: absolute;
  top: 18px;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 8px 14px;
  border-radius: 999px;
  background: var(--green);
  color: #04210f;
  font-size: 16px;
  font-weight: 900;
  z-index: 6;
}

.is-pitch.closed .pitch-x { display: none; }

.is-pitch.closed .pitch-plus {
  display: flex;
  animation: pop 0.7s ease;
}

.pitch-hint {
  position: absolute;
  top: 84px;
  left: 50%;
  transform: translateX(-50%);
  padding: 9px 15px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  font-size: 14px;
  font-weight: 700;
  color: #fff;
  white-space: nowrap;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.is-pitch.active:not(.closed) .pitch-hint {
  opacity: 1;
}

.is-pitch.blocked:not(.closed) .pitch-hint {
  animation: shake 0.45s ease;
}

.is-pitch.blocked:not(.closed) .pitch-x {
  animation: bump 0.45s ease, xpulse 1.1s ease-in-out 0.45s infinite;
}

/* On phones the rail would sit on the ad's CTA; it only shows beside the card on desktop */
.is-pitch .rail {
  display: none;
}

/* ---------- Dock (bottom bar) ---------- */
#dock {
  flex: none;
  position: relative;
  width: 100%;
  max-width: 440px;
  margin: 0 auto;
  height: calc(76px + env(safe-area-inset-bottom, 0px));
  padding: 0 16px env(safe-area-inset-bottom, 0px);
}

.dock-row {
  height: 76px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 4px;
}

.play-row,
#app.playing .ready-row {
  display: none;
}

#app.playing .play-row {
  display: flex;
}

.stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  min-width: 80px;
}

.stat b {
  font-size: 20px;
  font-weight: 800;
  letter-spacing: -0.3px;
  font-variant-numeric: tabular-nums;
  line-height: 1.15;
}

.stat span {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
}

.stat.timer b {
  font-size: 30px;
  letter-spacing: -1px;
  transition: color 0.2s ease;
}

/* The TikTok "+" button, stretched into Play */
.tt-plus {
  height: 44px;
  padding: 0 26px;
  border: none;
  border-radius: 12px;
  background: #fff;
  color: #000;
  font-family: inherit;
  font-size: 16px;
  font-weight: 800;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  box-shadow: -4px 0 0 var(--cyan), 4px 0 0 var(--accent);
  cursor: pointer;
  transition: transform 0.12s ease;
}

.tt-plus svg {
  width: 16px;
  height: 16px;
}

.tt-plus:hover { transform: translateY(-1px); }
.tt-plus:active { transform: scale(0.97); }

/* TikTok-style scrub line along the bottom of the card doubles as the clock */
.scrub {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 3px;
  z-index: 4;
  background: rgba(255, 255, 255, 0.22);
  visibility: hidden;
}

#app.playing .scrub {
  visibility: visible;
}

.scrub i {
  display: block;
  height: 100%;
  width: 100%;
  background: #fff;
  transition: width 0.12s linear, background 0.2s ease;
}

#app.critical::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 45;
  box-shadow: inset 0 0 140px 40px rgba(255, 0, 0, 0.35);
}

/* ---------- +1s fly ---------- */
.fly-plus {
  position: fixed;
  z-index: 70;
  font-size: 22px;
  font-weight: 900;
  color: var(--green);
  pointer-events: none;
  transform: translateX(-50%);
  text-shadow: 0 2px 12px rgba(39, 224, 127, 0.6);
  animation: fly 1s ease-out forwards;
}

/* ---------- Game over ---------- */
.overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
  z-index: 50;
  background: rgba(0, 0, 0, 0.72);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.go-box {
  position: relative;
  max-width: 340px;
  width: 100%;
  text-align: center;
  background: var(--panel);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 24px;
  padding: 34px 26px 26px;
  box-shadow: 0 40px 80px -20px rgba(0, 0, 0, 0.8);
  animation: rise 0.35s ease;
}

.go-badge {
  position: absolute;
  top: -13px;
  left: 50%;
  transform: translateX(-50%);
  padding: 5px 12px;
  border-radius: 999px;
  background: var(--green);
  color: #04210f;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.3px;
  white-space: nowrap;
}

.go-box h2 {
  margin: 0;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 2.5px;
  text-transform: uppercase;
  color: var(--muted);
}

.go-score {
  margin: 16px 0 22px;
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 8px;
}

.go-score .big {
  font-size: 80px;
  font-weight: 900;
  line-height: 0.9;
  letter-spacing: -3px;
}

.go-score .unit {
  font-size: 18px;
  color: var(--muted);
  font-weight: 600;
}

.go-stats {
  display: flex;
  justify-content: center;
  gap: 40px;
  margin-bottom: 24px;
}

.go-stats div {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.go-stats span {
  font-size: 26px;
  font-weight: 900;
}

.go-stats small {
  font-size: 11px;
  color: var(--muted);
}

.primary {
  width: 100%;
  padding: 15px 24px;
  border: none;
  border-radius: 12px;
  background: var(--accent);
  color: #fff;
  font-family: inherit;
  font-size: 16px;
  font-weight: 800;
  cursor: pointer;
  transition: transform 0.12s ease, filter 0.12s ease;
}

.primary:hover { filter: brightness(1.07); }
.primary:active { transform: scale(0.98); }

/* ---------- anims ---------- */
@keyframes xpulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(254, 44, 85, 0.7); }
  50% { box-shadow: 0 0 0 10px rgba(254, 44, 85, 0); }
}

@keyframes shake {
  0%, 100% { transform: translateX(-50%); }
  20% { transform: translateX(calc(-50% - 8px)); }
  40% { transform: translateX(calc(-50% + 8px)); }
  60% { transform: translateX(calc(-50% - 5px)); }
  80% { transform: translateX(calc(-50% + 5px)); }
}

@keyframes bump {
  0%, 100% { transform: scale(1); }
  40% { transform: scale(1.25); }
}

@keyframes pop {
  0% { transform: scale(0.4); opacity: 0; }
  55% { transform: scale(1.15); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}

@keyframes fly {
  0% { opacity: 0; transform: translate(-50%, 0) scale(0.7); }
  20% { opacity: 1; transform: translate(-50%, -26px) scale(1.25); }
  100% { opacity: 0; transform: translate(-50%, -86px) scale(1); }
}

@keyframes rise {
  from { transform: translateY(16px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

/* ---------- Desktop: 9:16 card with the rail beside it, like TikTok web ---------- */
@media (min-width: 660px) {
  /* Left padding matches the rail + gap on the right, so the card (and the dock under it) sits dead centre */
  .slot {
    padding: 16px 6px 14px 70px;
  }

  .card {
    flex: none;
    height: 100%;
    aspect-ratio: 9 / 16;
    max-width: calc(100vw - 140px);
    border-radius: 20px;
  }

  .caption {
    right: 16px;
  }

  .rail,
  .is-pitch .rail {
    display: flex;
    position: static;
    align-self: flex-end;
    margin-bottom: 6px;
    width: 48px;
  }

  .rail-btn {
    text-shadow: none;
    color: #e6e7ea;
  }

  .rail-btn .ic {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.1);
  }

  .rail-btn svg {
    width: 24px;
    height: 24px;
    filter: none;
  }

  .tt-lines {
    right: 16px;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.001s !important;
    animation-iteration-count: 1 !important;
  }
}
