/* styles.css */

/* =========================================================
   GLOBAL
   ========================================================= */

/* Prevent initial flash: hide the other view based on saved view */
html[data-view="gallery"] #tagging-view { display: none !important; }
html[data-view="tagging"] #gallery-view { display: none !important; }

/* --- Variables --- */
:root{
  --side-ui-gap: 44px;
  --tag-top: 35px;     /* top bar height */
  --tag-bottom: 35px;  /* bottom bar height */

  --gallery-cols: 3;   /* default */
}

/* --- Resets --- */
*{ box-sizing: border-box; }

body{
  margin: 0;
  font-family: sans-serif;
  background: white;
  color: black;
  font-size: 14px;
  overflow: hidden;
}

@media (max-width: 768px){
  body{ overflow: auto; }
}

button{
  background: none;
  border: none;
  font-family: inherit;
  cursor: pointer;
  letter-spacing: 0.05em;
  font-size: 14px;
  color: black;
}

.hidden{ display:none; }

/* --- Fullscreen pages --- */
.page,
#gallery-view{
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100dvh;
  background: white;
  overflow: hidden; /* IMPORTANT: children handle scrolling */
}

/* =========================================================
   GALLERY GRID
   ========================================================= */

#gallery-grid{
  display: grid;
  width: 100%;
  gap: 0;
  align-content: start;
  align-items: start;

  grid-template-columns: repeat(var(--gallery-cols), 1fr);

  height: 100%;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;

  touch-action: pan-y; /* allow pinch on grid without page zoom */
  overscroll-behavior: auto;
}

#gallery-grid img{
  width: 100%;
  aspect-ratio: 3 / 4;
  object-fit: cover;
  cursor: pointer;
  display: block;
  -webkit-user-drag: none;
  user-select: none;
  -webkit-user-select: none;
}

/* ---------- SINGLE-IMAGE MODE (height-driven, no scroll) ---------- */
#gallery-grid.single-image{
  overflow: hidden;      /* stop the grid from scrolling in single-image mode */
  display: grid;
  place-items: start;    /* (was invalid: left) */
  grid-template-columns: 1fr;
  grid-auto-rows: 1fr;
}

#gallery-grid.single-image img{
  height: 100%;
  width: auto;
  max-height: 100dvh;
  object-fit: cover;
  aspect-ratio: 3 / 4;
}

/* =========================================================
   TAGGING VIEW — SHARED
   ========================================================= */

.question-anchor{
  position: relative;
  display: inline-block;
}

#question-popover{
  position: fixed;
  top: 50%;
  left: 50%;
  width: 300px;
  height: fit-content;
  transform: translate(-50%, -50%);
}

/* stage sizing */
.tagging-stage{
  position: relative;
  --stage-max-h: calc(100dvh - var(--tag-top) - var(--tag-bottom));
  width: min(
    520px,
    calc(100vw - (var(--side-ui-gap) * 2)),
    calc(var(--stage-max-h) * 3 / 4)
  );
  aspect-ratio: 3 / 4;
  height: auto;
  max-height: var(--stage-max-h);
  display: grid;
  place-items: center;
  background: #d9d9d9;
}

.image-column{
  width: 100%;
  display: grid;
  place-items: center;
  min-height: 0;
}

#image-wrapper{
  width: 100%;
  height: 100%;
  background: #d9d9d9;
  overflow: hidden;
  position: relative;
  touch-action: none;           /* stop page pinch-zoom on this area */
  overscroll-behavior: contain; /* prevent scroll chaining */
}

#main-image{
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  cursor: pointer;
  transform-origin: 0 0;
  will-change: transform;
}

.tag-label{
  position: absolute;
  background: rgba(255,255,255,0.9);
  border: 1px solid #333;
  padding: 2px 5px;
  pointer-events: auto;
  cursor: pointer;
  z-index: 9000;
}

