:root {
  --bg: #fbf6ec;
  --surface: #ffffff;
  --cream: #f7ead2;
  --ink: #3b2416;
  --ink-2: #6e5442;
  --line: #e6d7bf;
  --accent: #e8822e;
  --accent-ink: #ffffff;
  --moss: #4f6b4a;
  --moss-soft: #e3ecdf;
  --red: #b5533c;
  --red-soft: #f6e1da;
  --radius: 12px;
  --shadow: 0 1px 2px rgb(59 36 22 / 6%), 0 4px 16px rgb(59 36 22 / 7%);
  color-scheme: light;
}

* { 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(--ink);
}

a { color: var(--moss); }
h1, h2, h3 { line-height: 1.2; margin: 0; }
h1 { font-size: 1.75rem; }
.muted { color: var(--ink-2); }
.small { font-size: 0.85rem; }
[hidden] { display: none !important; }

/* ---------- top bar ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.6rem 1.5rem;
  background: var(--ink);
  color: var(--cream);
}
.brand { display: flex; align-items: center; gap: 0.6rem; color: inherit; text-decoration: none; font-size: 1.05rem; }
.account-inner { display: flex; align-items: center; gap: 0.6rem; }
.account-name { display: flex; align-items: center; gap: 0.4rem; }
.avatar {
  display: grid;
  place-items: center;
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
  font-size: 0.8rem;
}
.tag { font-size: 0.7rem; padding: 0.05rem 0.4rem; border-radius: 99px; background: rgb(255 255 255 / 15%); }
.topbar .btn.ghost { color: var(--cream); border-color: rgb(247 234 210 / 35%); }
.topbar .btn.ghost:hover { background: rgb(255 255 255 / 10%); }

.view { max-width: 1400px; margin: 0 auto; padding: 1.5rem; }

/* ---------- buttons, forms ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { background: var(--cream); }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { background: #d47224; }
.btn.danger { background: var(--red); border-color: var(--red); color: #fff; }
.btn.ghost { background: transparent; }
.btn.small { padding: 0.25rem 0.6rem; font-size: 0.85rem; }
.btn.large { padding: 0.8rem 1.4rem; font-size: 1.05rem; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.field { display: grid; gap: 0.3rem; margin: 0 0 1rem; }
.field > span { font-weight: 600; font-size: 0.9rem; }
.field small { color: var(--ink-2); }
input:not([type='checkbox']), textarea, select {
  width: 100%;
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  font: inherit;
}
textarea { resize: vertical; }
.toolbar select { width: auto; }
.form-error { color: var(--red); background: var(--red-soft); padding: 0.5rem 0.75rem; border-radius: 8px; margin: 0 0 1rem; }
.form-error p { margin: 0.15rem 0; }

/* ---------- dialogs ---------- */

.dialog {
  width: min(32rem, calc(100vw - 2rem));
  max-height: calc(100vh - 2rem);
  padding: 1.5rem;
  border: none;
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--ink);
  box-shadow: 0 20px 60px rgb(0 0 0 / 30%);
}
.dialog.wide { width: min(44rem, calc(100vw - 2rem)); }
.dialog::backdrop { background: rgb(30 18 10 / 55%); }
.dialog h2 { margin-bottom: 1rem; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 0.5rem; margin-top: 0.5rem; }

