:root {
  --bg: #0e1116;
  --fg: #e6edf3;
  --muted: #8b949e;
  --accent: #4b9cff;
  --card: #161b22;
  --border: #30363d;
}
* { box-sizing: border-box; }
[hidden], .hidden { display: none !important; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--fg);
  min-height: 100vh;
}
header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
}
header h1 { font-size: 18px; margin: 0; font-weight: 600; }
.stats { color: var(--muted); font-size: 12px; }

main { max-width: 1200px; margin: 0 auto; padding: 16px 24px 96px; }

#search-form {
  display: flex;
  gap: 8px;
  margin: 10px 0;
}
#q {
  flex: 1;
  padding: 10px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--fg);
  font-size: 16px;   /* MUST stay >=16px: iOS auto-zooms smaller focused inputs */
}
#q:focus { outline: 2px solid var(--accent); }
button, .image-drop {
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--fg);
  border-radius: 8px;
  padding: 10px 14px;
  cursor: pointer;
  font-size: 14px;
}
button[type=submit] { background: var(--accent); border-color: var(--accent); color: #fff; }
.image-drop.dragover { background: var(--accent); color: #fff; }

#mode-toggles {
  display: flex;
  gap: 6px;
  margin-bottom: 12px;
}
.pill {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 12px;
  letter-spacing: 0.03em;
}
.pill.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.pill:hover:not(.active) {
  border-color: var(--accent);
  color: var(--fg);
}

#results {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 12px;
}
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.05s ease, border-color 0.1s;
}
@media (hover: hover) {
  .card:hover { border-color: var(--accent); transform: translateY(-1px); }
}
.card .thumb-wrap {
  position: relative;
  aspect-ratio: 16/9;
  background: #000;
  overflow: hidden;
}
.card img { width: 100%; height: 100%; object-fit: cover; display: block; }
.card .ts-badge {
  position: absolute;
  bottom: 6px; right: 6px;
  background: rgba(0,0,0,0.75);
  font-size: 11px;
  padding: 2px 6px;
  border-radius: 4px;
}
.card .kind-badge {
  position: absolute;
  top: 6px; left: 6px;
  background: rgba(75,156,255,0.85);
  font-size: 10px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  padding: 2px 6px;
  border-radius: 4px;
}
.card .body { padding: 10px 12px; }
.card .title {
  font-size: 13px;
  font-weight: 600;
  margin: 0 0 4px;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.card .subtitle {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}





.empty {
  color: var(--muted);
  text-align: center;
  padding: 80px 20px;
  font-size: 14px;
}
.cluster-badge {
  position: absolute;
  bottom: 6px; left: 6px;
  background: rgba(255,255,255,0.16);
  color: #fff;
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 4px;
  letter-spacing: 0.04em;
}
#more-zone {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  margin: 24px 0 80px;
  min-height: 60px;
}
#more-btn {
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--fg);
  padding: 10px 28px;
  border-radius: 999px;
  cursor: pointer;
  font-size: 13px;
}
#more-btn:hover { border-color: var(--accent); }
#more-status {
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}


/* --- scan control --- */
.scan-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 6px;
  flex-wrap: wrap;
}
#scan-btn {
  font-size: 12px;
  padding: 5px 12px;
  border-radius: 999px;
  cursor: pointer;
}
#scan-btn:disabled { opacity: .5; cursor: not-allowed; }
.scan-status { font-size: 12px; opacity: .7; }


/* ===========================================================================
   Mobile
   The stylesheet originally had no media queries at all. Everything below is
   about a 375px iPhone: safe-area insets, thumb-sized tap targets, and a player
   that does not depend on 100vh (which iOS Safari measures against a URL bar
   that shrinks as you scroll).
   =========================================================================== */

.drop-short { display: none; }

/* Respect the notch/home indicator everywhere that touches a screen edge. */
header {
  padding-left: max(24px, env(safe-area-inset-left));
  padding-right: max(24px, env(safe-area-inset-right));
  padding-top: max(16px, env(safe-area-inset-top));
}






