/*
 * Industry Beans colouring sheets - iPad, Safari, staff-operated.
 *
 * Colours are from the brand palette (guidelines p.23). Sky blue is the accent and is used
 * "sparingly" per the guidelines, so it appears on primary buttons and nowhere else.
 *
 * Sized for a member of staff holding an iPad with a child waiting: large targets, one obvious
 * action per screen, nothing that needs a second look.
 */

:root {
  --charcoal: #3f4444;
  --sky: #7fcaee;
  --warm-grey: #cbc4bc;
  --light-grey: #e0e0df;
  --off-white: #f5f4f4;
  --white: #fff;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
}

body {
  background: var(--off-white);
  color: var(--charcoal);
  font-family: 'Aktiv Grotesk', -apple-system, BlinkMacSystemFont, 'Helvetica Neue', Helvetica,
    Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
}

.screen {
  min-height: 100%;
  padding: max(24px, env(safe-area-inset-top)) 24px 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  text-align: center;
}

.screen[hidden] {
  display: none;
}

h1 {
  margin: 0;
  font-size: 2rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.lede {
  margin: 0;
  font-size: 1.25rem;
  max-width: 28ch;
}

.quiet {
  margin: 0;
  color: var(--charcoal);
  opacity: 0.65;
  font-size: 0.95rem;
}

.error {
  margin: 0;
  color: #a4343a;
  font-size: 1.05rem;
  font-weight: 600;
}

.error[hidden] {
  display: none;
}

/* --- controls ------------------------------------------------------------ */

button {
  font: inherit;
  border-radius: 999px;
  border: 2px solid transparent;
  padding: 16px 32px;
  min-height: 60px;
  cursor: pointer;
  font-weight: 600;
  /* Staff tap this with a child leaning on the iPad - no accidental text selection. */
  -webkit-user-select: none;
  user-select: none;
}

button[hidden] {
  display: none;
}

.primary {
  background: var(--sky);
  color: var(--charcoal);
}

.primary.big {
  font-size: 1.35rem;
  padding: 22px 56px;
  min-height: 76px;
}

.secondary {
  background: transparent;
  border-color: var(--warm-grey);
  color: var(--charcoal);
}

button:disabled {
  opacity: 0.45;
  cursor: default;
}

/*
 * A button that reads as a quiet link. Used for "Info for customers", which must never compete
 * with the one obvious action on the screen.
 */
.link {
  background: none;
  border: 0;
  padding: 4px 8px;
  min-height: 0;
  font-size: 0.95rem;
  font-weight: 400;
  color: var(--charcoal);
  opacity: 0.7;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.footnote {
  margin: 0;
}

/* --- PIN ----------------------------------------------------------------- */

#pin-form {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: center;
}

#pin-input {
  font: inherit;
  font-size: 1.5rem;
  letter-spacing: 0.4em;
  text-align: center;
  padding: 14px 20px;
  min-height: 60px;
  width: min(320px, 80vw);
  border: 2px solid var(--warm-grey);
  border-radius: 12px;
  background: var(--white);
  color: var(--charcoal);
}

/* --- capture ------------------------------------------------------------- */

/*
 * The camera stage is sized from the HEIGHT LEFT OVER, not from the width.
 *
 * Sizing it from width (max-width 900px on a 4:3 box = 675px tall) pushed "Take photo" below the
 * fold on an iPad mini in landscape - a 744px viewport cannot hold 675px of stage plus a 76px
 * button plus padding, and staff had to scroll to reach the only button on the screen. Reported
 * from a real device.
 *
 * flex: 1 1 0 makes the flex layout hand it the leftover height, and aspect-ratio then derives
 * the width - so the ratio is kept while shrinking, and the preview still matches what the
 * canvas captures. Both max dimensions are capped in the same 4:3 proportion so the box stays
 * 4:3 whichever axis runs out first: 675px tall when width caps at 900, and three quarters of
 * the available width on a screen too narrow for that.
 */
.stage {
  flex: 1 1 0;
  min-height: 0;
  width: auto;
  max-width: min(900px, 100%);
  max-height: min(675px, calc((100vw - 48px) * 0.75));
  aspect-ratio: 4 / 3;
  background: var(--charcoal);
  border-radius: 16px;
  overflow: hidden;
  display: flex;
}

#preview,
#shot {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

#preview[hidden],
#shot[hidden] {
  display: none;
}

.controls {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  justify-content: center;
  /* The one thing on this screen that must always be reachable. Never shrink it. */
  flex: 0 0 auto;
}

