:root {
  --ink: #17131f;
  --ink-raise: #221b2e;
  --haze: #3a3048;
  --light: #f0ecf5;
  --dim: #9a90ab;
  --candle: #e9b44c;
  --danger: #d0596a;
  --ok: #6fbf8b;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue",
    Arial, sans-serif;
  --serif: ui-serif, "New York", Georgia, "Times New Roman", serif;
  --gutter: 20px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--ink);
  color: var(--light);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

body { min-height: 100dvh; }

a { color: var(--candle); text-decoration: none; }

button {
  font: inherit;
  color: inherit;
  border: 0;
  background: none;
  cursor: pointer;
}

:focus-visible {
  outline: 2px solid var(--candle);
  outline-offset: 3px;
}

.num { font-variant-numeric: tabular-nums; }

/* ---------- shared chrome ---------- */

.masthead {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 18px var(--gutter);
  font-size: 13px;
  letter-spacing: 0.04em;
  color: var(--dim);
}

.masthead b {
  color: var(--light);
  font-weight: 600;
  letter-spacing: 0.06em;
}

.langs { display: flex; gap: 2px; }

.langs button {
  padding: 4px 7px;
  border-radius: 4px;
  font-size: 12px;
  color: var(--dim);
}

.langs button[aria-pressed="true"] {
  color: var(--ink);
  background: var(--candle);
}

.stack {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}

.center {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 0 var(--gutter) 40px;
  text-align: center;
}

/* ---------- upload page ---------- */

.shutter {
  position: relative;
  width: min(62vw, 240px);
  aspect-ratio: 1;
  border-radius: 50%;
  border: 2px solid var(--candle);
  display: grid;
  place-items: center;
  transition: transform 140ms ease, background-color 140ms ease;
}

.shutter::after {
  content: "";
  position: absolute;
  inset: 12px;
  border-radius: 50%;
  border: 1px solid rgba(233, 180, 76, 0.28);
}

.shutter:active { transform: scale(0.96); background: rgba(233, 180, 76, 0.1); }

.shutter span {
  width: 42%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: var(--candle);
}

.shutter-label {
  margin-top: 26px;
  font-size: 19px;
  font-weight: 600;
}

.caption {
  margin-top: 10px;
  color: var(--dim);
  font-size: 14px;
  line-height: 1.5;
  max-width: 34ch;
}

.gallery-link {
  margin-top: 14px;
  width: min(84vw, 320px);
}

#gallery-btn {
  margin-top: 26px;
}

.back-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

/* ---------- entry / landing ---------- */

.entry-tiles {
  display: flex;
  flex-direction: column;
  gap: 14px;
  width: min(88vw, 360px);
}

.entry-tile {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 22px 24px;
  background: var(--ink-raise);
  border: 1px solid var(--haze);
  color: var(--light);
  font-size: 18px;
  font-weight: 600;
  text-align: left;
}

.entry-tile:active { background: var(--haze); }

.entry-tile svg {
  width: 26px;
  height: 26px;
  flex-shrink: 0;
  color: var(--candle);
}

/* ---------- progress ---------- */

.queue {
  width: min(100%, 420px);
  margin-top: 30px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.queue-row {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 14px;
  color: var(--dim);
  text-align: left;
}

.bar {
  flex: 1;
  height: 3px;
  background: var(--haze);
  overflow: hidden;
}

.bar i {
  display: block;
  height: 100%;
  width: 0;
  background: var(--candle);
  transition: width 200ms linear;
}

.queue-row.done .bar i { background: var(--ok); }
.queue-row.failed .bar i { background: var(--danger); width: 100% !important; }

/* ---------- name sheet ---------- */

.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(10, 8, 14, 0.82);
  display: grid;
  place-items: end center;
  z-index: 40;
}

.sheet-backdrop[hidden] { display: none; }

.sheet {
  width: 100%;
  max-width: 460px;
  background: var(--ink-raise);
  border-top: 1px solid var(--haze);
  padding: 26px var(--gutter) calc(26px + env(safe-area-inset-bottom));
}

.sheet h2 { margin: 0 0 6px; font-size: 20px; font-weight: 600; }
.sheet p { margin: 0 0 18px; color: var(--dim); font-size: 14px; line-height: 1.5; }

.qr-image {
  display: block;
  width: min(70vw, 280px);
  margin: 18px auto;
  background: #fff;
  padding: 14px;
}

input[type="text"], input[type="password"] {
  width: 100%;
  padding: 14px 16px;
  background: var(--ink);
  border: 1px solid var(--haze);
  color: var(--light);
  font: inherit;
  font-size: 17px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 14px 22px;
  background: var(--candle);
  color: #241a05;
  font-weight: 600;
  font-size: 16px;
}

.btn:active { filter: brightness(0.92); }
.btn.wide { width: 100%; margin-top: 14px; }
.btn.quiet { background: transparent; color: var(--light); border: 1px solid var(--haze); }

/* ---------- gallery ---------- */

.grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 3px;
  padding: 0 3px 90px;
}

