/* Art direction: festival-poster print. Flat muted paper colours with grain,
   charcoal ink drawings with hatching, bold white grotesk, a loose script logo. */
:root {
  --paper: #6f8fbf;          /* dusty blue: the select screen */
  --ink: #34343a;            /* charcoal */
  --white: #f6f3ec;          /* slightly warm print white */
  --cream: #ece4d2;
  --cap-color: #b8483c;      /* brick red: tube caps only */
  --script: "Mrs Saint Delafield", "Brush Script MT", cursive;
  --grotesk: "Inter Tight", "Helvetica Neue", Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--paper);
  color: var(--white);
  font-family: var(--grotesk);
  font-weight: 700;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  overscroll-behavior: none;
}

/* paper grain over everything, like a print */
body::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 100;
  pointer-events: none;
  opacity: 0.32;
  mix-blend-mode: multiply;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='180' height='180'><filter id='g'><feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='3' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0.2  0 0 0 0 0.2  0 0 0 0 0.22  0 0 0 0.9 0'/></filter><rect width='100%' height='100%' filter='url(%23g)'/></svg>");
}

[hidden] { display: none !important; }

button { font: inherit; color: inherit; }

.script {
  margin: 0;
  font-family: var(--script);
  font-weight: 400;
  line-height: 1;
  color: var(--white);
  transform: rotate(-6deg);
}

/* ---------- select ---------- */

.select {
  max-width: 440px;
  margin: 0 auto;
  padding: max(28px, env(safe-area-inset-top)) 16px 0;
}

.poster-head { text-align: center; margin-bottom: 26px; }
.poster-head .script { font-size: 54px; margin-bottom: -2px; }
/* home: just the script title, as wide as a big bold heading would be */
.poster-head .hero {
  font-size: clamp(96px, 30.5vw, 132px);
  font-weight: 400;
  letter-spacing: 0;
  line-height: 0.9;
  margin: 4px 0 6px;
}

h1 {
  margin: 0;
  font-size: clamp(38px, 12vw, 52px);
  font-weight: 800;
  line-height: 0.95;
  letter-spacing: -0.015em;
}

.grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px 14px;
  padding: 0 4px 160px;
}

.card {
  appearance: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
}

/* each face on its own hand-cut blob of paper */
.avatar {
  position: relative;
  width: min(100%, 152px);
  aspect-ratio: 1;
  border-radius: var(--blob);
  transition: transform 0.18s ease;
}
.spinner {
  position: absolute;
  inset: 0;
  rotate: var(--upright, 0deg); /* stays upright when the phone turns (set by app.js) */
  border-radius: var(--blob);
  overflow: hidden;
  background: var(--c);
}
.avatar img {
  position: absolute;
  inset: 10%;
  width: 80%;
  height: 80%;
  object-fit: contain;
  pointer-events: none;
}
.card:active .avatar { transform: scale(0.95); }
.card.spin .spinner { animation: spin 0.4s cubic-bezier(0.65, 0, 0.35, 1); }

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* after a shuffle, the faces pop back in */
.grid.shuffled .avatar { animation: pop 0.35s cubic-bezier(0.34, 1.56, 0.64, 1); }
@keyframes pop {
  from { transform: scale(0.6); opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .card.spin .spinner, .grid.shuffled .avatar { animation: none; }
}

/* selected: a charcoal pen line drawn around the blob */
.avatar::after {
  content: "";
  position: absolute;
  inset: -9px;
  border: 3.5px solid var(--ink);
  border-radius: var(--blob);
  filter: url(#ink);
  opacity: 0;
  transform: scale(0.94) rotate(-4deg);
  transition: opacity 0.18s ease, transform 0.25s ease;
  pointer-events: none;
}
.card[aria-checked="true"] .avatar::after { opacity: 1; transform: none; }
.card:focus-visible { outline: none; }
.card:focus-visible .avatar::after { opacity: 0.5; transform: none; }

.card > span:last-child {
  font-size: 17px;
  font-weight: 800;
  letter-spacing: 0.01em;
  text-transform: uppercase;
  color: var(--white);
  opacity: 0.85;
}
.card[aria-checked="true"] > span:last-child { opacity: 1; color: var(--ink); }

.empty {
  margin: 0 auto;
  font-size: 16px;
  line-height: 1.5;
  text-align: center;
}
.empty code { color: var(--ink); }

.next-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 30px 16px max(12px, env(safe-area-inset-bottom));
  background: linear-gradient(to top, var(--paper) 55%, transparent);
  pointer-events: none;
}

.next {
  width: 100%;
  max-width: 360px;
  height: 54px;
  border: 0;
  border-radius: 999px;
  background: var(--white);
  color: var(--ink);
  font-size: 18px;
  font-weight: 800;
  letter-spacing: 0.04em;
  cursor: pointer;
  pointer-events: auto;
  transition: opacity 0.2s ease, transform 0.15s ease;
}
.next:active { transform: scale(0.98); }
.next:disabled { opacity: 0.3; cursor: default; }

/* shuffle + next side by side, together as wide as next used to be */
.next-actions {
  display: flex;
  gap: 10px;
  width: 100%;
  max-width: 360px;
  pointer-events: auto;
}
.next-actions .next { flex: 1; width: auto; max-width: none; }
.shuffle {
  flex: none;
  width: 54px;
  height: 54px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--white);
  color: var(--ink);
  cursor: pointer;
  transition: transform 0.15s ease;
}
.shuffle:active { transform: scale(0.92); }

