.word {
  position: relative; /* For positioning the ::after pseudo-element */
  cursor: pointer;
  /* MODIFIED: Changed 'padding' to 'padding-right' to animate it smoothly */
  transition: color 0.2s, background-color 0.2s, padding-right 0.3s ease-out;
  padding: 2px 3px;
  border-radius: 4px;
  margin: 0 1px;
  pointer-events: auto;
  /* --- MOBILE FRIENDLY: Prevent text selection/magnifying glass on long press --- */
  -webkit-user-select: none; /* Safari */
  -moz-user-select: none;    /* Firefox */
  -ms-user-select: none;     /* IE/Edge */
  user-select: none;         /* Standard */
  -webkit-touch-callout: none; /* iOS Safari */
}

.word:hover {
  background-color: var(--accent-color);
  color: var(--bg-color);
  box-shadow: 0 0 10px var(--accent-glow);
}

.word.active {
  background: linear-gradient(90deg, var(--accent-color), #00c4b3);
  color: #000;
  font-weight: 600;
  box-shadow: 0 0 10px var(--accent-glow);
}

.word.pulsing {
  animation: pulse-anim 1.5s infinite;
}

/* MODIFIED: The padding will now animate smoothly and is relative to font size */
.word.with_translation {
  padding-right: 1.8em;
}

.word.with_translation.translation-pinned {
  color: var(--accent-color-lighter);
  font-style: italic;
}

.word.with_translation.translation-pinned:hover {
  color: var(--tertiary-text-color);
}

.word.with_translation.translation-pinned.active, .word.with_translation.translation-pinned.active:hover {
  color:#000;
}

/* --- NEW: Styles for inline translation display --- */
.inline-translation-text {
  position: absolute;
  top: 100%;
  left: 5%; /* Aligns with the left edge of the word */
  /* transform: translateY(8px); MODIFIED: Start slightly below */
  transform: translateY(-40%);
  margin-top: -0.2em; /* Moved closer to the word to fit in the interline space */
  background: transparent;
  border: none;
  padding: 0;
  box-shadow: none;
  width: max-content;
  max-width: 250px;
  font-size: 0.9em;
  font-style: italic;
  white-space: normal;
  z-index: 20;
  pointer-events: none; /* Text is not interactive */
  opacity: 0; /* MODIFIED: Start invisible */
  /* MODIFIED: Add transform animation and a delay */
  transition: opacity 0.3s ease-out 0.1s, transform 0.3s ease-out 0.1s;
  color: var(--accent-color-lighter);
  text-align: left;
}

/* NEW: Final state for the translation text animation */
.word.with_translation .inline-translation-text {
  transform: translateY(-40%);
  opacity: 1;
}

.inline-translation-text.error {
  color: #ff9a9a;
}

.add-to-repetitions-btn {
  /* Positioned inside the .word element's padding area */
  position: absolute;
  top: 50%;
  right: 0.25em;
  /* MODIFIED: Start scaled down and invisible for the animation */
  transform: translateY(-50%) scale(0);
  opacity: 0;
  z-index: 21; /* Above other elements */

  background-color: rgba(255, 255, 255, 0.1);
  border: 1px solid var(--border-color);
  color: var(--primary-text-color);
  border-radius: 50%;
  cursor: pointer;
  font-weight: bold;
  /* MODIFIED: Use a bouncy easing function and a delay */
  transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275) 0.15s;
  width: 1.3em;
  height: 1.3em;
  padding: 0;
  font-size: 1.1em;

  /* Use flexbox to perfectly center the '+' icon */
  display: flex;
  align-items: center;
  justify-content: center;
}

/* NEW: Final state for the button animation */
.word.with_translation .add-to-repetitions-btn {
  opacity: 1;
  transform: translateY(-70%) scale(1);
}

.add-to-repetitions-btn:hover {
  background-color: var(--accent-color);
  color: var(--bg-color);
}

.add-to-repetitions-btn.added {
  background-color: #00c4b3;
  color: var(--added-color);
  border-color: #00c4b3;
  cursor: default;
}

.word.search-match {
  background-color: #ffc107; /* Yellow */
  color: #000;
}

.word.search-match.current-match {
  background-color: #ff9800; /* Orange */
  outline: 2px solid #ff9800;
  box-shadow: 0 0 10px #ff9800;
}

.word.double-tap-flash {
  /* Use an animation to provide feedback without permanently changing state */
  animation: double-tap-flash-anim 0.4s ease-out;
}

@keyframes pulse-anim {
  0% {
    box-shadow: 0 0 0 0 rgba(0, 196, 179, 0.7);
  }
  70% {
    box-shadow: 0 0 0 10px rgba(0, 196, 179, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(0, 196, 179, 0);
  }
}

@keyframes double-tap-flash-anim {
  50% {
    background-color: var(--accent-color);
    color: var(--bg-color);
  }
}