@media (max-width: 700px) {
  header {
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
    padding-bottom: 12px;
  }
  header h1 { font-size: 16px; }
  .stats { font-size: 11px; line-height: 1.4; }

  main { padding: 12px 12px 80px; }

  /* Two columns of thumbnails beats one giant card: more results per screen,
     and 16:9 art is still legible at ~165px wide. */
  #results {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }
  .card .body { padding: 8px 9px; }
  .card .title { font-size: 12px; }
  .card .subtitle { font-size: 11px; -webkit-line-clamp: 2; }

  /* Search row: the input keeps the full width, the two buttons sit beneath it
     rather than being crushed onto one line. */
  #search-form {
    flex-wrap: wrap;
    gap: 8px;
    padding: 8px 0;
  }
  #q { flex: 1 1 100%; }
  .image-drop, #search-form button[type=submit] {
    flex: 1 1 0;
    text-align: center;
    min-height: 44px;          /* Apple HIG minimum tap target */
    display: flex;
    align-items: center;
    justify-content: center;
  }
  .drop-long { display: none; }
  .drop-short { display: inline; }

  /* Toggles become full-width segments -- easier to hit than 12px pills. */
  #mode-toggles { gap: 6px; }
  .pill {
    flex: 1 1 0;
    min-height: 40px;
    font-size: 13px;
    padding: 6px 8px;
  }

  .scan-row { gap: 8px; }
  #scan-btn { min-height: 36px; }
  .scan-status { font-size: 11px; }

  
  
  

  #more-zone { margin: 16px 0 40px; }
  #more-btn { min-height: 44px; width: 100%; }
}

/* Very narrow phones: one column reads better than two cramped ones. */
@media (max-width: 360px) {
  #results { grid-template-columns: minmax(0, 1fr); }
}




/* Brief affordance so the hidden controls are discoverable. */



/* Holds a still of the clip over the video until it is genuinely playing at the
   right timestamp, hiding the opening frame the element paints before seeking. */






/* ===========================================================================
   Player — one panel, overlays on the video instead of stacked boxes
   =========================================================================== */

#player-wrap {
  position: fixed;
  inset: 0;
  z-index: 10;
  background: rgba(4, 7, 11, 0.92);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: max(20px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right))
           max(20px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}

.player-panel {
  width: 100%;
  max-width: min(1100px, 100%);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;                 /* keeps the video corners inside the card */
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.55);
}

.player-stage {
  position: relative;
  background: #000;
  line-height: 0;                   /* no stray descender gap under the video */
}

#player {
  display: block;
  width: 100%;
  max-height: min(70vh, 70dvh);
  background: #000;
}

/* Still of the clip, held over the video until it plays at the right point. */
.player-cover {
  position: absolute;
  inset: 0;
  background-color: #000;
  background-size: contain;
  background-position: center;
  background-repeat: no-repeat;
  pointer-events: none;
}
.player-cover[hidden] { display: none; }

/* Single compact caption row. */
.player-meta {
  padding: 11px 14px;
  font-size: 13px;
  line-height: 1.45;
  color: var(--fg);
  border-top: 1px solid var(--border);
}
.player-meta .pm-title { font-weight: 600; }
.player-meta .pm-sub {
  color: var(--muted);
  font-size: 12px;
  margin-top: 2px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.player-meta a { color: var(--accent); text-decoration: none; }

/* Close control sits on the video, not below it. */
.close-player {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 40px;
  height: 40px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  border: 0;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  cursor: pointer;
  z-index: 3;
}
.close-player:hover { background: rgba(0, 0, 0, 0.8); }

/* Overlays, not extra blocks. */
.tap-hint {
  position: absolute;
  left: 50%;
  bottom: 10px;
  transform: translateX(-50%);
  padding: 5px 12px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.6);
  color: #fff;
  font-size: 11px;
  white-space: nowrap;
  opacity: 0;
  transition: opacity 0.4s ease;
  pointer-events: none;
  z-index: 2;
}
.tap-hint.visible { opacity: 1; }
.tap-hint[hidden] { display: none; }

.player-note {
  position: absolute;
  left: 10px;
  right: 10px;
  bottom: 10px;
  padding: 8px 12px;
  border-radius: 8px;
  background: rgba(248, 81, 73, 0.92);
  color: #fff;
  font-size: 12px;
  line-height: 1.4;
  white-space: pre-wrap;
  word-break: break-word;
  z-index: 3;
  max-height: 60%;
  overflow: auto;
}
.player-note[hidden] { display: none; }

@media (max-width: 700px) {
  .player-panel { border-radius: 12px; }
  #player { max-height: min(58vh, 58dvh); }
  .player-meta { padding: 9px 12px; font-size: 12px; }
  .player-meta .pm-sub { font-size: 11px; -webkit-line-clamp: 2; }
  .close-player { width: 44px; height: 44px; }
}

/* ===========================================================================
   Publication images (wol.jw.org)
   =========================================================================== */
#image-wrap {
  position: fixed;
  inset: 0;
  z-index: 10;
  background: rgba(4, 7, 11, 0.92);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: max(20px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right))
           max(20px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}