.tag-input{
  position: absolute;
  z-index: 9999;
  border: 1px solid #333;
  padding: 4px 6px;
  background: white;
  width: 220px;
  max-width: calc(100% - 18px);
  font-size: 13px; /* prevents iOS input-focus zoom */
  line-height: 1.2;
}

.tag-error{
  position: absolute;
  z-index: 10000;
  background: rgba(30, 30, 30, 0.95);
  border: 1px solid #333;
  padding: 3px 6px;
  font-size: 12px;
  color: white;
  pointer-events: none;
}

#tag-toggle-icon{
  position: absolute;
  left: 10px;
  bottom: 10px;
  width: 22px;
  height: 22px;
  background: url("../images/price-tag.png") no-repeat center center;
  background-size: contain;
  z-index: 9999;
  display: none;
  transform-origin: left bottom;
  pointer-events: auto;
  cursor: pointer;
  transition: transform 120ms ease-out, box-shadow 120ms ease-out;
  transform: scale(1) translateZ(0);
}

@media (hover: hover){
  #tag-toggle-icon:hover{
    transform: scale(1.1) translateZ(0);
  }
}

.inline-icon{
  height: 1em;
  width: auto;
  vertical-align: -0.15em;
  margin-right: 4px;
}

/* =========================================================
   GALLERY TAG LIST — GLOBAL TEXT STYLING
   ========================================================= */

#gallery-tag-list,
#gallery-tag-list *{
  font-size: inherit;
  text-transform: lowercase;
  text-align: right;
}

#gallery-tag-list li.disabled{
  opacity: 0.25;
  cursor: default;
  pointer-events: none;
}

#gallery-tag-list li.selected{
  pointer-events: auto;
  opacity: 1;
  font-weight: 700;
  color: black;
}

@media (hover: hover) and (pointer: fine){
  #gallery-tag-list li:hover{
    font-weight: 700;
    color: black;
  }
}

/* --- Shared button emphasis --- */
#questionBtn,
#nextBtn,
#galleryBtn,
.gallery-clear-btn,
.gallery-help-btn{
  font-weight: 400;
}

@media (hover: hover){
  #questionBtn:hover,
  #prevBtn:hover,
  #nextBtn:hover,
  .gallery-clear-btn:hover,
  .gallery-help-btn:hover{
    font-weight: 700;
    font-size: 15px;
    color: black;
  }

  #galleryBtn:hover{
    font-weight: 700;
    color: black;
  }
}

#questionBtn:active,
#prevBtn:active,
#nextBtn:active,
#galleryBtn:active,
.gallery-clear-btn:active,
.gallery-help-btn:active{
  font-weight: 700;
  font-size: 15px;
  color: black;
}

#questionBtn:focus-visible,
#prevBtn:focus-visible,
#nextBtn:focus-visible,
#galleryBtn:focus-visible,
.gallery-clear-btn:focus-visible,
.gallery-help-btn:focus-visible{
  font-weight: 700;
  outline: none;
  font-size: 15px;
  color: black;
}

/* =========================================================
   TAGGING VIEW — DESKTOP (≥ 769px)
   ========================================================= */

#tagging-view{
  height: 100dvh;
  display: grid;
  grid-template-rows: var(--tag-top) 1fr var(--tag-bottom);
  overflow: hidden;
}

#tagging-view .top-nav{
  grid-row: 1;
  height: var(--tag-top);
  display: flex;
  align-items: center;
  justify-content: center;
  background: white;
  z-index: 100;
}

#tagging-view .tagging-layout{
  grid-row: 2;
  min-height: 0;
  display: grid;
  place-items: center;
  overflow: hidden;
}

#tagging-view .bottom-nav{
  grid-row: 3;
  height: var(--tag-bottom);
  display: flex;
  align-items: center;
  justify-content: center;
  background: white;
  z-index: 100;
}

.side-btn{
  position: fixed;
  top: 50%;
  transform: translateY(-50%);
  z-index: 200;
  padding: 5px;
}
.side-btn.left{ left: 10px; }
.side-btn.right{ right: 10px; }

