@font-face {
  font-family: "HackGenConsole";
  src: url("/fonts/HackGenConsole-Regular.ttf") format("truetype");
  font-display: swap;
}

:root {
  color-scheme: dark;
  --bg: #090909;
  --surface: #121212;
  --ink: #f7f7f5;
  --muted: #a5a5a2;
  --line: rgba(255, 255, 255, .14);
  --accent: #ff8fb3;
}

* { box-sizing: border-box; }

html { background: var(--bg); }

body {
  min-width: 280px;
  margin: 0;
  overflow-x: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: "HackGenConsole", "Yu Gothic", monospace;
}

button, input { font: inherit; }
button { color: inherit; }

button:focus-visible,
a:focus-visible,
input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 4px;
}

.viewer { min-height: 100svh; }

.viewer-header {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  min-height: 76px;
  gap: 20px;
  padding: 16px clamp(18px, 4vw, 64px);
  border-bottom: 1px solid var(--line);
}

.viewer-header h1 {
  margin: 0;
  font-size: clamp(16px, 2vw, 22px);
  font-weight: 400;
}

.back-link,
.text-button {
  border: 0;
  background: none;
  color: var(--muted);
  text-decoration: none;
  cursor: pointer;
}

.back-link:hover,
.text-button:hover { color: var(--accent); }
.viewer-header .text-button { justify-self: end; }

.stage {
  position: relative;
  display: grid;
  grid-template-columns: clamp(48px, 7vw, 104px) minmax(0, 1fr) clamp(48px, 7vw, 104px);
  align-items: stretch;
  min-height: calc(100svh - 152px);
}

.stage figure {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  align-items: center;
  min-width: 0;
  min-height: 0;
  margin: 0;
  padding: clamp(18px, 4vw, 54px) 0 16px;
}

.stage img {
  display: block;
  width: 100%;
  height: 100%;
  max-height: calc(100svh - 220px);
  object-fit: contain;
  opacity: 0;
  transition: opacity .25s ease;
}

.stage img.is-loaded { opacity: 1; }

.stage figcaption {
  padding-top: 15px;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

.stage-arrow {
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: clamp(24px, 3vw, 40px);
}

.stage-arrow:hover { color: var(--accent); }

.page-controls {
  display: flex;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
  min-height: 76px;
  gap: clamp(18px, 4vw, 48px);
  padding: 16px 20px;
  border-block: 1px solid var(--line);
}

.page-controls form {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
}

.page-controls input {
  width: 70px;
  border: 1px solid var(--line);
  border-radius: 0;
  background: var(--surface);
  color: var(--ink);
  padding: 8px 10px;
  text-align: right;
}

.thumbnail-panel {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 2px;
  padding: 2px;
}

.thumbnail-panel[hidden] { display: none; }

.thumbnail {
  position: relative;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  border: 0;
  padding: 0;
  background: #171717;
  cursor: pointer;
}

.thumbnail img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: .7;
  transition: opacity .18s ease, transform .3s ease;
}

.thumbnail:hover img,
.thumbnail.is-current img { opacity: 1; }
.thumbnail:hover img { transform: scale(1.025); }

.thumbnail.is-current::after {
  content: "";
  position: absolute;
  inset: 0;
  border: 3px solid var(--accent);
  pointer-events: none;
}

.slideshow {
  position: fixed;
  z-index: 100;
  inset: 0;
  display: grid;
  place-items: center;
  overflow: hidden;
  background: #000;
  opacity: 0;
  visibility: hidden;
  transition: opacity .35s ease, visibility .35s;
}

.slideshow.is-visible {
  opacity: 1;
  visibility: visible;
}

.slideshow-backdrop {
  position: absolute;
  inset: -30px;
  background-position: center;
  background-size: cover;
  filter: blur(28px) brightness(.28);
  opacity: .65;
  transform: scale(1.08);
}

.slideshow > img {
  position: relative;
  z-index: 1;
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: center center;
  align-self: center;
  justify-self: center;
  opacity: 0;
  transition: opacity .7s ease;
}

.slideshow > img.is-loaded { opacity: 1; }

.slideshow-topbar,
.slideshow-actions,
.exit-hint {
  position: absolute;
  z-index: 2;
}