/*
 * Short landscape viewports - iPad mini, and any phone held sideways. Buy the stage some height
 * back by tightening everything around it rather than letting it push the button off screen.
 */
@media (max-height: 780px) {
  #screen-capture {
    gap: 12px;
    padding-top: max(12px, env(safe-area-inset-top));
    padding-bottom: 12px;
  }

  #screen-capture .primary.big {
    padding: 16px 44px;
    min-height: 64px;
  }
}

/* --- working ------------------------------------------------------------- */

.spinner {
  width: 56px;
  height: 56px;
  border: 5px solid var(--light-grey);
  border-top-color: var(--sky);
  border-radius: 50%;
  animation: spin 900ms linear infinite;
}

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

@media (prefers-reduced-motion: reduce) {
  .spinner {
    animation-duration: 3s;
  }
}

/* --- result -------------------------------------------------------------- */

.result-grid {
  display: flex;
  gap: 28px;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  width: 100%;
}

#sheet {
  max-width: min(70vw, 900px);
  max-height: 78vh;
  background: var(--white);
  border: 1px solid var(--light-grey);
  box-shadow: 0 6px 24px rgba(63, 68, 68, 0.14);
}

.result-side {
  display: flex;
  flex-direction: column;
  gap: 18px;
  align-items: center;
}

.qr-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 16px;
  background: var(--white);
  border-radius: 16px;
  border: 1px solid var(--light-grey);
}

#qr {
  width: 190px;
  height: 190px;
  display: block;
  image-rendering: pixelated;
}

#qr[hidden] {
  display: none;
}

/* --- info for customers -------------------------------------------------- */

/*
 * Read at arm's length by a parent holding the iPad, so it is set larger than body copy and
 * capped at a comfortable measure. Two columns in landscape - which is how the iPad is held -
 * so the whole thing fits without scrolling.
 */
#screen-info {
  justify-content: flex-start;
  gap: 16px;
}

/* Wider than the 28ch default: this one is a sentence to read, not a prompt to act on. */
#screen-info .lede {
  max-width: 60ch;
}

.facts {
  list-style: none;
  margin: 0;
  padding: 0;
  text-align: left;
  width: 100%;
  max-width: 1000px;
  display: grid;
  gap: 14px;
}

@media (min-width: 820px) {
  .facts {
    grid-template-columns: 1fr 1fr;
    gap: 14px 28px;
  }
}

.facts li {
  background: var(--white);
  border: 1px solid var(--light-grey);
  border-radius: 14px;
  padding: 14px 18px;
  font-size: 1.05rem;
  line-height: 1.45;
}

.facts strong {
  display: block;
}

/*
 * --- print ---------------------------------------------------------------
 *
 * window.print() prints this page, so everything except the sheet is removed and the sheet is
 * laid out to fill the page exactly. The @page size itself is set at runtime in app.js, because
 * it has to match the orientation of the sheet we actually got back.
 */
/*
 * Sheets are always landscape, so the page size is a constant rather than something set at
 * runtime. Safari on iOS honours @page inconsistently - if it ignores this, staff pick
 * landscape in the iOS print dialog. margin: 0 is also what suppresses the browser's own
 * URL/timestamp headers where the engine supports it.
 */
@page {
  size: A4 landscape;
  margin: 0;
}

@media print {
  body {
    background: var(--white);
  }

  .screen {
    padding: 0;
    min-height: 0;
    display: none;
  }

  #screen-result {
    display: block;
  }

  .footnote,
  #screen-info {
    display: none !important;
  }

  .result-side,
  .qr-box,
  button {
    display: none !important;
  }

  .result-grid {
    display: block;
  }

  #sheet {
    max-width: none;
    max-height: none;
    width: 100%;
    height: auto;
    border: 0;
    box-shadow: none;
  }
}

/* --- parent-facing scan page --------------------------------------------- */

.sheet-preview {
  max-width: min(92vw, 640px);
  max-height: 46vh;
  background: var(--white);
  border: 1px solid var(--light-grey);
  border-radius: 8px;
}

/*
 * An <a> that reads as the primary button. It has to be a link, not a button: only a real link
 * can open the image in a new tab from a single tap without the popup blocker getting involved.
 */
.button-link {
  display: inline-block;
  text-decoration: none;
  text-align: center;
  line-height: 1.2;
  max-width: 90vw;
}

.plain-link {
  color: var(--charcoal);
  text-decoration: underline;
  text-underline-offset: 3px;
}
