/* Pinpoint: window, board, markers and menus. Shared colours come from /assets/site.css. */

:root {
  /* Pinpoint's board is a shade darker than the site's field */
  --pp-field: #1a2233;
  --pp-field-line: rgba(255, 255, 255, 0.045);
  --pp-scrim: rgba(8, 11, 18, 0.62);

  /* Markers look the same in both themes: they always sit on the dark board */
  --mk-rim: #e3262f;
  --mk-fill: #3f070d;
  --mk-fill-hi: #6a0e17;
  --mk-ink: #ff3d48;
  --mk-glow: rgba(255, 40, 52, 0.45);
  --mk-ok-rim: #3fd37e;
  --mk-ok-fill: #0a3f22;
  --mk-ok-ink: #8dffb7;
  --mk-ok-glow: rgba(63, 211, 126, 0.55);
  --mk-late: #f0b04d;
  --mk-wrong: #ffffff;
  --mk-miss: #ff6b6b;
  --mk-needed: #f0b04d;
  --oct: polygon(29.29% 0, 70.71% 0, 100% 29.29%, 100% 70.71%, 70.71% 100%, 29.29% 100%, 0 70.71%, 0 29.29%);
}
@media (prefers-color-scheme: dark) {
  :root {
    --pp-field: #111827;
    --pp-field-line: rgba(255, 255, 255, 0.035);
    --pp-scrim: rgba(3, 6, 12, 0.66);
  }
}

.desk {
  flex: none;
  min-height: calc(100vh - var(--hdr));
  padding-inline: 16px;
  padding-block: 16px;
  display: grid;
  place-items: center;
  background-image: radial-gradient(circle, var(--desk-dot) 1px, transparent 1.5px);
  background-size: 20px 20px;
}

@supports (height: 100dvh) {
  .desk { min-height: calc(100dvh - var(--hdr)); }
}

/* ---------- Window ---------- */
.window {
  width: min(100%, 780px, max(260px, calc(100vh - 214px - var(--hdr))));
  display: flex;
  flex-direction: column;
  background: var(--win);
  border: 1.5px solid var(--win-line);
  border-radius: 14px;
  box-shadow: var(--win-shadow);
  overflow: hidden;
}
@supports (height: 100dvh) {
  .window { width: min(100%, 780px, max(260px, calc(100dvh - 214px - var(--hdr)))); }
}
.window.is-opening { animation: win-in 0.22s ease-out; }
.window.is-closing { animation: win-out 0.16s ease-in forwards; pointer-events: none; }

.titlebar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 7px 7px 7px 14px;
  background: var(--bar);
  color: var(--bar-ink);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-mark {
  width: 15px;
  height: 15px;
  clip-path: var(--oct);
  background: var(--mk-rim);
  display: grid;
  place-items: center;
}
.brand-mark::after { content: ""; width: 9px; height: 9px; clip-path: var(--oct); background: var(--mk-fill); }
.brand h1 {
  margin: 0;
  font: 400 13px/1 "Bungee", "Arial Black", Impact, sans-serif;
  letter-spacing: 0.08em;
  white-space: nowrap;
}
.icon-btn {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--bar-muted);
  cursor: pointer;
  transition: background-color 0.12s, color 0.12s;
}
.icon-btn:hover { background: var(--bad); color: var(--on-state); }

/* ---------- Status strip (one row, so its height never changes) ---------- */
.status {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 45px;
  padding: 11px 14px;
  border-bottom: 1px solid var(--line);
}
.phase { display: flex; align-items: baseline; gap: 10px; min-width: 0; white-space: nowrap; overflow: hidden; }
.phase-label {
  font-weight: 700;
  font-size: 13px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}
.phase-detail {
  overflow: hidden;
  text-overflow: ellipsis;
  font: 400 12px/1 "Martian Mono", ui-monospace, "Cascadia Mono", Menlo, monospace;
  color: var(--muted);
}
.count {
  flex: none;
  font: 600 13px/1 "Martian Mono", ui-monospace, Menlo, monospace;
  font-variant-numeric: tabular-nums;
}
.progress { position: absolute; left: 0; right: 0; bottom: -1px; height: 3px; overflow: hidden; }
.progress-fill {
  height: 100%;
  background: var(--ok);
  transform: scaleX(0);
  transform-origin: left center;
  transition: transform 0.12s ease;
}
.progress-fill.is-failed { background: var(--bad); }