.view-all-btn{
  font-size: 14px;
  color: black;
  letter-spacing: 0.05em;
  padding: 10px 0;
}

/* Question popover — hover to open (desktop) */
@media (hover: hover) and (pointer: fine){
  #question-popover{ display: none; }
  .question-anchor:hover #question-popover{ display: block; }
}

/* =========================================================
   TAGGING VIEW — MOBILE (≤ 768px)
   ========================================================= */

@media (max-width: 768px){
  :root{
    --tag-bottom: calc(35px + env(safe-area-inset-bottom));
  }

  #tagging-view{
    grid-template-rows: var(--tag-top) 1fr var(--tag-bottom);
  }

  #tagging-view .top-nav{
    height: var(--tag-top);
  }

  #tagging-view .bottom-nav{
    height: var(--tag-bottom);
    padding-bottom: env(safe-area-inset-bottom);
  }

  .tagging-stage{
    width: calc(100vw - (var(--side-ui-gap) * 2));
    height: auto;
    max-height: 100%;
    max-width: 520px;
    display: grid;
    place-items: center;
    aspect-ratio: 3 / 4;
  }

  #image-wrapper,
  #main-image{
    width: 100%;
    height: 100%;
  }

  .tag-input{
    font-size: 16px;
    line-height: 1.2;
  }

  .side-btn.left{ left: 5px; }
  .side-btn.right{ right: 5px; }

  /* Mobile: hidden by default, JS toggles it */
  @media (hover: none){
    #question-popover{ display: none; }
    #question-popover.open{ display: block; }
  }
}

/* =========================================================
   GALLERY VIEW — DESKTOP (≥ 769px)
   ========================================================= */

#gallery-view{ overflow: hidden; }

.gallery-layout{
  height: 100%;
  display: grid;
  grid-template-columns: 120px 1fr;
  gap: 10px;
  padding: 0;
  overflow: hidden;
}

/* hide scrollbars but keep scroll */
.gallery-sidebar,
#gallery-grid,
#gallery-tag-list{
  scrollbar-width: none;
  -ms-overflow-style: none;
}
.gallery-sidebar::-webkit-scrollbar,
#gallery-grid::-webkit-scrollbar,
#gallery-tag-list::-webkit-scrollbar{
  width: 0;
  height: 0;
}

/* sidebar */
.gallery-sidebar ul{ list-style:none; padding-left:0; }
.gallery-sidebar li{ cursor:pointer; }
.gallery-sidebar li.selected{ font-weight:bold; }

@media (min-width: 769px){
  .gallery-layout{
    padding-left: 10px;
  }

  #gallery-grid{
    height: 100%;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
  }

  #gallery-view .help-anchor{
    position: fixed;
    bottom: 20px;
    left: 20px;
    z-index: 300;
  }

  .gallery-clear-btn{
    position: fixed;
    left: 10px;
    top: 10px;
    z-index: 300;
    color: black;
    align-self: flex-start;
    margin-bottom: 10px;
  }

  .gallery-sidebar{
    height: 100%;
    display: grid;
    grid-template-rows: auto 1fr;
    overflow: hidden;
  }

  .gallery-sidebar-top{
    display: flex;
    flex-direction: column;
    align-items: right;
    position: sticky;
    top: 0;
    background: white;
    z-index: 20;
    padding-top: 10px;
    padding-right: 10px;
  }

  #gallery-tag-list{
    overflow-y: auto;
    min-height: 0;
    padding: 0;
    margin-top: 0px;
  }
}

/* help popover (gallery) */
.help-anchor{
  position: relative;
  display: inline-block;
}

.gallery-help-btn{
  padding: 0;
  line-height: 1;
  position: relative;
  z-index: 2;
  color: black;
}

