/* Dark only. No light variant, no toggle. */
:root {
  --bg: #121212;
  --raised: #1e1e1e;
  --line: #2c2c2c;
  --text: #e8e8e8;
  --dim: #9a9a9a;
  --accent: #8ab4f8;
  --bad: #f28b82;

  --rail-w: 92px;
  --topbar-h: 52px;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 "Segoe UI", -apple-system, Roboto, Helvetica, Arial, sans-serif;
  overflow: hidden;
}

body.lb-open { overflow: hidden; }

h1 { font-size: 1.15rem; font-weight: 600; margin: 0; }

code, pre {
  font-family: Consolas, "Courier New", monospace;
  font-size: .88em;
}

button {
  font: inherit;
  color: var(--text);
  background: #2a2a2a;
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: .4rem .9rem;
  cursor: pointer;
}

button:hover { background: #343434; }
button:disabled { opacity: .5; cursor: default; }

.ghost {
  background: transparent;
  color: var(--dim);
}

.screen[hidden] { display: none; }

/* ----------------------------------------------------------- setup */

.setup, .failure {
  max-width: 34rem;
  margin: 0 auto;
  padding: 3rem 1.25rem;
  height: 100%;
  overflow-y: auto;
}

.lede { color: var(--dim); margin: .5rem 0 2rem; }

label {
  display: block;
  margin: 1rem 0 .3rem;
  font-size: .82rem;
  font-weight: 600;
}

.opt { font-weight: 400; color: var(--dim); }

input, textarea {
  display: block;
  width: 100%;
  padding: .5rem .6rem;
  color: var(--text);
  background: var(--raised);
  border: 1px solid var(--line);
  border-radius: 4px;
  font: inherit;
}

textarea {
  resize: vertical;
  font-family: Consolas, "Courier New", monospace;
  font-size: .85rem;
}

input:focus, textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
}

.pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.pair label { margin-top: 1rem; }

.warn {
  margin: 1.5rem 0;
  padding: .7rem .85rem;
  border-left: 3px solid #6b5b1f;
  background: #201d13;
  color: var(--dim);
  font-size: .85rem;
}

.error {
  margin: 1rem 0;
  padding: .7rem .85rem;
  border-left: 3px solid var(--bad);
  background: #241717;
  color: var(--bad);
  font-size: .88rem;
}

#setup-submit {
  margin-top: .5rem;
  background: #1a3a63;
  border-color: #2b5c8a;
  font-weight: 600;
}

/* --------------------------------------------------------- failure */

.failure pre {
  padding: .8rem;
  overflow-x: auto;
  background: var(--raised);
  border: 1px solid var(--line);
  border-radius: 4px;
}

.failure ol { color: var(--dim); }
.failure li { margin: .4rem 0; }

/* --------------------------------------------------------- gallery */

.gallery {
  /* Containing block for the absolutely positioned rail. */
  position: relative;
  display: grid;
  /* search-summary and chips are grid items too (rail is absolutely
     positioned, so it opts out); each collapses to 0 height via the "auto"
     track when its [hidden] leaves it with no box, and the scroller keeps
     the 1fr track regardless of how many of the middle rows are showing. */
  grid-template-rows: var(--topbar-h) auto auto 1fr;
  height: 100%;
}

.topbar {
  display: flex;
  gap: 1rem;
  align-items: center;
  padding: 0 1rem;
  border-bottom: 1px solid var(--line);
  background: var(--bg);
}

.status {
  flex: 1;
  color: var(--dim);
  font-size: .85rem;
}

.status.busy::after {
  content: "";
  display: inline-block;
  width: .6em;
  height: .6em;
  margin-left: .5em;
  border: 2px solid var(--dim);
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin .7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.scroller {
  position: relative;
  overflow-y: auto;
  scrollbar-width: none;
  overflow-x: hidden;
  padding: 0 var(--rail-w) 4rem 1rem;
}

.scroller::-webkit-scrollbar { width: 0; height: 0; }

.section { margin-bottom: 1.5rem; }

.section-header {
  position: sticky;
  top: 0;
  z-index: 2;
  margin: 0 0 .6rem;
  padding: .7rem 0 .4rem;
  background: linear-gradient(var(--bg) 70%, transparent);
  font-size: .95rem;
  font-weight: 600;
}

.row {
  display: flex;
  margin-bottom: 4px;
}

.tile {
  position: relative;
  padding: 0;
  border: 0;
  border-radius: 2px;
  overflow: hidden;
  background: var(--raised);
  cursor: pointer;
  flex: 0 0 auto;
}

.tile img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  transition: opacity .18s ease, transform .12s ease;
}

.tile.loaded img { opacity: 1; }

.tile:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Play badge. The thumbnail itself was a plain image like any other. */
.tile-video::after {
  content: "";
  position: absolute;
  right: 8px;
  bottom: 8px;
  width: 0;
  height: 0;
  border-left: 11px solid rgba(255, 255, 255, .92);
  border-top: 7px solid transparent;
  border-bottom: 7px solid transparent;
  filter: drop-shadow(0 0 2px rgba(0, 0, 0, .8));
  pointer-events: none;
}

/* Selection. The checkbox is a span -- see the note in grid.ts. */
.tile-check {
  position: absolute;
  top: 6px;
  left: 6px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, .9);
  background: rgba(0, 0, 0, .35);
  filter: drop-shadow(0 0 2px rgba(0, 0, 0, .8));
  opacity: 0;
  /* Invisible must also mean unclickable, or the corner of every tile
     silently toggles selection instead of opening the photo. */
  pointer-events: none;
  transition: opacity .12s ease;
}