/* ---------- Board ---------- */
.board {
  position: relative;
  flex: none;
  width: 100%;
  max-width: 100%;
  aspect-ratio: 1 / 1;
  overflow: hidden;
  background-color: var(--pp-field);
  background-image:
    radial-gradient(ellipse at 50% 45%, rgba(255, 255, 255, 0.03), transparent 70%),
    linear-gradient(var(--pp-field-line) 1px, transparent 1px),
    linear-gradient(90deg, var(--pp-field-line) 1px, transparent 1px);
  background-size: 100% 100%, calc(var(--unit, 400px) / 8) calc(var(--unit, 400px) / 8), calc(var(--unit, 400px) / 8) calc(var(--unit, 400px) / 8);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.board.is-play { cursor: crosshair; }
.board:focus { outline: none; }
.field { position: absolute; inset: 0; }

/* Markers: a thin bright rim around a dark octagon, number in the middle */
.dot {
  position: absolute;
  left: 0;
  top: 0;
  width: var(--dpx, 70px);
  aspect-ratio: 1 / 1;
  pointer-events: none;
  filter: drop-shadow(0 0 calc(var(--dpx, 70px) * 0.09) var(--mk-glow));
}
.dot-rim {
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  clip-path: var(--oct);
  background: var(--mk-rim);
  animation: dot-in var(--pop, 0.2s) cubic-bezier(0.2, 0.9, 0.3, 1.25) both;
}
.dot-fill {
  display: grid;
  place-items: center;
  width: 90%;
  height: 90%;
  clip-path: var(--oct);
  background: radial-gradient(circle at 50% 38%, var(--mk-fill-hi), var(--mk-fill) 72%);
}
.dot-num {
  font: 700 calc(var(--dpx, 70px) * 0.33)/1 "Orbitron", "Martian Mono", ui-monospace, monospace;
  color: var(--mk-ink);
  text-shadow: 0 0 calc(var(--dpx, 70px) * 0.08) var(--mk-glow);
}

/* Correct click: green, then gone right away */
.dot.is-hit { filter: drop-shadow(0 0 calc(var(--dpx, 70px) * 0.12) var(--mk-ok-glow)); }
.dot.is-hit .dot-rim { background: var(--mk-ok-rim); animation: dot-out 0.15s ease-in 0.08s forwards; }
.dot.is-hit .dot-fill { background: var(--mk-ok-fill); }
.dot.is-hit .dot-num { color: var(--mk-ok-ink); text-shadow: 0 0 calc(var(--dpx, 70px) * 0.08) var(--mk-ok-glow); }

/* Fails */
.dot.is-wrong .dot-rim { background: var(--mk-wrong); animation: dot-shake 0.36s ease; }
.dot.is-late .dot-rim { background: var(--mk-late); animation: dot-blink 0.4s steps(2, jump-none) 3; }
.dot.is-late .dot-num { color: var(--mk-late); }
.dot.is-needed::after {
  content: "";
  position: absolute;
  inset: -16%;
  border: 3px solid var(--mk-needed);
  border-radius: 50%;
}
.miss-mark {
  position: absolute;
  left: 0;
  top: 0;
  width: calc(var(--dpx, 70px) * 0.5);
  height: calc(var(--dpx, 70px) * 0.5);
  margin: calc(var(--dpx, 70px) * -0.25) 0 0 calc(var(--dpx, 70px) * -0.25);
  pointer-events: none;
}
.miss-mark::before,
.miss-mark::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 100%;
  height: 3px;
  margin: -1.5px 0 0 -50%;
  border-radius: 2px;
  background: var(--mk-miss);
  box-shadow: 0 0 8px rgba(255, 80, 80, 0.6);
  transform: rotate(45deg);
}
.miss-mark::after { transform: rotate(-45deg); }

/* ---------- Menu (start and end of a round) ---------- */
.menu {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: grid;
  place-items: center;
  padding: 16px;
  background: var(--pp-scrim);
}
.card {
  width: min(100%, 420px);
  max-height: 100%;
  overflow: auto;
  padding: 20px 22px 22px;
  border-radius: 12px;
  background: var(--win);
  color: var(--ink);
  box-shadow: 0 20px 50px -20px rgba(0, 0, 0, 0.6);
}
.card h2 {
  margin: 0 0 10px;
  font: 400 19px/1.15 "Bungee", "Arial Black", Impact, sans-serif;
  text-wrap: balance;
}
.card h2.is-win { color: var(--ok); }
.card h2.is-fail { color: var(--bad); }
.menu-text { margin: 0 0 4px; }
.menu-score {
  margin: 0 0 16px;
  font: 400 12px/1.4 "Martian Mono", ui-monospace, Menlo, monospace;
  color: var(--muted);
}
/* The round's count, then its average reaction time on its own line */
.menu-count { display: block; }
.menu-avg { display: block; margin-top: 2px; color: var(--ink); }
.rules {
  display: grid;
  gap: 5px;
  margin: 0 0 16px;
  padding-left: 1.25em;
  color: var(--muted);
}
.rules li::marker { color: var(--ink); font-weight: 700; }
.rules-short { display: none; margin: 0 0 14px; color: var(--muted); }
.levels-label {
  margin: 0 0 7px;
  font: 600 11px/1 "Martian Mono", ui-monospace, Menlo, monospace;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}
