:root {
  color-scheme: light dark;
  --bg: #0f1115;
  --surface: #1a1d24;
  --text: #f4f6fb;
  --muted: #9aa3b2;
  --accent: #5b8cff;
  --border: #2a3140;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
}

main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1rem 1rem 6rem;
}

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

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

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

.create-name {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  width: min(100%, 20rem);
}

.create-name-label {
  color: var(--muted);
  font-size: 0.9rem;
}

.create-name input,
.modal-form input[type="text"] {
  width: 100%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 10px;
  padding: 0.65rem 0.85rem;
  font-size: 1rem;
}

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

.sort-control {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 999px;
  padding: 0.35rem 0.75rem 0.35rem 0.9rem;
}

.sort-label {
  color: var(--muted);
  font-size: 0.85rem;
}

.sort-control select {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--text);
  font-size: 0.9rem;
  padding: 0.15rem 1.25rem 0.15rem 0;
  cursor: pointer;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 12px) calc(50% + 1px), calc(100% - 7px) calc(50% + 1px);
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}

button, .btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 999px;
  padding: 0.6rem 1rem;
  font-size: 0.95rem;
  cursor: pointer;
}

button.primary, .btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

button.danger {
  background: #c0392b;
  border-color: #c0392b;
  color: #fff;
}

button:disabled { opacity: 0.5; cursor: not-allowed; }

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

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

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

.tile .check {
  position: absolute;
  top: 6px;
  left: 6px;
  width: 1.5rem;
  height: 1.5rem;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 0.9rem;
  display: grid;
  place-items: center;
  line-height: 1;
}

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

.tile-video-fallback {
  width: 100%;
  height: 100%;
  background: linear-gradient(145deg, #2a3140 0%, #151820 100%);
}

.badge {
  position: absolute;
  right: 6px;
  bottom: 6px;
  background: rgba(0,0,0,0.65);
  color: #fff;
  font-size: 0.7rem;
  padding: 0.15rem 0.4rem;
  border-radius: 6px;
}

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

.bottom-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  gap: 0.5rem;
  padding: 0.75rem 1rem calc(0.75rem + env(safe-area-inset-bottom));
  background: rgba(15, 17, 21, 0.92);
  backdrop-filter: blur(8px);
  border-top: 1px solid var(--border);
  justify-content: center;
}

.bottom-bar button { flex: 1; max-width: 220px; }

.progress {
  margin: 0.75rem 0;
  height: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  overflow: hidden;
}

.progress[hidden] {
  display: none;
}

.progress > span {
  display: block;
  height: 100%;
  background: var(--accent);
  width: 0%;
  transition: width 0.2s ease;
}

.status { color: var(--muted); font-size: 0.85rem; min-height: 1.2rem; }

.modal {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: end center;
  padding: 1rem;
}

.modal[hidden] { display: none; }

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
}

.modal-sheet {
  position: relative;
  width: min(420px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 1rem;
  z-index: 1;
}

.modal-sheet h2 {
  margin: 0 0 0.75rem;
  font-size: 1rem;
}

.modal-form {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.modal-form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.modal-form-actions button {
  flex: 1;
  min-width: 7rem;
}

.modal-options {
  display: grid;
  gap: 0.5rem;
}

.modal-options button,
.modal-cancel {
  width: 100%;
  max-width: none;
  border-radius: 12px;
}

.modal-cancel {
  margin-top: 0.75rem;
}

.hero {
  min-height: 70dvh;
  display: grid;
  place-items: center;
  text-align: center;
  gap: 1rem;
}

.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.92);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 50;
}

.lightbox.open {
  display: flex;
  flex-direction: column;
}

.lightbox-media {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 0;
  padding: 4.5rem 1rem 1rem;
}

.lightbox-media img,
.lightbox-media video {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
}

.lightbox-actions {
  position: absolute;
  top: 1rem;
  right: 1rem;
  left: 1rem;
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
  z-index: 2;
}

.lightbox-actions .close {
  position: static;
}