/* arrow points the way a tap will sort: down = A to Z, up = Z to A */
.sort-arrow { transform-box: fill-box; transform-origin: center; transition: transform 0.25s ease; }
.sort.up .sort-arrow { transform: rotate(180deg); }

.site-foot {
  display: flex;
  justify-content: space-between;
  width: 100%;
  max-width: 360px;
  margin-top: 12px;
  padding: 0 6px;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.01em;
  color: var(--white);
  pointer-events: auto;
}
.site-foot a { color: inherit; text-decoration: none; }
/* previous / next person, either side of the tube */
.char-nav {
  position: absolute;
  z-index: 2;
  top: 50%;
  width: 48px;
  height: 48px;
  margin-top: -24px;
}
.char-nav:active { transform: scale(0.92); }
.char-prev { left: 16px; }
.char-next { right: 16px; }

.play-foot {
  position: absolute;
  z-index: 2;
  left: 50%;
  bottom: max(12px, env(safe-area-inset-bottom));
  width: calc(100% - 32px);
  margin: 0;
  transform: translateX(-50%);
}
.site-foot a:hover { text-decoration: underline; }

/* ---------- pin lock ---------- */

.lock {
  max-width: 440px;
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0 auto;
  padding: max(28px, env(safe-area-inset-top)) 16px max(24px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  align-items: center;
}

.pin-dots {
  display: flex;
  justify-content: center;
  gap: 18px;
  margin: 8px 0 10px;
}
.pin-dots span {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 3px solid var(--white);
  transition: background 0.12s ease, transform 0.12s ease;
}
.pin-dots span.on { background: var(--white); transform: scale(1.1); }

.pin-error {
  height: 22px;
  margin: 0 0 10px;
  font-size: 15px;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-align: center;
  color: var(--ink);
  opacity: 0;
}
.lock[data-error="1"] .pin-error { opacity: 1; }
.lock[data-error="1"] .pin-dots { animation: shake 0.4s ease; }
.lock[data-error="1"] .pin-dots span { border-color: var(--ink); }

@keyframes shake {
  20%, 60% { transform: translateX(-10px); }
  40%, 80% { transform: translateX(10px); }
}

.keypad {
  display: grid;
  grid-template-columns: repeat(3, 76px);
  gap: 14px 22px;
  justify-content: center;
}
.keypad button {
  position: relative;
  width: 76px;
  height: 76px;
  border: 0;
  border-radius: 50%;
  background: none;
  color: var(--white);
  font-size: 30px;
  font-weight: 800;
  cursor: pointer;
  transition: transform 0.1s ease, background 0.1s ease;
}
/* wobbly pen circle around each key */
.keypad button::before {
  content: "";
  position: absolute;
  inset: 0;
  border: 3px solid var(--ink);
  border-radius: 50%;
  filter: url(#ink);
}
.keypad button:active { transform: scale(0.92); background: rgba(52, 52, 58, 0.18); }
.keypad .del::before { display: none; }
.keypad .del { display: grid; place-items: center; }

.opens {
  margin: auto 0 0;
  padding-top: 28px;
  font-size: 17px;
  font-weight: 800;
  letter-spacing: 0.01em;
  text-align: center;
}

/* ---------- groan tube ---------- */

.play {
  position: fixed;
  inset: 0;
  overflow: hidden;
  touch-action: none;
  background: var(--c, var(--paper));
}

.stage {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 100vw;
  height: 100vh;
  transform: translate(-50%, -50%);
}

.play-head {
  position: absolute;
  top: max(14px, env(safe-area-inset-top));
  left: 12px;
  right: 12px;
  z-index: 2;
  display: grid;
  grid-template-columns: 44px 1fr 44px;
  align-items: start;
}

.back {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border: 0;
  background: none;
  color: var(--white);
  cursor: pointer;
}

.play-title { text-align: center; }
/* name signed underneath, starting from the middle of the title */
.title-block { display: inline-block; text-align: left; }
.play-title .script {
  font-size: 46px;
  margin: -6px 0 0 42%;
  white-space: nowrap;
}

.name {
  margin: 0;
  font-size: 40px;
  font-weight: 800;
  line-height: 1;
  letter-spacing: -0.015em;
  text-transform: uppercase;
}

.hint {
  position: absolute;
  left: 0;
  right: 0;
  bottom: calc(max(12px, env(safe-area-inset-bottom)) + 34px);
  margin: 0;
  font-size: 17px;
  font-weight: 800;
  letter-spacing: 0.01em;
  text-align: center;
  text-transform: uppercase;
  pointer-events: none;
  transition: opacity 0.5s ease;
}
.hint:empty, .hint.gone { opacity: 0; }

.tube-wrap {
  position: absolute;
  left: 50%;
  top: 50%;
  width: var(--tw);
  height: var(--th);
  margin: calc(var(--th) / -2) 0 0 calc(var(--tw) / -2);
}

/* the tube: a straight cream body with engraving-style hatching down one side
   and a wobbly charcoal pen outline, and a slightly wider cap on each end */
.tube {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(var(--cap) / 2);
  bottom: calc(var(--cap) / 2);
  border-radius: 5px;
  background:
    repeating-linear-gradient(100deg, transparent 0 5px, rgba(52, 52, 58, 0.55) 5px 6.2px) right / 30% 100% no-repeat,
    repeating-linear-gradient(100deg, transparent 0 9px, rgba(52, 52, 58, 0.3) 9px 10px) right / 52% 100% no-repeat,
    var(--cream);
  overflow: hidden;
}
/* outline */
.tube::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 2;
  border: var(--line) solid var(--ink);
  border-radius: 5px;
  filter: url(#ink);
  pointer-events: none;
}

/* end caps: their own colour, not one of the face colours */
.cap {
  position: absolute;
  z-index: 3;
  left: calc(var(--line) * -1.6);
  right: calc(var(--line) * -1.6);
  height: var(--cap);
  border-radius: 7px;
  background:
    repeating-linear-gradient(100deg, transparent 0 4px, rgba(52, 52, 58, 0.45) 4px 5.2px) right / 32% 100% no-repeat,
    var(--cap-color);
}
.cap::after {
  content: "";
  position: absolute;
  inset: 0;
  border: var(--line) solid var(--ink);
  border-radius: 7px;
  filter: url(#ink);
}
.cap-top { top: 0; }
.cap-bottom { bottom: 0; }

.token {
  position: absolute;
  top: var(--face-top);
  left: 50%;
  width: var(--face);
  height: var(--face);
  z-index: 1;
  border-radius: 50%;
  overflow: hidden;
  background: var(--c, #ccc);
  box-shadow: 0 0 0 3px var(--ink);
  transform: translate(-50%, 0);
  will-change: transform;
}
/* plain ball (no face): a bit of engraving-style shading and a highlight */
.token.ball {
  background:
    radial-gradient(circle at 34% 30%, rgba(246, 243, 236, 0.75) 0 9%, transparent 10%),
    repeating-linear-gradient(120deg, transparent 0 4px, rgba(52, 52, 58, 0.4) 4px 5.2px) right bottom / 45% 55% no-repeat,
    var(--c, #ccc);
}
.token img {
  position: absolute;
  inset: 9%;
  width: 82%;
  height: 82%;
  object-fit: contain;
  pointer-events: none;
}