.levels {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 6px;
  margin: 0 0 18px;
}
.level {
  display: grid;
  gap: 4px;
  justify-items: center;
  padding: 9px 2px 8px;
  border: 1.5px solid var(--line);
  border-radius: 9px;
  background: transparent;
  color: var(--ink);
  font: 600 12.5px/1.1 "Figtree", system-ui, sans-serif;
  cursor: pointer;
}
.level small { font: 400 10px/1.2 "Martian Mono", ui-monospace, Menlo, monospace; color: var(--muted); }
.level:hover { border-color: var(--ink); }
.level[aria-checked="true"] { border-color: var(--btn); background: var(--btn); color: var(--btn-ink); }
.level[aria-checked="true"] small { color: inherit; opacity: 0.8; }
.menu-actions { display: flex; gap: 8px; }

/* Leaderboard status in the end menu: saved and rank, or a prompt to log in */
.menu-lb {
  margin: -8px 0 16px;
  font: 500 13.5px/1.35 "Figtree", system-ui, sans-serif;
  color: var(--muted);
}
.menu-lb.is-saved { color: var(--ok); }
.menu-lb.is-held { color: var(--accent-ink); }
.menu-lb.is-failed { color: var(--bad); }
.menu-lb a { color: inherit; font-weight: 700; text-underline-offset: 3px; }
.menu-lb.is-guest a { color: var(--accent-ink); }

/* ---------- Footer ---------- */
.footer {
  display: grid;
  gap: 3px;
  min-height: 66px;
  padding: 12px 14px;
  border-top: 1px solid var(--line);
  align-content: center;
}
.message { margin: 0; font-weight: 500; }
.best {
  font: 400 11px/1.3 "Martian Mono", ui-monospace, Menlo, monospace;
  color: var(--muted);
  letter-spacing: 0.02em;
}
/* "· won 12 of 30 · 40%": this device's rounds on the level that picked every marker, kept on one line */
.best-win { white-space: nowrap; }

.btn {
  font: 600 14px/1 "Figtree", system-ui, sans-serif;
  padding: 11px 18px;
  border: 1.5px solid var(--btn);
  border-radius: 9px;
  background: var(--btn);
  color: var(--btn-ink);
  cursor: pointer;
  transition: transform 0.12s ease, border-color 0.12s ease;
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(1px); }
.btn-quiet { background: transparent; color: var(--ink); border-color: var(--line); }
.btn-quiet:hover { border-color: var(--ink); }
.btn:focus-visible,
.icon-btn:focus-visible,
.level:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

@keyframes dot-in { from { opacity: 0; transform: scale(0.55); } to { opacity: 1; transform: none; } }
@keyframes dot-out { to { opacity: 0; transform: scale(1.18); } }
@keyframes dot-shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-7%); }
  40% { transform: translateX(6%); }
  60% { transform: translateX(-4%); }
  80% { transform: translateX(2%); }
}
@keyframes dot-blink { 50% { opacity: 0.3; } }
@keyframes win-in { from { opacity: 0; transform: translateY(8px) scale(0.98); } to { opacity: 1; transform: none; } }
@keyframes win-out { to { opacity: 0; transform: translateY(6px) scale(0.97); } }