.help-popover{
  position: absolute;
  top: 0;
  left: 0;
  transform: translate(18px, -100%);
  background: white;
  border: 1px solid #333;
  padding: 14px 16px;
  text-align: left;
  box-shadow: 0 2px 10px rgba(0,0,0,0.2);
  z-index: 1;
  width: 200px;
}

.help-popover.hidden{ display:none; }

@media (hover: hover) and (pointer: fine){
  .help-anchor .help-popover{ display:none; }
  .help-anchor .gallery-help-btn:hover + .help-popover,
  .help-anchor .help-popover:hover,
  .help-anchor .gallery-help-btn:focus-visible + .help-popover{
    display:block;
  }
}

/* =========================================================
   GALLERY VIEW — MOBILE (≤ 768px)
   ========================================================= */

@media (max-width: 768px){
  :root{
    --gallery-bottom-bar: 40px;
  }

  #gallery-view{
    padding-bottom: var(--gallery-bottom-bar);
    box-sizing: border-box;
    overflow: hidden;
  }

  .gallery-layout{
    display: flex;
    flex-direction: column-reverse;
    height: 100%;
  }

  /* mobile tag list */
  #gallery-tag-list{
    display: flex;
    flex-direction: column;
    flex-wrap: wrap;
    height: 6em;
    align-content: flex-start;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 0;
    margin: 0;
  }

  #gallery-tag-list li{
    width: 150px;
    white-space: normal;
    line-height: 1;
    padding: 0 10px;
    margin: 0 0 2px 0;
    text-align: left;
    font-weight: 400;
    color: black;
  }

  .help-popover{
    transform: translate(calc(-100% - 18px), -100%);
  }

  #gallery-view .help-anchor{
    position: fixed;
    right: 15px;
    bottom: calc(10px + env(safe-area-inset-bottom));
    left: auto;
    z-index: 400;
  }

  .gallery-clear-btn{
    position: fixed;
    left: 15px;
    bottom: calc(10px + env(safe-area-inset-bottom));
    z-index: 400;
    color: black;
  }
}
/* styles.css */

/* =========================================================
   GLOBAL
   ========================================================= */

/* Prevent initial flash: hide the other view based on saved view */
html[data-view="gallery"] #tagging-view { display: none !important; }
html[data-view="tagging"] #gallery-view { display: none !important; }

/* --- Variables --- */
:root{
  --side-ui-gap: 44px;
  --tag-top: 35px;     /* top bar height */
  --tag-bottom: 35px;  /* bottom bar height */

  --gallery-cols: 3;   /* default */
}

/* --- Resets --- */
*{ box-sizing: border-box; }

body{
  margin: 0;
  font-family: sans-serif;
  background: white;
  color: black;
  font-size: 14px;
  overflow: hidden;
}

@media (max-width: 768px){
  body{ overflow: auto; }
}

button{
  background: none;
  border: none;
  font-family: inherit;
  cursor: pointer;
  letter-spacing: 0.05em;
  font-size: 14px;
  color: black;
}

.hidden{ display:none; }

/* --- Fullscreen pages --- */
.page,
#gallery-view{
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100dvh;
  background: white;
  overflow: hidden; /* IMPORTANT: children handle scrolling */
}

/* =========================================================
   GALLERY GRID
   ========================================================= */

#gallery-grid{
  display: grid;
  width: 100%;
  gap: 0;
  align-content: start;
  align-items: start;

  grid-template-columns: repeat(var(--gallery-cols), 1fr);

  height: 100%;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;

  touch-action: pan-y; /* allow pinch on grid without page zoom */
  overscroll-behavior: auto;
}

#gallery-grid img{
  width: 100%;
  aspect-ratio: 3 / 4;
  object-fit: cover;
  cursor: pointer;
  display: block;
  -webkit-user-drag: none;
  user-select: none;
  -webkit-user-select: none;
}

