/* VectorTrackz: the replay viewer's controls (src/ui/replaybar.ts), and the doors to a replay on
   the other screens: WATCH on a row of RECORDS and on a track's best time, and the REPLAYS list.
   The colours and the type are style.css's. */

/* ---- the viewer ---- */
/* The whole view: a drag on the picture turns the free camera, and any touch brings the controls back. */
.rp {
  position: fixed;
  inset: 0;
  z-index: 6;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  cursor: default;
  touch-action: none;
}
.rp.rp-idle { cursor: none; }
.rp-chrome { transition: opacity 0.3s ease-out; }
/* Faded, the controls take no press: the tap that brings them back presses nothing. */
.rp.rp-idle .rp-chrome { opacity: 0; pointer-events: none; }

.rp-top {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px 14px;
  padding-top: max(8px, env(safe-area-inset-top));
  padding-left: max(12px, env(safe-area-inset-left));
  padding-right: max(12px, env(safe-area-inset-right));
  background: linear-gradient(to bottom, rgba(4, 6, 13, 0.86) 40%, rgba(4, 6, 13, 0));
}
.rp-actions { display: flex; gap: 8px; }
.rp-notice {
  flex: 1 1 auto;
  min-width: 0;
  text-align: center;
  font-size: clamp(10px, 1.3vw, 13px);
  font-weight: 700;
  letter-spacing: 0.16em;
  color: var(--orange);
  text-shadow: 0 0 8px rgba(255, 178, 60, 0.6);
}

.rp-foot {
  padding: 10px 12px 8px;
  padding-bottom: max(8px, env(safe-area-inset-bottom));
  padding-left: max(12px, env(safe-area-inset-left));
  padding-right: max(12px, env(safe-area-inset-right));
  background: linear-gradient(to top, rgba(4, 6, 13, 0.92) 62%, rgba(4, 6, 13, 0));
}
.rp-row { display: flex; align-items: center; gap: 6px; }
.rp-gap { flex: 1 1 auto; }