.dropzone {
  display: grid;
  gap: 0.25rem;
  place-items: center;
  padding: 2rem 1rem;
  margin-bottom: 1rem;
  border: 2px dashed var(--line);
  border-radius: var(--radius);
  background: #fff;
  text-align: center;
  cursor: pointer;
}
.dropzone.over, .dropzone:hover { border-color: var(--accent); background: #fff8f0; }
.file-list { list-style: none; padding: 0; margin: 0 0 1rem; display: grid; gap: 0.4rem; max-height: 14rem; overflow: auto; }
.file-list li { display: flex; align-items: center; gap: 0.6rem; padding: 0.3rem; background: #fff; border-radius: 8px; }
.file-list img { width: 3rem; height: 3rem; object-fit: cover; border-radius: 6px; }
.file-list .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
progress { width: 100%; margin-bottom: 1rem; accent-color: var(--accent); }

/* ---------- sign-in ---------- */

.signin { max-width: 30rem; margin: 10vh auto; text-align: center; display: grid; justify-items: center; gap: 0.75rem; }
.signin h1 { font-size: 2rem; }
.ms-logo { display: grid; grid-template-columns: 9px 9px; gap: 2px; }
.ms-logo i { width: 9px; height: 9px; background: #fff; }
.ms-logo i:nth-child(1) { background: #f25022; }
.ms-logo i:nth-child(2) { background: #7fba00; }
.ms-logo i:nth-child(3) { background: #00a4ef; }
.ms-logo i:nth-child(4) { background: #ffb900; }

/* ---------- headings, toolbar ---------- */

.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; margin-bottom: 1.25rem; flex-wrap: wrap; }
.page-head p { margin: 0.35rem 0 0; }
.page-head .desc { max-width: 60rem; margin-top: 0.5rem; }

/* ---------- Markdown (pack descriptions) ---------- */

.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md p, .md ul, .md ol, .md blockquote, .md pre { margin: 0.5rem 0; }
.md h3, .md h4, .md h5, .md h6 { margin: 1rem 0 0.35rem; }
.md h3 { font-size: 1.2rem; }
.md h4 { font-size: 1.05rem; }
.md h5, .md h6 { font-size: 0.95rem; color: var(--ink-2); }
.md ul, .md ol { padding-left: 1.4rem; }
.md li + li { margin-top: 0.15rem; }
.md li > ul, .md li > ol { margin: 0.15rem 0; }
.md blockquote { padding: 0.1rem 0 0.1rem 0.9rem; border-left: 3px solid var(--line); color: var(--ink-2); }
.md code { font: 0.88em ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; background: var(--cream); padding: 0.1em 0.35em; border-radius: 4px; }
.md pre { background: var(--cream); padding: 0.7rem 0.9rem; border-radius: 8px; overflow-x: auto; }
.md pre code { background: none; padding: 0; }
.md hr { border: 0; border-top: 1px solid var(--line); margin: 1rem 0; }
.md a { overflow-wrap: anywhere; }
.md-preview { margin: -0.4rem 0 1rem; padding: 0.7rem 0.9rem; border: 1px dashed var(--line); border-radius: 8px; background: var(--bg); max-height: 16rem; overflow-y: auto; font-size: 0.95rem; }
.md-preview::before { content: 'Preview'; display: block; font-size: 0.72rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; color: var(--ink-2); margin-bottom: 0.35rem; }
.head-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.crumbs { margin-bottom: 0.75rem; }
.crumbs a { text-decoration: none; }
.toolbar { display: flex; align-items: center; gap: 1.25rem; flex-wrap: wrap; padding: 0.6rem 0; margin-bottom: 1rem; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.toolbar #summary { margin-right: auto; }
.check { display: flex; align-items: center; gap: 0.4rem; cursor: pointer; }
.check input { accent-color: var(--accent); width: 1rem; height: 1rem; }
.sort { display: flex; align-items: center; gap: 0.4rem; }

.empty { text-align: center; padding: 3rem 1rem; color: var(--ink-2); display: grid; justify-items: center; gap: 0.75rem; }
.empty.wide { grid-column: 1 / -1; border: 2px dashed var(--line); border-radius: var(--radius); }

/* ---------- pack cards ---------- */

.pack-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 1.25rem; }
.pack-card {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  color: inherit;
  text-decoration: none;
  transition: transform 0.12s, box-shadow 0.12s;
}
.pack-card:hover { transform: translateY(-2px); box-shadow: 0 6px 24px rgb(59 36 22 / 14%); }
.cover { aspect-ratio: 16 / 10; display: grid; gap: 2px; background: var(--cream); }
.cover img { width: 100%; height: 100%; object-fit: cover; display: block; min-height: 0; }
.cover.n2 { grid-template-columns: 1fr 1fr; }
.cover.n3 { grid-template-columns: 2fr 1fr; grid-template-rows: 1fr 1fr; }
.cover.n3 img:first-child { grid-row: span 2; }
.cover.n4 { grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; }
.cover-empty { display: grid; place-items: center; color: var(--ink-2); font-size: 0.9rem; }
.pack-body { padding: 0.9rem 1rem 1rem; }
.pack-body h2 { font-size: 1.15rem; }
.pack-body .desc { margin: 0.3rem 0 0; color: var(--ink-2); display: -webkit-box; -webkit-line-clamp: 2; line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.pack-body .meta { margin: 0.6rem 0 0; font-size: 0.85rem; color: var(--ink-2); display: flex; align-items: center; gap: 0.3rem; flex-wrap: wrap; }
.badge { margin-left: auto; background: var(--accent); color: #fff; padding: 0.05rem 0.5rem; border-radius: 99px; font-size: 0.75rem; font-weight: 600; }

/* ---------- image cards ---------- */

.image-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 1.25rem; border-radius: var(--radius); }
.image-grid.dropping { outline: 3px dashed var(--accent); outline-offset: 6px; }
.image-card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; display: flex; flex-direction: column; }
.thumb { position: relative; display: block; padding: 0; border: 0; background: var(--cream); cursor: zoom-in; aspect-ratio: 4 / 3; }
.thumb img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; display: block; }
.rank { position: absolute; top: 0.5rem; left: 0.5rem; background: rgb(59 36 22 / 80%); color: var(--cream); font-size: 0.8rem; font-weight: 600; padding: 0.1rem 0.5rem; border-radius: 99px; }
.card-body { padding: 0.75rem 0.9rem 0.9rem; display: grid; gap: 0.3rem; }
.card-body p { margin: 0; }
.card-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 0.5rem; }
.card-top h3 { font-size: 1rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding-top: 0.3rem; }
.meta { font-size: 0.85rem; color: var(--ink-2); }
.warn { margin-left: 0.4rem; padding: 0 0.4rem; border-radius: 4px; background: var(--red-soft); color: var(--red); font-size: 0.75rem; font-weight: 600; }
.tag-license { margin-left: 0.4rem; padding: 0 0.4rem; border-radius: 4px; background: var(--moss-soft); color: var(--moss); font-size: 0.75rem; font-weight: 600; }
.credit { font-size: 0.85rem; }
.source { font-size: 0.85rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.voters { font-size: 0.8rem; display: flex; flex-direction: column; gap: 0.1rem; }
.voters .for { color: var(--moss); }
.voters .against { color: var(--red); }

/* ---------- voting ---------- */

.vote { display: inline-flex; align-items: center; gap: 0.15rem; background: var(--bg); border-radius: 99px; padding: 0.15rem; flex-shrink: 0; }
.vote-btn {
  width: 2rem;
  height: 2rem;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--ink-2);
  font-size: 0.85rem;
  cursor: pointer;
}
.vote-btn.up:hover { background: var(--moss-soft); color: var(--moss); }
.vote-btn.down:hover { background: var(--red-soft); color: var(--red); }
.vote-btn.up.on { background: var(--moss); color: #fff; }
.vote-btn.down.on { background: var(--red); color: #fff; }
.score { min-width: 2rem; text-align: center; font-weight: 700; font-variant-numeric: tabular-nums; }
.score.pos { color: var(--moss); }
.score.neg { color: var(--red); }

/* ---------- lightbox ---------- */

.dialog.lb-dialog { width: calc(100vw - 2rem); height: calc(100vh - 2rem); max-width: none; max-height: none; padding: 0; overflow: hidden; background: #1e140c; }
.lightbox { position: relative; height: 100%; display: grid; grid-template-columns: 1fr 22rem; height: 100%; }
.lb-stage { position: relative; display: grid; place-items: center; min-width: 0; min-height: 0; padding: 1rem 3.5rem; }
.lb-stage img { max-width: 100%; max-height: calc(100vh - 4rem); object-fit: contain; box-shadow: 0 10px 40px rgb(0 0 0 / 50%); }
.lb-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 2.75rem;
  height: 4rem;
  border: 0;
  border-radius: 8px;
  background: rgb(255 255 255 / 8%);
  color: var(--cream);
  font-size: 2rem;
  cursor: pointer;
}
.lb-nav:hover:not(:disabled) { background: rgb(255 255 255 / 18%); }
.lb-nav:disabled { opacity: 0.2; cursor: default; }
.lb-nav.prev { left: 0.5rem; }
.lb-nav.next { right: 0.5rem; }
.lb-side { background: var(--bg); padding: 1.5rem; overflow: auto; display: flex; flex-direction: column; gap: 0.75rem; }
.lb-side h2 { font-size: 1.3rem; overflow-wrap: anywhere; }
.lb-side .vote { align-self: flex-start; transform: scale(1.15); transform-origin: left center; }
.lb-side dl { display: grid; grid-template-columns: auto 1fr; gap: 0.35rem 0.75rem; margin: 0.5rem 0; font-size: 0.9rem; }
.lb-side dt { color: var(--ink-2); }
.lb-side dd { margin: 0; overflow-wrap: anywhere; }
.lb-side dd.license .license-actions { display: flex; flex-wrap: wrap; gap: 0.35rem; margin-top: 0.35rem; }
.lb-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.lb-side .hint { margin-top: auto; }
.lb-close { position: absolute; top: 0.75rem; right: 0.75rem; z-index: 1; }

@media (max-width: 800px) {
  .lightbox { grid-template-columns: 1fr; grid-template-rows: 55% 45%; }
  .lb-stage { padding: 0.5rem 3rem; }
  .lb-stage img { max-height: 100%; }
  .view { padding: 1rem; }
  .topbar { padding: 0.5rem 1rem; }
  .account-name { display: none; }
}

/* ---------- toasts ---------- */

.toasts { position: fixed; bottom: 1rem; left: 50%; transform: translateX(-50%); display: grid; gap: 0.5rem; z-index: 100; }
.toast { background: var(--ink); color: var(--cream); padding: 0.6rem 1rem; border-radius: 8px; box-shadow: var(--shadow); transition: opacity 0.5s; }
.toast.ok { background: var(--moss); color: #fff; }
.toast.error { background: var(--red); color: #fff; }
.toast.hide { opacity: 0; }