/* ---------- SINGLE-IMAGE MODE (height-driven, no scroll) ---------- */
#gallery-grid.single-image{
  overflow: hidden;      /* stop the grid from scrolling in single-image mode */
  display: grid;
  place-items: start;    /* (was invalid: left) */
  grid-template-columns: 1fr;
  grid-auto-rows: 1fr;
}

#gallery-grid.single-image img{
  height: 100%;
  width: auto;
  max-height: 100dvh;
  object-fit: cover;
  aspect-ratio: 3 / 4;
}

/* =========================================================
   TAGGING VIEW — SHARED
   ========================================================= */

.question-anchor{
  position: relative;
  display: inline-block;
}

#question-popover{
  position: fixed;
  top: 50%;
  left: 50%;
  width: 300px;
  height: fit-content;
  transform: translate(-50%, -50%);
}

/* stage sizing */
.tagging-stage{
  position: relative;
  --stage-max-h: calc(100dvh - var(--tag-top) - var(--tag-bottom));
  width: min(
    520px,
    calc(100vw - (var(--side-ui-gap) * 2)),
    calc(var(--stage-max-h) * 3 / 4)
  );
  aspect-ratio: 3 / 4;
  height: auto;
  max-height: var(--stage-max-h);
  display: grid;
  place-items: center;
  background: #d9d9d9;
}

.image-column{
  width: 100%;
  display: grid;
  place-items: center;
  min-height: 0;
}

#image-wrapper{
  width: 100%;
  height: 100%;
  background: #d9d9d9;
  overflow: hidden;
  position: relative;
  touch-action: none;           /* stop page pinch-zoom on this area */
  overscroll-behavior: contain; /* prevent scroll chaining */
}

#main-image{
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  cursor: pointer;
  transform-origin: 0 0;
  will-change: transform;
}

.tag-label{
  position: absolute;
  background: rgba(255,255,255,0.9);
  border: 1px solid #333;
  padding: 2px 5px;
  pointer-events: auto;
  cursor: pointer;
  z-index: 9000;
}

.tag-input{
  position: absolute;
  z-index: 9999;
  border: 1px solid #333;
  padding: 4px 6px;
  background: white;
  width: 220px;
  max-width: calc(100% - 18px);
  font-size: 13px; /* prevents iOS input-focus zoom */
  line-height: 1.2;
}

.tag-error{
  position: absolute;
  z-index: 10000;
  background: rgba(30, 30, 30, 0.95);
  border: 1px solid #333;
  padding: 3px 6px;
  font-size: 12px;
  color: white;
  pointer-events: none;
}

#tag-toggle-icon{
  position: absolute;
  left: 10px;
  bottom: 10px;
  width: 22px;
  height: 22px;
  background: url("../images/price-tag.png") no-repeat center center;
  background-size: contain;
  z-index: 9999;
  display: none;
  transform-origin: left bottom;
  pointer-events: auto;
  cursor: pointer;
  transition: transform 120ms ease-out, box-shadow 120ms ease-out;
  transform: scale(1) translateZ(0);
}

@media (hover: hover){
  #tag-toggle-icon:hover{
    transform: scale(1.1) translateZ(0);
  }
}

.inline-icon{
  height: 1em;
  width: auto;
  vertical-align: -0.15em;
  margin-right: 4px;
}

/* =========================================================
   GALLERY TAG LIST — GLOBAL TEXT STYLING
   ========================================================= */

#gallery-tag-list,
#gallery-tag-list *{
  font-size: inherit;
  text-transform: lowercase;
  text-align: right;
}

#gallery-tag-list li.disabled{
  opacity: 0.25;
  cursor: default;
  pointer-events: none;
}

#gallery-tag-list li.selected{
  pointer-events: auto;
  opacity: 1;
  font-weight: 700;
  color: black;
}

@media (hover: hover) and (pointer: fine){
  #gallery-tag-list li:hover{
    font-weight: 700;
    color: black;
  }
}

/* --- Shared button emphasis --- */
#questionBtn,
#nextBtn,
#galleryBtn,
.gallery-clear-btn,
.gallery-help-btn{
  font-weight: 400;
}

