* { box-sizing: border-box; }
:root {
  --bg: #f4f0ff;
  --card: #ffffff;
  --ink: #2b2350;
  --muted: #8b84ad;
  --line: #e8e2f7;
  --brand: #7c5cff;
  --brand-soft: #efe9ff;
  --good: #28b487;
  --warn: #ff7a59;
}
/* overscroll-behavior: stop pull-to-refresh from reloading the game mid-round,
   which on phones is a very easy accidental gesture while tapping the board. */
html, body { margin: 0; padding: 0; overscroll-behavior-y: none; }
body {
  font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  background: var(--bg);
  color: var(--ink);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
}
#app {
  width: 100%;
  max-width: 780px;
  padding: 14px 14px 32px;
  text-align: center;
}
header h1 { font-size: 22px; margin: 4px 0 12px; letter-spacing: .3px; }
.stats { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.pill {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 13px;
  color: var(--muted);
}
.pill b { color: var(--ink); font-weight: 700; }
.pill.timer b { color: var(--brand); }
.pill.urgent b { color: var(--warn); }
.hint { font-size: 13px; color: var(--muted); margin: 14px 0 10px; }

.boards {
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
}
.board-wrap { flex: 1 1 320px; max-width: 360px; }
.board-label {
  font-size: 11px;
  letter-spacing: 1px;
  color: var(--muted);
  margin-bottom: 5px;
  font-weight: 700;
}
canvas {
  width: 100%;
  height: auto;
  aspect-ratio: 1 / 1;
  background: #fff;
  border: 2px solid var(--line);
  border-radius: 14px;
  display: block;
  touch-action: manipulation;
  /* Long-pressing the board on iOS otherwise raises the selection / callout
     sheet mid-round. Scoped to the canvas so the challenge link in the share
     box stays selectable (long-press to copy is the fallback there). */
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}
#right { cursor: crosshair; border-color: var(--brand); }

.actions { display: flex; gap: 8px; justify-content: center; margin-top: 16px; flex-wrap: wrap; }
.btn {
  font: inherit;
  font-size: 14px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink);
  padding: 10px 16px;
  border-radius: 12px;
  cursor: pointer;
  transition: transform .08s, background .15s;
}
.btn:active { transform: scale(.96); }
.btn:hover { background: var(--brand-soft); }
.btn.primary { background: var(--brand); color: #fff; border-color: var(--brand); }
.btn.primary:hover { background: #6a49f5; }
.btn.tiny { font-size: 12px; padding: 6px 10px; }
.btn:disabled { opacity: .5; cursor: default; }

footer {
  margin-top: 18px;
  font-size: 12px;
  color: var(--muted);
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
}

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(43, 35, 80, .45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 50;
}
.hidden { display: none !important; }
/* Playfield wraps the two boards; the result card is absolutely positioned
   INSIDE it, so the card lands dead-centre over the canvases — exactly where
   the player is already looking. No scrolling, no position:fixed (which is
   what grey-screened inside webviews). Absolute within a normal-flow parent
   is reliable everywhere. */
.playfield { position: relative; }
.end-card {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  z-index: 12;
  width: min(420px, 94%);
  background: var(--card);
  border: 2px solid var(--brand);
  border-radius: 18px;
  padding: 20px 18px;
  box-shadow: 0 12px 40px rgba(43,35,80,.28);
  text-align: center;
}
.auto-note { font-size: 12px; color: var(--brand); margin-top: 10px; font-weight: 600; }
.ad-box {
  background: var(--card);
  border-radius: 18px;
  padding: 24px;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 20px 60px rgba(43,35,80,.2);
}
.ad-box.modal { text-align: center; }
.ad-title { font-size: 18px; font-weight: 700; margin-bottom: 10px; }
.ad-note { font-size: 13px; color: var(--muted); line-height: 1.5; }
.ad-bar { height: 8px; background: var(--brand-soft); border-radius: 99px; overflow: hidden; margin: 14px 0; }
.ad-bar div { height: 100%; width: 0; background: var(--brand); border-radius: 99px; transition: width .05s linear; }
.result-row { display: flex; gap: 10px; justify-content: center; margin: 16px 0; flex-wrap: wrap; }
.result-row .pill { font-size: 14px; }
.modal-actions { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin-top: 8px; }
.share-box { margin-top: 14px; }
.share-box input {
  width: 100%;
  margin-top: 8px;
  padding: 9px 10px;
  font: inherit;
  font-size: 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  color: var(--ink);
}
.toast {
  position: fixed;
  left: 50%;
  bottom: 34px;
  transform: translateX(-50%);
  background: var(--ink);
  color: #fff;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 13px;
  z-index: 80;
  box-shadow: 0 8px 30px rgba(0,0,0,.2);
}
.mark {
  position: absolute;
  width: 30px;
  height: 30px;
  border: 3px solid var(--good);
  border-radius: 50%;
  pointer-events: none;
  transform: translate(-50%, -50%);
  box-shadow: 0 0 0 3px rgba(255,255,255,.8);
}
.miss {
  position: absolute;
  width: 26px;
  height: 26px;
  pointer-events: none;
  transform: translate(-50%, -50%);
  color: var(--warn);
  font-size: 24px;
  font-weight: 700;
  line-height: 26px;
  text-align: center;
}
.board-wrap { position: relative; }
/* Lightweight viral bar. Anchored to the bottom edge of the playfield, below
   the canvases, so it never blocks difference taps. Slides up, auto-hides. */
.share-bar {
  position: absolute;
  left: 50%;
  bottom: 6px;
  transform: translateX(-50%) translateY(10px);
  z-index: 11;
  display: flex;
  align-items: center;
  gap: 8px;
  width: min(440px, 96%);
  padding: 8px 10px 8px 14px;
  background: var(--ink);
  color: #fff;
  border-radius: 14px;
  box-shadow: 0 10px 30px rgba(43,35,80,.32);
  opacity: 0;
  transition: opacity .28s ease, transform .28s ease;
  pointer-events: none;
}
.share-bar.show { opacity: 1; transform: translateX(-50%) translateY(0); pointer-events: auto; }
.share-bar-text { flex: 1; text-align: left; font-size: 12px; line-height: 1.35; }
.share-bar-close {
  flex: 0 0 auto;
  border: 0;
  background: transparent;
  color: #cfc8ea;
  font-size: 15px;
  line-height: 1;
  padding: 6px;
  cursor: pointer;
}
.share-bar .btn.tiny { flex: 0 0 auto; white-space: nowrap; }

/* ---- Phones: keep BOTH boards on screen (no scrolling to compare) ----
   Below ~700px the two 360px boards cannot sit side by side at a readable
   size (each would be ~175px, creatures ~9px — unplayable), so they stack.
   Stacking is only acceptable if both fit in the viewport: the whole game is
   comparing picture A with picture B, and scrolling turns that into memory.
   So the canvas width is derived from viewport height; the chrome around it
   (title, hint, buttons, footer) is tightened to buy back the space. */
@media (max-width: 700px) {
  #app { padding: 8px 10px calc(8px + env(safe-area-inset-bottom, 0px)); max-width: 100%; }
  header h1 { font-size: 17px; margin: 2px 0 6px; }
  .stats { gap: 5px; }
  .pill { padding: 3px 9px; font-size: 12px; }
  .hint { font-size: 12px; margin: 6px 0 5px; }
  .boards { gap: 8px; }
  .board-wrap {
    flex: 1 1 100%;
    /* 217px = everything that is NOT a canvas (title, stats, hint line, the two
       board labels, action row, footer, page padding) measured on a real phone
       viewport. Whatever height is left is split evenly between the two boards,
       so both are fully visible without scrolling. vh is the fallback for
       browsers without dvh (iOS < 15.4); safe-area is subtracted so the iPhone
       home indicator never eats the lower board. */
    max-width: min(360px, calc((100vh - 217px) / 2));
    max-width: min(360px, calc((100dvh - 217px - env(safe-area-inset-bottom, 0px)) / 2));
    margin: 0 auto;
  }
  .board-label { font-size: 10px; margin-bottom: 3px; }
  .actions { gap: 6px; margin-top: 6px; }
  .btn { font-size: 13px; padding: 7px 11px; }
  footer { margin-top: 8px; font-size: 10px; gap: 8px; }
  .share-bar { bottom: 2px; }
}
