/* ==========================================================================
   Community meme tags — search bar above the gallery, tag panel in the modal.

   The search field has no box: just an animated gradient rule under the text,
   painted with the active skin's own gradient so it changes with the skin.
   Colours ride on --sk-* throughout, with neutral fallbacks.
   ========================================================================== */

:root {
  --mt-accent: var(--sk-accent, #ff3df0);
  --mt-glow: var(--sk-glow, rgba(255, 61, 240, 0.55));
  --mt-glow2: var(--sk-glow2, rgba(0, 229, 255, 0.45));
  --mt-rule: var(--sk-grad, linear-gradient(45deg, #ff3df0, #00e5ff, #ffc61a, #ff3df0));
}

.meme-gallery[hidden],
.mt-suggest[hidden],
.mt-panel[hidden] {
  display: none !important;
}

/* ------------------------------------------------------------- search bar --- */

/* The gallery sits over an animated globe, and the field itself has no box to
   sit in, so the block needs its own dark plate to stay readable. */
.mt-search {
  position: relative;
  /* Above the thumbnails' copy buttons. This element makes a stacking context,
     so the suggestion list's own z-index counts only inside it - the whole
     block has to outrank them out here, or the dropdown opens underneath. */
  z-index: 20;
  margin: 2rem auto 0;
  padding: 1.15rem 1.35rem 1rem;
  max-width: 640px;
  width: 100%;
  border-radius: 18px;
  background: rgba(0, 0, 0, 0.82);
}

/* Anchors the suggestion list to the input rather than to the whole plate. */
.mt-search-field {
  position: relative;
}

.mt-search-row {
  position: relative;
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.3rem 0 0.6rem;
  border: 0;
  background: none;
}

/* The whole design: one moving rule, no box. */
.mt-search-row::after {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 2px;
  border-radius: 2px;
  background-image: var(--mt-rule);
  background-size: 300% 100%;
  animation: mt-slide 9s linear infinite;
  transition: height 0.2s ease, box-shadow 0.2s ease;
}

.mt-search-row:focus-within::after {
  height: 3px;
  box-shadow: 0 0 16px -2px var(--mt-glow);
  animation-duration: 4s;
}

@keyframes mt-slide {
  to {
    background-position: 300% 0;
  }
}

.mt-search-icon {
  display: flex;
  flex: none;
  align-items: center;
  color: var(--mt-accent);
}

.mt-search-icon svg {
  width: 1.1rem;
  height: 1.1rem;
}

.mt-search-input {
  flex: 1;
  min-width: 0;
  padding: 0.5rem 0;
  border: none;
  outline: none;
  background: transparent;
  color: var(--text-primary, #fff);
  font: inherit;
  font-size: 1.05rem;
}

.mt-search-input::placeholder {
  color: var(--text-secondary, #808080);
  opacity: 1;
}

.mt-search-clear {
  flex: none;
  width: 2rem;
  height: 2rem;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--text-secondary, #808080);
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
  transition: color 0.2s ease, background 0.2s ease;
}

.mt-search-clear:hover {
  color: var(--text-primary, #fff);
  background: rgba(127, 127, 127, 0.15);
}

/* ----------------------------------------------------------- suggestions --- */

.mt-suggest {
  position: absolute;
  z-index: 30;
  left: 0;
  right: 0;
  top: calc(100% + 0.5rem);
  overflow: hidden;
  border: 1px solid rgba(127, 127, 127, 0.3);
  border-radius: 0.75rem;
  background: #0a0a0a;
  box-shadow: 0 18px 40px -12px rgba(0, 0, 0, 0.9);
}

.mt-suggest-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  width: 100%;
  padding: 0.6rem 1rem;
  border: none;
  background: transparent;
  color: var(--text-primary, #fff);
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.mt-suggest-item:hover {
  background: rgba(127, 127, 127, 0.12);
  color: var(--mt-accent);
}

.mt-suggest-count {
  flex: none;
  color: var(--text-secondary, #808080);
  font-size: 0.8rem;
  font-variant-numeric: tabular-nums;
}

/* ------------------------------------------------------------- tag cloud --- */

.mt-cloud-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  margin-top: 0.9rem;
  padding: 0.35rem 0.85rem;
  border: 1px solid rgba(127, 127, 127, 0.35);
  border-radius: 999px;
  background: #000;
  color: var(--text-secondary, #808080);
  font: inherit;
  font-size: 0.78rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: pointer;
  transition: color 0.2s ease, border-color 0.2s ease;
}

.mt-cloud-toggle:hover,
.mt-cloud-toggle-open {
  color: var(--mt-accent);
  border-color: var(--mt-accent);
}

.mt-cloud-caret {
  display: flex;
  align-items: center;
  transition: transform 0.2s ease;
}

.mt-cloud-caret svg {
  width: 0.6rem;
  height: 0.6rem;
}

.mt-cloud-toggle-open .mt-cloud-caret {
  transform: rotate(90deg);
}

.mt-cloud-total {
  color: var(--mt-accent);
  font-variant-numeric: tabular-nums;
}

.mt-cloud {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
  max-height: 11rem;
  overflow-y: auto;
  margin-top: 0.75rem;
  padding-right: 0.25rem;
}

.mt-cloud[hidden] {
  display: none;
}

.mt-cloud-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.3rem 0.75rem;
  border: 1px solid rgba(127, 127, 127, 0.35);
  border-radius: 999px;
  background: #000;
  color: #b9b9b9;
  font: inherit;
  font-size: 0.8rem;
  cursor: pointer;
  transition: color 0.2s ease, border-color 0.2s ease, transform 0.2s ease,
    box-shadow 0.2s ease;
}

.mt-cloud-chip:hover {
  color: var(--mt-accent);
  border-color: var(--mt-accent);
  transform: translateY(-1px);
  box-shadow: 0 0 16px -4px var(--mt-glow);
}

.mt-cloud-count {
  color: var(--mt-accent);
  font-size: 0.7rem;
  font-variant-numeric: tabular-nums;
  opacity: 0.85;
}

/* ------------------------------------------------- tag many memes at once --- */

.mt-bulk-start {
  margin-top: 0.9rem;
  margin-left: 0.5rem;
  padding: 0.35rem 0.85rem;
  border: 1px solid rgba(127, 127, 127, 0.35);
  border-radius: 999px;
  background: #000;
  color: var(--text-secondary, #808080);
  font: inherit;
  font-size: 0.78rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: pointer;
  transition: color 0.2s ease, border-color 0.2s ease;
}

.mt-bulk-start:hover {
  color: var(--mt-accent);
  border-color: var(--mt-accent);
}

.mt-bulk-start[hidden] {
  display: none;
}

.mt-bulk {
  margin-top: 0.9rem;
  padding: 0.85rem 0.9rem;
  border: 1px solid var(--mt-accent);
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.6);
}

.mt-bulk[hidden] {
  display: none;
}

.mt-bulk-row {
  display: flex;
  gap: 0.5rem;
}

.mt-bulk-add {
  flex: none;
  padding: 0.5rem 1rem;
  border: 1px solid var(--mt-accent);
  border-radius: 8px;
  background: transparent;
  color: var(--mt-accent);
  font: inherit;
  font-size: 0.85rem;
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease;
}

.mt-bulk-add:hover:not(:disabled) {
  background: var(--mt-accent);
  color: #000;
}

.mt-bulk-add:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* Staged tag words. Empty until the first one is added, so it collapses. */
.mt-bulk-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.mt-bulk-tags:not(:empty) {
  margin-top: 0.6rem;
}

.mt-bulk-tag {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.25rem 0.4rem 0.25rem 0.7rem;
  border: 1px solid var(--mt-accent);
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.5);
  color: #fff;
  font-size: 0.85rem;
}

.mt-bulk-tag-x {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 1.2rem;
  height: 1.2rem;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: rgba(127, 127, 127, 0.25);
  color: #fff;
  font: inherit;
  font-size: 0.95rem;
  line-height: 1;
  cursor: pointer;
}

.mt-bulk-tag-x:hover {
  background: var(--mt-accent);
  color: #000;
}

.mt-bulk-input {
  flex: 1;
  min-width: 0;
  padding: 0.55rem 0.85rem;
  border: 1px solid var(--border-color, #2a2a2a);
  border-radius: 8px;
  outline: none;
  background: #000;
  color: var(--text-primary, #fff);
  font: inherit;
  font-size: 0.95rem;
}

.mt-bulk-input:focus {
  border-color: var(--mt-accent);
  box-shadow: 0 0 18px -6px var(--mt-glow);
}

.mt-bulk-input::placeholder {
  color: var(--text-secondary, #808080);
}

.mt-bulk-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.45rem;
  margin-top: 0.7rem;
}

.mt-bulk-count {
  flex: 1;
  min-width: 8rem;
  color: var(--mt-accent);
  font-size: 0.85rem;
}

.mt-bulk-clear,
.mt-bulk-cancel,
.mt-bulk-apply {
  flex: none;
  padding: 0.45rem 1rem;
  border-radius: 999px;
  font: inherit;
  font-size: 0.85rem;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease, color 0.2s ease,
    border-color 0.2s ease;
}

.mt-bulk-clear,
.mt-bulk-cancel {
  border: 1px solid rgba(127, 127, 127, 0.35);
  background: transparent;
  color: var(--text-secondary, #808080);
}

.mt-bulk-clear:hover,
.mt-bulk-cancel:hover {
  color: var(--text-primary, #fff);
  border-color: var(--text-secondary, #808080);
}

.mt-bulk-apply {
  border: 1px solid var(--mt-accent);
  background: var(--mt-accent);
  color: #000;
  font-weight: 700;
}

.mt-bulk-apply:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 0 22px -4px var(--mt-glow);
}

.mt-bulk-apply:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.mt-bulk-msg {
  min-height: 1.1rem;
  margin-top: 0.55rem;
  color: var(--text-secondary, #808080);
  font-size: 0.82rem;
}

/* --- picking state on the thumbnails ---

   Nothing here fades a meme. The gallery sits on an animated 3D background,
   so any transparency lets the background read straight through the picture
   you are trying to judge. The state is carried by a checkbox and a ring
   instead, and every thumbnail stays fully opaque. */

.meme-gallery.mt-picking .meme-item {
  cursor: copy;
  transition: box-shadow 0.15s ease;
}

/* An empty box on every tile, so it is obvious the whole grid is selectable. */
.meme-gallery.mt-picking .meme-item::after {
  content: '';
  position: absolute;
  top: 0.4rem;
  right: 0.4rem;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 1.6rem;
  height: 1.6rem;
  border: 2px solid rgba(255, 255, 255, 0.9);
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.55);
  color: transparent;
  font-size: 1rem;
  font-weight: 700;
  line-height: 1;
  box-shadow: 0 1px 6px rgba(0, 0, 0, 0.7);
}

.meme-gallery.mt-picking .meme-item:hover::after {
  border-color: var(--mt-accent);
}

.meme-gallery.mt-picking .meme-item.mt-picked {
  /* Inset so the ring never overlaps a neighbour in the grid. */
  outline: 4px solid var(--mt-accent);
  outline-offset: -4px;
  box-shadow: 0 0 0 2px #000, 0 0 26px -4px var(--mt-glow);
}

.meme-gallery.mt-picking .meme-item.mt-picked::after {
  content: '✓';
  border-color: var(--mt-accent);
  background: var(--mt-accent);
  color: #000;
}

/* ---------------------------------------------------------------- status --- */

.mt-status {
  min-height: 1.2rem;
  margin-top: 0.75rem;
  color: var(--text-secondary, #808080);
  font-size: 0.85rem;
  text-align: center;
}

.mt-status-hit {
  color: var(--mt-accent);
}

.mt-status-miss {
  color: var(--text-secondary, #808080);
}

/* --------------------------------------------------------- search results --- */

.mt-results {
  margin-top: 1rem;
}

.mt-hit {
  outline: 2px solid var(--mt-accent);
  outline-offset: 2px;
  box-shadow: 0 0 24px -6px var(--mt-glow);
  animation: mt-pop 0.35s ease both;
}

@keyframes mt-pop {
  from {
    opacity: 0;
    transform: scale(0.94);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

.mt-hit-tags {
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  padding: 1.5rem 0.5rem 0.45rem;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.85), transparent);
  pointer-events: none;
}

.mt-hit-tag {
  padding: 0.1rem 0.4rem;
  border-radius: 0.3rem;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  font-size: 0.68rem;
  line-height: 1.5;
  white-space: nowrap;
}

/* -------------------------------------------------------------- modal panel --- */

/* The modal centres a single image by default; with the panel it becomes a column. */
.meme-modal.mt-open {
  flex-direction: column;
  gap: 1rem;
}

.meme-modal.mt-open .modal-image {
  max-height: 60vh;
  margin: 0;
}

/* The modal blanks every caret inside it — our inputs need theirs back. */
.meme-modal input.mt-add-input {
  caret-color: auto;
}

.mt-panel {
  flex: none;
  width: min(640px, 90vw);
  padding: 1rem 1.15rem 1.15rem;
  border: 1px solid var(--border-color, #2a2a2a);
  border-radius: 0.9rem;
  /* The modal already blurs everything behind it - a second backdrop-filter
     here costs a lot over the animated background and shows nothing. */
  background: #0b0b0b;
  box-shadow: 0 0 30px -10px var(--mt-glow2);
}

.mt-panel-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.75rem;
}

.mt-panel-title {
  color: var(--mt-accent);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.mt-panel-count {
  color: #808080;
  font-size: 0.78rem;
}

.mt-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  min-height: 2rem;
  margin-bottom: 0.85rem;
}

.mt-empty {
  color: #808080;
  font-size: 0.88rem;
}

/* A tag plus its "doesn't fit" button, kept together so they wrap as one. */
.mt-chip-wrap {
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
}

.mt-chip-wrong {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 1.35rem;
  height: 1.35rem;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 50%;
  background: transparent;
  color: #6e6e78;
  font: inherit;
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  transition: color 0.15s ease, background 0.15s ease, border-color 0.15s ease;
}

.mt-chip-wrong:hover:not(:disabled) {
  color: #000;
  background: #ff5c5c;
  border-color: #ff5c5c;
}

.mt-chip-wrong:disabled {
  opacity: 0.3;
  cursor: default;
}

.mt-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.35rem 0.75rem;
  border: 1px solid var(--mt-accent);
  border-radius: 999px;
  background: transparent;
  color: #fff;
  font: inherit;
  font-size: 0.85rem;
  cursor: pointer;
  transition: background 0.2s ease, transform 0.2s ease, box-shadow 0.2s ease;
}

.mt-chip:hover {
  background: var(--mt-accent);
  color: #000;
  transform: translateY(-1px);
  box-shadow: 0 0 18px -4px var(--mt-glow);
}

.mt-chip-count {
  padding: 0 0.35rem;
  border-radius: 999px;
  background: rgba(127, 127, 127, 0.25);
  font-size: 0.7rem;
  font-variant-numeric: tabular-nums;
}

.mt-chip:hover .mt-chip-count {
  background: rgba(0, 0, 0, 0.25);
}

.mt-add {
  display: flex;
  gap: 0.5rem;
}

/* Anchors the suggestion list to the field rather than the whole panel. */
.mt-add-field {
  position: relative;
  flex: 1;
  min-width: 0;
}

.mt-add-suggest {
  position: absolute;
  z-index: 5;
  left: 0;
  right: 0;
  top: calc(100% + 0.35rem);
  max-height: 12rem;
  overflow-y: auto;
  border: 1px solid rgba(127, 127, 127, 0.35);
  border-radius: 0.7rem;
  background: #0c0c12;
  box-shadow: 0 16px 36px -12px rgba(0, 0, 0, 0.9);
}

.mt-add-suggest[hidden] {
  display: none;
}

.mt-add-suggest-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  width: 100%;
  padding: 0.55rem 0.9rem;
  border: none;
  background: transparent;
  color: #fff;
  font: inherit;
  font-size: 0.9rem;
  text-align: left;
  cursor: pointer;
}

.mt-add-suggest-item:hover,
.mt-add-suggest-item.is-picked {
  background: rgba(127, 127, 127, 0.14);
  color: var(--mt-accent);
}

.mt-add-suggest-count {
  flex: none;
  color: #808080;
  font-size: 0.78rem;
  font-variant-numeric: tabular-nums;
}

.mt-add-input {
  flex: 1;
  min-width: 0;
  padding: 0.6rem 0.9rem;
  border: 1px solid var(--border-color, #2a2a2a);
  border-radius: 999px;
  outline: none;
  background: rgba(0, 0, 0, 0.5);
  color: #fff;
  font: inherit;
  font-size: 0.95rem;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.mt-add-input:focus {
  border-color: var(--mt-accent);
  box-shadow: 0 0 18px -6px var(--mt-glow);
}

.mt-add-btn {
  flex: none;
  padding: 0.6rem 1.4rem;
  border: 1px solid var(--mt-accent);
  border-radius: 999px;
  background: var(--mt-accent);
  color: #000;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.mt-add-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 0 22px -4px var(--mt-glow);
}

/* Message on the left, the way out on the right. */
.mt-foot {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-top: 0.6rem;
}

.mt-msg {
  flex: 1;
  min-width: 0;
  min-height: 1.1rem;
  color: #808080;
  font-size: 0.82rem;
}

.mt-done {
  flex: none;
  padding: 0.45rem 1.3rem;
  border: 1px solid var(--mt-accent);
  border-radius: 999px;
  background: transparent;
  color: var(--mt-accent);
  font: inherit;
  font-size: 0.88rem;
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease, transform 0.2s ease;
}

.mt-done:hover {
  background: var(--mt-accent);
  color: #000;
  transform: translateY(-1px);
}

.mt-msg-ok {
  color: var(--mt-accent);
}

.mt-msg-warn {
  color: #f5c542;
}

.mt-msg-error {
  color: #ff5c5c;
}

/* ------------------------------------------------------------------ mobile --- */

@media (max-width: 640px) {
  .mt-search {
    margin-top: 1.25rem;
  }

  .meme-modal.mt-open .modal-image {
    max-height: 45vh;
  }

  .mt-panel {
    width: 94vw;
    padding: 0.85rem 0.9rem 1rem;
  }

  .mt-add {
    flex-wrap: wrap;
  }

  .mt-add-btn {
    width: 100%;
  }
}

@media (prefers-reduced-motion: reduce) {
  .mt-hit {
    animation: none;
  }
}