@media (hover: hover){
  #questionBtn:hover,
  #prevBtn:hover,
  #nextBtn:hover,
  .gallery-clear-btn:hover,
  .gallery-help-btn:hover{
    font-weight: 700;
    font-size: 15px;
    color: black;
  }

  #galleryBtn:hover{
    font-weight: 700;
    color: black;
  }
}

#questionBtn:active,
#prevBtn:active,
#nextBtn:active,
#galleryBtn:active,
.gallery-clear-btn:active,
.gallery-help-btn:active{
  font-weight: 700;
  font-size: 15px;
  color: black;
}

#questionBtn:focus-visible,
#prevBtn:focus-visible,
#nextBtn:focus-visible,
#galleryBtn:focus-visible,
.gallery-clear-btn:focus-visible,
.gallery-help-btn:focus-visible{
  font-weight: 700;
  outline: none;
  font-size: 15px;
  color: black;
}

/* =========================================================
   TAGGING VIEW — DESKTOP (≥ 769px)
   ========================================================= */

#tagging-view{
  height: 100dvh;
  display: grid;
  grid-template-rows: var(--tag-top) 1fr var(--tag-bottom);
  overflow: hidden;
}

#tagging-view .top-nav{
  grid-row: 1;
  height: var(--tag-top);
  display: flex;
  align-items: center;
  justify-content: center;
  background: white;
  z-index: 100;
}

#tagging-view .tagging-layout{
  grid-row: 2;
  min-height: 0;
  display: grid;
  place-items: center;
  overflow: hidden;
}

#tagging-view .bottom-nav{
  grid-row: 3;
  height: var(--tag-bottom);
  display: flex;
  align-items: center;
  justify-content: center;
  background: white;
  z-index: 100;
}

.side-btn{
  position: fixed;
  top: 50%;
  transform: translateY(-50%);
  z-index: 200;
  padding: 5px;
}
.side-btn.left{ left: 10px; }
.side-btn.right{ right: 10px; }

.view-all-btn{
  font-size: 14px;
  color: black;
  letter-spacing: 0.05em;
  padding: 10px 0;
}

/* Question popover — hover to open (desktop) */
@media (hover: hover) and (pointer: fine){
  #question-popover{ display: none; }
  .question-anchor:hover #question-popover{ display: block; }
}

/* =========================================================
   TAGGING VIEW — MOBILE (≤ 768px)
   ========================================================= */

@media (max-width: 768px){
  :root{
    --tag-bottom: calc(35px + env(safe-area-inset-bottom));
  }

  #tagging-view{
    grid-template-rows: var(--tag-top) 1fr var(--tag-bottom);
  }

  #tagging-view .top-nav{
    height: var(--tag-top);
  }

  #tagging-view .bottom-nav{
    height: var(--tag-bottom);
    padding-bottom: env(safe-area-inset-bottom);
  }

  .tagging-stage{
    width: calc(100vw - (var(--side-ui-gap) * 2));
    height: auto;
    max-height: 100%;
    max-width: 520px;
    display: grid;
    place-items: center;
    aspect-ratio: 3 / 4;
  }

  #image-wrapper,
  #main-image{
    width: 100%;
    height: 100%;
  }

  .tag-input{
    font-size: 16px;
    line-height: 1.2;
  }

  .side-btn.left{ left: 5px; }
  .side-btn.right{ right: 5px; }

  /* Mobile: hidden by default, JS toggles it */
  @media (hover: none){
    #question-popover{ display: none; }
    #question-popover.open{ display: block; }
  }
}

/* =========================================================
   GALLERY VIEW — DESKTOP (≥ 769px)
   ========================================================= */

#gallery-view{ overflow: hidden; }

.gallery-layout{
  height: 100%;
  display: grid;
  grid-template-columns: 120px 1fr;
  gap: 10px;
  padding: 0;
  overflow: hidden;
}

