@font-face {
  font-family: "LowresPixel";
  src: url("assets/font/LowresPixel-Regular.otf") format("opentype");
}

@font-face {
  font-family: "Unixel";
  src: url("assets/font/unixel-Regular.ttf") format("truetype");
  unicode-range: U+0600-06FF, U+FB50-FDFF, U+FE70-FEFF;
}

/* ------------------ Base ------------------ */

:root {
  --bg-color: #0b0f1a;
  --text-color: #e6e6e6;
  --border-color: #e6e6e6;
}

body.light {
  --bg-color: #e6e6e6;
  --text-color: #0b0f1a;
  --border-color: #0b0f1a;
}

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

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg-color);
  font-family: "Unixel", "LowresPixel", monospace;
  user-select: none;
  -webkit-user-select: none;
}

body {
  display: flex;
  justify-content: center;
  align-items: center;
  transition: background-color 0.3s ease, color 0.3s ease;
}

body.is-copying-active,
body.is-copying-active * {
  pointer-events: none !important;
  cursor: not-allowed !important;
}

a {
  text-decoration: none;
}

/* ------------------ Frame ------------------ */

.frame {
  width: 96vw;
  height: 96dvh;
  border: 2px solid var(--border-color);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ------------------ Navbar ------------------ */

.navbar {
  border-bottom: 2px solid var(--border-color);
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  padding: 0.7rem 1.5rem;
  gap: 1rem;
}

.nav__left {
  display: flex;
  align-items: center;
  min-width: 0;
}

.nav__center {
  display: flex;
  justify-content: center;
  min-width: 0;
}

.nav__right {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.6rem;
  min-width: 0;
}

.navbar__title {
  margin: 0;
  font-size: 2rem;
  color: var(--text-color);
  white-space: nowrap;
}

/* ------------------ Search ------------------ */

.search__box {
  display: flex;
  width: 100%;
  max-width: 420px;
  min-width: 0;
}

.search__box input {
  flex: 1;
  background: transparent;
  border: 2px solid var(--border-color);
  border-right: none;
  color: var(--text-color);
  font-family: inherit;
  padding: 0.4rem 0.7rem;
  min-width: 0;
}

.search__button {
  background: transparent;
  border: 2px solid var(--border-color);
  color: var(--text-color);
  font-family: inherit;
  padding: 0.4rem 1rem;
  cursor: pointer;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  white-space: nowrap;
  flex-shrink: 0;
}

.search__button i {
  font-size: 0.9rem;
  line-height: 1;
}

.search__button:active {
  transform: scale(1.1);
}

input::placeholder {
  color: var(--text-color);
}

input:focus {
  outline: none;
}

/* ------------------ Theme Button ------------------ */

.theme__toggle {
  background: transparent;
  margin-left: 0;
  border: 2px solid var(--border-color);
  color: var(--text-color);
  font-family: inherit;
  padding: 0.3rem 0.6rem;
  cursor: pointer;
  line-height: 1;
  height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  white-space: nowrap;
  flex-shrink: 0;
}

.theme__toggle i {
  font-size: 0.9rem;
  line-height: 1;
  flex-shrink: 0;
}

.theme__toggle:active {
  transform: scale(1.1);
}

/* ------------------ Category Button ------------------ */

.category__toggle {
  background: transparent;
  margin-left: 0;
  border: 2px solid var(--border-color);
  color: var(--text-color);
  font-family: inherit;
  padding: 0.3rem 0.6rem;
  cursor: pointer;
  line-height: 1;
  width: 125px;
  min-width: 125px;
  height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  white-space: nowrap;
  overflow: hidden;
  flex-shrink: 0;
}

.category__toggle i {
  font-size: 0.9rem;
  line-height: 1;
  flex-shrink: 0;
}

.category__toggle span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.category__toggle:active {
  transform: scale(1.08);
}

/* ------------------ Navbar Favorite Button ------------------ */

.favorites__btn {
  background: transparent;
  border: 2px solid var(--border-color);
  color: var(--text-color);
  font-family: inherit;
  padding: 0;
  cursor: pointer;
  width: 36px;
  min-width: 36px;
  height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  flex-shrink: 0;
}

.favorites__btn i {
  font-size: 0.95rem;
  line-height: 1;
}

.favorites__btn:active {
  transform: scale(1.08);
}

/* ------------------ Gallery Area ------------------ */

.empty-state {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--text-color);
  font-size: 1rem;
  text-align: center;
  pointer-events: none;
}

.content__collections {
  position: relative;
}

