*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #0a0a0a;
  --surface: #161616;
  --surface2: #222;
  --accent: #e8e8e8;
  --muted: #666;
  --radius: 12px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--accent);
  font-family: var(--font);
  overflow: hidden;
  touch-action: pan-y;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

/* ── SEARCH SCREEN ── */
#search_screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  padding: 24px;
  gap: 32px;
}

.logo {
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: -0.5px;
  color: #fff;
}

.logo span {
  color: var(--muted);
  font-weight: 300;
}

.search_row {
  display: flex;
  width: 100%;
  max-width: 480px;
  gap: 8px;
}

#search_input {
  flex: 1;
  background: var(--surface);
  border: 1px solid #333;
  border-radius: var(--radius);
  color: var(--accent);
  font-size: 1rem;
  padding: 14px 16px;
  outline: none;
  transition: border-color 0.15s;
}

#search_input:focus {
  border-color: #555;
}

#search_input::placeholder {
  color: var(--muted);
}

#search_btn {
  background: var(--accent);
  color: var(--bg);
  border: none;
  border-radius: var(--radius);
  padding: 14px 20px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s;
}

#search_btn:active {
  opacity: 0.7;
}

.recents {
  width: 100%;
  max-width: 480px;
}

.recents_label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-bottom: 8px;
}

.recents_list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.recent_chip {
  background: var(--surface2);
  border: 1px solid #333;
  border-radius: 999px;
  color: var(--accent);
  font-size: 0.85rem;
  padding: 6px 14px;
  cursor: pointer;
  transition: background 0.1s;
}

.recent_chip:active {
  background: #333;
}

/* ── GALLERY SCREEN ── */
#gallery_screen {
  display: none;
  position: fixed;
  inset: 0;
  background: #000;
  overflow: hidden;
  touch-action: none;
}

#gallery_screen.active {
  display: flex;
  align-items: center;
  justify-content: center;
}

/* image container with slide transition */
#img_track {
  display: flex;
  width: 100%;
  height: 100%;
  transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
  will-change: transform;
}

.img_slide {
  flex: 0 0 100%;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.img_slide img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  display: block;
}

.img_slide .img_err {
  color: var(--muted);
  font-size: 0.9rem;
  text-align: center;
  padding: 24px;
}

/* overlay UI */
#gallery_overlay {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 10;
}

#gallery_top {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  background: linear-gradient(to bottom, rgba(0,0,0,0.6), transparent);
  pointer-events: all;
}

#back_btn {
  background: rgba(0,0,0,0.5);
  border: none;
  border-radius: 999px;
  color: #fff;
  font-size: 1.2rem;
  width: 40px;
  height: 40px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}

#back_btn:active {
  background: rgba(0,0,0,0.8);
}

#img_counter {
  font-size: 0.85rem;
  color: rgba(255,255,255,0.8);
  background: rgba(0,0,0,0.4);
  padding: 4px 10px;
  border-radius: 999px;
}

#fs_btn {
  background: rgba(0,0,0,0.5);
  border: none;
  border-radius: 999px;
  color: #fff;
  font-size: 1rem;
  width: 40px;
  height: 40px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}

#fs_btn:active {
  background: rgba(0,0,0,0.8);
}

/* desktop nav arrows */
#arrow_left, #arrow_right {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  background: rgba(0,0,0,0.45);
  border: none;
  border-radius: 999px;
  color: #fff;
  font-size: 1.4rem;
  width: 48px;
  height: 48px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: all;
  transition: background 0.15s, opacity 0.15s;
  opacity: 0;
}

#gallery_screen:hover #arrow_left,
#gallery_screen:hover #arrow_right {
  opacity: 1;
}

#arrow_left { left: 16px; }
#arrow_right { right: 16px; }

#arrow_left:active, #arrow_right:active {
  background: rgba(0,0,0,0.75);
}

/* loading indicator */
#loading_bar {
  position: fixed;
  top: 0;
  left: 0;
  height: 2px;
  background: #fff;
  width: 0%;
  transition: width 0.3s;
  z-index: 100;
  display: none;
}

#loading_bar.active {
  display: block;
}

/* error toast */
#toast {
  position: fixed;
  bottom: 32px;
  left: 50%;
  transform: translateX(-50%) translateY(60px);
  background: #c0392b;
  color: #fff;
  padding: 10px 20px;
  border-radius: 999px;
  font-size: 0.85rem;
  z-index: 200;
  transition: transform 0.25s;
  white-space: nowrap;
}

#toast.show {
  transform: translateX(-50%) translateY(0);
}

/* mobile: hide arrows */
@media (hover: none) {
  #arrow_left, #arrow_right { display: none; }
}
