/* Fence Challenge · "Play on paper".
 * The camera image is the hero: it fills the screen, and everything else
 * floats over it on dark glass. Bright colour appears only where it teaches
 * (the enclosed inside, the corner leaks). */
:root {
  --bg0: #07060a;
  --text: rgba(255, 255, 255, 0.94);
  --muted: rgba(255, 255, 255, 0.72);
  --muted2: rgba(255, 255, 255, 0.54);
  --glass: rgba(12, 11, 16, 0.64);
  --glass-strong: rgba(12, 11, 16, 0.82);
  --line: rgba(255, 255, 255, 0.14);
  --line-strong: rgba(255, 255, 255, 0.28);
  --neon: #2df6ac;
  --neon-soft: rgba(45, 246, 172, 0.16);
  --magenta: #ff3bd4;
  --amber: #ffd24a;
  --sans: "Manrope", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --ease: cubic-bezier(0.2, 0.7, 0.2, 1);
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg0);
  color: var(--text);
  font-family: var(--sans);
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

body {
  overflow: hidden;
  overscroll-behavior: none;
  background:
    radial-gradient(900px 620px at 85% -10%, rgba(45, 246, 172, 0.07), transparent 65%),
    radial-gradient(800px 600px at 0% 110%, rgba(178, 120, 255, 0.08), transparent 65%),
    var(--bg0);
}

.sr-only {
  position: absolute !important;
  width: 1px; height: 1px;
  margin: -1px; padding: 0; border: 0;
  overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%);
  white-space: nowrap;
}

svg { width: 22px; height: 22px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }

button { font: inherit; color: inherit; }
button:focus-visible, a:focus-visible, .pill:focus-visible {
  outline: 2.5px solid var(--amber);
  outline-offset: 3px;
}

/* ---------- stage: the camera image and the drawing over it ---------- */

/* The stage is the space the controls leave free, so nothing covers the
 * paper. view.js measures the top bar and the dock into these variables. */
.stage {
  position: fixed;
  top: var(--stage-top, 0px);
  right: var(--stage-right, 0px);
  bottom: var(--stage-bottom, 0px);
  left: 0;
  overflow: hidden;
  touch-action: manipulation;
}
.media {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}
.overlay {
  position: absolute;
  left: 0; top: 0;
  width: 0; height: 0;
  pointer-events: none;
}
/* A photo can be zoomed on its board: a tap on the picture, or this button,
 * switches between the board and the whole picture. */
.zoomBtn {
  position: absolute;
  z-index: 3;
  right: 10px;
  bottom: 10px;
}
.ctl.zoomBtn[aria-pressed="true"] { background: var(--glass); border-color: var(--line); color: var(--text); }
.zoomBtn .i-out, .zoomBtn[aria-pressed="true"] .i-in { display: none; }
.zoomBtn[aria-pressed="true"] .i-out { display: block; }
body[data-fc-state="photo"] .stage { cursor: zoom-out; }
body[data-fc-state="photo"][data-fc-zoom="0"] .stage { cursor: zoom-in; }

body[data-fc-state="start"] .media,
body[data-fc-state="starting"] .media,
body[data-fc-state="error"] .media { opacity: 0; }
video.media { transition: opacity 0.4s var(--ease); }

/* ---------- top bar ---------- */

.topbar {
  position: fixed;
  z-index: 20;
  top: 0; left: 0; right: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: calc(12px + var(--safe-t)) calc(14px + var(--safe-r)) 12px calc(14px + var(--safe-l));
  pointer-events: none;
}
.topbar > * { pointer-events: auto; }
.grow { flex: 1; }

.ctl {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 48px;
  min-height: 48px;
  padding: 0;
  border: 1px solid var(--line);
  background: var(--glass);
  -webkit-backdrop-filter: blur(14px) saturate(1.2);
  backdrop-filter: blur(14px) saturate(1.2);
  color: var(--text);
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.12s ease;
}
.ctl.round { border-radius: 999px; width: 48px; height: 48px; }
.ctl:hover { background: var(--glass-strong); border-color: var(--line-strong); }
.ctl:active { transform: scale(0.96); }
.ctl[aria-pressed="true"] { background: rgba(255, 210, 74, 0.2); border-color: rgba(255, 210, 74, 0.75); color: var(--amber); }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--glass);
  -webkit-backdrop-filter: blur(14px) saturate(1.2);
  backdrop-filter: blur(14px) saturate(1.2);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.01em;
  white-space: nowrap;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}
.chip:hover { background: var(--glass-strong); border-color: var(--line-strong); }
.chip svg { width: 18px; height: 18px; }

