/* THEME TOKENS – Herrljunga, "It's a must". Keep the colours in sync with theme.js.
 * Measures taken from the Figma design (402 px wide) are multiplied by --k to fit the 480 px wide stage. */
:root {
  --red: #b12028;           /* the customer's red: every screen and the header */
  --red-dark: #8f1a20;
  --ink: #3a1418;           /* text on the light surfaces */
  --bg: #f1eee7;            /* the light playing field */
  --lane: #ece7e1;
  --white: #ffffff;
  --soft: rgba(255, 255, 255, 0.8);    /* secondary text on red */
  --hair: rgba(255, 255, 255, 0.3);    /* thin lines on red */
  --focus: #ffd98a;
  --error: #ffd2c7;
  --ease-out: cubic-bezier(0.2, 0.7, 0.2, 1);
  /* Adobe Fonts, web project ybj0esh */
  --font: "cy-text", "cy", "Avenir Next", "Helvetica Neue", Arial, sans-serif;   /* running text */
  --font-display: "vincente", Georgia, serif;                                    /* headings and numbers */
  --font-bold: "germania-one", "vincente", Impact, sans-serif;                   /* buttons */
  --u: 1px;                 /* 1 logical game pixel (stage is 480 wide), set on #stage from JS */
  --k: 1.194;               /* 480 / 402 */
  --band: 62;               /* height of the empty band at the top, in game pixels – set on #stage from JS */
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--red);   /* also what the phone's browser tints its own bars with */
  color: var(--white);
  font-family: var(--font);
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
}

body {
  display: grid;
  place-items: center;
  height: 100dvh;
}

#stage {
  /* 1 Figma pixel. Worked out here, not on :root: --u is set on this element, and a variable built from
     another one is fixed where it is declared. */
  --f: calc(var(--u) * var(--k));
  position: relative;
  width: 480px;
  height: 800px;
  overflow: hidden;
  touch-action: none;
  background: var(--bg);
  box-shadow: 0 20px 80px rgba(0, 0, 0, 0.35);
}

#game {
  display: block;
  width: 100%;
  height: 100%;
}

/* ---------- HUD buttons ---------- */
.hud-buttons {
  position: absolute;
  right: calc(var(--u) * 12);
  bottom: calc(var(--u) * 12);
  display: flex;
  gap: calc(var(--u) * 8);
  z-index: 15;
}
.icon-btn {
  width: calc(var(--u) * 44);
  height: calc(var(--u) * 44);
  border-radius: 50%;
  border: 2px solid var(--white);
  background: var(--red);
  color: var(--white);
  display: grid;
  place-items: center;
  padding: 0;
  cursor: pointer;
}
.icon-btn:hover { background: var(--red-dark); }
.icon-btn svg { width: 55%; height: 55%; fill: currentColor; }
.icon-btn .ico-off { display: none; }
.icon-btn.muted .ico-on { display: none; }
.icon-btn.muted .ico-off { display: block; }
/* the pause button grows in beside the mute button when a round starts */
#btnPause {
  transition: width .3s var(--ease-out), margin .3s var(--ease-out), opacity .25s ease, visibility 0s;
}
body:not(.playing) #btnPause {
  width: 0;
  margin-left: calc(var(--u) * -8);
  border-width: 0;
  opacity: 0;
  visibility: hidden;
  transition: width .3s var(--ease-out), margin .3s var(--ease-out), opacity .2s ease, visibility 0s .3s;
}