.tile:hover .tile-check,
.tile:focus-visible .tile-check,
.grid.selecting .tile-check {
  opacity: 1;
  pointer-events: auto;
}

.tile.selected .tile-check {
  background: var(--accent);
  border-color: var(--accent);
}

.tile.selected .tile-check::after {
  content: "";
  position: absolute;
  left: 6px;
  top: 2px;
  width: 4px;
  height: 9px;
  border: solid #121212;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

/* Inset the image, not the tile: the row geometry must not move. */
.tile.selected img { transform: scale(.86); }

.selbar {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  z-index: 9;
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: .5rem .6rem .5rem 1rem;
  border-radius: 999px;
  background: var(--raised);
  border: 1px solid var(--line);
  box-shadow: 0 6px 24px rgba(0, 0, 0, .55);
}

.selbar[hidden] { display: none; }
.selbar-count { font-size: .9rem; }

.danger { color: var(--bad); border-color: var(--bad); }
.danger:hover { background: var(--bad); color: #121212; }

.tile.broken {
  background: repeating-linear-gradient(
    -45deg, #1e1e1e, #1e1e1e 8px, #262626 8px, #262626 16px);
}

/* ------------------------------------------------------------ rail */

.rail {
  position: absolute;
  top: var(--topbar-h);
  right: 0;
  bottom: 0;
  width: var(--rail-w);
  /* Above the sticky section headers (z-index 2), which would otherwise
     paint their background over the year labels. */
  z-index: 4;
  touch-action: none;
  user-select: none;
}

.rail-year {
  position: absolute;
  right: 36px;
  transform: translateY(-50%);
  padding: 2px 8px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: #b9b9b9;
  font-size: .8rem;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  /* Insurance: keeps the digits legible if anything light ends up behind. */
  text-shadow: 0 1px 3px rgba(0, 0, 0, .9);
}

.rail-year:hover { color: var(--text); background: #262626; }

.rail-year.active { text-shadow: none; }

.rail-year.active {
  color: #0b1a2b;
  background: var(--accent);
  font-weight: 600;
}

/* Draggable scroll thumb: a half-disc against the right edge. */
.rail-thumb {
  position: absolute;
  right: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  width: 30px;
  height: 44px;
  border-radius: 22px 0 0 22px;
  background: #4a5563;
  cursor: grab;
  touch-action: none;
}

.rail-thumb:hover { background: #57636f; }
.rail-thumb.dragging { background: var(--accent); cursor: grabbing; }

.rail-arrow {
  width: 0;
  height: 0;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
}

.rail-arrow.up { border-bottom: 6px solid #fff; }
.rail-arrow.down { border-top: 6px solid #fff; }
.rail-thumb.dragging .rail-arrow.up { border-bottom-color: #0b1a2b; }
.rail-thumb.dragging .rail-arrow.down { border-top-color: #0b1a2b; }

/* Bubble naming the month under the thumb while dragging. */
.rail-bubble {
  position: absolute;
  right: 38px;
  transform: translateY(-50%);
  padding: 6px 14px;
  border-radius: 16px;
  background: #4a5563;
  color: #fff;
  font-size: .9rem;
  font-weight: 600;
  white-space: nowrap;
  pointer-events: none;
}

.rail-bubble[hidden] { display: none; }

/* -------------------------------------------------------- lightbox */

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: 64px 1fr 64px;
  grid-template-rows: 1fr auto;
  align-items: center;
  background: rgba(0, 0, 0, .94);
}

.lightbox[hidden] { display: none; }

.lb-stage {
  grid-column: 2;
  grid-row: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  min-height: 0;
}

.lb-media {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.lb-nav, .lb-close, .lb-delete {
  background: transparent;
  border: 0;
  color: #cfcfcf;
  font-size: 2.2rem;
  line-height: 1;
}

.lb-nav:hover, .lb-close:hover { background: transparent; color: #fff; }
.lb-delete:hover { background: transparent; color: var(--bad); }

.lb-prev { grid-column: 1; grid-row: 1; }
.lb-next { grid-column: 3; grid-row: 1; }

.lb-close {
  position: absolute;
  top: 8px;
  right: 14px;
  font-size: 2rem;
}

.lb-delete {
  position: absolute;
  top: 12px;
  right: 70px;
  font-size: 1.4rem;
}

.lb-caption {
  grid-column: 1 / -1;
  grid-row: 2;
  padding: .8rem;
  text-align: center;
  color: var(--dim);
  font-size: .82rem;
  word-break: break-all;
}

.lb-spinner {
  width: 28px;
  height: 28px;
  border: 3px solid #555;
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin .7s linear infinite;
}

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

.search {
  display: flex;
  align-items: center;
  gap: .25rem;
  flex: 1 1 auto;
  max-width: 24rem;
}

.search input {
  width: 100%;
  padding: .35rem .6rem;
  border-radius: 999px;
}

.search-summary {
  padding: .5rem var(--rail-w) 0 1rem;
  opacity: .7;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
  padding: .5rem var(--rail-w) .5rem 1rem;
}

.chips button {
  padding: .3rem .75rem;
  border-radius: 999px;
  cursor: pointer;
}

.hint {
  font-size: .85em;
  opacity: .7;
}