/* A small switch drawn inside the "count first" chip. */
.toggle .sw {
  position: relative;
  width: 28px; height: 16px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.18);
  transition: background 0.18s ease;
}
.toggle .sw::after {
  content: "";
  position: absolute;
  top: 2px; left: 2px;
  width: 12px; height: 12px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.18s var(--ease);
}
.toggle[aria-pressed="true"] { border-color: rgba(255, 210, 74, 0.6); }
.toggle[aria-pressed="true"] .sw { background: var(--amber); }
.toggle[aria-pressed="true"] .sw::after { transform: translateX(12px); background: var(--bg0); }

.langSel {
  display: flex;
  gap: 0;
  padding: 2px;
  border-radius: 999px;
  background: var(--glass);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  border: 1px solid var(--line);
}
.langSel button {
  min-width: 44px;
  min-height: 44px;
  padding: 0 6px;
  border: none;
  border-radius: 999px;
  background: transparent;
  color: var(--muted2);
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  cursor: pointer;
  transition: color 0.12s ease, background 0.12s ease;
}
.langSel button:hover { color: var(--text); }
.langSel button[aria-pressed="true"] { color: var(--bg0); background: var(--amber); }

/* ---------- start sheet ---------- */

.sheet {
  position: fixed;
  z-index: 10;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(76px + var(--safe-t)) calc(16px + var(--safe-r)) calc(24px + var(--safe-b)) calc(16px + var(--safe-l));
  overflow-y: auto;
}
.card {
  width: 100%;
  max-width: 440px;
  margin: auto;
  padding: 28px 24px 24px;
  border-radius: 24px;
  border: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(22, 20, 30, 0.86), rgba(12, 11, 16, 0.9));
  -webkit-backdrop-filter: blur(18px);
  backdrop-filter: blur(18px);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.55);
}
.sheetTitle {
  margin: 0;
  font-size: clamp(26px, 7vw, 32px);
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.1;
}
.lede { margin: 10px 0 18px; color: var(--muted); font-size: 16px; }
.needTitle {
  margin: 0 0 6px;
  color: var(--muted2);
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}
.need { margin: 0 0 14px; padding: 0; list-style: none; }
.need li {
  position: relative;
  padding: 5px 0 5px 22px;
  font-size: 15px;
}
.need li::before {
  content: "";
  position: absolute;
  left: 5px; top: 14px;
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--muted);
}
.kit {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 14px 0 12px;
  border-radius: 12px;
  border: 1px solid var(--line);
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  text-decoration: none;
  transition: background 0.15s ease, border-color 0.15s ease;
}
.kit:hover { background: rgba(255, 255, 255, 0.06); border-color: var(--line-strong); }
.kit svg { width: 19px; height: 19px; }
/* On a computer: a QR code to carry this page to a phone. */
.phone {
  display: flex;
  gap: 16px;
  align-items: center;
  margin: 16px 0 0;
  padding: 14px;
  border-radius: 16px;
  border: 1px solid var(--line-strong);
  background: rgba(255, 255, 255, 0.05);
}
.qr {
  flex: none;
  width: 132px;
  height: 132px;
  border-radius: 10px;
  overflow: hidden;
  background: #fff;
}
.qr svg { display: block; width: 100%; height: 100%; stroke: none; }
.phoneText p { margin: 0 0 6px; color: var(--muted); font-size: 14px; line-height: 1.4; }
.phoneText p:last-child { margin-bottom: 0; }
.phoneText .phoneTitle { color: var(--text); font-size: 16px; font-weight: 700; }
@media (max-width: 460px) {
  .phone { flex-direction: column; align-items: flex-start; }
}
.ownTab { margin-top: 12px; }
@media (min-width: 720px) {
  body[data-fc-desktop="1"] .card { max-width: 500px; }
  .qr { width: 148px; height: 148px; }
}

