:root {
  --bg: #111;
  --panel: #1b1b1b;
  --fg: #ddd;
  --dim: #888;
  --acc: #e0574f;
  --line: #333;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 13px/1.45 system-ui, sans-serif;
}

#app {
  display: grid;
  grid-template-columns: 230px 1fr;
  min-height: 100vh;
}

#side {
  background: var(--panel);
  border-right: 1px solid var(--line);
  padding: 12px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: auto;
}

#side h1 {
  font-size: 15px;
  margin: 0 0 4px;
}

#side .sub {
  color: var(--dim);
  margin: 0 0 12px;
  font-size: 12px;
}

.prob {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 14px;
}

.prob button {
  flex: 1 1 auto;
  min-width: 64px;
  padding: 6px 8px;
  background: #2a2a2a;
  color: var(--fg);
  border: 1px solid #444;
  cursor: pointer;
}

.prob button.on {
  background: var(--acc);
  border-color: var(--acc);
  color: #fff;
}

#main {
  padding: 14px 18px 40px;
}

#exportbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-bottom: 12px;
}

#exportbar button {
  padding: 6px 12px;
  background: #2a2a2a;
  color: var(--fg);
  border: 1px solid #444;
  cursor: pointer;
}

#exportbar button.primary {
  background: var(--acc);
  border-color: var(--acc);
  color: #fff;
}

#exportbar button:disabled {
  opacity: .4;
  cursor: default;
}

#exportbar .n { color: var(--dim); }

.hint {
  color: var(--dim);
  margin: 0 0 12px;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  color: var(--dim);
  margin-bottom: 10px;
  font-family: ui-monospace, monospace;
  font-size: 12px;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(420px, 1fr));
  gap: 16px;
}

.tile {
  position: relative;
  background: transparent;
}

.tile.sel .view {
  border-color: var(--acc);
  box-shadow: 0 0 0 2px var(--acc);
}

.tile .pick {
  position: absolute;
  top: 8px;
  left: 8px;
  width: 18px;
  height: 18px;
  accent-color: var(--acc);
  z-index: 2;
  cursor: pointer;
}

.view {
  width: 100%;
  aspect-ratio: 16 / 5;
  object-fit: contain;
  background: #0a0a0a;
  border: 1px solid var(--line);
  border-radius: 4px;
  cursor: zoom-in;
  display: block;
}

.cap {
  margin-top: 6px;
  font-family: ui-monospace, monospace;
  font-size: 12px;
  user-select: all;
}

.cap .tag { color: var(--dim); font-family: system-ui, sans-serif; }
.cap a {
  color: var(--acc);
  text-decoration: none;
  margin-left: 8px;
  cursor: pointer;
  font-family: system-ui, sans-serif;
  user-select: none;
}
.cap a:hover { text-decoration: underline; }

#status {
  color: var(--dim);
  margin: 20px 0;
}

#lightbox {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .88);
  z-index: 20;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

#lightbox.open { display: flex; }

#lightbox-stage {
  max-width: 96vw;
  max-height: 86vh;
  overflow: auto;
  display: flex;
  align-items: center;
  justify-content: center;
}

#lightbox img {
  max-width: min(96vw, 1600px);
  max-height: 86vh;
  object-fit: contain;
  border: 1px solid #444;
  background: #111;
  cursor: zoom-in;
  transition: transform .15s ease;
  transform-origin: center center;
}

#lightbox.zoomed #lightbox-stage {
  max-width: 100vw;
  max-height: 100vh;
  width: 100vw;
  height: 100vh;
}

#lightbox.zoomed img {
  max-width: none;
  max-height: none;
  width: auto;
  height: auto;
  min-width: 180vw;
  cursor: zoom-out;
  transform: scale(1);
}

#lightbox button {
  position: absolute;
  padding: 8px 12px;
  background: #2a2a2a;
  color: #fff;
  border: 1px solid #555;
  cursor: pointer;
  z-index: 2;
}

#lightbox-close {
  top: 16px;
  right: 16px;
}

#lightbox button.nav {
  top: 50%;
  transform: translateY(-50%);
  width: 44px;
  height: 64px;
  font-size: 28px;
  line-height: 1;
  padding: 0;
}

#lightbox-prev { left: 16px; }
#lightbox-next { right: 16px; }

#lightbox button.nav:disabled {
  opacity: .35;
  cursor: default;
}

#lightbox-meta {
  position: absolute;
  left: 50%;
  bottom: 14px;
  transform: translateX(-50%);
  color: #ccc;
  font: 12px/1.4 ui-monospace, monospace;
  background: rgba(0, 0, 0, .55);
  padding: 4px 10px;
  border-radius: 4px;
  pointer-events: none;
  max-width: 90vw;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

@media (max-width: 800px) {
  #app { grid-template-columns: 1fr; }
  #side { height: auto; position: static; }
  .grid { grid-template-columns: 1fr; }
}
