:root {
  --bg: #17212b;
  --text: #e9edf2;
  --hint: #8f9aa8;
  --link: #5aa7e8;
  --card: #232e3c;
  --btn: #5aa7e8;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

/* атрибут hidden должен побеждать display из правил ниже */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.35 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior-y: none;
}

body.locked { overflow: hidden; }

.bar {
  position: sticky;
  top: 0;
  z-index: 10;
  padding: 12px 14px 10px;
  background: color-mix(in srgb, var(--bg) 92%, black);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid color-mix(in srgb, var(--text) 10%, transparent);
}

.title {
  font-size: 16px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sub {
  margin-top: 2px;
  font-size: 13px;
  color: var(--hint);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#content { padding: 12px 14px calc(20px + env(safe-area-inset-bottom)); }

/* состояния */
.state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 40px 0;
  color: var(--hint);
  font-size: 14px;
  text-align: center;
}

.spinner {
  width: 26px;
  height: 26px;
  border: 3px solid color-mix(in srgb, var(--hint) 35%, transparent);
  border-top-color: var(--link);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}

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

.btn {
  padding: 10px 18px;
  border: 0;
  border-radius: 10px;
  background: var(--btn);
  color: #fff;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
}

/* сетка */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(104px, 1fr));
  gap: 6px;
}

.grid img {
  width: 100%;
  aspect-ratio: 3 / 4;
  object-fit: cover;
  border-radius: 8px;
  background: var(--card);
  display: block;
  cursor: zoom-in;
}

.grid img.broken { opacity: .2; }

/* просмотрщик */
.viewer {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(0, 0, 0, .96);
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: pan-y;
}

.viewer[hidden] { display: none; }

.viewer img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  user-select: none;
}

.close {
  position: absolute;
  top: calc(10px + env(safe-area-inset-top));
  right: 12px;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, .12);
  color: #fff;
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
}

.counter {
  position: absolute;
  bottom: calc(16px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  padding: 6px 12px;
  border-radius: 100px;
  background: rgba(0, 0, 0, .55);
  color: #fff;
  font-size: 13px;
}
