:root {
  color-scheme: light;
  --bg: #f7f7f4;
  --panel: #ffffff;
  --ink: #202124;
  --muted: #687076;
  --line: #deded8;
  --accent: #0f766e;
  --accent-soft: #d8f1ee;
  --shadow: 0 10px 28px rgba(20, 31, 39, 0.09);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: "Segoe UI", Arial, sans-serif;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  gap: 16px;
  align-items: center;
  justify-content: space-between;
  padding: 18px clamp(16px, 4vw, 42px);
  border-bottom: 1px solid var(--line);
  background: rgba(247, 247, 244, 0.94);
  backdrop-filter: blur(10px);
}

h1 {
  margin: 0;
  font-size: 24px;
  font-weight: 700;
}

p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.actions {
  min-width: min(320px, 42vw);
}

input {
  width: 100%;
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 0 12px;
  color: var(--ink);
  background: var(--panel);
  font-size: 14px;
}

main {
  padding: 20px clamp(16px, 4vw, 42px) 42px;
}

.tabs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 14px;
}

.tab {
  flex: 0 0 auto;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 0 13px;
  background: var(--panel);
  color: var(--ink);
  cursor: pointer;
}

.tab.active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: #074541;
}

.gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 14px;
}

.card {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  cursor: pointer;
  position: relative;
}

.thumb-wrap {
  position: relative;
}

.thumb {
  width: 100%;
  aspect-ratio: 4 / 3;
  display: block;
  object-fit: cover;
  background: #e8ebe8;
}

.count-badge {
  position: absolute;
  bottom: 6px;
  right: 6px;
  background: rgba(0,0,0,.65);
  color: #fff;
  font-size: 11px;
  padding: 2px 7px;
  border-radius: 10px;
  pointer-events: none;
}

.meta {
  padding: 10px 11px 12px;
}

.meta strong,
#previewTitle {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 14px;
}

.meta span,
#previewPath {
  display: block;
  margin-top: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--muted);
  font-size: 12px;
}

.empty {
  grid-column: 1 / -1;
  padding: 38px 0;
  color: var(--muted);
  text-align: center;
}

.preview {
  width: min(940px, calc(100vw - 28px));
  border: 0;
  border-radius: 8px;
  padding: 0;
  background: var(--panel);
  box-shadow: 0 24px 70px rgba(20, 31, 39, 0.28);
}

.preview::backdrop {
  background: rgba(15, 23, 42, 0.55);
}

.preview img {
  width: 100%;
  max-height: 72vh;
  display: block;
  object-fit: contain;
  background: #111827;
}

.preview-footer {
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
}

button {
  font: inherit;
}

#copyLink {
  height: 36px;
  border: 0;
  border-radius: 7px;
  padding: 0 13px;
  background: var(--accent);
  color: white;
  cursor: pointer;
}

.icon-button {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.9);
  color: var(--ink);
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
  z-index: 1;
}

.nav-btn {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 40px;
  height: 60px;
  border: 0;
  background: rgba(255,255,255,.7);
  color: #333;
  font-size: 28px;
  cursor: pointer;
  z-index: 2;
  display: none;
  border-radius: 4px;
}
.nav-btn.left { left: 4px; }
.nav-btn.right { right: 4px; }
.nav-btn:hover { background: #fff; }

@media (max-width: 640px) {
  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .actions {
    min-width: 0;
  }

  .gallery {
    grid-template-columns: repeat(auto-fill, minmax(142px, 1fr));
  }

  .preview-footer {
    align-items: stretch;
    flex-direction: column;
  }
}
