/* ------------------------------------------------------------------
   Guide Drop — styles
   Colours, sizes and fonts come from the Figma file.
   Font: Die Grotesk by Klim, one variable font file. Its "opsz"
   (optical size) setting picks the cut used in Figma:
     A = 6 (small labels)   B = 18 (body text)
     C = 30 (buttons)       D = 42 (big titles)

   Layouts:
     Phone  (≤ 700px wide)        title on top
     Wide   (> 700px)             title + challenge in a left column
     Wide & tall (≥ 964px high)   the Figma layout: huge title across the
                                  top, page starts 199px down
------------------------------------------------------------------- */

@font-face {
  font-family: "Die Grotesk";
  src: url("fonts/die-grotesk-vf-roman.woff2") format("woff2");
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}

:root {
  --bg: #f5f5f5;
  --orange: #ff3300;
  --ink: #000;
  --text: #353535;
  --muted: #aaa;
  --faint: #cdcdcd;
  --ruler: #f8f8f8;
  --border: #e6e6e6;
  --margin-guide: rgba(214, 0, 214, .22);   /* InDesign-style margin lines */

  --font: "Die Grotesk", "Helvetica Neue", Helvetica, Arial, sans-serif;

  --ruler-size: 25px;
  --page-ratio: 1.41598; /* A4: 699.49 / 494 */
  --title-size: 137px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-variation-settings: "opsz" 18; /* B by default */
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
  touch-action: manipulation;   /* no double-tap zoom */
  overscroll-behavior: none;    /* no pull-to-refresh / bounce mid-drag */
}

p { margin: 0; }
button { font: inherit; }

[hidden] { display: none !important; }

/* ---------- Screens ---------- */

.screen {
  display: none;
  position: relative;
  min-height: 100svh;
  padding: 0 0 40px;
}
.screen.active { display: block; }

/* ---------- Big title ---------- */