/* ---------- Overlays ---------- */
.overlay {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(var(--u) * 24) calc(var(--u) * 24) calc(var(--u) * 68);
  background: var(--red);
  overflow-y: auto;
  overflow-x: hidden;
  touch-action: pan-y;
  --fade: 0.4s;
  transition: opacity var(--fade) ease, visibility 0s;
}
/* Screens cross-fade instead of popping: a hidden screen fades out, then leaves the tab order. */
.overlay.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity var(--fade) ease, visibility 0s var(--fade);
}
#screenPause { --fade: 0.2s; background: rgba(177, 32, 40, 0.94); }
/* …and the content of the screen coming in rises into place, one block after the other */
.overlay:not(.hidden) .panel > * { animation: rise .55s var(--ease-out) backwards; }
.overlay:not(.hidden) .panel > :nth-child(2) { animation-delay: .06s; }
.overlay:not(.hidden) .panel > :nth-child(3) { animation-delay: .12s; }
.overlay:not(.hidden) .panel > :nth-child(4) { animation-delay: .18s; }
.overlay:not(.hidden) .panel > :nth-child(5) { animation-delay: .24s; }
.overlay:not(.hidden) .panel > :nth-child(n+6) { animation-delay: .3s; }
#screenPause:not(.hidden) .panel > * { animation-duration: .3s; animation-delay: 0s; }
@keyframes rise {
  from { opacity: 0; transform: translateY(calc(var(--u) * 16)); }
}

.panel {
  width: 100%;
  max-width: calc(var(--u) * 400);
  margin: auto;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: calc(var(--u) * 18);
}
.panel.compact { max-width: calc(var(--u) * 320); }

