.gate { position: fixed; inset: 0; background: #181818; z-index: 200;
        display: flex; align-items: center; justify-content: center;
        font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif; }
.gate.hidden { display: none; }
.gate-box { background: #222; border: 1px solid #333; border-radius: 10px;
            padding: 36px 40px; min-width: 320px; box-shadow: 0 8px 24px rgba(0,0,0,0.5);
            display: flex; flex-direction: column; gap: 14px; align-items: stretch; }
.gate-box h2 { color: #fff; font-size: 22px; font-weight: 600; text-align: center; }
.gate-box p { color: #aaa; font-size: 13px; text-align: center; margin-bottom: 4px; }
.gate-box input { padding: 10px 12px; background: #2c2c2c; border: 1px solid #444;
                  border-radius: 5px; color: #ddd; font-size: 14px; }
.gate-box input:focus { outline: none; border-color: #5a8ac8; }
.gate-box button { padding: 10px; background: #4a7ab8; border: 1px solid #6a9ad8;
                   color: #fff; border-radius: 5px; cursor: pointer; font-size: 14px;
                   font-weight: 600; }
.gate-box button:hover { background: #5a8ac8; }
.gate-error { color: #f08080; font-size: 12px; min-height: 16px; text-align: center; }
.app-hidden { display: none; }

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
       background: #181818; color: #ddd; display: flex; flex-direction: column; }

.topbar { display: flex; gap: 14px; align-items: center; padding: 10px 16px;
          border-bottom: 1px solid #333; background: #1f1f1f; flex-shrink: 0;
          flex-wrap: wrap; }
.topbar h1 { font-size: 16px; font-weight: 600; color: #fff; margin-right: 12px; }
.filter-label { font-size: 11px; color: #888; text-transform: uppercase;
                letter-spacing: 0.5px; margin-right: 2px; }
.cat-filters { display: flex; gap: 6px; align-items: center; }
.cat-chip { padding: 6px 14px; background: #2c2c2c; border: 1px solid #444;
            border-radius: 16px; color: #ddd; cursor: pointer; font-size: 13px;
            font-weight: 500; }
.cat-chip:hover { background: #353535; }
.cat-chip.active { background: #5a8ac8; border-color: #7aaadd; color: #fff;
                   box-shadow: 0 1px 3px rgba(0,0,0,0.3); }
.cat-chip.cat-favorite.active { background: #d4a01b; border-color: #f5c142; color: #1a1a1a; }
.filters { display: flex; gap: 6px; align-items: center; }
.chip { padding: 5px 13px; background: #2c2c2c; border: 1px solid #444;
        border-radius: 16px; color: #ddd; cursor: pointer; font-size: 12px; }
.chip:hover { background: #353535; }
.chip.active { background: #4a7ab8; border-color: #5a8ac8; color: #fff; }
#sort { padding: 5px 10px; background: #2c2c2c; border: 1px solid #444;
        color: #ddd; border-radius: 4px; font-size: 12px; }
.pagination { margin-left: auto; display: flex; gap: 8px; align-items: center;
              font-size: 14px; color: #fff; font-weight: 500; }
.pagination button { padding: 9px 14px; background: #4a7ab8; border: 1px solid #6a9ad8;
                     color: #fff; border-radius: 6px; cursor: pointer; font-size: 14px;
                     font-weight: 600; box-shadow: 0 1px 2px rgba(0,0,0,0.3);
                     transition: background 0.12s, transform 0.05s; }
.pagination button:hover:not(:disabled) { background: #5a8ac8; }
.pagination button:active:not(:disabled) { transform: translateY(1px); }
.pagination button:disabled { background: #2c2c2c; border-color: #444;
                              color: #666; opacity: 0.6; cursor: not-allowed;
                              box-shadow: none; }
.page-jump { display: flex; align-items: center; gap: 6px; color: #ccc;
             font-size: 13px; padding: 0 4px; }
#page-input { width: 60px; padding: 7px 8px; background: #2c2c2c;
              border: 1px solid #555; border-radius: 5px; color: #fff;
              font-size: 13px; text-align: center; -moz-appearance: textfield; }
#page-input:focus { outline: none; border-color: #6a9ad8; background: #333; }
#page-input::-webkit-outer-spin-button,
#page-input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
#page-total { color: #aaa; }
#page-info { color: #aaa; font-size: 12px; }

.grid { flex: 1; overflow-y: auto; padding: 12px;
        display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
        gap: 8px; align-content: start; }

.tile { position: relative; aspect-ratio: 1; background: #2a2a2a;
        border-radius: 6px; overflow: hidden; cursor: pointer; }
.tile img { width: 100%; height: 100%; object-fit: cover; display: block;
            transition: transform 0.15s; }
.tile:hover { outline: 2px solid #5a8ac8; }
.tile:hover img { transform: scale(1.04); }
.video-badge, .gif-badge { position: absolute; bottom: 6px; right: 6px;
                            background: rgba(0,0,0,0.75); color: white;
                            padding: 2px 7px; border-radius: 3px;
                            font-size: 10px; font-weight: 600; pointer-events: none; }
.video-badge { background: rgba(220, 50, 50, 0.85); }
.fav-badge { position: absolute; top: 6px; right: 6px; color: #f5c142;
             font-size: 20px; line-height: 1;
             text-shadow: 0 1px 3px rgba(0,0,0,0.8), 0 0 1px rgba(0,0,0,0.9);
             pointer-events: none; }
.tile-audio { display: flex; flex-direction: column; align-items: center;
              justify-content: center; padding: 10px; }
.audio-icon { font-size: 56px; color: #5a8ac8; line-height: 1; margin-bottom: 8px; }
.tile-meta { font-size: 10px; color: #aaa; word-break: break-all;
             text-align: center; line-height: 1.3; max-height: 4em; overflow: hidden; }

.empty-state, .loading { grid-column: 1/-1; padding: 60px;
                          text-align: center; color: #666; font-size: 14px; }

.lightbox { position: fixed; inset: 0; background: rgba(0,0,0,0.94);
            display: flex; flex-direction: column; align-items: center;
            justify-content: center; z-index: 100; }
.lightbox.hidden { display: none; }
.lb-content { max-width: 92vw; max-height: 80vh; display: flex;
              align-items: center; justify-content: center; }
.lb-content img, .lb-content video { max-width: 92vw; max-height: 80vh; display: block; }
.lb-content video { background: black; }
.audio-player { display: flex; flex-direction: column; align-items: center;
                gap: 14px; padding: 30px; }
.audio-player audio { width: 360px; }
.audio-name { color: #fff; font-size: 14px; }
.lb-meta { color: #ccc; font-size: 12px; margin-top: 16px;
           text-align: center; padding: 0 20px; line-height: 1.5; }
.lb-meta a { color: #8ab4ff; text-decoration: none; }
.lb-meta a:hover { text-decoration: underline; }

.lb-cat { display: flex; gap: 8px; align-items: center; justify-content: center;
          margin-top: 14px; padding: 0 20px; }
.lb-cat-label { color: #888; font-size: 11px; text-transform: uppercase;
                letter-spacing: 0.5px; margin-right: 4px; }
.lb-cat-btn { padding: 6px 14px; background: #2c2c2c; border: 1px solid #444;
              border-radius: 4px; color: #ddd; cursor: pointer; font-size: 12px;
              font-weight: 500; transition: background 0.12s; }
.lb-cat-btn:hover { background: #353535; }
.lb-cat-btn.active { background: #4a7ab8; border-color: #6a9ad8; color: #fff; }
.lb-cat-btn.active.cat-meme { background: #b85a4a; border-color: #d87a6a; }
.lb-fav { color: #f5c142; }
.lb-fav.active { background: #d4a01b; border-color: #f5c142; color: #1a1a1a; }
.lb-cat-source { color: #777; font-size: 11px; margin-left: 8px; }
.lb-cat-source.user { color: #8ab4ff; }

.close, .nav { position: absolute; background: rgba(255,255,255,0.18);
               border: 1px solid rgba(255,255,255,0.25); color: white; cursor: pointer;
               transition: background 0.15s, transform 0.05s;
               box-shadow: 0 2px 8px rgba(0,0,0,0.4); }
.close { top: 20px; right: 24px; width: 52px; height: 52px;
         font-size: 32px; border-radius: 26px; line-height: 1; font-weight: 600; }
.nav { top: 50%; transform: translateY(-50%); width: 64px; height: 110px;
       font-size: 44px; border-radius: 8px; line-height: 1; font-weight: 700; }
.nav.prev { left: 24px; }
.nav.next { right: 24px; }
.close:hover, .nav:hover { background: rgba(255,255,255,0.32); }
.close:active, .nav:active { transform: translateY(-50%) scale(0.97); }
.close:active { transform: scale(0.95); }

/* ==== Mobile bottom navigation ==== */
.mobile-nav { display: none; }

@media (max-width: 768px) {
  /* Tighter top bar and grid; smaller font */
  .topbar { padding: 8px; gap: 6px; }
  .topbar h1 { font-size: 14px; margin-right: 0; flex-basis: 100%; }
  .filter-label { display: none; }
  .cat-chip, .chip { padding: 7px 10px; font-size: 12px; }
  .cat-filters, .filters { flex-wrap: wrap; gap: 4px; }
  #sort { font-size: 12px; padding: 6px 8px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
          gap: 4px; padding: 6px; padding-bottom: 76px; }
  .video-badge, .gif-badge { font-size: 9px; padding: 1px 5px; }
  .fav-badge { font-size: 16px; }
  .tile-meta { font-size: 9px; }

  /* Hide the desktop top-bar pagination on mobile — replaced by bottom nav */
  .pagination { display: none; }

  /* Sticky bottom bar — always visible while scrolling */
  .mobile-nav {
    display: flex; align-items: center; gap: 6px;
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
    padding: 8px 10px;
    background: rgba(28, 28, 28, 0.96);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border-top: 1px solid #333;
    box-shadow: 0 -2px 8px rgba(0,0,0,0.45);
    padding-bottom: max(8px, env(safe-area-inset-bottom));
  }
  .mobile-nav button {
    flex: 1; padding: 12px 0; min-width: 0;
    background: #4a7ab8; border: 1px solid #6a9ad8; color: #fff;
    border-radius: 6px; font-size: 16px; font-weight: 700;
    cursor: pointer; box-shadow: 0 1px 2px rgba(0,0,0,0.3);
  }
  .mobile-nav button:disabled {
    background: #2c2c2c; border-color: #444;
    color: #666; opacity: 0.55; box-shadow: none;
  }
  .mnav-info {
    display: flex; align-items: center; gap: 4px;
    color: #ddd; font-size: 13px; padding: 0 4px;
    flex-shrink: 0;
  }
  #mnav-page-input {
    width: 52px; padding: 9px 6px;
    background: #2c2c2c; border: 1px solid #555; color: #fff;
    border-radius: 5px; font-size: 14px; text-align: center;
    -moz-appearance: textfield;
  }
  #mnav-page-input::-webkit-outer-spin-button,
  #mnav-page-input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
  #mnav-page-total { color: #aaa; }

  /* Lightbox tweaks for touch */
  .close { width: 48px; height: 48px; font-size: 28px; top: 12px; right: 12px; }
  .nav   { width: 52px; height: 96px; font-size: 38px; }
  .nav.prev { left: 8px; } .nav.next { right: 8px; }
  .lb-cat { flex-wrap: wrap; row-gap: 8px; }
  .lb-content { max-width: 96vw; max-height: 70vh; }
  .lb-content img, .lb-content video { max-width: 96vw; max-height: 70vh; }
}
