:root {
  --ink: #f2efe9;
  --muted: #9aa1a9;
  --panel: rgba(14, 17, 21, 0.78);
  --line: rgba(255, 255, 255, 0.14);
  --bg: #0b0d10;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.45 "Inter", "Segoe UI", system-ui, sans-serif;
}

body.locked { overflow: hidden; }

.masthead {
  padding: 34px clamp(18px, 5vw, 56px) 10px;
}

.masthead h1 {
  margin: 0;
  font-size: clamp(20px, 3vw, 28px);
  font-weight: 600;
  letter-spacing: 0.01em;
}

.masthead h1 span { color: var(--muted); font-weight: 400; }

.masthead p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(215px, 1fr));
  gap: 10px;
  padding: 18px clamp(14px, 5vw, 56px) 40px;
}

.tile {
  position: relative;
  display: block;
  aspect-ratio: 4 / 3;
  overflow: hidden;
  border-radius: 10px;
  background: #15181d;
  color: inherit;
  text-decoration: none;
}

.tile img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform 0.35s ease, filter 0.35s ease;
}

.tile:hover img,
.tile:focus-visible img { transform: scale(1.03); filter: brightness(1.06); }

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

.tile .badge {
  position: absolute;
  left: 8px;
  bottom: 8px;
  padding: 2px 7px;
  border-radius: 999px;
  background: rgba(8, 10, 13, 0.72);
  color: #e9e5dc;
  font-size: 10.5px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.tile .badge.plain { color: #b9bfc6; }

.empty {
  padding: 20px clamp(18px, 5vw, 56px);
  color: var(--muted);
}

/* ---------- viewer ---------- */

.viewer {
  position: fixed;
  inset: 0;
  z-index: 10;
  background: #05070a;
}

.viewer[hidden] { display: none; }

#view {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  cursor: grab;
  touch-action: none;
}

#view:active { cursor: grabbing; }
#view[hidden] { display: none; }

#fallback {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

#fallback[hidden] { display: none; }

.hud { position: fixed; z-index: 12; pointer-events: none; }

.hud-top {
  top: max(18px, env(safe-area-inset-top));
  left: 22px;
}

.hud-top h2 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.9), 0 0 14px rgba(0, 0, 0, 0.7);
}

#source {
  margin: 2px 0 0;
  color: #d2d8df;
  font-size: 12px;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.9), 0 0 12px rgba(0, 0, 0, 0.75);
}

.hud-bottom {
  left: 50%;
  bottom: max(18px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
  backdrop-filter: blur(14px);
  pointer-events: auto;
  max-width: 96vw;
}

.ctl {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 11px;
  border-radius: 9px;
  color: var(--ink);
  font: inherit;
  font-size: 12.5px;
  white-space: nowrap;
}

label.ctl { gap: 10px; color: var(--muted); }

input[type="range"] {
  width: 96px;
  accent-color: #e8e2d6;
  cursor: pointer;
}

.btn {
  border: 1px solid transparent;
  background: transparent;
  cursor: pointer;
}

.btn:hover { background: rgba(255, 255, 255, 0.07); }

.btn[aria-pressed="true"] {
  border-color: var(--line);
  background: rgba(255, 255, 255, 0.12);
  font-weight: 600;
}

.btn[aria-pressed="true"]::before {
  content: "✓";
  margin-right: 5px;
  font-size: 11px;
}

.hint {
  bottom: max(74px, calc(env(safe-area-inset-bottom) + 74px));
  left: 50%;
  transform: translateX(-50%);
  margin: 0;
  padding: 5px 12px;
  border-radius: 999px;
  background: rgba(10, 12, 15, 0.55);
  color: #c9cfd6;
  font-size: 11.5px;
  opacity: 0.9;
  transition: opacity 0.8s;
}

.hint.gone { opacity: 0; }

.loading {
  position: fixed;
  inset: 0;
  z-index: 11;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 13px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  transition: opacity 0.25s;
}

.loading.gone { opacity: 0; pointer-events: none; }
.loading.error { color: #f0b3a8; text-transform: none; letter-spacing: 0; }

#sbsview {
  position: fixed;
  inset: 0;
  z-index: 13;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #000;
}

#sbsview[hidden] { display: none; }

.foot {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 18px;
  padding: 0 clamp(18px, 5vw, 56px) 34px;
  color: #6f767e;
  font-size: 11.5px;
}

@media (max-width: 720px) {
  .grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 7px; }
  .hud-bottom { flex-wrap: wrap; justify-content: center; }
  input[type="range"] { width: 70px; }
  .hint { display: none; }
}