@media (min-width: 620px) { .grid { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 980px) { .grid { grid-template-columns: repeat(4, 1fr); } }

.tile {
  position: relative;
  display: block;
  width: 100%;
  aspect-ratio: 1;
  background: var(--ink-raise);
  overflow: hidden;
}

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

.tile .count {
  position: absolute;
  left: 8px;
  bottom: 8px;
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 3px 8px 3px 6px;
  background: rgba(15, 12, 20, 0.62);
  backdrop-filter: blur(6px);
  font-size: 13px;
  font-weight: 600;
}

.tile .count.mine { color: var(--candle); }

.tile .rank-badge {
  position: absolute;
  top: 8px;
  left: 8px;
  padding: 3px 7px;
  background: rgba(15, 12, 20, 0.62);
  backdrop-filter: blur(6px);
  font-size: 12px;
  font-weight: 600;
  color: var(--candle);
}

.gallery-tabs {
  display: flex;
  gap: 8px;
  padding: 4px var(--gutter) 14px;
}

.gallery-tabs .tab {
  padding: 8px 16px;
  border: 1px solid var(--haze);
  color: var(--dim);
  font-size: 14px;
}

.gallery-tabs .tab[aria-pressed="true"] {
  border-color: var(--candle);
  color: var(--candle);
}

.empty {
  padding: 60px var(--gutter);
  text-align: center;
  color: var(--dim);
  line-height: 1.6;
}

/* ---------- viewer ---------- */

.viewer {
  position: fixed;
  inset: 0;
  background: #0c0911;
  z-index: 50;
  display: flex;
  flex-direction: column;
}

.viewer[hidden] { display: none; }

.viewer-stage {
  flex: 1;
  display: grid;
  place-items: center;
  overflow: hidden;
}

.viewer-stage img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.viewer-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px var(--gutter) calc(20px + env(safe-area-inset-bottom));
}

.author { color: var(--dim); font-size: 14px; }

.heart {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 10px 18px;
  border: 1px solid var(--haze);
  font-size: 17px;
  font-weight: 600;
}

.heart[aria-pressed="true"] {
  border-color: var(--candle);
  color: var(--candle);
}

.heart svg { width: 22px; height: 22px; }
.heart[aria-pressed="true"] svg { fill: var(--candle); }
.heart.pop svg { animation: pop 320ms ease; }

@keyframes pop {
  0% { transform: scale(1); }
  45% { transform: scale(1.35); }
  100% { transform: scale(1); }
}

.viewer-close {
  position: absolute;
  top: 8px;
  right: 8px;
  padding: 12px 16px;
  font-size: 22px;
  color: var(--light);
  z-index: 2;
}

/* ---------- projector screen ---------- */

.projector {
  position: fixed;
  inset: 0;
  background: #000;
  overflow: hidden;
}

.slide {
  position: absolute;
  inset: 0;
  opacity: 0;
  transition: opacity 1200ms ease;
  background-size: contain;
  background-position: center;
  background-repeat: no-repeat;
}

.slide.on { opacity: 1; }

.slide-blur {
  position: absolute;
  inset: -6%;
  background-size: cover;
  background-position: center;
  filter: blur(46px) brightness(0.32) saturate(0.7);
  z-index: -1;
}

.projector-foot {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 34px 40px;
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.72));
}

.projector-names {
  font-family: var(--serif);
  font-size: clamp(28px, 4vw, 52px);
  line-height: 1.05;
}

.projector-meta { color: rgba(255, 255, 255, 0.7); font-size: 17px; margin-top: 6px; }

.projector-invite {
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  width: 120px;
  gap: 8px;
  text-align: center;
  font-size: 12px;
  color: rgba(255, 255, 255, 0.78);
  margin-right: 16px;
}

.projector-invite img {
  width: 108px;
  height: 108px;
  background: #fff;
  padding: 6px;
  align-self: center;
}

/* ---------- screen: top button + leaderboard overlay ---------- */

.screen-top-btn {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 10;
  padding: 10px 18px;
  background: rgba(15, 12, 20, 0.6);
  backdrop-filter: blur(6px);
  border: 1px solid var(--haze);
  color: var(--light);
  font-size: 14px;
  font-weight: 600;
}

.leaderboard-view {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: #050308;
  overflow-y: auto;
  padding: 90px 40px 60px;
  display: none;
}

.leaderboard-view.show { display: block; }

.leaderboard-back {
  position: fixed;
  top: 20px;
  left: 20px;
  z-index: 21;
}

.podium {
  display: flex;
  justify-content: center;
  align-items: flex-end;
  gap: 28px;
  flex-wrap: wrap;
  margin: 0 0 56px;
}

.podium-card { text-align: center; cursor: pointer; }

.podium-card img {
  width: min(26vw, 280px);
  aspect-ratio: 1;
  object-fit: cover;
  border: 2px solid var(--haze);
}

.podium-card.rank-1 img {
  width: min(32vw, 360px);
  border-color: var(--candle);
  border-width: 3px;
}

.podium-card.rank-2 img, .podium-card.rank-3 img {
  border-color: rgba(233, 180, 76, 0.5);
}

.podium-rank {
  margin-top: 14px;
  font-family: var(--serif);
  font-size: clamp(24px, 3vw, 34px);
  color: var(--candle);
}

