/* Tokens: see DESIGN.md. Do not add values that aren't there. */
@font-face {
  font-family: "Pirata One";
  src: url("/fonts/pirata-one-latin.woff2") format("woff2");
  font-display: swap;
}
@font-face {
  font-family: "EB Garamond";
  src: url("/fonts/eb-garamond-latin.woff2") format("woff2");
  font-weight: 400 800;
  font-display: swap;
}
@font-face {
  font-family: "EB Garamond";
  src: url("/fonts/eb-garamond-italic-latin.woff2") format("woff2");
  font-weight: 400 800;
  font-style: italic;
  font-display: swap;
}

:root {
  --night: #140f1c;
  --night-2: #1f1729;
  --rule: #3a2e49;
  --parchment: #efe4cc;
  --parchment-dim: #b9aec4;
  --gilt: #d9b65d;
  --gilt-ink: #1c1405;
  --violet: #8f73cf;
  --ok: #9ad48f;
  --wait: #e9c46a;
  --danger: #f08a8f;
  --scrim: rgba(10, 7, 14, 0.98);
  --band-shade: linear-gradient(to bottom, rgba(20, 15, 28, 0.45) 0%, rgba(20, 15, 28, 0.55) 45%, #140f1c 100%);

  --fs-small: 16px;
  --fs-body: 20px;
  --fs-lead: 24px;
  --fs-h2: 40px;
  --fs-h1: 44px;

  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 24px; --s6: 32px; --s7: 48px; --s8: 64px;
  --r-photo: 0;
  --r-ctl: 10px;
  --r-pill: 999px;
  --shadow: 0 16px 48px rgba(0, 0, 0, 0.55);

  --gutter: var(--s4);
  --display: "Pirata One", Georgia, serif;
  --serif: "EB Garamond", Georgia, "Times New Roman", serif;
  color-scheme: dark;
}
@media (min-width: 960px) {
  :root { --gutter: 40px; --fs-h1: 80px; }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  background: var(--night);
  color: var(--parchment);
  font: 400 var(--fs-body)/1.5 var(--serif);
  font-variant-numeric: oldstyle-nums;
  -webkit-tap-highlight-color: transparent;
}
img { display: block; max-width: 100%; }
button, input { font: inherit; color: inherit; }
a { color: var(--parchment); text-underline-offset: 0.2em; text-decoration-thickness: 1px; }
:focus-visible { outline: 3px solid var(--gilt); outline-offset: 3px; }
main:focus { outline: none; }
h1, h2 { font-family: var(--display); font-weight: 400; margin: 0; text-wrap: balance; }

.skip {
  position: absolute; left: var(--s4); top: -100px; z-index: 10;
  padding: var(--s3) var(--s4); background: var(--gilt); color: var(--gilt-ink); border-radius: var(--r-ctl);
}
.skip:focus { top: var(--s4); }

/* ---------- Poster band: logo, title, prize. Slim, so photos start on the first screen ---------- */
.band { position: relative; height: 176px; overflow: hidden; }
.band-art { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; object-position: 50% 24%; }
.band::after { content: ""; position: absolute; inset: 0; background: var(--band-shade); }
.band-inner {
  position: relative; z-index: 1; height: 100%; max-width: 1240px; margin-inline: auto;
  display: flex; flex-direction: column; justify-content: space-between; padding: var(--s2) var(--gutter) var(--s4);
}
.band-top { display: flex; align-items: center; justify-content: space-between; }
.logo { display: inline-flex; align-items: center; min-height: 48px; border-radius: var(--r-ctl); }
.logo img { width: 112px; height: auto; }
.top-link { display: none; }
h1 { font-size: var(--fs-h1); line-height: 1; color: var(--parchment); }
.prize { margin: var(--s1) 0 0; font-style: italic; font-weight: 500; font-size: var(--fs-body); line-height: 1.3; color: var(--gilt); }
body[data-route="enter"] .band { display: none; }
body[data-stage="winners"] .prize { display: none; }

/* ---------- Lead: the one action or one line for this stage ---------- */
#lead { display: grid; gap: var(--s3); padding: var(--s4) var(--gutter); max-width: 1240px; margin-inline: auto; }
#lead:empty { display: none; }
body[data-route="enter"] #lead { display: none; }
.note { margin: 0; font-size: var(--fs-lead); font-weight: 600; line-height: 1.3; text-align: center; }
.note span { display: block; color: var(--parchment-dim); font-size: var(--fs-body); font-weight: 400; }

@media (min-width: 960px) {
  .band { height: 280px; }
  .logo img { width: 128px; }
  .top-link {
    display: inline-flex; align-items: center; min-height: 48px; padding-inline: var(--s2);
    font-size: var(--fs-body); text-decoration: none; border-radius: var(--r-ctl);
  }
  .top-link:hover { text-decoration: underline; }
  .prize { font-size: var(--fs-lead); }
  #lead { grid-template-columns: auto 1fr; align-items: center; padding-block: var(--s5); }
  #lead > * { grid-column: 1 / -1; }
  #lead > .btn { grid-column: auto; justify-self: start; min-width: 320px; }
  .note { text-align: left; }
}
/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s3);
  min-height: 64px; padding: var(--s3) var(--s6); border-radius: var(--r-ctl);
  font-size: var(--fs-lead); font-weight: 600; line-height: 1.2; text-decoration: none; text-align: center;
  border: 1px solid transparent; cursor: pointer; transition: transform 0.1s ease, background-color 0.15s ease;
}
.btn:active { transform: scale(0.98); }
.btn[disabled] { opacity: 0.5; cursor: default; }
.btn-primary { background: var(--gilt); color: var(--gilt-ink); }
.btn-primary:hover { background: var(--parchment); }
.btn-ghost { background: transparent; color: var(--parchment); border-color: var(--rule); }
.btn-ghost:hover { border-color: var(--parchment-dim); }
.btn-block { width: 100%; }
.btn svg { width: 28px; height: 28px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
@media (min-width: 960px) { #lead .btn-block { justify-self: start; width: auto; min-width: 320px; } }

/* ---------- Your entry ---------- */
.mine { display: grid; gap: var(--s3); text-align: left; }
.mine-row {
  display: grid; grid-template-columns: 64px 1fr; gap: var(--s4); align-items: center;
  padding: var(--s3); background: var(--night-2); border-radius: var(--r-ctl);
}
.mine-row img { width: 64px; aspect-ratio: 4 / 5; object-fit: cover; border-radius: calc(var(--r-ctl) - 4px); background: var(--rule); }
.mine-row .status { margin: 0; font-size: var(--fs-lead); font-weight: 600; line-height: 1.2; }
.mine-row .sub { margin: var(--s1) 0 0; color: var(--parchment-dim); font-size: var(--fs-body); line-height: 1.3; }
.mine-row .link {
  display: inline-flex; align-items: center; min-height: 44px; margin-top: var(--s1); padding: 0;
  background: none; border: 0; cursor: pointer; font-size: var(--fs-body); font-weight: 600;
  color: var(--parchment); text-decoration: underline; text-underline-offset: 0.2em; text-decoration-thickness: 1px;
}
.status-pending { color: var(--wait); }
.status-approved { color: var(--ok); }
.status-rejected { color: var(--danger); }
.status-late { color: var(--parchment-dim); }

/* ---------- Gallery ---------- */
.gallery { padding-bottom: var(--s8); }
.grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 2px; }
@media (min-width: 640px) { .grid { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 960px) {
  .gallery { max-width: 1240px; margin-inline: auto; padding-inline: var(--gutter); }
  .grid { grid-template-columns: repeat(4, 1fr); gap: var(--s1); }
}
.tile {
  position: relative; display: block; width: 100%; padding: 0; border: 0; cursor: zoom-in;
  aspect-ratio: 4 / 5; border-radius: var(--r-photo); overflow: hidden; background: var(--night-2);
}
.tile img { width: 100%; height: 100%; object-fit: cover; transition: transform 0.4s ease; }
@media (hover: hover) { .tile:hover img { transform: scale(1.03); } }
.tile.voted::after { content: ""; position: absolute; inset: 0; box-shadow: inset 0 0 0 4px var(--violet); }
.tile:focus-visible { outline-offset: -3px; }
.tile.skeleton { cursor: default; animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.55; } }

.empty { padding: var(--s7) var(--gutter) var(--s8); text-align: center; }
.empty h2 { font-size: var(--fs-h2); }
.empty p { margin: var(--s2) 0 0; color: var(--parchment-dim); font-size: var(--fs-lead); }

/* ---------- Winners: the photos are the page ---------- */
.winners { display: grid; grid-template-columns: 1fr 1fr; gap: 2px; margin: 0 calc(-1 * var(--gutter)); }
.winner { position: relative; margin: 0; }
.winner .tile { border-radius: var(--r-photo); }
.winner figcaption {
  position: absolute; inset: auto 0 0; display: grid; justify-items: center; gap: var(--s1);
  padding: var(--s7) var(--s3) var(--s3); pointer-events: none; text-align: center;
  background: linear-gradient(to top, rgba(20, 15, 28, 0.92), rgba(20, 15, 28, 0));
  font-size: var(--fs-body); font-weight: 600; line-height: 1.2; color: var(--parchment);
}
.winner .place { font: 400 var(--fs-h2)/1 var(--display); color: var(--gilt); }
@media (min-width: 960px) {
  .winners { margin: 0; gap: var(--s2); max-width: 880px; width: 100%; justify-self: center; }
  .winner .tile { border-radius: var(--r-ctl); }
  .winner figcaption { font-size: var(--fs-lead); border-radius: 0 0 var(--r-ctl) var(--r-ctl); }
}
/* ---------- Enter form ---------- */
.form-closed { min-height: 0; padding-top: var(--s7); }
/* The whole form fits one phone screen below the 72px header; the photo area takes what is left. */
.form {
  display: flex; flex-direction: column; gap: var(--s3); max-width: 34rem; margin-inline: auto;
  min-height: calc(100svh - 72px); padding: 0 var(--gutter) var(--s4);
}
@media (min-width: 960px) { .form { min-height: calc(100vh - 96px); } }
.form-head { display: flex; align-items: center; gap: var(--s2); margin-left: calc(-1 * var(--s3)); }
.form h2 { font-size: var(--fs-h2); line-height: 1.05; }
.back {
  display: inline-grid; place-items: center; width: 48px; height: 48px; flex: none;
  text-decoration: none; border-radius: var(--r-ctl);
}
.back svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.picker {
  position: relative; display: grid; place-items: center; width: 100%; flex: 1 1 0; min-height: 140px;
  border-radius: var(--r-ctl); background: var(--night-2); cursor: pointer; overflow: hidden;
  box-shadow: inset 0 0 0 1px var(--rule), inset 0 0 0 10px var(--night-2), inset 0 0 0 11px var(--gilt);
}
.picker:focus-within { outline: 3px solid var(--gilt); outline-offset: 3px; }
.picker input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.picker .ph { display: grid; gap: var(--s3); justify-items: center; padding: var(--s5); text-align: center; pointer-events: none; }
.picker .ph svg { width: 56px; height: 56px; fill: none; stroke: var(--gilt); stroke-width: 1.4; stroke-linecap: round; stroke-linejoin: round; }
.picker .ph strong { font-size: var(--fs-lead); font-weight: 600; }
.picker .ph span { color: var(--parchment-dim); font-size: var(--fs-body); }
.picker img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; pointer-events: none; }
.picker.has-photo { box-shadow: none; }
.picker .change {
  position: absolute; left: 50%; bottom: var(--s4); transform: translateX(-50%); pointer-events: none;
  padding: var(--s2) var(--s5); border-radius: var(--r-pill); background: var(--scrim); font-weight: 600; white-space: nowrap;
}

