:root {
  color-scheme: light dark;

  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-strong: #f0f3f5;
  --border: #dfe4e8;
  --text: #1a1d21;
  --muted: #68727f;
  --accent: #2368d1;
  --accent-soft: #e4eefc;
  --green: #21845b;
  --amber: #b76912;
  --red: #c13f3a;
  --shadow: 0 16px 40px rgba(28, 34, 42, 0.12);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111316;
    --surface: #1b1f24;
    --surface-strong: #232930;
    --border: #303741;
    --text: #ecf0f4;
    --muted: #9aa4af;
    --accent: #73a7ff;
    --accent-soft: #1f324d;
    --green: #62c98d;
    --amber: #f0b260;
    --red: #f0716b;
    --shadow: 0 16px 40px rgba(0, 0, 0, 0.36);
  }
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
}

button,
input,
select {
  font: inherit;
}

button,
a,
input,
select {
  -webkit-tap-highlight-color: transparent;
}

.hidden {
  display: none !important;
}

.app {
  margin: 0 auto;
  max-width: 1440px;
  min-height: 100dvh;
  padding: 20px;
  padding-top: calc(20px + env(safe-area-inset-top, 0px));
  padding-right: calc(20px + env(safe-area-inset-right, 0px));
  padding-bottom: calc(28px + env(safe-area-inset-bottom, 0px));
  padding-left: calc(20px + env(safe-area-inset-left, 0px));
}

.topbar {
  align-items: center;
  display: grid;
  gap: 12px;
  grid-template-columns: minmax(170px, 1fr) minmax(220px, 360px) auto;
  position: sticky;
  top: 0;
  z-index: 20;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  border-bottom: 1px solid color-mix(in srgb, var(--border) 72%, transparent);
  margin: -20px -20px 0;
  padding: 16px 20px 14px;
  padding-top: calc(16px + env(safe-area-inset-top, 0px));
  backdrop-filter: blur(18px);
}

.brand {
  align-items: baseline;
  display: flex;
  gap: 10px;
  min-width: 0;
}

.brand h1 {
  font-size: 18px;
  font-weight: 700;
  line-height: 1.2;
  margin: 0;
}

.summary {
  color: var(--muted);
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.search {
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  display: flex;
  gap: 8px;
  min-height: 40px;
  min-width: 0;
  padding: 0 12px;
}

.search:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent);
}

.search__icon {
  color: var(--muted);
  flex: 0 0 auto;
  font-size: 18px;
  line-height: 1;
}

.search input {
  appearance: none;
  background: transparent;
  border: 0;
  color: var(--text);
  flex: 1;
  font-size: 16px;
  min-width: 0;
  outline: 0;
  width: 100%;
}

.toolbar {
  align-items: center;
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.select,
.button,
.density,
.icon-button,
.folder-chip {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
}

.select {
  border-radius: 8px;
  min-height: 40px;
  outline: 0;
  padding: 0 34px 0 12px;
}

.select:focus {
  border-color: var(--accent);
}

.button {
  border-radius: 8px;
  cursor: pointer;
  font-weight: 650;
  min-height: 40px;
  padding: 0 14px;
}

.button:hover {
  border-color: color-mix(in srgb, var(--accent) 48%, var(--border));
  color: var(--accent);
}

.density {
  align-items: center;
  border-radius: 8px;
  display: flex;
  gap: 8px;
  height: 40px;
  padding: 0 10px;
}

.density span {
  color: var(--muted);
  font-size: 16px;
  line-height: 1;
}

.density input {
  accent-color: var(--accent);
  inline-size: 96px;
}

.icon-button {
  align-items: center;
  border-radius: 8px;
  cursor: pointer;
  display: inline-flex;
  font-size: 20px;
  height: 40px;
  justify-content: center;
  line-height: 1;
  text-decoration: none;
  transition: border-color 0.15s ease, color 0.15s ease, transform 0.15s ease;
  width: 40px;
}

.icon-button:hover {
  border-color: color-mix(in srgb, var(--accent) 48%, var(--border));
  color: var(--accent);
}

.icon-button:active {
  transform: translateY(1px);
}

.icon-button:disabled {
  cursor: default;
  opacity: 0.42;
  transform: none;
}

.icon-button.is-loading {
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.folders {
  display: flex;
  gap: 8px;
  margin: 16px -20px 18px;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  padding: 0 20px 2px;
  scrollbar-width: thin;
}

.folder-chip {
  border-radius: 999px;
  cursor: pointer;
  flex: 0 0 auto;
  font-size: 13px;
  min-height: 34px;
  padding: 0 14px;
}

.folder-chip[aria-pressed="true"] {
  background: var(--accent-soft);
  border-color: color-mix(in srgb, var(--accent) 48%, var(--border));
  color: var(--accent);
  font-weight: 650;
}

.content {
  min-height: 60vh;
}

.masonry {
  --column-width: 240px;

  column-gap: 16px;
  column-width: var(--column-width);
}

.photo-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  break-inside: avoid;
  display: inline-block;
  margin: 0 0 16px;
  overflow: hidden;
  transition: border-color 0.15s ease, transform 0.15s ease, box-shadow 0.15s ease;
  width: 100%;
}

.photo-card:hover {
  border-color: color-mix(in srgb, var(--accent) 35%, var(--border));
  box-shadow: 0 10px 28px rgba(28, 34, 42, 0.12);
  transform: translateY(-1px);
}

.photo-card__button {
  background: var(--surface-strong);
  border: 0;
  cursor: zoom-in;
  display: block;
  min-height: 120px;
  overflow: hidden;
  padding: 0;
  position: relative;
  width: 100%;
}

.photo-card__button img {
  background: var(--surface-strong);
  display: block;
  height: auto;
  width: 100%;
}

.photo-card__fallback {
  align-items: center;
  aspect-ratio: 4 / 3;
  color: var(--muted);
  display: flex;
  font-size: 24px;
  font-weight: 750;
  justify-content: center;
  letter-spacing: 0;
  width: 100%;
}

.photo-card__meta {
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  border: 1px solid color-mix(in srgb, var(--border) 72%, transparent);
  border-radius: 999px;
  color: var(--text);
  font-size: 11px;
  inset: 10px auto auto 10px;
  max-width: calc(100% - 20px);
  overflow: hidden;
  padding: 2px 8px;
  position: absolute;
  text-overflow: ellipsis;
  white-space: nowrap;
  backdrop-filter: blur(12px);
}

.photo-card__caption {
  display: grid;
  gap: 2px;
  padding: 10px 12px 12px;
}

.photo-card__caption strong,
.photo-card__caption span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.photo-card__caption strong {
  font-size: 13px;
  font-weight: 650;
}

.photo-card__caption span {
  color: var(--muted);
  font-size: 12px;
}

.empty {
  color: var(--muted);
  margin: 18vh 0 0;
  text-align: center;
}

.add-dialog {
  background: transparent;
  border: 0;
  color: var(--text);
  max-width: min(420px, calc(100vw - 28px));
  padding: 0;
  width: 100%;
}

.add-dialog::backdrop {
  background: rgba(8, 10, 13, 0.56);
  backdrop-filter: blur(8px);
}

.add-dialog__box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
  display: grid;
  gap: 14px;
  padding: 16px;
}

