:root {
  --bg: #0d0d0c;
  --panel: #171614;
  --line: #2f2c28;
  --text: #f2efe8;
  --muted: #b3ada3;
  --accent: #e3ab4f;
  --danger: #ff8f7a;
  --ctrl: clamp(56px, 5.2vw, 88px);
  --gap: clamp(12px, 1.6vw, 28px);
  --radius: 12px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}

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

:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 3px;
}

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* Viewer */

.viewer {
  position: fixed;
  inset: 0;
  user-select: none;
  -webkit-user-select: none;
}

.viewer[data-controls="hidden"] { cursor: none; }

.stage {
  position: absolute;
  inset: 0;
  overflow: hidden;
  touch-action: none;
}

/* Single layout: only the first frame is used and fills the screen. */
.frame {
  position: relative;
  overflow: hidden;
  background: var(--bg);
}

.frame:not(:first-child) { display: none; }

.viewer[data-layout="single"] .frame:first-child {
  position: absolute;
  inset: 0;
}

/* Grid layout: 2x2, thin dark gutters so each photo reads as its own tile. */
.viewer[data-layout="grid"] .stage {
  display: grid;
  grid-template: 1fr 1fr / 1fr 1fr;
  gap: 4px;
}

.viewer[data-layout="grid"] .frame { display: block; }
.viewer[data-layout="grid"] .progress { visibility: hidden; }

.frame.is-error::after {
  content: "Foto tidak bisa dimuat";
  position: absolute;
  left: 50%;
  bottom: 16px;
  translate: -50% 0;
  padding: 8px 14px;
  border-radius: 8px;
  background: rgba(13, 13, 12, 0.8);
  font-size: 15px;
  white-space: nowrap;
}

.slide {
  position: absolute;
  inset: 0;
  margin: 0;
  opacity: 0;
  transition: opacity 900ms ease;
}

.slide.is-active { opacity: 1; }

/* Low-res copy of the same photo fills the letterbox bars on a 16:9 TV. */
.slide-bg {
  position: absolute;
  inset: -10%;
  background: center / cover no-repeat;
  filter: blur(28px) brightness(0.4);
}

.slide img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

/* Controls */

.ctrl {
  display: inline-grid;
  place-items: center;
  width: var(--ctrl);
  height: var(--ctrl);
  padding: 0;
  border: 0;
  border-radius: var(--radius);
  background: rgba(13, 13, 12, 0.62);
  color: var(--text);
  cursor: pointer;
  flex: none;
}

.ctrl svg { width: 48%; height: 48%; fill: currentColor; }
.ctrl:active { background: rgba(13, 13, 12, 0.85); }

@media (hover: hover) {
  .ctrl:hover { background: rgba(13, 13, 12, 0.85); }
}

.icon-exit, .icon-pause, .icon-single { display: none; }
#layoutBtn[aria-pressed="true"] .icon-grid { display: none; }
#layoutBtn[aria-pressed="true"] .icon-single { display: block; }
#fullscreenBtn[aria-pressed="true"] .icon-enter,
#playBtn[aria-pressed="true"] .icon-play { display: none; }
#fullscreenBtn[aria-pressed="true"] .icon-exit,
#playBtn[aria-pressed="true"] .icon-pause { display: block; }

.topbar, .bottombar, .nav {
  transition: opacity 300ms ease;
}

.viewer[data-controls="hidden"] .topbar,
.viewer[data-controls="hidden"] .bottombar,
.viewer[data-controls="hidden"] .nav {
  opacity: 0;
  pointer-events: none;
}

.topbar {
  position: absolute;
  inset: 0 0 auto 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--gap);
  padding: var(--gap);
  padding-top: max(var(--gap), env(safe-area-inset-top));
  background: linear-gradient(rgba(0, 0, 0, 0.55), transparent);
}

.topbar-actions { display: flex; gap: calc(var(--gap) / 1.5); }

.counter {
  margin: 0;
  font-size: clamp(16px, 1.4vw, 24px);
  font-variant-numeric: tabular-nums;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.8);
}

