:root {
  --bg: #f6f5f2;
  --surface: #ffffff;
  --text: #1d1c1a;
  --muted: #6b6862;
  --border: #e3e0da;
  --accent: #b4532a;
  --accent-ink: #ffffff;
  --accent-soft: #f6e6dd;
  --danger: #b42318;
  --ok-bg: #e7f4ea; --ok-ink: #1f5f30;
  --err-bg: #fdecea; --err-ink: #8a1c12;
  --radius: 12px;
  --shadow: 0 1px 2px rgb(0 0 0 / .05), 0 4px 16px rgb(0 0 0 / .04);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161514; --surface: #201f1d; --text: #edebe7; --muted: #a29e96; --border: #34322e;
    --accent: #e07a4a; --accent-ink: #1a0f09; --accent-soft: #3a2519;
    --danger: #f07167; --ok-bg: #173622; --ok-ink: #a8e0b5; --err-bg: #3d1713; --err-ink: #f7b4ab;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); }
img { max-width: 100%; display: block; }
h1 { font-size: 1.75rem; margin: .2rem 0 1rem; line-height: 1.2; }
h2 { font-size: 1.05rem; margin: 1.25rem 0 .5rem; }
h3 { font-size: 1rem; margin: .35rem 0 .15rem; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.hint { color: var(--muted); font-weight: 400; font-size: .8rem; }
.prewrap { white-space: pre-wrap; }

/* Layout */
.container { max-width: 1120px; margin: 0 auto; padding: 1.5rem 16px 4rem; }
.topbar { background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 5; }
.topbar-inner { max-width: 1120px; margin: 0 auto; padding: .7rem 16px; display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; }
.brand { font-weight: 700; color: var(--text); text-decoration: none; letter-spacing: -.01em; }
.brand-mark { color: var(--accent); }
.nav { margin-left: auto; display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; }
.nav a { color: var(--text); text-decoration: none; }
.nav a.active { color: var(--accent); font-weight: 600; }
.nav a.btn { color: var(--accent-ink); }
.me { display: flex; align-items: center; gap: .45rem; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.page-head h1 { margin-bottom: 0; }
.crumbs { margin: 0 0 .5rem; font-size: .9rem; }
.crumbs a { color: var(--muted); text-decoration: none; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.25rem; box-shadow: var(--shadow); }
.card > h2:first-child { margin-top: 0; }
.narrow { max-width: 520px; margin: 2rem auto; }
.auth-card { max-width: 420px; margin: 3rem auto; }
.auth-card h1 { margin-bottom: .2rem; }
.stack { display: flex; flex-direction: column; gap: .9rem; }

/* Forms */
label { display: flex; flex-direction: column; gap: .3rem; font-weight: 600; font-size: .9rem; }
label.check { flex-direction: row; align-items: center; font-weight: 400; }
input, select, textarea {
  font: inherit; color: inherit; background: var(--bg); border: 1px solid var(--border);
  border-radius: 8px; padding: .55rem .7rem; width: 100%; font-weight: 400;
}
input[type=checkbox] { width: auto; }
input[type=file] { padding: .4rem; background: transparent; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: transparent; }
input:disabled { opacity: .65; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem 1.25rem; }
.span-2 { grid-column: 1 / -1; }
.actions { display: flex; align-items: center; gap: 1rem; }
@media (max-width: 640px) { .form-grid { grid-template-columns: 1fr; } }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .3rem;
  background: var(--accent); color: var(--accent-ink); border: 1px solid var(--accent);
  border-radius: 8px; padding: .55rem 1rem; font: inherit; font-weight: 600;
  text-decoration: none; cursor: pointer; white-space: nowrap;
}
.btn:hover { filter: brightness(1.06); }
.btn-secondary { background: transparent; color: var(--accent); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-small { padding: .35rem .75rem; font-size: .875rem; }
button.link { background: none; border: 0; padding: 0; font: inherit; color: var(--muted); cursor: pointer; }
button.link:hover { color: var(--text); text-decoration: underline; }
form.inline { display: inline; }

.flash { border-radius: 8px; padding: .7rem 1rem; margin-bottom: 1rem; }
.flash ul { margin: 0; padding-left: 1.1rem; }
.flash-success { background: var(--ok-bg); color: var(--ok-ink); }
.flash-error { background: var(--err-bg); color: var(--err-ink); }

/* Stats & filters */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: .75rem; margin-bottom: 1rem; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .8rem 1rem; display: flex; flex-direction: column; }
.stat-label { color: var(--muted); font-size: .8rem; }
.stat-value { font-size: 1.35rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.filters { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; margin-bottom: 1.25rem; }
.filters input[type=search] { flex: 1 1 240px; width: auto; }
.filters select { width: auto; flex: 0 1 auto; }

/* Grid of items */
.grid { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 1rem; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); transition: transform .12s, border-color .12s; }
.tile:hover { transform: translateY(-2px); border-color: var(--accent); }
.tile a { color: inherit; text-decoration: none; display: block; }
.tile-img { aspect-ratio: 1; background: var(--accent-soft); display: grid; place-items: center; }
.tile-img img { width: 100%; height: 100%; object-fit: cover; }
.tile-body { padding: .75rem .9rem .9rem; }
.tile-body h3 { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile-body p { margin: 0; }
.tile-meta { display: flex; gap: .6rem; flex-wrap: wrap; margin-top: .35rem !important; font-size: .875rem; }
.placeholder { font-size: 2.5rem; color: var(--accent); opacity: .35; }
.chip { display: inline-block; background: var(--accent-soft); color: var(--accent); border-radius: 999px; padding: .1rem .6rem; font-size: .75rem; font-weight: 600; }
.empty { text-align: center; padding: 3rem 1rem; }
.empty h2 { margin-top: 0; }

/* Item detail */
.detail { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); gap: 1.25rem; align-items: start; }
@media (max-width: 820px) { .detail { grid-template-columns: 1fr; } }
.gallery-main img { width: 100%; max-height: 520px; object-fit: contain; border-radius: 8px; background: var(--bg); }
.gallery-empty { aspect-ratio: 4 / 3; display: grid; place-content: center; text-align: center; background: var(--accent-soft); border-radius: 8px; }
.thumbs { list-style: none; padding: 0; margin: .75rem 0 0; display: flex; gap: .5rem; flex-wrap: wrap; }
.thumbs li { position: relative; }
.thumbs img { width: 72px; height: 72px; object-fit: cover; border-radius: 6px; border: 1px solid var(--border); }
.thumb-remove {
  position: absolute; top: -6px; right: -6px; width: 22px; height: 22px; border-radius: 50%;
  border: 1px solid var(--border); background: var(--surface); color: var(--danger); cursor: pointer; line-height: 1; font-size: 15px;
}
.upload { display: flex; gap: .75rem; align-items: flex-end; flex-wrap: wrap; margin-top: 1rem; padding-top: 1rem; border-top: 1px solid var(--border); }
.upload label { flex: 1 1 220px; }
.facts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .75rem 1rem; margin: 0; }
.facts dt { color: var(--muted); font-size: .8rem; }
.facts dd { margin: 0; font-weight: 600; }
.danger-zone { margin-top: 1.5rem; }
.danger-zone summary { cursor: pointer; color: var(--danger); font-size: .9rem; }

/* Profile */
.profile-grid { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr); gap: 1.25rem; align-items: start; }
@media (max-width: 820px) { .profile-grid { grid-template-columns: 1fr; } }
.profile-grid .card .danger-zone { margin-top: 0; }
.avatar { border-radius: 50%; object-fit: cover; flex: none; }
.avatar-sm { width: 28px; height: 28px; }
.avatar-lg { width: 88px; height: 88px; font-size: 2rem; }
.avatar-initial { display: inline-grid; place-items: center; background: var(--accent-soft); color: var(--accent); font-weight: 700; }
.avatar-sm.avatar-initial { font-size: .85rem; }
.avatar-row { display: flex; gap: 1rem; align-items: center; flex-wrap: wrap; }
@media (max-width: 480px) { .me-name { display: none; } }