.add-dialog__header,
.add-dialog__actions {
  align-items: center;
  display: flex;
  justify-content: space-between;
}

.add-dialog__header strong {
  font-size: 15px;
}

.form-field {
  display: grid;
  gap: 6px;
}

.form-field span,
.upload-status {
  color: var(--muted);
  font-size: 12px;
}

.form-field input {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 16px;
  min-height: 40px;
  outline: 0;
  padding: 0 12px;
}

.form-field input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent);
}

.form-field .select {
  width: 100%;
}

.upload-status {
  min-height: 18px;
  margin: 0;
}

.viewer {
  background: transparent;
  border: 0;
  color: var(--text);
  height: 100dvh;
  max-height: none;
  max-width: none;
  padding: 0;
  width: 100vw;
}

.viewer::backdrop {
  background: rgba(8, 10, 13, 0.76);
  backdrop-filter: blur(12px);
}

.viewer__frame {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  height: 100%;
  padding: 14px;
  padding-top: calc(14px + env(safe-area-inset-top, 0px));
  padding-right: calc(14px + env(safe-area-inset-right, 0px));
  padding-bottom: calc(14px + env(safe-area-inset-bottom, 0px));
  padding-left: calc(14px + env(safe-area-inset-left, 0px));
}

.viewer__bar {
  align-items: center;
  display: grid;
  gap: 8px;
  grid-template-columns: 40px minmax(0, 1fr) repeat(5, 40px);
  margin: 0 auto 12px;
  max-width: 1180px;
  width: 100%;
}

.viewer__title {
  align-items: baseline;
  background: color-mix(in srgb, var(--surface) 90%, transparent);
  border: 1px solid color-mix(in srgb, var(--border) 76%, transparent);
  border-radius: 8px;
  display: flex;
  gap: 10px;
  height: 40px;
  min-width: 0;
  padding: 8px 12px;
  backdrop-filter: blur(18px);
}

.viewer__title strong,
.viewer__title span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.viewer__title strong {
  min-width: 0;
}

.viewer__title span {
  color: var(--muted);
  flex: 0 1 auto;
  font-size: 12px;
}

.viewer__stage {
  align-items: center;
  display: flex;
  justify-content: center;
  min-height: 0;
}

.viewer__stage img {
  border-radius: 8px;
  box-shadow: var(--shadow);
  display: block;
  max-height: 100%;
  max-width: 100%;
  object-fit: contain;
}

.toast {
  background: var(--text);
  border-radius: 8px;
  bottom: calc(18px + env(safe-area-inset-bottom, 0px));
  color: var(--bg);
  left: 50%;
  opacity: 0;
  padding: 9px 12px;
  pointer-events: none;
  position: fixed;
  transform: translate(-50%, 8px);
  transition: opacity 0.18s ease, transform 0.18s ease;
  z-index: 80;
}

.toast--show {
  opacity: 1;
  transform: translate(-50%, 0);
}

@media (max-width: 780px) {
  .app {
    padding: 14px;
    padding-top: calc(14px + env(safe-area-inset-top, 0px));
    padding-right: calc(14px + env(safe-area-inset-right, 0px));
    padding-bottom: calc(22px + env(safe-area-inset-bottom, 0px));
    padding-left: calc(14px + env(safe-area-inset-left, 0px));
  }

  .topbar {
    grid-template-columns: 1fr;
    margin: -14px -14px 0;
    padding: 12px 14px;
    padding-top: calc(12px + env(safe-area-inset-top, 0px));
  }

  .brand {
    justify-content: space-between;
  }

  .toolbar {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto 40px 40px;
    justify-content: stretch;
  }

  .select {
    min-width: 0;
    width: 100%;
  }

  .density input {
    inline-size: 72px;
  }

  .folders {
    margin: 14px -14px 14px;
    padding-inline: 14px;
  }

  .masonry {
    column-gap: 12px;
    column-width: min(var(--column-width), calc(100vw - 28px));
  }

  .photo-card {
    margin-bottom: 12px;
  }

  .viewer__bar {
    grid-template-columns: 40px minmax(0, 1fr) repeat(4, 40px);
  }

  .viewer__title span {
    display: none;
  }

  .viewer__nav:first-child {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}