.field { display: grid; gap: var(--s1); }
.field label { font-size: var(--fs-body); font-weight: 600; }
.input {
  width: 100%; min-height: 56px; padding: 0 var(--s4); border: 1px solid var(--rule); border-radius: var(--r-ctl);
  background: var(--night-2); font-size: var(--fs-lead);
}
.input:focus { outline: none; border-color: var(--gilt); }
.input::placeholder { color: var(--parchment-dim); opacity: 1; font-style: italic; }
.phone { display: flex; align-items: stretch; border: 1px solid var(--rule); border-radius: var(--r-ctl); background: var(--night-2); }
.phone:focus-within { border-color: var(--gilt); }
.phone span { display: flex; align-items: center; padding: 0 var(--s3) 0 var(--s4); color: var(--parchment-dim); font-size: var(--fs-lead); border-right: 1px solid var(--rule); }
.phone .input { border: 0; background: transparent; font-variant-numeric: lining-nums tabular-nums; }
.err { margin: 0; color: var(--danger); font-size: var(--fs-body); font-weight: 600; }
.field[data-invalid] .input, .field[data-invalid] .phone { border-color: var(--danger); }

.check { display: flex; gap: var(--s3); align-items: center; min-height: 48px; cursor: pointer; line-height: 1.3; }
.check input {
  flex: none; width: 28px; height: 28px; margin: 0; cursor: pointer;
  appearance: none; -webkit-appearance: none; border: 2px solid var(--parchment-dim); border-radius: 6px; background: var(--night-2);
  display: grid; place-items: center;
}
.check input:checked { background: var(--gilt); border-color: var(--gilt); }
.check input:checked::after {
  content: ""; width: 7px; height: 13px; margin-top: -3px;
  border: solid var(--gilt-ink); border-width: 0 3px 3px 0; transform: rotate(45deg);
}
.field[data-invalid] .check { color: var(--danger); }
.field[data-invalid] .check input { border-color: var(--danger); }
.replace-note { margin: 0; color: var(--wait); font-weight: 600; }
.rules { margin: 0; color: var(--parchment-dim); font-style: italic; font-size: var(--fs-small); line-height: 1.35; }
.form-error { margin: 0; padding: var(--s4); border-left: 3px solid var(--danger); background: var(--night-2); color: var(--danger); font-weight: 600; }

