:root {
  --bg: #0f1115;
  --panel: #171a21;
  --panel-2: #1f232c;
  --border: #2a2f3a;
  --text: #e6e8ec;
  --muted: #9aa2b1;
  --accent: #4f8cff;
  --accent-hover: #3d78e8;
  --danger: #e5484d;
  --radius: 10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font: 15px/1.5 system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}

body.centered {
  display: flex;
  min-height: 100vh;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1.25rem;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.brand { font-weight: 700; font-size: 1.1rem; color: var(--text); }
.brand:hover { text-decoration: none; }

main {
  max-width: 1000px;
  margin: 0 auto;
  padding: 1.5rem 1.25rem 4rem;
}

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 1.25rem;
}

h1, h2, h3 { margin-top: 0; }
.section-title { display: flex; align-items: center; gap: 0.5rem; }
.count {
  font-size: 0.8rem;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.1rem 0.6rem;
  color: var(--muted);
}

label { display: block; font-weight: 600; margin-bottom: 0.35rem; }
small, .hint, .empty { color: var(--muted); }
.hint { font-size: 0.85rem; margin: 0 0 0.75rem; }

input[type=text], input[type=password], input[type=file], .field input {
  width: 100%;
  padding: 0.55rem 0.7rem;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font: inherit;
}
input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

.field { margin-bottom: 1rem; }

.slug-input {
  display: flex;
  align-items: stretch;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  background: var(--panel-2);
}
.slug-input .prefix {
  padding: 0.55rem 0.6rem;
  color: var(--muted);
  background: #12151b;
  border-right: 1px solid var(--border);
  white-space: nowrap;
  font-size: 0.9rem;
  display: flex;
  align-items: center;
}
.slug-input input { border: 0; border-radius: 0; }

button {
  font: inherit;
  font-weight: 600;
  padding: 0.55rem 1rem;
  background: var(--accent);
  color: #fff;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
}
button:hover { background: var(--accent-hover); }
button.ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
}
button.ghost:hover { background: var(--panel-2); }

.flash {
  padding: 0.7rem 0.9rem;
  border-radius: 8px;
  margin-bottom: 1rem;
}
.flash.error {
  background: rgba(229, 72, 77, 0.12);
  border: 1px solid rgba(229, 72, 77, 0.4);
  color: #ff9a9d;
}

/* Login */
.login { width: 320px; max-width: 100%; text-align: center; }
.login h1 { margin-bottom: 1rem; }
.login input { margin-bottom: 0.9rem; text-align: center; }
.login button { width: 100%; }

/* Grid */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 1rem;
}
.tile {
  position: relative;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  color: var(--text);
}
.tile:hover { border-color: var(--accent); }
.tile-link { display: block; color: var(--text); }
.tile-link:hover { text-decoration: none; }

.tile-delete {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 30px;
  height: 30px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  background: rgba(15, 17, 21, 0.72);
  color: #fff;
  border: 1px solid var(--border);
  opacity: 0;
  transition: opacity 0.12s ease, background 0.12s ease;
}
.tile:hover .tile-delete,
.tile-delete:focus-visible { opacity: 1; }
.tile-delete:hover { background: var(--danger); border-color: var(--danger); }
.thumb {
  aspect-ratio: 1;
  background:
    repeating-conic-gradient(#20242d 0% 25%, #191c23 0% 50%) 50% / 20px 20px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.thumb img { max-width: 100%; max-height: 100%; object-fit: contain; }
.tile-meta {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.5rem;
  padding: 0.5rem 0.6rem;
  font-size: 0.82rem;
}
.tile-titles { min-width: 0; }
.tile-meta .title {
  display: block;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.tile-meta .sub {
  display: block;
  color: var(--muted);
  font-size: 0.75rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.tile-meta .dims { color: var(--muted); flex-shrink: 0; }

/* Tabs */
.tabs {
  display: flex;
  gap: 0.25rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1.25rem;
}
.tab {
  background: transparent;
  color: var(--muted);
  border: 0;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  padding: 0.6rem 0.9rem;
  font-weight: 600;
  margin-bottom: -1px;
}
.tab:hover { background: transparent; color: var(--text); }
.tab.active { color: var(--text); border-bottom-color: var(--accent); }
.tab .count { margin-left: 0.35rem; }

/* Library search */
.library-head { margin-bottom: 1rem; }
.search {
  width: 100%;
  max-width: 420px;
  padding: 0.55rem 0.8rem;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font: inherit;
}

.optional { color: var(--muted); font-weight: 400; }
.linklike {
  background: none;
  border: 0;
  padding: 0;
  color: var(--accent);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  text-decoration: underline;
}

/* Name form (upload + preview) */
.name-form { display: flex; gap: 0.5rem; }
.name-form input { flex: 1; }
.name-form button { flex-shrink: 0; }

/* Preview header */
.preview-titles { display: flex; flex-direction: column; }
.preview-slug { color: var(--muted); font-size: 0.85rem; }

/* Preview */
.preview-head { display: flex; align-items: baseline; gap: 1rem; margin-bottom: 1rem; }
.preview-head h2 { margin: 0; }
.back { font-size: 0.9rem; }

.preview-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.6fr) minmax(280px, 1fr);
  gap: 1.25rem;
  align-items: start;
}
.preview-image {
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    repeating-conic-gradient(#20242d 0% 25%, #191c23 0% 50%) 50% / 24px 24px;
}
.preview-image img { max-width: 100%; max-height: 70vh; border-radius: 6px; }
.preview-side .card { margin-bottom: 1rem; }

.copy-row { display: flex; gap: 0.5rem; margin-bottom: 0.6rem; }
.copy-row input { flex: 1; font-size: 0.85rem; }
.copy-row button { flex-shrink: 0; }
.open-raw { font-size: 0.9rem; }

.details { display: grid; grid-template-columns: auto 1fr; gap: 0.35rem 1rem; margin: 0; }
.details dt { color: var(--muted); font-weight: 600; }
.details dd { margin: 0; word-break: break-all; }
.mono, .raw-url { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }

.card.danger { border-color: rgba(229, 72, 77, 0.4); }
.danger-btn { background: var(--danger); }
.danger-btn:hover { background: #c93b40; }

/* Delete-confirmation modal */
.modal-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(0, 0, 0, 0.6);
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.modal-backdrop.open { display: flex; }
.modal {
  width: 380px;
  max-width: 100%;
  margin: 0;
  border-color: rgba(229, 72, 77, 0.4);
}
.modal h3 { margin-bottom: 0.5rem; }
.modal p { margin: 0 0 1.25rem; color: var(--muted); }
.modal-actions { display: flex; justify-content: flex-end; gap: 0.6rem; }

@media (max-width: 720px) {
  .preview-grid { grid-template-columns: 1fr; }
}
