:root {
  color-scheme: dark;
  --bg: #111214;
  --surface: #1b1c1f;
  --border: #2c2d31;
  --text: #f2f2f3;
  --muted: #9a9ba0;
  --accent: #5b8def;
  --danger: #e5534b;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

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

/* --- Gallery --- */

.topbar {
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  z-index: 10;
}

.topbar-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.topbar-row-secondary {
  gap: 0.5rem;
}

.topbar-row-secondary .btn,
.topbar-row-secondary .save-to-photos-btn {
  flex: 1;
}

.topbar h1 {
  font-size: 1.1rem;
  margin: 0;
}

.topbar-controls {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.topbar select {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  padding: 0.4rem 0.6rem;
}

.btn {
  border: none;
  border-radius: 0.5rem;
  padding: 0.4rem 0.75rem;
  font-size: 0.85rem;
  cursor: pointer;
  white-space: nowrap;
}

.btn-outline {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
}

.btn-outline.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.btn-accent {
  background: var(--accent);
  color: #fff;
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.save-to-photos-btn {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 0.5rem;
  padding: 0.4rem 0.75rem;
  font-size: 0.85rem;
  cursor: pointer;
  white-space: nowrap;
}

.empty-state {
  text-align: center;
  color: var(--muted);
  padding: 3rem 1rem;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 0.5rem;
  padding: 0.5rem;
}

.tile {
  position: relative;
  padding: 0;
  border: none;
  background: var(--surface);
  border-radius: 0.5rem;
  overflow: hidden;
  aspect-ratio: 1 / 1;
  cursor: pointer;
}

.tile img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.tile-checkmark {
  display: none;
  position: absolute;
  top: 0.35rem;
  right: 0.35rem;
  width: 1.4rem;
  height: 1.4rem;
  border-radius: 999px;
  border: 2px solid #fff;
  background: rgba(0, 0, 0, 0.35);
}

.grid.select-mode .tile-checkmark {
  display: block;
}

.tile.selected {
  outline: 3px solid var(--accent);
  outline-offset: -3px;
}

.tile.selected .tile-checkmark {
  background: var(--accent);
  border-color: var(--accent);
}

.tile.selected .tile-checkmark::after {
  content: "";
  position: absolute;
  left: 0.4rem;
  top: 0.15rem;
  width: 0.35rem;
  height: 0.7rem;
  border: solid #fff;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

#sentinel {
  height: 1px;
}

.lightbox[hidden] {
  display: none;
}

.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.92);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  padding: 1rem;
  z-index: 100;
}

.lightbox img {
  max-width: 100%;
  max-height: 80vh;
  border-radius: 0.5rem;
}

.lightbox-hint {
  color: var(--muted);
  font-size: 0.9rem;
}

.lightbox-close {
  position: absolute;
  top: 1rem;
  right: 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 999px;
  width: 2.5rem;
  height: 2.5rem;
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
}

.modal-overlay[hidden] {
  display: none;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 200;
}

.modal-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  padding: 1.25rem;
  max-width: 360px;
  width: 100%;
}

.modal-box p {
  margin: 0 0 1rem;
  line-height: 1.5;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
}

/* --- Admin --- */

.login-gate {
  max-width: 320px;
  margin: 4rem auto;
  padding: 1rem;
  text-align: center;
}

.login-gate form {
  display: flex;
  gap: 0.5rem;
  margin-top: 1rem;
}

.login-gate input {
  flex: 1;
  padding: 0.6rem;
  border-radius: 0.5rem;
  border: 1px solid var(--border);
  background: var(--surface);
}

.error {
  color: var(--danger);
  font-size: 0.9rem;
}

.success {
  color: #4caf6a;
}

.status {
  color: var(--muted, #888);
  font-style: italic;
}

.admin-app {
  max-width: 720px;
  margin: 0 auto;
  padding: 1rem;
}

.admin-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}

.admin-header h1 {
  font-size: 1.25rem;
  margin: 0;
}

.logout-link {
  color: var(--muted);
  text-decoration: none;
  font-size: 0.9rem;
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  padding: 0.35rem 0.75rem;
}

.logout-link:hover {
  color: var(--text);
}

.tabs {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1.5rem;
  border-bottom: 1px solid var(--border);
}

.tab-btn {
  background: none;
  border: none;
  padding: 0.6rem 1rem;
  cursor: pointer;
  color: var(--muted);
  border-bottom: 2px solid transparent;
}

.tab-btn.active {
  color: var(--text);
  border-bottom-color: var(--accent);
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

#upload-form,
#category-create-form {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  max-width: 400px;
}

#upload-form label {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.9rem;
  color: var(--muted);
}

#category-create-form {
  flex-direction: row;
  max-width: none;
}

#category-create-form input {
  flex: 1;
}

input,
select,
button {
  padding: 0.5rem 0.7rem;
  border-radius: 0.5rem;
  border: 1px solid var(--border);
  background: var(--surface);
}

button {
  cursor: pointer;
}

.upload-results {
  list-style: none;
  padding: 0;
  margin-top: 1rem;
}

.memes-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: 1rem;
}

.meme-row,
.category-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0.5rem;
}

.meme-row img {
  width: 48px;
  height: 48px;
  object-fit: cover;
  border-radius: 0.3rem;
}

.meme-filename {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.85rem;
  color: var(--muted);
}

.category-row input {
  flex: 1;
}

.pager {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-top: 1rem;
}

.categories-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: 1rem;
}

.duplicates-list {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  margin-top: 1rem;
}

.duplicate-group {
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  padding: 0.5rem;
}

.duplicate-group-label {
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 0.5rem;
}

.duplicate-group .meme-row {
  border: none;
  padding: 0.25rem 0;
}

/* --- Foodmap --- */

.place-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 1rem;
  padding: 1rem;
}

.place-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  overflow: hidden;
}

.place-card img {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  display: block;
}

.place-card-body {
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.place-card-body h3 {
  margin: 0;
  font-size: 1rem;
}

.place-rating {
  color: var(--accent);
  letter-spacing: 0.1rem;
}

.place-tag {
  display: inline-block;
  width: fit-content;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.15rem 0.6rem;
  font-size: 0.75rem;
  color: var(--muted);
}

.place-notes {
  margin: 0;
  font-size: 0.85rem;
  color: var(--muted);
}

.place-address {
  margin: 0;
  font-size: 0.85rem;
}

.place-address a {
  color: var(--accent);
}

.places-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: 1rem;
}

.place-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0.5rem;
}

.place-row img {
  width: 48px;
  height: 48px;
  object-fit: cover;
  border-radius: 0.3rem;
}

.place-row-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.place-row-address {
  font-size: 0.8rem;
  color: var(--muted);
}

#mark-eaten-form {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

#mark-eaten-form label {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.9rem;
  color: var(--muted);
}

#place-create-form {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  max-width: 400px;
}

#place-create-form label {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.9rem;
  color: var(--muted);
}