/* ---------- Footer ---------- */
.foot {
  display: grid; justify-items: center; gap: var(--s2); padding: var(--s7) var(--gutter) var(--s8);
  border-top: 1px solid var(--rule); text-align: center; color: var(--parchment-dim); font-size: var(--fs-small);
}
.foot p { margin: 0; }
.foot a { display: inline-flex; align-items: center; min-height: 48px; font-size: var(--fs-body); }

/* ---------- Fullscreen viewer ---------- */
dialog#viewer {
  width: 100%; height: 100%; max-width: none; max-height: none; margin: 0; padding: 0; border: 0;
  background: var(--scrim); color: var(--parchment); overflow: hidden;
}
dialog#viewer::backdrop { background: var(--scrim); }
body:has(dialog[open]) { overflow: hidden; }
.viewer-stage { position: absolute; inset: 0; display: grid; place-items: center; touch-action: none; overflow: hidden; }
.viewer-img { max-width: 100%; max-height: 100%; object-fit: contain; user-select: none; -webkit-user-drag: none; transform-origin: 0 0; will-change: transform; }
.viewer-close, .viewer-nav {
  position: absolute; display: grid; place-items: center; width: 56px; height: 56px; padding: 0;
  border: 1px solid var(--rule); border-radius: var(--r-pill); background: var(--night-2); color: var(--parchment); cursor: pointer;
}
.viewer-close svg, .viewer-nav svg { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.viewer-close { top: max(var(--s4), env(safe-area-inset-top)); right: var(--s4); }
.viewer-nav { top: 50%; transform: translateY(-50%); display: none; }
.viewer-prev { left: var(--s5); }
.viewer-next { right: var(--s5); }
@media (hover: hover) and (min-width: 768px) { .viewer-nav { display: grid; } }
.viewer-nav[hidden] { display: none; }
.viewer-bar {
  position: absolute; left: 50%; bottom: max(var(--s4), env(safe-area-inset-bottom)); transform: translateX(-50%);
  width: min(34rem, calc(100% - 2 * var(--s4))); display: grid; gap: var(--s3);
  padding: var(--s4); border-radius: var(--r-ctl); background: var(--night-2); box-shadow: var(--shadow); text-align: center;
}
.viewer-bar[hidden] { display: none; }
.viewer-bar p { margin: 0; font-size: var(--fs-lead); font-weight: 600; line-height: 1.3; }
.viewer-bar .row { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s3); }
.viewer-bar .btn { padding-inline: var(--s4); }
.viewer-bar .msg-ok { color: var(--ok); }
.viewer-bar .msg-err { color: var(--danger); }
.viewer-bar .msg-dim { color: var(--parchment-dim); font-weight: 400; }

/* ---------- Upload progress (pinned) ---------- */
.sending {
  position: fixed; left: var(--s4); right: var(--s4); bottom: max(var(--s4), env(safe-area-inset-bottom)); z-index: 5;
  max-width: 34rem; margin-inline: auto; padding: var(--s4); border-radius: var(--r-ctl);
  background: var(--night-2); box-shadow: var(--shadow); display: grid; gap: var(--s3);
}
.sending p { margin: 0; font-size: var(--fs-lead); font-weight: 600; }
.sending .bar { height: 8px; border-radius: var(--r-pill); background: var(--rule); overflow: hidden; }
.sending i { display: block; width: 0; height: 100%; background: var(--gilt); transition: width 0.2s ease; }

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

/* Short phones (e.g. 375x667): keep the first screen and the form within one viewport. Last, so it wins. */
@media (max-height: 720px) {
  .form { gap: var(--s2); }
  .picker { min-height: 104px; }
}
