/* Every card is an Instagram portrait post, 4:5. The list is sized as the
   profile grid shows posts. The podium and places 4-10 stay put at the top
   and are sized off the window's height so they always fit; only the list
   scrolls beneath them. */
:root {
  --bg: #fafafa;
  --fg: #262626;
  --muted: #737373;
  --line: #dbdbdb;
  --grid-w: 309px;
  --gold: #e8b923;
  --silver: #b7bcc4;
  --bronze: #c98a4b;
  --gold-h: 18vh;
  --runner-h: 9vh;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

.top { position: relative; flex: none; border-bottom: 1px solid var(--line); padding-bottom: 6px; }
.scroll { flex: 1; overflow-y: auto; }

.logout { position: absolute; top: 10px; right: 16px; color: var(--muted); font-size: 13px; }

h2 {
  max-width: 1300px;
  margin: 16px auto 0;
  padding: 0 16px;
  font-size: 18px;
  font-weight: 600;
}
h2 span { color: var(--muted); font-weight: 400; }

/* Card faces: the pool's cards and whatever sits in a place. */
.card, .place .face {
  position: relative;
  margin: 0;
  aspect-ratio: 4 / 5;
  border-radius: 6px;
  overflow: hidden;
  background: #ddd;
  user-select: none;
}
.card img, .place .face img { width: 100%; height: 100%; object-fit: cover; display: block; }
.card figcaption, .place .face figcaption {
  position: absolute;
  inset: auto 0 0 0;
  padding: 32px 12px 10px;
  background: linear-gradient(transparent, rgb(0 0 0 / .7));
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  line-height: 1.25;
}
.place .face figcaption { font-size: clamp(10px, 1.4vh, 14px); padding: 20px 8px 6px; }
.runner .face figcaption { display: none; }

/* The podium: 2, 1, 3 side by side, first place tallest. */
#podium {
  display: flex;
  justify-content: center;
  align-items: flex-end;
  gap: 12px;
  padding: calc(4px + 2.6vh) 16px 0;
}
.step { display: flex; flex-direction: column; }
.step .place { height: calc(var(--gold-h) * .85); }
.step-1 .place { height: var(--gold-h); }
.block {
  display: grid;
  place-items: center;
  color: #fff;
  font-size: 1.8vh;
  line-height: 1;
  font-weight: 700;
  border-radius: 0 0 6px 6px;
}
.step-1 .block { height: 3.6vh; background: var(--gold); }
.step-2 .block { height: 2.8vh; background: var(--silver); }
.step-3 .block { height: 2.4vh; background: var(--bronze); }

#runners {
  display: flex;
  justify-content: center;
  gap: 8px;
  padding: 8px 16px 0;
}
.runner .place { height: var(--runner-h); }
.runner-no { text-align: center; color: var(--muted); font-weight: 600; font-size: 12px; line-height: 1.2; }

/* A place: empty, it is a dashed outline of a card. */
.place {
  aspect-ratio: 4 / 5;
  position: relative;
  border: 2px dashed var(--line);
  border-radius: 8px;
  transition: border-color .15s, background .15s;
}
.place:has(.face) { border: none; }
.place .face { height: 100%; }
.place .remove {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 26px;
  height: 26px;
  border: none;
  border-radius: 50%;
  background: rgb(0 0 0 / .55);
  color: #fff;
  font-size: 16px;
  line-height: 26px;
  cursor: pointer;
}
.place.over { border: 2px solid var(--fg); background: rgb(0 0 0 / .04); }

/* The list of all cards: fixed order, never rearranged. */
#pool {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, var(--grid-w)), var(--grid-w)));
  justify-content: center;
  gap: 4px;
  padding: 16px 16px 48px;
}
#pool.over { outline: 2px dashed var(--line); outline-offset: -8px; }
.card { border-radius: 0; }
.card .badge {
  display: none;
  position: absolute;
  top: 8px;
  left: 8px;
  min-width: 32px;
  padding: 4px 8px;
  border-radius: 16px;
  background: var(--fg);
  color: #fff;
  font-weight: 700;
  text-align: center;
}
.card.placed img { opacity: .35; }
.card.placed .badge { display: block; }

/* A phone: places 4-10 shrink to fit the width in one row. */
@media (max-width: 700px) {
  :root { --gold-h: 16vh; }
  #runners { gap: 4px; padding-inline: 8px; }
  .runner .place { height: auto; width: calc((100vw - 16px - 6 * 4px) / 7); }
  .card figcaption { font-size: 12px; padding: 24px 8px 6px; }
}

/* The login page. */
body.login { display: grid; place-items: center; }
.login form { display: flex; flex-direction: column; gap: 10px; width: min(320px, 100% - 32px); }
.login input, .login button { font: inherit; padding: 10px 12px; border-radius: 6px; border: 1px solid var(--line); }
.login button { background: var(--fg); color: #fff; border: none; cursor: pointer; font-weight: 600; }
.login .error { color: #c0392b; margin: 0; text-align: center; }

/* A card landing on a place: it pops in, and the medal places glow. */
.particle {
  position: fixed;
  z-index: 10;
  pointer-events: none;
  line-height: 1;
  text-shadow: 0 0 6px currentColor;
  opacity: 0;  /* left over once its animation ends */
}
.face.landed { animation: land .6s cubic-bezier(.3, 1.6, .5, 1); }
.face.landed-1 { animation: land-gold 1.2s cubic-bezier(.3, 1.6, .5, 1); }
@keyframes land {
  from { transform: scale(.5); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}
@keyframes land-gold {
  0% { transform: scale(.3) rotate(-8deg); opacity: 0; }
  40% { transform: scale(1.15) rotate(3deg); opacity: 1; }
  70% { transform: scale(.97) rotate(-1deg); }
  100% { transform: scale(1) rotate(0); }
}
.step-1 .face { animation: glow-gold 2.4s ease-in-out infinite; }
.step-2 .face { box-shadow: 0 0 14px 2px rgb(183 188 196 / .8); }
.step-3 .face { box-shadow: 0 0 12px 1px rgb(201 138 75 / .6); }
.step-1 .face.landed-1 { animation: land-gold 1.2s cubic-bezier(.3, 1.6, .5, 1), glow-gold 2.4s 1.2s ease-in-out infinite; }
@keyframes glow-gold {
  0%, 100% { box-shadow: 0 0 10px 2px rgb(232 185 35 / .55); }
  50% { box-shadow: 0 0 26px 8px rgb(255 215 0 / .9); }
}
.step-1 .place:has(.face)::before {
  content: "👑";
  position: absolute;
  z-index: 2;
  top: -2.6vh;
  left: 50%;
  translate: -50% 0;
  font-size: 2.8vh;
  rotate: -12deg;
  filter: drop-shadow(0 2px 3px rgb(0 0 0 / .3));
}
@media (prefers-reduced-motion: reduce) {
  .face.landed, .face.landed-1, .step-1 .face { animation: none; }
}

/* The viewer: the whole photo, uncropped, over a dimmed page. */
.card, .place .face { cursor: pointer; }
#viewer {
  padding: 0;
  border: none;
  background: transparent;
  max-width: 100vw;
  max-height: 100dvh;
  text-align: center;
  cursor: zoom-out;
  outline: none;
}
#viewer::backdrop { background: rgb(0 0 0 / .85); }
#viewer[open] { animation: land .25s ease-out; }
#viewer img { display: block; max-width: 94vw; max-height: 86dvh; margin: auto; border-radius: 6px; }
#viewer p { margin: 10px 0 0; color: #fff; font-size: 17px; font-weight: 600; }