.empty-state.is-hidden {
  display: none;
}

.content__collections {
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.content__box {
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-columns: repeat(auto-fit, 180px);
  grid-auto-rows: 180px;
  justify-content: center;
  align-content: center;
  gap: 20px;
  padding: 20px;
}

/* ------------------ Image Boxes ------------------ */

.box {
  width: 180px;
  height: 180px;
  display: flex;
  flex-direction: column;
  border: 2px solid var(--border-color);
  background: var(--bg-color);
  overflow: hidden;
  opacity: 0;
  transform: translateY(8px);
  animation: boxFadeIn 0.4s ease forwards;
}

@keyframes boxFadeIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ----- Image Section ----- */

.gallery-card__image {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px;
  overflow: hidden;
  position: relative;
  transition: transform 0.1s ease, filter 0.1s ease;
}

.gallery-card__image.is-pressed {
  transform: scale(0.95);
  filter: brightness(0.9);
}

.gallery-card__image:active {
  transform: scale(0.95);
  filter: brightness(0.9);
}

.gallery-card__image img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  will-change: auto;
}

/* ----- Meta Section ----- */

.gallery-card__meta {
  border-top: 2px solid var(--border-color);
  padding: 0.35rem 0.5rem;
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-color);
  color: var(--text-color);
  gap: 0.4rem;
  min-height: 42px;
}

.gallery-card__meta-text {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  min-width: 0;
  flex: 1;
}

.gallery-card__title {
  margin: 0;
  font-size: 0.7rem;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.gallery-card__category {
  font-size: 0.6rem;
  opacity: 0.8;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ------------------ Favorite Button ------------------ */

.fav-btn {
  position: static;
  background: transparent;
  border: none;
  color: var(--text-color);
  cursor: pointer;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  flex-shrink: 0;
  touch-action: manipulation;
}

.fav-btn i {
  font-size: 0.95rem;
  line-height: 1;
  pointer-events: none;
}

.fav-btn:active {
  transform: scale(0.85);
}

.fav-btn.is-active {
  color: #ff3b5c;
}

/* ------------------ Preview Modal ------------------ */

.preview-modal {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 999;
}

.preview-modal.is-open {
  display: flex;
}

.preview-modal__overlay {
  position: absolute;
  inset: 0;
  background: var(--bg-color);
  opacity: 0.95;
}

.preview-modal__container {
  position: relative;
  z-index: 2;
  width: 96vw;
  height: 96dvh;
  border: 2px solid var(--border-color);
  background: var(--bg-color);
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  align-items: stretch;
  justify-items: stretch;
  box-sizing: border-box;
  overflow: hidden;
}

.preview-modal__image {
  width: 100%;
  height: 100%;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  padding: 0 78px; 
  box-sizing: border-box;
}

.preview-modal__image img {
  width: 90%;
  height: 90%;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  user-select: none;
  -webkit-user-drag: none;
}

.preview-modal__meta {
  width: 100%;
  min-height: 58px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  text-align: center;
  color: var(--text-color);
  padding: 10px 56px;
  border-top: 2px solid var(--border-color);
}

.preview-modal__title {
  margin: 0;
  max-width: 100%;
  font-size: 1rem;
  line-height: 1.25;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.preview-modal__category {
  max-width: 100%;
  font-size: 0.75rem;
  line-height: 1.2;
  opacity: 0.7;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.preview-modal__close {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 42px;
  height: 42px;
  border: 2px solid var(--border-color);
  background: var(--bg-color);
  color: var(--text-color);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 10;
  border-radius: 0;
  -webkit-appearance: none;
  appearance: none;
}

.preview-modal__close:focus,
.preview-modal__close:focus-visible {
  outline: none;
  border-radius: 0;
}

.preview-modal__close i {
  font-size: 1.15rem;
  pointer-events: none;
}

.preview-modal__close:active {
  transform: scale(0.9);
}

.preview-modal__nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 46px;
  height: 46px;
  border: 2px solid var(--border-color);
  background: var(--bg-color);
  color: var(--text-color);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 3;
  transition: transform 0.1s ease;
}

.preview-modal__nav.prev {
  left: 16px;
}

.preview-modal__nav.next {
  right: 16px;
}

.preview-modal__nav i {
  font-size: 1.5rem;
  pointer-events: none;
}

.preview-modal__nav:active {
  transform: translateY(-50%) scale(0.9);
}

/* ------------------ Metadata Color Palette ------------------ */

.modal-palette-container {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
  margin-top: 8px;
  max-width: 100%;
}

.palette-chip {
  width: 24px;
  height: 24px;
  box-sizing: border-box;
  image-rendering: pixelated;
  cursor: pointer;
  transition: transform 0.1s ease, box-shadow 0.1s ease;
  position: relative;
}

.palette-chip:active {
  transform: scale(0.85);
}

.palette-chip.is-copied {
  animation: chipCopiedFeedback 0.4s ease-out;
}

/* ------------------ Toast Notification for Color Copy ------------------ */

.toast-panel {
  position: fixed;
  bottom: 30px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;
  pointer-events: none;
}

.copy-toast {
  background-color: var(--text-color);
  color: var(--bg-color);
  padding: 12px 20px;
  font-size: 14px;
  font-weight: bold;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.5s ease, visibility 0.5s ease, transform 0.5s ease;
}

.copy-toast.show {
  opacity: 1;
  visibility: visible;
  transform: translateY(-10px);
}

/* ------------------ Pagination ------------------ */

.pagination {
  min-height: 50px;
  display: grid;
  grid-template-columns: auto auto auto;
  justify-content: center;
  align-items: center;
  column-gap: 0.8rem;
  row-gap: 0;
  color: var(--text-color);
}

#prevBtn {
  grid-column: 1;
  grid-row: 1;
}

#pageNumber {
  grid-column: 2;
  grid-row: 1;
}

#nextBtn {
  grid-column: 3;
  grid-row: 1;
}