.slideshow-topbar {
  top: 0;
  left: 0;
  right: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  gap: 16px;
  padding: max(14px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 14px max(16px, env(safe-area-inset-left));
  background: linear-gradient(#0009, transparent);
}

.slideshow-brand {
  overflow: hidden;
  font-size: clamp(13px, 1.4vw, 17px);
  white-space: nowrap;
  text-overflow: ellipsis;
  text-shadow: 0 1px 8px #000;
}

.icon-button,
.round-button,
.exit-hint {
  border: 1px solid rgba(255, 255, 255, .42);
  background: rgba(0, 0, 0, .44);
  backdrop-filter: blur(12px);
  cursor: pointer;
}

.icon-button {
  display: grid;
  place-items: center;
  justify-self: end;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  padding: 0;
}

.icon-button svg {
  width: 17px;
  height: 17px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: square;
  stroke-width: 1.8;
}

.fullscreen-exit,
.icon-button.is-fullscreen .fullscreen-enter { display: none; }

.icon-button.is-fullscreen .fullscreen-exit { display: block; }

.slideshow-status {
  position: static;
  display: flex;
  align-items: center;
  justify-self: center;
  gap: 10px;
  color: #fffc;
  font-size: 11px;
  white-space: nowrap;
}

.slideshow-progress {
  width: min(18vw, 180px);
  height: 2px;
  overflow: hidden;
  background: #fff4;
}

.slideshow-progress i {
  display: block;
  width: 100%;
  height: 100%;
  background: var(--accent);
  transform: scaleX(0);
  transform-origin: left;
}

.slideshow-progress i.is-running {
  animation: progress 6s linear forwards;
}

@keyframes progress { to { transform: scaleX(1); } }

.slideshow-actions {
  left: 50%;
  bottom: max(22px, env(safe-area-inset-bottom));
  display: flex;
  align-items: center;
  gap: 14px;
  transform: translateX(-50%);
}

.round-button {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  font-size: 17px;
}

.round-button-main {
  width: 46px;
  height: 46px;
  border-color: var(--accent);
  background: rgba(255, 143, 179, .2);
}

.exit-hint {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  right: max(24px, env(safe-area-inset-right));
  bottom: max(22px, env(safe-area-inset-bottom));
  min-height: 40px;
  border-radius: 999px;
  padding: 8px 12px;
  color: #fffd;
  font-size: 11px;
}

.icon-button,
.round-button,
.exit-hint {
  opacity: .62;
  transition: opacity .2s ease, border-color .2s ease, background-color .2s ease;
}

.icon-button:hover,
.icon-button:focus-visible,
.round-button:hover,
.round-button:focus-visible,
.exit-hint:hover,
.exit-hint:focus-visible {
  opacity: 1;
}

.slideshow-topbar,
.slideshow-actions,
.exit-hint {
  transition: opacity .25s ease;
}

.slideshow.is-ui-hidden { cursor: none; }

.slideshow.is-ui-hidden .slideshow-topbar,
.slideshow.is-ui-hidden .slideshow-actions,
.slideshow.is-ui-hidden .exit-hint {
  opacity: 0;
  pointer-events: none;
}

kbd {
  padding: 2px 5px;
  border: 1px solid #ffffff55;
  border-radius: 3px;
  font-family: inherit;
}

noscript {
  display: block;
  padding: 30px;
  text-align: center;
}

@media (max-width: 650px) {
  .viewer-header {
    grid-template-columns: 1fr auto;
    min-height: 64px;
  }
  .viewer-header h1 { display: none; }
  .stage {
    grid-template-columns: 44px minmax(0, 1fr) 44px;
    min-height: calc(100svh - 140px);
  }
  .stage figure { padding-top: 12px; }
  .stage img { max-height: calc(100svh - 198px); }
  .page-controls { gap: 18px; }
  #previous-bottom, #next-bottom { display: none; }
  .thumbnail-panel { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .slideshow-brand { visibility: hidden; }
  .slideshow-progress { width: min(28vw, 110px); }
  .exit-hint {
    left: auto;
    right: max(12px, env(safe-area-inset-right));
    transform: none;
    white-space: nowrap;
  }
  .exit-hint span { display: none; }
  .slideshow-actions { bottom: max(22px, env(safe-area-inset-bottom)); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    scroll-behavior: auto !important;
    transition-duration: .01ms !important;
  }
  .thumbnail img { transform: none !important; }
}