.podium-likes { margin-top: 2px; font-size: 15px; color: var(--light); }
.podium-author { margin-top: 2px; font-size: 14px; color: var(--dim); }

.rest-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 14px;
  max-width: 1200px;
  margin: 0 auto;
}

.rest-tile {
  position: relative;
  aspect-ratio: 1;
  cursor: pointer;
  background: var(--ink-raise);
}

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

.rest-tile .rank-badge, .rest-tile .likes-badge {
  position: absolute;
  padding: 2px 7px;
  font-size: 12px;
  font-weight: 600;
  background: rgba(15, 12, 20, 0.65);
  backdrop-filter: blur(4px);
}

.rest-tile .rank-badge { top: 6px; left: 6px; color: var(--candle); }
.rest-tile .likes-badge { bottom: 6px; right: 6px; color: var(--light); }

.lb-viewer {
  position: fixed;
  inset: 0;
  z-index: 30;
  background: #000;
  display: none;
  align-items: center;
  justify-content: center;
}

.lb-viewer.show { display: flex; }

.lb-viewer img { max-width: 94vw; max-height: 94vh; object-fit: contain; }

@media (max-width: 620px) {
  .leaderboard-view { padding: 80px 16px 40px; }
  .podium { gap: 14px; }
}

/* ---------- top ten ---------- */

.reveal {
  position: fixed;
  inset: 0;
  background: var(--ink);
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.25fr);
  align-items: center;
  gap: clamp(20px, 5vw, 70px);
  padding: clamp(20px, 5vw, 70px);
}

.reveal-rank {
  text-align: right;
}

.rank-number {
  font-family: var(--serif);
  font-size: clamp(90px, 20vw, 260px);
  line-height: 0.82;
  color: var(--candle);
  font-variant-numeric: tabular-nums;
}

.rank-votes {
  margin-top: 18px;
  font-size: clamp(16px, 2vw, 24px);
  color: var(--dim);
}

.rank-author {
  margin-top: 4px;
  font-size: clamp(18px, 2.4vw, 30px);
}

.reveal-photo {
  max-height: 84dvh;
  max-width: 100%;
  object-fit: contain;
  justify-self: start;
}

.reveal-hint {
  position: fixed;
  bottom: 22px;
  left: 0;
  right: 0;
  text-align: center;
  color: var(--haze);
  font-size: 14px;
}

.fade-in { animation: fade 520ms ease; }

@keyframes fade {
  from { opacity: 0; transform: translateY(14px); }
  to { opacity: 1; transform: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

/* ---------- admin ---------- */

.admin {
  max-width: 1080px;
  margin: 0 auto;
  padding: 0 var(--gutter) 60px;
}

.admin h1 { font-size: 22px; font-weight: 600; margin: 8px 0 22px; }
.admin h2 { font-size: 15px; font-weight: 600; color: var(--dim); margin: 34px 0 12px; }

.stats {
  display: flex;
  flex-wrap: wrap;
  gap: 28px;
  padding: 18px 0;
  border-top: 1px solid var(--haze);
  border-bottom: 1px solid var(--haze);
}

.stat b { display: block; font-size: 26px; font-weight: 600; }
.stat span { font-size: 13px; color: var(--dim); }

.switches { display: flex; flex-wrap: wrap; gap: 10px; margin: 18px 0; }

.switch {
  padding: 9px 15px;
  border: 1px solid var(--haze);
  font-size: 14px;
  color: var(--dim);
}

.switch[aria-pressed="true"] {
  border-color: var(--candle);
  color: var(--candle);
}

.mod-list { display: flex; flex-direction: column; gap: 14px; }

.mod {
  display: grid;
  grid-template-columns: 120px minmax(0, 1fr) auto;
  gap: 16px;
  align-items: center;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--haze);
}

.mod img { width: 120px; height: 120px; object-fit: cover; background: var(--ink-raise); }
.mod-meta { font-size: 14px; color: var(--dim); line-height: 1.6; }
.mod-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }

.mini {
  padding: 9px 14px;
  border: 1px solid var(--haze);
  font-size: 14px;
}

.mini.go { border-color: var(--ok); color: var(--ok); }
.mini.no { border-color: var(--danger); color: var(--danger); }

.leaderboard { display: flex; flex-direction: column; gap: 2px; }

.lb-row {
  display: grid;
  grid-template-columns: 34px 54px minmax(0, 1fr) auto;
  gap: 14px;
  align-items: center;
  padding: 7px 0;
  font-size: 15px;
}

.lb-row img { width: 54px; height: 54px; object-fit: cover; }
.lb-row .rank { color: var(--candle); font-weight: 600; }
.lb-row .votes { font-weight: 600; }

@media (max-width: 620px) {
  .reveal { grid-template-columns: 1fr; text-align: center; }
  .reveal-rank { text-align: center; }
  .reveal-photo { justify-self: center; max-height: 46dvh; }
  .mod { grid-template-columns: 84px minmax(0, 1fr); }
  .mod img { width: 84px; height: 84px; }
  .mod-actions { grid-column: 1 / -1; justify-content: flex-start; }
}