.page__btn {
  min-width: 82px;
  background: transparent;
  border: 2px solid var(--border-color);
  color: var(--text-color);
  font-family: inherit;
  font-size: 0.9rem;
  padding: 0.45rem 0.8rem;
  cursor: pointer;
  transition:
    transform 0.15s ease,
    opacity 0.15s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  line-height: 1;
}

.page__btn i {
  font-size: 0.85rem;
  line-height: 1;
}

.page__btn:active:not(:disabled) {
  transform: scale(1.08);
}

.page__btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

#pageNumber {
  min-width: 90px;
  display: inline-flex;
  justify-content: center;
  align-items: center;
  padding: 0.45rem 0.6rem;
  text-align: center;
  font-size: 1rem;
  font-weight: bold;
  color: var(--text-color);
}

.pagination.is-hidden {
  opacity: 0;
  pointer-events: none;
}

.gallery-info {
  min-height: 22px;
  display: flex;
  justify-content: center;
  align-items: center;
  margin-bottom: 8px;
  color: var(--text-color);
}

.image__count {
  font-size: 0.75rem;
  text-align: center;
}

/* ------------------ Footer ------------------ */

.footer {
  min-height: 45px;
  border-top: 2px solid var(--border-color);
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  column-gap: 1rem;
  padding: 0 1.3rem;
  color: var(--text-color);
  font-size: 0.8rem;
  background-color: var(--bg-color);
}

