:root {
  --bg: #121110;
  --surface: #1c1a18;
  --surface-2: #26231f;
  --line: #34302b;
  --text: #f1ece4;
  --muted: #a39c91;
  --accent: #e8a74a;
  --accent-ink: #1a1408;
  --ok: #7cc58a;
  --warn: #e6c062;
  --danger: #e2685a;
  --radius: 14px;
  --serif: 'Fraunces', Georgia, serif;
  --sans: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.55 var(--sans); }
img { max-width: 100%; display: block; }
a { color: var(--accent); }
h1, h2, h3 { font-family: var(--serif); font-weight: 600; line-height: 1.2; margin: 0 0 .6em; }
h1 { font-size: 1.9rem; }
h2 { font-size: 1.4rem; }
h3 { font-size: 1.05rem; font-family: var(--sans); }
code { background: var(--surface-2); padding: 1px 6px; border-radius: 6px; }
.wrap { width: 100%; max-width: 1180px; margin: 0 auto; padding: 0 16px; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.nowrap { white-space: nowrap; }
.center { text-align: center; }
.ok { color: var(--ok); }
.warn { color: var(--warn); }

/* header */
.site-header { border-bottom: 1px solid var(--line); background: rgba(18, 17, 16, .9); backdrop-filter: blur(8px); position: sticky; top: 0; z-index: 10; }
.header-row { display: flex; align-items: center; gap: 20px; min-height: 64px; flex-wrap: wrap; padding-top: 8px; padding-bottom: 8px; }
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); text-decoration: none; font-family: var(--serif); font-size: 1.25rem; font-weight: 700; }
.brand-mark { width: 22px; height: 22px; border-radius: 50%; border: 3px solid var(--accent); box-shadow: inset 0 0 0 4px var(--bg), inset 0 0 0 10px var(--accent); }
.badge { font: 600 .7rem var(--sans); text-transform: uppercase; letter-spacing: .08em; background: var(--accent); color: var(--accent-ink); padding: 2px 8px; border-radius: 99px; }
.nav { display: flex; gap: 4px; flex: 1; flex-wrap: wrap; }
.nav a { color: var(--muted); text-decoration: none; padding: 6px 12px; border-radius: 99px; font-weight: 500; }
.nav a:hover { color: var(--text); }
.nav a.active { background: var(--surface-2); color: var(--text); }
.nav .admin-link { color: var(--accent); }
.auth { margin-left: auto; min-height: 40px; display: flex; align-items: center; }
.user-chip { display: flex; align-items: center; gap: 8px; font-size: .9rem; }
.user-chip img { width: 28px; height: 28px; border-radius: 50%; }
.user-chip span { max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.banner { background: linear-gradient(90deg, rgba(232, 167, 74, .16), rgba(232, 167, 74, .04)); border-bottom: 1px solid var(--line); padding: 10px 0; font-size: .92rem; }

main { padding-top: 28px; padding-bottom: 64px; }
.loading, .empty { color: var(--muted); text-align: center; padding: 60px 0; }

/* buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid transparent; border-radius: 99px; padding: 9px 18px; font: 600 .9rem var(--sans); cursor: pointer; text-decoration: none; color: var(--text); background: var(--surface-2); transition: transform .1s, background .15s; }
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .55; cursor: wait; }
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: #f1b55e; }
.btn-ghost { background: transparent; border-color: var(--line); }
.btn-ghost:hover { border-color: var(--muted); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-wide { width: 100%; padding: 13px; font-size: 1rem; }
.btn-vote { background: var(--accent); color: var(--accent-ink); padding: 6px 16px; }
.danger { color: var(--danger) !important; }
.btn-ghost.danger { border-color: rgba(226, 104, 90, .5); }
.link-btn { background: none; border: 0; padding: 0 4px; color: var(--accent); cursor: pointer; font: inherit; text-decoration: underline; text-underline-offset: 3px; }
.icon-btn { background: none; border: 0; color: var(--muted); font-size: 1.3rem; cursor: pointer; line-height: 1; padding: 0 4px; }
.icon-btn:hover { color: var(--danger); }
.pill { font-size: .78rem; padding: 3px 10px; border-radius: 99px; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.pill.voted { background: rgba(124, 197, 138, .15); color: var(--ok); }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-top: 12px; }

/* gallery */
.gallery-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 22px; }
.tabs { display: inline-flex; background: var(--surface); border: 1px solid var(--line); border-radius: 99px; padding: 4px; }
.tab { background: none; border: 0; color: var(--muted); font: 600 .95rem var(--sans); padding: 8px 20px; border-radius: 99px; cursor: pointer; }
.tab.active { background: var(--accent); color: var(--accent-ink); }
.tab .count { opacity: .7; font-weight: 500; margin-left: 4px; }
.hint { color: var(--muted); margin: 0; font-size: .92rem; }