.image-panel {
  width: 100%;
  max-width: min(1100px, 100%);
  max-height: 100%;
  overflow: auto;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.55);
}
.image-stage { position: relative; background: #000; line-height: 0; }
#image-full {
  display: block;
  width: 100%;
  max-height: min(68vh, 68dvh);
  object-fit: contain;
}
.image-meta {
  padding: 11px 14px;
  font-size: 13px;
  line-height: 1.45;
  border-top: 1px solid var(--border);
}
.image-meta .pm-title { font-weight: 600; margin-bottom: 4px; }
.im-row { margin-top: 6px; color: var(--fg); }
.im-label {
  display: block;
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.im-links { margin-top: 10px; font-size: 12px; color: var(--muted); }
.image-meta a { color: var(--accent); text-decoration: none; }
.image-card .kind-badge { background: rgba(46, 160, 67, 0.9); }
.image-card .subtitle { -webkit-line-clamp: 4; }

@media (max-width: 700px) {
  #image-full { max-height: min(55vh, 55dvh); }
  .image-meta { padding: 9px 12px; font-size: 12px; }
}

/* ===========================================================================
   Top area (v14): header with a discreet info button, then a sticky search
   head -- source tabs, the search row, and "Match by" chips.
   =========================================================================== */
header { align-items: center; padding-top: 12px; padding-bottom: 12px; }
.info-wrap { position: relative; }
.icon-btn {
  position: relative;
  display: flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; padding: 0;
  border-radius: 50%;
  background: transparent;
  border: 1px solid transparent;
  color: var(--muted);
}
.icon-btn:hover, .icon-btn[aria-expanded="true"] {
  color: var(--fg); border-color: var(--border); background: var(--card);
}
.info-dot {
  position: absolute; top: 5px; right: 5px;
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 2px var(--bg);
}
.info-panel {
  position: absolute; right: 0; top: calc(100% + 8px);
  width: 290px;
  z-index: 20;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px 14px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.5);
  font-size: 12px;
}
.info-h {
  color: var(--muted);
  font-size: 10px; letter-spacing: 0.06em; text-transform: uppercase;
  margin: 2px 0 6px;
}
.info-h:not(:first-child) { margin-top: 12px; }
.stats-grid {
  display: grid; grid-template-columns: 1fr auto; gap: 3px 12px; margin: 0;
}
.stats-grid dt { color: var(--muted); }
.stats-grid dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }
.info-panel .scan-status { opacity: 1; color: var(--fg); margin-bottom: 8px; min-height: 1em; }
.info-panel #scan-btn { width: 100%; border-radius: 8px; padding: 7px 12px; font-size: 12px; }

.search-head {
  position: sticky; top: 0; z-index: 5;
  background: var(--bg);
  padding: 6px 0 10px;
  margin-bottom: 8px;
  border-bottom: 1px solid transparent;
}
.source-tabs {
  display: inline-flex;
  padding: 3px;
  gap: 2px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
}
.source-tab {
  border: 0; background: transparent; color: var(--muted);
  padding: 7px 18px; border-radius: 7px; font-size: 14px; font-weight: 600;
}
.source-tab.active { background: var(--accent); color: #fff; }
.source-tab:hover:not(.active) { color: var(--fg); }

.method-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.method-label { color: var(--muted); font-size: 12px; }
.method-chips { display: flex; gap: 6px; flex-wrap: wrap; }
.method-chips[hidden] { display: none; }
.chip {
  background: transparent; border: 1px solid var(--border); color: var(--muted);
  padding: 5px 12px; border-radius: 999px; font-size: 12px;
}
.chip.active { border-color: var(--accent); color: var(--fg); background: rgba(75, 156, 255, 0.15); }
.chip:hover:not(.active) { color: var(--fg); }
.image-query {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--accent); border-radius: 999px;
  padding: 3px 4px 3px 12px; font-size: 12px;
  max-width: 100%;
}
.image-query[hidden] { display: none; }
#image-query-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 50vw; }
#image-query-clear {
  border: 0; background: transparent; color: var(--muted);
  padding: 2px 6px; font-size: 12px;
}

/* Why an image matched. */
.kind-badge.match-description { background: rgba(163, 113, 247, 0.9); }
.kind-badge.match-picture { background: rgba(46, 160, 67, 0.9); }
.kind-badge.match-both { background: rgba(210, 153, 34, 0.92); }

@media (max-width: 700px) {
  header { flex-direction: row; align-items: center; }
  .source-tabs { display: flex; }
  .source-tab { flex: 1 1 0; min-height: 40px; }
  .chip { min-height: 34px; font-size: 13px; }
  .info-panel { width: min(290px, calc(100vw - 24px)); }
}