.title {
  font-variation-settings: "opsz" 42; /* D */
  font-weight: 700;
  font-size: var(--title-size);
  line-height: 1;
  margin: 0;
  padding: 0 0 0 15px;
  white-space: nowrap;
  user-select: none;
}
.title--orange { color: var(--orange); }
.title--white  { color: #fff; }
.title--grey   { color: #ddd; }
.title--black  { color: var(--ink); }

/* ---------- Buttons ---------- */

.btn {
  display: block;
  border: 0;
  background: var(--ink);
  color: #fff;
  font-weight: 500;
  font-variation-settings: "opsz" 30; /* C */
  cursor: pointer;
  transition: transform .08s ease, opacity .15s ease;
}
.btn:hover  { opacity: .85; }
.btn:active { transform: scale(.98); }
.btn:focus-visible { outline: 2px solid var(--orange); outline-offset: 3px; }

.btn--big {
  width: 347px;
  max-width: 100%;
  height: 62px;
  border-radius: 3px;
  font-size: 20px;
}

/* Next sits centred near the bottom of the page, only after a drop */
.page .btn--next {
  position: absolute;
  left: 50%;
  bottom: 7%;
  transform: translateX(-50%);
  z-index: 4;
}
.page .btn--next:active { transform: translateX(-50%) scale(.98); }

.btn--next {
  width: 184px;
  height: 44px;
  border-radius: 2px;
  font-size: 14px;
  animation: fade-in .25s ease;
}

/* ---------- Start screen ---------- */

.start-body {
  position: absolute;
  left: 0; right: 0;
  top: 60%;              /* a little below the middle on desktop */
  transform: translateY(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 41px;
  padding: 0 24px;
  text-align: center;
}
/* start screen: big title — fills the width on desktop (capped on short screens) */
.title--hero {
  font-size: min(calc((100vw - 30px) / 4.66), 36svh);
  line-height: .95;
}

/* ==================================================================
   GAME SCREEN — wide layout (default)
   ================================================================== */

#screen-game {
  --panel-min: 210px;
  --stage-top: 24px;
  --stage-bottom: 24px;
  /* page width: design size (494px), shrunk to fit the space */
  --pw: min(494px,
            calc(100vw - var(--panel-min) - 48px - var(--ruler-size)),
            calc((100svh - var(--stage-top) - var(--stage-bottom) - var(--ruler-size) - 2px) / var(--page-ratio)));
  --ph: calc(var(--pw) * var(--page-ratio));
  padding: 0;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
#screen-game.active {
  display: grid;
  grid-template-columns: minmax(var(--panel-min), 1fr) auto minmax(24px, 1fr);
  align-items: start;
}

.round-count {
  position: absolute;
  top: 18px;
  right: 10px;
  font-size: 20px;
  color: var(--faint);
  font-variation-settings: "opsz" 6; /* A */
}

.panel {
  grid-column: 1;
  padding: 18px 24px 24px 30px;
  min-width: 0;
}
/* short screens: the title sits in the left column, sized to fit it */
.panel .title {
  padding: 0;
  margin: 0 0 28px -2px;
  font-size: clamp(34px, calc((50vw - 300px) / 4.9), 120px);
}

.challenge {
  font-size: 18px;
  color: var(--text);
  max-width: 351px;
}
.challenge__name { font-weight: 500; }
/* always two lines tall, so one- and two-line descriptions don't shift things */
.challenge__desc { line-height: 1.3; min-height: 2.6em; }
.challenge__num {
  margin-top: 14px;
  width: 39px;
  height: 39px;
  border-radius: 50%;
  background: #fff;
  color: #d5d5d5;
  font-size: 20px;
  font-weight: 500;
  display: grid;
  place-items: center;
}

/* mini page showing the target */
.challenge__diagram {
  position: relative;
  margin-top: 18px;
  width: 72px;
  height: calc(72px * var(--page-ratio));
  background: #fff;
  box-shadow: 1.5px 1.5px 0 rgba(0, 0, 0, .06);
}
.diagram__line { position: absolute; background: #dcdcdc; }
.diagram__line.is-h { left: 0; right: 0; height: 1px; }
.diagram__line.is-v { top: 0; bottom: 0; width: 1px; }
.diagram__line.is-target { background: var(--orange); }
.diagram__line.is-h.is-target { height: 2px; margin-top: -.5px; }
.diagram__line.is-v.is-target { width: 2px; margin-left: -.5px; }

.hint.is-done { visibility: hidden; }   /* hidden after a drop, space kept */
.hint {
  margin-top: 22px;
  font-size: 14px;
  color: var(--muted);
  font-variation-settings: "opsz" 6; /* A */
  min-height: 1.2em;
}

.stage-wrap {
  grid-column: 2;
  padding-top: var(--stage-top);
  padding-bottom: var(--stage-bottom);
}

/* ---------- Stage: rulers + page ---------- */

.stage {
  position: relative;
  width: calc(var(--ruler-size) + var(--pw));
  height: calc(var(--ruler-size) + var(--ph));
  border: 1px solid var(--border);
  box-sizing: content-box;
}

.ruler {
  position: absolute;
  background-color: var(--ruler);
  touch-action: none;
  overflow: hidden;
}
.ruler--corner {
  left: 0; top: 0;
  width: var(--ruler-size); height: var(--ruler-size);
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}
.ruler--top {
  left: var(--ruler-size); top: 0; right: 0; height: var(--ruler-size);
  border-bottom: 1px solid var(--border);
}
.ruler--left {
  left: 0; top: var(--ruler-size); bottom: 0; width: var(--ruler-size);
  border-right: 1px solid var(--border);
}
.ruler--top.is-active  { cursor: row-resize; }
.ruler--left.is-active { cursor: col-resize; }

.page {
  position: absolute;
  left: var(--ruler-size);
  top: var(--ruler-size);
  width: var(--pw);
  height: var(--ph);
  background: #fff;
  box-shadow: 2px 2px 0 rgba(0, 0, 0, .07);
  overflow: hidden;
}
/* margin guides: 12.7mm on A4, same on every side */
.page::before {
  content: "";
  position: absolute;
  inset: calc(var(--pw) * 0.0605);
  border: 1px solid var(--margin-guide);
  pointer-events: none;
}

/* ---------- Lines ---------- */

.line { position: absolute; pointer-events: none; }
.line.is-h { left: 0; right: 0; height: 1px; }
.line.is-v { top: 0; bottom: 0; width: 1px; }

.line--guide { background: var(--orange); z-index: 3; touch-action: none; outline: none; }
.line--guide.is-ready { pointer-events: auto; }
/* bigger invisible grab area around the 1px guide, for fingers */
.line--guide.is-ready::before { content: ""; position: absolute; inset: -14px; }
.line--guide.is-h.is-ready { cursor: row-resize; }
.line--guide.is-v.is-ready { cursor: col-resize; }
.line--guide.is-dragging { box-shadow: 0 0 0 .5px var(--orange); }
.line--guide.is-dropped { background: #ff8a6b; }
.line--guide:focus-visible { box-shadow: 0 0 0 2px rgba(255, 51, 0, .25); }

.line--target { background: #8a8a8a; z-index: 2; }

/* distance marker between the two lines */
.measure { position: absolute; z-index: 2; pointer-events: none; color: var(--muted); }
.measure::before, .measure::after { content: ""; position: absolute; }
.measure.is-h { border-left: 1px solid #bbb; width: 0; }
.measure.is-h::before, .measure.is-h::after { left: -4px; width: 7px; height: 1px; background: #bbb; }
.measure.is-h::before { top: 0; }
.measure.is-h::after  { bottom: 0; }
.measure.is-v { border-top: 1px solid #bbb; height: 0; }
.measure.is-v::before, .measure.is-v::after { top: -4px; height: 7px; width: 1px; background: #bbb; }
.measure.is-v::before { left: 0; }
.measure.is-v::after  { right: 0; }
.measure__label { position: absolute; font-size: 11px; white-space: nowrap; }
.measure.is-h .measure__label { left: 8px; top: 50%; transform: translateY(-50%); }
.measure.is-v .measure__label { top: 8px; left: 50%; transform: translateX(-50%); }

/* ---------- Round result (on the page) ---------- */

.result {
  position: absolute;
  left: 0; right: 0;
  top: 23.5%;
  text-align: center;
  pointer-events: none;
  z-index: 1;
  animation: fade-in .25s ease;
}
.result__label { font-size: 14px; color: var(--muted); font-variation-settings: "opsz" 6; }
.result__score {
  font-size: calc(var(--pw) * 0.2137); /* 105.5px on a 494px page */
  font-weight: 500;
  color: #2f2f2f;
  line-height: 1.2;
}
.result__off {
  font-variation-settings: "opsz" 6; /* A */
  position: absolute;
  left: 0; right: 0;
  text-align: center;
  font-size: 14px;
  color: var(--muted);
  pointer-events: none;
  animation: fade-in .25s ease;
}

/* ---------- Wide & tall: the Figma layout ---------- */

@media (min-width: 701px) and (min-height: 964px) {
  #screen-game { --stage-top: 199px; }
  .panel { padding-top: 193px; }
  .panel .title {
    position: absolute;
    left: 0; top: 0;
    margin: 0;
    padding-left: 15px;
    font-size: var(--title-size);
  }
}

/* ==================================================================
   Final screen
   ================================================================== */

.final-head .title { line-height: .92; }
.final-score__out { color: #ddd; }

.final-body {
  --col: 440px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  margin: -40px auto 0;
  padding: 0 24px;
}
.final-body .btn--big { width: var(--col); }

.card {
  width: var(--col);
  max-width: 100%;
  background: #fff;
  border-radius: 6px;
  padding: 8px 0;
  margin-bottom: 4px;
}

.results {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  color: #000;
  font-variation-settings: "opsz" 6; /* A */
  font-variant-numeric: tabular-nums;
}
.results th {
  text-align: left;
  font-weight: 400;
  font-size: 11px;
  color: #b4b4b4;
  padding: 12px 10px 10px;
}
.results td {
  padding: 13px 10px;
  vertical-align: middle;
  white-space: nowrap;
}
.results tbody tr:nth-child(odd) td { background: #fafafa; }   /* super-subtle stripes */
.results th:first-child, .results td:first-child { padding-left: 20px; }
.results th:last-child,  .results td:last-child  { padding-right: 20px; }
.results__num { width: 1%; color: #c4c4c4; }
.results td.results__num { color: #c4c4c4; }
.results__name { display: flex; align-items: center; gap: 10px; }
.results__result { color: #7a7a7a; }
.results__pts { text-align: right !important; }
.results td.results__pts { font-size: 14px; }

/* tiny version of the challenge diagram in each row */
.mini {
  position: relative;
  flex: none;
  width: 14px;
  height: calc(14px * var(--page-ratio));
  background: #fff;
  box-shadow: 0 0 0 1px #e4e4e4;
}
.mini span { position: absolute; background: var(--orange); }
.mini .is-h { left: 0; right: 0; height: 1px; }
.mini .is-v { top: 0; bottom: 0; width: 1px; }


@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

/* ==================================================================
   Replay video panel
   ================================================================== */

.reel {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(245, 245, 245, .92);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  overflow-y: auto;
}
.reel__box {
  position: relative;
  width: min(440px, 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  text-align: center;
}
.reel__close {
  position: absolute;
  top: -6px; right: -4px;
  width: 40px; height: 40px;
  border: 0;
  background: none;
  font-size: 30px;
  line-height: 1;
  color: #8a8a8a;
  cursor: pointer;
}
.reel__title { margin: 0; font-size: 22px; font-weight: 500; color: #1f1f1f; }
.reel__frame {
  position: relative;
  height: min(52svh, 520px);
  aspect-ratio: 9 / 16;
  margin: 6px 0 2px;
  border-radius: 6px;
  overflow: hidden;
  background: #fff;
  box-shadow: 0 1px 0 rgba(0, 0, 0, .04), 0 10px 30px rgba(0, 0, 0, .08);
}
.reel__frame canvas, .reel__frame video { display: block; width: 100%; height: 100%; }
.reel__progress { width: 200px; height: 2px; background: #e2e2e2; overflow: hidden; }
.reel__progress span { display: block; height: 100%; width: 0; background: var(--orange); }
.reel__status { font-size: 13px; color: #8a8a8a; min-height: 1.2em; font-variation-settings: "opsz" 6; }
.reel__actions { width: 100%; display: flex; flex-direction: column; align-items: center; gap: 10px; }
.reel__actions .btn--big { width: 100%; }
.btn--link {
  display: grid;
  place-items: center;
  text-decoration: none;
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ==================================================================
   Shorter desktop screens: smaller titles on start / final
   ================================================================== */

@media (max-width: 1100px), (max-height: 800px) {
  :root { --title-size: clamp(56px, 13vw, 110px); }
  .final-body { margin-top: 24px; }
}

/* ==================================================================
   PHONES: stack everything, Next button on the page
   ================================================================== */

@media (max-width: 700px) {
  /* "Guide Drop" spans the full width (its width is 4.66 × the font size) */
  :root { --title-size: calc((100vw - 20px) / 4.66); }
  .screen { padding-bottom: 24px; }

  #screen-game {
    --pw: min(494px,
              calc(100vw - 32px - var(--ruler-size)),
              calc((100svh - 250px) / var(--page-ratio)));
  }
  #screen-game.active { display: flex; flex-direction: column; }

  .panel { padding: 0; }
  .panel .title { margin: 0; padding-left: 10px; font-size: var(--title-size); }

  /* "2 of 5" in the bottom-right corner */
  .round-count {
    top: auto;
    bottom: 12px;
    right: 14px;
    font-size: 16px;
  }

  .challenge {
    max-width: none;
    padding: 18px 16px 0 24px;     /* a little further below the title */
    display: grid;
    grid-template-columns: auto 1fr auto;
    grid-template-rows: auto auto;
    column-gap: 14px;
    align-items: center;
    font-size: 16px;
  }
  .challenge__num { grid-row: 1 / span 2; grid-column: 1; margin: 0; width: 34px; height: 34px; font-size: 17px; }
  /* name and hint left-aligned together, hint tucked right under the name */
  .challenge__name { grid-row: 1; grid-column: 2; align-self: end; }
  .challenge .hint {
    grid-row: 2; grid-column: 2; align-self: start;
    margin: 1px 0 0; padding: 0;
    text-align: left; font-size: 13px; min-height: 0;
  }
  .challenge__desc { display: none; }   /* phones: just the name + diagram */
  .challenge__diagram {
    grid-column: 3; grid-row: 1 / span 2;
    margin: 0; width: 36px; height: calc(36px * var(--page-ratio));
  }

  /* centre the page itself (not page + ruler): pull the ruler out to the left */
  .stage-wrap { align-self: stretch; padding: 14px 0 0; display: flex; justify-content: center; }
  .stage { margin-left: calc(-1 * var(--ruler-size)); }

  .title--hero { font-size: var(--title-size); line-height: 1; }  /* one line, full width */
  .start-body { gap: 28px; top: 50%; }

  /* buttons 10% smaller on phones */
  .btn--big { height: 56px; font-size: 18px; }
  .btn--next { width: 166px; height: 40px; font-size: 13px; }
  .title { padding-left: 10px; }
  .results th:first-child, .results td:first-child { padding-left: 12px; }
  .results th:last-child,  .results td:last-child  { padding-right: 12px; }
  .results td, .results th { padding-left: 6px; padding-right: 6px; }
  .results { font-size: 12px; }
  .results__result { white-space: normal; }
}