/* A control: an icon in a square a thumb can find, or a word. */
button.rp-btn {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  width: 46px;
  height: 42px;
  padding: 0;
  background: rgba(4, 6, 13, 0.78);
}
button.rp-btn.rp-word { width: auto; padding: 0 16px; font-size: clamp(11px, 1.3vw, 14px); letter-spacing: 0.18em; white-space: nowrap; }
button.rp-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; pointer-events: none; }
button.rp-btn.rp-play { width: 60px; color: #fff; border-color: var(--cyan); box-shadow: 0 0 12px rgba(62, 231, 255, 0.4), inset 0 0 14px rgba(62, 231, 255, 0.14); }
button.rp-btn:active { background: rgba(62, 231, 255, 0.25); }
/* These take no keyboard focus: no focus ring to leave behind after a click. */
button.rp-btn:focus, button.rp-btn:focus-visible { outline: none; }
.rp-camera svg { margin-right: 8px; }
.rp-speed {
  flex: 0 0 auto;
  min-width: 46px;
  text-align: center;
  font-size: clamp(12px, 1.4vw, 15px);
  font-weight: 700;
  color: var(--cyan);
  text-shadow: 0 0 8px rgba(62, 231, 255, 0.6);
  font-variant-numeric: tabular-nums;
}
.rp-time {
  flex: 0 0 auto;
  margin-left: 10px;
  font-size: clamp(12px, 1.4vw, 15px);
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--fg);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.rp-cars { display: inline-flex; align-items: center; gap: 6px; margin-right: 6px; }
.rp-car {
  max-width: 24vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.14em;
  color: var(--fg);
}

/* ---- the scrub bar: the whole run ---- */
.rp-scrub { position: relative; height: 34px; margin-bottom: 4px; cursor: pointer; touch-action: none; }
.rp-track {
  position: absolute;
  left: 0;
  right: 0;
  top: 18px;
  height: 8px;
  background: rgba(111, 126, 166, 0.22);
  border: 1px solid rgba(111, 126, 166, 0.6);
}
/* How much of it can be sought to so far, then how much has been played. */
.rp-built { position: absolute; left: 0; top: 0; bottom: 0; width: 0; background: rgba(62, 231, 255, 0.24); }
.rp-played { position: absolute; left: 0; top: 0; bottom: 0; width: 0; background: var(--cyan); box-shadow: 0 0 8px var(--cyan); }
.rp-thumb {
  position: absolute;
  top: 50%;
  left: 0;
  width: 6px;
  height: 22px;
  margin: -11px 0 0 -3px;
  background: #fff;
  box-shadow: 0 0 10px #fff, 0 0 16px var(--cyan);
}
.rp-scrub.on .rp-thumb { width: 8px; margin-left: -4px; height: 26px; margin-top: -13px; }
.rp-marks { position: absolute; inset: 0; }
/* What happened where, each with its own shape as well as its colour, standing on the bar. */
.rp-mark { position: absolute; bottom: 100%; transform: translateX(-50%); }
/* A lap: a white post through the bar. */
.rp-mark.lap { bottom: -5px; width: 2px; height: 22px; background: #fff; box-shadow: 0 0 6px #fff; }
/* The finish: a gold post with a flag. */
.rp-mark.finish { bottom: -5px; width: 3px; height: 24px; background: var(--gold); box-shadow: 0 0 6px var(--gold); }
.rp-mark.finish::after { content: ''; position: absolute; top: 0; right: 3px; width: 8px; height: 7px; background: var(--gold); }
/* A stunt: a lime diamond. */
.rp-mark.stunt { margin-bottom: 4px; width: 9px; height: 9px; background: var(--lime); transform: translateX(-50%) rotate(45deg); box-shadow: 0 0 6px var(--lime); }
/* A penalty: a red triangle pointing at the bar. */
.rp-mark.penalty { margin-bottom: 2px; width: 0; height: 0; border-left: 6px solid transparent; border-right: 6px solid transparent; border-top: 11px solid var(--red); filter: drop-shadow(0 0 4px var(--red)); }
/* A wreck: a red cross. */
.rp-mark.wreck { margin-bottom: 2px; width: 13px; height: 13px; }
.rp-mark.wreck::before, .rp-mark.wreck::after { content: ''; position: absolute; left: 5px; top: -1px; width: 3px; height: 15px; background: var(--red); box-shadow: 0 0 5px var(--red); }
.rp-mark.wreck::before { transform: rotate(45deg); }
.rp-mark.wreck::after { transform: rotate(-45deg); }

/* ---- a phone on its side ---- */
@media (max-height: 640px) {
  .rp-top { padding: 5px 10px 10px; }
  .rp-foot { padding: 6px 10px 5px; }
  .rp-row { gap: 5px; }
  button.rp-btn { width: 44px; height: 40px; }
  button.rp-btn.rp-play { width: 54px; }
  button.rp-btn.rp-word { padding: 0 11px; letter-spacing: 0.12em; }
  .rp-scrub { height: 30px; margin-bottom: 3px; }
  .rp-track { top: 15px; }
  .rp-speed { min-width: 40px; }
  .rp-time { margin-left: 6px; }
  /* Whose car it is is on the picture: here there is room for the two arrows only. */
  .rp-car { display: none; }
}
@media (max-width: 560px) {
  .rp-time { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .rp-chrome { transition: none; }
}

/* ---- WATCH: on a row of RECORDS ---- */
table.records td.watch { width: 1%; padding-top: 1px; padding-bottom: 1px; text-align: right; }
table.records td.watch button { min-width: 0; padding: 2px 12px; font-size: 10px; letter-spacing: 0.18em; }
table.records tr.has-replay { cursor: pointer; }

/* ---- WATCH: beside a track's card, when its best time has a replay ---- */
.track-cell { display: flex; align-items: stretch; gap: 4px; min-width: 0; }
.track-cell > button.track-card { flex: 1 1 auto; }
button.track-watch { flex: 0 0 auto; min-width: 0; width: 74px; padding: 0 6px; font-size: 10px; letter-spacing: 0.14em; color: var(--gold); border-color: rgba(255, 215, 0, 0.4); }
button.track-watch.hidden { display: none; }

/* ---- REPLAYS: the ones the player kept ---- */
.replay-list { display: flex; flex-direction: column; gap: 6px; width: 100%; margin: 6px auto 0; text-align: left; }
.replay-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 10px;
  border: 1px solid rgba(62, 231, 255, 0.25);
  background: rgba(4, 6, 13, 0.6);
}
.replay-text { flex: 1 1 auto; min-width: 0; display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 16px; }
.replay-title { font-size: clamp(12px, 1.4vw, 15px); font-weight: 700; letter-spacing: 0.16em; color: var(--cyan); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.replay-time { font-size: clamp(12px, 1.4vw, 15px); font-weight: 700; color: var(--gold); font-variant-numeric: tabular-nums; }
.replay-facts { font-size: 10px; font-weight: 500; letter-spacing: 0.14em; color: var(--muted); }
.replay-facts.warn { color: var(--orange); }
.replay-row button { flex: 0 0 auto; min-width: 0; padding: 7px 14px; font-size: 11px; letter-spacing: 0.18em; }
.replay-row button.danger { color: var(--red); border-color: rgba(255, 90, 90, 0.45); }
.replay-empty { margin: 14px 0; text-align: center; }
@media (max-height: 640px) {
  .replay-list { gap: 4px; }
  .replay-row { padding: 3px 8px; }
  table.records td.watch button { padding: 0 10px; font-size: 9px; }
}

/* ---- TOON (issue #69): the viewer's strips as ink panels, its controls as white inked keys ---- */
body.look-toon .rp-top, body.look-toon .rp-foot { background: rgba(29, 34, 51, 0.92); }
body.look-toon .rp-top { border-bottom: 3px solid #12141c; }
body.look-toon .rp-foot { border-top: 3px solid #12141c; }
body.look-toon button.rp-btn {
  font-style: italic;
  font-weight: 900;
  letter-spacing: 0.06em;
  color: #12141c;
  background: #fff;
  border: 2px solid #12141c;
  box-shadow: 3px 3px 0 #12141c;
}
body.look-toon button.rp-btn.rp-play { color: #12141c; background: #ffd21f; border-color: #12141c; box-shadow: 3px 3px 0 #12141c; }
body.look-toon button.rp-btn:active { background: #ffd21f; box-shadow: none; }
body.look-toon .rp-notice, body.look-toon .rp-speed { color: #ffd21f; text-shadow: none; font-style: italic; }
body.look-toon .rp-time, body.look-toon .rp-car { color: #fff; font-style: italic; }
body.look-toon .rp-track { background: #fff; border: 2px solid #12141c; }
body.look-toon .rp-built { background: #b8dcff; }
body.look-toon .rp-played { background: #2a74f0; box-shadow: none; }
body.look-toon .rp-thumb { background: #ffd21f; border: 2px solid #12141c; box-shadow: 2px 2px 0 #12141c; }
body.look-toon .rp-mark.lap { background: #fff; box-shadow: 0 0 0 1px #12141c; }
body.look-toon .rp-mark.finish, body.look-toon .rp-mark.stunt, body.look-toon .rp-mark.wreck::before, body.look-toon .rp-mark.wreck::after { box-shadow: 0 0 0 1px #12141c; }
body.look-toon .rp-mark.penalty { filter: drop-shadow(0 0 1px #12141c); }

/* The doors to a replay on the other screens. */
body.look-toon #overlay button.track-watch { color: #855e00; }
body.look-toon #overlay .replay-row button.danger { color: #c41d12; border-style: dashed; }
body.look-toon .replay-title { color: var(--cyan); font-style: italic; font-weight: 900; }
body.look-toon .replay-time { color: var(--ink); font-style: italic; }