.nav {
  position: absolute;
  top: 50%;
  translate: 0 -50%;
  height: calc(var(--ctrl) * 1.6);
}

.nav-prev { left: var(--gap); }
.nav-next { right: var(--gap); }

.bottombar {
  position: absolute;
  inset: auto 0 0 0;
  padding: var(--gap);
  padding-bottom: max(var(--gap), env(safe-area-inset-bottom));
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.7));
}

.bottombar-row {
  display: flex;
  align-items: center;
  gap: var(--gap);
}

/* Autoplay countdown: the only place the accent appears outside focus states. */
.progress {
  height: 4px;
  margin-bottom: var(--gap);
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.18);
  overflow: hidden;
}

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

.progress-fill.is-running {
  animation: progress var(--duration, 8s) linear forwards;
}

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

.thumbs {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  scrollbar-width: none;
  padding: 4px;
  min-width: 0;
  flex: 1;
}

.thumbs::-webkit-scrollbar { display: none; }

.thumb {
  flex: none;
  width: calc(var(--ctrl) * 1.5);
  height: var(--ctrl);
  padding: 0;
  border: 2px solid transparent;
  border-radius: 8px;
  background: #222;
  overflow: hidden;
  cursor: pointer;
  opacity: 0.6;
}

.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb[aria-current="true"] { border-color: var(--accent); opacity: 1; }

/* Status: loading, empty, error */

.status {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 14px;
  padding: 32px;
  text-align: center;
  pointer-events: none;
}

.status[hidden] { display: none; }
.status .btn { pointer-events: auto; margin-top: 8px; }

.status.is-overlay {
  inset: auto 0 calc(var(--ctrl) * 2.4) 0;
  place-content: end center;
}

.status.is-overlay .status-title {
  padding: 10px 16px;
  border-radius: 8px;
  background: rgba(13, 13, 12, 0.8);
  font-size: 16px;
}

.status-title { margin: 0; font-size: clamp(20px, 2vw, 32px); }
.status-detail { margin: 0; max-width: 60ch; color: var(--muted); font-size: clamp(15px, 1.2vw, 20px); line-height: 1.5; }
.status-detail:empty { display: none; }

/* Setup dialog */

.setup {
  width: min(600px, calc(100vw - 32px));
  max-height: calc(100dvh - 32px);
  padding: clamp(20px, 3vw, 36px);
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--panel);
  color: var(--text);
}

.setup::backdrop { background: rgba(0, 0, 0, 0.72); }

.setup h1 { margin: 0 0 20px; font-size: 26px; font-weight: 650; }

.field { display: grid; gap: 8px; margin-bottom: 16px; }
.field > span { font-size: 15px; color: var(--muted); }

.field input, .field textarea {
  width: 100%;
  min-height: 52px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #0f0f0e;
  font-size: 17px;
}

.field textarea { resize: vertical; line-height: 1.5; }

.hint { margin: -4px 0 20px; color: var(--muted); font-size: 14px; line-height: 1.55; }
.hint strong { color: var(--text); font-weight: 600; }

.field-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 16px;
  align-items: end;
}

.check {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 52px;
  margin-bottom: 16px;
  cursor: pointer;
}

.check input { width: 24px; height: 24px; accent-color: var(--accent); }

.form-error {
  margin: 0 0 16px;
  padding: 12px 14px;
  border-radius: 10px;
  background: rgba(255, 143, 122, 0.12);
  color: var(--danger);
  line-height: 1.5;
}

.form-error[hidden] { display: none; }

.actions { display: flex; justify-content: flex-end; gap: 12px; margin-top: 8px; }

.btn {
  min-height: 52px;
  padding: 0 22px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: transparent;
  cursor: pointer;
  font-weight: 600;
}

.btn-primary { border-color: var(--accent); background: var(--accent); color: #1a1408; }
.btn[hidden] { display: none; }

@media (max-width: 520px) {
  .field-row { grid-template-columns: 1fr; gap: 0; }
  .actions .btn { flex: 1; }
  .nav { height: var(--ctrl); }
}

@media (prefers-reduced-motion: reduce) {
  .slide, .topbar, .bottombar, .nav { transition: none; }
}