/* ---------- Start screen (Figma: "Ny design", Frame 11) ---------- */
.overlay.menu { align-items: flex-start; padding-left: 0; padding-right: 0; padding-top: 0; }
.menu .panel {
  gap: 0;
  max-width: none;
  margin: 0 auto;           /* from the top, also when the screen is taller than the content */
  padding-top: calc(var(--u) * var(--band));
}
.brand {
  position: relative;
  width: calc(var(--f) * 274);
  height: calc(var(--f) * 105);
  margin: calc(var(--f) * 11) 0 0;
}
.brand img { position: absolute; display: block; height: auto; }
.brand-logo { left: 0; top: 0; width: 100%; }
.brand-ribbon { left: calc(var(--f) * 25); top: calc(var(--f) * 48); width: calc(var(--f) * 211); }
.cans {
  position: relative;       /* the cans stand in front of the ribbon's tails */
  display: block;
  width: calc(var(--f) * 285);
  height: auto;
  margin-top: calc(var(--f) * -3);
}
.intro {
  margin: calc(var(--f) * 11) 0 0;
  font-size: calc(var(--f) * 16);
  line-height: 1.266;
}
/* a button that reads as text: opens the terms */
.link {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 0.18em;
}
.link:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; border-radius: calc(var(--f) * 4); }
.prize { font-weight: 700; text-decoration: none; }
.prize::after {             /* the small arrow after the prize */
  content: "";
  display: inline-block;
  width: calc(var(--f) * 7);
  height: calc(var(--f) * 7);
  margin-left: calc(var(--f) * 5);
  border: solid currentColor;
  border-width: calc(var(--f) * 2.5) calc(var(--f) * 2.5) 0 0;
  transform: translateY(calc(var(--f) * -1)) rotate(45deg);
}
/* the four ingredients and the sour nisse, each where the design has it */
.legend {
  position: relative;
  flex: none;
  width: calc(var(--f) * 402);
  height: calc(var(--f) * 63);
  margin-top: calc(var(--f) * 12);
}
.legend > img {
  position: absolute;
  left: calc(var(--f) * var(--x));
  top: calc(var(--f) * var(--y));
  width: calc(var(--f) * var(--w));
  height: auto;
}
.ban {
  position: absolute;
  left: calc(var(--f) * 315);
  top: 0;
  width: calc(var(--f) * 63);
  height: calc(var(--f) * 63);
}
.ban img { position: absolute; left: calc(var(--f) * 4); top: calc(var(--f) * 9.3); width: calc(var(--f) * 51); height: auto; }
.ban::before, .ban::after { content: ""; position: absolute; }
.ban::before { inset: 0; border: calc(var(--f) * 5) solid #ff0000; border-radius: 50%; z-index: 1; }
.ban::after {
  left: 50%; top: 50%;
  width: calc(var(--f) * 5);
  height: calc(var(--f) * 58);
  background: #ff0000;
  transform: translate(-50%, -50%) rotate(45deg);
  z-index: 1;
}
.menu .btn.start { margin-top: calc(var(--f) * 21); }
.terms-link { margin-top: calc(var(--f) * 12); font-size: calc(var(--f) * 13); color: var(--soft); }
/* a computer, when the game is for phones only: a note where the start button was */
.desktop-note {
  display: none;
  flex-direction: column;
  gap: calc(var(--f) * 4);
  width: calc(var(--f) * 336);
  margin-top: calc(var(--f) * 21);
  padding: calc(var(--f) * 14) calc(var(--f) * 18);
  border-radius: calc(var(--f) * 20);
  background: var(--white);
  color: var(--ink);
  font-size: calc(var(--f) * 14);
  line-height: 1.4;
}
.desktop-note strong { font-family: var(--font-display); font-weight: 400; font-size: calc(var(--f) * 24); line-height: 1.1; color: var(--red); }
.desktop-note .url { font-weight: 700; overflow-wrap: anywhere; -webkit-user-select: text; user-select: text; }
.desktop .desktop-note { display: flex; }
.desktop :is(#btnStart, .menu .howto, #btnPause) { display: none; }
.menu .board { width: calc(var(--f) * 336); min-height: calc(var(--f) * 150); margin-top: calc(var(--f) * 20); }

h2, h3 {
  font-family: var(--font-display);
  font-weight: 400;
  margin: 0;
}
h2 { font-size: calc(var(--f) * 46); line-height: 1.1; }
h3 { font-size: calc(var(--f) * 30); line-height: 1.1; margin-bottom: calc(var(--f) * 8); }
.pause-note { margin: 0; font-size: calc(var(--f) * 14); line-height: 1.45; color: var(--soft); }

.btn {
  font-family: var(--font-bold);
  font-weight: 400;
  font-size: calc(var(--f) * 26);
  line-height: 1;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  color: var(--red);
  background: var(--white);
  border: calc(var(--f) * 3) solid var(--white);
  border-radius: 999px;
  min-height: calc(var(--f) * 48);
  padding: calc(var(--f) * 6) calc(var(--f) * 28);
  cursor: pointer;
  transition: transform .1s ease, background-color .15s ease;
}
.btn.start {
  display: grid;
  place-items: center;
  width: calc(var(--f) * 203);
  height: calc(var(--f) * 48);
  padding: 0;
}
.btn.start img { display: block; width: calc(var(--f) * 96); height: auto; }
.btn:hover { background: var(--bg); }
.btn:active { transform: scale(0.97); }
.btn.ghost { background: transparent; color: var(--white); }
.btn.ghost:hover { background: rgba(255, 255, 255, 0.12); }
.btn.small { font-size: calc(var(--f) * 19); min-height: 0; padding: calc(var(--f) * 7) calc(var(--f) * 18); }
.btn:focus-visible, .icon-btn:focus-visible, input:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }

.howto {
  list-style: none;
  margin: calc(var(--f) * 18) 0 0;
  padding: 0 calc(var(--f) * 24);
  font-size: calc(var(--f) * 13);
  line-height: 1.5;
  color: var(--soft);
  display: grid;
  gap: calc(var(--u) * 4);
}
.key {
  display: inline-block;
  min-width: calc(var(--u) * 22);
  padding: 0 calc(var(--u) * 5);
  margin: 0 calc(var(--u) * 2);
  border: 1px solid var(--soft);
  border-radius: calc(var(--u) * 5);
  font-size: calc(var(--u) * 12);
  color: var(--white);
}
/* the list: an outlined box on the red */
.board {
  width: 100%;
  border: calc(var(--f) * 4) solid var(--white);
  border-radius: calc(var(--f) * 20);
  padding: calc(var(--f) * 11) calc(var(--f) * 20) calc(var(--f) * 12);
}
.board ol {
  list-style: none;
  margin: 0;
  padding: 0;
  font-size: calc(var(--f) * 15);
  font-variant-numeric: tabular-nums;
  counter-reset: rank;
}
.board li {
  display: flex;
  align-items: baseline;
  gap: calc(var(--u) * 10);
  padding: calc(var(--u) * 5) 0;
  border-bottom: 1px solid var(--hair);
  counter-increment: rank;
}
.board li:last-child { border-bottom: 0; }
.board li::before {
  content: counter(rank) ".";
  opacity: 0.7;
  width: calc(var(--u) * 26);
  text-align: left;
}
.board li .n { flex: 1; text-align: left; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.board li .s { white-space: nowrap; }
.board li.me { font-weight: 700; color: var(--focus); }
.board li.me .n::after { content: " ←"; }
.board .empty { color: var(--soft); justify-content: center; border: 0; }
.board .empty::before { content: none; }

/* ---------- End screen ---------- */
.final {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: calc(var(--u) * 2);
}
.final .label { font-size: calc(var(--f) * 16); color: var(--soft); }
.final strong {
  font-family: var(--font-display);
  font-weight: 400;
  font-size: calc(var(--f) * 72);
  line-height: 1.05;
  font-variant-numeric: tabular-nums;
}
.final .meta { font-size: calc(var(--f) * 14); color: var(--soft); }

.name-form {
  width: 100%;
  display: grid;
  gap: calc(var(--u) * 8);
  font-size: calc(var(--f) * 15);
}
.name-form.hidden { display: none; }
.name-form .btn { justify-self: center; }
.form-lead { margin: 0; }
.form-note { margin: 0; font-size: calc(var(--f) * 12); line-height: 1.4; color: var(--soft); }
.name-form input[type="email"] { text-transform: none; }
.name-form input {
  flex: 1;
  min-width: 0;
  font-family: var(--font);
  font-size: max(16px, calc(var(--u) * 18)); /* >=16px avoids iOS zoom */
  color: var(--ink);
  background: var(--bg);
  border: 0;
  border-radius: 999px;
  padding: calc(var(--u) * 10) calc(var(--u) * 18);
  text-transform: uppercase;
  -webkit-user-select: text;
  user-select: text;
}
.name-form input::placeholder { color: var(--ink); opacity: 0.5; }

.form-error { margin: 0; color: var(--error); font-size: calc(var(--f) * 13); }
.form-error:empty { display: none; }

/* ---------- Terms & personal data: on top of the screen it was opened from ---------- */
.overlay.info { z-index: 30; align-items: flex-start; }
#screenInfo { z-index: 31; }   /* the terms can open on top of the prizes */
.info-text {
  width: 100%;
  text-align: left;
  font-size: calc(var(--f) * 13);
  line-height: 1.5;
}
.info-text h2 { font-size: calc(var(--f) * 30); margin: calc(var(--f) * 16) 0 calc(var(--f) * 6); }
.info-text h2:first-child { margin-top: 0; }
.info-text h3 { font-size: calc(var(--f) * 24); margin: calc(var(--f) * 14) 0 calc(var(--f) * 6); }
.info-text p { margin: 0 0 calc(var(--f) * 8); }
.info-text .prizes { line-height: 1.7; }
.info-text ul { margin: 0 0 calc(var(--f) * 8); padding-left: calc(var(--f) * 18); display: grid; gap: calc(var(--f) * 6); }
.info-text .todo { background: var(--focus); color: var(--ink); padding: 0 0.25em; border-radius: 0.2em; -webkit-user-select: text; user-select: text; }
.info-text a { color: inherit; text-decoration: underline; overflow-wrap: anywhere; -webkit-user-select: text; user-select: text; }

.actions { display: flex; gap: calc(var(--u) * 10); flex-wrap: wrap; justify-content: center; }

.rotate-hint {
  display: none;
  position: absolute;
  left: 50%;
  top: calc(var(--u) * 70);
  transform: translateX(-50%);
  z-index: 20;
  background: var(--white);
  color: var(--ink);
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 12px;
  white-space: nowrap;
  pointer-events: none;
}
@media (orientation: landscape) and (max-height: 500px) and (pointer: coarse) {
  .rotate-hint { display: block; }
}

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