.privacy {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  margin: 18px 0 0;
  padding: 12px 14px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--muted);
  font-size: 14px;
}
.privacy svg { width: 18px; height: 18px; margin-top: 1px; color: var(--muted2); }
.msg { margin: 16px 0 0; color: #ffe3a3; font-size: 15px; }
.msg:empty { display: none; }
.actions { display: flex; flex-direction: column; gap: 10px; margin-top: 20px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 54px;
  padding: 0 22px;
  border-radius: 16px;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.005em;
  cursor: pointer;
  transition: transform 0.12s ease, background 0.15s ease, opacity 0.2s ease, border-color 0.15s ease;
}
.btn:active { transform: scale(0.985); }
.btn.primary { border: none; background: #f6f5ef; color: #0b0a0e; }
.btn.primary:hover { background: #fff; }
.btn.primary[disabled] { opacity: 0.7; cursor: progress; }
.btn.secondary { border: 1px solid var(--line-strong); background: transparent; color: var(--text); }
.btn.secondary:hover { background: rgba(255, 255, 255, 0.06); }

/* ---------- live dock ---------- */

.dock {
  position: fixed;
  z-index: 20;
  left: 0; right: 0; bottom: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 12px calc(14px + var(--safe-r)) calc(16px + var(--safe-b)) calc(14px + var(--safe-l));
  pointer-events: none;
}
.dock > * { pointer-events: auto; }

/* The status line has room for two lines, always: the picture above it keeps
 * its size whatever the message, and no message ever covers the paper. */
.status {
  display: flex;
  align-items: center;
  justify-content: center;
  width: min(560px, 100%);
  min-height: calc(2.6em + 20px);
  margin: 0;
  padding: 9px 18px;
  border-radius: 22px;
  background: var(--glass);
  -webkit-backdrop-filter: blur(14px) saturate(1.2);
  backdrop-filter: blur(14px) saturate(1.2);
  border: 1px solid var(--line);
  color: var(--text);
  font-size: 15px;
  font-weight: 600;
  text-align: center;
  line-height: 1.3;
}
.status:empty { visibility: hidden; }
.status[data-tone="leak"] { border-color: rgba(255, 59, 212, 0.6); }
.status[data-tone="fence"] { border-color: rgba(45, 246, 172, 0.6); }

.row {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
  width: 100%;
  max-width: 560px;
}
.side { display: flex; gap: 10px; align-items: center; }
.side.end { justify-content: flex-end; }

.pill {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-width: 104px;
  min-height: 76px;
  padding: 6px 20px 8px;
  border-radius: 26px;
  border: 1.5px solid var(--line-strong);
  background: var(--glass);
  -webkit-backdrop-filter: blur(16px) saturate(1.2);
  backdrop-filter: blur(16px) saturate(1.2);
  color: var(--text);
  cursor: default;
  transition: border-color 0.25s ease, box-shadow 0.25s ease, color 0.25s ease, background 0.25s ease;
}
.pill .lab {
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted2);
}
.pill .num {
  font-size: 38px;
  font-weight: 800;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
  color: rgba(255, 255, 255, 0.8);
}
.pill.live {
  border-color: rgba(45, 246, 172, 0.9);
  background: linear-gradient(180deg, rgba(45, 246, 172, 0.2), rgba(12, 11, 16, 0.7));
  box-shadow: 0 0 26px rgba(45, 246, 172, 0.38), inset 0 1px 0 rgba(255, 255, 255, 0.1);
}
.pill.live .num { color: #b9ffe4; text-shadow: 0 0 18px rgba(45, 246, 172, 0.7); }
.pill.live .lab { color: rgba(185, 255, 228, 0.8); }
.pill.hiddenNum { cursor: pointer; border-style: dashed; border-color: rgba(255, 210, 74, 0.8); box-shadow: none; background: var(--glass); }
.pill.hiddenNum .num { color: var(--amber); text-shadow: none; }
.pill.hiddenNum .lab { color: rgba(255, 210, 74, 0.8); }
.pill.pop .num { animation: pop 0.42s var(--ease); }
@keyframes pop { 0% { transform: scale(0.72); } 60% { transform: scale(1.12); } 100% { transform: scale(1); } }
/* The first closed fence: the pill glows twice with the neon of the inside. */
.pill.cheer { animation: cheer 1.6s ease-out; }
@keyframes cheer {
  0%, 100% { box-shadow: 0 0 26px rgba(45, 246, 172, 0.38); }
  25%, 70% { box-shadow: 0 0 48px 8px rgba(45, 246, 172, 0.7); }
  48% { box-shadow: 0 0 22px rgba(45, 246, 172, 0.3); }
}

/* The board the camera recognised, named for a moment at the top of the picture. */
.boardTag {
  position: absolute;
  z-index: 2;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  display: inline-flex;
  align-items: center;
  gap: 8px;
  max-width: calc(100% - 24px);
  margin: 0;
  padding: 7px 16px 7px 12px;
  border-radius: 999px;
  border: 1px solid rgba(45, 246, 172, 0.55);
  background: var(--glass-strong);
  -webkit-backdrop-filter: blur(14px) saturate(1.2);
  backdrop-filter: blur(14px) saturate(1.2);
  color: var(--text);
  font-size: 14px;
  font-weight: 700;
  white-space: nowrap;
  pointer-events: none;
  animation: tagIn 0.35s var(--ease);
  transition: opacity 0.4s ease;
}
.boardTag svg { width: 18px; height: 18px; color: var(--neon); stroke-width: 2.4; }
.boardTag.out { opacity: 0; }
@keyframes tagIn { from { opacity: 0; transform: translate(-50%, -6px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* Photo mode: the number sits on its own line, the two photo actions below it. */
body[data-fc-state="photo"] .row { grid-template-columns: 1fr 1fr; row-gap: 10px; }
body[data-fc-state="photo"] .row .pill { grid-column: 1 / -1; grid-row: 1; justify-self: center; }
body[data-fc-state="photo"] .row .side { justify-content: flex-end; min-width: 0; }
body[data-fc-state="photo"] .row .side.end { justify-content: flex-start; }
body[data-fc-state="photo"] .row .chip { white-space: normal; line-height: 1.15; text-align: left; }

#pauseBtn .i-play { display: none; }
#pauseBtn[data-paused="true"] .i-pause { display: none; }
#pauseBtn[data-paused="true"] .i-play { display: block; }

.continue {
  width: 100%;
  max-width: 360px;
  border: none;
  background: #f6f5ef;
  color: #0b0a0e;
}
.continue:hover { background: #fff; }
.continue[disabled] {
  background: var(--glass);
  color: var(--muted2);
  border: 1px solid var(--line);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  cursor: default;
}
/* Why "Continue on screen" is not available yet. The line keeps its height
 * when empty, so the picture does not move when the button wakes up. */
.why {
  width: 100%;
  max-width: 360px;
  min-height: 1.3em;
  margin: -6px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.3;
  text-align: center;
}
.why:empty { visibility: hidden; }

/* Narrow phones: the "count first" label may wrap onto two short lines. */
@media (max-width: 420px) {
  .topbar { gap: 8px; }
  .toggle { gap: 6px; padding: 0 10px; font-size: 12px; line-height: 1.15; white-space: normal; max-width: 128px; text-align: left; }
}
@media (max-width: 380px) {
  .chip { padding: 0 11px; font-size: 12.5px; }
  .pill { min-width: 92px; padding: 6px 14px 8px; }
  .row { gap: 8px; }
}
@media (min-width: 720px) {
  .status { font-size: 16px; }
  .pill .num { font-size: 42px; }
}
/* Landscape phones: the controls move to a column on the right, so the
 * board keeps the full height of the screen. */
@media (max-height: 520px) and (orientation: landscape) {
  /* The top bar joins the column too, so the picture keeps the full height. */
  .topbar {
    left: auto;
    width: calc(236px + var(--safe-r));
    flex-wrap: wrap;
    gap: 8px;
    padding: calc(8px + var(--safe-t)) calc(12px + var(--safe-r)) 0 12px;
  }
  .topbar .langSel { order: 2; }
  .topbar .grow { order: 1; }
  #countBtn { order: 3; flex: 1 1 100%; justify-content: center; }
  .dock {
    top: var(--dock-top, calc(72px + var(--safe-t)));
    left: auto;
    width: calc(236px + var(--safe-r));
    justify-content: flex-start;
    gap: 8px;
    padding: 6px calc(12px + var(--safe-r)) calc(8px + var(--safe-b)) 12px;
    overflow-y: auto;
    pointer-events: auto;
  }
  /* The start sheet stays clear of the column. */
  .sheet { padding: calc(12px + var(--safe-t)) calc(248px + var(--safe-r)) calc(12px + var(--safe-b)) calc(16px + var(--safe-l)); }
  .status { font-size: 14px; border-radius: 16px; min-height: 0; width: 100%; }
  .row { grid-template-columns: auto auto; justify-content: center; }
  .row .side:not(.end) { order: 1; }
  .row .pill { order: 0; }
  .row .side.end { display: none; }
  .row .side.end:has(> :not([hidden])) { display: flex; order: 2; grid-column: 1 / -1; justify-content: center; }
  .pill { min-height: 60px; min-width: 96px; }
  .pill .num { font-size: 30px; }
  .continue { min-height: 44px; font-size: 15px; padding: 0 14px; line-height: 1.15; }
  .why { font-size: 12px; margin-top: -2px; }
  body[data-fc-state="photo"] .row { grid-template-columns: 1fr; row-gap: 8px; }
  body[data-fc-state="photo"] .row .side { display: flex; justify-content: center; grid-column: 1; }
  body[data-fc-state="photo"] .row .side.end { display: none; }
  body[data-fc-state="photo"] .row .side.end:has(> :not([hidden])) { display: flex; justify-content: center; grid-column: 1; }
}

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