/* hide scrollbars but keep scroll */
.gallery-sidebar,
#gallery-grid,
#gallery-tag-list{
  scrollbar-width: none;
  -ms-overflow-style: none;
}
.gallery-sidebar::-webkit-scrollbar,
#gallery-grid::-webkit-scrollbar,
#gallery-tag-list::-webkit-scrollbar{
  width: 0;
  height: 0;
}

/* sidebar */
.gallery-sidebar ul{ list-style:none; padding-left:0; }
.gallery-sidebar li{ cursor:pointer; }
.gallery-sidebar li.selected{ font-weight:bold; }

@media (min-width: 769px){
  .gallery-layout{
    padding-left: 10px;
  }

  #gallery-grid{
    height: 100%;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
  }

  #gallery-view .help-anchor{
    position: fixed;
    bottom: 20px;
    left: 20px;
    z-index: 300;
  }

  .gallery-clear-btn{
    position: fixed;
    left: 10px;
    top: 10px;
    z-index: 300;
    color: black;
    align-self: flex-start;
    margin-bottom: 10px;
  }

  .gallery-sidebar{
    height: 100%;
    display: grid;
    grid-template-rows: auto 1fr;
    overflow: hidden;
  }

  .gallery-sidebar-top{
    display: flex;
    flex-direction: column;
    align-items: right;
    position: sticky;
    top: 0;
    background: white;
    z-index: 20;
    padding-top: 10px;
    padding-right: 10px;
  }

  #gallery-tag-list{
    overflow-y: auto;
    min-height: 0;
    padding: 0;
    margin-top: 0px;
  }
}

/* help popover (gallery) */
.help-anchor{
  position: relative;
  display: inline-block;
}

.gallery-help-btn{
  padding: 0;
  line-height: 1;
  position: relative;
  z-index: 2;
  color: black;
}

.help-popover{
  position: absolute;
  top: 0;
  left: 0;
  transform: translate(18px, -100%);
  background: white;
  border: 1px solid #333;
  padding: 14px 16px;
  text-align: left;
  box-shadow: 0 2px 10px rgba(0,0,0,0.2);
  z-index: 1;
  width: 200px;
}

.help-popover.hidden{ display:none; }

@media (hover: hover) and (pointer: fine){
  .help-anchor .help-popover{ display:none; }
  .help-anchor .gallery-help-btn:hover + .help-popover,
  .help-anchor .help-popover:hover,
  .help-anchor .gallery-help-btn:focus-visible + .help-popover{
    display:block;
  }
}

/* =========================================================
   GALLERY VIEW — MOBILE (≤ 768px)
   ========================================================= */

@media (max-width: 768px){
  :root{
    --gallery-bottom-bar: 40px;
  }

  #gallery-view{
    padding-bottom: var(--gallery-bottom-bar);
    box-sizing: border-box;
    overflow: hidden;
  }

  .gallery-layout{
    display: flex;
    flex-direction: column-reverse;
    height: 100%;
  }

  /* mobile tag list */
  #gallery-tag-list{
    display: flex;
    flex-direction: column;
    flex-wrap: wrap;
    height: 6em;
    align-content: flex-start;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 0;
    margin: 0;
  }

  #gallery-tag-list li{
    width: 150px;
    white-space: normal;
    line-height: 1;
    padding: 0 10px;
    margin: 0 0 2px 0;
    text-align: left;
    font-weight: 400;
    color: black;
  }

  .help-popover{
    transform: translate(calc(-100% - 18px), -100%);
  }

  #gallery-view .help-anchor{
    position: fixed;
    right: 15px;
    bottom: calc(10px + env(safe-area-inset-bottom));
    left: auto;
    z-index: 400;
  }

  .gallery-clear-btn{
    position: fixed;
    left: 15px;
    bottom: calc(10px + env(safe-area-inset-bottom));
    z-index: 400;
    color: black;
  }
}