@media (max-width: 460px) {
  .levels { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 420px) {
  .titlebar h1 { font-size: 12px; }
  .status, .footer { padding-inline: 12px; }
  .card { padding: 16px; }
  .card h2 { font-size: 16px; }
}

/* Short screens: budget for everything around the board */
@media (max-height: 612px) {
  .window { width: min(100%, 780px, max(260px, calc(100vh - 241px - var(--hdr)))); }
}
@supports (height: 100dvh) {
  @media (max-height: 612px) {
    .window { width: min(100%, 780px, max(260px, calc(100dvh - 241px - var(--hdr)))); }
  }
}

/* Landscape phones: status and footer move beside the board */
@media (orientation: landscape) and (max-height: 540px) and (min-aspect-ratio: 8 / 5) {
  .desk { padding-block: 8px; }
  .window {
    width: auto;
    display: grid;
    grid-template-columns: auto minmax(200px, 260px);
    grid-template-rows: auto auto 1fr;
  }
  .titlebar { grid-column: 1 / -1; }
  .board { grid-column: 1; grid-row: 2 / span 2; width: calc(100vh - 65px - var(--hdr)); }
  .status { grid-column: 2; grid-row: 2; border-left: 1px solid var(--line); }
  .footer { grid-column: 2; grid-row: 3; border-top: 0; border-left: 1px solid var(--line); align-content: end; }
}
@supports (height: 100dvh) {
  @media (orientation: landscape) and (max-height: 540px) and (min-aspect-ratio: 8 / 5) {
    .board { width: calc(100dvh - 65px - var(--hdr)); }
  }
}

/* Small boards: one-line rules so the whole menu, buttons included, fits */
@media (max-width: 560px), (max-height: 700px) {
  .menu { padding: 10px; }
  .card { padding: 14px 14px 16px; }
  .card h2 { margin-bottom: 8px; font-size: 16px; }
  .rules { display: none; }
  .rules-short { display: block; font-size: 13.5px; }
  .levels { margin-bottom: 12px; }
  .level { padding-block: 7px 6px; }
  .menu-score { margin-bottom: 12px; }
  .menu-lb { margin-bottom: 12px; }
}
/* Phones: the end menu's count line goes (the status strip above the board shows it); the round's
   average stays. With nothing picked there is no average (.no-avg), so the line goes. */
@media (max-width: 460px) {
  .menu-count { display: none; }
  .menu-score { margin-bottom: 10px; }
  .menu-score.no-avg { display: none; }
  .menu-avg { margin-top: 0; }
}
/* Short boards: the menu keeps the title, reason, the round's average, the save line (rank and win
   rate), difficulty and buttons. The status strip above still shows how many were picked, so the
   count line goes; with nothing picked there is no average (.no-avg) and the line goes too. */
@media (max-height: 540px) {
  .rules-short, .levels-label, .menu-count, .level small { display: none; }
  .menu-score { margin: -6px 0 8px; font-size: 11.5px; }
  .menu-score.no-avg { display: none; }
  .menu-avg { margin-top: 0; }
  .menu-lb { margin: 0 0 10px; }
  .card { padding: 12px 14px 14px; }
  .card h2 { margin-bottom: 6px; }
  .menu-text { margin-bottom: 10px; font-size: 13.5px; }
  .level { padding-block: 7px; }
  .levels { margin-bottom: 10px; }
}
/* Smallest boards (small phones): names only on the difficulty buttons; the average stays */
@media (max-width: 380px), (max-height: 456px) {
  .menu-count { display: none; }
  .menu-score { margin: -6px 0 8px; font-size: 11.5px; }
  .menu-score.no-avg { display: none; }
  .menu-avg { margin-top: 0; }
  .menu-lb { margin-top: 0; }
  .levels-label, .level small { display: none; }
  .level { padding-block: 8px; }
  .levels { gap: 5px; margin-bottom: 12px; }
  .menu-text { font-size: 14px; }
}
/* Tight boards (landscape phones, 320 px wide phones): everything a little closer, so the average and
   the save line fit with the difficulty and the buttons, and the card never has to scroll */
@media (max-height: 540px), (max-width: 340px) {
  .menu { padding: 6px; }
  .card { padding: 10px 12px 12px; }
  .card h2 { margin-bottom: 4px; }
  .menu-text { margin-bottom: 6px; font-size: 13px; line-height: 1.3; }
  .menu-score { margin: -2px 0 6px; line-height: 1.3; }
  .menu-lb { margin: 0 0 8px; font-size: 12.5px; line-height: 1.3; }
  .level { padding-block: 6px; }
  .levels { margin-bottom: 8px; }
  .menu-actions .btn { padding-block: 9px; }
}
/* The shortest boards (small phones held sideways): the title says what ended the round and the
   footer beside the board says how far it got, so the longer reason makes way for the rest */
@media (max-height: 340px) {
  .menu-text { display: none; }
}

@media (forced-colors: active) {
  .dot-rim { border: 2px solid ButtonText; }
  .dot.is-hit .dot-rim { background: Highlight; }
  .level[aria-checked="true"] { outline: 3px solid Highlight; }
}

@media (prefers-reduced-motion: reduce) {
  .window.is-opening,
  .window.is-closing,
  .dot-rim,
  .dot.is-wrong .dot-rim,
  .dot.is-late .dot-rim { animation: none; }
  .dot.is-hit .dot-rim { animation: none; }
  .btn, .progress-fill { transition: none; }
}