.grid { columns: 3 300px; column-gap: 18px; }
.card { break-inside: avoid; margin: 0 0 18px; background: var(--surface); border-radius: var(--radius); overflow: hidden; border: 1px solid var(--line); }
.img-btn { display: block; width: 100%; padding: 0; border: 0; background: var(--surface-2); cursor: zoom-in; }
.img-btn img { width: 100%; height: auto; }
.card figcaption { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 14px; min-height: 52px; }
.card .title { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.votes { font-weight: 600; color: var(--accent); white-space: nowrap; }

/* lightbox */
.lightbox { max-width: 96vw; max-height: 96vh; padding: 0; border: 0; background: transparent; color: var(--text); overflow: visible; }
.lightbox::backdrop { background: rgba(0, 0, 0, .9); }
.lightbox img { max-width: 94vw; max-height: 86vh; object-fit: contain; border-radius: 6px; margin: 0 auto; }
.lightbox-caption { text-align: center; color: var(--muted); margin: 10px 0 0; }
.lightbox-close { position: fixed; top: 14px; right: 18px; background: rgba(0, 0, 0, .5); color: #fff; border: 0; font-size: 2rem; width: 44px; height: 44px; border-radius: 50%; cursor: pointer; line-height: 1; }

/* panels & forms */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 24px; margin-bottom: 20px; }
.panel.narrow { max-width: 560px; margin-left: auto; margin-right: auto; }
.auth-inline { display: flex; justify-content: center; margin: 20px 0 8px; min-height: 44px; }
.form { display: grid; gap: 18px; margin-top: 18px; }
.field { display: grid; gap: 6px; font-weight: 500; font-size: .92rem; }
input:not([type=checkbox]):not([type=radio]):not([type=file]), select, textarea {
  width: 100%; background: var(--bg); color: var(--text); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; font: 400 .95rem var(--sans);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: transparent; }
.dropzone { position: relative; display: grid; place-items: center; min-height: 200px; border: 2px dashed var(--line); border-radius: var(--radius); text-align: center; cursor: pointer; overflow: hidden; padding: 16px; }
.dropzone:hover { border-color: var(--accent); }
.dropzone input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.dropzone img { max-height: 320px; border-radius: 8px; }
.dropzone.has-file .dz-text { display: none; }
.cat-choice { border: 0; padding: 0; margin: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.cat-choice legend { font-weight: 500; font-size: .92rem; margin-bottom: 6px; }
.cat-choice label { position: relative; cursor: pointer; }
.cat-choice input { position: absolute; opacity: 0; }
.cat-choice label span { display: grid; gap: 2px; border: 1px solid var(--line); border-radius: 12px; padding: 14px; background: var(--bg); }
.cat-choice small { color: var(--muted); }
.cat-choice input:checked + span { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); background: rgba(232, 167, 74, .08); }
.cat-choice input:focus-visible + span { outline: 2px solid var(--accent); }
.progress { position: relative; height: 34px; background: var(--bg); border-radius: 99px; overflow: hidden; border: 1px solid var(--line); }
.progress .bar { position: absolute; inset: 0 auto 0 0; width: 0; background: rgba(232, 167, 74, .35); transition: width .2s; }
.progress .ptext { position: relative; display: block; text-align: center; line-height: 32px; font-size: .88rem; }
.my-entry-img { border-radius: 10px; margin: 8px 0 16px; width: 100%; }
.details { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0 0 18px; }
.details dt { color: var(--muted); }
.details dd { margin: 0; }
.notice { border-radius: 12px; padding: 14px 18px; margin-bottom: 20px; background: var(--surface-2); text-align: center; }
.notice.left { text-align: left; }
.notice.error { background: rgba(226, 104, 90, .12); border: 1px solid rgba(226, 104, 90, .4); }
.notice.warn { background: rgba(230, 192, 98, .1); border: 1px solid rgba(230, 192, 98, .35); }
.notice ul { margin: 8px 0 0; padding-left: 20px; }

/* results */
.results { margin-bottom: 48px; }
.results h2 { font-size: 1.8rem; border-bottom: 1px solid var(--line); padding-bottom: 8px; }
.winners { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 18px; margin-bottom: 22px; }
.winner { margin: 0; background: var(--surface); border: 1px solid var(--accent); border-radius: var(--radius); overflow: hidden; box-shadow: 0 0 40px rgba(232, 167, 74, .12); }
.winner figcaption { display: grid; gap: 2px; padding: 14px 16px; }
.trophy { color: var(--accent); font-weight: 600; font-size: .85rem; text-transform: uppercase; letter-spacing: .06em; }
.ranking { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; }
.ranking li { display: grid; grid-template-columns: 34px 56px 1fr auto; align-items: center; gap: 12px; background: var(--surface); border-radius: 10px; padding: 6px 14px 6px 6px; }
.ranking .rank { text-align: center; font-family: var(--serif); font-size: 1.1rem; color: var(--muted); }
.ranking .thumb img { width: 56px; height: 42px; object-fit: cover; border-radius: 6px; }
.rtitle { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* admin */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; margin-bottom: 20px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 18px; color: var(--muted); font-size: .88rem; }
.stat span { display: block; font-family: var(--serif); font-size: 2rem; color: var(--text); line-height: 1.1; }
.controls { display: grid; gap: 14px; }
.controls .row { margin-top: 0; flex-wrap: nowrap; }
.switch { display: flex; align-items: center; gap: 10px; cursor: pointer; }
.switch input { width: 18px; height: 18px; accent-color: var(--accent); }
.end-row { border-top: 1px solid var(--line); padding-top: 16px; margin-top: 18px; }
.tally { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 24px; }
.tally ol { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; }
.tally li { display: grid; grid-template-columns: 48px 1fr auto; gap: 10px; align-items: center; }
.tally img { width: 48px; height: 36px; object-fit: cover; border-radius: 4px; }
.tally b { color: var(--accent); font-size: 1.1rem; }
.invites { list-style: none; padding: 0; margin: 16px 0 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 6px; }
.invites li { display: flex; align-items: center; gap: 8px; background: var(--bg); border-radius: 8px; padding: 6px 8px 6px 12px; }
.invites li > span:first-child { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.table-wrap { overflow-x: auto; margin-top: 12px; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th { text-align: left; color: var(--muted); font-weight: 500; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.thumb-sm { width: 64px; height: 48px; object-fit: cover; border-radius: 6px; }
#vote-filter { margin-top: 8px; }

/* footer & privacy page */
.site-footer { text-align: center; padding-bottom: 32px; font-size: .85rem; }
.site-footer a { color: var(--muted); }
.prose h2 { font-size: 1.15rem; margin-top: 1.6em; }
.prose ul { padding-left: 20px; }
.prose li { margin-bottom: 6px; }

/* toasts */
#toasts { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); display: grid; gap: 8px; z-index: 100; width: min(92vw, 440px); }
.toast { background: var(--surface-2); border: 1px solid var(--line); border-left: 4px solid var(--accent); padding: 12px 16px; border-radius: 10px; box-shadow: 0 8px 30px rgba(0, 0, 0, .4); transition: opacity .4s, transform .4s; }
.toast.success { border-left-color: var(--ok); }
.toast.error { border-left-color: var(--danger); }
.toast.out { opacity: 0; transform: translateY(8px); }

@media (max-width: 640px) {
  h1 { font-size: 1.5rem; }
  .header-row { gap: 10px; }
  .nav { order: 3; flex-basis: 100%; }
  .auth { margin-left: auto; }
  .panel { padding: 18px; }
  .grid { columns: 1; }
  .gallery-head { flex-direction: column; align-items: stretch; }
  .tabs { justify-content: center; }
  .tab { flex: 1; }
  .cat-choice { grid-template-columns: 1fr; }
}