.footer p {
  margin: 0;
  min-width: 0;
  text-align: center;
  line-height: 1.3;
  color: var(--text-color);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.footer__logo {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.9rem;
}

.footer__logo:first-child {
  justify-self: start;
}

.footer__logo:last-child {
  justify-self: end;
}

.footer__logo a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.footer__logo i {
  font-size: 1.5rem;
  color: var(--text-color);
}

.footer__logo i:active {
  transform: scale(1.1);
}

/* ------------------ Mobile Gallery Layout ------------------ */

@media (max-width: 700px) {
  .footer {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: auto auto;
    row-gap: 0.25rem;
    min-height: 60px;
    padding: 0.45rem 1rem;
  }

  .footer__logo:first-child {
    grid-column: 1 / 2;
    grid-row: 1;
    justify-self: start;
  }

  .footer__logo:last-child {
    grid-column: 2 / 3;
    grid-row: 1;
    justify-self: end;
  }

  .footer p {
    grid-column: 1 / 3;
    grid-row: 2;
    justify-self: center;
    white-space: normal;
    overflow: visible;
    text-overflow: unset;
    font-size: 0.75rem;
    line-height: 1.3;
  }

  .toast-panel {
    bottom: 20px;
  }

  .copy-toast {
    padding: 10px 15px;
    font-size: 12px;
  }
}

@media (max-width: 650px) {
  .navbar {
    grid-template-columns: 1fr auto;
    grid-template-rows: auto auto;
    align-items: center;
    column-gap: 1rem;
    row-gap: 0.2rem;
    padding: 0.45rem 1rem;
  }

  .nav__left {
    grid-column: 1 / 2;
    grid-row: 1;
  }

  .nav__right {
    grid-column: 2 / 3;
    grid-row: 1;
    justify-self: end;
    gap: 0.45rem;
  }

  .category__toggle span {
    display: none;
  }

  .category__toggle {
    width: 36px;
    min-width: 36px;
    padding: 0;
    gap: 0;
  }

  .nav__center {
    grid-column: 1 / 3;
    grid-row: 2;
    margin-top: 0;
  }

  .search__box {
    width: 100%;
    max-width: none;
  }

  .search__box span {
    display: none;
  }

  .theme__toggle span {
    display: none;
  }

  .theme__toggle {
    width: 36px;
    min-width: 36px;
    height: 34px;
    padding: 0;
    gap: 0;
  }
}

@media (max-width: 600px) {
  .preview-modal__container {
    width: 95vw;
    height: 95dvh;
  }

  .preview-modal__image {
    padding: 0 54px;
  }

  .preview-modal__image img {
    width: 100%;
    height: 100%;
  }

  .preview-modal__meta {
    min-height: 52px;
  }

  .preview-modal__title {
    font-size: 0.9rem;
  }

  .preview-modal__category {
    font-size: 0.7rem;
  }

  .preview-modal__close {
    top: 10px;
    right: 10px;
    width: 38px;
    height: 38px;
  }

  .preview-modal__nav {
    width: 38px;
    height: 38px;
  }

  .preview-modal__nav.prev {
    left: 10px;
  }

  .preview-modal__nav.next {
    right: 10px;
  }

  .preview-modal__nav i {
    font-size: 1.25rem;
  }

  .modal-palette-container {
    gap: 4px;
    margin-top: 6px;
  }

  .palette-chip {
    width: 20px;
    height: 20px;
    border-width: 1px;
  }
}

@media (max-width: 430px) {
  .footer {
    grid-template-columns: 1fr;
    grid-template-rows: auto;
    min-height: 45px;
    padding: 0.5rem;
  }

  .footer p {
    grid-column: 1;
    grid-row: 1;
    font-size: 0.7rem;
    text-align: center;
  }

  .footer__logo {
    display: none;
  }

  .content__box {
    grid-template-columns: repeat(auto-fit, 180px);
    grid-auto-rows: 180px;
    justify-content: center;
    align-content: center;
    gap: 15px;
    padding: 10px;
  }

  .box {
    width: 180px;
    height: 180px;
  }
}

/* ------------------ Landscape Mode ------------------ */

@media (max-height: 480px) and (orientation: landscape) {
  .navbar {
    padding: 0.3rem 1rem;
    gap: 0.5rem;
  }

  .navbar__title {
    font-size: 1.5rem;
  }

  .search__box {
    max-width: 300px;
  }

  .footer {
    min-height: 34px;
    height: 34px;
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    grid-template-rows: 1fr;
    align-items: center;
    column-gap: 0.6rem;
    padding: 0 0.7rem;
    font-size: 0.65rem;
  }

  .footer__logo {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.45rem;
  }

  .footer__logo:first-child {
    grid-column: 1 / 2;
    grid-row: 1;
    justify-self: start;
  }

  .footer__logo:last-child {
    grid-column: 3 / 4;
    grid-row: 1;
    justify-self: end;
  }

  .footer__logo a {
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .footer__logo i {
    font-size: 1rem;
  }

  .footer p {
    grid-column: 2 / 3;
    grid-row: 1;
    justify-self: center;
    margin: 0;
    font-size: 0.6rem;
    line-height: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .content__box {
    grid-template-columns: repeat(auto-fit, 140px);
    grid-auto-rows: 140px;
    gap: 10px;
    padding: 10px;
  }

  .box {
    width: 140px;
    height: 140px;
  }

  .gallery-card__image {
    padding: 6px;
  }

  .gallery-card__meta {
    padding: 0.3rem 0.4rem;
  }

  .gallery-card__title {
    font-size: 0.6rem;
  }

  .gallery-card__category {
    font-size: 0.55rem;
  }

  .pagination {
    min-height: 50px;
    gap: 0.8rem;
  }

  .fav-btn {
    width: 24px;
    height: 24px;
    top: 4px;
    right: 4px;
  }

  .fav-btn i {
    font-size: 0.9rem;
  }

  .modal-palette-container {
    gap: 4px;
    margin-top: 4px;
  }

  .palette-chip {
    width: 18px;
    height: 18px;
    border-width: 1px;
  }
}